StoneyVCV v2
StoneyDSP Modules for VCV Rack 2.
Loading...
Searching...
No Matches
Widget.hpp
Go to the documentation of this file.
1
31#pragma once
32
33#define STONEYVCV_COMPONENTLIBRARY_PANELWIDGET_HPP_INCLUDED 1
34
35#if defined (STONEYVCV_BUILD_COMPONENTLIBRARY)
36
37//==============================================================================
38
39#include <StoneyVCV.hpp>
41
42//==============================================================================
43
44#include <rack.hpp>
45#include <StoneyDSP/Core.hpp>
46
47//==============================================================================
48
49namespace StoneyDSP
50{
55//==============================================================================
56
57namespace StoneyVCV
58{
63//==============================================================================
64
65namespace ComponentLibrary
66{
71//==============================================================================
72
84struct Widget : virtual ::rack::widget::Widget
85{
86 //==========================================================================
87
88public:
89
90 using DrawArgs = ::rack::widget::Widget::DrawArgs;
91
92 //==========================================================================
93
99
105 Widget(::rack::math::Rect newBox);
106
111 virtual ~Widget() noexcept;
112
113 //==========================================================================
114
121
128 virtual void draw(const ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::DrawArgs &args) override;
129
130 //==========================================================================
131
132 struct PixelRatioChangeEvent : ::rack::widget::Widget::BaseEvent {
133 float newPixelRatio = APP->window->pixelRatio;
134 };
135
145 ::StoneyDSP::ignoreUnused(e);
146 };
147
153
154 //==========================================================================
155
157 friend TWidget *::rack::createWidget(::rack::math::Vec pos);
158
161
163 friend TWidget *::StoneyDSP::StoneyVCV::createWidget(::rack::math::Vec pos);
164
167
169 friend TWidget *::StoneyDSP::StoneyVCV::createWidgetSized(::rack::math::Vec pos, ::rack::math::Vec size);
170
172 friend TWidget *::StoneyDSP::StoneyVCV::createWidgetCenteredSized(::rack::math::Vec pos, ::rack::math::Vec size);
173
175
176 //==========================================================================
177
182 ::rack::math::Rect box = ::rack::math::Rect(::rack::math::Vec(), ::rack::math::Vec(INFINITY, INFINITY));
183
188 ::rack::Widget *parent = NULL;
189
190 ::std::list<::rack::Widget *> children;
191
198 bool visible = true;
199
206
207 //==========================================================================
208
213 float lastPixelRatio = {APP->window->pixelRatio};
214
219 const float *pixelRatioPtr = NULL;
220
221 //==========================================================================
222
223private:
224
225 //==========================================================================
226
229};
230
231//==============================================================================
232
237struct ThemedWidget : virtual ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget
238{
239
240 //==========================================================================
241
242public:
243
245
246 //==========================================================================
247
253
259 ThemedWidget(::rack::math::Rect newBox);
260
266
267 //==========================================================================
268
275
283 virtual void draw(const ::StoneyDSP::StoneyVCV::ComponentLibrary::ThemedWidget::DrawArgs &args) override;
284
285 const bool &getPrefersDarkPanels() const noexcept;
286
287 //==========================================================================
288
294 struct PrefersDarkPanelsChangeEvent : ::rack::widget::Widget::BaseEvent {
295 bool newPrefersDarkPanels = {::rack::settings::preferDarkPanels};
296 };
297
307 {
308 if(this->lastPrefersDarkPanels != e.newPrefersDarkPanels)
309 this->lastPrefersDarkPanels = e.newPrefersDarkPanels;
310 }
311
312 //==========================================================================
313
315
316 //==========================================================================
317
318protected:
319
320 //==========================================================================
321
322 bool lastPrefersDarkPanels = {::rack::settings::preferDarkPanels};
323
324 //==========================================================================
325
326private:
327
328 //==========================================================================
329
334 const bool *prefersDarkPanelsPtr = NULL;
335
336 //==========================================================================
337
340};
341
342//==============================================================================
343
345{
346
347 //==========================================================================
348
349public:
350
351 //==========================================================================
352
353 using DrawArgs = ::rack::widget::FramebufferWidget::DrawArgs;
354
355 //==========================================================================
356
358
359 FramebufferWidget(::rack::math::Rect newBox);
360
362
363 //==========================================================================
364
366
367 virtual void draw(const ::StoneyDSP::StoneyVCV::ComponentLibrary::FramebufferWidget::DrawArgs &args) override;
368
369 //==========================================================================
370
372
373 //==========================================================================
374
375private:
376
377 //==========================================================================
378
381};
382
383//==============================================================================
384
385struct TransparentWidget : virtual ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget
386{
387
388 //==========================================================================
389
390public:
391
392 //==========================================================================
393
395
396 //==========================================================================
397
399
400 TransparentWidget(::rack::math::Rect newBox);
401
403
404 //==========================================================================
405
407
408 //==========================================================================
409
410private:
411
412 //==========================================================================
413
414 // Override behavior to do nothing instead
415
416 virtual void onHover(const HoverEvent& e) override {}
417 virtual void onButton(const ButtonEvent& e) override {}
418 virtual void onHoverKey(const HoverKeyEvent& e) override {}
419 virtual void onHoverText(const HoverTextEvent& e) override {}
420 virtual void onHoverScroll(const HoverScrollEvent& e) override {}
421 virtual void onDragHover(const DragHoverEvent& e) override {}
422 virtual void onPathDrop(const PathDropEvent& e) override {}
423
424 //==========================================================================
425
428};
429
430//==============================================================================
431
432struct OpaqueWidget : virtual ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget
433{
434
435 //==========================================================================
436
437public:
438
439 //==========================================================================
440
442
443 OpaqueWidget(::rack::math::Rect newBox);
444
446
447 //==========================================================================
448
449 virtual void onHover(const HoverEvent& e) override
450 {
451 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onHover(e);
452 e.stopPropagating();
453 // Consume if not consumed by child
454 if (!e.isConsumed())
455 e.consume(this);
456 }
457
458 virtual void onButton(const ButtonEvent& e) override
459 {
460 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onButton(e);
461 e.stopPropagating();
462 if (e.button == GLFW_MOUSE_BUTTON_LEFT) {
463 // Consume if not consumed by child
464 if (!e.isConsumed())
465 e.consume(this);
466 }
467 }
468
469 virtual void onHoverKey(const HoverKeyEvent& e) override
470 {
471 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onHoverKey(e);
472 e.stopPropagating();
473 }
474
475 virtual void onHoverText(const HoverTextEvent& e) override
476 {
477 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onHoverText(e);
478 e.stopPropagating();
479 }
480
481 virtual void onHoverScroll(const HoverScrollEvent& e) override
482 {
483 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onHoverScroll(e);
484 e.stopPropagating();
485 }
486
487 virtual void onDragHover(const DragHoverEvent& e) override
488 {
489 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onDragHover(e);
490 e.stopPropagating();
491 // Consume if not consumed by child
492 if (!e.isConsumed())
493 e.consume(this);
494 }
495
496 virtual void onPathDrop(const PathDropEvent& e) override
497 {
498 ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::onPathDrop(e);
499 e.stopPropagating();
500 }
501
502 //==========================================================================
503
505
506 //==========================================================================
507
508private:
509
510 //==========================================================================
511
514};
515
516//==============================================================================
517
518struct SvgWidget : virtual ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget
519{
520
521 //==========================================================================
522
523public:
524
525 //==========================================================================
526
528
529 //==========================================================================
530
532
533 SvgWidget(::rack::math::Rect newBox);
534
536
537 //==========================================================================
538
539 void wrap() noexcept;
540
541 void setSvg(::std::shared_ptr<::rack::window::Svg> newSvg);
542
543 virtual void draw(const ::StoneyDSP::StoneyVCV::ComponentLibrary::SvgWidget::DrawArgs &args) override;
544
545 //==========================================================================
546
548
549 //==========================================================================
550
552
553 //==========================================================================
554
555 ::std::shared_ptr<::rack::window::Svg> svg;
556
557 //==========================================================================
558
559private:
560
561 //==========================================================================
562
565};
566
567//==============================================================================
568
570} // namespace ComponentLibrary
571
572//==============================================================================
573
575} // namespace StoneyVCV
576
577//==============================================================================
578
580} // namespace StoneyDSP
581
582//==============================================================================
583
584#endif // STONEYVCV_BUILD_COMPONENTLIBRARY
585
586//==============================================================================
StoneyDSP Modules for VCV Rack 2.
StoneyDSP Modules for VCV Rack 2.
#define STONEYVCV_DECLARE_WIDGET_FACTORY_FUNCTIONS(ClassName)
Add this definition to a class or struct's declaration body to make it compatible with the StoneyVCV ...
Definition StoneyVCV.hpp:426
The StoneyDSP namespace.
Definition StoneyVCV.hpp:78
::rack::widget::FramebufferWidget::DrawArgs DrawArgs
Definition Widget.hpp:353
virtual void onPathDrop(const PathDropEvent &e) override
Definition Widget.hpp:496
virtual void onDragHover(const DragHoverEvent &e) override
Definition Widget.hpp:487
virtual void onHoverScroll(const HoverScrollEvent &e) override
Definition Widget.hpp:481
virtual void onHoverText(const HoverTextEvent &e) override
Definition Widget.hpp:475
virtual void onHoverKey(const HoverKeyEvent &e) override
Definition Widget.hpp:469
virtual void onButton(const ButtonEvent &e) override
Definition Widget.hpp:458
::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::DrawArgs DrawArgs
Definition Widget.hpp:527
Occurs after the prefersDarkPanels setting is changed.
Definition Widget.hpp:294
The ThemedWidget struct.
Definition Widget.hpp:238
ThemedWidget(::rack::math::Rect newBox)
Construct a new ThemedWidget object with its' position and size set using a rack::math::Rect.
virtual ~ThemedWidget() noexcept
Destroys the ThemedWidget object.
ThemedWidget()
Construct a new ThemedWidget object.
::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::DrawArgs DrawArgs
Definition Widget.hpp:244
virtual void onPrefersDarkPanelsChange(const PrefersDarkPanelsChangeEvent &e)
Called after the prefersDarkPanels setting is changed.
Definition Widget.hpp:306
virtual void onDragHover(const DragHoverEvent &e) override
Definition Widget.hpp:421
::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::DrawArgs DrawArgs
Definition Widget.hpp:394
virtual void onButton(const ButtonEvent &e) override
Definition Widget.hpp:417
virtual void onHoverScroll(const HoverScrollEvent &e) override
Definition Widget.hpp:420
virtual void onPathDrop(const PathDropEvent &e) override
Definition Widget.hpp:422
virtual void onHoverText(const HoverTextEvent &e) override
Definition Widget.hpp:419
virtual void onHoverKey(const HoverKeyEvent &e) override
Definition Widget.hpp:418
The Widget struct.
Definition Widget.hpp:85
::rack::widget::Widget::DrawArgs DrawArgs
Definition Widget.hpp:90
const float & getPixelRatio() const noexcept
Widget()
Construct a new Widget object.
::rack::Widget * parent
Automatically set when Widget is added as a child to another Widget.
Definition Widget.hpp:188
::std::list<::rack::Widget * > children
Definition Widget.hpp:190
const float * pixelRatioPtr
Definition Widget.hpp:219
::rack::math::Rect box
Position relative to parent and size of Widget.
Definition Widget.hpp:182
virtual void draw(const ::StoneyDSP::StoneyVCV::ComponentLibrary::Widget::DrawArgs &args) override
Draws the Widget to the NanoVG context.
virtual void step() override
Advances the Widget by one frame.
friend TWidget * StoneyDSP::StoneyVCV::createWidgetCenteredSized(::rack::math::Vec pos, ::rack::math::Vec size)
friend TWidget * rack::createWidget(::rack::math::Vec pos)
friend TWidget * rack::createWidgetCentered(::rack::math::Vec pos)
bool requestedDelete
If set to true, parent will delete Widget in the next step().
Definition Widget.hpp:205
float lastPixelRatio
Definition Widget.hpp:213
virtual ~Widget() noexcept
Destroys the Widget object.
friend TWidget * StoneyDSP::StoneyVCV::createWidgetSized(::rack::math::Vec pos, ::rack::math::Vec size)
bool visible
Disables rendering but allow stepping.
Definition Widget.hpp:198
Widget(::rack::math::Rect newBox)
Construct a new Widget object with its' position and size set using a rack::math::Rect.
virtual void onPixelRatioChange(const PixelRatioChangeEvent &e)
Called after the App->window->pixelRatio setting is changed.
Definition Widget.hpp:144
Definition StoneyVCV.hpp:125