Code

extend the semantics of sp_canvas_force_full_redraw_after_interruptions to allow...
[inkscape.git] / src / display / sp-canvas.h
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;
69     
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);
80     
81     void (* render) (SPCanvasItem *item, SPCanvasBuf *buf);
82     double (* point) (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
83     
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;
117     
118     guint idle_id;
119     
120     SPCanvasItem *root;
121     
122     double dx0, dy0;
123     int x0, y0;
124     
125     /* Area that needs redrawing, stored as a microtile array */
126     int    tLeft,tTop,tRight,tBottom;
127     int    tileH,tileV;
128     uint8_t *tiles;
129     
130     /* Last known modifier state, for deferred repick when a button is down */
131     int state;
132     
133     /* The item containing the mouse pointer, or NULL if none */
134     SPCanvasItem *current_item;
135     
136     /* Item that is about to become current (used to track deletions and such) */
137     SPCanvasItem *new_current_item;
138     
139     /* Item that holds a pointer grab, or NULL if none */
140     SPCanvasItem *grabbed_item;
141     
142     /* Event mask specified when grabbing an item */
143     guint grabbed_event_mask;
144     
145     /* If non-NULL, the currently focused item */
146     SPCanvasItem *focused_item;
147     
148     /* Event on which selection of current item is based */
149     GdkEvent pick_event;
150     
151     int close_enough;
152     
153     /* GC for temporary draw pixmap */
154     GdkGC *pixmap_gc;
155     
156     unsigned int need_update : 1;
157     unsigned int need_redraw : 1;
158     unsigned int need_repick : 1;
160     NRRectL redraw_aborted;
161     long redraw_count;
162     glong slowest_buffer;
163     
164     int forced_redraw_count;
165     int forced_redraw_limit;
166     
167     /* For use by internal pick_current_item() function */
168     unsigned int left_grabbed_item : 1;
169     /* For use by internal pick_current_item() function */
170     unsigned int in_repick : 1;
172     // In most tools Inkscape only generates enter and leave events
173     // on the current item, but no other enter events if a mouse button
174     // is depressed -- see function pick_current_item().  Some tools
175     // may wish the canvas to generate to all enter events, (e.g., the
176     // connector tool).  If so, they may temporarily set this flag to
177     // 'true'.
178     bool gen_all_enter_events;
179     
180     int rendermode;
181     
182     NR::Rect getViewbox() const;
183 };
185 GtkWidget *sp_canvas_new_aa();
187 SPCanvasGroup *sp_canvas_root(SPCanvas *canvas);
189 void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int clear);
190 void sp_canvas_update_now(SPCanvas *canvas);
192 void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2);
193 void sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count);
194 void sp_canvas_end_forced_full_redraws(SPCanvas *canvas);
196 void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy);
197 void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy);
199 NR::Point sp_canvas_window_to_world(SPCanvas const *canvas, NR::Point const win);
200 NR::Point sp_canvas_world_to_window(SPCanvas const *canvas, NR::Point const world);
202 bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, NR::Point const &world);
204 #endif
206 /*
207   Local Variables:
208   mode:c++
209   c-file-style:"stroustrup"
210   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
211   indent-tabs-mode:nil
212   fill-column:99
213   End:
214 */
215 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :