Code

Remove warnings
[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 <cstring>
15 #include <string>
17 #include <gtkmm/box.h>
18 #include <gtkmm.h>
20 #include "display/sp-canvas.h"
21 #include "xml/repr.h"
22 #include "ui/widget/color-picker.h"
23 #include "ui/widget/scalar-unit.h"
24 #include "ui/widget/registered-widget.h"
25 #include "ui/widget/registry.h"
26 //#include "ui/widget/tolerance-slider.h"
27 #include "xml/node-event-vector.h"
28 #include "snapper.h"
29 #include "line-snapper.h"
31 struct SPDesktop;
32 struct SPNamedView;
33 class SPDocument;
35 namespace Inkscape {
38 enum GridType {
39     GRID_RECTANGULAR = 0,
40     GRID_AXONOMETRIC = 1
41 };
42 #define GRID_MAXTYPENR 1
44 #define INKSCAPE_TYPE_GRID_CANVASITEM            (Inkscape::grid_canvasitem_get_type ())
45 #define INKSCAPE_GRID_CANVASITEM(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
46 #define INKSCAPE_GRID_CANVASITEM_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
47 #define INKSCAPE_IS_GRID_CANVASITEM(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_GRID_CANVASITEM))
48 #define INKSCAPE_IS_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_GRID_CANVASITEM))
50 class CanvasGrid;
52 /** \brief  All the variables that are tracked for a grid specific
53             canvas item. */
54 struct GridCanvasItem : public SPCanvasItem{
55     CanvasGrid *grid; // the owning grid object
56 };
58 struct GridCanvasItemClass {
59     SPCanvasItemClass parent_class;
60 };
62 /* Standard Gtk function */
63 GtkType grid_canvasitem_get_type (void);
67 class CanvasGrid {
68 public:
69     virtual ~CanvasGrid();
71     // TODO: see effect.h and effect.cpp from live_effects how to link enums to SVGname to typename properly. (johan)
72     const char * getName();
73     const char * getSVGName();
74     GridType     getGridType();
75     static const char * getName(GridType type);
76     static const char * getSVGName(GridType type);
77     static GridType     getGridTypeFromSVGName(const char * typestr);
78     static GridType     getGridTypeFromName(const char * typestr);
80     static CanvasGrid* NewGrid(SPNamedView * nv, Inkscape::XML::Node * repr, SPDocument *doc, GridType gridtype);
81     static void writeNewGridToRepr(Inkscape::XML::Node * repr, SPDocument * doc, GridType gridtype);
83     GridCanvasItem * createCanvasItem(SPDesktop * desktop);
85     virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
86     virtual void Render (SPCanvasBuf *buf) = 0;
88     virtual void readRepr() = 0;
89     virtual void onReprAttrChanged (Inkscape::XML::Node * /*repr*/, const gchar */*key*/, const gchar */*oldval*/, const gchar */*newval*/, bool /*is_interactive*/) = 0;
91     Gtk::Widget * newWidget();
93     Inkscape::XML::Node * repr;
94     SPDocument *doc;
96     Inkscape::Snapper* snapper;
98     static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
100     bool isVisible() { return (isEnabled() &&visible); };
101     bool isEnabled();
103 protected:
104     CanvasGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument *in_doc, GridType type);
106     virtual Gtk::Widget * newSpecificWidget() = 0;
108     GSList * canvasitems;  // list of created canvasitems
110     SPNamedView * namedview;
112     Inkscape::UI::Widget::Registry _wr;
113     bool visible;
115     GridType gridtype;
117 private:
118     CanvasGrid(const CanvasGrid&);
119     CanvasGrid& operator=(const CanvasGrid&);
120 };
123 class CanvasXYGrid : public CanvasGrid {
124 public:
125     CanvasXYGrid(SPNamedView * nv, Inkscape::XML::Node * in_repr, SPDocument * in_doc);
126     virtual ~CanvasXYGrid();
128     void Update (NR::Matrix const &affine, unsigned int flags);
129     void Render (SPCanvasBuf *buf);
131     void readRepr();
132     void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
134     NR::Point origin;
135     guint32 color;
136     guint32 empcolor;
137     gint  empspacing;
138     SPUnit const* gridunit;
140     NR::Point spacing; /**< Spacing between elements of the grid */
141     bool scaled[2];    /**< Whether the grid is in scaled mode, which can
142                             be different in the X or Y direction, hense two
143                             variables */
144     NR::Point ow;      /**< Transformed origin by the affine for the zoom */
145     NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
147 protected:
148     virtual Gtk::Widget * newSpecificWidget();
150 private:
151     CanvasXYGrid(const CanvasXYGrid&);
152     CanvasXYGrid& operator=(const CanvasXYGrid&);
154     void updateWidgets();
156     bool render_dotted;
157 };
161 class CanvasXYGridSnapper : public LineSnapper
163 public:
164     CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);
165     bool ThisSnapperMightSnap() const;
167 private:
168     LineList _getSnapLines(NR::Point const &p) const;
169     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;
170     CanvasXYGrid *grid;
171 };
173 }; /* namespace Inkscape */
178 #endif