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 {
37 #define INKSCAPE_TYPE_GRID_CANVASITEM (Inkscape::grid_canvasitem_get_type ())
38 #define INKSCAPE_GRID_CANVASITEM(obj) (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
39 #define INKSCAPE_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
40 #define INKSCAPE_IS_GRID_CANVASITEM(obj) (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_GRID_CANVASITEM))
41 #define INKSCAPE_IS_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_GRID_CANVASITEM))
43 class CanvasGrid;
45 /** \brief All the variables that are tracked for a grid specific
46 canvas item. */
47 struct GridCanvasItem : public SPCanvasItem{
48 CanvasGrid *grid; // the owning grid object
49 };
51 struct GridCanvasItemClass {
52 SPCanvasItemClass parent_class;
53 };
55 /* Standard Gtk function */
56 GtkType grid_canvasitem_get_type (void);
60 class CanvasGrid {
61 public:
62 CanvasGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr);
63 virtual ~CanvasGrid();
65 static CanvasGrid* NewGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr, const char * gridtype);
66 static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype);
68 virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
69 virtual void Render (SPCanvasBuf *buf) = 0;
71 virtual void readRepr() {};
72 virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
74 virtual Gtk::Widget & getWidget() = 0;
76 void hide();
77 void show();
78 void set_visibility(bool visible);
79 void toggle_visibility();
80 void enable_snapping() { snapenabled = true; snapper->setEnabled(true); } ;
81 void disable_snapping() { snapenabled = false; snapper->setEnabled(false); } ;
82 void toggle_snapping() { snapenabled = !snapenabled; snapper->setEnabled(snapenabled);};
84 Inkscape::XML::Node * repr;
86 Inkscape::Snapper* snapper;
88 static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
89 protected:
90 GridCanvasItem * canvasitem;
92 SPNamedView * namedview;
94 Gtk::VBox vbox;
96 bool snapenabled;
97 bool visible;
99 private:
100 CanvasGrid(const CanvasGrid&);
101 CanvasGrid& operator=(const CanvasGrid&);
103 };
106 class CanvasXYGrid : public CanvasGrid {
107 public:
108 CanvasXYGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr);
109 ~CanvasXYGrid();
111 void Update (NR::Matrix const &affine, unsigned int flags);
112 void Render (SPCanvasBuf *buf);
114 void readRepr();
115 void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
117 Gtk::Widget & getWidget();
119 NR::Point origin;
120 guint32 color;
121 guint32 empcolor;
122 gint empspacing;
123 SPUnit const* gridunit;
125 NR::Point spacing; /**< Spacing between elements of the grid */
126 bool scaled[2]; /**< Whether the grid is in scaled mode, which can
127 be different in the X or Y direction, hense two
128 variables */
129 NR::Point ow; /**< Transformed origin by the affine for the zoom */
130 NR::Point sw; /**< Transformed spacing by the affine for the zoom */
131 private:
132 CanvasXYGrid(const CanvasXYGrid&);
133 CanvasXYGrid& operator=(const CanvasXYGrid&);
135 void updateWidgets();
137 Gtk::Table table;
139 Inkscape::UI::Widget::RegisteredCheckButton _rcbgrid, _rcbsnbb, _rcbsnnod;
140 Inkscape::UI::Widget::RegisteredUnitMenu _rumg, _rums;
141 Inkscape::UI::Widget::RegisteredScalarUnit _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
142 Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
143 Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
145 Inkscape::UI::Widget::Registry _wr;
147 };
151 class CanvasXYGridSnapper : public LineSnapper
152 {
153 public:
154 CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
156 private:
157 LineList _getSnapLines(NR::Point const &p) const;
159 CanvasXYGrid *grid;
160 };
180 #define INKSCAPE_TYPE_CXYGRID (Inkscape::cxygrid_get_type ())
181 #define INKSCAPE_CXYGRID(obj) (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_CXYGRID, CXYGrid))
182 #define INKSCAPE_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_CXYGRID, CXYGridClass))
183 #define INKSCAPE_IS_CXYGRID(obj) (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_CXYGRID))
184 #define INKSCAPE_IS_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_CXYGRID))
187 /** \brief All the variables that are tracked for a grid specific
188 canvas item. */
189 struct CXYGrid : public SPCanvasItem{
190 NR::Point origin; /**< Origin of the grid */
191 NR::Point spacing; /**< Spacing between elements of the grid */
192 guint32 color; /**< Color for normal lines */
193 guint32 empcolor; /**< Color for emphisis lines */
194 gint empspacing; /**< Spacing between emphisis lines */
195 bool scaled[2]; /**< Whether the grid is in scaled mode, which can
196 be different in the X or Y direction, hense two
197 variables */
198 NR::Point ow; /**< Transformed origin by the affine for the zoom */
199 NR::Point sw; /**< Transformed spacing by the affine for the zoom */
200 };
202 struct CXYGridClass {
203 SPCanvasItemClass parent_class;
204 };
206 /* Standard Gtk function */
207 GtkType cxygrid_get_type (void);
209 }; /* namespace Inkscape */
214 #endif