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

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