1 #ifndef SEEN_SP_CANVAS_H
2 #define SEEN_SP_CANVAS_H
4 /** \file
5 * SPCanvas, SPCanvasBuf.
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 <glibmm/ustring.h>
38 #include <2geom/matrix.h>
39 #include <libnr/nr-rect-l.h>
41 #include <2geom/rect.h>
43 G_BEGIN_DECLS
45 #define SP_TYPE_CANVAS sp_canvas_get_type()
46 #define SP_CANVAS(obj) (GTK_CHECK_CAST((obj), SP_TYPE_CANVAS, SPCanvas))
47 #define SP_IS_CANVAS(obj) (GTK_CHECK_TYPE((obj), SP_TYPE_CANVAS))
49 GType sp_canvas_get_type();
51 struct SPCanvas;
52 struct SPCanvasItem;
53 struct SPCanvasGroup;
55 enum {
56 SP_CANVAS_UPDATE_REQUESTED = 1 << 0,
57 SP_CANVAS_UPDATE_AFFINE = 1 << 1
58 };
60 /**
61 * The canvas buf contains the actual pixels.
62 */
63 struct SPCanvasBuf{
64 guchar *buf;
65 int buf_rowstride;
66 NRRectL rect;
67 NRRectL visible_rect;
68 /// Background color, given as 0xrrggbb
69 guint32 bg_color;
70 // If empty, ignore contents of buffer and use a solid area of bg_color
71 bool is_empty;
72 cairo_t *ct;
73 };
75 G_END_DECLS
77 // SPCanvas -------------------------------------------------
78 /**
79 * Port of GnomeCanvas for inkscape needs.
80 */
81 struct SPCanvas {
82 GtkWidget widget;
84 guint idle_id;
86 SPCanvasItem *root;
88 double dx0, dy0;
89 int x0, y0;
91 /* Area that needs redrawing, stored as a microtile array */
92 int tLeft,tTop,tRight,tBottom;
93 int tileH,tileV;
94 uint8_t *tiles;
96 /* Last known modifier state, for deferred repick when a button is down */
97 int state;
99 /* The item containing the mouse pointer, or NULL if none */
100 SPCanvasItem *current_item;
102 /* Item that is about to become current (used to track deletions and such) */
103 SPCanvasItem *new_current_item;
105 /* Item that holds a pointer grab, or NULL if none */
106 SPCanvasItem *grabbed_item;
108 /* Event mask specified when grabbing an item */
109 guint grabbed_event_mask;
111 /* If non-NULL, the currently focused item */
112 SPCanvasItem *focused_item;
114 /* Event on which selection of current item is based */
115 GdkEvent pick_event;
117 int close_enough;
119 /* GC for temporary draw pixmap */
120 GdkGC *pixmap_gc;
122 unsigned int need_update : 1;
123 unsigned int need_redraw : 1;
124 unsigned int need_repick : 1;
126 int forced_redraw_count;
127 int forced_redraw_limit;
129 /* For use by internal pick_current_item() function */
130 unsigned int left_grabbed_item : 1;
131 /* For use by internal pick_current_item() function */
132 unsigned int in_repick : 1;
134 // In most tools Inkscape only generates enter and leave events
135 // on the current item, but no other enter events if a mouse button
136 // is depressed -- see function pick_current_item(). Some tools
137 // may wish the canvas to generate to all enter events, (e.g., the
138 // connector tool). If so, they may temporarily set this flag to
139 // 'true'.
140 bool gen_all_enter_events;
142 /* For scripting, sometimes we want to delay drawing. */
143 bool drawing_disabled;
145 int rendermode;
147 #if ENABLE_LCMS
148 bool enable_cms_display_adj;
149 Glib::ustring* cms_key;
150 #endif // ENABLE_LCMS
152 bool is_scrolling;
154 Geom::Rect getViewbox() const;
155 NR::IRect getViewboxIntegers() const;
156 };
158 GtkWidget *sp_canvas_new_aa();
160 SPCanvasGroup *sp_canvas_root(SPCanvas *canvas);
162 void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int clear, bool is_scrolling = false);
163 void sp_canvas_update_now(SPCanvas *canvas);
165 void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2);
166 void sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count);
167 void sp_canvas_end_forced_full_redraws(SPCanvas *canvas);
169 bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, Geom::Point const &world);
171 void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy);
172 void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy);
174 Geom::Point sp_canvas_window_to_world(SPCanvas const *canvas, Geom::Point const win);
175 Geom::Point sp_canvas_world_to_window(SPCanvas const *canvas, Geom::Point const world);
177 #endif // SEEN_SP_CANVAS_H
179 /*
180 Local Variables:
181 mode:c++
182 c-file-style:"stroustrup"
183 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
184 indent-tabs-mode:nil
185 fill-column:99
186 End:
187 */
188 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :