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