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