Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

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