Code

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