From b07699efdd3e4a951b845d6f428f3967f28ba914 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 27 Apr 2021 14:15:36 +0200 Subject: [PATCH 1/2] Style update for the volume meter --- plugins/editor/layout/main.fl | 6 ++--- plugins/editor/src/editor/Editor.cpp | 2 +- plugins/editor/src/editor/GUIComponents.cpp | 28 ++++++++++++++++++--- plugins/editor/src/editor/GUIComponents.h | 4 +++ plugins/editor/src/editor/layout/main.hpp | 4 +-- 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/plugins/editor/layout/main.fl b/plugins/editor/layout/main.fl index 2f94bbef..9baf34ec 100644 --- a/plugins/editor/layout/main.fl +++ b/plugins/editor/layout/main.fl @@ -20,7 +20,7 @@ widget_class mainView {open class RoundedGroup } { Fl_Box {} { - comment {tag=kTagAbout} selected + comment {tag=kTagAbout} image {../resources/logo_text_shaded.png} xywh {32 9 120 60} class AboutButton } @@ -147,11 +147,11 @@ widget_class mainView {open class KnobCCBox } Fl_Box leftMeter_ { - xywh {740 10 15 90} box BORDER_BOX + xywh {740 15 15 85} box BORDER_BOX class VMeter } Fl_Box rightMeter_ {selected - xywh {760 10 15 90} box BORDER_BOX + xywh {760 15 15 85} box BORDER_BOX class VMeter } } diff --git a/plugins/editor/src/editor/Editor.cpp b/plugins/editor/src/editor/Editor.cpp index f98d5854..6c3d72e3 100644 --- a/plugins/editor/src/editor/Editor.cpp +++ b/plugins/editor/src/editor/Editor.cpp @@ -722,10 +722,10 @@ void Editor::Impl::createFrameContents() }; auto createVMeter = [this, &palette](const CRect& bounds, int, const char*, CHoriTxtAlign, int) { SLevelMeter* meter = new SLevelMeter(bounds); + meter->setFrameColor(CColor(0x00, 0x00, 0x00, 0x00)); meter->setNormalFillColor(CColor(0x00, 0xaa, 0x11)); meter->setDangerFillColor(CColor(0xaa, 0x00, 0x00)); OnThemeChanged.push_back([meter, palette]() { - meter->setFrameColor(palette->inactiveText); meter->setBackColor(palette->knobInactiveTrack); }); return meter; diff --git a/plugins/editor/src/editor/GUIComponents.cpp b/plugins/editor/src/editor/GUIComponents.cpp index 76d7f9a0..5af20031 100644 --- a/plugins/editor/src/editor/GUIComponents.cpp +++ b/plugins/editor/src/editor/GUIComponents.cpp @@ -1036,16 +1036,38 @@ void SLevelMeter::draw(CDrawContext* dc) dc->setDrawMode(kAliasing); + CCoord radius = radius_; + bool isRounded = radius > 0.0; + + SharedPointer largeRoundRect; + SharedPointer fillRoundRect; + + if (isRounded) { + largeRoundRect = owned(dc->createRoundRectGraphicsPath(largeBounds, radius)); + fillRoundRect = owned(dc->createRoundRectGraphicsPath(fillBounds, radius)); + } + if (backColor_.alpha > 0) { dc->setFillColor(backColor_); - dc->drawRect(largeBounds, kDrawFilled); + if (!isRounded) + dc->drawRect(largeBounds, kDrawFilled); + else + dc->drawGraphicsPath(largeRoundRect, CDrawContext::kPathFilled); } dc->setFrameColor(frameColor_); dc->setFillColor(fillColor); - dc->drawRect(fillBounds, kDrawFilled); - dc->drawRect(largeBounds); + if (!isRounded) { + if (fill > 0) + dc->drawRect(fillBounds, kDrawFilled); + dc->drawRect(largeBounds); + } + else { + if (fill > 0 && fillBounds.getHeight() >= radius) + dc->drawGraphicsPath(fillRoundRect, CDrawContext::kPathFilled); + dc->drawGraphicsPath(largeRoundRect, CDrawContext::kPathStroked); + } } /// diff --git a/plugins/editor/src/editor/GUIComponents.h b/plugins/editor/src/editor/GUIComponents.h index 99378f2a..dfbd0be4 100644 --- a/plugins/editor/src/editor/GUIComponents.h +++ b/plugins/editor/src/editor/GUIComponents.h @@ -386,6 +386,9 @@ public: CColor getDangerFillColor() const { return dangerFillColor_; } void setDangerFillColor(CColor color) { dangerFillColor_ = color; invalid(); } + CCoord getRoundRectRadius() const { return radius_; } + void setRoundRectRadius(CCoord radius) { radius_ = radius; invalid(); } + protected: void draw(CDrawContext* dc) override; @@ -398,6 +401,7 @@ private: CColor safeFillColor_; CColor dangerFillColor_; CColor backColor_; + CCoord radius_ = 5.0; }; /// diff --git a/plugins/editor/src/editor/layout/main.hpp b/plugins/editor/src/editor/layout/main.hpp index 4c0f9910..936db5da 100644 --- a/plugins/editor/src/editor/layout/main.hpp +++ b/plugins/editor/src/editor/layout/main.hpp @@ -78,10 +78,10 @@ view__25->addView(view__28); auto* const view__29 = createKnobCCBox(CRect(85, 5, 155, 95), kTagSetCCPan, "Pan", kCenterText, 12); panCCKnob_ = view__29; view__25->addView(view__29); -auto* const view__30 = createVMeter(CRect(170, 5, 185, 95), -1, "", kCenterText, 14); +auto* const view__30 = createVMeter(CRect(170, 10, 185, 95), -1, "", kCenterText, 14); leftMeter_ = view__30; view__25->addView(view__30); -auto* const view__31 = createVMeter(CRect(190, 5, 205, 95), -1, "", kCenterText, 14); +auto* const view__31 = createVMeter(CRect(190, 10, 205, 95), -1, "", kCenterText, 14); rightMeter_ = view__31; view__25->addView(view__31); enterPalette(defaultPalette); From 8b38a7633b977ba434e850f1faf7e328c03c3a89 Mon Sep 17 00:00:00 2001 From: Jean Pierre Cimalando Date: Tue, 27 Apr 2021 14:23:14 +0200 Subject: [PATCH 2/2] Anti-aliasing for the rounded volume meter --- plugins/editor/src/editor/GUIComponents.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/editor/src/editor/GUIComponents.cpp b/plugins/editor/src/editor/GUIComponents.cpp index 5af20031..88e48609 100644 --- a/plugins/editor/src/editor/GUIComponents.cpp +++ b/plugins/editor/src/editor/GUIComponents.cpp @@ -1034,11 +1034,11 @@ void SLevelMeter::draw(CDrawContext* dc) fillColor.alpha = static_cast(A * 255.0); } - dc->setDrawMode(kAliasing); - CCoord radius = radius_; bool isRounded = radius > 0.0; + dc->setDrawMode(isRounded ? kAntiAliasing : kAliasing); + SharedPointer largeRoundRect; SharedPointer fillRoundRect;