Skip to content

Commit

Permalink
use enum class for VuMeter style
Browse files Browse the repository at this point in the history
  • Loading branch information
scheffle committed Mar 15, 2024
1 parent e5c075d commit dd3cf04
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 30 deletions.
12 changes: 5 additions & 7 deletions vstgui/lib/controls/cvumeter.cpp
Expand Up @@ -22,11 +22,9 @@ namespace VSTGUI {
* @param style kHorizontal or kVertical
*/
//------------------------------------------------------------------------
CVuMeter::CVuMeter (const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed, int32_t style)
: CControl (size, nullptr, 0)
, offBitmap (nullptr)
, nbLed (nbLed)
, style (style)
CVuMeter::CVuMeter (const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed,
Style style)
: CControl (size, nullptr, 0), offBitmap (nullptr), nbLed (nbLed), style (style)
{
setDecreaseStepValue (0.1f);

Expand Down Expand Up @@ -126,8 +124,8 @@ void CVuMeter::draw (CDrawContext *_pContext)
setOldValue (newValue);

newValue = (newValue - getMin ()) / getRange (); // normalize
if (style & kHorizontal)

if (style == Style::kHorizontal)
{
auto tmp = (CCoord)(((int32_t)(nbLed * newValue + 0.5f) / (float)nbLed) * getOnBitmap ()->getWidth ());
pointOff (tmp, 0);
Expand Down
41 changes: 20 additions & 21 deletions vstgui/lib/controls/cvumeter.h
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "../enumbitset.h"
#include "ccontrol.h"

namespace VSTGUI {
Expand All @@ -15,20 +16,15 @@ namespace VSTGUI {
//-----------------------------------------------------------------------------
class CVuMeter : public CControl
{
private:
enum StyleEnum
{
StyleHorizontal = 0,
StyleVertical,
};
public:
enum Style
enum class Style : int32_t
{
kHorizontal = 1 << StyleHorizontal,
kVertical = 1 << StyleVertical,
kHorizontal,
kVertical,
};

CVuMeter (const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed, int32_t style = kVertical);
CVuMeter (const CRect& size, CBitmap* onBitmap, CBitmap* offBitmap, int32_t nbLed,
Style style = Style::kVertical);
CVuMeter (const CVuMeter& vuMeter);

//-----------------------------------------------------------------------------
Expand All @@ -45,11 +41,14 @@ class CVuMeter : public CControl

int32_t getNbLed () const { return nbLed; }
void setNbLed (int32_t nb) { nbLed = nb; invalid (); }

void setStyle (int32_t newStyle) { style = newStyle; invalid (); }
int32_t getStyle () const { return style; }
//@}

void setStyle (Style newStyle)
{
style = newStyle;
invalid ();
}
Style getStyle () const { return style; }
//@}

// overrides
void setDirty (bool state) override;
Expand All @@ -60,16 +59,16 @@ class CVuMeter : public CControl

CLASS_METHODS(CVuMeter, CControl)
protected:
~CVuMeter () noexcept override;
~CVuMeter () noexcept override;

CBitmap* offBitmap;

int32_t nbLed;
int32_t style;
float decreaseValue;

CRect rectOn;
CRect rectOff;
int32_t nbLed;
Style style;
float decreaseValue;

CRect rectOn;
CRect rectOff;
};

} // VSTGUI
5 changes: 3 additions & 2 deletions vstgui/uidescription/viewcreator/vumetercreator.cpp
Expand Up @@ -59,7 +59,8 @@ bool VuMeterCreator::apply (CView* view, const UIAttributes& attributes,

const auto* attr = attributes.getAttributeValue (kAttrOrientation);
if (attr)
vuMeter->setStyle (*attr == strVertical ? CVuMeter::kVertical : CVuMeter::kHorizontal);
vuMeter->setStyle (*attr == strVertical ? CVuMeter::Style::kVertical
: CVuMeter::Style::kHorizontal);

int32_t numLed;
if (attributes.getIntegerAttribute (kAttrNumLed, numLed))
Expand Down Expand Up @@ -113,7 +114,7 @@ bool VuMeterCreator::getAttributeValue (CView* view, const string& attributeName
}
else if (attributeName == kAttrOrientation)
{
if (vuMeter->getStyle () & CVuMeter::kVertical)
if (vuMeter->getStyle () == CVuMeter::Style::kVertical)
stringValue = strVertical;
else
stringValue = strHorizontal;
Expand Down

0 comments on commit dd3cf04

Please sign in to comment.