From 44ec4f70da65c6e1a3a28633f80a1dd1cc7aa249 Mon Sep 17 00:00:00 2001 From: Eknous-P Date: Thu, 13 Nov 2025 18:21:25 +0400 Subject: [PATCH] channel color for gradient part 1 very not work --- src/gui/chanOsc.cpp | 62 ++++++++++++++++++++++++++++++++++++++------ src/gui/gradient.cpp | 17 ++++++++---- src/gui/gui.cpp | 6 ++--- src/gui/gui.h | 4 +-- 4 files changed, 71 insertions(+), 18 deletions(-) diff --git a/src/gui/chanOsc.cpp b/src/gui/chanOsc.cpp index 49aaceecc..8e421d23b 100644 --- a/src/gui/chanOsc.cpp +++ b/src/gui/chanOsc.cpp @@ -341,9 +341,30 @@ void FurnaceGUI::drawChanOsc() { } ImGui::TableNextColumn(); - if (ImGui::ColorEdit4(_("Background"),(float*)&chanOscGrad.bgColor)) { + ImGui::Text(_("Background:")); + ImGui::Indent(); + if (ImGui::RadioButton(_("Solid color"),chanOscColorMode==0)) { + chanOscColorMode=0; updateChanOscGradTex=true; } + if (chanOscColorMode==0) { + ImGui::Indent(); + if (ImGui::ColorEdit4(_("Color"),(float*)&chanOscGrad.bgColor)) { + updateChanOscGradTex=true; + } + ImGui::Unindent(); + } + if (ImGui::RadioButton(_("Channel color"),chanOscColorMode==1)) { + chanOscColorMode=1; + chanOscGrad.bgColor.x=0.0f; + chanOscGrad.bgColor.y=0.0f; + chanOscGrad.bgColor.z=0.0f; + chanOscGrad.bgColor.w=0.0f; + updateChanOscGradTex=true; + } + // in preparation of image texture + ImGui::Unindent(); + ImGui::Combo(_("X Axis##AxisX"),&chanOscColorX,LocalizedComboGetter,chanOscRefs,GUI_OSCREF_MAX); ImGui::Combo(_("Y Axis##AxisY"),&chanOscColorY,LocalizedComboGetter,chanOscRefs,GUI_OSCREF_MAX); @@ -351,10 +372,13 @@ void FurnaceGUI::drawChanOsc() { } } else { ImGui::SetNextItemWidth(400.0f*dpiScale); - ImGui::BeginDisabled(chanOscUseChanColor); - ImGui::ColorPicker4(_("Color"),(float*)&chanOscColor); + bool chanOscColorModeB=chanOscColorMode; + ImGui::BeginDisabled(chanOscColorModeB); + ImGui::ColorEdit4(_("Color"),(float*)&chanOscColor); ImGui::EndDisabled(); - ImGui::Checkbox(_("Set to channel color"), &chanOscUseChanColor); + if (ImGui::Checkbox(_("Set to channel color"), &chanOscColorModeB)) { + chanOscColorMode=chanOscColorModeB; + } } ImGui::AlignTextToFramePadding(); @@ -773,7 +797,15 @@ void FurnaceGUI::drawChanOsc() { } } } - ImU32 color=ImGui::GetColorU32(chanOscUseChanColor?channelColor(oscChans[i]):chanOscColor); + ImU32 color; + switch (chanOscColorMode) { + case 0: + color=ImGui::GetColorU32(chanOscColor); + break; + case 1: + color=ImGui::GetColorU32(channelColor(oscChans[i])); + break; + } if (chanOscUseGrad) { float xVal=computeGradPos(chanOscColorX,ch,oscBufs.size()); float yVal=computeGradPos(chanOscColorY,ch,oscBufs.size()); @@ -781,7 +813,22 @@ void FurnaceGUI::drawChanOsc() { xVal=CLAMP(xVal,0.0f,1.0f); yVal=CLAMP(yVal,0.0f,1.0f); - color=chanOscGrad.get(xVal,1.0f-yVal); + switch (chanOscColorMode) { + case 0: + color=chanOscGrad.get(xVal,1.0f-yVal); + break; + case 1: + color=ImAlphaBlendColors(color,chanOscGrad.get(xVal,1.0f-yVal)); + break; + } + // char buf[256]; + // snprintf(buf, 256, "%f:%f",xVal,yVal); + // dl->AddText(inRect.Min,-1,buf); + // dl->AddCircleFilled( + // ImVec2( + // ImLerp(inRect.Min.x,inRect.Max.x,xVal), + // ImLerp(inRect.Min.y,inRect.Max.y,1.0f-yVal) + // ), 2, 0xffff0000); } if (rend->supportsDrawOsc() && settings.shaderOsc) { @@ -886,10 +933,9 @@ void FurnaceGUI::drawChanOsc() { text+=fmt::sprintf("%s",noteName(chanState->note+60)); break; } - case 'l': { + case 'l': text+='\n'; break; - } case '%': text+='%'; break; diff --git a/src/gui/gradient.cpp b/src/gui/gradient.cpp index b33564f0b..be4e08eb1 100644 --- a/src/gui/gradient.cpp +++ b/src/gui/gradient.cpp @@ -109,21 +109,28 @@ void Gradient2D::render() { if (dist>1) dist=1; ImU32 shadeColor=ImGui::ColorConvertFloat4ToU32( + // ps: multiplying dist to the color channels fixes old + // mixing, but breaks if the bg is 0. and vice versa (not + // multiplying fixes 0 bg mixing) ImVec4( i.color.x*i.color.w*dist, i.color.y*i.color.w*dist, i.color.z*i.color.w*dist, - 1.0f + 1.0f*dist // this idk ) ); ImU32 origColor=g[j*width+k]; + // note: this really breaks the color mixing if theres a background + // and the bitshifts are necessary to avoid overflow (but prob only for alpha) + // this needs to be redone, its a temporary proof-of-concept solution anyway g[j*width+k]=( - (MIN( 0xff, (origColor&0xff) + (shadeColor&0xff) )) | // R - (MIN( 0xff00, (origColor&0xff00) + (shadeColor&0xff00) )) | // G - (MIN(0xff0000,(origColor&0xff0000)+(shadeColor&0xff0000))) | // B - (origColor&0xff000000) // A + (MIN(0xff,(origColor &0xff)+(shadeColor &0xff)) ) | // R + (MIN(0xff,(origColor>> 8&0xff)+(shadeColor>> 8&0xff))<< 8) | // G + (MIN(0xff,(origColor>>16&0xff)+(shadeColor>>16&0xff))<<16) | // B + (MIN(0xff,(origColor>>24&0xff)+(shadeColor>>24&0xff))<<24) // A ); + // ps 2: replacing this with ImAlphaBlendColors doesnt work } } } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2284d0ea1..ab04f7830 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -8402,7 +8402,7 @@ void FurnaceGUI::syncState() { chanOscTextColor.z=e->getConfFloat("chanOscTextColorB",1.0f); chanOscTextColor.w=e->getConfFloat("chanOscTextColorA",0.75f); chanOscUseGrad=e->getConfBool("chanOscUseGrad",false); - chanOscUseChanColor=e->getConfBool("chanOscUseChanColor", false); + chanOscColorMode=e->getConfInt("chanOscColorMode",0); chanOscGrad.fromString(e->getConfString("chanOscGrad","")); chanOscGrad.render(); @@ -8577,7 +8577,7 @@ void FurnaceGUI::commitState(DivConfig& conf) { conf.set("chanOscTextColorA",chanOscTextColor.w); conf.set("chanOscUseGrad",chanOscUseGrad); conf.set("chanOscGrad",chanOscGrad.toString()); - conf.set("chanOscUseChanColor",chanOscUseChanColor); + conf.set("chanOscColorMode",chanOscColorMode); // commit x-y osc state conf.set("xyOscXChannel",xyOscXChannel); @@ -9190,6 +9190,7 @@ FurnaceGUI::FurnaceGUI(): chanOscColorX(GUI_OSCREF_CENTER), chanOscColorY(GUI_OSCREF_CENTER), chanOscCenterStrat(1), + chanOscColorMode(0), chanOscWindowSize(20.0f), chanOscTextX(0.0f), chanOscTextY(0.0f), @@ -9201,7 +9202,6 @@ FurnaceGUI::FurnaceGUI(): chanOscUseGrad(false), chanOscNormalize(false), chanOscRandomPhase(false), - chanOscUseChanColor(false), chanOscAutoCols(false), chanOscTextFormat("%c"), chanOscColor(1.0f,1.0f,1.0f,1.0f), diff --git a/src/gui/gui.h b/src/gui/gui.h index 024d40c33..0a0076e57 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2696,10 +2696,10 @@ class FurnaceGUI { bool oscZoomSlider; // per-channel oscilloscope - int chanOscCols, chanOscColorX, chanOscColorY, chanOscCenterStrat; + int chanOscCols, chanOscColorX, chanOscColorY, chanOscCenterStrat, chanOscColorMode; float chanOscWindowSize, chanOscTextX, chanOscTextY, chanOscAmplify, chanOscLineSize; bool chanOscWaveCorr, chanOscOptions, updateChanOscGradTex, chanOscUseGrad; - bool chanOscNormalize, chanOscRandomPhase, chanOscUseChanColor, chanOscAutoCols; + bool chanOscNormalize, chanOscRandomPhase, chanOscAutoCols; String chanOscTextFormat; ImVec4 chanOscColor, chanOscTextColor; Gradient2D chanOscGrad;