Code

NR ==> Geom conversion in sp-canvas
[inkscape.git] / src / display / sp-canvas.h
1 #ifndef SEEN_SP_CANVAS_H
2 #define SEEN_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 <glibmm/ustring.h>
38 #include <libnr/nr-matrix.h>
39 #include <libnr/nr-rect.h>
40 #include <libnr/nr-rect-l.h>
42 G_BEGIN_DECLS
44 struct SPCanvas;
45 struct SPCanvasGroup;
46 typedef struct _SPCanvasItemClass SPCanvasItemClass;
48 enum {
49     SP_CANVAS_UPDATE_REQUESTED  = 1 << 0,
50     SP_CANVAS_UPDATE_AFFINE     = 1 << 1
51 };
53 /**
54  * The canvas buf contains the actual pixels.
55  */
56 struct SPCanvasBuf{
57     guchar *buf;
58     int buf_rowstride;
59     NRRectL rect;
60     NRRectL visible_rect;
61     /// Background color, given as 0xrrggbb
62     guint32 bg_color;
63     // If empty, ignore contents of buffer and use a solid area of bg_color
64     bool is_empty;
65     cairo_t *ct;
66 };
68 /**
69  * An SPCanvasItem refers to a SPCanvas and to its parent item; it has
70  * four coordinates, a bounding rectangle, and a transformation matrix.
71  */
72 struct SPCanvasItem : public GtkObject {
73     SPCanvas *canvas;
74     SPCanvasItem *parent;
76     double x1, y1, x2, y2;
77     NR::Rect bounds;
78     NR::Matrix xform;
79 };
81 /**
82  * The vtable of an SPCanvasItem.
83  */
84 struct _SPCanvasItemClass : public GtkObjectClass {
85     void (* update) (SPCanvasItem *item, NR::Matrix const &affine, unsigned int flags);
87     void (* render) (SPCanvasItem *item, SPCanvasBuf *buf);
88     double (* point) (SPCanvasItem *item, NR::Point p, SPCanvasItem **actual_item);
90     int (* event) (SPCanvasItem *item, GdkEvent *event);
91 };
93 SPCanvasItem *sp_canvas_item_new(SPCanvasGroup *parent, GtkType type, const gchar *first_arg_name, ...);
95 G_END_DECLS
97 #define sp_canvas_item_set gtk_object_set
99 void sp_canvas_item_affine_absolute(SPCanvasItem *item, NR::Matrix const &aff);
101 void sp_canvas_item_raise(SPCanvasItem *item, int positions);
102 void sp_canvas_item_lower(SPCanvasItem *item, int positions);
103 void sp_canvas_item_show(SPCanvasItem *item);
104 void sp_canvas_item_hide(SPCanvasItem *item);
105 int sp_canvas_item_grab(SPCanvasItem *item, unsigned int event_mask, GdkCursor *cursor, guint32 etime);
106 void sp_canvas_item_ungrab(SPCanvasItem *item, guint32 etime);
108 NR::Matrix sp_canvas_item_i2w_affine(SPCanvasItem const *item);
110 void sp_canvas_item_grab_focus(SPCanvasItem *item);
112 void sp_canvas_item_request_update(SPCanvasItem *item);
114 /* get item z-order in parent group */
116 gint sp_canvas_item_order(SPCanvasItem * item);
119 // SPCanvas -------------------------------------------------
120 /**
121  * Port of GnomeCanvas for inkscape needs.
122  */
123 struct SPCanvas {
124     GtkWidget widget;
126     guint idle_id;
128     SPCanvasItem *root;
130     double dx0, dy0;
131     int x0, y0;
133     /* Area that needs redrawing, stored as a microtile array */
134     int    tLeft,tTop,tRight,tBottom;
135     int    tileH,tileV;
136     uint8_t *tiles;
138     /* Last known modifier state, for deferred repick when a button is down */
139     int state;
141     /* The item containing the mouse pointer, or NULL if none */
142     SPCanvasItem *current_item;
144     /* Item that is about to become current (used to track deletions and such) */
145     SPCanvasItem *new_current_item;
147     /* Item that holds a pointer grab, or NULL if none */
148     SPCanvasItem *grabbed_item;
150     /* Event mask specified when grabbing an item */
151     guint grabbed_event_mask;
153     /* If non-NULL, the currently focused item */
154     SPCanvasItem *focused_item;
156     /* Event on which selection of current item is based */
157     GdkEvent pick_event;
159     int close_enough;
161     /* GC for temporary draw pixmap */
162     GdkGC *pixmap_gc;
164     unsigned int need_update : 1;
165     unsigned int need_redraw : 1;
166     unsigned int need_repick : 1;
168     int forced_redraw_count;
169     int forced_redraw_limit;
171     /* For use by internal pick_current_item() function */
172     unsigned int left_grabbed_item : 1;
173     /* For use by internal pick_current_item() function */
174     unsigned int in_repick : 1;
176     // In most tools Inkscape only generates enter and leave events
177     // on the current item, but no other enter events if a mouse button
178     // is depressed -- see function pick_current_item().  Some tools
179     // may wish the canvas to generate to all enter events, (e.g., the
180     // connector tool).  If so, they may temporarily set this flag to
181     // 'true'.
182     bool gen_all_enter_events;
184     int rendermode;
186 #if ENABLE_LCMS
187     bool enable_cms_display_adj;
188     Glib::ustring* cms_key;
189 #endif // ENABLE_LCMS
191     bool is_scrolling;
193     NR::Rect getViewbox() const;
194     NR::IRect getViewboxIntegers() const;
195 };
197 GtkWidget *sp_canvas_new_aa();
199 SPCanvasGroup *sp_canvas_root(SPCanvas *canvas);
201 void sp_canvas_scroll_to(SPCanvas *canvas, double cx, double cy, unsigned int clear, bool is_scrolling = false);
202 void sp_canvas_update_now(SPCanvas *canvas);
204 void sp_canvas_request_redraw(SPCanvas *canvas, int x1, int y1, int x2, int y2);
205 void sp_canvas_force_full_redraw_after_interruptions(SPCanvas *canvas, unsigned int count);
206 void sp_canvas_end_forced_full_redraws(SPCanvas *canvas);
208 bool sp_canvas_world_pt_inside_window(SPCanvas const *canvas, Geom::Point const &world);
210 void sp_canvas_window_to_world(SPCanvas const *canvas, double winx, double winy, double *worldx, double *worldy);
211 void sp_canvas_world_to_window(SPCanvas const *canvas, double worldx, double worldy, double *winx, double *winy);
213 Geom::Point sp_canvas_window_to_world(SPCanvas const *canvas, Geom::Point const win);
214 Geom::Point sp_canvas_world_to_window(SPCanvas const *canvas, Geom::Point const world);
216 #endif // SEEN_SP_CANVAS_H
218 /*
219   Local Variables:
220   mode:c++
221   c-file-style:"stroustrup"
222   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
223   indent-tabs-mode:nil
224   fill-column:99
225   End:
226 */
227 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :