Horizon
selectables.hpp
1 #pragma once
2 #include "common/common.hpp"
3 #include "util/uuid.hpp"
4 #include "util/layer_range.hpp"
5 #include <map>
6 #include <set>
7 
8 namespace horizon {
9 class Selectable {
10 public:
11  float x;
12  float y;
13  float c_x;
14  float c_y;
15  float width;
16  float height;
17  float angle;
18  uint8_t flags;
19  enum class Flag { SELECTED = 1, PRELIGHT = 2, ALWAYS = 4, PREVIEW = 8 };
20  bool get_flag(Flag f) const;
21  void set_flag(Flag f, bool v);
22 
23  Selectable(const Coordf &center, const Coordf &box_center, const Coordf &box_dim, float angle = 0,
24  bool always = false);
25  bool inside(const Coordf &c, float expand = 0) const;
26  float area() const;
27  bool is_line() const;
28  bool is_point() const;
29  bool is_box() const;
30  std::array<Coordf, 4> get_corners() const;
31 } __attribute__((packed));
32 
34 public:
35  UUID uuid;
36  ObjectType type;
37  unsigned int vertex;
38  LayerRange layer;
39  SelectableRef(const UUID &uu, ObjectType ty, unsigned int v = 0, LayerRange la = 10000)
40  : uuid(uu), type(ty), vertex(v), layer(la)
41  {
42  }
43  bool operator<(const SelectableRef &other) const
44  {
45  if (type < other.type) {
46  return true;
47  }
48  if (type > other.type) {
49  return false;
50  }
51  if (uuid < other.uuid) {
52  return true;
53  }
54  else if (uuid > other.uuid) {
55  return false;
56  }
57  return vertex < other.vertex;
58  }
59  bool operator==(const SelectableRef &other) const
60  {
61  return (uuid == other.uuid) && (vertex == other.vertex) && (type == other.type);
62  }
63 };
64 
65 class Selectables {
66  friend class Canvas;
67  friend class CanvasGL;
68  friend class DragSelection;
69  friend class SelectablesRenderer;
70 
71 public:
72  Selectables(const class Canvas &ca);
73  void clear();
74  void append(const UUID &uu, ObjectType ot, const Coordf &center, const Coordf &a, const Coordf &b,
75  unsigned int vertex = 0, LayerRange layer = 10000, bool always = false);
76  void append(const UUID &uu, ObjectType ot, const Coordf &center, unsigned int vertex = 0, LayerRange layer = 10000,
77  bool always = false);
78  void append_angled(const UUID &uu, ObjectType ot, const Coordf &center, const Coordf &box_center,
79  const Coordf &box_dim, float angle, unsigned int vertex = 0, LayerRange layer = 10000,
80  bool always = false);
81  void append_line(const UUID &uu, ObjectType ot, const Coordf &p0, const Coordf &p1, float width,
82  unsigned int vertex = 0, LayerRange layer = 10000, bool always = false);
83  void update_preview(const std::set<SelectableRef> &sel);
84 
85  void group_begin();
86  void group_end();
87 
88 private:
89  const Canvas &ca;
90  std::vector<Selectable> items;
91  std::vector<SelectableRef> items_ref;
92  std::map<SelectableRef, unsigned int> items_map;
93  std::vector<int> items_group;
94 
95  int group_max = 0;
96  int group_current = -1;
97 };
98 } // namespace horizon
horizon::LayerRange
Definition: layer_range.hpp:7
horizon::Selectables
Definition: selectables.hpp:65
horizon::SelectablesRenderer
Definition: selectables_renderer.hpp:5
horizon::Selectable
Definition: selectables.hpp:9
libzip::uint8_t
zip_uint8_t uint8_t
zip_uint8_t typedef.
Definition: zip.hpp:78
horizon::CanvasGL
Definition: canvas_gl.hpp:18
horizon::DragSelection
Definition: drag_selection.hpp:8
horizon::Canvas
Definition: canvas.hpp:22
horizon::Coord< float >
horizon::SelectableRef
Definition: selectables.hpp:33
horizon::UUID
This class encapsulates a UUID and allows it to be uses as a value type.
Definition: uuid.hpp:16