Code

New Grids are now ready to go. bug testing can start i think.
[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 {
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();
64     
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);
69     
70     virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
71     virtual void Render (SPCanvasBuf *buf) = 0;
72     
73     virtual void readRepr() {};
74     virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
75     
76     virtual Gtk::Widget & getWidget() = 0;
78     Inkscape::XML::Node * repr;
79     
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);
83     
84 protected:
85     GSList * canvasitems;  // list of created canvasitems
87     SPNamedView * namedview;
88     
89     Gtk::VBox vbox;
91 private:
92     CanvasGrid(const CanvasGrid&);
93     CanvasGrid& operator=(const CanvasGrid&);
94  
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);
105     
106     void readRepr();
107     void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
108     
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&);
126     
127     void updateWidgets();
129     Gtk::Table table;
130     
131     Inkscape::UI::Widget::RegisteredCheckButton _rcbgrid, _rcbsnbb, _rcbsnnod;
132     Inkscape::UI::Widget::RegisteredUnitMenu    _rumg, _rums;
133     Inkscape::UI::Widget::RegisteredScalarUnit  _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
134     Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
135     Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
136     
137     Inkscape::UI::Widget::Registry _wr;
139 };
143 class CanvasXYGridSnapper : public LineSnapper
145 public:
146     CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
148 private:    
149     LineList _getSnapLines(NR::Point const &p) const;
150     
151     CanvasXYGrid *grid;
152 }; 
172 #define INKSCAPE_TYPE_CXYGRID            (Inkscape::cxygrid_get_type ())
173 #define INKSCAPE_CXYGRID(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_CXYGRID, CXYGrid))
174 #define INKSCAPE_CXYGRID_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_CXYGRID, CXYGridClass))
175 #define INKSCAPE_IS_CXYGRID(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_CXYGRID))
176 #define INKSCAPE_IS_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_CXYGRID))
179 /** \brief  All the variables that are tracked for a grid specific
180             canvas item. */
181 struct CXYGrid : public SPCanvasItem{
182         NR::Point origin;  /**< Origin of the grid */
183         NR::Point spacing; /**< Spacing between elements of the grid */
184         guint32 color;     /**< Color for normal lines */
185         guint32 empcolor;  /**< Color for emphisis lines */
186         gint empspacing;   /**< Spacing between emphisis lines */
187         bool scaled[2];    /**< Whether the grid is in scaled mode, which can
188                                                 be different in the X or Y direction, hense two
189                                                     variables */
190         NR::Point ow;      /**< Transformed origin by the affine for the zoom */
191         NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
192 };
194 struct CXYGridClass {
195         SPCanvasItemClass parent_class;
196 };
198 /* Standard Gtk function */
199 GtkType cxygrid_get_type (void);
201 }; /* namespace Inkscape */
206 #endif