Skip to content

Commit 58de3e5

Browse files
committed
Quantum tweaks in preparation for another plugin
Signed-off-by: falkTX <falktx@falktx.com>
1 parent 4f3fc42 commit 58de3e5

2 files changed

Lines changed: 53 additions & 10 deletions

File tree

‎opengl/Quantum.cpp‎

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ template<bool small>
353353
void AbstractQuantumSwitch<small>::onNanoDisplay()
354354
{
355355
const bool checked = isChecked();
356+
const bool enabled = isEnabled();
356357
const uint blockSize = small ? theme.textHeight / 2 : theme.fontSize;
357358
const int yOffset = (getHeight() - blockSize - theme.borderSize * 2) / 2;
358359

@@ -362,21 +363,22 @@ void AbstractQuantumSwitch<small>::onNanoDisplay()
362363
fill();
363364

364365
beginPath();
366+
365367
if (checked)
366-
{
367368
rect(theme.borderSize + blockSize , yOffset + theme.borderSize, blockSize, blockSize);
368-
fillColor(theme.widgetActiveColor);
369-
}
370369
else
371-
{
372370
rect(theme.borderSize, yOffset + theme.borderSize, blockSize, blockSize);
371+
372+
if (checked && enabled)
373+
fillColor(theme.widgetActiveColor);
374+
else
373375
fillColor(theme.textDarkColor);
374-
}
376+
375377
fill();
376378

377379
if (label != nullptr && label[0] != '\0')
378380
{
379-
fillColor(checked ? theme.textLightColor : theme.textMidColor);
381+
fillColor(checked && enabled ? theme.textLightColor : theme.textMidColor);
380382
fontSize(theme.fontSize);
381383
textAlign(ALIGN_LEFT|ALIGN_MIDDLE);
382384
text(blockSize * 2 + theme.borderSize * 2 + theme.padding * 2, getHeight() / 2, label, nullptr);
@@ -1256,15 +1258,41 @@ void QuantumValueMeter::setUnitLabel(const char* const label)
12561258
repaint();
12571259
}
12581260

1259-
void QuantumValueMeter::setValue(const float value2)
1261+
void QuantumValueMeter::setValue(float value2)
12601262
{
1263+
if (value2 > maximum)
1264+
value2 = maximum;
1265+
else if (value2 < minimum)
1266+
value2 = minimum;
1267+
12611268
if (d_isEqual(value, value2))
12621269
return;
12631270

12641271
value = value2;
12651272
repaint();
12661273
}
12671274

1275+
void QuantumValueMeter::setValueCentered(const bool centered)
1276+
{
1277+
if (valueCentered == centered)
1278+
return;
1279+
1280+
valueCentered = centered;
1281+
repaint();
1282+
}
1283+
1284+
void QuantumValueMeter::setValueFormat(const char* const format)
1285+
{
1286+
std::free(valueFormat);
1287+
1288+
if (format != nullptr && format[0] != '\0')
1289+
valueFormat = strdup(format);
1290+
else
1291+
valueFormat = nullptr;
1292+
1293+
repaint();
1294+
}
1295+
12681296
void QuantumValueMeter::setTextColor(const Color color)
12691297
{
12701298
textColor = color;
@@ -1353,16 +1381,27 @@ void QuantumValueMeter::onNanoDisplay()
13531381
char valuestr[32] = {};
13541382
const float roundedValue = std::round(value * 10.0f)/10.0f;
13551383

1356-
if (unitLabel != nullptr)
1384+
if (valueFormat != nullptr)
1385+
std::snprintf(valuestr, sizeof(valuestr)-1, valueFormat, roundedValue);
1386+
else if (unitLabel != nullptr)
13571387
std::snprintf(valuestr, sizeof(valuestr)-1, "%.1f %s", roundedValue, unitLabel);
13581388
else
13591389
std::snprintf(valuestr, sizeof(valuestr)-1, "%.1f", roundedValue);
13601390

13611391
beginPath();
13621392
fontSize(theme.fontSize);
13631393
fillColor(textColor);
1364-
textAlign(ALIGN_CENTER|ALIGN_MIDDLE);
1365-
text(getWidth()/2, getHeight()/2, valuestr, nullptr);
1394+
1395+
if (valueCentered)
1396+
{
1397+
textAlign(ALIGN_CENTER|ALIGN_MIDDLE);
1398+
text(getWidth() * 0.5f, getHeight() * 0.5f, valuestr, nullptr);
1399+
}
1400+
else
1401+
{
1402+
textAlign(ALIGN_RIGHT|ALIGN_MIDDLE);
1403+
text(getWidth() * 0.8f, getHeight() * 0.5f, valuestr, nullptr);
1404+
}
13661405
}
13671406

13681407
// --------------------------------------------------------------------------------------------------------------------

‎opengl/Quantum.hpp‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ class QuantumValueMeter : public NanoSubWidget
515515
void setValue(float value);
516516
void setTextColor(Color color);
517517
void setUnitLabel(const char* label);
518+
void setValueCentered(bool centered);
519+
void setValueFormat(const char* format);
518520

519521
protected:
520522
void onNanoDisplay() override;
@@ -527,6 +529,8 @@ class QuantumValueMeter : public NanoSubWidget
527529
Color textColor = theme.textLightColor;
528530
char* unitLabel = nullptr;
529531
float value = 0.f;
532+
bool valueCentered = false;
533+
char* valueFormat = nullptr;
530534

531535
DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(QuantumValueMeter)
532536
};

0 commit comments

Comments
 (0)