summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDana Jansens <danakj@orodu.net>2002-12-20 23:26:51 +0000
committerDana Jansens <danakj@orodu.net>2002-12-20 23:26:51 +0000
commit8d3d9ae75c3b023288af18492713b00ca8244fe1 (patch)
treecc95aa85896b355bedf987da2e9ffe562e9ddd42
parente5c5b4bf700f9bf00dd88bd4b6a471ac1ccefaff (diff)
add rect
-rw-r--r--otk_c/Makefile4
-rw-r--r--otk_c/rect.c94
-rw-r--r--otk_c/rect.h8
3 files changed, 104 insertions, 2 deletions
diff --git a/otk_c/Makefile b/otk_c/Makefile
index 28c1488a..9a93825d 100644
--- a/otk_c/Makefile
+++ b/otk_c/Makefile
@@ -3,8 +3,8 @@ exec_prefix=$(prefix)
libdir=$(exec_prefix)/lib
targets = libotk.so libotk.a
-sources = display.c screeninfo.c
-headers = display.h screeninfo.h
+sources = display.c screeninfo.c rect.c
+headers = display.h screeninfo.h rect.h
CFLAGS+=-I/usr/gwar/include/python2.2
diff --git a/otk_c/rect.c b/otk_c/rect.c
new file mode 100644
index 00000000..14b5fc56
--- /dev/null
+++ b/otk_c/rect.c
@@ -0,0 +1,94 @@
+// -*- mode: C; indent-tabs-mode: nil; -*-
+
+#include "../config.h"
+#include "rect.h"
+
+extern PyTypeObject OtkRect_Type;
+
+PyObject *OtkRect_New(int x, int y, int width, int height)
+{
+ OtkRect* self;
+
+ self = PyObject_New(OtkRect, &OtkRect_Type);
+
+ self->x = x;
+ self->y = y;
+ self->width = width;
+ self->height = height;
+
+ return (PyObject*)self;
+}
+
+
+
+static PyObject *otkrect_getx(OtkRect* self, PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, ":getX"))
+ return NULL;
+ return PyInt_FromLong(self->x);
+}
+
+static PyObject *otkrect_gety(OtkRect* self, PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, ":getY"))
+ return NULL;
+ return PyInt_FromLong(self->y);
+}
+
+static PyObject *otkrect_getwidth(OtkRect* self, PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, ":getWidth"))
+ return NULL;
+ return PyInt_FromLong(self->width);
+}
+
+static PyObject *otkrect_getheight(OtkRect* self, PyObject* args)
+{
+ if (!PyArg_ParseTuple(args, ":getHeight"))
+ return NULL;
+ return PyInt_FromLong(self->height);
+}
+
+
+static PyMethodDef get_methods[] = {
+ {"getX", (PyCFunction)otkrect_getx, METH_VARARGS,
+ "Get the X coordinate."},
+ {"getY", (PyCFunction)otkrect_gety, METH_VARARGS,
+ "Get the Y coordinate."},
+ {"getWidth", (PyCFunction)otkrect_getwidth, METH_VARARGS,
+ "Get the width."},
+ {"getHeight", (PyCFunction)otkrect_getheight, METH_VARARGS,
+ "Get the height."},
+ {NULL, NULL, 0, NULL}
+};
+
+
+
+static void otkrect_dealloc(PyObject* self)
+{
+ PyObject_Del(self);
+}
+
+static PyObject *otkrect_getattr(PyObject *obj, char *name)
+{
+ return Py_FindMethod(get_methods, obj, name);
+}
+
+
+PyTypeObject OtkRect_Type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "OtkRect",
+ sizeof(OtkRect),
+ 0,
+ otkrect_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ otkrect_getattr, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+};
diff --git a/otk_c/rect.h b/otk_c/rect.h
index 4d08828c..50547b57 100644
--- a/otk_c/rect.h
+++ b/otk_c/rect.h
@@ -1,5 +1,13 @@
+// -*- mode: C; indent-tabs-mode: nil; -*-
+#ifndef __rect_h
+#define __rect_h
+
+#include <Python.h>
+
typedef struct {
int x, y, width, height;
} OtkRect;
PyObject *OtkRect_New(int x, int y, int width, int height);
+
+#endif // __rect_h