Horizon
tool_draw_polygon_rectangle.hpp
1 #pragma once
2 #include "core/tool.hpp"
3 
4 namespace horizon {
5 
7 public:
8  using ToolBase::ToolBase;
9  ToolResponse begin(const ToolArgs &args) override;
10  ToolResponse update(const ToolArgs &args) override;
11  bool can_begin() override;
12 
13  class Settings : public ToolSettings {
14  public:
15  json serialize() const override;
16  void load_from_json(const json &j) override;
17  enum class Mode { CENTER, CORNER };
18  Mode mode = Mode::CENTER;
19  };
20 
21  const ToolSettings *get_settings_const() const override
22  {
23  return &settings;
24  }
25 
26  void apply_settings() override;
27 
28  std::set<InToolActionID> get_actions() const override
29  {
30  using I = InToolActionID;
31  return {
32  I::LMB,
33  I::CANCEL,
34  I::RMB,
35  I::RECTANGLE_MODE,
36  I::POLYGON_CORNER_RADIUS,
37  I::POLYGON_DECORATION_POSITION,
38  I::POLYGON_DECORATION_SIZE,
39  I::POLYGON_DECORATION_STYLE,
40  };
41  }
42 
43 protected:
44  ToolSettings *get_settings() override
45  {
46  return &settings;
47  }
48 
49 private:
50  Settings settings;
51 
52  enum class Decoration { NONE, CHAMFER, NOTCH };
53 
54  Decoration decoration = Decoration::NONE;
55  int decoration_pos = 0;
56  Coordi first_pos;
57  Coordi second_pos;
58  int step = 0;
59  uint64_t decoration_size = 1_mm;
60  int64_t corner_radius = 0;
61 
62  class Polygon *temp = nullptr;
63 
64  void update_polygon();
65  void update_tip();
66 };
67 } // namespace horizon
This is what a Tool receives when the user did something.
Definition: tool.hpp:23
Common interface for all Tools.
Definition: tool.hpp:121
Definition: tool_draw_polygon_rectangle.hpp:13
Definition: tool_draw_polygon_rectangle.hpp:6
ToolResponse begin(const ToolArgs &args) override
Gets called right after the constructor has finished.
Definition: tool_draw_polygon_rectangle.cpp:171
ToolResponse update(const ToolArgs &args) override
Gets called whenever the user generated some sort of input.
Definition: tool_draw_polygon_rectangle.cpp:225
bool can_begin() override
Definition: tool_draw_polygon_rectangle.cpp:28
To signal back to the core what the Tool did, a Tool returns a ToolResponse.
Definition: tool.hpp:42
Definition: tool.hpp:84
a class to store JSON values
Definition: json.hpp:166
zip_uint64_t uint64_t
zip_uint64_t_t typedef.
Definition: zip.hpp:108
zip_int64_t int64_t
zip_int64_t typedef.
Definition: zip.hpp:103