Code

angled guidelines: create angled line when dragging from edge of rulers
[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-2007 <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     virtual ~CanvasGrid();
72     // TODO: see effect.h and effect.cpp from live_effects how to link enums to SVGname to typename properly. (johan)
73     const char * getName();
74     const char * getSVGName();
75     GridType     getGridType();
76     static const char * getName(GridType type);
77     static const char * getSVGName(GridType type);
78     static GridType     getGridTypeFromSVGName(const char * typestr);
79     static GridType     getGridTypeFromName(const char * typestr);
81     static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument *doc, GridType gridtype);
82     static void writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype);
84     GridCanvasItem * createCanvasItem(SPDesktop * desktop);
86     virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
87     virtual void Render (SPCanvasBuf *buf) = 0;
89     virtual void readRepr() = 0;
90     virtual void onReprAttrChanged (Inkscape::XML::Node * /*repr*/, const gchar */*key*/, const gchar */*oldval*/, const gchar */*newval*/, bool /*is_interactive*/) = 0;
92     virtual Gtk::Widget & getWidget() = 0;
94     Inkscape::XML::Node * repr;
95     SPDocument *doc;
97     Inkscape::Snapper* snapper;
99     static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
101     bool isVisible() { return (isEnabled() &&visible); };
102     bool isEnabled();
104 protected:
105     CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type);
107     GSList * canvasitems;  // list of created canvasitems
109     SPNamedView * namedview;
111     Gtk::VBox vbox;
112     Gtk::Label namelabel;
114     Inkscape::UI::Widget::Registry _wr;
115     Inkscape::UI::Widget::RegisteredCheckButton _rcb_visible;
116     bool visible;
117     Inkscape::UI::Widget::RegisteredCheckButton _rcb_enabled;
118     
119     GridType gridtype;
121 private:
122     CanvasGrid(const CanvasGrid&);
123     CanvasGrid& operator=(const CanvasGrid&);
124 };
127 class CanvasXYGrid : public CanvasGrid {
128 public:
129     CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc);
130     virtual ~CanvasXYGrid();
132     void Update (NR::Matrix const &affine, unsigned int flags);
133     void Render (SPCanvasBuf *buf);
135     void readRepr();
136     void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
138     Gtk::Widget & getWidget();
140     NR::Point origin;
141     guint32 color;
142     guint32 empcolor;
143     gint  empspacing;
144     SPUnit const* gridunit;
146     NR::Point spacing; /**< Spacing between elements of the grid */
147     bool scaled[2];    /**< Whether the grid is in scaled mode, which can
148                             be different in the X or Y direction, hense two
149                             variables */
150     NR::Point ow;      /**< Transformed origin by the affine for the zoom */
151     NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
152 private:
153     CanvasXYGrid(const CanvasXYGrid&);
154     CanvasXYGrid& operator=(const CanvasXYGrid&);
156     void updateWidgets();
158     Gtk::Table table;
160     Inkscape::UI::Widget::RegisteredUnitMenu    _rumg, _rums;
161     Inkscape::UI::Widget::RegisteredScalarUnit  _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
162     Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
163     Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
164     Inkscape::UI::Widget::RegisteredCheckButton _rcb_dotted;
166     bool render_dotted;
167 };
171 class CanvasXYGridSnapper : public LineSnapper
173 public:
174     CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
175     bool ThisSnapperMightSnap() const;
177 private:
178     LineList _getSnapLines(NR::Point const &p) const;
179     void _addSnappedLine(SnappedConstraints &sc, NR::Point const snapped_point, NR::Coord const snapped_distance, NR::Point const normal_to_line, const NR::Point point_on_line) const;
180     CanvasXYGrid *grid;
181 };
183 }; /* namespace Inkscape */
188 #endif