GUI: implement GB envelope view

This commit is contained in:
tildearrow 2022-04-17 01:15:34 -05:00
parent 003c9c3235
commit 768419f461
1 changed files with 42 additions and 5 deletions

View File

@ -943,7 +943,7 @@ void FurnaceGUI::drawFMEnv(unsigned char tl, unsigned char ar, unsigned char dr,
ImU32 colorR=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ENVELOPE_RELEASE]); // Relsease triangle
ImU32 colorS=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ENVELOPE_SUS_GUIDE]); // Sustain horiz/vert line color
ImGui::ItemSize(size,style.FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID("alg"))) {
if (ImGui::ItemAdd(rect,ImGui::GetID("fmEnv"))) {
ImGui::RenderFrame(rect.Min,rect.Max,ImGui::GetColorU32(ImGuiCol_FrameBg),true,style.FrameRounding);
//Adjust for OPLL global sustain setting
@ -1003,7 +1003,7 @@ void FurnaceGUI::drawFMEnv(unsigned char tl, unsigned char ar, unsigned char dr,
}
void FurnaceGUI::drawGBEnv(unsigned char vol, unsigned char len, unsigned char sLen, bool dir, const ImVec2& size) {
//ImDrawList* dl=ImGui::GetWindowDrawList();
ImDrawList* dl=ImGui::GetWindowDrawList();
ImGuiWindow* window=ImGui::GetCurrentWindow();
ImVec2 minArea=window->DC.CursorPos;
@ -1013,13 +1013,50 @@ void FurnaceGUI::drawGBEnv(unsigned char vol, unsigned char len, unsigned char s
);
ImRect rect=ImRect(minArea,maxArea);
ImGuiStyle& style=ImGui::GetStyle();
//ImU32 color=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ENVELOPE]);
ImU32 color=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ENVELOPE]);
//ImU32 colorS=ImGui::GetColorU32(uiColors[GUI_COLOR_FM_ENVELOPE_SUS_GUIDE]); // Sustain horiz/vert line color
ImGui::ItemSize(size,style.FramePadding.y);
if (ImGui::ItemAdd(rect,ImGui::GetID("alg"))) {
if (ImGui::ItemAdd(rect,ImGui::GetID("gbEnv"))) {
ImGui::RenderFrame(rect.Min,rect.Max,ImGui::GetColorU32(ImGuiCol_FrameBg),true,style.FrameRounding);
float volY=1.0-((float)vol/15.0);
float lenPos=(sLen>62)?1.0:((float)sLen/384.0);
float envEndPoint=((float)len/7.0)*((float)(dir?(15-vol):vol)/15.0);
// TODO: this whole thing
ImVec2 pos1=ImLerp(rect.Min,rect.Max,ImVec2(0.0,volY));
ImVec2 pos2;
if (dir) {
if (len>0) {
if (lenPos<envEndPoint) {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,volY*(1.0-(lenPos/envEndPoint))));
} else {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(envEndPoint,0.0));
}
} else {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,volY));
}
} else {
if (len>0) {
if (lenPos<envEndPoint) {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,volY+(1.0-volY)*(lenPos/envEndPoint)));
} else {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(envEndPoint,1.0));
}
} else {
pos2=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,volY));
}
}
ImVec2 pos3=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,(len>0 || sLen<63)?((dir && sLen>62)?0.0:1.0):volY));
addAALine(dl,pos1,pos2,color);
if (lenPos>=envEndPoint && sLen<63 && dir) {
pos3=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,0.0));
addAALine(dl,pos2,pos3,color);
ImVec2 pos4=ImLerp(rect.Min,rect.Max,ImVec2(lenPos,1.0));
addAALine(dl,pos3,pos4,color);
} else {
addAALine(dl,pos2,pos3,color);
}
}
}