summaryrefslogtreecommitdiffstats
path: root/src/display/canvas-grid.h
blob: c501ab3f38a9fbdc50391b3ac6b33336c48d933b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#ifndef INKSCAPE_CANVAS_GRID_H
#define INKSCAPE_CANVAS_GRID_H

/*
 * Inkscape::CXYGrid
 *
 * Generic (and quite unintelligent) grid item for gnome canvas
 *
 * Copyright (C) Johan Engelen 2006 <johan@shouraizou.nl>
 * Copyright (C) Lauris Kaplinski 2000
 *
 */

#include <display/sp-canvas.h>
#include "xml/repr.h"
#include <gtkmm/box.h>


#include <gtkmm.h>
#include "ui/widget/color-picker.h"
#include "ui/widget/scalar-unit.h"

#include "ui/widget/registered-widget.h"
#include "ui/widget/registry.h"
#include "ui/widget/tolerance-slider.h"

#include "xml/node-event-vector.h"

#include "snapper.h"
#include "line-snapper.h"

struct SPDesktop;
struct SPNamedView;

namespace Inkscape {

#define INKSCAPE_TYPE_GRID_CANVASITEM            (Inkscape::grid_canvasitem_get_type ())
#define INKSCAPE_GRID_CANVASITEM(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
#define INKSCAPE_GRID_CANVASITEM_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_GRID_CANVASITEM, GridCanvasItem))
#define INKSCAPE_IS_GRID_CANVASITEM(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_GRID_CANVASITEM))
#define INKSCAPE_IS_GRID_CANVASITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_GRID_CANVASITEM))

class CanvasGrid;

/** \brief  All the variables that are tracked for a grid specific
            canvas item. */
struct GridCanvasItem : public SPCanvasItem{
    CanvasGrid *grid; // the owning grid object
};

struct GridCanvasItemClass {
    SPCanvasItemClass parent_class;
};

/* Standard Gtk function */
GtkType grid_canvasitem_get_type (void);



class CanvasGrid {
public:
    CanvasGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr);
    virtual ~CanvasGrid();
    
    static CanvasGrid* NewGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr, const char * gridtype);
    static void writeNewGridToRepr(Inkscape::XML::Node * repr, const char * gridtype);
    
    virtual void Update (NR::Matrix const &affine, unsigned int flags) = 0;
    virtual void Render (SPCanvasBuf *buf) = 0;
    
    virtual void readRepr() {};
    virtual void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive) {};
    
    virtual Gtk::Widget & getWidget() = 0;

    bool enabled;
    bool visible;
    void hide();
    void show();

    Inkscape::XML::Node * repr;
    
    Inkscape::Snapper* snapper;

    static void on_repr_attr_changed (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive, void * data);
protected:
    GridCanvasItem * canvasitem;

    SPNamedView * namedview;
    
    Gtk::VBox vbox;

private:
    CanvasGrid(const CanvasGrid&);
    CanvasGrid& operator=(const CanvasGrid&);
 
};


class CanvasXYGrid : public CanvasGrid {
public:
    CanvasXYGrid(SPDesktop *desktop, Inkscape::XML::Node * in_repr);
    ~CanvasXYGrid();

    void Update (NR::Matrix const &affine, unsigned int flags);
    void Render (SPCanvasBuf *buf);
    
    void readRepr();
    void onReprAttrChanged (Inkscape::XML::Node * repr, const gchar *key, const gchar *oldval, const gchar *newval, bool is_interactive);
    
    Gtk::Widget & getWidget();

    NR::Point origin;
    guint32 color;
    guint32 empcolor;
    gint  empspacing;
    SPUnit const* gridunit;

    NR::Point spacing; /**< Spacing between elements of the grid */
    bool scaled[2];    /**< Whether the grid is in scaled mode, which can
                            be different in the X or Y direction, hense two
                            variables */
    NR::Point ow;      /**< Transformed origin by the affine for the zoom */
    NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
private:
    CanvasXYGrid(const CanvasXYGrid&);
    CanvasXYGrid& operator=(const CanvasXYGrid&);
    
    void updateWidgets();

    Gtk::Table table;
    
    Inkscape::UI::Widget::RegisteredCheckButton _rcbgrid, _rcbsnbb, _rcbsnnod;
    Inkscape::UI::Widget::RegisteredUnitMenu    _rumg, _rums;
    Inkscape::UI::Widget::RegisteredScalarUnit  _rsu_ox, _rsu_oy, _rsu_sx, _rsu_sy;
    Inkscape::UI::Widget::RegisteredColorPicker _rcp_gcol, _rcp_gmcol;
    Inkscape::UI::Widget::RegisteredSuffixedInteger _rsi;
    
    Inkscape::UI::Widget::Registry _wr;

};



class CanvasXYGridSnapper : public LineSnapper
{
public:
    CanvasXYGridSnapper(CanvasXYGrid *grid, SPNamedView const *nv, NR::Coord const d);

private:    
    LineList _getSnapLines(NR::Point const &p) const;
    
    CanvasXYGrid *grid;
}; 



















#define INKSCAPE_TYPE_CXYGRID            (Inkscape::cxygrid_get_type ())
#define INKSCAPE_CXYGRID(obj)            (GTK_CHECK_CAST ((obj), INKSCAPE_TYPE_CXYGRID, CXYGrid))
#define INKSCAPE_CXYGRID_CLASS(klass)    (GTK_CHECK_CLASS_CAST ((klass), INKSCAPE_TYPE_CXYGRID, CXYGridClass))
#define INKSCAPE_IS_CXYGRID(obj)         (GTK_CHECK_TYPE ((obj), INKSCAPE_TYPE_CXYGRID))
#define INKSCAPE_IS_CXYGRID_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), INKSCAPE_TYPE_CXYGRID))


/** \brief  All the variables that are tracked for a grid specific
            canvas item. */
struct CXYGrid : public SPCanvasItem{
	NR::Point origin;  /**< Origin of the grid */
	NR::Point spacing; /**< Spacing between elements of the grid */
	guint32 color;     /**< Color for normal lines */
	guint32 empcolor;  /**< Color for emphisis lines */
	gint empspacing;   /**< Spacing between emphisis lines */
	bool scaled[2];    /**< Whether the grid is in scaled mode, which can
					        be different in the X or Y direction, hense two
						    variables */
	NR::Point ow;      /**< Transformed origin by the affine for the zoom */
	NR::Point sw;      /**< Transformed spacing by the affine for the zoom */
};

struct CXYGridClass {
	SPCanvasItemClass parent_class;
};

/* Standard Gtk function */
GtkType cxygrid_get_type (void);

}; /* namespace Inkscape */




#endif