Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

878 rindas
24 KiB

  1. /*
  2. * PypyCaca libcaca Python bindings
  3. * Copyright (c) 2006 Jean-Yves Lamoureux <jylam@lnxscene.org>
  4. * All Rights Reserved
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2 of the License, or (at your option) any later version.
  10. *
  11. * This library is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19. * 02111-1307 USA
  20. */
  21. /** \file pycaca.c
  22. * \version \$Id:
  23. * \author Jean-Yves Lamoureux <jylam@lnxscene.org>
  24. * \brief Main \e pypycaca bindings functions
  25. *
  26. * This file contains functions for python bindings
  27. */
  28. #include "pypycaca.h"
  29. static PyMethodDef CacaMethods[] = {
  30. {"init", pycaca_init, METH_VARARGS, "Init libcaca"},
  31. {"set_delay", pycaca_set_delay, METH_VARARGS, "Set delay"},
  32. {"get_rendertime", pycaca_get_rendertime, METH_NOARGS, "Get render time"},
  33. {"get_width", pycaca_get_width, METH_NOARGS, "Get width"},
  34. {"get_height", pycaca_get_height, METH_NOARGS, "Get Height"},
  35. {"set_size", pycaca_set_size, METH_VARARGS, "Set size"},
  36. {"set_width", pycaca_set_width, METH_VARARGS, "Set width"},
  37. {"set_height", pycaca_set_height, METH_VARARGS, "Set height"},
  38. {"set_window_title", pycaca_set_window_title, METH_VARARGS, "Set window titl"},
  39. {"get_window_width", pycaca_get_window_width, METH_NOARGS, "Get window width"},
  40. {"get_window_height", pycaca_get_window_height, METH_NOARGS, "Get Window height"},
  41. {"refresh", pycaca_refresh, METH_NOARGS, "Refresh window"},
  42. {"end", pycaca_end, METH_NOARGS, "End libcaca"},
  43. {"get_feature", pycaca_get_feature, METH_VARARGS, "Get feature"},
  44. {"set_feature", pycaca_set_feature, METH_VARARGS, "Set feature"},
  45. {"get_feature_name", pycaca_get_feature_name, METH_VARARGS, "Get feature name"},
  46. {"get_event", pycaca_get_event, METH_VARARGS, "Get event"},
  47. {"wait_event", pycaca_wait_event, METH_VARARGS, "Wait event"},
  48. {"get_mouse_x", pycaca_get_mouse_x, METH_NOARGS, "Get Mouse X"},
  49. {"get_mouse_y", pycaca_get_mouse_y, METH_NOARGS, "Get mouse Y"},
  50. {"draw_line", pycaca_draw_line, METH_VARARGS, "Init libcaca"},
  51. {"draw_thin_line", pycaca_draw_thin_line, METH_VARARGS, "Init libcaca"},
  52. {"draw_circle", pycaca_draw_circle, METH_VARARGS, "Init libcaca"},
  53. {"draw_ellipse", pycaca_draw_ellipse, METH_VARARGS, "Init libcaca"},
  54. {"draw_thin_ellipse", pycaca_draw_thin_ellipse, METH_VARARGS, "Init libcaca"},
  55. {"fill_ellipse", pycaca_fill_ellipse, METH_VARARGS, "Init libcaca"},
  56. {"draw_box", pycaca_draw_box, METH_VARARGS, "Init libcaca"},
  57. {"fill_box", pycaca_fill_box, METH_VARARGS, "Init libcaca"},
  58. {"draw_thin_box", pycaca_draw_thin_box, METH_VARARGS, "Init libcaca"},
  59. {"draw_triangle", pycaca_draw_triangle, METH_VARARGS, "Init libcaca"},
  60. {"draw_thin_triangle", pycaca_draw_thin_triangle, METH_VARARGS, "Init libcaca"},
  61. {"fill_triangle", pycaca_fill_triangle, METH_VARARGS, "Init libcaca"},
  62. {"draw_polyline", pycaca_draw_polyline, METH_VARARGS, ""},
  63. {"draw_thin_polyline", pycaca_draw_thin_polyline, METH_VARARGS, ""},
  64. {"set_color", pycaca_set_color, METH_VARARGS, "Init libcaca"},
  65. {"get_fg_color", pycaca_get_fg_color, METH_VARARGS, ""},
  66. {"get_bg_color", pycaca_get_bg_color, METH_VARARGS, ""},
  67. {"get_color_name", pycaca_get_color_name, METH_VARARGS, ""},
  68. {"putchar", pycaca_putchar, METH_VARARGS, ""},
  69. {"putstr", pycaca_putstr, METH_VARARGS, ""},
  70. {"printf", pycaca_printf, METH_VARARGS, ""},
  71. {"clear", pycaca_clear, METH_VARARGS, ""},
  72. {"load_sprite", pycaca_load_sprite, METH_VARARGS, ""},
  73. {"draw_sprite", pycaca_draw_sprite, METH_VARARGS, ""},
  74. {"get_sprite_frames", pycaca_get_sprite_frames, METH_VARARGS, ""},
  75. {"get_sprite_width", pycaca_get_sprite_width, METH_VARARGS, ""},
  76. {"get_sprite_height", pycaca_get_sprite_height, METH_VARARGS, ""},
  77. {"get_sprite_dx", pycaca_get_sprite_dx, METH_VARARGS, ""},
  78. {"get_sprite_dy", pycaca_get_sprite_dy, METH_VARARGS, ""},
  79. {"free_sprite", pycaca_free_sprite, METH_VARARGS, ""},
  80. {"get_html", pycaca_get_html, METH_VARARGS, ""},
  81. {"get_html3", pycaca_get_html3, METH_VARARGS, ""},
  82. {"get_irc", pycaca_get_irc, METH_VARARGS, ""},
  83. {"get_ansi", pycaca_get_ansi, METH_VARARGS, ""},
  84. {"create_bitmap", pycaca_create_bitmap, METH_VARARGS, ""},
  85. {"set_bitmap_palette", pycaca_set_bitmap_palette, METH_VARARGS, ""},
  86. {"set_bitmap_gamma", pycaca_set_bitmap_gamma, METH_VARARGS, ""},
  87. {"draw_bitmap", pycaca_draw_bitmap, METH_VARARGS, ""},
  88. {"free_bitmap", pycaca_free_bitmap, METH_VARARGS, ""},
  89. // {"", , METH_VARARGS, ""},
  90. {NULL, NULL, 0, NULL} /* Sentinel */
  91. };
  92. PyMODINIT_FUNC
  93. initcaca(void)
  94. {
  95. PyObject *obj, *dict;
  96. obj = Py_InitModule("caca", CacaMethods);
  97. dict = PyModule_GetDict(obj);
  98. SET_INTCONSTANT(dict,CACA_EVENT_NONE );
  99. SET_INTCONSTANT(dict,CACA_EVENT_KEY_PRESS );
  100. SET_INTCONSTANT(dict,CACA_EVENT_KEY_RELEASE );
  101. SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_PRESS );
  102. SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_RELEASE );
  103. SET_INTCONSTANT(dict,CACA_EVENT_MOUSE_MOTION );
  104. SET_INTCONSTANT(dict,CACA_EVENT_RESIZE );
  105. SET_INTCONSTANT(dict,CACA_EVENT_ANY );
  106. SET_INTCONSTANT(dict, CACA_COLOR_BLACK );
  107. SET_INTCONSTANT(dict, CACA_COLOR_BLUE );
  108. SET_INTCONSTANT(dict, CACA_COLOR_GREEN );
  109. SET_INTCONSTANT(dict, CACA_COLOR_CYAN );
  110. SET_INTCONSTANT(dict, CACA_COLOR_RED );
  111. SET_INTCONSTANT(dict, CACA_COLOR_MAGENTA );
  112. SET_INTCONSTANT(dict, CACA_COLOR_BROWN );
  113. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTGRAY );
  114. SET_INTCONSTANT(dict, CACA_COLOR_DARKGRAY );
  115. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTBLUE );
  116. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTGREEN );
  117. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTCYAN );
  118. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTRED );
  119. SET_INTCONSTANT(dict, CACA_COLOR_LIGHTMAGENTA );
  120. SET_INTCONSTANT(dict, CACA_COLOR_YELLOW );
  121. SET_INTCONSTANT(dict, CACA_COLOR_WHITE );
  122. SET_INTCONSTANT(dict, CACA_BACKGROUND );
  123. SET_INTCONSTANT(dict, CACA_BACKGROUND_BLACK );
  124. SET_INTCONSTANT(dict, CACA_BACKGROUND_SOLID );
  125. SET_INTCONSTANT(dict, CACA_BACKGROUND_MIN );
  126. SET_INTCONSTANT(dict, CACA_BACKGROUND_MAX );
  127. SET_INTCONSTANT(dict, CACA_ANTIALIASING );
  128. SET_INTCONSTANT(dict, CACA_ANTIALIASING_NONE );
  129. SET_INTCONSTANT(dict, CACA_ANTIALIASING_PREFILTER );
  130. SET_INTCONSTANT(dict, CACA_ANTIALIASING_MIN );
  131. SET_INTCONSTANT(dict, CACA_ANTIALIASING_MAX );
  132. SET_INTCONSTANT(dict, CACA_DITHERING );
  133. SET_INTCONSTANT(dict, CACA_DITHERING_NONE );
  134. SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED2 );
  135. SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED4 );
  136. SET_INTCONSTANT(dict, CACA_DITHERING_ORDERED8 );
  137. SET_INTCONSTANT(dict, CACA_DITHERING_RANDOM );
  138. SET_INTCONSTANT(dict, CACA_DITHERING_FSTEIN );
  139. SET_INTCONSTANT(dict, CACA_DITHERING_MIN );
  140. SET_INTCONSTANT(dict, CACA_DITHERING_MAX );
  141. SET_INTCONSTANT(dict, CACA_FEATURE_UNKNOWN );
  142. SET_INTCONSTANT(dict, CACA_KEY_UNKNOWN );
  143. SET_INTCONSTANT(dict, CACA_KEY_BACKSPACE );
  144. SET_INTCONSTANT(dict, CACA_KEY_TAB );
  145. SET_INTCONSTANT(dict, CACA_KEY_RETURN );
  146. SET_INTCONSTANT(dict, CACA_KEY_PAUSE );
  147. SET_INTCONSTANT(dict, CACA_KEY_ESCAPE );
  148. SET_INTCONSTANT(dict, CACA_KEY_DELETE );
  149. SET_INTCONSTANT(dict, CACA_KEY_UP );
  150. SET_INTCONSTANT(dict, CACA_KEY_DOWN );
  151. SET_INTCONSTANT(dict, CACA_KEY_LEFT );
  152. SET_INTCONSTANT(dict, CACA_KEY_RIGHT );
  153. SET_INTCONSTANT(dict, CACA_KEY_INSERT );
  154. SET_INTCONSTANT(dict, CACA_KEY_HOME );
  155. SET_INTCONSTANT(dict, CACA_KEY_END );
  156. SET_INTCONSTANT(dict, CACA_KEY_PAGEUP );
  157. SET_INTCONSTANT(dict, CACA_KEY_PAGEDOWN );
  158. SET_INTCONSTANT(dict, CACA_KEY_F1 );
  159. SET_INTCONSTANT(dict, CACA_KEY_F2 );
  160. SET_INTCONSTANT(dict, CACA_KEY_F3 );
  161. SET_INTCONSTANT(dict, CACA_KEY_F4 );
  162. SET_INTCONSTANT(dict, CACA_KEY_F5 );
  163. SET_INTCONSTANT(dict, CACA_KEY_F6 );
  164. SET_INTCONSTANT(dict, CACA_KEY_F7 );
  165. SET_INTCONSTANT(dict, CACA_KEY_F8 );
  166. SET_INTCONSTANT(dict, CACA_KEY_F9 );
  167. SET_INTCONSTANT(dict, CACA_KEY_F10 );
  168. SET_INTCONSTANT(dict, CACA_KEY_F11 );
  169. SET_INTCONSTANT(dict, CACA_KEY_F12 );
  170. SET_INTCONSTANT(dict, CACA_KEY_F13 );
  171. SET_INTCONSTANT(dict, CACA_KEY_F14 );
  172. SET_INTCONSTANT(dict, CACA_KEY_F15 );
  173. }
  174. /*******************/
  175. /* Basic functions */
  176. /*******************/
  177. static PyObject *
  178. pycaca_init(PyObject *self, PyObject *args)
  179. {
  180. int ret;
  181. ret = caca_init();
  182. return Py_BuildValue("i", ret);
  183. }
  184. static PyObject *
  185. pycaca_set_delay(PyObject *self, PyObject *args)
  186. {
  187. int value=0;
  188. if (!PyArg_ParseTuple(args, "i", &value))
  189. caca_set_delay(value);
  190. return Py_BuildValue("i", 1); /*FIXME*/
  191. }
  192. static PyObject *
  193. pycaca_get_rendertime(PyObject *self, PyObject *args)
  194. {
  195. int ret = caca_get_rendertime();
  196. return Py_BuildValue("i", ret);
  197. }
  198. static PyObject *
  199. pycaca_get_width(PyObject *self, PyObject *args)
  200. {
  201. int ret = caca_get_width();
  202. return Py_BuildValue("i", ret);
  203. }
  204. static PyObject *
  205. pycaca_get_height(PyObject *self, PyObject *args)
  206. {
  207. int ret = caca_get_height();
  208. return Py_BuildValue("i", ret);
  209. }
  210. static PyObject *
  211. pycaca_set_size(PyObject *self, PyObject *args)
  212. {
  213. int width, height;
  214. if (!PyArg_ParseTuple(args, "ii", &width, &height))
  215. caca_set_size(width, height);
  216. return Py_BuildValue("i", 1); /* FIXME */
  217. }
  218. static PyObject *
  219. pycaca_set_width(PyObject *self, PyObject *args)
  220. {
  221. int width;
  222. if (!PyArg_ParseTuple(args, "i", &width));
  223. caca_set_width(width);
  224. return Py_BuildValue("i", 1); /* FIXME */
  225. }
  226. static PyObject *
  227. pycaca_set_height(PyObject *self, PyObject *args)
  228. {
  229. int height;
  230. if (!PyArg_ParseTuple(args, "i", &height));
  231. caca_set_height(height);
  232. return Py_BuildValue("i", 1); /* FIXME */
  233. }
  234. static PyObject *
  235. pycaca_set_window_title(PyObject *self, PyObject *args)
  236. {
  237. int ret;
  238. const char *str;
  239. if (!PyArg_ParseTuple(args, "s", &str));
  240. ret = caca_set_window_title(str);
  241. return Py_BuildValue("i", ret); /* FIXME */
  242. }
  243. static PyObject *
  244. pycaca_get_window_width(PyObject *self, PyObject *args)
  245. {
  246. int ret = caca_get_window_width();
  247. return Py_BuildValue("i", ret);
  248. }
  249. static PyObject *
  250. pycaca_get_window_height(PyObject *self, PyObject *args)
  251. {
  252. int ret = caca_get_window_height();
  253. return Py_BuildValue("i", ret);
  254. }
  255. static PyObject *
  256. pycaca_refresh(PyObject *self, PyObject *args)
  257. {
  258. caca_refresh();
  259. return Py_BuildValue("i", 1); /*FIXME*/
  260. }
  261. static PyObject *
  262. pycaca_end(PyObject *self, PyObject *args)
  263. {
  264. caca_end();
  265. return Py_BuildValue("i", 1); /*FIXME*/
  266. }
  267. static PyObject *
  268. pycaca_get_feature(PyObject *self, PyObject *args)
  269. {
  270. int value, ret;
  271. if (!PyArg_ParseTuple(args, "i", &value));
  272. ret = caca_get_feature(value);
  273. return Py_BuildValue("i", ret);
  274. }
  275. static PyObject *
  276. pycaca_set_feature(PyObject *self, PyObject *args)
  277. {
  278. int value;
  279. if (!PyArg_ParseTuple(args, "i", &value));
  280. caca_set_feature(value);
  281. return Py_BuildValue("i", 1); /* FIXME */
  282. }
  283. static PyObject *
  284. pycaca_get_feature_name(PyObject *self, PyObject *args)
  285. {
  286. int value;
  287. char* ret;
  288. if (!PyArg_ParseTuple(args, "i", &value));
  289. ret = (char* const)caca_get_feature_name(value);
  290. return Py_BuildValue("s", ret);
  291. }
  292. /******************/
  293. /* Event handling */
  294. /******************/
  295. static PyObject *
  296. pycaca_get_event(PyObject *self, PyObject *args)
  297. {
  298. int value, ret;
  299. if (!PyArg_ParseTuple(args, "i", &value));
  300. ret = caca_get_event(value);
  301. return Py_BuildValue("i", ret);
  302. }
  303. static PyObject *
  304. pycaca_wait_event(PyObject *self, PyObject *args)
  305. {
  306. int value, ret;
  307. if (!PyArg_ParseTuple(args, "i", &value));
  308. ret = caca_get_event(value);
  309. return Py_BuildValue("i", ret);
  310. }
  311. static PyObject *
  312. pycaca_get_mouse_x(PyObject *self, PyObject *args)
  313. {
  314. int ret = caca_get_mouse_x();
  315. return Py_BuildValue("i", ret);
  316. }
  317. static PyObject *
  318. pycaca_get_mouse_y(PyObject *self, PyObject *args)
  319. {
  320. int ret = caca_get_mouse_y();
  321. return Py_BuildValue("i", ret);
  322. }
  323. /**********************/
  324. /* Primitives drawing */
  325. /**********************/
  326. static PyObject *
  327. pycaca_draw_line(PyObject *self, PyObject *args)
  328. {
  329. int x1, y1, x2, y2;
  330. char c;
  331. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c));
  332. caca_draw_line(x1,y1,x2,y2,c);
  333. return Py_BuildValue("i", 1); /* FIXME */
  334. }
  335. static PyObject *
  336. pycaca_draw_polyline(PyObject *self, PyObject *args)
  337. {
  338. PyObject *list_x, *list_y, *item;
  339. int *x, *y, n, lenx, leny, i;
  340. char c;
  341. if (!PyArg_ParseTuple(args, "OOic", &list_x, &list_y, &n, &c));
  342. lenx = PySequence_Length(list_x);
  343. leny = PySequence_Length(list_y);
  344. x = (int*) malloc(lenx*sizeof(int));
  345. y = (int*) malloc(leny*sizeof(int));
  346. if((x == NULL) || (y==NULL))
  347. return NULL; /* FIXME */
  348. for(i=0;i<lenx;i++)
  349. {
  350. item = PySequence_GetItem(list_x, i);
  351. x[i] = PyInt_AsLong(item);
  352. }
  353. for(i=0;i<leny;i++)
  354. {
  355. item = PySequence_GetItem(list_y, i);
  356. y[i] = PyInt_AsLong(item);
  357. }
  358. caca_draw_polyline(x,y,n,c);
  359. free(x); free(y);
  360. return Py_BuildValue("i", 1); /* FIXME */
  361. }
  362. static PyObject *
  363. pycaca_draw_thin_line(PyObject *self, PyObject *args)
  364. {
  365. int x1, y1, x2, y2;
  366. if (!PyArg_ParseTuple(args, "iiii", &x1,&y1,&x2,&y2));
  367. caca_draw_thin_line(x1,y1,x2,y2);
  368. return Py_BuildValue("i", 1); /* FIXME */
  369. }
  370. static PyObject *
  371. pycaca_draw_thin_polyline(PyObject *self, PyObject *args)
  372. {
  373. PyObject *list_x, *list_y, *item;
  374. int *x, *y, n, lenx, leny, i;
  375. if (!PyArg_ParseTuple(args, "OOi", &list_x, &list_y, &n));
  376. lenx = PySequence_Length(list_x);
  377. leny = PySequence_Length(list_y);
  378. x = (int*) malloc(lenx*sizeof(int));
  379. y = (int*) malloc(leny*sizeof(int));
  380. if((x == NULL) || (y==NULL))
  381. return NULL; /* FIXME */
  382. for(i=0;i<lenx;i++)
  383. {
  384. item = PySequence_GetItem(list_x, i);
  385. x[i] = PyInt_AsLong(item);
  386. }
  387. for(i=0;i<leny;i++)
  388. {
  389. item = PySequence_GetItem(list_y, i);
  390. y[i] = PyInt_AsLong(item);
  391. }
  392. caca_draw_thin_polyline(x,y,n);
  393. free(x); free(y);
  394. return Py_BuildValue("i", 1); /* FIXME */
  395. }
  396. static PyObject *
  397. pycaca_draw_circle(PyObject *self, PyObject *args)
  398. {
  399. int x1, y1, x2;
  400. char c;
  401. if (!PyArg_ParseTuple(args, "iiic", &x1,&y1,&x2,&c));
  402. caca_draw_circle(x1,y1,x2,c);
  403. return Py_BuildValue("i", 1); /* FIXME */
  404. }
  405. static PyObject *
  406. pycaca_draw_ellipse(PyObject *self, PyObject *args)
  407. {
  408. int x1, y1, x2,y2;
  409. char c;
  410. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c));
  411. caca_draw_ellipse(x1,y1,x2,y2,c);
  412. return Py_BuildValue("i", 1); /* FIXME */
  413. }
  414. static PyObject *
  415. pycaca_draw_thin_ellipse(PyObject *self, PyObject *args)
  416. {
  417. int x1, y1, x2,y2;
  418. if (!PyArg_ParseTuple(args, "iiii", &x1,&y1,&x2,&y2));
  419. caca_draw_thin_ellipse(x1,y1,x2,y2);
  420. return Py_BuildValue("i", 1); /* FIXME */
  421. }
  422. static PyObject *
  423. pycaca_fill_ellipse(PyObject *self, PyObject *args)
  424. {
  425. int x1, y1, x2,y2;
  426. char c;
  427. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c));
  428. caca_fill_ellipse(x1,y1,x2,y2,c);
  429. return Py_BuildValue("i", 1); /* FIXME */
  430. }
  431. static PyObject *
  432. pycaca_draw_box(PyObject *self, PyObject *args)
  433. {
  434. int x1, y1, x2,y2;
  435. char c;
  436. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c));
  437. caca_draw_box(x1,y1,x2,y2,c);
  438. return Py_BuildValue("i", 1); /* FIXME */
  439. }
  440. static PyObject *
  441. pycaca_fill_box(PyObject *self, PyObject *args)
  442. {
  443. int x1, y1, x2,y2;
  444. char c;
  445. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2,&c));
  446. caca_fill_box(x1,y1,x2,y2,c);
  447. return Py_BuildValue("i", 1); /* FIXME */
  448. }
  449. static PyObject *
  450. pycaca_draw_thin_box(PyObject *self, PyObject *args)
  451. {
  452. int x1, y1, x2,y2;
  453. if (!PyArg_ParseTuple(args, "iiiic", &x1,&y1,&x2,&y2));
  454. caca_draw_thin_box(x1,y1,x2,y2);
  455. return Py_BuildValue("i", 1); /* FIXME */
  456. }
  457. static PyObject *
  458. pycaca_draw_triangle(PyObject *self, PyObject *args)
  459. {
  460. int x1, y1, x2,y2, x3, y3;
  461. char c;
  462. if (!PyArg_ParseTuple(args, "iiiiiic", &x1,&y1,&x2,&y2,&x3,&y3,&c));
  463. caca_draw_triangle(x1,y1,x2,y2,x3,y3,c);
  464. return Py_BuildValue("i", 1); /* FIXME */
  465. }
  466. static PyObject *
  467. pycaca_draw_thin_triangle(PyObject *self, PyObject *args)
  468. {
  469. int x1, y1, x2,y2, x3, y3;
  470. if (!PyArg_ParseTuple(args, "iiiiii", &x1,&y1,&x2,&y2,&x3,&y3));
  471. caca_draw_thin_triangle(x1,y1,x2,y2,x3,y3);
  472. return Py_BuildValue("i", 1); /* FIXME */
  473. }
  474. static PyObject *
  475. pycaca_fill_triangle(PyObject *self, PyObject *args)
  476. {
  477. int x1, y1, x2,y2, x3, y3;
  478. char c;
  479. if (!PyArg_ParseTuple(args, "iiiiiic", &x1,&y1,&x2,&y2,&x3,&y3,&c));
  480. caca_fill_triangle(x1,y1,x2,y2,x3,y3,c);
  481. return Py_BuildValue("i", 1); /* FIXME */
  482. }
  483. /**********************/
  484. /* Character printing */
  485. /**********************/
  486. static PyObject *
  487. pycaca_set_color(PyObject *self, PyObject *args)
  488. {
  489. int c1,c2;
  490. if (!PyArg_ParseTuple(args, "ii", &c1,&c2));
  491. caca_set_color(c1,c2);
  492. return Py_BuildValue("i", 1); /* FIXME */
  493. }
  494. static PyObject *
  495. pycaca_get_fg_color(PyObject *self, PyObject *args)
  496. {
  497. int ret = caca_get_fg_color();
  498. return Py_BuildValue("i", ret);
  499. }
  500. static PyObject *
  501. pycaca_get_bg_color(PyObject *self, PyObject *args)
  502. {
  503. int ret = caca_get_bg_color();
  504. return Py_BuildValue("i", ret);
  505. }
  506. static PyObject *
  507. pycaca_get_color_name(PyObject *self, PyObject *args)
  508. {
  509. int c;
  510. char *ret;
  511. if (!PyArg_ParseTuple(args, "i", &c));
  512. ret = (char *)caca_get_color_name(c);
  513. return Py_BuildValue("s", ret); /* FIXME */
  514. }
  515. static PyObject *
  516. pycaca_putchar(PyObject *self, PyObject *args)
  517. {
  518. int x,y;
  519. char c;
  520. if (!PyArg_ParseTuple(args, "iic", &x,&y,&c));
  521. caca_putchar(x,y,c);
  522. return Py_BuildValue("i", 1); /* FIXME */
  523. }
  524. static PyObject *
  525. pycaca_putstr(PyObject *self, PyObject *args)
  526. {
  527. int x,y;
  528. char *c;
  529. if (!PyArg_ParseTuple(args, "iis", &x,&y,&c));
  530. caca_putstr(x,y,c);
  531. return Py_BuildValue("i", 1); /* FIXME */
  532. }
  533. static PyObject *
  534. pycaca_printf(PyObject *self, PyObject *args)
  535. {
  536. int x,y;
  537. char *c;
  538. if (!PyArg_ParseTuple(args, "iic", &x,&y,&c));
  539. caca_putstr(x,y,(char const*)c);
  540. return Py_BuildValue("i", 1); /* FIXME */
  541. }
  542. /*static PyObject *
  543. caca_get_screen(PyObject *self, PyObject *args);*/
  544. static PyObject *
  545. pycaca_clear(PyObject *self, PyObject *args)
  546. {
  547. caca_clear();
  548. return Py_BuildValue("i", 1); /* FIXME */
  549. }
  550. /********************/
  551. /* Sprite functions */
  552. /********************/
  553. static PyObject *
  554. pycaca_load_sprite(PyObject *self, PyObject *args)
  555. {
  556. char *filename;
  557. struct caca_sprite *ret;
  558. /*Quick and dirty hack. Gruik.*/
  559. if (!PyArg_ParseTuple(args, "s", &filename));
  560. ret = (struct caca_sprite*) caca_load_sprite(filename);
  561. return Py_BuildValue("i", PyCObject_FromVoidPtr(ret, NULL));
  562. }
  563. static PyObject *
  564. pycaca_draw_sprite(PyObject *self, PyObject *args)
  565. {
  566. int x, y, sprite, frame;
  567. if (!PyArg_ParseTuple(args, "iiii", &x, &y, &sprite,&frame));
  568. caca_draw_sprite(x,y, (struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite), frame);
  569. return Py_BuildValue("i", 1); /* FIXME */
  570. }
  571. static PyObject *
  572. pycaca_get_sprite_frames(PyObject *self, PyObject *args)
  573. {
  574. int sprite, ret;
  575. if (!PyArg_ParseTuple(args, "i", &sprite));
  576. ret = caca_get_sprite_frames((struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite));
  577. return Py_BuildValue("i", ret);
  578. }
  579. static PyObject *
  580. pycaca_get_sprite_width(PyObject *self, PyObject *args)
  581. {
  582. int sprite, ret, i;
  583. if (!PyArg_ParseTuple(args, "ii", &sprite, &i));
  584. ret = caca_get_sprite_width((struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite),i);
  585. return Py_BuildValue("i", ret);
  586. }
  587. static PyObject *
  588. pycaca_get_sprite_height(PyObject *self, PyObject *args)
  589. {
  590. int sprite, ret, i;
  591. if (!PyArg_ParseTuple(args, "ii", &sprite, i));
  592. ret = caca_get_sprite_height((struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite),i);
  593. return Py_BuildValue("i", ret);
  594. }
  595. static PyObject *
  596. pycaca_get_sprite_dx(PyObject *self, PyObject *args)
  597. {
  598. int sprite, ret, i;
  599. if (!PyArg_ParseTuple(args, "ii", &sprite), &i);
  600. ret = caca_get_sprite_dx((struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite),i);
  601. return Py_BuildValue("i", ret);
  602. }
  603. static PyObject *
  604. pycaca_get_sprite_dy(PyObject *self, PyObject *args)
  605. {
  606. int sprite, ret, i;
  607. if (!PyArg_ParseTuple(args, "ii", &sprite), &i);
  608. ret = caca_get_sprite_dy((struct caca_sprite const *)PyCObject_AsVoidPtr((void*)sprite),i);
  609. return Py_BuildValue("i", ret);
  610. }
  611. static PyObject *
  612. pycaca_free_sprite(PyObject *self, PyObject *args)
  613. {
  614. int sprite;
  615. if (!PyArg_ParseTuple(args, "i", &sprite));
  616. caca_free_sprite((struct caca_sprite *)PyCObject_AsVoidPtr((void*)sprite));
  617. return Py_BuildValue("i", 1); /* FIXME */
  618. }
  619. /*************/
  620. /* Exporters */
  621. /*************/
  622. static PyObject *
  623. pycaca_get_html(PyObject *self, PyObject *args)
  624. {
  625. if (!PyArg_ParseTuple(args, ""));
  626. return Py_BuildValue("s",caca_get_html());
  627. }
  628. static PyObject *
  629. pycaca_get_html3(PyObject *self, PyObject *args)
  630. {
  631. if (!PyArg_ParseTuple(args, ""));
  632. return Py_BuildValue("s",caca_get_html3());
  633. }
  634. static PyObject *
  635. pycaca_get_irc(PyObject *self, PyObject *args)
  636. {
  637. if (!PyArg_ParseTuple(args, ""));
  638. return Py_BuildValue("s",caca_get_irc());
  639. }
  640. static PyObject *
  641. pycaca_get_ansi(PyObject *self, PyObject *args)
  642. {
  643. int trailing;
  644. if (!PyArg_ParseTuple(args, "i", &trailing));
  645. return Py_BuildValue("s",caca_get_ansi(trailing));
  646. }
  647. /**********/
  648. /* Bitmap */
  649. /**********/
  650. static PyObject *
  651. pycaca_create_bitmap(PyObject *self, PyObject *args)
  652. {
  653. int a,b,c,d,e,f,g,h;
  654. struct caca_bitmap *ret;
  655. if (!PyArg_ParseTuple(args, "iiiiiiii", &a,&b,&c,&d,&e,&f,&g,&h));
  656. ret = (struct caca_bitmap*) caca_create_bitmap(a,b,c,d,e,f,g,h);
  657. return Py_BuildValue("i", PyCObject_FromVoidPtr(ret, NULL));
  658. }
  659. static PyObject *
  660. pycaca_set_bitmap_palette(PyObject *self, PyObject *args)
  661. {
  662. int bitmap;
  663. PyObject *list_r, *list_g, *list_b, *list_a, *item;
  664. unsigned int *r,*g,*b,*a,i;
  665. if (!PyArg_ParseTuple(args, "iOOOO", &bitmap, &list_r, &list_g, &list_b, &list_a));
  666. if((PySequence_Length(list_r)!=256) ||
  667. (PySequence_Length(list_g)!=256) ||
  668. (PySequence_Length(list_b)!=256) ||
  669. (PySequence_Length(list_a)!=256))
  670. {
  671. PyErr_SetString(PyExc_TypeError, "Lengths of colors lists must be 256");
  672. }
  673. r = malloc(256*sizeof(unsigned int));
  674. g = malloc(256*sizeof(unsigned int));
  675. b = malloc(256*sizeof(unsigned int));
  676. a = malloc(256*sizeof(unsigned int));
  677. for(i=0;i<256;i++)
  678. {
  679. item = PySequence_GetItem(list_r, i);
  680. r[i] = PyInt_AsLong(item);
  681. item = PySequence_GetItem(list_g, i);
  682. g[i] = PyInt_AsLong(item);
  683. item = PySequence_GetItem(list_b, i);
  684. b[i] = PyInt_AsLong(item);
  685. item = PySequence_GetItem(list_a, i);
  686. a[i] = PyInt_AsLong(item);
  687. }
  688. caca_set_bitmap_palette((struct caca_bitmap *)PyCObject_AsVoidPtr((void*)bitmap), r,g,b,a);
  689. return Py_BuildValue("i", 1); /* FIXME */
  690. }
  691. static PyObject *
  692. pycaca_set_bitmap_gamma(PyObject *self, PyObject *args)
  693. {
  694. int bitmap;
  695. float value;
  696. if (!PyArg_ParseTuple(args, "if", &bitmap, &value));
  697. caca_set_bitmap_gamma((struct caca_bitmap *)PyCObject_AsVoidPtr((void*)bitmap),value);
  698. return Py_BuildValue("i", 1); /* FIXME */
  699. }
  700. static PyObject *
  701. pycaca_draw_bitmap(PyObject *self, PyObject *args)
  702. {
  703. PyObject *pixels, *item;
  704. int bitmap, x1,x2,y1,y2;
  705. unsigned char *buffer;
  706. int i;
  707. if (!PyArg_ParseTuple(args, "iiiiiO", &x1,&y1,&x2,&y2,&bitmap,&pixels));
  708. buffer = malloc(PySequence_Length(pixels)*sizeof(unsigned char));
  709. for(i=0;i<PySequence_Length(pixels);i++)
  710. {
  711. item = PySequence_GetItem(pixels, i);
  712. buffer[i] = (unsigned char)PyInt_AsLong(item);
  713. }
  714. caca_draw_bitmap(x1,y1,x2,y2, (struct caca_bitmap *)PyCObject_AsVoidPtr((void*)bitmap), (void*)buffer);
  715. free(buffer);
  716. return Py_BuildValue("i", 1); /* FIXME */
  717. }
  718. static PyObject *
  719. pycaca_free_bitmap(PyObject *self, PyObject *args)
  720. {
  721. int bitmap;
  722. if (!PyArg_ParseTuple(args, "i", &bitmap));
  723. caca_free_bitmap((struct caca_bitmap *)PyCObject_AsVoidPtr((void*)bitmap));
  724. return Py_BuildValue("i", 1); /* FIXME */
  725. }
  726. /*
  727. void caca_draw_bitmap(int, int, int, int, struct caca_bitmap const *, void *);
  728. */