blob: 3e8bc28f381aa1526dbaa5d26f471889bf499a9c (
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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Author:
* Tavmjong Bah
*
* Copyright (C) 2020 Tavmjong Bah
*
* Rewrite of GridCanvasItem.
*
* Released under GNU GPL v2+, read the file 'COPYING' for more information.
*/
#ifndef SEEN_CANVAS_ITEM_GRID_H
#define SEEN_CANVAS_ITEM_GRID_H
#include <cstdint>
#include <2geom/point.h>
#include "canvas-item.h"
#include "preferences.h"
uint32_t constexpr GRID_DEFAULT_MAJOR_COLOR = 0x0099e54d;
uint32_t constexpr GRID_DEFAULT_MINOR_COLOR = 0x0099e526;
namespace Inkscape {
class CanvasItemGrid : public CanvasItem
{
public:
CanvasItemGrid(CanvasItemGroup *group);
// Selection
bool contains(Geom::Point const &p, double tolerance = 0) override;
// Properties
void set_major_color(uint32_t color);
void set_minor_color(uint32_t color);
void set_origin(Geom::Point const &point);
void set_spacing(Geom::Point const &point);
void set_dotted(bool b);
void set_major_line_interval(int n);
void set_no_emp_when_zoomed_out(bool noemp);
protected:
~CanvasItemGrid() override = default;
bool _dotted;
Geom::Point _origin;
Geom::Point _spacing; /**< Spacing between elements of the grid */
int _major_line_interval;
bool _no_emp_when_zoomed_out;
uint32_t _major_color;
uint32_t _minor_color;
private:
std::unique_ptr<Preferences::PreferencesObserver> _pref_tracker;
};
/** Canvas Item for rectangular grids */
class CanvasItemGridXY final : public CanvasItemGrid
{
public:
CanvasItemGridXY(CanvasItemGroup *group);
protected:
friend class GridSnapperXY;
void _update(bool propagate) override;
void _render(CanvasItemBuffer &buf) const override;
bool scaled[2]; /**< Whether the grid is in scaled mode, which can
be different in the X or Y direction, hence two
variables */
Geom::Point ow; /**< Transformed origin by the affine for the zoom */
Geom::Point sw[2]; /**< Transformed spacing by the affine for the zoom */
};
/** Canvas Item for axonometric grids */
class CanvasItemGridAxonom final : public CanvasItemGrid
{
public:
CanvasItemGridAxonom(CanvasItemGroup *group);
// Properties
void set_angle_x(double value);
void set_angle_z(double value);
protected:
friend class GridSnapperAxonom;
void _update(bool propagate) override;
void _render(CanvasItemBuffer &buf) const override;
bool scaled; /**< Whether the grid is in scaled mode */
double angle_deg[3]; /**< Angle of each axis (note that angle[2] == 0) */
double angle_rad[3]; /**< Angle of each axis (note that angle[2] == 0) */
double tan_angle[3]; /**< tan(angle[.]) */
double lyw = 1.0; /**< Transformed length y by the affine for the zoom */
double lxw_x = 1.0;
double lxw_z = 1.0;
double spacing_ylines = 1.0;
Geom::Point ow; /**< Transformed origin by the affine for the zoom */
};
} // namespace Inkscape
#endif // SEEN_CANVAS_ITEM_GRID_H
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
|