GUI: channel pair hints, part 4
now with flooring
This commit is contained in:
parent
8422e5dc1b
commit
6f9e3e0058
20
extern/imgui_patched/imgui.cpp
vendored
20
extern/imgui_patched/imgui.cpp
vendored
|
@ -3513,6 +3513,26 @@ void ImGui::RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MODIFIED: Render a rectangle shaped with optional rounding and borders on DrawList
|
||||||
|
void ImGui::RenderFrameDrawList(ImDrawList* dl, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border, float rounding)
|
||||||
|
{
|
||||||
|
ImGuiContext& g = *GImGui;
|
||||||
|
if (g.Style.FrameShading>0.0f) {
|
||||||
|
ImVec4 fill_colPre=ImGui::ColorConvertU32ToFloat4(fill_col);
|
||||||
|
fill_colPre.w*=1.0f-g.Style.FrameShading;
|
||||||
|
ImU32 fill_col1=ImGui::ColorConvertFloat4ToU32(fill_colPre);
|
||||||
|
dl->AddRectFilledMultiColor(p_min, p_max, fill_col, fill_col, fill_col1, fill_col1, rounding);
|
||||||
|
} else {
|
||||||
|
dl->AddRectFilled(p_min, p_max, fill_col, rounding);
|
||||||
|
}
|
||||||
|
const float border_size = g.Style.FrameBorderSize;
|
||||||
|
if (border && border_size > 0.0f)
|
||||||
|
{
|
||||||
|
dl->AddRect(p_min + ImVec2(1, 1), p_max + ImVec2(1, 1), GetColorU32(ImGuiCol_BorderShadow), rounding, 0, border_size);
|
||||||
|
dl->AddRect(p_min, p_max, GetColorU32(ImGuiCol_Border), rounding, 0, border_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
|
void ImGui::RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding)
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
|
|
1
extern/imgui_patched/imgui_internal.h
vendored
1
extern/imgui_patched/imgui_internal.h
vendored
|
@ -3449,6 +3449,7 @@ namespace ImGui
|
||||||
IMGUI_API void RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL);
|
IMGUI_API void RenderTextClippedEx(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, const char* text, const char* text_end, const ImVec2* text_size_if_known, const ImVec2& align = ImVec2(0, 0), const ImRect* clip_rect = NULL);
|
||||||
IMGUI_API void RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known);
|
IMGUI_API void RenderTextEllipsis(ImDrawList* draw_list, const ImVec2& pos_min, const ImVec2& pos_max, float clip_max_x, float ellipsis_max_x, const char* text, const char* text_end, const ImVec2* text_size_if_known);
|
||||||
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
IMGUI_API void RenderFrame(ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f);
|
||||||
|
IMGUI_API void RenderFrameDrawList(ImDrawList* dl, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, bool border = true, float rounding = 0.0f); // MODIFIED - draw list version of RenderFrame
|
||||||
IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
|
IMGUI_API void RenderFrameBorder(ImVec2 p_min, ImVec2 p_max, float rounding = 0.0f);
|
||||||
IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, ImDrawFlags flags = 0);
|
IMGUI_API void RenderColorRectWithAlphaCheckerboard(ImDrawList* draw_list, ImVec2 p_min, ImVec2 p_max, ImU32 fill_col, float grid_step, ImVec2 grid_off, float rounding = 0.0f, ImDrawFlags flags = 0);
|
||||||
IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight
|
IMGUI_API void RenderNavHighlight(const ImRect& bb, ImGuiID id, ImGuiNavHighlightFlags flags = ImGuiNavHighlightFlags_TypeDefault); // Navigation highlight
|
||||||
|
|
|
@ -28,6 +28,17 @@
|
||||||
#include "../utfutils.h"
|
#include "../utfutils.h"
|
||||||
#include <fmt/printf.h>
|
#include <fmt/printf.h>
|
||||||
|
|
||||||
|
struct DelayedLabel {
|
||||||
|
float posCenter, posY;
|
||||||
|
ImVec2 textSize;
|
||||||
|
const char* label;
|
||||||
|
DelayedLabel(float pc, float py, ImVec2 ts, const char* l):
|
||||||
|
posCenter(pc),
|
||||||
|
posY(py),
|
||||||
|
textSize(ts),
|
||||||
|
label(l) {}
|
||||||
|
};
|
||||||
|
|
||||||
inline float randRange(float min, float max) {
|
inline float randRange(float min, float max) {
|
||||||
return min+((float)rand()/(float)RAND_MAX)*(max-min);
|
return min+((float)rand()/(float)RAND_MAX)*(max-min);
|
||||||
}
|
}
|
||||||
|
@ -1136,22 +1147,30 @@ void FurnaceGUI::drawPattern() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// HACK: rendering here would cause the pairs to be drawn behind the pattern for some reason...
|
// HACK: rendering here would cause the pairs to be drawn behind the pattern for some reason...
|
||||||
|
// ...so we capture the table's window draw list...
|
||||||
tdl=ImGui::GetWindowDrawList();
|
tdl=ImGui::GetWindowDrawList();
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ...and then use it here
|
||||||
ImGui::PushFont(mainFont);
|
ImGui::PushFont(mainFont);
|
||||||
if (patChannelPairs && e->isRunning() && tdl!=NULL) { // pair hints
|
if (patChannelPairs && e->isRunning() && tdl!=NULL) { // pair hints
|
||||||
float pos=0.0f;
|
float pos=0.0f;
|
||||||
float posCenter=0.0f;
|
float posCenter=0.0f;
|
||||||
float posMin=FLT_MAX;
|
float posMin=FLT_MAX;
|
||||||
float posMax=-FLT_MAX;
|
float posMax=-FLT_MAX;
|
||||||
float posY=chanHeadBottom;
|
|
||||||
ImVec2 textSize;
|
ImVec2 textSize;
|
||||||
|
unsigned int floors[4][4]; // bit array
|
||||||
|
std::vector<DelayedLabel> delayedLabels;
|
||||||
|
|
||||||
|
memset(floors,0,4*4*sizeof(unsigned int));
|
||||||
|
|
||||||
for (int i=0; i<chans; i++) {
|
for (int i=0; i<chans; i++) {
|
||||||
bool isPaired=false;
|
bool isPaired=false;
|
||||||
int numPairs=0;
|
int numPairs=0;
|
||||||
|
unsigned int pairMin=i;
|
||||||
|
unsigned int pairMax=i;
|
||||||
|
unsigned char curFloor=0;
|
||||||
if (!e->curSubSong->chanShow[i]) {
|
if (!e->curSubSong->chanShow[i]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1164,11 +1183,34 @@ void FurnaceGUI::drawPattern() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
isPaired=true;
|
isPaired=true;
|
||||||
break;
|
if ((unsigned int)pairCh<pairMin) pairMin=pairCh;
|
||||||
|
if ((unsigned int)pairCh>pairMax) pairMax=pairCh;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isPaired) continue;
|
if (!isPaired) continue;
|
||||||
|
|
||||||
|
float posY=chanHeadBottom;
|
||||||
|
|
||||||
|
// find a free floor
|
||||||
|
while (curFloor<4) {
|
||||||
|
bool free=true;
|
||||||
|
for (unsigned int j=pairMin; j<=pairMax; j++) {
|
||||||
|
const unsigned int j0=j>>5;
|
||||||
|
const unsigned int j1=1U<<(j&31);
|
||||||
|
if (floors[curFloor][j0]&j1) {
|
||||||
|
free=false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (free) break;
|
||||||
|
curFloor++;
|
||||||
|
}
|
||||||
|
if (curFloor<4) {
|
||||||
|
// occupy floor
|
||||||
|
floors[curFloor][pairMin>>5]|=1U<<(pairMin&31);
|
||||||
|
floors[curFloor][pairMax>>5]|=1U<<(pairMax&31);
|
||||||
|
}
|
||||||
|
|
||||||
pos=(patChanX[i+1]+patChanX[i])*0.5;
|
pos=(patChanX[i+1]+patChanX[i])*0.5;
|
||||||
posCenter=pos;
|
posCenter=pos;
|
||||||
posMin=pos;
|
posMin=pos;
|
||||||
|
@ -1180,8 +1222,11 @@ void FurnaceGUI::drawPattern() {
|
||||||
} else {
|
} else {
|
||||||
textSize=ImGui::CalcTextSize(pairs.label);
|
textSize=ImGui::CalcTextSize(pairs.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
posY+=(textSize.y+ImGui::GetStyle().ItemSpacing.y)*curFloor;
|
||||||
|
|
||||||
tdl->AddLine(
|
tdl->AddLine(
|
||||||
ImVec2(pos,posY),
|
ImVec2(pos,chanHeadBottom),
|
||||||
ImVec2(pos,posY+textSize.y),
|
ImVec2(pos,posY+textSize.y),
|
||||||
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
|
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
|
||||||
2.0f*dpiScale
|
2.0f*dpiScale
|
||||||
|
@ -1200,7 +1245,7 @@ void FurnaceGUI::drawPattern() {
|
||||||
if (pos<posMin) posMin=pos;
|
if (pos<posMin) posMin=pos;
|
||||||
if (pos>posMax) posMax=pos;
|
if (pos>posMax) posMax=pos;
|
||||||
tdl->AddLine(
|
tdl->AddLine(
|
||||||
ImVec2(pos,posY),
|
ImVec2(pos,chanHeadBottom),
|
||||||
ImVec2(pos,posY+textSize.y),
|
ImVec2(pos,posY+textSize.y),
|
||||||
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
|
ImGui::GetColorU32(uiColors[GUI_COLOR_PATTERN_PAIR]),
|
||||||
2.0f*dpiScale
|
2.0f*dpiScale
|
||||||
|
@ -1230,21 +1275,26 @@ void FurnaceGUI::drawPattern() {
|
||||||
2.0f*dpiScale
|
2.0f*dpiScale
|
||||||
);
|
);
|
||||||
|
|
||||||
ImGui::RenderFrame(
|
delayedLabels.push_back(DelayedLabel(posCenter,posY,textSize,pairs.label));
|
||||||
ImVec2(posCenter-textSize.x*0.5-6.0f*dpiScale,posY+textSize.y*0.5-3.0f*dpiScale),
|
|
||||||
ImVec2(posCenter+textSize.x*0.5+6.0f*dpiScale,posY+textSize.y*1.5+3.0f*dpiScale),
|
|
||||||
ImGui::GetColorU32(ImGuiCol_FrameBg),
|
|
||||||
true,
|
|
||||||
ImGui::GetStyle().FrameRounding
|
|
||||||
);
|
|
||||||
|
|
||||||
tdl->AddText(
|
|
||||||
ImVec2(posCenter-textSize.x*0.5,posY+textSize.y*0.5),
|
|
||||||
ImGui::GetColorU32(ImGuiCol_Text),
|
|
||||||
pairs.label
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (DelayedLabel& i: delayedLabels) {
|
||||||
|
ImGui::RenderFrameDrawList(
|
||||||
|
tdl,
|
||||||
|
ImVec2(i.posCenter-i.textSize.x*0.5-6.0f*dpiScale,i.posY+i.textSize.y*0.5-3.0f*dpiScale),
|
||||||
|
ImVec2(i.posCenter+i.textSize.x*0.5+6.0f*dpiScale,i.posY+i.textSize.y*1.5+3.0f*dpiScale),
|
||||||
|
ImGui::GetColorU32(ImGuiCol_FrameBg),
|
||||||
|
true,
|
||||||
|
ImGui::GetStyle().FrameRounding
|
||||||
|
);
|
||||||
|
|
||||||
|
tdl->AddText(
|
||||||
|
ImVec2(i.posCenter-i.textSize.x*0.5,i.posY+i.textSize.y*0.5),
|
||||||
|
ImGui::GetColorU32(ImGuiCol_Text),
|
||||||
|
i.label
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue