25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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