Horizon
Loading...
Searching...
No Matches
canvas_gl.hpp
1#pragma once
2#include "canvas.hpp"
3#include "drag_selection.hpp"
4#include "grid.hpp"
5#include "marker.hpp"
6#include "triangle_renderer.hpp"
7#include "selectables_renderer.hpp"
8#include "util/msd_animator.hpp"
9#include <gtkmm.h>
10#include <glm/glm.hpp>
11#include "appearance.hpp"
12#include "annotation.hpp"
13#include "snap_filter.hpp"
14#include "picture_renderer.hpp"
15#include "selection_filter.hpp"
16#include "input_devices_prefs.hpp"
17#include "util/scroll_direction.hpp"
18
19namespace horizon {
20class CanvasGL : public Canvas, public Gtk::GLArea {
21 friend Grid;
22 friend DragSelection;
23 friend SelectablesRenderer;
24 friend TriangleRenderer;
25 friend MarkerRenderer;
26 friend Markers;
27 friend CanvasAnnotation;
28 friend PictureRenderer;
29
30public:
31 CanvasGL();
32
33 enum class SelectionMode { HOVER, NORMAL };
34 void set_selection_mode(SelectionMode mode);
35 SelectionMode get_selection_mode() const;
36 typedef sigc::signal<void, SelectionMode> type_signal_selection_mode_changed;
37 type_signal_selection_mode_changed signal_selection_mode_changed()
38 {
39 return s_signal_selection_mode_changed;
40 }
41
42 enum class SelectionTool { BOX, LASSO, PAINT };
43 SelectionTool selection_tool = SelectionTool::BOX;
44
45 enum class SelectionQualifier { INCLUDE_ORIGIN, INCLUDE_BOX, TOUCH_BOX, AUTO };
46 SelectionQualifier selection_qualifier = SelectionQualifier::INCLUDE_ORIGIN;
47
48 enum class SelectionModifierAction { TOGGLE, ADD, REMOVE };
49 SelectionModifierAction selection_modifier_action = SelectionModifierAction::TOGGLE;
50
51 bool selection_sticky = false;
52
53 enum class HighlightMode { HIGHLIGHT, DIM, SHADOW };
54 void set_highlight_mode(HighlightMode mode);
55 HighlightMode get_highlight_mode() const;
56 void set_highlight_enabled(bool x);
57 void set_highlight_on_top(bool on_top);
58
59 enum class LayerMode { AS_IS, WORK_ONLY, SHADOW_OTHER };
60 void set_layer_mode(LayerMode mode);
61
62 std::set<SelectableRef> get_selection() const;
63 void set_selection(const std::set<SelectableRef> &sel, bool emit = true);
64 void select_all();
65 void set_cursor_pos(const Coordi &c);
66 void set_cursor_external(bool v);
67 Coordi get_cursor_pos() const;
68 Coordf get_cursor_pos_win() const;
69 Target get_current_target() const;
70 void set_selection_allowed(bool a);
71 std::pair<float, Coordf> get_scale_and_offset() const;
72 void set_scale_and_offset(float sc, Coordf ofs);
73 Coordi snap_to_grid(const Coordi &c, unsigned int div = 1) const;
74
75 void set_flip_view(bool fl);
76 bool get_flip_view() const override;
77
78 void set_view_angle(float a);
79 float get_view_angle() const override;
80
81 void set_cursor_size(float size);
82 void set_cursor_size(Appearance::CursorSize);
83
84 void clear() override;
85
86 typedef sigc::signal<void> type_signal_selection_changed;
87 type_signal_selection_changed signal_selection_changed()
88 {
89 return s_signal_selection_changed;
90 }
91
92 type_signal_selection_changed signal_hover_selection_changed()
93 {
94 return s_signal_hover_selection_changed;
95 }
96
97 typedef sigc::signal<void, const Coordi &> type_signal_cursor_moved;
98 type_signal_cursor_moved signal_cursor_moved()
99 {
100 return s_signal_cursor_moved;
101 }
102
103 typedef sigc::signal<void, unsigned int> type_signal_grid_mul_changed;
104 type_signal_grid_mul_changed signal_grid_mul_changed()
105 {
106 return s_signal_grid_mul_changed;
107 }
108 unsigned int get_grid_mul() const
109 {
110 return grid.mul;
111 }
112
113 typedef sigc::signal<std::string, const SelectableRef &> type_signal_request_display_name;
114 type_signal_request_display_name signal_request_display_name()
115 {
116 return s_signal_request_display_name;
117 }
118
119 typedef sigc::signal<void, bool &> type_signal_can_steal_focus;
120 type_signal_can_steal_focus signal_can_steal_focus()
121 {
122 return s_signal_can_steal_focus;
123 }
124
125 typedef sigc::signal<void> type_signal_scale_changed;
126 type_signal_scale_changed signal_scale_changed()
127 {
128 return s_signal_scale_changed;
129 }
130
131 void center_and_zoom(const Coordf &center, float scale = -1);
132 void zoom_to_bbox(const Coordf &a, const Coordf &b);
133 void zoom_to_bbox(const std::pair<Coordf, Coordf> &bb);
134 void ensure_min_size(float w, float h);
135 void zoom_to(const Coordf &c, float inc);
136
137 Glib::PropertyProxy<int> property_work_layer()
138 {
139 return p_property_work_layer.get_proxy();
140 }
141 Glib::PropertyProxy<float> property_layer_opacity()
142 {
143 return p_property_layer_opacity.get_proxy();
144 }
145 Glib::PropertyProxy_ReadOnly<float> property_layer_opacity() const
146 {
147 return Glib::PropertyProxy_ReadOnly<float>(this, "layer-opacity");
148 }
149 Markers markers;
150 void update_markers() override;
151
152 std::set<SelectableRef> get_selection_at(const Coordi &c) const;
153 Coordf screen2canvas(const Coordf &p) const;
154 void update_cursor_pos(double x, double y);
155
156 const Appearance &get_appearance() const;
157 void set_appearance(const Appearance &a);
158 const Color &get_color(ColorP colorp) const;
159
160 bool touchpad_pan = false;
161
162 bool smooth_zoom = true;
163 bool snap_to_targets = true;
164
165 float zoom_base = 1.5;
166
167 void inhibit_drag_selection();
168
169 int _animate_step(GdkFrameClock *frame_clock);
170
171 float get_width() const
172 {
173 return m_width;
174 }
175 float get_height() const
176 {
177 return m_height;
178 }
179
180 CanvasAnnotation *create_annotation();
181 void remove_annotation(CanvasAnnotation *a);
182 bool layer_is_annotation(int l) const;
183
184 std::set<SnapFilter> snap_filter;
185
186 void set_grid_spacing(uint64_t x, uint64_t y);
187 void set_grid_spacing(uint64_t s);
188 Coordi get_grid_spacing() const;
189 void set_grid_origin(const Coordi &c);
190
191 SelectionFilter selection_filter;
192
193 bool layer_is_visible(int layer) const;
194 bool layer_is_visible(LayerRange layer) const;
195
196 void set_colors2(const std::vector<ColorI> &c);
197
198 int get_last_grid_div() const;
199
200 void append_target(const Target &target);
201
202 void set_msd_params(const MSD::Params &params);
203
204 bool show_pictures = true;
205
206 InputDevicesPrefs input_devices_prefs;
207
208protected:
209 void push() override;
210 void request_push() override;
211
212private:
213 static const int MAT3_XX = 0;
214 static const int MAT3_X0 = 2;
215 static const int MAT3_YY = 4;
216 static const int MAT3_Y0 = 5;
217
218 float m_width, m_height;
219 glm::mat3 screenmat;
220 float scale = 1e-5;
221 Coord<float> offset;
222 glm::mat3 viewmat;
223 glm::mat3 viewmat_noflip;
224 bool flip_view = false;
225 float view_angle = 0;
226 void update_viewmat();
227 Coordf canvas2screen(const Coordf &p) const;
228
229 Coord<float> cursor_pos;
230 Coord<int64_t> cursor_pos_grid;
231 bool cursor_external = false;
232
233 GLuint renderbuffer;
234 GLuint stencilrenderbuffer;
235 GLuint fbo;
236 bool needs_resize = false;
237 enum PushFilter {
238 PF_NONE = 0,
239 PF_TRIANGLES = (1 << 0),
240 PF_CURSOR = (1 << 1),
241 PF_SELECTABLES = (1 << 2),
242 PF_MARKER = (1 << 3),
243 PF_DRAG_SELECTION = (1 << 4),
244 PF_ALL = 0xff
245 };
246 PushFilter push_filter = PF_ALL;
247 void request_push(PushFilter filter);
248
249 void resize_buffers();
250
251 Grid grid;
252 DragSelection drag_selection;
253 SelectablesRenderer selectables_renderer;
254 TriangleRenderer triangle_renderer;
255
256 MarkerRenderer marker_renderer;
257
258 PictureRenderer picture_renderer;
259
260 enum class ZoomTo { CURSOR, CENTER };
261
262 void pan_drag_begin(GdkEventButton *button_event);
263 void pan_drag_end(GdkEventButton *button_event);
264 void pan_drag_move(GdkEventMotion *motion_event);
265 void pan_drag_move(GdkEventScroll *scroll_event, ScrollDirection scroll_direction);
266 void pan_zoom(GdkEventScroll *scroll_event, ZoomTo zoom_to, ScrollDirection scroll_direction);
267 void start_smooth_zoom(const Coordf &c, float inc);
268 void cursor_move(GdkEvent *motion_event);
269 void hover_prelight_update(GdkEvent *motion_event);
270 bool pan_dragging = false;
271 Coord<float> pan_pointer_pos_orig;
272 Coord<float> pan_offset_orig;
273
274 void set_scale(float x, float y, float new_scale);
275
276 bool selection_allowed = true;
277 Glib::Property<int> p_property_work_layer;
278 Glib::Property<float> p_property_layer_opacity;
279
280 Gtk::Menu *clarify_menu;
281
282 HighlightMode highlight_mode = HighlightMode::HIGHLIGHT;
283 bool highlight_enabled = false;
284 bool highlight_on_top = false;
285 Appearance appearance;
286
287 LayerMode layer_mode = LayerMode::AS_IS;
288
289 bool drag_selection_inhibited = false;
290
291 MSDAnimator zoom_animator;
292 float zoom_animation_scale_orig = 1;
293 Coordf zoom_animation_pos;
294
295 Gdk::ModifierType grid_fine_modifier = Gdk::MOD1_MASK;
296 float cursor_size = 20;
297
298 static const int first_annotation_layer = 20000;
299 int annotation_layer_current = first_annotation_layer;
300 std::map<int, CanvasAnnotation> annotations;
301
302 void draw_bitmap_text(const Coordf &p, float scale, const std::string &rtext, int angle, ColorP color,
303 int layer) override;
304 std::pair<Coordf, Coordf> measure_bitmap_text(const std::string &text) const override;
305 void draw_bitmap_text_box(const Placement &q, float width, float height, const std::string &s, ColorP color,
306 int layer, TextBoxMode mode) override;
307
308 SelectionMode selection_mode = SelectionMode::HOVER;
309
310 Glib::RefPtr<Gtk::GestureZoom> gesture_zoom;
311 void zoom_gesture_begin_cb(GdkEventSequence *seq);
312 void zoom_gesture_update_cb(GdkEventSequence *seq);
313 Coord<float> gesture_zoom_pos_orig;
314 Coord<float> gesture_zoom_offset_orig;
315 float gesture_zoom_scale_orig = 1;
316
317 Glib::RefPtr<Gtk::GestureDrag> gesture_drag;
318 Coord<float> gesture_drag_offset_orig;
319
320 void drag_gesture_begin_cb(GdkEventSequence *seq);
321 void drag_gesture_update_cb(GdkEventSequence *seq);
322
323 bool can_snap_to_target(const Target &t) const;
324
325 std::vector<ColorI> colors2;
326
327 bool can_set_scale() const;
328
329 int last_grid_div = 1;
330
331protected:
332 void on_size_allocate(Gtk::Allocation &alloc) override;
333 void on_realize() override;
334 bool on_render(const Glib::RefPtr<Gdk::GLContext> &context) override;
335 bool on_button_press_event(GdkEventButton *button_event) override;
336 bool on_button_release_event(GdkEventButton *button_event) override;
337 bool on_motion_notify_event(GdkEventMotion *motion_event) override;
338 bool on_scroll_event(GdkEventScroll *scroll_event) override;
339 Glib::RefPtr<Gdk::GLContext> on_create_context() override;
340
341 type_signal_selection_changed s_signal_selection_changed;
342 type_signal_selection_changed s_signal_hover_selection_changed;
343 type_signal_selection_mode_changed s_signal_selection_mode_changed;
344 type_signal_cursor_moved s_signal_cursor_moved;
345 type_signal_grid_mul_changed s_signal_grid_mul_changed;
346 type_signal_request_display_name s_signal_request_display_name;
347 type_signal_can_steal_focus s_signal_can_steal_focus;
348 type_signal_scale_changed s_signal_scale_changed;
349};
350} // namespace horizon
Definition appearance.hpp:7
Definition common.hpp:278
Your typical coordinate class.
Definition common.hpp:88
Definition input_devices_prefs.hpp:6
Definition layer_range.hpp:11
Definition msd_animator.hpp:5
Definition placement.hpp:8
Definition target.hpp:7
Definition msd.hpp:13