 |
Flutter Impeller
|
|
Go to the documentation of this file.
5 #ifndef FLUTTER_IMPELLER_PLAYGROUND_WIDGETS_H_
6 #define FLUTTER_IMPELLER_PLAYGROUND_WIDGETS_H_
13 #include "third_party/imgui/imgui.h"
15 #define IMPELLER_PLAYGROUND_POINT(default_position, radius, color) \
17 static impeller::Point position = default_position; \
18 static impeller::Point reset_position = default_position; \
19 float radius_ = radius; \
20 impeller::Color color_ = color; \
22 static bool dragging = false; \
23 impeller::Point mouse_pos(ImGui::GetMousePos().x, ImGui::GetMousePos().y); \
24 static impeller::Point prev_mouse_pos = mouse_pos; \
26 if (ImGui::IsKeyPressed(ImGuiKey_R)) { \
27 position = reset_position; \
31 bool hovering = position.GetDistance(mouse_pos) < radius_ && \
32 position.GetDistance(prev_mouse_pos) < radius_; \
33 if (!ImGui::IsMouseDown(0)) { \
35 } else if (hovering && ImGui::IsMouseClicked(0)) { \
39 position += mouse_pos - prev_mouse_pos; \
41 ImGui::GetBackgroundDrawList()->AddCircleFilled( \
42 {position.x, position.y}, radius_, \
43 ImColor(color_.red, color_.green, color_.blue, \
44 (hovering || dragging) ? 0.6f : 0.3f)); \
45 if (hovering || dragging) { \
46 ImGui::GetBackgroundDrawList()->AddText( \
47 {position.x - radius_, position.y + radius_ + 10}, \
48 ImColor(color_.red, color.green, color.blue, 1.0f), \
49 impeller::SPrintF("x:%0.3f y:%0.3f", position.x, position.y) \
52 prev_mouse_pos = mouse_pos; \
56 #define IMPELLER_PLAYGROUND_LINE(default_position_a, default_position_b, \
57 radius, color_a, color_b) \
59 impeller::Point position_a = default_position_a; \
60 impeller::Point position_b = default_position_b; \
62 impeller::Color color_a_ = color_a; \
63 impeller::Color color_b_ = color_b; \
65 position_a = IMPELLER_PLAYGROUND_POINT(position_a, r_, color_a_); \
66 position_b = IMPELLER_PLAYGROUND_POINT(position_b, r_, color_b_); \
68 auto dir = (position_b - position_a).Normalize() * r_; \
69 auto line_a = position_a + dir; \
70 auto line_b = position_b - dir; \
71 ImGui::GetBackgroundDrawList()->AddLine( \
72 {line_a.x, line_a.y}, {line_b.x, line_b.y}, \
73 ImColor(color_b.red, color_b.green, color_b.blue, 0.3f)); \
75 std::make_tuple(position_a, position_b); \
78 #endif // FLUTTER_IMPELLER_PLAYGROUND_WIDGETS_H_