1 #ifndef __SP_CANVAS_H__
2 #define __SP_CANVAS_H__
4 /** \file
5 * SPCanvas, SPCanvasBuf, and SPCanvasItem.
6 *
7 * Authors:
8 * Federico Mena <federico@nuclecu.unam.mx>
9 * Raph Levien <raph@gimp.org>
10 * Lauris Kaplinski <lauris@kaplinski.com>
11 *
12 * Copyright (C) 1998 The Free Software Foundation
13 * Copyright (C) 2002 Lauris Kaplinski
14 *
15 * Released under GNU GPL, read the file 'COPYING' for more information
16 */
18 #ifdef HAVE_CONFIG_H
19 # include "config.h"
20 #endif
22 #ifdef HAVE_INTTYPES_H
23 # include <inttypes.h>
24 #else
25 # ifdef HAVE_STDINT_H
26 # include <stdint.h>
27 # endif
28 #endif
30 #include <glib/gtypes.h>
31 #include <gdk/gdkevents.h>
32 #include <gdk/gdkgc.h>
33 #include <gtk/gtkobject.h>
34 #include <gtk/gtkwidget.h>
36 #include <libnr/nr-matrix.h>
37 #include <libnr/nr-rect.h>
38 #include <libnr/nr-rect-l.h>
40 struct SPCanvas;
41 struct SPCanvasGroup;
43 enum {
44 SP_CANVAS_UPDATE_REQUESTED = 1 << 0,
45 SP_CANVAS_UPDATE_AFFINE = 1 << 1
46 };
48 /**
49 * The canvas buf contains the actual pixels.
50 */
51 struct SPCanvasBuf{
52 guchar *buf;
53 int buf_rowstride;
54 NRRectL rect;
55 NRRectL visible_rect;
56 /// Background color, given as 0xrrggbb
57 guint32 bg_color;
58 // If empty, ignore contents of buffer and use a solid area of bg_color
59 bool is_empty;
60 };
62 /**
63 * An SPCanvasItem refers to a SPCanvas and to its parent item; it has
64 * four coordinates, a bounding rectangle, and a transformation matrix.
65 */
66 struct SPCanvasItem : public GtkObject {
67 SPCanvas *canvas;
68 SPCanvasItem *parent;
70 double x1, y1, x2, y2;
71 NR::Rect bounds;
72 NR::Matrix xform;
73 };
75 /**
76 * The vtable of an SPCanvasItem.
77 */
78 struct SPCanvasItemClass : public GtkObjectClass {
79 void (* update) (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
81 void (* render) (SPCanvasItem *item, SPCanvasBuf *buf);
82 double (* point) (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
84 int (* event) (SPCanvasItem *item, GdkEvent *event);
85 };
87 SPCanvasItem *sp_canvas_item_new(SPCanvasGroup *parent, GtkType type, const gchar *first_arg_name, ...);
89 #define sp_canvas_item_set gtk_object_set
91 void sp_canvas_item_affine_absolute(SPCanvasItem *item, NR::Matrix const &aff);
93 void sp_canvas_item_raise(SPCanvasItem *item, int positions);
94 void sp_canvas_item_lower(SPCanvasItem *item, int positions);
95 void sp_canvas_item_show(SPCanvasItem *item);
96 void sp_canvas_item_hide(SPCanvasItem *item);
97 int sp_canvas_item_grab(SPCanvasItem *item, unsigned int event_mask, GdkCursor *cursor, guint32 etime);
98 void sp_canvas_item_ungrab(SPCanvasItem *item, guint32 etime);
100 NR::Matrix sp_canvas_item_i2w_affine(SPCanvasItem const *item);
102 void sp_canvas_item_grab_focus(SPCanvasItem *item);
104 void sp_canvas_item_request_update(SPCanvasItem *item);
106 /* get item z-order in parent group */
108 gint sp_canvas_item_order(SPCanvasItem * item);
111 // SPCanvas -------------------------------------------------
112 /**
113 * Port of GnomeCanvas for inkscape needs.
114 */
115 struct SPCanvas {
116 GtkWidget widget;
118 guint idle_id;
120 SPCanvasItem *root;
122 double dx0, dy0;
123 int x0, y0;
125 /* Area that needs redrawing, stored as a microtile array */
126 int tLeft,tTop,tRight,tBottom;
127 int tileH,tileV;
128 uint8_t *tiles;
130 /* Last known modifier state, for deferred repick when a button is down */
131 int state;
133 /* The item containing the mouse pointer, or NULL if none */
134 SPCanvasItem *current_item;
136 /* Item that is about to become current (used to track deletions and such) */
137 SPCanvasItem *new_current_item;
139 /* Item that holds a pointer grab, or NULL if none */
140 SPCanvasItem *grabbed_item;
142 /* Event mask specified when grabbing an item */
143 guint grabbed_event_mask;
145 /* If non-NULL, the currently focused item */
146 SPCanvasItem *focused_item;
148 /* Event on which selection of current item is based */
149 GdkEvent pick_event;
151 int close_enough;
153 /* GC for temporary draw pixmap */
154 GdkGC *pixmap_gc;
156 unsigned int need_update : 1;
157 unsigned int need_redraw : 1;
158 unsigned int need_repick : 1;
160 /* For use by internal pick_current_item() function */
161 unsigned int left_grabbed_item : 1;
162 /* For use by internal pick_current_item() function */
163 unsigned int in_repick : 1;
165 // In most tools Inkscape only generates enter and leave events
166 // on the current item, but no other enter events if a mouse button
167 // is depressed -- see function pick_current_item(). Some tools
168 // may wish the canvas to generate to all enter events, (e.g., the
169 // connector tool). If so, they may temporarily set this flag to
170 // 'true'.
171 bool gen_all_enter_events;
173 int rendermode;
175 NR::Rect getViewbox() const;
176 };
178 GtkWidget *sp_canvas_new_aa();
180 SPCanvasGroup *sp_canvas_root(SPCanvas *canvas);
182 void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int clear);
183 void sp_canvas_update_now(SPCanvas *canvas);
185 void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2);
187 void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy);
188 void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy);
190 NR::Point sp_canvas_window_to_world(SPCanvas const *canvas, NR::Point const win);
191 NR::Point sp_canvas_world_to_window(SPCanvas const *canvas, NR::Point const world);
193 bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, NR::Point const &world);
195 #endif
197 /*
198 Local Variables:
199 mode:c++
200 c-file-style:"stroustrup"
201 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
202 indent-tabs-mode:nil
203 fill-column:99
204 End:
205 */
206 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :