19 #ifndef INC_C4ConsoleQtShapes
20 #define INC_C4ConsoleQtShapes
29 class C4ConsoleQtShape :
public QObject
36 int32_t dragging_border, selected_border;
37 uint32_t border_color;
38 const class C4PropertyDelegateShape *parent_delegate;
39 class C4ConsoleQtShapes *shape_list;
43 uint32_t GetBorderColor(int32_t border_index,
bool dragging_border_is_bitmask, uint32_t default_color = 0u)
const;
45 C4ConsoleQtShape(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
47 virtual bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border,
bool shift_down,
bool ctrl_down) = 0;
48 virtual void Draw(
class C4TargetFacet &cgo,
float line_width) = 0;
51 int32_t AbsX(int32_t rel_x=0)
const;
52 int32_t AbsY(int32_t rel_y=0)
const;
55 virtual bool StartDragging(int32_t *border, int32_t x, int32_t y,
bool shift_down,
bool ctrl_down) { dragging_border = *border;
return true; }
56 virtual void StopDragging();
57 virtual void Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_t hit_range, Qt::CursorShape *drag_cursor) = 0;
58 bool IsDragging()
const {
return dragging_border != -1; }
60 virtual void SetValue(
const C4Value &val) = 0;
61 virtual C4Value GetValue()
const = 0;
63 const class C4PropertyDelegateShape *GetParentDelegate()
const {
return parent_delegate; }
66 virtual bool IsSelectionAllowed(int32_t border)
const {
return false; }
67 bool Select(int32_t border);
68 void ResetSelection();
75 virtual class C4ConsoleQtGraph *GetGraphShape() {
return nullptr; }
79 void BorderSelectionChanged();
83 class C4ConsoleQtRect :
public C4ConsoleQtShape
87 bool store_as_proplist;
88 bool properties_lowercase;
90 C4ConsoleQtRect(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
92 bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border,
bool shift_down,
bool ctrl_down)
override;
93 void Draw(
class C4TargetFacet &cgo,
float line_width)
override;
94 void Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_t hit_range, Qt::CursorShape *drag_cursor)
override;
96 void SetValue(
const C4Value &val)
override;
97 C4Value GetValue()
const override;
101 class C4ConsoleQtCircle :
public C4ConsoleQtShape
106 bool can_move_center;
108 C4ConsoleQtCircle(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
110 bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border,
bool shift_down,
bool ctrl_down)
override;
111 void Draw(
class C4TargetFacet &cgo,
float line_width)
override;
112 void Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_t hit_range, Qt::CursorShape *drag_cursor)
override;
114 void SetValue(
const C4Value &val)
override;
115 C4Value GetValue()
const override;
119 class C4ConsoleQtPoint :
public C4ConsoleQtShape
123 bool horizontal_fix{
false };
124 bool vertical_fix{
false };
126 C4ConsoleQtPoint(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
128 bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border,
bool shift_down,
bool ctrl_down)
override;
129 void Draw(
class C4TargetFacet &cgo,
float line_width)
override;
130 void Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_t hit_range, Qt::CursorShape *drag_cursor)
override;
132 void SetValue(
const C4Value &val)
override;
133 C4Value GetValue()
const override;
137 class C4ConsoleQtGraph :
public C4ConsoleQtShape
151 int32_t vertex_indices[2];
153 uint32_t line_thickness{1};
155 Edge() { vertex_indices[0] = vertex_indices[1] = -1; }
156 bool connects_to(int32_t vertex_index)
const;
157 bool connects_to(int32_t vertex_index, int32_t *idx)
const;
163 std::vector<Vertex> vertices;
164 std::vector<Edge> edges;
172 int32_t GetEdgeCountForVertex(int32_t vertex_index)
const;
175 void SetVertexPos(int32_t vertex_index, int32_t new_x, int32_t new_y);
176 void EditEdge(int32_t edge_index, int32_t change_vertex_index, int32_t new_vertex_index);
177 void InsertEdgeBefore(int32_t insert_edge_index, int32_t vertex1, int32_t vertex2);
178 void InsertVertexBefore(int32_t insert_vertex_index, int32_t x, int32_t y);
179 void RemoveEdge(int32_t edge_index);
180 void RemoveVertex(int32_t vertex_index);
183 static void EditGraphValue_SetVertexPos(
C4ValueArray *vvertices, int32_t vertex_index, int32_t new_x, int32_t new_y);
184 static void EditGraphValue_EditEdge(
C4ValueArray *vvertices,
C4ValueArray *vedges, int32_t edge_index, int32_t change_vertex_index, int32_t new_vertex_index);
185 static void EditGraphValue_InsertEdgeBefore(
C4ValueArray *vvertices,
C4ValueArray *vedges, int32_t insert_edge_index, int32_t vertex1, int32_t vertex2);
186 static void EditGraphValue_InsertVertexBefore(
C4ValueArray *vvertices,
C4ValueArray *vedges, int32_t insert_vertex_index, int32_t x, int32_t y);
189 static bool EditGraphValue_EdgeConnectsTo(
C4PropList *edge, int32_t vertex_index);
192 bool allow_vertex_selection =
false;
193 bool allow_edge_selection =
false;
194 bool horizontal_fix =
false;
195 bool vertical_fix =
false;
196 bool structure_fix =
false;
197 bool draw_arrows =
false;
199 C4Value vertex_delegate, edge_delegate;
202 int32_t drag_snap_offset_x = 0, drag_snap_offset_y = 0;
203 bool drag_snapped =
false;
204 int32_t drag_snap_vertex = -1, drag_source_vertex_index = -1;
207 static bool IsVertexDrag(int32_t border) {
return border >= 0; }
208 static bool IsEdgeDrag(int32_t border) {
return border < -1; }
209 static int32_t DragBorderToVertex(int32_t border) {
return border; }
210 static int32_t DragBorderToEdge(int32_t border) {
return -2 - border; }
211 static int32_t VertexToDragBorder(int32_t vertex) {
return vertex; }
212 static int32_t EdgeToDragBorder(int32_t edge) {
return -edge - 2; }
214 void DrawEdge(
class C4TargetFacet &cgo,
const Vertex &v0,
const Vertex &v2, uint32_t clr,
float line_width,
float edge_width,
bool highlight);
216 C4ConsoleQtGraph(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
218 bool IsHit(int32_t x, int32_t y, int32_t hit_range, Qt::CursorShape *drag_cursor, int32_t *drag_border,
bool shift_down,
bool ctrl_down)
override;
219 void Draw(
class C4TargetFacet &cgo,
float line_width)
override;
220 void Drag(int32_t x, int32_t y, int32_t dx, int32_t dy, int32_t hit_range, Qt::CursorShape *drag_cursor)
override;
221 bool StartDragging(int32_t *border, int32_t x, int32_t y,
bool shift_down,
bool ctrl_down)
override;
222 void StopDragging()
override;
224 void SetValue(
const C4Value &val)
override;
225 C4Value GetValue()
const override;
227 bool IsSelectionAllowed(int32_t border)
const override;
233 class C4ConsoleQtGraph *GetGraphShape()
override {
return this; }
236 void EditEdge(int32_t edge_index, int32_t change_vertex_index, int32_t new_vertex);
237 int32_t AddVertex(int32_t new_x, int32_t new_y);
238 int32_t AddEdge(int32_t connect_vertex_index_1, int32_t connect_vertex_index_2);
239 void InsertVertexBefore(int32_t insert_vertex_index, int32_t x, int32_t y);
240 void InsertEdgeBefore(int32_t insert_edge_index, int32_t connect_vertex_index_1, int32_t connect_vertex_index_2);
241 virtual int32_t InsertVertexOnEdge(int32_t split_edge_index, int32_t x, int32_t y);
242 virtual int32_t InsertVertexOnVertex(int32_t target_vertex_index, int32_t x, int32_t y);
243 virtual void RemoveEdge(int32_t edge_index);
244 virtual void RemoveVertex(int32_t vertex_index,
bool create_skip_connection);
246 virtual bool IsPolyline()
const {
return false; }
249 virtual bool IsVertexHit(int32_t vertex_index, Qt::CursorShape *drag_cursor,
bool shift_down,
bool ctrl_down);
250 virtual bool IsEdgeHit(int32_t edge_index, Qt::CursorShape *drag_cursor,
bool shift_down,
bool ctrl_down);
257 class C4ConsoleQtPolyline :
public C4ConsoleQtGraph
260 bool start_from_object =
false;
262 C4ConsoleQtPolyline(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list);
264 void Draw(
class C4TargetFacet &cgo,
float line_width)
override;
265 void SetValue(
const C4Value &val)
override;
266 C4Value GetValue()
const override;
269 int32_t InsertVertexOnEdge(int32_t split_edge_index, int32_t x, int32_t y)
override;
270 int32_t InsertVertexOnVertex(int32_t target_vertex_index, int32_t x, int32_t y)
override;
271 void RemoveEdge(int32_t edge_index)
override;
273 bool IsVertexHit(int32_t vertex_index, Qt::CursorShape *drag_cursor,
bool shift_down,
bool ctrl_down)
override;
274 bool IsPolyline()
const override {
return true; }
278 class C4ConsoleQtPolygon :
public C4ConsoleQtPolyline
281 C4ConsoleQtPolygon(
class C4Object *for_obj,
C4PropList *props,
const class C4PropertyDelegateShape *parent_delegate,
class C4ConsoleQtShapes *shape_list)
282 : C4ConsoleQtPolyline(for_obj, props, parent_delegate, shape_list) {}
284 void SetValue(
const C4Value &val)
override;
287 int32_t InsertVertexOnEdge(int32_t split_edge_index, int32_t x, int32_t y)
override;
288 int32_t InsertVertexOnVertex(int32_t target_vertex_index, int32_t x, int32_t y)
override;
289 void RemoveEdge(int32_t edge_index)
override;
291 bool IsVertexHit(int32_t vertex_index, Qt::CursorShape *drag_cursor,
bool shift_down,
bool ctrl_down)
override;
295 class C4ConsoleQtShapes
297 typedef std::list<std::unique_ptr<C4ConsoleQtShape> > ShapeList;
299 C4ConsoleQtShape *dragging_shape{
nullptr}, *selected_shape{
nullptr};
300 Qt::CursorShape drag_cursor{Qt::CursorShape::ArrowCursor};
301 float drag_x{0}, drag_y{0};
303 C4ConsoleQtShapes() =
default;
305 C4ConsoleQtShape *CreateShape(
class C4Object *for_obj,
C4PropList *props,
const C4Value &val,
const class C4PropertyDelegateShape *parent_delegate);
306 void AddShape(C4ConsoleQtShape *shape);
307 void RemoveShape(C4ConsoleQtShape *shape);
311 bool MouseDown(
float x,
float y,
float hit_range,
bool shift_down,
bool ctrl_down);
312 void MouseMove(
float x,
float y,
bool left_down,
float hit_range,
bool shift_down,
bool ctrl_down);
313 void MouseUp(
float x,
float y,
bool shift_down,
bool ctrl_down);
318 bool HasDragCursor()
const {
return drag_cursor != Qt::CursorShape::ArrowCursor; }
319 Qt::CursorShape GetDragCursor()
const {
return drag_cursor; }
320 bool IsDragging()
const {
return !!dragging_shape; }
323 void SetSelectedShape(C4ConsoleQtShape *new_selection, int32_t selected_border);
324 C4ConsoleQtShape *GetSelectedShape()
const {
return selected_shape; }
329 class C4ConsoleQtShapeHolder
331 C4ConsoleQtShape *shape{
nullptr};
335 static bool last_visit_flag;
338 C4ConsoleQtShapeHolder() =
default;
339 ~C4ConsoleQtShapeHolder() { Clear(); }
342 void Set(C4ConsoleQtShape *new_shape);
343 C4ConsoleQtShape *Get()
const {
return shape; }
346 void visit() { last_visit = last_visit_flag; }
347 bool was_visited()
const {
return last_visit == last_visit_flag; }
348 static void begin_visit() { last_visit_flag = !last_visit_flag; }
351 const C4Value &GetLastValue()
const {
return last_value; }
352 void SetLastValue(
const C4Value &new_val) { last_value = new_val; }
C4PropList * getPropList() const
void MouseMove(int32_t iButton, int32_t iX, int32_t iY, DWORD dwKeyParam, class C4Viewport *pVP)