Code

Filter effects dialog:
[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;
34 class SPDocument;
36 namespace Inkscape {
39 enum GridType {
40     GRID_RECTANGULAR = 0,
41     GRID_AXONOMETRIC = 1
42 };
43 #define GRID_MAXTYPENR 1
45 #define INKSCAPE_TYPE_GRID_CANVASITEM            (Inkscape::grid_canvasitem_get_type ())
46 #define INKSCAPE_GRID_CANVASITEM(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
47 #define INKSCAPE_GRID_CANVASITEM_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
48 #define INKSCAPE_IS_GRID_CANVASITEM(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_GRID_CANVASITEM))
49 #define INKSCAPE_IS_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_GRID_CANVASITEM))
51 class CanvasGrid;
53 /** \brief  All the variables that are tracked for a grid specific
54             canvas item. */
55 struct GridCanvasItem : public SPCanvasItem{
56     CanvasGrid *grid; // the owning grid object
57 };
59 struct GridCanvasItemClass {
60     SPCanvasItemClass parent_class;
61 };
63 /* Standard Gtk function */
64 GtkType grid_canvasitem_get_type (void);
68 class CanvasGrid {
69 public:
70     CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc);
71     virtual ~CanvasGrid();
72     
73     static const char * getName(GridType type);
74     static const char * getSVGName(GridType type);
75     static GridType     getGridTypeFromSVGName(const char * typestr);
76     static GridType     getGridTypeFromName(const char * typestr);
77     
78     static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument *doc, GridType gridtype);
79     static void writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype);
81     GridCanvasItem * createCanvasItem(SPDesktop * desktop);
82     
83     virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
84     virtual void Render (SPCanvasBuf *buf) = 0;
85     
86     virtual void readRepr() {};
87     virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
88     
89     virtual Gtk::Widget & getWidget() = 0;
91     Inkscape::XML::Node * repr;
92     SPDocument *doc;
93     
94     Inkscape::Snapper* snapper;
96     static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
97     
98 protected:
99     GSList * canvasitems;  // list of created canvasitems
101     SPNamedView * namedview;
102     
103     Gtk::VBox vbox;
105 private:
106     CanvasGrid(const CanvasGrid&);
107     CanvasGrid& operator=(const CanvasGrid&);
108  
109 };
112 class CanvasXYGrid : public CanvasGrid {
113 public:
114     CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc);
115     ~CanvasXYGrid();
117     void Update (NR::Matrix const &affine, unsigned int flags);
118     void Render (SPCanvasBuf *buf);
119     
120     void readRepr();
121     void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
122     
123     Gtk::Widget & getWidget();
125     NR::Point origin;
126     guint32 color;
127     guint32 empcolor;
128     gint  empspacing;
129     SPUnit const* gridunit;
131     NR::Point spacing; /**< Spacing between elements of the grid */
132     bool scaled[2];    /**< Whether the grid is in scaled mode, which can
133                             be different in the X or Y direction, hense two
134                             variables */
135     NR::Point ow;      /**< Transformed origin by the affine for the zoom */
136     NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
137 private:
138     CanvasXYGrid(const CanvasXYGrid&);
139     CanvasXYGrid& operator=(const CanvasXYGrid&);
140     
141     void updateWidgets();
143     Gtk::Table table;
144     
145     Inkscape::UI::Widget::RegisteredUnitMenu    _rumg, _rums;
146     Inkscape::UI::Widget::RegisteredScalarUnit  _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
147     Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
148     Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
149     Inkscape::UI::Widget::RegisteredCheckButton _rcb_dotted;
150     
151     Inkscape::UI::Widget::Registry _wr; 
152         
153     bool render_dotted;
154 };
158 class CanvasXYGridSnapper : public LineSnapper
160 public:
161     CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
163 private:    
164     LineList _getSnapLines(NR::Point const &p) const;
165     
166     CanvasXYGrid *grid;
167 }; 
169 }; /* namespace Inkscape */
174 #endif