Flutter Engine
The Flutter Engine
widgets.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7namespace impeller {
8
10 if (ImGui::GetCurrentContext()) {
11 impeller::Point mouse_pos(ImGui::GetMousePos().x, ImGui::GetMousePos().y);
12 if (!point.prev_mouse_pos.has_value()) {
13 point.prev_mouse_pos = mouse_pos;
14 }
15
16 if (ImGui::IsKeyPressed(ImGuiKey_R)) {
17 point.position = point.reset_position;
18 point.dragging = false;
19 }
20
21 bool hovering =
22 point.position.GetDistance(mouse_pos) < point.radius &&
23 point.position.GetDistance(point.prev_mouse_pos.value()) < point.radius;
24 if (!ImGui::IsMouseDown(0)) {
25 point.dragging = false;
26 } else if (hovering && ImGui::IsMouseClicked(0)) {
27 point.dragging = true;
28 }
29 if (point.dragging) {
30 point.position += mouse_pos - point.prev_mouse_pos.value();
31 }
32 ImGui::GetBackgroundDrawList()->AddCircleFilled(
33 {point.position.x, point.position.y}, point.radius,
34 ImColor(point.color.red, point.color.green, point.color.blue,
35 (hovering || point.dragging) ? 0.6f : 0.3f));
36 if (hovering || point.dragging) {
37 ImGui::GetBackgroundDrawList()->AddText(
38 {point.position.x - point.radius,
39 point.position.y + point.radius + 10},
40 ImColor(point.color.red, point.color.green, point.color.blue, 1.0f),
41 impeller::SPrintF("x:%0.3f y:%0.3f", point.position.x,
42 point.position.y)
43 .c_str());
44 }
45 point.prev_mouse_pos = mouse_pos;
46 }
47 return point.position;
48}
49
50std::tuple<Point, Point> DrawPlaygroundLine(PlaygroundPoint& point_a,
51 PlaygroundPoint& point_b) {
52 Point position_a = DrawPlaygroundPoint(point_a);
53 Point position_b = DrawPlaygroundPoint(point_b);
54
55 if (ImGui::GetCurrentContext()) {
56 auto dir = (position_b - position_a).Normalize() * point_a.radius;
57 auto line_a = position_a + dir;
58 auto line_b = position_b - dir;
59 ImGui::GetBackgroundDrawList()->AddLine(
60 {line_a.x, line_a.y}, {line_b.x, line_b.y},
61 ImColor(point_b.color.red, point_b.color.green, point_b.color.blue,
62 0.3f));
63 }
64 return std::make_tuple(position_a, position_b);
65}
66//
67
68} // namespace impeller
double y
double x
static void Normalize(char *s)
Definition: flags.cc:296
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
Point DrawPlaygroundPoint(PlaygroundPoint &point)
Definition: widgets.cc:9
std::tuple< Point, Point > DrawPlaygroundLine(PlaygroundPoint &point_a, PlaygroundPoint &point_b)
Definition: widgets.cc:50
std::string SPrintF(const char *format,...)
Definition: strings.cc:12
Scalar blue
Definition: color.h:138
Scalar red
Definition: color.h:128
Scalar green
Definition: color.h:133
std::optional< Point > prev_mouse_pos
Definition: widgets.h:26
constexpr Type GetDistance(const TPoint &p) const
Definition: point.h:200