2019-12-07 21:18:27 -07:00
|
|
|
#define PY_SSIZE_T_CLEAN
|
|
|
|
#include <Python.h>
|
|
|
|
#include "scode.h"
|
|
|
|
#include "fbprimitive.h"
|
|
|
|
#include "ep_init.h"
|
2019-12-09 12:28:28 -07:00
|
|
|
#include "ep_util.h"
|
2019-12-07 21:18:27 -07:00
|
|
|
|
|
|
|
static PyObject *do_setpixel(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 x, y;
|
|
|
|
UINT16 color, oldcolor;
|
|
|
|
BOOL xor;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "iiHi", &x, &y, &color, &xor))
|
|
|
|
return NULL;
|
|
|
|
oldcolor = Fb_setpixel(x, y, color, xor);
|
|
|
|
return PyLong_FromLong((long)oldcolor);
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *do_line(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 x1, y1, x2, y2;
|
|
|
|
UINT16 color;
|
|
|
|
BOOL xor;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "iiiiHi", &x1, &y1, &x2, &y2, &color, &xor))
|
|
|
|
return NULL;
|
|
|
|
Fb_line(x1, y1, x2, y2, color, xor);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *do_rectangle(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 x1, y1, x2, y2;
|
|
|
|
UINT16 color;
|
|
|
|
BOOL xor;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "iiiiHi", &x1, &y1, &x2, &y2, &color, &xor))
|
|
|
|
return NULL;
|
|
|
|
Fb_rectangle(x1, y1, x2, y2, color, xor);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PyObject *do_filled_rectangle(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 x1, y1, x2, y2;
|
|
|
|
UINT16 color;
|
|
|
|
BOOL xor;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "iiiiHi", &x1, &y1, &x2, &y2, &color, &xor))
|
|
|
|
return NULL;
|
|
|
|
Fb_filled_rectangle(x1, y1, x2, y2, color, xor);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2019-12-07 23:30:05 -07:00
|
|
|
static PyObject *do_textout(PyObject *self, PyObject *args)
|
|
|
|
{
|
|
|
|
INT32 x, y;
|
|
|
|
PSTR text;
|
|
|
|
|
|
|
|
if (!PyArg_ParseTuple(args, "iis", &x, &y, &text))
|
|
|
|
return NULL;
|
|
|
|
Fb_textout(x, y, text);
|
|
|
|
Py_RETURN_NONE;
|
|
|
|
}
|
|
|
|
|
2019-12-07 21:18:27 -07:00
|
|
|
static PyMethodDef UPIWIN_tmpMethods[] = {
|
|
|
|
{"setpixel", do_setpixel, METH_VARARGS, "Set a single pixel on the display."},
|
|
|
|
{"line", do_line, METH_VARARGS, "Draw a line on the display."},
|
|
|
|
{"rectangle", do_rectangle, METH_VARARGS, "Draw a rectangle on the display."},
|
|
|
|
{"filled_rectangle", do_filled_rectangle, METH_VARARGS, "Draw a filled rectangle on the display."},
|
2019-12-07 23:30:05 -07:00
|
|
|
{"textout", do_textout, METH_VARARGS, "Draw text on the display."},
|
2019-12-07 21:18:27 -07:00
|
|
|
{NULL, NULL, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static PyModuleDef DefUPIWIN_tmp = {
|
|
|
|
PyModuleDef_HEAD_INIT, /* standard garbage */
|
|
|
|
MOD_NAME_UPIWIN_TMP, /* module name */
|
|
|
|
NULL, /* no doc string */
|
|
|
|
-1, /* no per-module memory */
|
|
|
|
UPIWIN_tmpMethods, /* method defs */
|
|
|
|
NULL, /* no slots for multi-phase init */
|
|
|
|
NULL, /* no traversal proc */
|
|
|
|
NULL, /* no clear function */
|
|
|
|
NULL /* no free function */
|
|
|
|
};
|
|
|
|
|
2019-12-09 12:28:28 -07:00
|
|
|
BEGIN_CONSTANT_TABLE(UPIWIN_tmpConstants)
|
|
|
|
/* primitive color values */
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_BLACK)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_RED)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_GREEN)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_BLUE)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_YELLOW)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_CYAN)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_MAGENTA)
|
|
|
|
CONSTANT_INT_MACRO(FBPRIMCLR_WHITE)
|
|
|
|
END_CONSTANT_TABLE
|
|
|
|
|
2019-12-07 21:18:27 -07:00
|
|
|
PyObject *Epython_init_upiwin_tmp_module(void)
|
|
|
|
{
|
|
|
|
PyObject *module;
|
|
|
|
|
2019-12-07 21:20:40 -07:00
|
|
|
module = PyModule_Create(&DefUPIWIN_tmp);
|
2019-12-09 12:28:28 -07:00
|
|
|
if (module)
|
|
|
|
{
|
|
|
|
if (FAILED(Epython_register_constants(module, UPIWIN_tmpConstants)))
|
|
|
|
{
|
|
|
|
Py_DECREF(module);
|
|
|
|
module = NULL;
|
|
|
|
}
|
|
|
|
}
|
2019-12-07 21:18:27 -07:00
|
|
|
return module;
|
|
|
|
}
|