iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
IGraphicsStructs.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
19#include <functional>
20#include <vector>
21#include <chrono>
22#include <cmath>
23#include <numeric>
24
25#include "IPlugUtilities.h"
26#include "IPlugLogger.h"
27#include "IPlugStructs.h"
28
29#include "IGraphicsPrivate.h"
30#include "IGraphicsUtilities.h"
31#include "IGraphicsConstants.h"
32
33BEGIN_IPLUG_NAMESPACE
34BEGIN_IGRAPHICS_NAMESPACE
35
36class IGraphics;
37class IControl;
38class ILambdaControl;
39class IPopupMenu;
40struct IRECT;
41struct IVec2;
42struct IMouseInfo;
43struct IColor;
44struct IGestureInfo;
45
46using IActionFunction = std::function<void(IControl*)>;
47using IAnimationFunction = std::function<void(IControl*)>;
48using IControlFunction = std::function<void(IControl*)>;
49using ILambdaDrawFunction = std::function<void(ILambdaControl*, IGraphics&, IRECT&)>;
50using IKeyHandlerFunc = std::function<bool(const IKeyPress& key, bool isUp)>;
51using IDropHandlerFunc = std::function<bool(const std::vector<const char*>& paths, float x, float y)>;
52using IMsgBoxCompletionHandlerFunc = std::function<void(EMsgBoxResult result)>;
53using IFileDialogCompletionHandlerFunc = std::function<void(const WDL_String& fileName, const WDL_String& path)>;
54using IColorPickerHandlerFunc = std::function<void(const IColor& result)>;
55using IGestureFunc = std::function<void(IControl*, const IGestureInfo&)>;
56using IPopupFunction = std::function<void(IPopupMenu* pMenu)>;
57using IDisplayTickFunc = std::function<void()>;
58using IUIAppearanceChangedFunc = std::function<void(EUIAppearance appearance)>;
59using ILiveEditEventFunc = std::function<void(const char* eventJson)>;
60using ITouchID = uintptr_t;
61
63void EmptyClickActionFunc(IControl* pCaller);
64
66void DefaultClickActionFunc(IControl* pCaller);
67
69void DefaultAnimationFunc(IControl* pCaller);
70
72void SplashClickActionFunc(IControl* pCaller);
73
75void SplashAnimationFunc(IControl* pCaller);
76
79
82
83using MTLTexturePtr = void*;
84
85using Milliseconds = std::chrono::duration<double, std::chrono::milliseconds::period>;
86using TimePoint = std::chrono::time_point<std::chrono::high_resolution_clock, Milliseconds>;
87
92{
93public:
99 IBitmap(APIBitmap* pAPIBitmap, int n, bool framesAreHorizontal, const char* name = "")
100 : mAPIBitmap(pAPIBitmap)
101 , mW(static_cast<int>(pAPIBitmap->GetWidth() / pAPIBitmap->GetScale()))
102 , mH(static_cast<int>(pAPIBitmap->GetHeight() / pAPIBitmap->GetScale()))
103 , mN(n)
104 , mFramesAreHorizontal(framesAreHorizontal)
105 , mResourceName(name, static_cast<int>(strlen(name)))
106 {
107 }
108
109 IBitmap()
110 : mAPIBitmap(nullptr)
111 , mW(0)
112 , mH(0)
113 , mN(0)
114 , mFramesAreHorizontal(false)
115 {
116 }
117
119 int W() const { return mW; }
120
122 int H() const { return mH; }
123
125 int FW() const { return (mFramesAreHorizontal && mN > 0 ? mW / mN : mW); }
126
128 int FH() const { return (mFramesAreHorizontal || mN <= 0 ? mH : mH / mN); }
129
131 int N() const { return mN; }
132
134 float GetScale() const { return mAPIBitmap->GetScale(); }
135
137 float GetDrawScale() const { return mAPIBitmap->GetDrawScale(); }
138
140 APIBitmap* GetAPIBitmap() const { return mAPIBitmap; }
141
143 bool GetFramesAreHorizontal() const { return mFramesAreHorizontal; }
144
146 const WDL_String& GetResourceName() const { return mResourceName; }
147
149 inline bool IsValid() const { return mAPIBitmap != nullptr; }
150
151private:
153 APIBitmap* mAPIBitmap;
155 int mW;
157 int mH;
159 int mN;
161 bool mFramesAreHorizontal;
163 WDL_String mResourceName;
164};
165
169#ifdef SVG_USE_SKIA
170struct ISVG
171{
172 ISVG(sk_sp<SkSVGDOM> svgDom)
173 : mSVGDom(svgDom)
174 {
175 }
176
178 float W() const
179 {
180 assert(mSVGDom);
181 return mSVGDom->containerSize().width();
182 }
183
185 float H() const
186 {
187 assert(mSVGDom);
188 return mSVGDom->containerSize().height();
189 }
190
192 inline bool IsValid() const { return mSVGDom != nullptr; }
193
194 sk_sp<SkSVGDOM> mSVGDom;
195};
196#else
197struct ISVG
198{
199 ISVG(NSVGimage* pImage)
200 {
201 mImage = pImage;
202 }
203
205 float W() const
206 {
207 assert(mImage);
208 return mImage->width;
209 }
210
212 float H() const
213 {
214 assert(mImage);
215 return mImage->height;
216 }
217
219 inline bool IsValid() const { return mImage != nullptr; }
220
221 NSVGimage* mImage = nullptr;
222};
223#endif
224
226struct IColor
227{
228 int A, R, G, B;
229
235 IColor(int a = 255, int r = 0, int g = 0, int b = 0) : A(a), R(r), G(g), B(b) {}
236
237 bool operator==(const IColor& rhs) { return (rhs.A == A && rhs.R == R && rhs.G == G && rhs.B == B); }
238 bool operator!=(const IColor& rhs) { return !operator==(rhs); }
239
245 void Set(int a = 255, int r = 0, int g = 0, int b = 0) { A = a; R = r; G = g; B = b; }
246
248 bool Empty() const { return A == 0 && R == 0 && G == 0 && B == 0; }
249
251 void Clamp() { A = Clip(A, 0, 255); R = Clip(R, 0, 255); G = Clip(G, 0, 255); B = Clip(B, 0, 255); }
252
255 void Randomise(int alpha = 255) { A = alpha; R = std::rand() % 255; G = std::rand() % 255; B = std::rand() % 255; }
256
259 void SetOpacity(float alpha)
260 {
261 A = static_cast<int>(Clip(alpha, 0.f, 1.f) * 255.f);
262 }
263
267 IColor WithOpacity(float alpha) const
268 {
269 IColor n = *this;
270 n.SetOpacity(alpha);
271 return n;
272 }
273
276 void Contrast(float c)
277 {
278 const int mod = static_cast<int>(c * 255.f);
279 R = Clip(R += mod, 0, 255);
280 G = Clip(G += mod, 0, 255);
281 B = Clip(B += mod, 0, 255);
282 }
283
287 IColor WithContrast(float c) const
288 {
289 IColor n = *this;
290 n.Contrast(c);
291 return n;
292 }
293
296 void GetRGBf(float* rgbf) const
297 {
298 rgbf[0] = R / 255.f;
299 rgbf[1] = G / 255.f;
300 rgbf[2] = B / 255.f;
301 }
302
305 void GetRGBAf(float* rgbaf) const
306 {
307 rgbaf[0] = R / 255.f;
308 rgbaf[1] = G / 255.f;
309 rgbaf[2] = B / 255.f;
310 rgbaf[3] = A / 255.f;
311 }
312
318 void GetHSLA(float& h, float& s, float& l, float& a) const
319 {
320 const float fR = R / 255.f;
321 const float fG = G / 255.f;
322 const float fB = B / 255.f;
323 a = A / 255.f;
324
325 const float fMin = std::min(fR, std::min(fG, fB));
326 const float fMax = std::max(fR, std::max(fG, fB));
327 const float fDiff = fMax - fMin;
328 const float fSum = fMax + fMin;
329
330 l = 50.f * fSum;
331
332 if (fMin == fMax) { s = 0.f; h = 0.f; l /= 100.f; return; }
333 else if (l < 50.f) { s = 100.f * fDiff / fSum; }
334 else { s = 100.f * fDiff / (2.f - fSum); }
335
336 if (fMax == fR) { h = 60.f * (fG - fB) / fDiff; }
337 if (fMax == fG) { h = 60.f * (fB - fR) / fDiff + 120.f; }
338 if (fMax == fB) { h = 60.f * (fR - fG) / fDiff + 240.f; }
339
340 if (h < 0.f) { h = h + 360.f; }
341
342 h /= 360.f;
343 s /= 100.f;
344 l /= 100.f;
345 }
346
349 int GetLuminosity() const
350 {
351 int min = R < G ? (R < B ? R : B) : (G < B ? G : B);
352 int max = R > G ? (R > B ? R : B) : (G > B ? G : B);
353 return (min + max) / 2;
354 };
355
359 static IColor GetRandomColor(bool randomAlpha = false)
360 {
361 int A = randomAlpha ? std::rand() & 0xFF : 255;
362 int R = std::rand() & 0xFF;
363 int G = std::rand() & 0xFF;
364 int B = std::rand() & 0xFF;
365
366 return IColor(A, R, G, B);
367 }
368
372 static IColor FromRGBf(float* rgbf)
373 {
374 int A = 255;
375 int R = static_cast<int>(rgbf[0] * 255.f);
376 int G = static_cast<int>(rgbf[1] * 255.f);
377 int B = static_cast<int>(rgbf[2] * 255.f);
378
379 return IColor(A, R, G, B);
380 }
381
385 static IColor FromRGBAf(float* rgbaf)
386 {
387 int R = static_cast<int>(rgbaf[0] * 255.f);
388 int G = static_cast<int>(rgbaf[1] * 255.f);
389 int B = static_cast<int>(rgbaf[2] * 255.f);
390 int A = static_cast<int>(rgbaf[3] * 255.f);
391
392 return IColor(A, R, G, B);
393 }
394
404 static IColor FromColorCode(int colorCode, int A = 0xFF)
405 {
406 int R = (colorCode >> 16) & 0xFF;
407 int G = (colorCode >> 8) & 0xFF;
408 int B = colorCode & 0xFF;
409
410 return IColor(A, R, G, B);
411 }
412
416 static IColor FromColorCodeStr(const char* hexStr)
417 {
418 WDL_String str(hexStr);
419
420 if ((str.GetLength() == 7 || str.GetLength() == 9) && str.Get()[0] == '#')
421 {
422 const bool hasAlpha = str.GetLength() == 9;
423 str.DeleteSub(0, 1);
424 const unsigned long colorCode = std::stoul(str.Get(), nullptr, 16);
425
426 if (hasAlpha)
427 return FromColorCode(static_cast<int>(colorCode >> 8), static_cast<int>(colorCode & 0xFF));
428
429 return FromColorCode(static_cast<int>(colorCode));
430 }
431 else
432 {
433 assert(0 && "Invalid color code str, returning black");
434 return IColor();
435 }
436 }
437
439 int ToColorCode() const
440 {
441 return (R << 16) | (G << 8) | B;
442 }
443
445 void ToColorCodeStr(WDL_String& str, bool withAlpha = true) const
446 {
447 if (withAlpha)
448 str.SetFormatted(32, "#%02x%02x%02x%02x", R, G, B, A);
449 else
450 str.SetFormatted(32, "#%02x%02x%02x", R, G, B);
451 }
452
459 static IColor FromHSLA(float h, float s, float l, float a = 1.f)
460 {
461 auto hue = [](float h, float m1, float m2) {
462 if (h < 0) h += 1;
463 if (h > 1) h -= 1;
464 if (h < 1.0f / 6.0f)
465 return m1 + (m2 - m1) * h * 6.0f;
466 else if (h < 3.0f / 6.0f)
467 return m2;
468 else if (h < 4.0f / 6.0f)
469 return m1 + (m2 - m1) * (2.0f / 3.0f - h) * 6.0f;
470 return m1;
471 };
472
473 IColor col;
474 h = std::fmod(h, 1.0f);
475 if (h < 0.0f) h += 1.0f;
476 s = Clip(s, 0.0f, 1.0f);
477 l = Clip(l, 0.0f, 1.0f);
478 float m2 = l <= 0.5f ? (l * (1 + s)) : (l + s - l * s);
479 float m1 = 2 * l - m2;
480 col.R = static_cast<int>(Clip(hue(h + 1.0f / 3.0f, m1, m2), 0.0f, 1.0f) * 255.f);
481 col.G = static_cast<int>(Clip(hue(h, m1, m2), 0.0f, 1.0f) * 255.f);
482 col.B = static_cast<int>(Clip(hue(h - 1.0f / 3.0f, m1, m2), 0.0f, 1.0f) * 255.f);
483 col.A = static_cast<int>(a * 255.f);
484 return col;
485 }
486
491 static IColor LinearInterpolateBetween(const IColor& start, const IColor& dest, float progress)
492 {
493 IColor result;
494 result.A = start.A + static_cast<int>(progress * static_cast<float>(dest.A - start.A));
495 result.R = start.R + static_cast<int>(progress * static_cast<float>(dest.R - start.R));
496 result.G = start.G + static_cast<int>(progress * static_cast<float>(dest.G - start.G));
497 result.B = start.B + static_cast<int>(progress * static_cast<float>(dest.B - start.B));
498 return result;
499 }
500};
501
502const IColor COLOR_TRANSPARENT(0, 0, 0, 0);
503const IColor COLOR_TRANSLUCENT(10, 0, 0, 0);
504const IColor COLOR_BLACK(255, 0, 0, 0);
505const IColor COLOR_BLACK_DROP_SHADOW(128, 0, 0, 0);
506const IColor COLOR_GRAY(255, 127, 127, 127);
507const IColor COLOR_LIGHT_GRAY(255, 240, 240, 240);
508const IColor COLOR_MID_GRAY(255, 200, 200, 200);
509const IColor COLOR_DARK_GRAY(255, 70, 70, 70);
510const IColor COLOR_WHITE(255, 255, 255, 255);
511const IColor COLOR_RED(255, 255, 0, 0);
512const IColor COLOR_GREEN(255, 0, 255, 0);
513const IColor COLOR_BLUE(255, 0, 0, 255);
514const IColor COLOR_YELLOW(255, 255, 255, 0);
515const IColor COLOR_ORANGE(255, 255, 127, 0);
516const IColor COLOR_INDIGO(255, 75, 0, 130);
517const IColor COLOR_VIOLET(255, 148, 0, 211);
518
519static IColor GetRainbow(int colorIdx)
520{
521 switch (colorIdx) {
522 case 0: return COLOR_RED;
523 case 1: return COLOR_ORANGE;
524 case 2: return COLOR_YELLOW;
525 case 3: return COLOR_GREEN;
526 case 4: return COLOR_BLUE;
527 case 5: return COLOR_INDIGO;
528 case 6: return COLOR_VIOLET;
529 default:
530 assert(0);
531 return COLOR_WHITE;
532 }
533}
534
535const IColor DEFAULT_GRAPHICS_BGCOLOR = COLOR_GRAY;
536const IColor DEFAULT_BGCOLOR = COLOR_TRANSPARENT;
537const IColor DEFAULT_FGCOLOR = COLOR_MID_GRAY;
538const IColor DEFAULT_PRCOLOR = COLOR_LIGHT_GRAY;
539
540const IColor DEFAULT_FRCOLOR = COLOR_DARK_GRAY;
541const IColor DEFAULT_HLCOLOR = COLOR_TRANSLUCENT;
542const IColor DEFAULT_SHCOLOR = IColor(60, 0, 0, 0);
543const IColor DEFAULT_X1COLOR = COLOR_BLACK;
544const IColor DEFAULT_X2COLOR = COLOR_GREEN;
545const IColor DEFAULT_X3COLOR = COLOR_BLUE;
546
547const IColor DEFAULT_TEXT_FGCOLOR = COLOR_BLACK;
548const IColor DEFAULT_TEXTENTRY_BGCOLOR = COLOR_WHITE;
549const IColor DEFAULT_TEXTENTRY_FGCOLOR = COLOR_BLACK;
550
552struct IBlend
553{
554 EBlend mMethod;
555 float mWeight;
556
560 IBlend(EBlend type = EBlend::Default, float weight = 1.0f)
561 : mMethod(type)
562 , mWeight(Clip(weight, 0.f, 1.f))
563 {}
564};
565
569inline float BlendWeight(const IBlend* pBlend)
570{
571 return (pBlend ? pBlend->mWeight : 1.0f);
572}
573
574const IBlend BLEND_75 = IBlend(EBlend::Default, 0.75f);
575const IBlend BLEND_50 = IBlend(EBlend::Default, 0.5f);
576const IBlend BLEND_25 = IBlend(EBlend::Default, 0.25f);
577const IBlend BLEND_10 = IBlend(EBlend::Default, 0.1f);
578const IBlend BLEND_05 = IBlend(EBlend::Default, 0.05f);
579const IBlend BLEND_01 = IBlend(EBlend::Default, 0.01f);
580const IBlend BLEND_DST_IN = IBlend(EBlend::DstIn, 1.f);
581const IBlend BLEND_DST_OVER = IBlend(EBlend::DstOver, 1.f);
582
585{
586 EFillRule mFillRule { EFillRule::Winding };
587 bool mPreserve { false };
588
589 IFillOptions(bool preserve = false, EFillRule fillRule = EFillRule::Winding)
590 : mFillRule(fillRule)
591 , mPreserve(preserve)
592 {
593 }
594
595};
596
599{
601 class DashOptions
602 {
603 public:
605 DashOptions()
606 : mOffset(0)
607 , mCount(0)
608 {}
609
614 DashOptions(float* array, float offset, int count)
615 {
616 SetDash(array, offset, count);
617 }
618
620 int GetCount() const { return mCount; }
621
623 float GetOffset() const { return mOffset; }
624
626 const float* GetArray() const { return mArray; }
627
632 void SetDash(float* pArray, float offset, int count)
633 {
634 assert(count >= 0 && count <= 8);
635
636 mCount = count;
637 mOffset = offset;
638
639 for (int i = 0; i < count; i++)
640 mArray[i] = pArray[i];
641 }
642
643 private:
644 float mArray[8] = {};
645 float mOffset;
646 int mCount;
647 };
648
649 float mMiterLimit = 10.f;
650 bool mPreserve = false;
651 ELineCap mCapOption = ELineCap::Butt;
652 ELineJoin mJoinOption = ELineJoin::Miter;
653 DashOptions mDash;
654};
655
657static const char* TextStyleString(ETextStyle style)
658{
659 switch (style)
660 {
661 case ETextStyle::Bold: return "Bold";
662 case ETextStyle::Italic: return "Italic";
663 case ETextStyle::Normal:
664 default:
665 return "Regular";
666 }
667}
668
670struct IText
671{
681 IText(float size = DEFAULT_TEXT_SIZE,
682 const IColor& color = DEFAULT_TEXT_FGCOLOR,
683 const char* fontID = nullptr,
684 EAlign align = EAlign::Center,
685 EVAlign valign = EVAlign::Middle,
686 float angle = 0,
687 const IColor& TEBGColor = DEFAULT_TEXTENTRY_BGCOLOR,
688 const IColor& TEFGColor = DEFAULT_TEXTENTRY_FGCOLOR)
689 : mSize(size)
690 , mFGColor(color)
691 , mTextEntryBGColor(TEBGColor)
692 , mTextEntryFGColor(TEFGColor)
693 , mAngle(angle)
694 , mAlign(align)
695 , mVAlign(valign)
696 {
697 strcpy(mFont, (fontID ? fontID : DEFAULT_FONT));
698 }
699
704 IText(float size, EVAlign valign, const IColor& color = DEFAULT_TEXT_FGCOLOR)
705 : IText()
706 {
707 mSize = size;
708 mVAlign = valign;
709 mFGColor = color;
710 }
711
716 IText(float size, EAlign align, const IColor& color = DEFAULT_TEXT_FGCOLOR)
717 : IText()
718 {
719 mSize = size;
720 mAlign = align;
721 mFGColor = color;
722 }
723
727 IText(float size, const char* fontID)
728 : IText()
729 {
730 mSize = size;
731 strcpy(mFont, (fontID ? fontID : DEFAULT_FONT));
732 }
733
734 IText WithFGColor(const IColor& fgColor) const { IText newText = *this; newText.mFGColor = fgColor; return newText; }
735 IText WithTEColors(const IColor& teBgColor, const IColor& teFgColor) const { IText newText = *this; newText.mTextEntryBGColor = teBgColor; newText.mTextEntryFGColor = teFgColor; return newText; }
736 IText WithAlign(EAlign align) const { IText newText = *this; newText.mAlign = align; return newText; }
737 IText WithVAlign(EVAlign valign) const { IText newText = *this; newText.mVAlign = valign; return newText; }
738 IText WithSize(float size) const { IText newText = *this; newText.mSize = size; return newText; }
739 IText WithAngle(float v) const { IText newText = *this; newText.mAngle = v; return newText; }
740 IText WithFont(const char* fontID) const { IText newText = *this; strcpy(newText.mFont, (fontID ? fontID : DEFAULT_FONT));; return newText; }
741
742 char mFont[FONT_LEN];
743 float mSize;
744 IColor mFGColor;
745 IColor mTextEntryBGColor;
746 IColor mTextEntryFGColor;
747 float mAngle = 0.f; // Degrees ccwise from normal.
748 EAlign mAlign = EAlign::Near;
749 EVAlign mVAlign = EVAlign::Middle;
750};
751
752const IText DEFAULT_TEXT = IText();
753
757struct IRECT
758{
759 float L, T, R, B;
760
763 {
764 L = T = R = B = 0.f;
765 }
766
772 IRECT(float l, float t, float r, float b)
773 : L(l), T(t), R(r), B(b)
774 {}
775
780 IRECT(float x, float y, const IBitmap& bitmap)
781 {
782 L = x;
783 T = y;
784 R = L + (float) bitmap.FW();
785 B = T + (float) bitmap.FH();
786 }
787
794 static IRECT MakeXYWH(float l, float t, float w, float h)
795 {
796 return IRECT(l, t, l+w, t+h);
797 }
798
805 static IRECT MakeMidXYWH(float x, float y, float w, float h)
806 {
807 return IRECT(x-(w/2.0f), y-(h/2.0f), x+(w/2.0f), y+(h/2.0f));
808 }
809
811 bool Empty() const
812 {
813 return (L == 0.f && T == 0.f && R == 0.f && B == 0.f);
814 }
815
817 void Clear()
818 {
819 L = T = R = B = 0.f;
820 }
821
822 bool operator==(const IRECT& rhs) const
823 {
824 return (L == rhs.L && T == rhs.T && R == rhs.R && B == rhs.B);
825 }
826
827 bool operator!=(const IRECT& rhs) const
828 {
829 return !(*this == rhs);
830 }
831
833 inline float W() const { return R - L; }
834
836 inline float H() const { return B - T; }
837
839 inline float MW() const { return 0.5f * (L + R); }
840
842 inline float MH() const { return 0.5f * (T + B); }
843
845 inline float Area() const { return W() * H(); }
846
851 inline IRECT Union(const IRECT& rhs) const
852 {
853 if (Empty()) { return rhs; }
854 if (rhs.Empty()) { return *this; }
855 return IRECT(std::min(L, rhs.L), std::min(T, rhs.T), std::max(R, rhs.R), std::max(B, rhs.B));
856 }
857
862 inline IRECT Intersect(const IRECT& rhs) const
863 {
864 if (Intersects(rhs))
865 return IRECT(std::max(L, rhs.L), std::max(T, rhs.T), std::min(R, rhs.R), std::min(B, rhs.B));
866
867 return IRECT();
868 }
869
874 inline bool Intersects(const IRECT& rhs) const
875 {
876 return (!Empty() && !rhs.Empty() && R >= rhs.L && L < rhs.R && B >= rhs.T && T < rhs.B);
877 }
878
883 inline bool Contains(const IRECT& rhs) const
884 {
885 return (!Empty() && !rhs.Empty() && rhs.L >= L && rhs.R <= R && rhs.T >= T && rhs.B <= B);
886 }
887
893 inline bool Contains(float x, float y) const
894 {
895 return (!Empty() && x >= L && x < R && y >= T && y < B);
896 }
897
904 inline bool ContainsEdge(float x, float y) const
905 {
906 return (!Empty() && x >= L && x <= R && y >= T && y <= B);
907 }
908
912 inline void Constrain(float& x, float& y) const
913 {
914 if (x < L) x = L;
915 else if (x > R) x = R;
916
917 if (y < T) y = T;
918 else if (y > B) y = B;
919 }
920
923 IRECT Inset(const IRECT& rhs) const
924 {
925 return IRECT(L + rhs.L, T + rhs.T, L + rhs.R, T + rhs.B);
926 }
927
933 bool Mergeable(const IRECT& rhs) const
934 {
935 if (Empty() || rhs.Empty())
936 return true;
937 if (L == rhs.L && R == rhs.R && ((T >= rhs.T && T <= rhs.B) || (rhs.T >= T && rhs.T <= B)))
938 return true;
939 return T == rhs.T && B == rhs.B && ((L >= rhs.L && L <= rhs.R) || (rhs.L >= L && rhs.L <= R));
940 }
941
948 inline IRECT FracRect(EDirection layoutDir, float frac, bool fromTopOrRight = false) const
949 {
950 if(layoutDir == EDirection::Vertical)
951 return FracRectVertical(frac, fromTopOrRight);
952 else
953 return FracRectHorizontal(frac, fromTopOrRight);
954 }
955
960 inline IRECT FracRectHorizontal(float frac, bool rhs = false) const
961 {
962 float widthOfSubRect = W() * frac;
963
964 if(rhs)
965 return IRECT(R - widthOfSubRect, T, R, B);
966 else
967 return IRECT(L, T, L + widthOfSubRect, B);
968 }
969
974 inline IRECT FracRectVertical(float frac, bool fromTop = false) const
975 {
976 float heightOfSubRect = H() * frac;
977
978 if(fromTop)
979 return IRECT(L, T, R, T + heightOfSubRect);
980 else
981 return IRECT(L, B - heightOfSubRect, R, B);
982 }
983
991 inline IRECT SubRectVertical(int numSlices, int sliceIdx) const
992 {
993 float heightOfSubRect = H() / (float) numSlices;
994 float t = heightOfSubRect * (float) sliceIdx;
995
996 return IRECT(L, T + t, R, T + t + heightOfSubRect);
997 }
998
1006 inline IRECT SubRectHorizontal(int numSlices, int sliceIdx) const
1007 {
1008 float widthOfSubRect = W() / (float) numSlices;
1009 float l = widthOfSubRect * (float) sliceIdx;
1010
1011 return IRECT(L + l, T, L + l + widthOfSubRect, B);
1012 }
1013
1019 inline IRECT SubRect(EDirection layoutDir, int numSlices, int sliceIdx) const
1020 {
1021 if(layoutDir == EDirection::Vertical)
1022 return SubRectVertical(numSlices, sliceIdx);
1023 else
1024 return SubRectHorizontal(numSlices, sliceIdx);
1025 }
1026
1031 inline IRECT GetFromTLHC(float w, float h) const { return IRECT(L, T, L+w, T+h); }
1032
1037 inline IRECT GetFromBLHC(float w, float h) const { return IRECT(L, B-h, L+w, B); }
1038
1043 inline IRECT GetFromTRHC(float w, float h) const { return IRECT(R-w, T, R, T+h); }
1044
1049 inline IRECT GetFromBRHC(float w, float h) const { return IRECT(R-w, B-h, R, B); }
1050
1054 inline IRECT GetFromTop(float amount) const { return IRECT(L, T, R, T+amount); }
1055
1059 inline IRECT GetFromBottom(float amount) const { return IRECT(L, B-amount, R, B); }
1060
1064 inline IRECT GetFromLeft(float amount) const { return IRECT(L, T, L+amount, B); }
1065
1069 inline IRECT GetFromRight(float amount) const { return IRECT(R-amount, T, R, B); }
1070
1074 inline IRECT GetReducedFromTop(float amount) const { return IRECT(L, T+amount, R, B); }
1075
1079 inline IRECT GetReducedFromBottom(float amount) const { return IRECT(L, T, R, B-amount); }
1080
1084 inline IRECT GetReducedFromLeft(float amount) const { return IRECT(L+amount, T, R, B); }
1085
1089 inline IRECT GetReducedFromRight(float amount) const { return IRECT(L, T, R-amount, B); }
1090
1094 inline IRECT ReduceFromTop(float amount) { IRECT r = GetFromTop(amount); T+=amount; return r; }
1095
1099 inline IRECT ReduceFromBottom(float amount) { IRECT r = GetFromBottom(amount); B-=amount; return r; }
1100
1104 inline IRECT ReduceFromLeft(float amount) { IRECT r = GetFromLeft(amount); L+=amount; return r; }
1105
1109 inline IRECT ReduceFromRight(float amount) { IRECT r = GetFromRight(amount); R-=amount; return r; }
1110
1117 inline IRECT GetGridCell(int row, int col, int nRows, int nColumns/*, EDirection = EDirection::Horizontal*/) const
1118 {
1119 assert(row * col <= nRows * nColumns); // not enough cells !
1120
1121 const IRECT vrect = SubRectVertical(nRows, row);
1122 return vrect.SubRectHorizontal(nColumns, col);
1123 }
1124
1132 inline IRECT GetGridCell(int cellIndex, int nRows, int nColumns, EDirection dir = EDirection::Horizontal, int nCells = 1) const
1133 {
1134 assert(cellIndex <= nRows * nColumns); // not enough cells !
1135
1136 int cell = 0;
1137
1138 if(dir == EDirection::Horizontal)
1139 {
1140 for(int row = 0; row < nRows; row++)
1141 {
1142 for(int col = 0; col < nColumns; col++)
1143 {
1144 if(cell == cellIndex)
1145 {
1146 const IRECT vrect = SubRectVertical(nRows, row);
1147 IRECT rect = vrect.SubRectHorizontal(nColumns, col);
1148
1149 for (int n = 1; n < nCells && (col + n) < nColumns; n++)
1150 {
1151 rect = rect.Union(vrect.SubRectHorizontal(nColumns, col + n));
1152 }
1153 return rect;
1154 }
1155
1156 cell++;
1157 }
1158 }
1159 }
1160 else
1161 {
1162 for(int col = 0; col < nColumns; col++)
1163 {
1164 for(int row = 0; row < nRows; row++)
1165 {
1166 if(cell == cellIndex)
1167 {
1168 const IRECT hrect = SubRectHorizontal(nColumns, col);
1169 IRECT rect = hrect.SubRectVertical(nRows, row);;
1170
1171 for (int n = 1; n < nCells && (row + n) < nRows; n++)
1172 {
1173 rect = rect.Union(hrect.SubRectVertical(nRows, row + n));
1174 }
1175 return rect;
1176 }
1177
1178 cell++;
1179 }
1180 }
1181 }
1182
1183 return *this;
1184 }
1185
1187 bool IsPixelAligned() const
1188 {
1189 // If all values are within 1/1000th of a pixel of an integer the IRECT is considered pixel aligned
1190
1191 auto isInteger = [](float x){ return std::fabs(x - std::round(x)) <= static_cast<float>(1e-3); };
1192
1193 return isInteger(L) && isInteger(T) && isInteger(R) && isInteger(B);
1194 }
1195
1200 bool IsPixelAligned(float scale) const
1201 {
1202 IRECT r = *this;
1203 r.Scale(scale);
1204 return r.IsPixelAligned();
1205 }
1206
1208 inline void PixelAlign()
1209 {
1210 L = std::floor(L);
1211 T = std::floor(T);
1212 R = std::ceil(R);
1213 B = std::ceil(B);
1214 }
1215
1219 inline void PixelAlign(float scale)
1220 {
1221 // N.B. - double precision is *required* for accuracy of the reciprocal
1222 Scale(scale);
1223 PixelAlign();
1224 Scale(static_cast<float>(1.0/static_cast<double>(scale)));
1225 }
1226
1229 inline IRECT GetPixelAligned() const
1230 {
1231 IRECT r = *this;
1232 r.PixelAlign();
1233 return r;
1234 }
1235
1239 inline IRECT GetPixelAligned(float scale) const
1240 {
1241 IRECT r = *this;
1242 r.PixelAlign(scale);
1243 return r;
1244 }
1245
1248 inline void PixelSnap()
1249 {
1250 L = std::round(L);
1251 T = std::round(T);
1252 R = std::round(R);
1253 B = std::round(B);
1254 }
1255
1258 inline void PixelSnap(float scale)
1259 {
1260 // N.B. - double precision is *required* for accuracy of the reciprocal
1261 Scale(scale);
1262 PixelSnap();
1263 Scale(static_cast<float>(1.0/static_cast<double>(scale)));
1264 }
1265
1267 inline IRECT GetPixelSnapped() const
1268 {
1269 IRECT r = *this;
1270 r.PixelSnap();
1271 return r;
1272 }
1273
1277 inline IRECT GetPixelSnapped(float scale) const
1278 {
1279 IRECT r = *this;
1280 r.PixelSnap(scale);
1281 return r;
1282 }
1283
1287 inline void Pad(float padding)
1288 {
1289 L -= padding;
1290 T -= padding;
1291 R += padding;
1292 B += padding;
1293 }
1294
1301 inline void Pad(float padL, float padT, float padR, float padB)
1302 {
1303 L -= padL;
1304 T -= padT;
1305 R += padR;
1306 B += padB;
1307 }
1308
1312 inline void HPad(float padding)
1313 {
1314 L -= padding;
1315 R += padding;
1316 }
1317
1321 inline void VPad(float padding)
1322 {
1323 T -= padding;
1324 B += padding;
1325 }
1326
1329 inline void MidHPad(float padding)
1330 {
1331 const float mw = MW();
1332 L = mw - padding;
1333 R = mw + padding;
1334 }
1335
1338 inline void MidVPad(float padding)
1339 {
1340 const float mh = MH();
1341 T = mh - padding;
1342 B = mh + padding;
1343 }
1344
1349 inline IRECT GetPadded(float padding) const
1350 {
1351 return IRECT(L-padding, T-padding, R+padding, B+padding);
1352 }
1353
1361 inline IRECT GetPadded(float padL, float padT, float padR, float padB) const
1362 {
1363 return IRECT(L-padL, T-padT, R+padR, B+padB);
1364 }
1365
1370 inline IRECT GetHPadded(float padding) const
1371 {
1372 return IRECT(L-padding, T, R+padding, B);
1373 }
1374
1379 inline IRECT GetVPadded(float padding) const
1380 {
1381 return IRECT(L, T-padding, R, B+padding);
1382 }
1383
1387 inline IRECT GetMidHPadded(float padding) const
1388 {
1389 return IRECT(MW()-padding, T, MW()+padding, B);
1390 }
1391
1395 inline IRECT GetMidVPadded(float padding) const
1396 {
1397 return IRECT(L, MH()-padding, R, MH()+padding);
1398 }
1399
1404 inline IRECT GetHSliced(float w, bool rhs = false) const
1405 {
1406 if(rhs)
1407 return IRECT(R - w, T, R, B);
1408 else
1409 return IRECT(L, T, L + w, B);
1410 }
1411
1416 inline IRECT GetVSliced(float h, bool bot = false) const
1417 {
1418 if(bot)
1419 return IRECT(L, B - h, R, B);
1420 else
1421 return IRECT(L, T, R, T + h);
1422 }
1423
1426 void Clank(const IRECT& rhs)
1427 {
1428 if (L < rhs.L)
1429 {
1430 R = std::min(rhs.R - 1, R + rhs.L - L);
1431 L = rhs.L;
1432 }
1433 if (T < rhs.T)
1434 {
1435 B = std::min(rhs.B - 1, B + rhs.T - T);
1436 T = rhs.T;
1437 }
1438 if (R >= rhs.R)
1439 {
1440 L = std::max(rhs.L, L - (R - rhs.R + 1));
1441 R = rhs.R - 1;
1442 }
1443 if (B >= rhs.B)
1444 {
1445 T = std::max(rhs.T, T - (B - rhs.B + 1));
1446 B = rhs.B - 1;
1447 }
1448 }
1449
1452 void Scale(float scale)
1453 {
1454 L *= scale;
1455 T *= scale;
1456 R *= scale;
1457 B *= scale;
1458 }
1459
1462 void ScaleAboutCentre(float scale)
1463 {
1464 float x = MW();
1465 float y = MH();
1466 float hw = W() / 2.f;
1467 float hh = H() / 2.f;
1468 L = x - (hw * scale);
1469 T = y - (hh * scale);
1470 R = x + (hw * scale);
1471 B = y + (hh * scale);
1472 }
1473
1477 IRECT GetScaled(float scale) const
1478 {
1479 IRECT r = *this;
1480 r.Scale(scale);
1481 return r;
1482 }
1483
1487 IRECT GetScaledAboutCentre(float scale) const
1488 {
1489 IRECT r = *this;
1490 r.ScaleAboutCentre(scale);
1491 return r;
1492 }
1493
1499 static IRECT LinearInterpolateBetween(const IRECT& start, const IRECT& dest, float progress)
1500 {
1501 IRECT result;
1502 result.L = start.L + progress * (dest.L - start.L);
1503 result.T = start.T + progress * (dest.T - start.T);
1504 result.R = start.R + progress * (dest.R - start.R);
1505 result.B = start.B + progress * (dest.B - start.B);
1506 return result;
1507 }
1508
1512 void GetRandomPoint(float& x, float& y) const
1513 {
1514 const float r1 = static_cast<float>(std::rand()/(static_cast<float>(RAND_MAX)+1.f));
1515 const float r2 = static_cast<float>(std::rand()/(static_cast<float>(RAND_MAX)+1.f));
1516
1517 x = L + r1 * W();
1518 y = T + r2 * H();
1519 }
1520
1523 {
1524 float l, t, r, b;
1525 GetRandomPoint(l, t);
1526 IRECT tmp = IRECT(l, t, R, B);
1527 tmp.GetRandomPoint(r, b);
1528
1529 return IRECT(l, t, r, b);
1530 }
1531
1537 void Offset(float l, float t, float r, float b)
1538 {
1539 L += l;
1540 T += t;
1541 R += r;
1542 B += b;
1543 }
1544
1551 IRECT GetOffset(float l, float t, float r, float b) const
1552 {
1553 return IRECT(L + l, T + t, R + r, B + b);
1554 }
1555
1559 void Translate(float x, float y)
1560 {
1561 L += x;
1562 T += y;
1563 R += x;
1564 B += y;
1565 }
1566
1571 IRECT GetTranslated(float x, float y) const
1572 {
1573 return IRECT(L + x, T + y, R + x, B + y);
1574 }
1575
1579 IRECT GetHShifted(float x) const
1580 {
1581 return GetTranslated(x, 0.f);
1582 }
1583
1587 IRECT GetVShifted(float y) const
1588 {
1589 return GetTranslated(0.f, y);
1590 }
1591
1596 {
1597 IRECT r;
1598 r.L = MW() - sr.W() / 2.f;
1599 r.T = MH() - sr.H() / 2.f;
1600 r.R = r.L + sr.W();
1601 r.B = r.T + sr.H();
1602
1603 return r;
1604 }
1605
1610 IRECT GetCentredInside(float w, float h = 0.f) const
1611 {
1612 w = std::max(w, 1.f);
1613
1614 if(h <= 0.f)
1615 h = w;
1616
1617 IRECT r;
1618 r.L = MW() - w / 2.f;
1619 r.T = MH() - h / 2.f;
1620 r.R = r.L + w;
1621 r.B = r.T + h;
1622
1623 return r;
1624 }
1625
1629 IRECT GetCentredInside(const IBitmap& bitmap) const
1630 {
1631 IRECT r;
1632 r.L = MW() - bitmap.FW() / 2.f;
1633 r.T = MH() - bitmap.FH() / 2.f;
1634 r.R = r.L + (float) bitmap.FW();
1635 r.B = r.T + (float) bitmap.FH();
1636
1637 return r;
1638 }
1639
1643 void VAlignTo(const IRECT& sr, EVAlign align)
1644 {
1645 const float height = H();
1646 switch (align)
1647 {
1648 case EVAlign::Top: T = sr.T; B = sr.T + height; break;
1649 case EVAlign::Bottom: T = sr.B - height; B = sr.B; break;
1650 case EVAlign::Middle: T = sr.T + (sr.H() * 0.5f) - (height * 0.5f); B = sr.T + (sr.H() * 0.5f) - (height * 0.5f) + height; break;
1651 }
1652 }
1653
1657 void HAlignTo(const IRECT& sr, EAlign align)
1658 {
1659 const float width = W();
1660 switch (align)
1661 {
1662 case EAlign::Near: L = sr.L; R = sr.L + width; break;
1663 case EAlign::Far: L = sr.R - width; R = sr.R; break;
1664 case EAlign::Center: L = sr.L + (sr.W() * 0.5f) - (width * 0.5f); R = sr.L + (sr.W() * 0.5f) - (width * 0.5f) + width; break;
1665 }
1666 }
1667
1672 IRECT GetVAlignedTo(const IRECT& sr, EVAlign align) const
1673 {
1674 IRECT result = *this;
1675 result.VAlignTo(sr, align);
1676 return result;
1677 }
1678
1681 {
1682 if(W() < H())
1683 return W();
1684 else
1685 return H();
1686 }
1687
1692 IRECT GetHAlignedTo(const IRECT& sr, EAlign align) const
1693 {
1694 IRECT result = *this;
1695 result.HAlignTo(sr, align);
1696 return result;
1697 }
1698
1700 void DBGPrint() { DBGMSG("L: %f, T: %f, R: %f, B: %f,: W: %f, H: %f\n", L, T, R, B, W(), H()); }
1701};
1702
1705{
1706 bool L, R, S, C, A;
1707 ITouchID touchID = 0;
1708 float touchRadius = 0.f;
1709
1717 IMouseMod(bool l = false, bool r = false, bool s = false, bool c = false, bool a = false, ITouchID touchID = 0)
1718 : L(l), R(r), S(s), C(c), A(a), touchID(touchID)
1719 {}
1720
1722 bool IsTouch() const { return touchID > 0; }
1723
1725 void DBGPrint() { DBGMSG("L: %i, R: %i, S: %i, C: %i,: A: %i\n", L, R, S, C, A); }
1726};
1727
1730{
1731 float x = 0.0, y = 0.0;
1732 float dX = 0.0, dY = 0.0;
1733 IMouseMod ms;
1734};
1735
1738{
1739 float x = 0.f;
1740 float y = 0.f;
1741 float scale = 0.f; // pinch,
1742 float velocity = 0.f; // pinch, rotate
1743 float angle = 0.f; // rotate,
1744 EGestureState state = EGestureState::Unknown;
1745 EGestureType type = EGestureType::Unknown;
1746};
1747
1750{
1751public:
1752 IRECTList()
1753 {}
1754
1755 IRECTList(const IRECTList&) = delete;
1756 IRECTList& operator=(const IRECTList&) = delete;
1757
1759 int Size() const { return mRects.GetSize(); }
1760
1763 void Add(const IRECT& rect)
1764 {
1765 mRects.Add(rect);
1766 }
1767
1771 void Set(int idx, const IRECT& rect)
1772 {
1773 *(mRects.GetFast() + idx) = rect;
1774 }
1775
1779 const IRECT& Get(int idx) const
1780 {
1781 return *(mRects.GetFast() + idx);
1782 }
1783
1785 void Clear()
1786 {
1787 mRects.Resize(0);
1788 }
1789
1793 {
1794 IRECT r = Get(0);
1795 for (auto i = 1; i < mRects.GetSize(); i++)
1796 r = r.Union(Get(i));
1797 return r;
1798 }
1799
1802 {
1803 for (auto i = 0; i < Size(); i++)
1804 {
1805 IRECT r = Get(i);
1806 r.PixelAlign();
1807 Set(i, r);
1808 }
1809 }
1810
1813 void PixelAlign(float scale)
1814 {
1815 for (auto i = 0; i < Size(); i++)
1816 {
1817 IRECT r = Get(i);
1818 r.PixelAlign(scale);
1819 Set(i, r);
1820 }
1821 }
1822
1827 int Find(float x, float y) const
1828 {
1829 for (auto i = 0; i < Size(); i++)
1830 {
1831 if(Get(i).Contains(x, y))
1832 return i;
1833 }
1834
1835 return -1;
1836 }
1837
1845 static bool GetFracGrid(const IRECT& input, IRECTList& rects, const std::initializer_list<float>& rowFractions, const std::initializer_list<float>& colFractions, EDirection layoutDir = EDirection::Horizontal)
1846 {
1847 IRECT spaceLeft = input;
1848 float y = 0.;
1849 float x = 0.;
1850
1851 // the fractions are summed in single precision, so allow for rounding error
1852 const float tolerance = 1e-4f;
1853
1854 if(std::abs(std::accumulate(rowFractions.begin(), rowFractions.end(), 0.f) - 1.f) > tolerance)
1855 return false;
1856
1857 if(std::abs(std::accumulate(colFractions.begin(), colFractions.end(), 0.f) - 1.f) > tolerance)
1858 return false;
1859
1860 if (layoutDir == EDirection::Horizontal)
1861 {
1862 for (auto& rowFrac : rowFractions)
1863 {
1864 IRECT thisRow = input.FracRectVertical(rowFrac, true).GetTranslated(0, y);
1865
1866 x = 0.;
1867
1868 for (auto& colFrac : colFractions)
1869 {
1870 IRECT thisCell = thisRow.FracRectHorizontal(colFrac).GetTranslated(x, 0);
1871
1872 rects.Add(thisCell);
1873
1874 x += thisCell.W();
1875 }
1876
1877 spaceLeft.Intersect(thisRow);
1878
1879 y = rects.Bounds().H();
1880 }
1881 }
1882
1883 if (layoutDir == EDirection::Vertical)
1884 {
1885 for (auto& colFrac : colFractions)
1886 {
1887 IRECT thisCol = input.FracRectHorizontal(colFrac).GetTranslated(x, 0);
1888
1889 y = 0.;
1890
1891 for (auto& rowFrac : rowFractions)
1892 {
1893 IRECT thisCell = thisCol.FracRectVertical(rowFrac, true).GetTranslated(0, y);
1894
1895 rects.Add(thisCell);
1896
1897 y += thisCell.H();
1898 }
1899
1900 spaceLeft.Intersect(thisCol);
1901
1902 x = rects.Bounds().W();
1903 }
1904 }
1905
1906 return true;
1907 }
1908
1911 {
1912 for (int i = 0; i < Size(); i++)
1913 {
1914 for (int j = i + 1; j < Size(); j++)
1915 {
1916 if (Get(i).Contains(Get(j)))
1917 {
1918 mRects.Delete(j);
1919 j--;
1920 }
1921 else if (Get(j).Contains(Get(i)))
1922 {
1923 mRects.Delete(i);
1924 i--;
1925 break;
1926 }
1927 else if (Get(i).Intersects(Get(j)))
1928 {
1929 IRECT intersection = Get(i).Intersect(Get(j));
1930
1931 if (Get(i).Mergeable(intersection))
1932 Set(i, Shrink(Get(i), intersection));
1933 else if (Get(j).Mergeable(intersection))
1934 Set(j, Shrink(Get(j), intersection));
1935 else if (Get(i).Area() < Get(j).Area())
1936 Set(i, Split(Get(i), intersection));
1937 else
1938 Set(j, Split(Get(j), intersection));
1939 }
1940 }
1941 }
1942
1943 for (int i = 0; i < Size(); i++)
1944 {
1945 for (int j = i + 1; j < Size(); j++)
1946 {
1947 if (Get(i).Mergeable(Get(j)))
1948 {
1949 Set(j, Get(i).Union(Get(j)));
1950 mRects.Delete(i);
1951 i = -1;
1952 break;
1953 }
1954 }
1955 }
1956 }
1957
1958private:
1963 IRECT Shrink(const IRECT &r, const IRECT &i)
1964 {
1965 if (i.L != r.L)
1966 return IRECT(r.L, r.T, i.L, r.B);
1967 if (i.T != r.T)
1968 return IRECT(r.L, r.T, r.R, i.T);
1969 if (i.R != r.R)
1970 return IRECT(i.R, r.T, r.R, r.B);
1971 return IRECT(r.L, i.B, r.R, r.B);
1972 }
1973
1978 IRECT Split(const IRECT r, const IRECT &i)
1979 {
1980 if (r.L == i.L)
1981 {
1982 if (r.T == i.T)
1983 {
1984 Add(IRECT(i.R, r.T, r.R, i.B));
1985 return IRECT(r.L, i.B, r.R, r.B);
1986 }
1987 else
1988 {
1989 Add(IRECT(r.L, r.T, r.R, i.T));
1990 return IRECT(i.R, i.T, r.R, r.B);
1991 }
1992 }
1993
1994 if (r.T == i.T)
1995 {
1996 Add(IRECT(r.L, r.T, i.L, i.B));
1997 return IRECT(r.L, i.B, r.R, r.B);
1998 }
1999 else
2000 {
2001 Add(IRECT(r.L, r.T, r.R, i.T));
2002 return IRECT(r.L, i.T, i.L, r.B);
2003 }
2004 }
2005
2006 WDL_TypedBuf<IRECT> mRects;
2007};
2008
2011{
2019 IMatrix(double xx, double yx, double xy, double yy, double tx, double ty)
2020 : mXX(xx), mYX(yx), mXY(xy), mYY(yy), mTX(tx), mTY(ty)
2021 {}
2022
2024 IMatrix() : IMatrix(1.0, 0.0, 0.0, 1.0, 0.0, 0.0)
2025 {}
2026
2031 IMatrix& Translate(float x, float y)
2032 {
2033 return Transform(IMatrix(1.0, 0.0, 0.0, 1.0, x, y));
2034 }
2035
2040 IMatrix& Scale(float x, float y)
2041 {
2042 return Transform(IMatrix(x, 0.0, 0.0, y, 0.0, 0.0));
2043 }
2044
2048 IMatrix& Rotate(float a)
2049 {
2050 const double rad = DegToRad(a);
2051 const double c = std::cos(rad);
2052 const double s = std::sin(rad);
2053
2054 return Transform(IMatrix(c, s, -s, c, 0.0, 0.0));
2055 }
2056
2061 IMatrix& Skew(float xa, float ya)
2062 {
2063 return Transform(IMatrix(1.0, std::tan(DegToRad(ya)), std::tan(DegToRad(xa)), 1.0, 0.0, 0.0));
2064 }
2065
2071 void TransformPoint(double& x, double& y, double x0, double y0) const
2072 {
2073 x = x0 * mXX + y0 * mXY + mTX;
2074 y = x0 * mYX + y0 * mYY + mTY;
2075 };
2076
2080 void TransformPoint(double& x, double& y) const
2081 {
2082 TransformPoint(x, y, x, y);
2083 };
2084
2089 IMatrix& Transform(const IRECT& before, const IRECT& after)
2090 {
2091 const double sx = after.W() / before.W();
2092 const double sy = after.H() / before.H();
2093 const double tx = after.L - before.L * sx;
2094 const double ty = after.T - before.T * sy;
2095
2096 return *this = IMatrix(sx, 0.0, 0.0, sy, tx, ty);
2097 }
2098
2103 {
2104 IMatrix p = *this;
2105
2106 mXX = m.mXX * p.mXX + m.mYX * p.mXY;
2107 mYX = m.mXX * p.mYX + m.mYX * p.mYY;
2108 mXY = m.mXY * p.mXX + m.mYY * p.mXY;
2109 mYY = m.mXY * p.mYX + m.mYY * p.mYY;
2110 mTX = m.mTX * p.mXX + m.mTY * p.mXY + p.mTX;
2111 mTY = m.mTX * p.mYX + m.mTY * p.mYY + p.mTY;
2112
2113 return *this;
2114 }
2115
2119 {
2120 IMatrix m = *this;
2121
2122 double d = 1.0 / (m.mXX * m.mYY - m.mYX * m.mXY);
2123
2124 mXX = m.mYY * d;
2125 mYX = -m.mYX * d;
2126 mXY = -m.mXY * d;
2127 mYY = m.mXX * d;
2128 mTX = (-(m.mTX * mXX) - (m.mTY * mXY));
2129 mTY = (-(m.mTX * mYX) - (m.mTY * mYY));
2130
2131 return *this;
2132 }
2133
2134 double mXX, mYX, mXY, mYY, mTX, mTY;
2135};
2136
2139{
2140 IColorStop()
2141 : mOffset(0.f)
2142 {}
2143
2147 IColorStop(IColor color, float offset)
2148 : mColor(color)
2149 , mOffset(offset)
2150 {
2151 assert(offset >= 0.0 && offset <= 1.0);
2152 }
2153
2154 IColor mColor;
2155 float mOffset;
2156};
2157
2160{
2161 EPatternType mType;
2162 EPatternExtend mExtend;
2163 IColorStop mStops[16];
2164 int mNStops;
2165 IMatrix mTransform;
2166
2169 IPattern(EPatternType type)
2170 : mType(type), mExtend(EPatternExtend::Pad), mNStops(0)
2171 {}
2172
2175 IPattern(const IColor& color)
2176 : mType(EPatternType::Solid), mExtend(EPatternExtend::Pad), mNStops(1)
2177 {
2178 mStops[0] = IColorStop(color, 0.0);
2179 }
2180
2188 static IPattern CreateLinearGradient(float x1, float y1, float x2, float y2, const std::initializer_list<IColorStop>& stops = {})
2189 {
2190 IPattern pattern(EPatternType::Linear);
2191
2192 // Calculate the affine transform from one line segment to another!
2193 const double xd = double(x2 - x1);
2194 const double yd = double(y2 - y1);
2195 const double d = sqrt(xd * xd + yd * yd);
2196 const double a = atan2(xd, yd);
2197 const double s = std::sin(a) / d;
2198 const double c = std::cos(a) / d;
2199
2200 const double x0 = -(x1 * c - y1 * s);
2201 const double y0 = -(x1 * s + y1 * c);
2202
2203 pattern.SetTransform(static_cast<float>(c),
2204 static_cast<float>(s),
2205 static_cast<float>(-s),
2206 static_cast<float>(c),
2207 static_cast<float>(x0),
2208 static_cast<float>(y0));
2209
2210 for (auto& stop : stops)
2211 pattern.AddStop(stop.mColor, stop.mOffset);
2212
2213 return pattern;
2214 }
2215
2221 static IPattern CreateLinearGradient(const IRECT& bounds, EDirection direction, const std::initializer_list<IColorStop>& stops = {})
2222 {
2223 float x1, y1, x2, y2;
2224
2225 if(direction == EDirection::Horizontal)
2226 {
2227 y1 = bounds.MH(); y2 = y1;
2228 x1 = bounds.L;
2229 x2 = bounds.R;
2230 }
2231 else//(direction == EDirection::Vertical)
2232 {
2233 x1 = bounds.MW(); x2 = x1;
2234 y1 = bounds.T;
2235 y2 = bounds.B;
2236 }
2237
2238 return CreateLinearGradient(x1, y1, x2, y2, stops);
2239 }
2240
2247 static IPattern CreateRadialGradient(float x1, float y1, float r, const std::initializer_list<IColorStop>& stops = {})
2248 {
2249 IPattern pattern(EPatternType::Radial);
2250
2251 const float s = 1.f / r;
2252
2253 pattern.SetTransform(s, 0, 0, s, -(x1 * s), -(y1 * s));
2254
2255 for (auto& stop : stops)
2256 pattern.AddStop(stop.mColor, stop.mOffset);
2257
2258 return pattern;
2259 }
2260
2268 static IPattern CreateSweepGradient(float x1, float y1, const std::initializer_list<IColorStop>& stops = {},
2269 float angleStart = 0.f, float angleEnd = 360.f)
2270 {
2271 IPattern pattern(EPatternType::Sweep);
2272
2273 #ifdef IGRAPHICS_SKIA
2274 angleStart -= 90;
2275 angleEnd -= 90;
2276 #endif
2277
2278 float rad = DegToRad(angleStart);
2279 float c = std::cos(rad);
2280 float s = std::sin(rad);
2281
2282 pattern.SetTransform(c, s, -s, c, -x1, -y1);
2283
2284 for (auto& stop : stops)
2285 {
2286 pattern.AddStop(stop.mColor, stop.mOffset * (angleEnd - angleStart) / 360.f);
2287 }
2288 return pattern;
2289 }
2290
2292 int NStops() const
2293 {
2294 return mNStops;
2295 }
2296
2300 const IColorStop& GetStop(int idx) const
2301 {
2302 return mStops[idx];
2303 }
2304
2308 void AddStop(IColor color, float offset)
2309 {
2310 assert(mType != EPatternType::Solid && mNStops < 16);
2311 assert(!mNStops || GetStop(mNStops - 1).mOffset < offset);
2312 if (mNStops < 16)
2313 mStops[mNStops++] = IColorStop(color, offset);
2314 }
2315
2323 void SetTransform(float xx, float yx, float xy, float yy, float tx, float ty)
2324 {
2325 mTransform = IMatrix(xx, yx, xy, yy, tx, ty);
2326 }
2327
2330 void SetTransform(const IMatrix& transform)
2331 {
2332 mTransform = transform;
2333 }
2334};
2335
2341{
2342 friend IGraphics;
2343
2344public:
2350 ILayer(APIBitmap* pBitmap, const IRECT& layerRect, IControl* pControl, const IRECT& controlRect)
2351 : mBitmap(pBitmap)
2352 , mControl(pControl)
2353 , mControlRECT(controlRect)
2354 , mRECT(layerRect)
2355 , mInvalid(false)
2356 {}
2357
2358 ILayer(const ILayer&) = delete;
2359 ILayer operator=(const ILayer&) = delete;
2360
2362 void Invalidate() { mInvalid = true; }
2363
2365 const APIBitmap* GetAPIBitmap() const { return mBitmap.get(); }
2366
2368 IBitmap GetBitmap() const { return IBitmap(mBitmap.get(), 1, false); }
2369
2371 const IRECT& Bounds() const { return mRECT; }
2372
2373private:
2374 std::unique_ptr<APIBitmap> mBitmap;
2375 IControl* mControl;
2376 IRECT mControlRECT;
2377 IRECT mRECT;
2378 bool mInvalid;
2379};
2380
2382using ILayerPtr = std::unique_ptr<ILayer>;
2383
2386{
2387 IShadow() {}
2388
2396 IShadow(const IPattern& pattern, float blurSize, float xOffset, float yOffset, float opacity, bool drawForeground = true)
2397 : mPattern(pattern)
2398 , mBlurSize(blurSize)
2399 , mXOffset(xOffset)
2400 , mYOffset(yOffset)
2401 , mOpacity(opacity)
2402 , mDrawForeground(drawForeground)
2403 {}
2404
2405 IPattern mPattern = COLOR_BLACK;
2406 float mBlurSize = 0.f;
2407 float mXOffset = 0.f;
2408 float mYOffset = 0.f;
2409 float mOpacity = 1.f;
2410 bool mDrawForeground = true;
2411};
2412
2415{
2416 IColor mColors[kNumVColors];
2417
2419 const IColor& GetColor(EVColor color) const
2420 {
2421 return mColors[(int) color];
2422 }
2423
2425 static const IColor& GetDefaultColor(EVColor idx)
2426 {
2427 switch(idx)
2428 {
2429 case kBG: return DEFAULT_BGCOLOR; // Background
2430 case kFG: return DEFAULT_FGCOLOR; // OFF/Foreground
2431 case kPR: return DEFAULT_PRCOLOR; // ON/Pressed
2432 case kFR: return DEFAULT_FRCOLOR; // Frame
2433 case kHL: return DEFAULT_HLCOLOR; // Highlight
2434 case kSH: return DEFAULT_SHCOLOR; // Shadow
2435 case kX1: return DEFAULT_X1COLOR; // Extra 1
2436 case kX2: return DEFAULT_X2COLOR; // Extra 2
2437 case kX3: return DEFAULT_X3COLOR; // Extra 3
2438 default:
2439 return COLOR_TRANSPARENT;
2440 };
2441 }
2442
2445 {
2446 ResetColors();
2447 }
2448
2451 IVColorSpec(const std::initializer_list<IColor>& colors)
2452 {
2453 assert(colors.size() <= kNumVColors);
2454
2455 int i = 0;
2456
2457 for(auto& c : colors)
2458 {
2459 mColors[i++] = c;
2460 }
2461
2462 for(; i<kNumVColors; i++)
2463 {
2464 mColors[i] = GetDefaultColor((EVColor) i);
2465 }
2466 }
2467
2470 {
2471 for (int i=0; i<kNumVColors; i++)
2472 {
2473 mColors[i] = GetDefaultColor((EVColor) i);
2474 }
2475 }
2476};
2477
2478const IVColorSpec DEFAULT_COLOR_SPEC = IVColorSpec();
2479
2480static constexpr bool DEFAULT_HIDE_CURSOR = true;
2481static constexpr bool DEFAULT_SHOW_VALUE = true;
2482static constexpr bool DEFAULT_SHOW_LABEL = true;
2483static constexpr bool DEFAULT_DRAW_FRAME = true;
2484static constexpr bool DEFAULT_DRAW_SHADOWS = true;
2485static constexpr bool DEFAULT_EMBOSS = false;
2486static constexpr float DEFAULT_ROUNDNESS = 0.f;
2487static constexpr float DEFAULT_FRAME_THICKNESS = 1.f;
2488static constexpr float DEFAULT_SHADOW_OFFSET = 3.f;
2489static constexpr float DEFAULT_WIDGET_FRAC = 1.f;
2490static constexpr float DEFAULT_WIDGET_ANGLE = 0.f;
2491static constexpr EOrientation DEFAULT_LABEL_ORIENTATION = EOrientation::North;
2492const IText DEFAULT_LABEL_TEXT {DEFAULT_TEXT_SIZE + 5.f, EVAlign::Top};
2493const IText DEFAULT_VALUE_TEXT {DEFAULT_TEXT_SIZE, EVAlign::Bottom};
2494
2497{
2498 bool hideCursor = DEFAULT_HIDE_CURSOR;
2499 bool showLabel = DEFAULT_SHOW_LABEL;
2500 bool showValue = DEFAULT_SHOW_VALUE;
2501 bool drawFrame = DEFAULT_DRAW_FRAME;
2502 bool drawShadows = DEFAULT_DRAW_SHADOWS;
2503 bool emboss = DEFAULT_EMBOSS;
2504 float roundness = DEFAULT_ROUNDNESS;
2505 float frameThickness = DEFAULT_FRAME_THICKNESS;
2506 float shadowOffset = DEFAULT_SHADOW_OFFSET;
2507 float widgetFrac = DEFAULT_WIDGET_FRAC;
2508 float angle = DEFAULT_WIDGET_ANGLE;
2509 IVColorSpec colorSpec = DEFAULT_COLOR_SPEC;
2510 IText labelText = DEFAULT_LABEL_TEXT;
2511 IText valueText = DEFAULT_VALUE_TEXT;
2512 EOrientation labelOrientation = DEFAULT_LABEL_ORIENTATION;
2513
2530 IVStyle(bool showLabel = DEFAULT_SHOW_LABEL,
2531 bool showValue = DEFAULT_SHOW_VALUE,
2532 const IVColorSpec& colors = {DEFAULT_BGCOLOR, DEFAULT_FGCOLOR, DEFAULT_PRCOLOR, DEFAULT_FRCOLOR, DEFAULT_HLCOLOR, DEFAULT_SHCOLOR, DEFAULT_X1COLOR, DEFAULT_X2COLOR, DEFAULT_X3COLOR},
2533 const IText& labelText = DEFAULT_LABEL_TEXT,
2534 const IText& valueText = DEFAULT_VALUE_TEXT,
2535 bool hideCursor = DEFAULT_HIDE_CURSOR,
2536 bool drawFrame = DEFAULT_DRAW_FRAME,
2537 bool drawShadows = DEFAULT_DRAW_SHADOWS,
2538 bool emboss = DEFAULT_EMBOSS,
2539 float roundness = DEFAULT_ROUNDNESS,
2540 float frameThickness = DEFAULT_FRAME_THICKNESS,
2541 float shadowOffset = DEFAULT_SHADOW_OFFSET,
2542 float widgetFrac = DEFAULT_WIDGET_FRAC,
2543 float angle = DEFAULT_WIDGET_ANGLE,
2544 EOrientation labelOrientation = DEFAULT_LABEL_ORIENTATION)
2545 : hideCursor(hideCursor)
2546 , showLabel(showLabel)
2547 , showValue(showValue)
2548 , drawFrame(drawFrame)
2549 , drawShadows(drawShadows)
2550 , emboss(emboss)
2551 , roundness(roundness)
2552 , frameThickness(frameThickness)
2553 , shadowOffset(shadowOffset)
2554 , widgetFrac(widgetFrac)
2555 , angle(angle)
2556 , colorSpec(colors)
2557 , labelText(labelText)
2558 , valueText(valueText)
2559 , labelOrientation(labelOrientation)
2560 {
2561 }
2562
2565 IVStyle(const std::initializer_list<IColor>& colors)
2566 : colorSpec(colors)
2567 {
2568 }
2569
2570 IVStyle WithShowLabel(bool show = true) const { IVStyle newStyle = *this; newStyle.showLabel = show; return newStyle; }
2571 IVStyle WithShowValue(bool show = true) const { IVStyle newStyle = *this; newStyle.showValue = show; return newStyle; }
2572 IVStyle WithLabelText(const IText& text) const { IVStyle newStyle = *this; newStyle.labelText = text; return newStyle;}
2573 IVStyle WithValueText(const IText& text) const { IVStyle newStyle = *this; newStyle.valueText = text; return newStyle; }
2574 IVStyle WithHideCursor(bool hide = true) const { IVStyle newStyle = *this; newStyle.hideCursor = hide; return newStyle; }
2575 IVStyle WithColor(EVColor idx, IColor color) const { IVStyle newStyle = *this; newStyle.colorSpec.mColors[idx] = color; return newStyle; }
2576 IVStyle WithColors(const IVColorSpec& spec) const { IVStyle newStyle = *this; newStyle.colorSpec = spec; return newStyle; }
2577 IVStyle WithRoundness(float v) const { IVStyle newStyle = *this; newStyle.roundness = Clip(v, 0.f, 1.f); return newStyle; }
2578 IVStyle WithFrameThickness(float v) const { IVStyle newStyle = *this; newStyle.frameThickness = v; return newStyle; }
2579 IVStyle WithShadowOffset(float v) const { IVStyle newStyle = *this; newStyle.shadowOffset = v; return newStyle; }
2580 IVStyle WithDrawShadows(bool v = true) const { IVStyle newStyle = *this; newStyle.drawShadows = v; return newStyle; }
2581 IVStyle WithDrawFrame(bool v = true) const { IVStyle newStyle = *this; newStyle.drawFrame = v; return newStyle; }
2582 IVStyle WithWidgetFrac(float v) const { IVStyle newStyle = *this; newStyle.widgetFrac = Clip(v, 0.f, 1.f); return newStyle; }
2583 IVStyle WithAngle(float v) const { IVStyle newStyle = *this; newStyle.angle = Clip(v, 0.f, 360.f); return newStyle; }
2584 IVStyle WithEmboss(bool v = true) const { IVStyle newStyle = *this; newStyle.emboss = v; return newStyle; }
2585 IVStyle WithLabelOrientation(EOrientation v) const { IVStyle newStyle = *this; newStyle.labelOrientation = v; return newStyle; }
2586};
2587
2588const IVStyle DEFAULT_STYLE = IVStyle();
2589
2592{
2593 None, // Not exposed to assistive technology
2594 Group,
2595 Label,
2596 Button,
2597 Toggle,
2598 Slider,
2599 ComboBox,
2600 RadioGroup,
2601 RadioButton,
2602 TabList,
2603 Tab,
2604 Meter,
2605 Image,
2606 TextInput,
2607 Menu, // A pop-up menu or a sub-menu, the parent of MenuItem nodes
2608 MenuItem
2609};
2610
2613{
2614 Click,
2615 Increment,
2616 Decrement,
2617 SetValue,
2618 Focus // The focus is about to be moved to a node by assistive technology. A control that moves the focus itself can return true from IControl::OnAccessibleAction()
2619};
2620
2623{
2624 EAccessibleRole role = EAccessibleRole::None;
2625 WDL_String label; // The name of the node, e.g. "Gain"
2626 WDL_String valueText; // The value as it should be read out, e.g. "-6 dB"
2627 WDL_String description; // Optional extra information, e.g. a tooltip
2628 IRECT bounds; // In the same coordinate space as IControl::GetRECT()
2629 bool hasNumericValue = false;
2630 double value = 0.; // Only valid if hasNumericValue, in the same units as min/max/step
2631 double min = 0.;
2632 double max = 1.;
2633 double step = 0.01;
2634 int toggled = -1; // -1: not toggleable, 0: off, 1: on
2635 int expanded = -1; // -1: not expandable, 0: collapsed, 1: expanded. For e.g. a button that shows/hides a section
2636 bool selected = false; // For RadioButton/Tab
2637 bool disabled = false;
2638 bool focusable = false; // Can take keyboard focus
2639 int parent = 0; // For nodes after the first: the index in the list of the node that this is a child of, which must come before it
2640
2642 bool IsInteractive() const
2643 {
2644 switch (role)
2645 {
2646 case EAccessibleRole::Button:
2647 case EAccessibleRole::Toggle:
2648 case EAccessibleRole::Slider:
2649 case EAccessibleRole::ComboBox:
2650 case EAccessibleRole::RadioButton:
2651 case EAccessibleRole::Tab:
2652 case EAccessibleRole::TextInput:
2653 case EAccessibleRole::MenuItem:
2654 return true;
2655 default:
2656 return false;
2657 }
2658 }
2659
2660 bool operator==(const IAccessibleNode& rhs) const
2661 {
2662 return role == rhs.role && bounds == rhs.bounds && hasNumericValue == rhs.hasNumericValue
2663 && value == rhs.value && min == rhs.min && max == rhs.max && step == rhs.step
2664 && toggled == rhs.toggled && expanded == rhs.expanded && selected == rhs.selected && disabled == rhs.disabled && focusable == rhs.focusable && parent == rhs.parent
2665 && !strcmp(label.Get(), rhs.label.Get()) && !strcmp(valueText.Get(), rhs.valueText.Get())
2666 && !strcmp(description.Get(), rhs.description.Get());
2667 }
2668
2669 bool operator!=(const IAccessibleNode& rhs) const { return !(*this == rhs); }
2670};
2671
2673using IAccessibleNodeList = std::vector<IAccessibleNode>;
2674
2675END_IGRAPHICS_NAMESPACE
2676END_IPLUG_NAMESPACE
2677
IPlug logging a.k.a tracing functionality.
Utility functions and macros.
A base class interface for a bitmap abstraction around the different drawing back end bitmap represen...
float GetScale() const
float GetDrawScale() const
User-facing bitmap abstraction that you use to manage bitmap data, independant of draw class/platform...
int W() const
bool GetFramesAreHorizontal() const
const WDL_String & GetResourceName() const
int N() const
int FH() const
float GetDrawScale() const
float GetScale() const
int H() const
int FW() const
APIBitmap * GetAPIBitmap() const
IBitmap(APIBitmap *pAPIBitmap, int n, bool framesAreHorizontal, const char *name="")
IBitmap Constructor.
bool IsValid() const
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:87
A control that can be specialised with a lambda function, for quick experiments without making a cust...
Definition: IControl.h:2108
An abstraction that is used to store a temporary raster image/framebuffer.
const APIBitmap * GetAPIBitmap() const
ILayer(APIBitmap *pBitmap, const IRECT &layerRect, IControl *pControl, const IRECT &controlRect)
Create a layer/offscreen context (used internally)
const IRECT & Bounds() const
void Invalidate()
Mark the layer as needing its contents redrawn
IBitmap GetBitmap() const
A class for setting the contents of a pop up menu.
Used to manage a list of rectangular areas and optimize them for drawing to the screen.
void Clear()
Clear the list.
void Set(int idx, const IRECT &rect)
Set a specific rectangle in the list (will crash if idx is invalid)
IRECT Bounds()
Get a union of all rectangles in the list.
int Size() const
void Add(const IRECT &rect)
Add a rectangle to the list.
void PixelAlign(float scale)
Pixel-align the IRECTs at the given scale factor then scale them back down.
void PixelAlign()
Align the rectangles to pixel boundaries.
void Optimize()
Remove rects that are contained by other rects and intersections and merge any rects that can be merg...
int Find(float x, float y) const
Find the first index of the rect that contains point x, y, if it exists.
static bool GetFracGrid(const IRECT &input, IRECTList &rects, const std::initializer_list< float > &rowFractions, const std::initializer_list< float > &colFractions, EDirection layoutDir=EDirection::Horizontal)
Fill an IRECTList with divisons of an input IRECT.
const IRECT & Get(int idx) const
Get an IRECT from the list (will crash if idx is invalid)
void DefaultAnimationFunc(IControl *pCaller)
An animation function that just calls the caller control's OnEndAnimation() method at the end of the ...
Definition: IControl.cpp:21
std::vector< IAccessibleNode > IAccessibleNodeList
A list of IAccessibleNode.
void EmptyClickActionFunc(IControl *pCaller)
A click action function that does nothing.
Definition: IControl.cpp:43
static const char * TextStyleString(ETextStyle style)
Helper to get a CString based on ETextStyle.
void DefaultClickActionFunc(IControl *pCaller)
A click action function that triggers the default animation function for DEFAULT_ANIMATION_DURATION.
Definition: IControl.cpp:45
void SplashClickActionFunc(IControl *pCaller)
The splash click action function is used by IVControls to start SplashAnimationFunc.
Definition: IControl.cpp:47
EAccessibleAction
An action that can be performed on a control via assistive technology or keyboard navigation.
void SplashAnimationFunc(IControl *pCaller)
The splash animation function is used by IVControls to animate the splash.
Definition: IControl.cpp:30
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
EAccessibleRole
The semantic role of a control (or part of a control), reported to assistive technology such as scree...
float BlendWeight(const IBlend *pBlend)
Helper function to extract the blend weight value from an IBlend ptr if it is valid.
void ShowBubbleVerticalActionFunc(IControl *pCaller)
Use with a param-linked control to popup the bubble control vertically.
Definition: IControl.cpp:66
void ShowBubbleHorizontalActionFunc(IControl *pCaller)
Use with a param-linked control to popup the bubble control horizontally.
Definition: IControl.cpp:55
Used to describe a particular gesture.
Used to group mouse coordinates with mouse modifier information.
Used to manage stroke behaviour for path based drawing back ends.
BEGIN_IPLUG_NAMESPACE T Clip(T x, T lo, T hi)
Clips the value x between lo and hi.
Used to describe a control (or a part of a control) to assistive technology.
bool IsInteractive() const
Used to manage composite/blend operations, independent of draw class/platform.
IBlend(EBlend type=EBlend::Default, float weight=1.0f)
Creates a new IBlend.
Used to manage color data, independent of draw class/platform.
IColor(int a=255, int r=0, int g=0, int b=0)
Create an IColor from ARGB values.
void SetOpacity(float alpha)
Set the color's opacity/alpha component with a float.
static IColor FromColorCode(int colorCode, int A=0xFF)
Create an IColor from a color code.
static IColor FromRGBAf(float *rgbaf)
Create an IColor from a 4 float RGBA array.
void GetRGBAf(float *rgbaf) const
Get the color as a 4 float array.
void Set(int a=255, int r=0, int g=0, int b=0)
Set the color parts.
IColor WithContrast(float c) const
Returns a new contrasted IColor based on this one.
void Randomise(int alpha=255)
Randomise the color parts, with optional alpha.
static IColor FromHSLA(float h, float s, float l, float a=1.f)
Create an IColor from Hue Saturation and Luminance values.
void GetRGBf(float *rgbf) const
Get the color as a 3 float array.
int ToColorCode() const
Convert the IColor to a single int (no alpha)
IColor WithOpacity(float alpha) const
Returns a new IColor with a different opacity.
int GetLuminosity() const
Gets the lightness of the color (HSL lightness component)
static IColor FromColorCodeStr(const char *hexStr)
Create an IColor from a color code in a CString.
static IColor FromRGBf(float *rgbf)
Create an IColor from a 3 float RGB array.
bool Empty() const
static IColor LinearInterpolateBetween(const IColor &start, const IColor &dest, float progress)
Helper function to linear interpolate between two IColors.
void GetHSLA(float &h, float &s, float &l, float &a) const
Get the Hue, Saturation and Luminance of the color.
void Contrast(float c)
Contrast the color.
void ToColorCodeStr(WDL_String &str, bool withAlpha=true) const
Convert the IColor to a hex string e.g.
static IColor GetRandomColor(bool randomAlpha=false)
Get a random IColor.
void Clamp()
Keep the member int variables within the range 0-255.
Used to represent a point/stop in a gradient.
IColorStop(IColor color, float offset)
Create an IColor stop.
Used to manage fill behaviour.
Used for key press info, such as ASCII representation, virtual key (mapped to win32 codes) and modifi...
Definition: IPlugStructs.h:615
Used to store transformation matrices.
IMatrix(double xx, double yx, double xy, double yy, double tx, double ty)
Create an IMatrix, specifying the values.
IMatrix & Rotate(float a)
Set the matrix for a rotation transform.
IMatrix & Scale(float x, float y)
Set the matrix for a scale transform.
IMatrix()
Create an identity matrix.
IMatrix & Transform(const IMatrix &m)
Transform this matrix with another.
IMatrix & Invert()
Changes the matrix to be the inverse of its original value.
void TransformPoint(double &x, double &y) const
Transforms the point x, y with the matrix.
IMatrix & Transform(const IRECT &before, const IRECT &after)
Sets up a transformation matrix to map one rectangle to another.
IMatrix & Translate(float x, float y)
Set the matrix for a translation transform.
IMatrix & Skew(float xa, float ya)
Set the matrix for a skew transform.
void TransformPoint(double &x, double &y, double x0, double y0) const
Transforms a point using this matrix.
Used to manage mouse modifiers i.e.
bool IsTouch() const
true if this IMouseMod is linked to a touch event
IMouseMod(bool l=false, bool r=false, bool s=false, bool c=false, bool a=false, ITouchID touchID=0)
Create an IMouseMod.
void DBGPrint()
Print the mouse modifier values to the console in Debug builds.
Used to store pattern information for gradients.
const IColorStop & GetStop(int idx) const
Get the IColorStop at a particular index (will crash if out of bounds)
int NStops() const
IPattern(const IColor &color)
Create an IPattern with a solid color fill.
void AddStop(IColor color, float offset)
Add an IColorStop to the IPattern.
static IPattern CreateLinearGradient(float x1, float y1, float x2, float y2, const std::initializer_list< IColorStop > &stops={})
Create a linear gradient IPattern.
static IPattern CreateSweepGradient(float x1, float y1, const std::initializer_list< IColorStop > &stops={}, float angleStart=0.f, float angleEnd=360.f)
Create a sweep gradient IPattern (SKIA only)
static IPattern CreateLinearGradient(const IRECT &bounds, EDirection direction, const std::initializer_list< IColorStop > &stops={})
Create a linear gradient IPattern across a rectangular area.
static IPattern CreateRadialGradient(float x1, float y1, float r, const std::initializer_list< IColorStop > &stops={})
Create a radial gradient IPattern.
void SetTransform(float xx, float yx, float xy, float yy, float tx, float ty)
Set the affine transform for the IPattern with values.
IPattern(EPatternType type)
Create an IPattern.
void SetTransform(const IMatrix &transform)
Set the affine transform for the IPattern with an IMatrix.
Used to manage a rectangular area, independent of draw class/platform.
IRECT ReduceFromRight(float amount)
Reduce in width from the right edge by 'amount' and return the removed region.
IRECT GetCentredInside(const IBitmap &bitmap) const
Get a rectangle with the same center point as this rectangle and the size of the bitmap.
IRECT GetReducedFromTop(float amount) const
Get a subrect of this IRECT reduced in height from the top edge by 'amount'.
IRECT GetFromTRHC(float w, float h) const
Get a subrect of this IRECT expanding from the top-right corner.
void VPad(float padding)
Pad this IRECT in the Y-axis N.B.
void MidHPad(float padding)
Set the width of this IRECT to 2*padding without changing it's center point on the X-axis.
IRECT GetReducedFromLeft(float amount) const
Get a subrect of this IRECT reduced in width from the left edge by 'amount'.
void Clear()
Set all fields of this IRECT to 0.
IRECT GetReducedFromRight(float amount) const
Get a subrect of this IRECT reduced in width from the right edge by 'amount'.
IRECT ReduceFromLeft(float amount)
Reduce in width from the left edge by 'amount' and return the removed region.
IRECT GetCentredInside(float w, float h=0.f) const
Get a rectangle with the same center point as this rectangle and the given size.
IRECT(float l, float t, float r, float b)
Construct a new IRECT with dimensions.
bool Contains(float x, float y) const
Returns true if this IRECT completely contains the point (x,y).
IRECT Intersect(const IRECT &rhs) const
Create a new IRECT that is the intersection of this IRECT and rhs.
void Pad(float padding)
Pad this IRECT N.B.
IRECT GetFromTLHC(float w, float h) const
Get a subrect of this IRECT expanding from the top-left corner.
IRECT GetFromRight(float amount) const
Get a subrect of this IRECT bounded in X by 'amount' and the right edge.
IRECT GetFromBottom(float amount) const
Get a subrect of this IRECT bounded in Y by 'amount' and the bottom edge.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
bool IsPixelAligned() const
IRECT GetPixelAligned() const
Get a copy of this IRECT with PixelAlign() called.
IRECT Inset(const IRECT &rhs) const
Offsets the input IRECT based on the parent.
static IRECT MakeXYWH(float l, float t, float w, float h)
Create a new IRECT with the given position and size.
void PixelAlign()
Pixel aligns the rect in an inclusive manner (moves all points outwards)
bool Mergeable(const IRECT &rhs) const
Return if this IRECT and rhs may be merged.
float GetLengthOfShortestSide() const
void Pad(float padL, float padT, float padR, float padB)
Pad this IRECT N.B.
IRECT()
Construct an empty IRECT
void GetRandomPoint(float &x, float &y) const
Get a random point within this rectangle.
IRECT ReduceFromTop(float amount)
Reduce in height from the top edge by 'amount' and return the removed region.
IRECT GetTranslated(float x, float y) const
Get a translated copy of this rectangle.
float MH() const
IRECT GetScaledAboutCentre(float scale) const
Get a copy of this IRECT where the width and height are multiplied by scale without changing the cent...
void PixelSnap()
Pixel aligns to nearest pixels This may make the IRECT smaller, unlike PixelAlign().
void VAlignTo(const IRECT &sr, EVAlign align)
Vertically align this rect to the reference IRECT.
bool ContainsEdge(float x, float y) const
Returns true if the point (x,y) is either contained in this IRECT or on an edge.
IRECT GetVSliced(float h, bool bot=false) const
Get a copy of this IRECT with a new height.
IRECT GetFromBLHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-left corner.
IRECT GetReducedFromBottom(float amount) const
Get a subrect of this IRECT reduced in height from the bottom edge by 'amount'.
IRECT FracRectVertical(float frac, bool fromTop=false) const
Returns a new IRECT with a height that is multiplied by frac.
void Offset(float l, float t, float r, float b)
Offset each field of the rectangle.
void MidVPad(float padding)
Set the height of this IRECT to 2*padding without changing it's center point on the Y-axis.
IRECT SubRect(EDirection layoutDir, int numSlices, int sliceIdx) const
Get a new rectangle which is a "slice" of this rectangle.
IRECT GetPixelSnapped() const
bool Empty() const
static IRECT MakeMidXYWH(float x, float y, float w, float h)
Create a new IRECT of size (y,h) centred at the given position (x,y)
void HAlignTo(const IRECT &sr, EAlign align)
Horizontally align this rect to the reference IRECT.
IRECT SubRectHorizontal(int numSlices, int sliceIdx) const
Returns a new IRECT which is a vertical "slice" of this IRECT.
IRECT GetScaled(float scale) const
Get a copy of this IRECT with all values multiplied by scale.
IRECT GetGridCell(int row, int col, int nRows, int nColumns) const
Get a subrect (by row, column) of this IRECT which is a cell in a grid of size (nRows * nColumns)
IRECT GetVPadded(float padding) const
Get a copy of this IRECT padded in the Y-axis N.B.
IRECT FracRect(EDirection layoutDir, float frac, bool fromTopOrRight=false) const
Get a new rectangle which is a fraction of this rectangle.
float W() const
IRECT ReduceFromBottom(float amount)
Reduce in height from the bottom edge by 'amount' and return the removed region.
static IRECT LinearInterpolateBetween(const IRECT &start, const IRECT &dest, float progress)
Get a rectangle that is a linear interpolation between start and dest
void Clank(const IRECT &rhs)
Clank will limit this IRECT's bounds based on the boundaries of the IRECT passed in as an argument.
void Scale(float scale)
Multiply each field of this IRECT by scale.
IRECT FracRectHorizontal(float frac, bool rhs=false) const
Returns a new IRECT with a width that is multiplied by frac.
void PixelAlign(float scale)
Pixel-align this IRECT at the given scale factor then scale it back down When scaling this mutliples ...
void HPad(float padding)
Pad this IRECT in the X-axis N.B.
IRECT Union(const IRECT &rhs) const
Create a new IRECT that is a union of this IRECT and rhs.
IRECT GetVShifted(float y) const
Get a copy of this rectangle translated on the Y axis.
float Area() const
void Constrain(float &x, float &y) const
Ensure the point (x,y) is inside this IRECT.
IRECT GetPixelAligned(float scale) const
Get a copy of this IRECT with PixelAlign(scale) called.
bool Intersects(const IRECT &rhs) const
Returns true if this IRECT shares any common pixels with rhs, false otherwise.
IRECT GetRandomSubRect() const
IRECT SubRectVertical(int numSlices, int sliceIdx) const
Returns a new IRECT which is a horizontal "slice" of this IRECT.
IRECT GetFromLeft(float amount) const
Get a subrect of this IRECT bounded in X by the left edge and 'amount'.
bool IsPixelAligned(float scale) const
Return true if, when scaled by scale, this IRECT is pixel aligned When scaling this mutliples each va...
IRECT GetFromTop(float amount) const
Get a subrect of this IRECT bounded in Y by the top edge and 'amount'.
float H() const
void Translate(float x, float y)
Translate this rectangle.
IRECT GetFromBRHC(float w, float h) const
Get a subrect of this IRECT expanding from the bottom-right corner.
IRECT(float x, float y, const IBitmap &bitmap)
Construct a new IRECT at the given position and with the same size as the bitmap.
IRECT GetHShifted(float x) const
Get a copy of this rectangle translated on the X axis.
IRECT GetMidHPadded(float padding) const
Get a copy of this IRECT where its width = 2 * padding but the center point on the X-axis has not cha...
IRECT GetHAlignedTo(const IRECT &sr, EAlign align) const
Get a rectangle the same dimensions as this one, horizontally aligned to the reference IRECT.
void ScaleAboutCentre(float scale)
Scale the width and height of this IRECT by scale without changing the center point.
float MW() const
bool Contains(const IRECT &rhs) const
Returns true if this IRECT completely contains rhs.
void PixelSnap(float scale)
Pixel align a scaled version of this IRECT.
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
IRECT GetHPadded(float padding) const
Get a copy of this IRECT padded in the X-axis N.B.
IRECT GetPixelSnapped(float scale) const
Get a copy of this IRECT with PixelSnap(scale) called.
void DBGPrint()
Print the IRECT's details to the console in Debug builds.
IRECT GetOffset(float l, float t, float r, float b) const
Get a copy of this rectangle where each field is offset by a specified amount.
IRECT GetVAlignedTo(const IRECT &sr, EVAlign align) const
Get a rectangle the same dimensions as this one, vertically aligned to the reference IRECT.
IRECT GetMidVPadded(float padding) const
Get a copy of this IRECT where its height = 2 * padding but the center point on the Y-axis has not ch...
IRECT GetPadded(float padL, float padT, float padR, float padB) const
Get a copy of this IRECT with the values padded N.B.
IRECT GetHSliced(float w, bool rhs=false) const
Get a copy of this IRECT with a new width.
IRECT GetGridCell(int cellIndex, int nRows, int nColumns, EDirection dir=EDirection::Horizontal, int nCells=1) const
Get a subrect (by index) of this IRECT which is a cell (or union of nCells sequential cells on same r...
User-facing SVG abstraction that you use to manage SVG data ISVG doesn't actually own the image data.
bool IsValid() const
float H() const
float W() const
Used to specify properties of a drop-shadow to a layer.
IShadow(const IPattern &pattern, float blurSize, float xOffset, float yOffset, float opacity, bool drawForeground=true)
Create an IShadow.
IText is used to manage font and text/text entry style for a piece of text on the UI,...
IText(float size=DEFAULT_TEXT_SIZE, const IColor &color=DEFAULT_TEXT_FGCOLOR, const char *fontID=nullptr, EAlign align=EAlign::Center, EVAlign valign=EVAlign::Middle, float angle=0, const IColor &TEBGColor=DEFAULT_TEXTENTRY_BGCOLOR, const IColor &TEFGColor=DEFAULT_TEXTENTRY_FGCOLOR)
Create a new IText with size, color, fontID ...
IText(float size, const char *fontID)
Create a new IText with size and fontID.
IText(float size, EVAlign valign, const IColor &color=DEFAULT_TEXT_FGCOLOR)
Create a new IText with size, vertical align, color.
IText(float size, EAlign align, const IColor &color=DEFAULT_TEXT_FGCOLOR)
Create a new IText with size, horizontal align, color.
Contains a set of 9 colors used to theme IVControls.
IVColorSpec(const std::initializer_list< IColor > &colors)
Create a new IVColorSpec object specifying the colors.
static const IColor & GetDefaultColor(EVColor idx)
void ResetColors()
Reset the colors to the defaults.
const IColor & GetColor(EVColor color) const
IVColorSpec()
Create a new IVColorSpec object with default colors.
A struct encapsulating a set of properties used to configure IVControls.
IVStyle(const std::initializer_list< IColor > &colors)
Create a new IVStyle based on a list of colors, and defaults for the other elements.
IVStyle(bool showLabel=DEFAULT_SHOW_LABEL, bool showValue=DEFAULT_SHOW_VALUE, const IVColorSpec &colors={DEFAULT_BGCOLOR, DEFAULT_FGCOLOR, DEFAULT_PRCOLOR, DEFAULT_FRCOLOR, DEFAULT_HLCOLOR, DEFAULT_SHCOLOR, DEFAULT_X1COLOR, DEFAULT_X2COLOR, DEFAULT_X3COLOR}, const IText &labelText=DEFAULT_LABEL_TEXT, const IText &valueText=DEFAULT_VALUE_TEXT, bool hideCursor=DEFAULT_HIDE_CURSOR, bool drawFrame=DEFAULT_DRAW_FRAME, bool drawShadows=DEFAULT_DRAW_SHADOWS, bool emboss=DEFAULT_EMBOSS, float roundness=DEFAULT_ROUNDNESS, float frameThickness=DEFAULT_FRAME_THICKNESS, float shadowOffset=DEFAULT_SHADOW_OFFSET, float widgetFrac=DEFAULT_WIDGET_FRAC, float angle=DEFAULT_WIDGET_ANGLE, EOrientation labelOrientation=DEFAULT_LABEL_ORIENTATION)
Create a new IVStyle to configure common styling for IVControls.
Encapsulate an xy point in one struct.