Code

a06d930740e505846bba863d83e40e02c4834e70
[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 <2geom/matrix.h>
17 #include "libnr/nr-pixops.h"
18 #include "sp-canvas-util.h"
19 #include <string.h>  /* for memset */
22 void
23 sp_canvas_update_bbox (SPCanvasItem *item, int x1, int y1, int x2, int y2)
24 {
25     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
26     item->x1 = x1;
27     item->y1 = y1;
28     item->x2 = x2;
29     item->y2 = y2;
30     sp_canvas_request_redraw (item->canvas, (int)item->x1, (int)item->y1, (int)item->x2, (int)item->y2);
31 }
33 void
34 sp_canvas_item_reset_bounds (SPCanvasItem *item)
35 {
36     item->x1 = 0.0;
37     item->y1 = 0.0;
38     item->x2 = 0.0;
39     item->y2 = 0.0;
40 }
42 void
43 sp_canvas_prepare_buffer (SPCanvasBuf *buf)
44 {
45     if (buf->is_empty) {
46         sp_canvas_clear_buffer(buf);
47         buf->is_empty = false;
48     }
49 }
51 void
52 sp_canvas_clear_buffer (SPCanvasBuf *buf)
53 {
54     unsigned char r, g, b;
56     r = (buf->bg_color >> 16) & 0xff;
57     g = (buf->bg_color >> 8) & 0xff;
58     b = buf->bg_color & 0xff;
60     if ((r != g) || (r != b)) {
61         int x, y;
62         for (y = buf->rect.y0; y < buf->rect.y1; y++) {
63             unsigned char *p;
64             p = buf->buf + (y - buf->rect.y0) * buf->buf_rowstride;
65             for (x = buf->rect.x0; x < buf->rect.x1; x++) {
66                 *p++ = r;
67                 *p++ = g;
68                 *p++ = b;
69             }
70         }
71     } else {
72         int y;
73         for (y = buf->rect.y0; y < buf->rect.y1; y++) {
74             memset (buf->buf + (y - buf->rect.y0) * buf->buf_rowstride, r, 4 * (buf->rect.x1 - buf->rect.x0)); 
75         }
76     }
77 }
79 Geom::Matrix sp_canvas_item_i2p_affine (SPCanvasItem * item)
80 {
81     g_assert (item != NULL); /* this may be overly zealous - it is
82                               * plausible that this gets called
83                               * with item == 0. */
85     return item->xform;
86 }
88 Geom::Matrix  sp_canvas_item_i2i_affine (SPCanvasItem * from, SPCanvasItem * to)
89 {
90     g_assert (from != NULL);
91     g_assert (to != NULL);
93     return sp_canvas_item_i2w_affine(from) * sp_canvas_item_i2w_affine(to).inverse();
94 }
96 void sp_canvas_item_set_i2w_affine (SPCanvasItem * item,  Geom::Matrix const &i2w)
97 {
98     g_assert (item != NULL);
100     sp_canvas_item_affine_absolute(item, i2w * sp_canvas_item_i2w_affine(item->parent).inverse());
103 void sp_canvas_item_move_to_z (SPCanvasItem * item, gint z)
105     g_assert (item != NULL);
107     gint current_z = sp_canvas_item_order (item);
109     if (current_z == -1) // not found in its parent
110         return;
112     if (z == current_z)
113         return;
115     if (z > current_z) {
116         sp_canvas_item_raise (item, z - current_z);
117     } else {
118         sp_canvas_item_lower (item, current_z - z);
119     }
122 gint
123 sp_canvas_item_compare_z (SPCanvasItem * a, SPCanvasItem * b)
125     gint const o_a = sp_canvas_item_order (a);
126     gint const o_b = sp_canvas_item_order (b);
128     if (o_a > o_b) return -1;
129     if (o_a < o_b) return 1;
131     return 0;
134 /*
135   Local Variables:
136   mode:c++
137   c-file-style:"stroustrup"
138   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
139   indent-tabs-mode:nil
140   fill-column:99
141   End:
142 */
143 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :