Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
ImGui::DragCanvas Struct Reference

#include <ImGuiLayer.h>

Public Member Functions

 DragCanvas (const void *id, SkPoint tl={ 0.0f, 0.0f }, SkPoint br={ 1.0f, 1.0f }, float aspect=-1.0f)
 
 ~DragCanvas ()
 
void fillColor (ImU32 color)
 
void dragPoint (SkPoint *p, bool tooltip=false, ImU32 color=0xFFFFFFFF)
 

Public Attributes

ImDrawList * fDrawList
 
ImVec2 fPos
 
ImVec2 fSize
 
skia_private::STArray< 4, ImVec2, true > fScreenPoints
 
SkMatrix fLocalToScreen
 
SkMatrix fScreenToLocal
 
int fID
 
bool fDragging
 

Detailed Description

Definition at line 38 of file ImGuiLayer.h.

Constructor & Destructor Documentation

◆ DragCanvas()

ImGui::DragCanvas::DragCanvas ( const void *  id,
SkPoint  tl = { 0.0f, 0.0f },
SkPoint  br = { 1.0f, 1.0f },
float  aspect = -1.0f 
)
inline

Definition at line 39 of file ImGuiLayer.h.

39 { 0.0f, 0.0f }, SkPoint br = { 1.0f, 1.0f },
40 float aspect = -1.0f)
41 : fID(0), fDragging(false) {
42 ImGui::PushID(id);
43 fDrawList = ImGui::GetWindowDrawList();
44
45 // Logical size
46 SkScalar w = SkTAbs(br.fX - tl.fX),
47 h = SkTAbs(br.fY - tl.fY);
48
49 // Determine aspect ratio automatically by default
50 if (aspect < 0) {
51 aspect = h / w;
52 }
53
54 float availWidth = std::max(ImGui::GetContentRegionAvailWidth(), 1.0f);
55 fPos = ImGui::GetCursorScreenPos();
56 fSize = ImVec2(availWidth, availWidth * aspect);
57
58 SkPoint local[4] = {
59 { tl.fX, tl.fY },
60 { br.fX, tl.fY },
61 { tl.fX, br.fY },
62 { br.fX, br.fY },
63 };
64 SkPoint screen[4] = {
65 { fPos.x , fPos.y },
66 { fPos.x + fSize.x, fPos.y },
67 { fPos.x , fPos.y + fSize.y },
68 { fPos.x + fSize.x, fPos.y + fSize.y },
69 };
70 fLocalToScreen.setPolyToPoly(local, screen, 4);
71 fScreenToLocal.setPolyToPoly(screen, local, 4);
72 }
static T SkTAbs(T value)
Definition SkTemplates.h:43
bool setPolyToPoly(const SkPoint src[], const SkPoint dst[], int count)
float SkScalar
Definition extension.cpp:12
SkScalar w
SkScalar h
ImDrawList * fDrawList
Definition ImGuiLayer.h:114
SkMatrix fScreenToLocal
Definition ImGuiLayer.h:125
SkMatrix fLocalToScreen
Definition ImGuiLayer.h:124
float fX
x-axis value
float fY
y-axis value
constexpr float x() const

◆ ~DragCanvas()

ImGui::DragCanvas::~DragCanvas ( )
inline

Definition at line 74 of file ImGuiLayer.h.

74 {
75 ImGui::SetCursorScreenPos(ImVec2(fPos.x, fPos.y + fSize.y));
76 ImGui::Spacing();
77 ImGui::PopID();
78 }

Member Function Documentation

◆ dragPoint()

void ImGui::DragCanvas::dragPoint ( SkPoint p,
bool  tooltip = false,
ImU32  color = 0xFFFFFFFF 
)
inline

Definition at line 84 of file ImGuiLayer.h.

84 {
85 // Transform points from logical coordinates to screen coordinates
87
88 // Invisible 10x10 button
89 ImGui::PushID(fID++);
90 ImGui::SetCursorScreenPos(ImVec2(center.fX - 5, center.fY - 5));
91 ImGui::InvisibleButton("", ImVec2(10, 10));
92
93 if (ImGui::IsItemActive() && ImGui::IsMouseDragging(0)) {
94 // Update screen position to track mouse, clamped to our area
95 ImGuiIO& io = ImGui::GetIO();
96 center.set(SkTPin(io.MousePos.x, fPos.x, fPos.x + fSize.x),
97 SkTPin(io.MousePos.y, fPos.y, fPos.y + fSize.y));
98
99 // Update local coordinates for the caller
101 fDragging = true;
102 }
103
104 if (tooltip && ImGui::IsItemHovered()) {
105 ImGui::SetTooltip("x: %.3f\ny: %.3f", p->fX, p->fY);
106 }
107
108 ImGui::PopID();
109
110 fScreenPoints.push_back(ImVec2(center.fX, center.fY));
111 fDrawList->AddCircle(fScreenPoints.back(), 5.0f, color);
112 }
SkColor4f color
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition SkTPin.h:19
static SkScalar center(float pos0, float pos1)
void mapXY(SkScalar x, SkScalar y, SkPoint *result) const
Definition SkMatrix.cpp:777
skia_private::STArray< 4, ImVec2, true > fScreenPoints
Definition ImGuiLayer.h:121

◆ fillColor()

void ImGui::DragCanvas::fillColor ( ImU32  color)
inline

Definition at line 80 of file ImGuiLayer.h.

80 {
81 fDrawList->AddRectFilled(fPos, ImVec2(fPos.x + fSize.x, fPos.y + fSize.y), color);
82 }

Member Data Documentation

◆ fDragging

bool ImGui::DragCanvas::fDragging

Definition at line 128 of file ImGuiLayer.h.

◆ fDrawList

ImDrawList* ImGui::DragCanvas::fDrawList

Definition at line 114 of file ImGuiLayer.h.

◆ fID

int ImGui::DragCanvas::fID

Definition at line 127 of file ImGuiLayer.h.

◆ fLocalToScreen

SkMatrix ImGui::DragCanvas::fLocalToScreen

Definition at line 124 of file ImGuiLayer.h.

◆ fPos

ImVec2 ImGui::DragCanvas::fPos

Definition at line 117 of file ImGuiLayer.h.

◆ fScreenPoints

skia_private::STArray<4, ImVec2, true> ImGui::DragCanvas::fScreenPoints

Definition at line 121 of file ImGuiLayer.h.

◆ fScreenToLocal

SkMatrix ImGui::DragCanvas::fScreenToLocal

Definition at line 125 of file ImGuiLayer.h.

◆ fSize

ImVec2 ImGui::DragCanvas::fSize

Definition at line 118 of file ImGuiLayer.h.


The documentation for this struct was generated from the following file: