選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

pypycaca.c 23 KiB

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