Code

Added missing translation.
[inkscape.git] / src / sp-paint-server.cpp
1 #define __SP_PAINT_SERVER_C__
3 /*
4  * Base class for gradients and patterns
5  *
6  * Author:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 1999-2002 Lauris Kaplinski
10  * Copyright (C) 2000-2001 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
15 #include <libnr/nr-pixblock-pattern.h>
16 #include "sp-paint-server.h"
18 static void sp_paint_server_class_init(SPPaintServerClass *psc);
19 static void sp_paint_server_init(SPPaintServer *ps);
21 static void sp_paint_server_release(SPObject *object);
23 static void sp_painter_stale_fill(SPPainter *painter, NRPixBlock *pb);
25 static SPObjectClass *parent_class;
26 static GSList *stale_painters = NULL;
28 GType sp_paint_server_get_type (void)
29 {
30     static GType type = 0;
31     if (!type) {
32         GTypeInfo info = {
33             sizeof(SPPaintServerClass),
34             NULL,       /* base_init */
35             NULL,       /* base_finalize */
36             (GClassInitFunc) sp_paint_server_class_init,
37             NULL,       /* class_finalize */
38             NULL,       /* class_data */
39             sizeof(SPPaintServer),
40             16, /* n_preallocs */
41             (GInstanceInitFunc) sp_paint_server_init,
42             NULL,       /* value_table */
43         };
44         type = g_type_register_static(SP_TYPE_OBJECT, "SPPaintServer", &info, (GTypeFlags) 0);
45     }
46     return type;
47 }
49 static void sp_paint_server_class_init(SPPaintServerClass *psc)
50 {
51     SPObjectClass *sp_object_class = (SPObjectClass *) psc;
52     sp_object_class->release = sp_paint_server_release;
53     parent_class = (SPObjectClass *) g_type_class_ref(SP_TYPE_OBJECT);
54 }
56 static void sp_paint_server_init(SPPaintServer *ps)
57 {
58     ps->painters = NULL;
59 }
61 static void sp_paint_server_release(SPObject *object)
62 {
63     SPPaintServer *ps = SP_PAINT_SERVER(object);
65     while (ps->painters) {
66         SPPainter *painter = ps->painters;
67         ps->painters = painter->next;
68         stale_painters = g_slist_prepend(stale_painters, painter);
69         painter->next = NULL;
70         painter->server = NULL;
71         painter->fill = sp_painter_stale_fill;
72     }
74     if (((SPObjectClass *) parent_class)->release) {
75         ((SPObjectClass *) parent_class)->release(object);
76     }
77 }
79 SPPainter *sp_paint_server_painter_new(SPPaintServer *ps,
80                                        Geom::Matrix const &full_transform,
81                                        Geom::Matrix const &parent_transform,
82                                        const NRRect *bbox)
83 {
84     g_return_val_if_fail(ps != NULL, NULL);
85     g_return_val_if_fail(SP_IS_PAINT_SERVER(ps), NULL);
86     g_return_val_if_fail(bbox != NULL, NULL);
88     SPPainter *painter = NULL;
89     SPPaintServerClass *psc = (SPPaintServerClass *) G_OBJECT_GET_CLASS(ps);
90     if ( psc->painter_new ) {
91         painter = (*psc->painter_new)(ps, full_transform, parent_transform, bbox);
92     }
94     if (painter) {
95         painter->next = ps->painters;
96         painter->server = ps;
97         painter->type = (SPPainterType) G_OBJECT_TYPE(ps);
98         ps->painters = painter;
99     }
101     return painter;
104 static void sp_paint_server_painter_free(SPPaintServer *ps, SPPainter *painter)
106     g_return_if_fail(ps != NULL);
107     g_return_if_fail(SP_IS_PAINT_SERVER(ps));
108     g_return_if_fail(painter != NULL);
110     SPPaintServerClass *psc = (SPPaintServerClass *) G_OBJECT_GET_CLASS(ps);
112     SPPainter *r = NULL;
113     for (SPPainter *p = ps->painters; p != NULL; p = p->next) {
114         if (p == painter) {
115             if (r) {
116                 r->next = p->next;
117             } else {
118                 ps->painters = p->next;
119             }
120             p->next = NULL;
121             if (psc->painter_free) {
122                 (*psc->painter_free) (ps, painter);
123             }
124             return;
125         }
126         r = p;
127     }
129     g_assert_not_reached();
132 SPPainter *sp_painter_free(SPPainter *painter)
134     g_return_val_if_fail(painter != NULL, NULL);
136     if (painter->server) {
137         sp_paint_server_painter_free(painter->server, painter);
138     } else {
139         SPPaintServerClass *psc = (SPPaintServerClass *) g_type_class_ref(painter->type);
140         if (psc->painter_free)
141             (*psc->painter_free)(NULL, painter);
142         stale_painters = g_slist_remove(stale_painters, painter);
143     }
145     return NULL;
148 static void sp_painter_stale_fill(SPPainter */*painter*/, NRPixBlock *pb)
150     nr_pixblock_render_gray_noise(pb, NULL);
154 /*
155   Local Variables:
156   mode:c++
157   c-file-style:"stroustrup"
158   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
159   indent-tabs-mode:nil
160   fill-column:99
161   End:
162 */
163 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :