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 /// Background color, given as 0xrrggbb
56 guint32 bg_color;
57 // If empty, ignore contents of buffer and use a solid area of bg_color
58 bool is_empty;
59 };
61 /**
62 * An SPCanvasItem refers to a SPCanvas and to its parent item; it has
63 * four coordinates, a bounding rectangle, and a transformation matrix.
64 */
65 struct SPCanvasItem : public GtkObject {
66 SPCanvas *canvas;
67 SPCanvasItem *parent;
69 double x1, y1, x2, y2;
70 NR::Rect bounds;
71 NR::Matrix xform;
72 };
74 /**
75 * The vtable of an SPCanvasItem.
76 */
77 struct SPCanvasItemClass : public GtkObjectClass {
78 void (* update) (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
80 void (* render) (SPCanvasItem *item, SPCanvasBuf *buf);
81 double (* point) (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
83 int (* event) (SPCanvasItem *item, GdkEvent *event);
84 };
86 SPCanvasItem *sp_canvas_item_new(SPCanvasGroup *parent, GtkType type, const gchar *first_arg_name, ...);
88 #define sp_canvas_item_set gtk_object_set
90 void sp_canvas_item_affine_absolute(SPCanvasItem *item, NR::Matrix const &aff);
92 void sp_canvas_item_raise(SPCanvasItem *item, int positions);
93 void sp_canvas_item_lower(SPCanvasItem *item, int positions);
94 void sp_canvas_item_show(SPCanvasItem *item);
95 void sp_canvas_item_hide(SPCanvasItem *item);
96 int sp_canvas_item_grab(SPCanvasItem *item, unsigned int event_mask, GdkCursor *cursor, guint32 etime);
97 void sp_canvas_item_ungrab(SPCanvasItem *item, guint32 etime);
99 NR::Matrix sp_canvas_item_i2w_affine(SPCanvasItem const *item);
101 void sp_canvas_item_grab_focus(SPCanvasItem *item);
103 void sp_canvas_item_request_update(SPCanvasItem *item);
105 /* get item z-order in parent group */
107 gint sp_canvas_item_order(SPCanvasItem * item);
110 // SPCanvas -------------------------------------------------
111 /**
112 * Port of GnomeCanvas for inkscape needs.
113 */
114 struct SPCanvas {
115 GtkWidget widget;
117 guint idle_id;
119 SPCanvasItem *root;
121 double dx0, dy0;
122 int x0, y0;
124 /* Area that needs redrawing, stored as a microtile array */
125 int tLeft,tTop,tRight,tBottom;
126 int tileH,tileV;
127 uint8_t *tiles;
129 /* Last known modifier state, for deferred repick when a button is down */
130 int state;
132 /* The item containing the mouse pointer, or NULL if none */
133 SPCanvasItem *current_item;
135 /* Item that is about to become current (used to track deletions and such) */
136 SPCanvasItem *new_current_item;
138 /* Item that holds a pointer grab, or NULL if none */
139 SPCanvasItem *grabbed_item;
141 /* Event mask specified when grabbing an item */
142 guint grabbed_event_mask;
144 /* If non-NULL, the currently focused item */
145 SPCanvasItem *focused_item;
147 /* Event on which selection of current item is based */
148 GdkEvent pick_event;
150 int close_enough;
152 /* GC for temporary draw pixmap */
153 GdkGC *pixmap_gc;
155 unsigned int need_update : 1;
156 unsigned int need_redraw : 1;
157 unsigned int need_repick : 1;
159 /* For use by internal pick_current_item() function */
160 unsigned int left_grabbed_item : 1;
161 /* For use by internal pick_current_item() function */
162 unsigned int in_repick : 1;
164 // In most tools Inkscape only generates enter and leave events
165 // on the current item, but no other enter events if a mouse button
166 // is depressed -- see function pick_current_item(). Some tools
167 // may wish the canvas to generate to all enter events, (e.g., the
168 // connector tool). If so, they may temporarily set this flag to
169 // 'true'.
170 bool gen_all_enter_events;
172 int rendermode;
174 NR::Rect getViewbox() const;
175 };
177 GtkWidget *sp_canvas_new_aa();
179 SPCanvasGroup *sp_canvas_root(SPCanvas *canvas);
181 void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int clear);
182 void sp_canvas_update_now(SPCanvas *canvas);
184 void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2);
186 void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy);
187 void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy);
189 NR::Point sp_canvas_window_to_world(SPCanvas const *canvas, NR::Point const win);
190 NR::Point sp_canvas_world_to_window(SPCanvas const *canvas, NR::Point const world);
192 bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, NR::Point const &world);
194 #endif
196 /*
197 Local Variables:
198 mode:c++
199 c-file-style:"stroustrup"
200 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
201 indent-tabs-mode:nil
202 fill-column:99
203 End:
204 */
205 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :