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

Last change on this file since 3925 was 3582, checked in by Sam Hocevar, 11 years ago

Coding style: remove tabs and trailing spaces.

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