Code

Split SPCanvasItem and SPCanvasGroup to individual .h files. Removed forward header.
[inkscape.git] / src / display / sp-canvas-util.cpp
1 #define __SP_CANVAS_UTILS_C__
3 /*
4  * Helper stuff for SPCanvas
5  *
6  * Authors:
7  *   Lauris Kaplinski <lauris@kaplinski.com>
8  *
9  * Copyright (C) 1999-2002 authors
10  * Copyright (C) 2001-2002 Ximian, Inc.
11  *
12  * Released under GNU GPL, read the file 'COPYING' for more information
13  */
16 #include <string.h>  // for memset
17 #include <2geom/matrix.h>
18 #include "libnr/nr-pixops.h"
19 #include "sp-canvas-item.h"
20 #include "sp-canvas-util.h"
23 void
24 sp_canvas_update_bbox (SPCanvasItem *item, int x1, int y1, int x2, int y2)
25 {
26     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
27     item->x1 = x1;
28     item->y1 = y1;
29     item->x2 = x2;
30     item->y2 = y2;
31     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
32 }
34 void
35 sp_canvas_item_reset_bounds (SPCanvasItem *item)
36 {
37     item->x1 = 0.0;
38     item->y1 = 0.0;
39     item->x2 = 0.0;
40     item->y2 = 0.0;
41 }
43 void
44 sp_canvas_prepare_buffer (SPCanvasBuf *buf)
45 {
46     if (buf->is_empty) {
47         sp_canvas_clear_buffer(buf);
48         buf->is_empty = false;
49     }
50 }
52 void
53 sp_canvas_clear_buffer (SPCanvasBuf *buf)
54 {
55     unsigned char r, g, b;
57     r = (buf->bg_color >> 16) & 0xff;
58     g = (buf->bg_color >> 8) & 0xff;
59     b = buf->bg_color & 0xff;
61     if ((r != g) || (r != b)) {
62         int x, y;
63         for (y = buf->rect.y0; y < buf->rect.y1; y++) {
64             unsigned char *p;
65             p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride;
66             for (x = buf->rect.x0; x < buf->rect.x1; x++) {
67                 *p++ = r;
68                 *p++ = g;
69                 *p++ = b;
70             }
71         }
72     } else {
73         int y;
74         for (y = buf->rect.y0; y < buf->rect.y1; y++) {
75             memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 4 * (buf->rect.x1 - buf->rect.x0)); 
76         }
77     }
78 }
80 Geom::Matrix sp_canvas_item_i2p_affine (SPCanvasItem * item)
81 {
82     g_assert (item != NULL); /* this may be overly zealous - it is
83                               * plausible that this gets called
84                               * with item == 0. */
86     return item->xform;
87 }
89 Geom::Matrix  sp_canvas_item_i2i_affine (SPCanvasItem * from, SPCanvasItem * to)
90 {
91     g_assert (from != NULL);
92     g_assert (to != NULL);
94     return sp_canvas_item_i2w_affine(from) * sp_canvas_item_i2w_affine(to).inverse();
95 }
97 void sp_canvas_item_set_i2w_affine (SPCanvasItem * item,  Geom::Matrix const &i2w)
98 {
99     g_assert (item != NULL);
101     sp_canvas_item_affine_absolute(item, i2w * sp_canvas_item_i2w_affine(item->parent).inverse());
104 void sp_canvas_item_move_to_z (SPCanvasItem * item, gint z)
106     g_assert (item != NULL);
108     gint current_z = sp_canvas_item_order (item);
110     if (current_z == -1) // not found in its parent
111         return;
113     if (z == current_z)
114         return;
116     if (z > current_z) {
117         sp_canvas_item_raise (item, z - current_z);
118     } else {
119         sp_canvas_item_lower (item, current_z - z);
120     }
123 gint
124 sp_canvas_item_compare_z (SPCanvasItem * a, SPCanvasItem * b)
126     gint const o_a = sp_canvas_item_order (a);
127     gint const o_b = sp_canvas_item_order (b);
129     if (o_a > o_b) return -1;
130     if (o_a < o_b) return 1;
132     return 0;
135 /*
136   Local Variables:
137   mode:c++
138   c-file-style:"stroustrup"
139   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
140   indent-tabs-mode:nil
141   fill-column:99
142   End:
143 */
144 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :