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