You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

862 lines
23 KiB

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