]> Dogcows Code - chaz/openbox/blob - otk_c/rect.c
add rect
[chaz/openbox] / otk_c / rect.c
1 // -*- mode: C; indent-tabs-mode: nil; -*-
2
3 #include "../config.h"
4 #include "rect.h"
5
6 extern PyTypeObject OtkRect_Type;
7
8 PyObject *OtkRect_New(int x, int y, int width, int height)
9 {
10 OtkRect* self;
11
12 self = PyObject_New(OtkRect, &OtkRect_Type);
13
14 self->x = x;
15 self->y = y;
16 self->width = width;
17 self->height = height;
18
19 return (PyObject*)self;
20 }
21
22
23
24 static PyObject *otkrect_getx(OtkRect* self, PyObject* args)
25 {
26 if (!PyArg_ParseTuple(args, ":getX"))
27 return NULL;
28 return PyInt_FromLong(self->x);
29 }
30
31 static PyObject *otkrect_gety(OtkRect* self, PyObject* args)
32 {
33 if (!PyArg_ParseTuple(args, ":getY"))
34 return NULL;
35 return PyInt_FromLong(self->y);
36 }
37
38 static PyObject *otkrect_getwidth(OtkRect* self, PyObject* args)
39 {
40 if (!PyArg_ParseTuple(args, ":getWidth"))
41 return NULL;
42 return PyInt_FromLong(self->width);
43 }
44
45 static PyObject *otkrect_getheight(OtkRect* self, PyObject* args)
46 {
47 if (!PyArg_ParseTuple(args, ":getHeight"))
48 return NULL;
49 return PyInt_FromLong(self->height);
50 }
51
52
53 static PyMethodDef get_methods[] = {
54 {"getX", (PyCFunction)otkrect_getx, METH_VARARGS,
55 "Get the X coordinate."},
56 {"getY", (PyCFunction)otkrect_gety, METH_VARARGS,
57 "Get the Y coordinate."},
58 {"getWidth", (PyCFunction)otkrect_getwidth, METH_VARARGS,
59 "Get the width."},
60 {"getHeight", (PyCFunction)otkrect_getheight, METH_VARARGS,
61 "Get the height."},
62 {NULL, NULL, 0, NULL}
63 };
64
65
66
67 static void otkrect_dealloc(PyObject* self)
68 {
69 PyObject_Del(self);
70 }
71
72 static PyObject *otkrect_getattr(PyObject *obj, char *name)
73 {
74 return Py_FindMethod(get_methods, obj, name);
75 }
76
77
78 PyTypeObject OtkRect_Type = {
79 PyObject_HEAD_INIT(NULL)
80 0,
81 "OtkRect",
82 sizeof(OtkRect),
83 0,
84 otkrect_dealloc, /*tp_dealloc*/
85 0, /*tp_print*/
86 otkrect_getattr, /*tp_getattr*/
87 0, /*tp_setattr*/
88 0, /*tp_compare*/
89 0, /*tp_repr*/
90 0, /*tp_as_number*/
91 0, /*tp_as_sequence*/
92 0, /*tp_as_mapping*/
93 0, /*tp_hash */
94 };
This page took 0.037497 seconds and 5 git commands to generate.