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

Last change on this file since 4333 was 4333, checked in by Sam Hocevar, 10 years ago

Large source code cleanup, getting rid of spaces, tabs, and svn keywords.

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