 |
Flutter Impeller
|
|
Go to the documentation of this file.
12 #include "third_party/imgui/imgui.h"
14 #define IMPELLER_PLAYGROUND_POINT(default_position, radius, color) \
16 static impeller::Point position = default_position; \
17 static impeller::Point reset_position = default_position; \
18 float radius_ = radius; \
19 impeller::Color color_ = color; \
21 static bool dragging = false; \
22 impeller::Point mouse_pos(ImGui::GetMousePos().x, ImGui::GetMousePos().y); \
23 static impeller::Point prev_mouse_pos = mouse_pos; \
25 if (ImGui::IsKeyPressed(ImGuiKey_R)) { \
26 position = reset_position; \
30 bool hovering = position.GetDistance(mouse_pos) < radius_ && \
31 position.GetDistance(prev_mouse_pos) < radius_; \
32 if (!ImGui::IsMouseDown(0)) { \
34 } else if (hovering && ImGui::IsMouseClicked(0)) { \
38 position += mouse_pos - prev_mouse_pos; \
40 ImGui::GetBackgroundDrawList()->AddCircleFilled( \
41 {position.x, position.y}, radius_, \
42 ImColor(color_.red, color_.green, color_.blue, \
43 (hovering || dragging) ? 0.6f : 0.3f)); \
44 if (hovering || dragging) { \
45 ImGui::GetBackgroundDrawList()->AddText( \
46 {position.x - radius_, position.y + radius_ + 10}, \
47 ImColor(color_.red, color.green, color.blue, 1.0f), \
48 impeller::SPrintF("x:%0.3f y:%0.3f", position.x, position.y) \
51 prev_mouse_pos = mouse_pos; \
55 #define IMPELLER_PLAYGROUND_LINE(default_position_a, default_position_b, \
56 radius, color_a, color_b) \
58 impeller::Point position_a = default_position_a; \
59 impeller::Point position_b = default_position_b; \
61 impeller::Color color_a_ = color_a; \
62 impeller::Color color_b_ = color_b; \
64 position_a = IMPELLER_PLAYGROUND_POINT(position_a, r_, color_a_); \
65 position_b = IMPELLER_PLAYGROUND_POINT(position_b, r_, color_b_); \
67 auto dir = (position_b - position_a).Normalize() * r_; \
68 auto line_a = position_a + dir; \
69 auto line_b = position_b - dir; \
70 ImGui::GetBackgroundDrawList()->AddLine( \
71 {line_a.x, line_a.y}, {line_b.x, line_b.y}, \
72 ImColor(color_b.red, color_b.green, color_b.blue, 0.3f)); \
74 std::make_tuple(position_a, position_b); \