Skip to content

Commit

Permalink
Fix scope bg color slider
Browse files Browse the repository at this point in the history
Fix multiScope bg slider not working in v2. Issue #67.
  • Loading branch information
chichian committed Feb 6, 2023
1 parent 86ae42c commit 0880eb3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 13 deletions.
47 changes: 43 additions & 4 deletions src/Widget_multiScope.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ multiScopeWidget::multiScopeWidget(multiScope *scopeModule) : TSSModuleWidgetBas
screenBg->box.size = Vec(screenContainer->box.size.x - RACK_GRID_WIDTH, screenContainer->box.size.y - 2 * RACK_GRID_WIDTH);
screenBg->emitLight = true; // Added to act like screen
screenContainer->addChild(screenBg);
trowaSoft::TSColorToHSL(screenBg->backgroundColor, &_lastBgColor); // Save our last guy
addChild(screenContainer);
}

Expand Down Expand Up @@ -400,8 +401,6 @@ void multiScopeWidget::step() {
return;
multiScope* scopeModule = dynamic_cast<multiScope*>(module);

static NVGcolor* lastEditColorPtr;

if (scopeModule->initialized)
{
if (!sizeLoaded)
Expand All @@ -416,6 +415,8 @@ void multiScopeWidget::step() {
}
scopeModule->lights[multiScope::INFO_DISPLAY_TOGGLE_LED].value = (scopeInfoDisplay->visible) ? 1.0 : 0.0;

TS_Panel* screenBg = screenContainer->getFirstDescendantOfType<TS_Panel>();

#if ENABLE_BG_COLOR_PICKER
// Color Picker (On-Screen)
for (int i = 0; i < 3; i++)
Expand All @@ -426,6 +427,10 @@ void multiScopeWidget::step() {
{
if (lastEditColorPtr == NULL || lastEditColorPtr != scopeModule->editColorPointer)
{
#if DEBUG_COLOR_SLIDER
debugCount = 0;
DEBUG("* Setting up colors on sliders.");
#endif
if (scopeModule->editColorPointer != NULL)
{
TSColorHSL selectedColor;
Expand All @@ -443,6 +448,12 @@ void multiScopeWidget::step() {
} // end if
else
{
#if DEBUG_COLOR_SLIDER
if (debugCount % 100 == 0)
{
DEBUG("* Read in color *");
}
#endif
// Read in color
TSColorHSL selectedColor;
for (int i = 0; i < 3; i++)
Expand All @@ -454,14 +465,42 @@ void multiScopeWidget::step() {
}
}
// Set our color
NVGcolor color = HueToColor(selectedColor.h, selectedColor.s, selectedColor.lum);
if (scopeModule->editColorPointer != NULL)
{
*(scopeModule->editColorPointer) = HueToColor(selectedColor.h, selectedColor.s, selectedColor.lum);//nvgHSL(selectedColor.h, selectedColor.s, selectedColor.lum);
*(scopeModule->editColorPointer) = color;//nvgHSL(selectedColor.h, selectedColor.s, selectedColor.lum);
}
if (screenBg && (_lastBgColor.h != selectedColor.h || _lastBgColor.s != selectedColor.s || _lastBgColor.lum != selectedColor.lum))
{
#if DEBUG_COLOR_SLIDER
if (debugCount % 100 == 0)
{
DEBUG("Color has changed!===============================");
for (int i = 0; i < 3; i++)
{
DEBUG("slider[%d] (Id %d) = %f --- OLD Val = %f", i, colorSliders[i]->debugId, colorSliders[i]->getValue(), _lastBgColor.hsl[i]);
}
}
#endif
if (scopeModule->negativeImage)
{
screenBg->backgroundColor = ColorInvertToNegative(color);
}
else
{
screenBg->backgroundColor = color;
}
_lastBgColor.h = selectedColor.h;
_lastBgColor.s = selectedColor.s;
_lastBgColor.lum = selectedColor.lum;
}
} // end else
lastEditColorPtr = scopeModule->editColorPointer;

} // end if we're showing the color picker
#if DEBUG_COLOR_SLIDER
debugCount = (debugCount + 1) % 100;
#endif
#endif

// Resizing ///////////////////////////////
Expand All @@ -470,7 +509,7 @@ void multiScopeWidget::step() {
screenContainer->box.size.x = box.size.x - inputAreaWidth;
if (sizeChange)
{
TS_Panel* screenBg = screenContainer->getFirstDescendantOfType<TS_Panel>();

if (screenBg)
{
screenBg->box.size.x = screenContainer->box.size.x - RACK_GRID_WIDTH;
Expand Down
6 changes: 5 additions & 1 deletion src/Widget_multiScope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ struct multiScopeWidget : TSSModuleWidgetBase {
ColorValueLight* fillColorLEDs[TROWA_SCOPE_NUM_WAVEFORMS];
bool sizeLoaded = false;
int lastWidth;

NVGcolor* lastEditColorPtr;
TSColorHSL _lastBgColor;
#if DEBUG_COLOR_SLIDER
int debugCount = 0;
#endif
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// multiScopeWidget()
// Instantiate a multiScope widget. v0.60 must have module as param.
Expand Down
29 changes: 21 additions & 8 deletions src/trowaSoftComponents.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ using namespace rack;

extern Plugin* pluginInstance;

#define DEBUG_COLOR_SLIDER 0 // Doesn't work in v2. I broke it in conversion somehow.

//=======================================================
// trowaSoft - TurtleMonkey Components
//=======================================================
Expand Down Expand Up @@ -2185,9 +2187,9 @@ struct TS_SvgPanel : SvgPanel
// TS_ColorSlider - Horizontal color slider control 'knob'.
// Meant for picking colors via Hue, Saturation, Lightness.
//--------------------------------------------------------------
struct TS_ColorSlider : Knob {
struct TS_ColorSlider : SliderKnob {
// If this control should be rendered
bool visible = true;
//bool visible = true;
// Starting color.
TSColorHSL startColorHSL;
// Ending color.
Expand All @@ -2200,8 +2202,19 @@ struct TS_ColorSlider : Knob {
int numStops = 24;
float handleWidth = 15.0;
float handleMargin = 3.0;
TS_ColorSlider() : Knob()
#if DEBUG_COLOR_SLIDER
int debugId = 0;
#endif
TS_ColorSlider() : SliderKnob()
{
#if DEBUG_COLOR_SLIDER
static int sliderId = 0;
sliderId++;
debugId = sliderId;
DEBUG("*COLOR SLIDER ID %d", debugId);
#endif


this->horizontal = true;
this->snap = false;
startColorHSL.h = 0.0;
Expand Down Expand Up @@ -2251,12 +2264,12 @@ struct TS_ColorSlider : Knob {
}
void onDragStart(const event::DragStart &e) override {
if (visible)
this->Knob::onDragStart(e);
this->SliderKnob::onDragStart(e);
}

void onDragMove(const event::DragMove &e) override {
if (visible) {
this->Knob::onDragMove(e);
this->SliderKnob::onDragMove(e);
}
// if (visible && paramQuantity)
// {
Expand All @@ -2282,11 +2295,11 @@ struct TS_ColorSlider : Knob {
}
void onDragEnd(const event::DragEnd &e) override {
if (visible)
this->Knob::onDragEnd(e);
this->SliderKnob::onDragEnd(e);
}
void onChange(const event::Change &e) override {
if (visible)
this->Knob::onChange(e);
this->SliderKnob::onChange(e);
}
void drawControl(const DrawArgs &args)
{
Expand Down Expand Up @@ -2355,7 +2368,7 @@ struct TS_ColorSlider : Knob {
{
drawControl(args);
}
this->Knob::drawLayer(args, layer);
this->SliderKnob::drawLayer(args, layer);
}
}
}; // end TS_ColorSlider
Expand Down
1 change: 1 addition & 0 deletions src/trowaSoftUtilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ namespace trowaSoft
void TSColorToHSL(NVGcolor color, TSColorHSL* hsv);
}


struct GlobalEffect {
NVGcompositeOperation compositeOperation = NVG_SOURCE_OVER;
const char* label;
Expand Down

0 comments on commit 0880eb3

Please sign in to comment.