[cairo-commit] pycairo/cairo pycairo-pattern.c,1.9,1.10
Steve Chaplin
commit at pdx.freedesktop.org
Mon Apr 4 06:51:22 PDT 2005
Committed by: stevech1097
Update of /cvs/cairo/pycairo/cairo
In directory gabe:/tmp/cvs-serv8018/cairo
Modified Files:
pycairo-pattern.c
Log Message:
SC 2005/04/04
Index: pycairo-pattern.c
===================================================================
RCS file: /cvs/cairo/pycairo/cairo/pycairo-pattern.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- pycairo-pattern.c 10 Dec 2004 15:16:40 -0000 1.9
+++ pycairo-pattern.c 4 Apr 2005 13:51:18 -0000 1.10
@@ -65,60 +65,59 @@
PyObject_Del(self);
}
+/* pycairo_pattern_new()
+ * pycairo_pattern_init()
+ * not used, use alternative constructors instead
+ */
+
+/* alternative constructor */
static PyObject *
-pycairo_pattern_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+pycairo_pattern_create_for_surface(PyTypeObject *type, PyObject *args)
{
- PyCairoPattern *self = (PyCairoPattern *)type->tp_alloc(type, 0);
+ PyCairoSurface *py_surface;
+ PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
- if (self)
- self->pattern = NULL;
- return (PyObject *)self;
+ if (py_pattern) {
+ if (!PyArg_ParseTuple(args, "O!:Pattern.create_for_surface",
+ &PyCairoSurface_Type, &py_surface))
+ return NULL;
+ py_pattern->pattern =
+ cairo_pattern_create_for_surface (py_surface->surface);
+ }
+ return (PyObject *)py_pattern;
}
-static int
-pycairo_pattern_init(PyCairoPattern *self, PyObject *args, PyObject *kwargs)
+/* alternative constructor */
+static PyObject *
+pycairo_pattern_create_linear(PyTypeObject *type, PyObject *args)
{
- static char *kwlist[] = { "x0", "y0", "x1", "y1",
- "cx0", "cy0", "radius0", "cx1", "cy1", "radius1",
- "surface",
- NULL };
- double x0 = -1.0, y0 = -1.0, x1 = -1.0, y1 = -1.0;
- double cx0 =-1.0, cy0 =-1.0, radius0 =-1.0, cx1 =-1.0, cy1 =-1.0, radius1 =-1.0;
- PyCairoSurface *surface = NULL;
- cairo_pattern_t *pattern = NULL;
-
- if (!PyArg_ParseTupleAndKeywords(args, kwargs,
- "|ddddddddddO!:Pattern.__init__", kwlist,
- &x0, &y0, &x1, &y1,
- &cx0, &cy0, &radius0,
- &cx1, &cy1, &radius1,
- &PyCairoSurface_Type, &surface
- )) /* change to keywords only? */
- return -1;
-
- /* three alternative constructors */
- if (x0 != -1.0 && y0 != -1.0 && x1 != -1.0 && y1 != -1.0) {
- pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
-
- } else if (cx0 != -1.0 && cy0 != -1.0 && radius0 != -1.0 &&
- cx1 != -1.0 && cy1 != -1.0 && radius1 != -1.0) {
- pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
- cx1, cy1, radius1);
-
- } else if (surface != NULL) {
- pattern = cairo_pattern_create_for_surface (surface->surface);
+ double x0, y0, x1, y1;
+ PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
- } else {
- PyErr_SetString(PyExc_ValueError, "incorrect arguments for pattern");
- return -1;
+ if (py_pattern) {
+ if (!PyArg_ParseTuple(args, "dddd:Pattern.create_linear",
+ &x0, &y0, &x1, &y1))
+ return NULL;
+ py_pattern->pattern = cairo_pattern_create_linear (x0, y0, x1, y1);
}
+ return (PyObject *)py_pattern;
+}
- if (!pattern) {
- PyErr_SetString(PyExc_RuntimeError, "could not create pattern");
- return -1;
+/* alternative constructor */
+static PyObject *
+pycairo_pattern_create_radial(PyTypeObject *type, PyObject *args)
+{
+ double cx0, cy0, radius0, cx1, cy1, radius1;
+ PyCairoPattern *py_pattern = (PyCairoPattern *)type->tp_alloc(type, 0);
+
+ if (py_pattern) {
+ if (!PyArg_ParseTuple(args, "dddddd:Pattern.create_radial",
+ &cx0, &cy0, &radius0, &cx1, &cy1, &radius1))
+ return NULL;
+ py_pattern->pattern = cairo_pattern_create_radial (cx0, cy0, radius0,
+ cx1, cy1, radius1);
}
- self->pattern = pattern;
- return 0;
+ return (PyObject *)py_pattern;
}
static PyObject *
@@ -207,7 +206,13 @@
static PyMethodDef pycairo_pattern_methods[] = {
{ "add_color_stop", (PyCFunction)pycairo_pattern_add_color_stop,
- METH_VARARGS },
+ METH_VARARGS },
+ { "create_for_surface", (PyCFunction)pycairo_pattern_create_for_surface,
+ METH_VARARGS | METH_CLASS },
+ { "create_linear", (PyCFunction)pycairo_pattern_create_linear,
+ METH_VARARGS | METH_CLASS },
+ { "create_radial", (PyCFunction)pycairo_pattern_create_radial,
+ METH_VARARGS | METH_CLASS },
{ "set_extend", (PyCFunction)pycairo_pattern_set_extend, METH_VARARGS },
{ "set_filter", (PyCFunction)pycairo_pattern_set_filter, METH_VARARGS },
{ "set_matrix", (PyCFunction)pycairo_pattern_set_matrix, METH_VARARGS },
@@ -258,9 +263,9 @@
0, /* tp_descr_get */
0, /* tp_descr_set */
0, /* tp_dictoffset */
- (initproc)pycairo_pattern_init, /* tp_init */
+ (initproc)0, /* tp_init */
(allocfunc)0, /* tp_alloc */
- pycairo_pattern_new, /* tp_new */
+ 0, /* tp_new */
0, /* tp_free */
(inquiry)0, /* tp_is_gc */
(PyObject *)0, /* tp_bases */
More information about the cairo-commit
mailing list