Code

Fixed a rendering problem in feOffset
[inkscape.git] / src / display / canvas-grid.h
1 #ifndef INKSCAPE_CANVAS_GRID_H
2 #define INKSCAPE_CANVAS_GRID_H
4 /*
5  * Inkscape::CXYGrid
6  *
7  * Generic (and quite unintelligent) grid item for gnome canvas
8  *
9  * Copyright (C) Johan Engelen 2006 <johan@shouraizou.nl>
10  * Copyright (C) Lauris Kaplinski 2000
11  *
12  */
14 #include <display/sp-canvas.h>
15 #include "xml/repr.h"
16 #include <gtkmm/box.h>
19 #include <gtkmm.h>
20 #include "ui/widget/color-picker.h"
21 #include "ui/widget/scalar-unit.h"
23 #include "ui/widget/registered-widget.h"
24 #include "ui/widget/registry.h"
25 #include "ui/widget/tolerance-slider.h"
27 #include "xml/node-event-vector.h"
29 #include "snapper.h"
30 #include "line-snapper.h"
32 struct SPDesktop;
33 struct SPNamedView;
35 namespace Inkscape {
38 enum GridType {
39     GRID_RECTANGULAR = 0,
40     GRID_AXONOMETRIC = 1
41 };
42 #define GRID_MAXTYPENR 1
44 #define INKSCAPE_TYPE_GRID_CANVASITEM            (Inkscape::grid_canvasitem_get_type ())
45 #define INKSCAPE_GRID_CANVASITEM(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
46 #define INKSCAPE_GRID_CANVASITEM_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
47 #define INKSCAPE_IS_GRID_CANVASITEM(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_GRID_CANVASITEM))
48 #define INKSCAPE_IS_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_GRID_CANVASITEM))
50 class CanvasGrid;
52 /** \brief  All the variables that are tracked for a grid specific
53             canvas item. */
54 struct GridCanvasItem : public SPCanvasItem{
55     CanvasGrid *grid; // the owning grid object
56 };
58 struct GridCanvasItemClass {
59     SPCanvasItemClass parent_class;
60 };
62 /* Standard Gtk function */
63 GtkType grid_canvasitem_get_type (void);
67 class CanvasGrid {
68 public:
69     CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr);
70     virtual ~CanvasGrid();
71     
72     static const char * getName(GridType type);
73     static const char * getSVGName(GridType type);
74     static GridType     getGridTypeFromSVGName(const char * typestr);
75     static GridType     getGridTypeFromName(const char * typestr);
76     
77     static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, GridType gridtype);
78     static void writeNewGridToRepr(Inkscape::XML::Node * repr, GridType gridtype);
80     GridCanvasItem * createCanvasItem(SPDesktop * desktop);
81     
82     virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
83     virtual void Render (SPCanvasBuf *buf) = 0;
84     
85     virtual void readRepr() {};
86     virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
87     
88     virtual Gtk::Widget & getWidget() = 0;
90     Inkscape::XML::Node * repr;
91     
92     Inkscape::Snapper* snapper;
94     static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
95     
96 protected:
97     GSList * canvasitems;  // list of created canvasitems
99     SPNamedView * namedview;
100     
101     Gtk::VBox vbox;
103 private:
104     CanvasGrid(const CanvasGrid&);
105     CanvasGrid& operator=(const CanvasGrid&);
106  
107 };
110 class CanvasXYGrid : public CanvasGrid {
111 public:
112     CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr);
113     ~CanvasXYGrid();
115     void Update (NR::Matrix const &affine, unsigned int flags);
116     void Render (SPCanvasBuf *buf);
117     
118     void readRepr();
119     void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
120     
121     Gtk::Widget & getWidget();
123     NR::Point origin;
124     guint32 color;
125     guint32 empcolor;
126     gint  empspacing;
127     SPUnit const* gridunit;
129     NR::Point spacing; /**< Spacing between elements of the grid */
130     bool scaled[2];    /**< Whether the grid is in scaled mode, which can
131                             be different in the X or Y direction, hense two
132                             variables */
133     NR::Point ow;      /**< Transformed origin by the affine for the zoom */
134     NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
135 private:
136     CanvasXYGrid(const CanvasXYGrid&);
137     CanvasXYGrid& operator=(const CanvasXYGrid&);
138     
139     void updateWidgets();
141     Gtk::Table table;
142     
143     Inkscape::UI::Widget::RegisteredUnitMenu    _rumg, _rums;
144     Inkscape::UI::Widget::RegisteredScalarUnit  _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
145     Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
146     Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
147     Inkscape::UI::Widget::RegisteredCheckButton _rcb_dotted;
148     
149     Inkscape::UI::Widget::Registry _wr; 
150         
151     bool render_dotted;
152 };
156 class CanvasXYGridSnapper : public LineSnapper
158 public:
159     CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
161 private:    
162     LineList _getSnapLines(NR::Point const &p) const;
163     
164     CanvasXYGrid *grid;
165 }; 
167 }; /* namespace Inkscape */
172 #endif