source: libcaca/trunk/python/pypycaca.c @ 521

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