forked from hoffstadt/DearPyGui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmvSlider3D.cpp
More file actions
511 lines (410 loc) · 17.9 KB
/
Copy pathmvSlider3D.cpp
File metadata and controls
511 lines (410 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#include "mvPyUtils.h"
#pragma hdrstop
#include "mvSlider3D.h"
#include "mvFontItems.h"
#include "mvThemes.h"
#include "mvContainers.h"
#include "mvItemHandlers.h"
#include <imgui_internal.h>
static float Dist2(ImVec2 const v, ImVec2 const w)
{
//return Sqr(v.x - w.x) + Sqr(v.y - w.y);
return ImLengthSqr(v - w);
}
static float DistOnSegmentSqr(ImVec2 const p, ImVec2 const v, ImVec2 const w)
{
float l2 = Dist2(v, w);
//if (l2 == 0.0f)
// return 0.0f;
float t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
return ImSaturate(t) * Dist2(w, v);
}
static float DistToSegmentSqr(ImVec2 const p, ImVec2 const v, ImVec2 const w)
{
float const lDx = v.x - w.x;
float const lDy = v.y - w.y;
float const dx = v.x - p.x;
float const dy = v.y - p.y;
float const l2 = ImSqrt(ImLengthSqr(w - v));
return ImAbs(lDx * dy - lDy * dx) / l2;
}
static bool SliderScalar3D(char const* pLabel, float* pValueX, float* pValueY, float* pValueZ, float const fMinX, float const fMaxX, float const fMinY, float const fMaxY, float const fMinZ, float const fMaxZ, float const fScale)
{
assert(fMinX < fMaxX);
assert(fMinY < fMaxY);
assert(fMinZ < fMaxZ);
ImGuiID const iID = ImGui::GetID(pLabel);
ImVec2 const vSizeSubstract = ImGui::CalcTextSize(std::to_string(1.0f).c_str()) * 1.1f;
float const vSizeFull = ImGui::GetContentRegionAvail().x;
float const fMinSize = (vSizeFull - vSizeSubstract.x * 0.5f) * fScale * 0.75f;
ImVec2 const vSize(fMinSize, fMinSize);
float const fHeightOffset = ImGui::GetTextLineHeight();
ImVec2 const vHeightOffset(0.0f, fHeightOffset);
ImVec2 vPos = ImGui::GetCursorScreenPos();
ImRect oRect(vPos + vHeightOffset, vPos + vSize + vHeightOffset);
ImGui::Text("%s", pLabel);
ImGui::PushID(iID);
ImU32 const uFrameCol = ImGui::GetColorU32(ImGuiCol_FrameBg) | 0xFF000000;
ImU32 const uFrameCol2 = ImGui::GetColorU32(ImGuiCol_FrameBgActive);
float& fX = *pValueX;
float& fY = *pValueY;
float& fZ = *pValueZ;
float const fDeltaX = fMaxX - fMinX;
float const fDeltaY = fMaxY - fMinY;
float const fDeltaZ = fMaxZ - fMinZ;
ImVec2 const vOriginPos = ImGui::GetCursorScreenPos();
ImDrawList* pDrawList = ImGui::GetWindowDrawList();
float const fX3 = vSize.x / 3.0f;
float const fY3 = vSize.y / 3.0f;
ImVec2 const vStart = oRect.Min;
ImVec2 aPositions[] = {
ImVec2(vStart.x, vStart.y + fX3),
ImVec2(vStart.x, vStart.y + vSize.y),
ImVec2(vStart.x + 2.0f * fX3, vStart.y + vSize.y),
ImVec2(vStart.x + vSize.x, vStart.y + 2.0f * fY3),
ImVec2(vStart.x + vSize.x, vStart.y),
ImVec2(vStart.x + fX3, vStart.y)
};
pDrawList->AddPolyline(&aPositions[0], 6, uFrameCol2, true, 1.0f);
// Cube Shape
pDrawList->AddLine(
oRect.Min + ImVec2(0.0f, vSize.y),
oRect.Min + ImVec2(fX3, 2.0f * fY3), uFrameCol2, 1.0f);
pDrawList->AddLine(
oRect.Min + ImVec2(fX3, 2.0f * fY3),
oRect.Min + ImVec2(vSize.x, 2.0f * fY3), uFrameCol2, 1.0f);
pDrawList->AddLine(
oRect.Min + ImVec2(fX3, 0.0f),
oRect.Min + ImVec2(fX3, 2.0f * fY3), uFrameCol2, 1.0f);
ImGui::PopID();
constexpr float fDragZOffsetX = 64.0f;
ImRect oZDragRect(ImVec2(vStart.x + 2.0f * fX3 + fDragZOffsetX, vStart.y + 2.0f * fY3), ImVec2(vStart.x + vSize.x + fDragZOffsetX, vStart.y + vSize.y));
ImVec2 const vMousePos = ImGui::GetMousePos();
ImVec2 const vSecurity(15.0f, 15.0f);
ImVec2 const vDragStart(oZDragRect.Min.x, oZDragRect.Max.y);
ImVec2 const vDragEnd(oZDragRect.Max.x, oZDragRect.Min.y);
ImRect frame_bb = ImRect(oRect.Min - vSecurity, oRect.Max + vSecurity);
bool bModified = false;
bool hovered;
bool held;
ImGuiID iHandleID = ImGui::GetID("##HandleZ");
ImGui::KeepAliveID(iHandleID);
bool pressed = ImGui::ButtonBehavior(oZDragRect, iHandleID, &hovered, &held);
if (held)
{
if (DistToSegmentSqr(vMousePos, vDragStart, vDragEnd) < 100.0f) // 100 is arbitrary threshold
{
float const fMaxDist = ImSqrt(Dist2(vDragStart, vDragEnd));
float const fDist = ImSaturate(ImSqrt(DistOnSegmentSqr(vMousePos, vDragStart, vDragEnd)) / fMaxDist);
fZ = fDist * fDeltaZ * fDist + fMinZ;
bModified = true;
}
}
float const fScaleZ = (fZ - fMinZ) / fDeltaZ;
ImVec2 const vRectStart(vStart.x, vStart.y + fX3);
ImVec2 const vRectEnd(vStart.x + fX3, vStart.y);
ImRect const oXYDrag((vRectEnd - vRectStart) * fScaleZ + vRectStart,
(vRectEnd - vRectStart) * fScaleZ + vRectStart + ImVec2(2.0f * fX3, 2.0f * fY3));
//if (ImGui::IsMouseHoveringRect(oXYDrag.Min - vSecurity, oXYDrag.Max + vSecurity) && ImGui::IsMouseDown(ImGuiMouseButton_Left))
iHandleID = ImGui::GetID("##Zone");
ImGui::KeepAliveID(iHandleID);
pressed = ImGui::ButtonBehavior(oXYDrag, iHandleID, &hovered, &held);
if (held)
{
ImVec2 const vLocalPos = ImGui::GetMousePos() - oXYDrag.Min;
fX = vLocalPos.x / (oXYDrag.Max.x - oXYDrag.Min.x) * fDeltaX + fMinX;
fY = fDeltaY - vLocalPos.y / (oXYDrag.Max.y - oXYDrag.Min.y) * fDeltaY + fMinY;
bModified = true;
}
fX = ImClamp(fX, fMinX, fMaxX);
fY = ImClamp(fY, fMinY, fMaxY);
fZ = ImClamp(fZ, fMinZ, fMaxZ);
float const fScaleX = (fX - fMinX) / fDeltaX;
float const fScaleY = 1.0f - (fY - fMinY) / fDeltaY;
ImVec4 const vBlue(70.0f / 255.0f, 102.0f / 255.0f, 230.0f / 255.0f, 1.0f);
ImVec4 const vOrange(255.0f / 255.0f, 128.0f / 255.0f, 64.0f / 255.0f, 1.0f);
ImS32 const uBlue = ImGui::GetColorU32(vBlue);
ImS32 const uOrange = ImGui::GetColorU32(vOrange);
constexpr float fBorderThickness = 2.0f; // TODO: move as Style
constexpr float fLineThickness = 3.0f; // TODO: move as Style
constexpr float fHandleRadius = 7.0f; // TODO: move as Style
constexpr float fHandleOffsetCoef = 2.0f; // TODO: move as Style
pDrawList->AddLine(
vDragStart,
vDragEnd, uFrameCol2, 1.0f);
pDrawList->AddRectFilled(
oXYDrag.Min, oXYDrag.Max, uFrameCol);
constexpr float fCursorOff = 10.0f;
float const fXLimit = fCursorOff / oXYDrag.GetWidth();
float const fYLimit = fCursorOff / oXYDrag.GetHeight();
float const fZLimit = fCursorOff / oXYDrag.GetWidth();
char pBufferX[16];
char pBufferY[16];
char pBufferZ[16];
ImFormatString(pBufferX, IM_ARRAYSIZE(pBufferX), "%.5f", *(float const*)&fX);
ImFormatString(pBufferY, IM_ARRAYSIZE(pBufferY), "%.5f", *(float const*)&fY);
ImFormatString(pBufferZ, IM_ARRAYSIZE(pBufferZ), "%.5f", *(float const*)&fZ);
ImU32 const uTextCol = ImGui::ColorConvertFloat4ToU32(ImGui::GetStyle().Colors[ImGuiCol_Text]);
ImVec2 const vCursorPos((oXYDrag.Max.x - oXYDrag.Min.x) * fScaleX + oXYDrag.Min.x, (oXYDrag.Max.y - oXYDrag.Min.y) * fScaleY + oXYDrag.Min.y);
ImGuiStyle& style = ImGui::GetStyle();
ImGui::PushFont(nullptr, style.FontSizeBase * 0.75f);
ImVec2 const vXSize = ImGui::CalcTextSize(pBufferX);
ImVec2 const vYSize = ImGui::CalcTextSize(pBufferY);
ImVec2 const vZSize = ImGui::CalcTextSize(pBufferZ);
ImVec2 const vTextSlideXMin = oRect.Min + ImVec2(0.0f, vSize.y);
ImVec2 const vTextSlideXMax = oRect.Min + ImVec2(2.0f * fX3, vSize.y);
ImVec2 const vXTextPos((vTextSlideXMax - vTextSlideXMin) * fScaleX + vTextSlideXMin);
ImVec2 const vTextSlideYMin = oRect.Min + ImVec2(vSize.x, 2.0f * fY3);
ImVec2 const vTextSlideYMax = oRect.Min + ImVec2(vSize.x, 0.0f);
ImVec2 const vYTextPos((vTextSlideYMax - vTextSlideYMin) * (1.0f - fScaleY) + vTextSlideYMin);
ImVec2 const vTextSlideZMin = vDragStart + ImVec2(fCursorOff, fCursorOff);
ImVec2 const vTextSlideZMax = vDragEnd + ImVec2(fCursorOff, fCursorOff);
ImVec2 const vZTextPos((vTextSlideZMax - vTextSlideZMin) * fScaleZ + vTextSlideZMin);
ImVec2 const vHandlePosX = vXTextPos + ImVec2(0.0f, vXSize.y + fHandleOffsetCoef * fCursorOff);
ImVec2 const vHandlePosY = vYTextPos + ImVec2(vYSize.x + (fHandleOffsetCoef + 1.0f) * fCursorOff, 0.0f);
ImRect handle_x_bb = ImRect(vHandlePosX - ImVec2(fHandleRadius, fHandleRadius) - vSecurity, vHandlePosX + ImVec2(fHandleRadius, fHandleRadius) + vSecurity);
ImRect handle_y_bb = ImRect(vHandlePosY - ImVec2(fHandleRadius, fHandleRadius) - vSecurity, vHandlePosY + ImVec2(fHandleRadius, fHandleRadius) + vSecurity);
//ImRect handle_z_bb = ImRect(vHandlePosY - ImVec2(fHandleRadius, fHandleRadius) - vSecurity, vHandlePosY + ImVec2(fHandleRadius, fHandleRadius) + vSecurity);
//if (ImGui::IsMouseHoveringRect(vHandlePosX - ImVec2(fHandleRadius, fHandleRadius) - vSecurity, vHandlePosX + ImVec2(fHandleRadius, fHandleRadius) + vSecurity) &&
// ImGui::IsMouseDown(ImGuiMouseButton_Left))
iHandleID = ImGui::GetID("##HandleX");
ImGui::KeepAliveID(iHandleID);
pressed = ImGui::ButtonBehavior(handle_x_bb, iHandleID, &hovered, &held);
if (held)
{
float const fCursorPosX = ImGui::GetMousePos().x - vStart.x;
fX = fDeltaX * fCursorPosX / (2.0f * fX3) + fMinX;
bModified = true;
}
//else if (ImGui::IsMouseHoveringRect(vHandlePosY - ImVec2(fHandleRadius, fHandleRadius) - vSecurity, vHandlePosY + ImVec2(fHandleRadius, fHandleRadius) + vSecurity) &&
// ImGui::IsMouseDown(ImGuiMouseButton_Left))
iHandleID = ImGui::GetID("##HandleY");
ImGui::KeepAliveID(iHandleID);
pressed = ImGui::ButtonBehavior(handle_y_bb, iHandleID, &hovered, &held);
if (held)
{
float const fCursorPosY = ImGui::GetMousePos().y - vStart.y;
fY = fDeltaY * (1.0f - fCursorPosY / (2.0f * fY3)) + fMinY;
bModified = true;
}
pDrawList->AddText(
ImVec2(
ImMin(ImMax(vXTextPos.x - vXSize.x * 0.5f, vTextSlideXMin.x), vTextSlideXMax.x - vXSize.x),
vXTextPos.y + fCursorOff),
uTextCol,
pBufferX);
pDrawList->AddText(
ImVec2(
vYTextPos.x + fCursorOff,
ImMin(ImMax(vYTextPos.y - vYSize.y * 0.5f, vTextSlideYMax.y), vTextSlideYMin.y - vYSize.y)),
uTextCol,
pBufferY);
pDrawList->AddText(
vZTextPos,
uTextCol,
pBufferZ);
ImGui::PopFont();
// Handles
pDrawList->AddNgonFilled(vHandlePosX, fHandleRadius, uBlue, 4);
pDrawList->AddNgonFilled(vHandlePosY, fHandleRadius, uBlue, 4);
// Vertical Line
if (fScaleY > 2.0f * fYLimit)
pDrawList->AddLine(ImVec2(vCursorPos.x, oXYDrag.Min.y + fCursorOff), ImVec2(vCursorPos.x, vCursorPos.y - fCursorOff), uOrange, fLineThickness);
if (fScaleY < 1.0f - 2.0f * fYLimit)
pDrawList->AddLine(ImVec2(vCursorPos.x, oXYDrag.Max.y - fCursorOff), ImVec2(vCursorPos.x, vCursorPos.y + fCursorOff), uOrange, fLineThickness);
// Horizontal Line
if (fScaleX > 2.0f * fXLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Min.x + fCursorOff, vCursorPos.y), ImVec2(vCursorPos.x - fCursorOff, vCursorPos.y), uOrange, fLineThickness);
if (fScaleX < 1.0f - 2.0f * fYLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Max.x - fCursorOff, vCursorPos.y), ImVec2(vCursorPos.x + fCursorOff, vCursorPos.y), uOrange, fLineThickness);
// Line To Text
// X
if (fScaleZ > 2.0f * fZLimit)
pDrawList->AddLine(
ImVec2(vCursorPos.x - 0.5f * fCursorOff, oXYDrag.Max.y + 0.5f * fCursorOff),
ImVec2(vXTextPos.x + 0.5f * fCursorOff, vXTextPos.y - 0.5f * fCursorOff), uOrange, fLineThickness
);
else
pDrawList->AddLine(
ImVec2(vCursorPos.x, oXYDrag.Max.y),
ImVec2(vXTextPos.x, vXTextPos.y), uOrange, 1.0f
);
pDrawList->AddCircleFilled(vXTextPos, 2.0f, uOrange, 3);
// Y
if (fScaleZ < 1.0f - 2.0f * fZLimit)
pDrawList->AddLine(
ImVec2(oXYDrag.Max.x + 0.5f * fCursorOff, vCursorPos.y - 0.5f * fCursorOff),
ImVec2(vYTextPos.x - 0.5f * fCursorOff, vYTextPos.y + 0.5f * fCursorOff), uOrange, fLineThickness
);
else
pDrawList->AddLine(
ImVec2(oXYDrag.Max.x, vCursorPos.y),
ImVec2(vYTextPos.x, vYTextPos.y), uOrange, 1.0f
);
pDrawList->AddCircleFilled(vYTextPos, 2.0f, uOrange, 3);
// Borders::Right
pDrawList->AddCircleFilled(ImVec2(oXYDrag.Max.x, vCursorPos.y), 2.0f, uOrange, 3);
if (fScaleY > fYLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Max.x, oXYDrag.Min.y), ImVec2(oXYDrag.Max.x, vCursorPos.y - fCursorOff), uBlue, fBorderThickness);
if (fScaleY < 1.0f - fYLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Max.x, oXYDrag.Max.y), ImVec2(oXYDrag.Max.x, vCursorPos.y + fCursorOff), uBlue, fBorderThickness);
// Borders::Top
pDrawList->AddCircleFilled(ImVec2(vCursorPos.x, oXYDrag.Min.y), 2.0f, uOrange, 3);
if (fScaleX > fXLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Min.x, oXYDrag.Min.y), ImVec2(vCursorPos.x - fCursorOff, oXYDrag.Min.y), uBlue, fBorderThickness);
if (fScaleX < 1.0f - fXLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Max.x, oXYDrag.Min.y), ImVec2(vCursorPos.x + fCursorOff, oXYDrag.Min.y), uBlue, fBorderThickness);
// Borders::Left
pDrawList->AddCircleFilled(ImVec2(oXYDrag.Min.x, vCursorPos.y), 2.0f, uOrange, 3);
if (fScaleY > fYLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Min.x, oXYDrag.Min.y), ImVec2(oXYDrag.Min.x, vCursorPos.y - fCursorOff), uBlue, fBorderThickness);
if (fScaleY < 1.0f - fYLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Min.x, oXYDrag.Max.y), ImVec2(oXYDrag.Min.x, vCursorPos.y + fCursorOff), uBlue, fBorderThickness);
// Borders::Bottom
pDrawList->AddCircleFilled(ImVec2(vCursorPos.x, oXYDrag.Max.y), 2.0f, uOrange, 3);
if (fScaleX > fXLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Min.x, oXYDrag.Max.y), ImVec2(vCursorPos.x - fCursorOff, oXYDrag.Max.y), uBlue, fBorderThickness);
if (fScaleX < 1.0f - fXLimit)
pDrawList->AddLine(ImVec2(oXYDrag.Max.x, oXYDrag.Max.y), ImVec2(vCursorPos.x + fCursorOff, oXYDrag.Max.y), uBlue, fBorderThickness);
pDrawList->AddLine(
oRect.Min + ImVec2(0.0f, fY3),
oRect.Min + ImVec2(2.0f * fX3, fY3), uFrameCol2, 1.0f);
pDrawList->AddLine(
oRect.Min + ImVec2(2.0f * fX3, fY3),
oRect.Min + ImVec2(vSize.x, 0.0f), uFrameCol2, 1.0f);
pDrawList->AddLine(
oRect.Min + ImVec2(2.0f * fX3, fY3),
oRect.Min + ImVec2(2.0f * fX3, vSize.y), uFrameCol2, 1.0f);
// Cursor
pDrawList->AddCircleFilled(vCursorPos, 5.0f, uBlue, 16);
// CursorZ
pDrawList->AddNgonFilled((vDragEnd - vDragStart) * fScaleZ + vDragStart, fHandleRadius, uBlue, 4);
ImGui::Dummy(vHeightOffset);
ImGui::Dummy(vHeightOffset * 1.25f);
ImGui::Dummy(vSize);
return bModified;
}
void mvSlider3D::draw(ImDrawList* drawlist, float x, float y)
{
//-----------------------------------------------------------------------------
// pre draw
//-----------------------------------------------------------------------------
// show/hide
if (!config.show)
return;
// focusing
if (info.focusNextFrame)
{
ImGui::SetKeyboardFocusHere();
info.focusNextFrame = false;
}
// cache old cursor position
ImVec2 previousCursorPos = ImGui::GetCursorPos();
// set cursor position if user set
if (info.dirtyPos)
ImGui::SetCursorPos(state.pos);
// update widget's position state
state.pos = { ImGui::GetCursorPosX(), ImGui::GetCursorPosY() };
// set item width
if (config.width != 0)
ImGui::SetNextItemWidth((float)config.width);
// set indent
if (config.indent > 0.0f)
ImGui::Indent(config.indent);
// push font if a font object is attached
if (font)
static_cast<mvFont*>(font.get())->pushFont();
// themes
apply_local_theming(this);
//-----------------------------------------------------------------------------
// draw
//-----------------------------------------------------------------------------
{
ScopedID id(uuid);
if(SliderScalar3D(config.specifiedLabel.c_str(), &(*_value)[0], &(*_value)[1], &(*_value)[2], _minX, _maxX, _minY, _maxY, _minZ, _maxZ, _scale))
{
submitCallback(*_value);
}
}
//-----------------------------------------------------------------------------
// update state
//-----------------------------------------------------------------------------
UpdateAppItemState(state);
//-----------------------------------------------------------------------------
// post draw
//-----------------------------------------------------------------------------
// set cursor position to cached position
if (info.dirtyPos)
DearPyGui::RestoreImGuiCursor(previousCursorPos);
if (config.indent > 0.0f)
ImGui::Unindent(config.indent);
// pop font off stack
if (font)
ImGui::PopFont();
// handle popping themes
cleanup_local_theming(this);
if (handlerRegistry)
handlerRegistry->checkEvents(&state);
// handle drag & drop if used
apply_drag_drop(this);
}
PyObject* mvSlider3D::getPyValue()
{
return ToPyFloatList(_value->data(), 4);
}
void mvSlider3D::setPyValue(PyObject* value)
{
std::vector<float> temp = ToFloatVect(value);
while (temp.size() < 4)
temp.push_back(0.0f);
std::array<float, 4> temp_array;
for (size_t i = 0; i < temp_array.size(); i++)
temp_array[i] = temp[i];
if (_value)
*_value = temp_array;
else
_value = std::make_shared<std::array<float, 4>>(temp_array);
}
void mvSlider3D::setDataSource(mvUUID dataSource)
{
if (dataSource == config.source) return;
config.source = dataSource;
mvAppItem* item = GetItem((*GContext->itemRegistry), dataSource);
if (!item)
{
mvThrowPythonError(mvErrorCode::mvSourceNotFound, "set_value",
"Source item not found: " + std::to_string(dataSource), this);
return;
}
if (DearPyGui::GetEntityValueType(item->type) != DearPyGui::GetEntityValueType(type))
{
mvThrowPythonError(mvErrorCode::mvSourceNotCompatible, "set_value",
"Values types do not match: " + std::to_string(dataSource), this);
return;
}
_value = *static_cast<std::shared_ptr<std::array<float, 4>>*>(item->getValue());
}
void mvSlider3D::handleSpecificKeywordArgs(PyObject* dict)
{
if (dict == nullptr)
return;
if (PyObject* item = PyDict_GetItemString(dict, "max_x")) _maxX = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "max_y")) _maxY = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "max_z")) _maxZ = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "min_x")) _minX = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "min_y")) _minY = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "min_z")) _minZ = ToFloat(item);
if (PyObject* item = PyDict_GetItemString(dict, "scale")) _scale = ToFloat(item);
}
void mvSlider3D::getSpecificConfiguration(PyObject* dict)
{
if (dict == nullptr)
return;
PyDict_SetItemString(dict, "max_x", mvPyObject(ToPyFloat(_maxX)));
PyDict_SetItemString(dict, "max_y", mvPyObject(ToPyFloat(_maxY)));
PyDict_SetItemString(dict, "max_z", mvPyObject(ToPyFloat(_maxZ)));
PyDict_SetItemString(dict, "min_x", mvPyObject(ToPyFloat(_minX)));
PyDict_SetItemString(dict, "min_y", mvPyObject(ToPyFloat(_minY)));
PyDict_SetItemString(dict, "min_z", mvPyObject(ToPyFloat(_minZ)));
PyDict_SetItemString(dict, "scale", mvPyObject(ToPyFloat(_scale)));
}