From 76b29fa31cee782c4862bbb65211630bbad5fd12 Mon Sep 17 00:00:00 2001 From: Eknous-P Date: Wed, 8 Oct 2025 19:54:49 +0400 Subject: [PATCH] centered vertical text someone pleeeeeease fix the clipping i give up --- src/gui/gui.cpp | 10 ++++++---- src/gui/gui.h | 4 ++-- src/gui/mixer.cpp | 22 +++++++++++++--------- src/gui/volMeter.cpp | 43 +++---------------------------------------- 4 files changed, 24 insertions(+), 55 deletions(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 933636b9f..8b1ac6351 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -455,7 +455,7 @@ void FurnaceGUI::VerticalText(const char* fmt, ...) { ImGui::Dummy(ImVec2(size.y,size.x)); } -void FurnaceGUI::VerticalText(float maxSize, const char* fmt, ...) { +void FurnaceGUI::VerticalText(float maxSize, bool centered, const char* fmt, ...) { va_list args; va_start(args, fmt); ImVec2 pos=ImGui::GetCursorScreenPos(); @@ -464,11 +464,13 @@ void FurnaceGUI::VerticalText(float maxSize, const char* fmt, ...) { vtxBegin=dl->_VtxCurrentIdx; char text[4096]; vsnprintf(text, 4096, fmt, args); + const char* textEol=ImGui::FindRenderedTextEnd(text); ImVec2 size=ImGui::CalcTextSize(text); - ImGui::RenderTextEllipsis(dl,pos,pos+ImVec2(maxSize,ImGui::GetFontSize()),maxSize,text,ImGui::FindRenderedTextEnd(text),&size); + ImGui::RenderTextEllipsis(dl,pos,pos+ImVec2(maxSize,ImGui::GetFontSize()),maxSize,text,textEol,&size); vtxEnd=dl->_VtxCurrentIdx; - ImGui::ShadeVertsTransformPos(dl, vtxBegin, vtxEnd, pos+ImVec2(size.x>maxSize?maxSize:size.x,0), 0, -1, pos); - ImGui::Dummy(ImVec2(size.y,size.x>maxSize?maxSize:size.x)); + float ySize=(size.x>maxSize)?maxSize:size.x; + ImGui::ShadeVertsTransformPos(dl, vtxBegin, vtxEnd, pos, 0, -1, pos+ImVec2(0,ySize+(centered?(maxSize-size.x)/2.0f:0))); + ImGui::Dummy(ImVec2(size.y,centered?maxSize:ySize)); } bool FurnaceGUI::CWSliderScalar(const char* label, ImGuiDataType data_type, void* p_data, const void* p_min, const void* p_max, const char* format, ImGuiSliderFlags flags) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 4af1f5794..e307f7cc2 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -2860,7 +2860,7 @@ class FurnaceGUI { void renderFMPreviewESFM(const DivInstrumentFM& params, const DivInstrumentESFM& esfmParams, int pos=0); void VerticalText(const char* fmt, ...); - void VerticalText(float maxSize, const char* fmt, ...); + void VerticalText(float maxSize, bool centered, const char* fmt, ...); // combo with locale static bool LocalizedComboGetter(void* data, int idx, const char** out_text); @@ -2991,7 +2991,7 @@ class FurnaceGUI { float drawSystemChannelInfo(const DivSysDef* whichDef, int keyHitOffset=-1, float width=-1.0f); void drawSystemChannelInfoText(const DivSysDef* whichDef); - void drawVolMeterInternal(ImDrawList* dl, ImRect rect, float* data, int chans); + void drawVolMeterInternal(ImDrawList* dl, ImRect rect, float* data, int chans, bool aspectRatio); void assignActionMap(std::map& actionMap, int first, int last); void drawKeybindSettingsTableRow(FurnaceGUIActions actionIdx); diff --git a/src/gui/mixer.cpp b/src/gui/mixer.cpp index 1cf6382f7..d39a4777f 100644 --- a/src/gui/mixer.cpp +++ b/src/gui/mixer.cpp @@ -226,16 +226,19 @@ void FurnaceGUI::drawMixer() { if (ImGui::Begin("Mixer",&mixerOpen,globalWinFlags|(settings.allowEditDocking?0:ImGuiWindowFlags_NoDocking),_("Mixer"))) { if (ImGui::BeginTabBar("MixerView")) { if (ImGui::BeginTabItem(_("Mixer"))) { - if (ImGui::VSliderFloat("##mixerMaster",ImVec2(40*dpiScale,ImGui::GetContentRegionAvail().y),&e->song.masterVol,0,3,"%.2fx")) { + float maxY=ImGui::GetContentRegionAvail().y; + VerticalText(maxY, true,_("Master Volume")); + ImGui::SameLine(); + if (ImGui::VSliderFloat("##mixerMaster",ImVec2(40*dpiScale,maxY),&e->song.masterVol,0,3,"%.2fx")) { if (e->song.masterVol<0) e->song.masterVol=0; if (e->song.masterVol>3) e->song.masterVol=3; MARK_MODIFIED; - } rightClickable //_("Master Volume") + } rightClickable ImGui::SameLine(); - if (ImGui::BeginChild("##mixerPerChipContainer",ImGui::GetContentRegionAvail())) { + if (ImGui::BeginChild("##mixerPerChipContainer")) { const float childWidth=60*dpiScale; for (int i=0; isong.systemLen; i++) { - if (chipMixer(i, ImVec2(childWidth, ImGui::GetContentRegionAvail().y))) MARK_MODIFIED; + if (chipMixer(i, ImVec2(childWidth,maxY))) MARK_MODIFIED; ImGui::SameLine(); } } @@ -428,21 +431,22 @@ bool FurnaceGUI::chipMixer(int which, ImVec2 size) { float volSliderHeight=size.y-ImGui::GetStyle().FramePadding.y*7-textHeight*2; - VerticalText(volSliderHeight-(ImGui::GetCursorPosY()-curPos.y),"%s",e->getSystemName(e->song.system[which])); + VerticalText(volSliderHeight-(ImGui::GetCursorPosY()-curPos.y), true,"%s",e->getSystemName(e->song.system[which])); ImGui::SameLine(); float vTextWidth=textHeight+2*ImGui::GetStyle().FramePadding.x; // TODO: per-chip per-out peak float volMeter[2]; - volMeter[0]=0; - volMeter[1]=0; + volMeter[0]=0.5; + volMeter[1]=0.5; ImGui::SetCursorPos(curPos); ImVec2 pos=ImGui::GetCursorScreenPos(); - drawVolMeterInternal(ImGui::GetWindowDrawList(),ImRect(pos,pos+ImVec2(size.x-vTextWidth,volSliderHeight)),volMeter,2); + drawVolMeterInternal(ImGui::GetWindowDrawList(),ImRect(pos,pos+ImVec2(size.x-vTextWidth,volSliderHeight)),volMeter,2,false); ImGui::PushStyleColor(ImGuiCol_FrameBg,0); ImGui::PushStyleColor(ImGuiCol_FrameBgActive,0); + ImGui::PushStyleColor(ImGuiCol_FrameBgHovered,127<song.systemPan[which], -1.0f, 1.0f)) { diff --git a/src/gui/volMeter.cpp b/src/gui/volMeter.cpp index 66c870741..b5a5576dc 100644 --- a/src/gui/volMeter.cpp +++ b/src/gui/volMeter.cpp @@ -48,47 +48,11 @@ void FurnaceGUI::drawVolMeter() { ImRect rect=ImRect(minArea,maxArea); ImGuiStyle& style=ImGui::GetStyle(); ImGui::ItemSize(ImVec2(4.0f,4.0f),style.FramePadding.y); - ImU32 lowColor=ImGui::GetColorU32(uiColors[GUI_COLOR_VOLMETER_LOW]); + // ImU32 lowColor=ImGui::GetColorU32(uiColors[GUI_COLOR_VOLMETER_LOW]); if (ImGui::ItemAdd(rect,ImGui::GetID("volMeter"))) { ImGui::RenderFrame(rect.Min,rect.Max,ImGui::GetColorU32(ImGuiCol_FrameBg),true,style.FrameRounding); int outChans=e->getAudioDescGot().outChans; - for (int i=0; i0.0) { - isClipping=8; - logPeak=0.0; - } - logPeak+=1.0; - ImU32 highColor=ImGui::GetColorU32( - ImLerp(uiColors[GUI_COLOR_VOLMETER_LOW],uiColors[GUI_COLOR_VOLMETER_HIGH],logPeak) - ); - ImRect s; - if (aspectRatio) { - s=ImRect( - ImLerp(rect.Min,rect.Max,ImVec2(0,float(i)/outChans)), - ImLerp(rect.Min,rect.Max,ImVec2(logPeak,float(i+1)/outChans)) - ); - if (i!=(outChans-1)) s.Max.y-=dpiScale; - if (isClipping) { - dl->AddRectFilled(s.Min,s.Max,ImGui::GetColorU32(uiColors[GUI_COLOR_VOLMETER_PEAK])); - } else { - dl->AddRectFilledMultiColor(s.Min,s.Max,lowColor,highColor,highColor,lowColor); - } - } else { - s=ImRect( - ImLerp(rect.Min,rect.Max,ImVec2(float(i)/outChans,1.0-logPeak)), - ImLerp(rect.Min,rect.Max,ImVec2(float(i+1)/outChans,1.0)) - ); - if (i!=(outChans-1)) s.Max.x-=dpiScale; - if (isClipping) { - dl->AddRectFilled(s.Min,s.Max,ImGui::GetColorU32(uiColors[GUI_COLOR_VOLMETER_PEAK])); - } else { - dl->AddRectFilledMultiColor(s.Min,s.Max,highColor,highColor,lowColor,lowColor); - } - } - } + drawVolMeterInternal(dl, rect, peak, outChans, aspectRatio); if (ImGui::IsItemHovered()) { if (aspectRatio) { ImGui::SetTooltip("%.1fdB",36*((ImGui::GetMousePos().x-ImGui::GetItemRectMin().x)/(rect.Max.x-rect.Min.x)-1.0)); @@ -103,8 +67,7 @@ void FurnaceGUI::drawVolMeter() { ImGui::End(); } -void FurnaceGUI::drawVolMeterInternal(ImDrawList* dl, ImRect rect, float* data, int chans) { - bool aspectRatio=(ImGui::GetWindowSize().x/ImGui::GetWindowSize().y)>1.0; +void FurnaceGUI::drawVolMeterInternal(ImDrawList* dl, ImRect rect, float* data, int chans, bool aspectRatio) { ImU32 lowColor=ImGui::GetColorU32(uiColors[GUI_COLOR_VOLMETER_LOW]); ImGuiStyle& style=ImGui::GetStyle(); ImGui::RenderFrame(rect.Min,rect.Max,ImGui::GetColorU32(ImGuiCol_FrameBg),true,style.FrameRounding);