0dde36935169803a8668d8a6ebfba574bd75f629
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(SPNamedView * nv, Inkscape::XML::Node * in_repr);
63 virtual ~CanvasGrid();
65 static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, const char * gridtype);
66 static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype);
68 GridCanvasItem * createCanvasItem(SPDesktop * desktop);
70 virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
71 virtual void Render (SPCanvasBuf *buf) = 0;
73 virtual void readRepr() {};
74 virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
76 virtual Gtk::Widget & getWidget() = 0;
78 Inkscape::XML::Node * repr;
80 Inkscape::Snapper* snapper;
82 static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
84 protected:
85 GSList * canvasitems; // list of created canvasitems
87 SPNamedView * namedview;
89 Gtk::VBox vbox;
91 private:
92 CanvasGrid(const CanvasGrid&);
93 CanvasGrid& operator=(const CanvasGrid&);
95 };
98 class CanvasXYGrid : public CanvasGrid {
99 public:
100 CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr);
101 ~CanvasXYGrid();
103 void Update (NR::Matrix const &affine, unsigned int flags);
104 void Render (SPCanvasBuf *buf);
106 void readRepr();
107 void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
109 Gtk::Widget & getWidget();
111 NR::Point origin;
112 guint32 color;
113 guint32 empcolor;
114 gint empspacing;
115 SPUnit const* gridunit;
117 NR::Point spacing; /**< Spacing between elements of the grid */
118 bool scaled[2]; /**< Whether the grid is in scaled mode, which can
119 be different in the X or Y direction, hense two
120 variables */
121 NR::Point ow; /**< Transformed origin by the affine for the zoom */
122 NR::Point sw; /**< Transformed spacing by the affine for the zoom */
123 private:
124 CanvasXYGrid(const CanvasXYGrid&);
125 CanvasXYGrid& operator=(const CanvasXYGrid&);
127 void updateWidgets();
129 Gtk::Table table;
131 Inkscape::UI::Widget::RegisteredUnitMenu _rumg, _rums;
132 Inkscape::UI::Widget::RegisteredScalarUnit _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
133 Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
134 Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
135 Inkscape::UI::Widget::RegisteredCheckButton _rcb_dotted;
137 Inkscape::UI::Widget::Registry _wr;
139 bool render_dotted;
140 };
144 class CanvasXYGridSnapper : public LineSnapper
145 {
146 public:
147 CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
149 private:
150 LineList _getSnapLines(NR::Point const &p) const;
152 CanvasXYGrid *grid;
153 };
155 }; /* namespace Inkscape */
160 #endif