mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-26 22:43:01 +00:00
GUI: macro UI refactor, part 4
This commit is contained in:
parent
24b7dd6f54
commit
3170803389
3 changed files with 63 additions and 17 deletions
|
@ -1067,6 +1067,10 @@ void FurnaceGUI::drawGBEnv(unsigned char vol, unsigned char len, unsigned char s
|
||||||
|
|
||||||
#define PARAMETER MARK_MODIFIED; e->notifyInsChange(curIns);
|
#define PARAMETER MARK_MODIFIED; e->notifyInsChange(curIns);
|
||||||
|
|
||||||
|
String genericGuide(float value) {
|
||||||
|
return fmt::sprintf("%d",(int)value);
|
||||||
|
}
|
||||||
|
|
||||||
void FurnaceGUI::drawMacros(std::vector<FurnaceGUIMacroDesc>& macros) {
|
void FurnaceGUI::drawMacros(std::vector<FurnaceGUIMacroDesc>& macros) {
|
||||||
float asFloat[256];
|
float asFloat[256];
|
||||||
int asInt[256];
|
int asInt[256];
|
||||||
|
@ -1081,7 +1085,12 @@ void FurnaceGUI::drawMacros(std::vector<FurnaceGUIMacroDesc>& macros) {
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
float lenAvail=ImGui::GetContentRegionAvail().x;
|
float lenAvail=ImGui::GetContentRegionAvail().x;
|
||||||
ImGui::Dummy(ImVec2(120.0f*dpiScale,dpiScale));
|
//ImGui::Dummy(ImVec2(120.0f*dpiScale,dpiScale));
|
||||||
|
ImGui::SetNextItemWidth(120.0f*dpiScale);
|
||||||
|
if (ImGui::InputInt("##MacroPointSize",¯oPointSize,1,16)) {
|
||||||
|
if (macroPointSize<1) macroPointSize=1;
|
||||||
|
if (macroPointSize>256) macroPointSize=256;
|
||||||
|
}
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
float availableWidth=ImGui::GetContentRegionAvail().x-reservedSpace;
|
float availableWidth=ImGui::GetContentRegionAvail().x-reservedSpace;
|
||||||
int totalFit=MIN(128,availableWidth/MAX(1,macroPointSize*dpiScale));
|
int totalFit=MIN(128,availableWidth/MAX(1,macroPointSize*dpiScale));
|
||||||
|
@ -1138,15 +1147,23 @@ void FurnaceGUI::drawMacros(std::vector<FurnaceGUIMacroDesc>& macros) {
|
||||||
}
|
}
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0.0f,0.0f));
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding,ImVec2(0.0f,0.0f));
|
||||||
|
|
||||||
if (i.macro->vZoom<0) {
|
if (i.macro->vZoom<1) {
|
||||||
i.macro->vZoom=i.max-i.min;
|
if (i.macro->name=="arp") {
|
||||||
i.macro->vScroll=0;
|
i.macro->vZoom=24;
|
||||||
|
i.macro->vScroll=120-12;
|
||||||
|
} else {
|
||||||
|
i.macro->vZoom=i.max-i.min;
|
||||||
|
i.macro->vScroll=0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (i.macro->vZoom>(i.max-i.min)) {
|
||||||
|
i.macro->vZoom=i.max-i.min;
|
||||||
|
}
|
||||||
|
|
||||||
if (i.isBitfield) {
|
if (i.isBitfield) {
|
||||||
PlotBitfield("##IMacro",asInt,totalFit,0,i.bitfieldBits,i.max,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)));
|
PlotBitfield("##IMacro",asInt,totalFit,0,i.bitfieldBits,i.max,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)));
|
||||||
} else {
|
} else {
|
||||||
PlotCustom("##IMacro",asFloat,totalFit,macroDragScroll,NULL,i.min+i.macro->vScroll,i.min+i.macro->vScroll+i.macro->vZoom,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)),sizeof(float),i.color,i.macro->len-macroDragScroll,i.hoverFunc,i.blockMode);
|
PlotCustom("##IMacro",asFloat,totalFit,macroDragScroll,NULL,i.min+i.macro->vScroll,i.min+i.macro->vScroll+i.macro->vZoom,ImVec2(availableWidth,(i.macro->open)?(i.height*dpiScale):(32.0f*dpiScale)),sizeof(float),i.color,i.macro->len-macroDragScroll,i.hoverFunc,i.blockMode,i.macro->open?genericGuide:NULL);
|
||||||
}
|
}
|
||||||
if (i.macro->open && (ImGui::IsItemClicked(ImGuiMouseButton_Left) || ImGui::IsItemClicked(ImGuiMouseButton_Right))) {
|
if (i.macro->open && (ImGui::IsItemClicked(ImGuiMouseButton_Left) || ImGui::IsItemClicked(ImGuiMouseButton_Right))) {
|
||||||
macroDragStart=ImGui::GetItemRectMin();
|
macroDragStart=ImGui::GetItemRectMin();
|
||||||
|
@ -1172,25 +1189,36 @@ void FurnaceGUI::drawMacros(std::vector<FurnaceGUIMacroDesc>& macros) {
|
||||||
}
|
}
|
||||||
if (i.macro->open) {
|
if (i.macro->open) {
|
||||||
if (ImGui::IsItemHovered() && ctrlWheeling) {
|
if (ImGui::IsItemHovered() && ctrlWheeling) {
|
||||||
macroPointSize+=wheelY;
|
if (ImGui::IsKeyDown(ImGuiKey_LeftShift) || ImGui::IsKeyDown(ImGuiKey_RightShift)) {
|
||||||
if (macroPointSize<1) macroPointSize=1;
|
i.macro->vZoom+=wheelY;
|
||||||
if (macroPointSize>256) macroPointSize=256;
|
if (i.macro->vZoom<1) i.macro->vZoom=1;
|
||||||
|
if (i.macro->vZoom>(i.max-i.min)) i.macro->vZoom=i.max-i.min;
|
||||||
|
if ((i.macro->vScroll+i.macro->vZoom)>(i.max-i.min)) {
|
||||||
|
i.macro->vScroll=(i.max-i.min)-i.macro->vZoom;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
macroPointSize+=wheelY;
|
||||||
|
if (macroPointSize<1) macroPointSize=1;
|
||||||
|
if (macroPointSize>256) macroPointSize=256;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// slider
|
// slider
|
||||||
if (!i.isBitfield) {
|
if (!i.isBitfield) {
|
||||||
ImS64 scrollV=i.max-i.macro->vScroll;
|
ImS64 scrollV=(i.max-i.min-i.macro->vZoom)-i.macro->vScroll;
|
||||||
ImS64 availV=i.macro->vZoom;
|
ImS64 availV=i.macro->vZoom;
|
||||||
ImS64 contentsV=(i.max-i.min);
|
ImS64 contentsV=(i.max-i.min);
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::SameLine(0.0f);
|
||||||
ImRect scrollbarPos=ImRect(ImGui::GetCursorScreenPos(),ImGui::GetCursorScreenPos());
|
ImRect scrollbarPos=ImRect(ImGui::GetCursorScreenPos(),ImGui::GetCursorScreenPos());
|
||||||
|
scrollbarPos.Min.x-=ImGui::GetStyle().ItemSpacing.x;
|
||||||
scrollbarPos.Max.x+=ImGui::GetStyle().ScrollbarSize;
|
scrollbarPos.Max.x+=ImGui::GetStyle().ScrollbarSize;
|
||||||
|
scrollbarPos.Max.x-=ImGui::GetStyle().ItemSpacing.x;
|
||||||
scrollbarPos.Max.y+=i.height*dpiScale;
|
scrollbarPos.Max.y+=i.height*dpiScale;
|
||||||
ImGui::Dummy(ImVec2(ImGui::GetStyle().ScrollbarSize,i.height*dpiScale));
|
ImGui::Dummy(ImVec2(ImGui::GetStyle().ScrollbarSize,i.height*dpiScale));
|
||||||
|
|
||||||
if (ImGui::ScrollbarEx(scrollbarPos,ImGui::GetID("IMacroVScroll"),ImGuiAxis_Y,&scrollV,availV,contentsV,0)) {
|
if (ImGui::ScrollbarEx(scrollbarPos,ImGui::GetID("IMacroVScroll"),ImGuiAxis_Y,&scrollV,availV,contentsV,0)) {
|
||||||
i.macro->vScroll=scrollV;
|
i.macro->vScroll=(i.max-i.min-i.macro->vZoom)-scrollV;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2925,7 +2953,7 @@ void FurnaceGUI::drawInsEdit() {
|
||||||
if (volMax>0) {
|
if (volMax>0) {
|
||||||
macroList.push_back(FurnaceGUIMacroDesc(volumeLabel,&ins->std.volMacro,volMin,volMax,160,uiColors[GUI_COLOR_MACRO_VOLUME]));
|
macroList.push_back(FurnaceGUIMacroDesc(volumeLabel,&ins->std.volMacro,volMin,volMax,160,uiColors[GUI_COLOR_MACRO_VOLUME]));
|
||||||
}
|
}
|
||||||
macroList.push_back(FurnaceGUIMacroDesc("Arpeggio",&ins->std.arpMacro,-120,120,160,uiColors[GUI_COLOR_MACRO_PITCH],false,macroAbsoluteMode,ins->std.arpMacro.mode?(¯oHoverNote):NULL));
|
macroList.push_back(FurnaceGUIMacroDesc("Arpeggio",&ins->std.arpMacro,-120,120,160,uiColors[GUI_COLOR_MACRO_PITCH],true,macroAbsoluteMode,ins->std.arpMacro.mode?(¯oHoverNote):NULL));
|
||||||
if (dutyMax>0) {
|
if (dutyMax>0) {
|
||||||
if (ins->type==DIV_INS_MIKEY) {
|
if (ins->type==DIV_INS_MIKEY) {
|
||||||
macroList.push_back(FurnaceGUIMacroDesc(dutyLabel,&ins->std.dutyMacro,0,dutyMax,160,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true,mikeyFeedbackBits));
|
macroList.push_back(FurnaceGUIMacroDesc(dutyLabel,&ins->std.dutyMacro,0,dutyMax,160,uiColors[GUI_COLOR_MACRO_OTHER],false,NULL,NULL,true,mikeyFeedbackBits));
|
||||||
|
|
|
@ -289,7 +289,7 @@ void PlotBitfield(const char* label, const int* values, int values_count, int va
|
||||||
PlotBitfieldEx(label, &Plot_IntArrayGetter, (void*)&data, values_count, values_offset, overlay_text, bits, graph_size);
|
PlotBitfieldEx(label, &Plot_IntArrayGetter, (void*)&data, values_count, values_offset, overlay_text, bits, graph_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode)
|
int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_getter)(void* data, int idx), void* data, int values_count, int values_display_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 frame_size, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float))
|
||||||
{
|
{
|
||||||
ImGuiContext& g = *GImGui;
|
ImGuiContext& g = *GImGui;
|
||||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||||
|
@ -428,13 +428,31 @@ int PlotCustomEx(ImGuiPlotType plot_type, const char* label, float (*values_gett
|
||||||
if (label_size.x > 0.0f)
|
if (label_size.x > 0.0f)
|
||||||
ImGui::RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
|
ImGui::RenderText(ImVec2(frame_bb.Max.x + style.ItemInnerSpacing.x, inner_bb.Min.y), label);
|
||||||
|
|
||||||
|
if (guideFunc && idx_hovered!=0) {
|
||||||
|
std::string guide=guideFunc(scale_max);
|
||||||
|
window->DrawList->AddText(frame_bb.Min+ImVec2(1.0f,1.0f),0xff000000,guide.c_str());
|
||||||
|
window->DrawList->AddText(frame_bb.Min+ImVec2(1.0f,-1.0f),0xff000000,guide.c_str());
|
||||||
|
window->DrawList->AddText(frame_bb.Min+ImVec2(-1.0f,1.0f),0xff000000,guide.c_str());
|
||||||
|
window->DrawList->AddText(frame_bb.Min+ImVec2(-1.0f,-1.0f),0xff000000,guide.c_str());
|
||||||
|
window->DrawList->AddText(frame_bb.Min,0xffffffff,guide.c_str());
|
||||||
|
|
||||||
|
std::string guide1=guideFunc(scale_min);
|
||||||
|
ImVec2 maxPos=frame_bb.Min;
|
||||||
|
maxPos.y=frame_bb.Max.y-ImGui::GetFont()->FontSize;
|
||||||
|
window->DrawList->AddText(maxPos+ImVec2(1.0f,1.0f),0xff000000,guide1.c_str());
|
||||||
|
window->DrawList->AddText(maxPos+ImVec2(1.0f,-1.0f),0xff000000,guide1.c_str());
|
||||||
|
window->DrawList->AddText(maxPos+ImVec2(-1.0f,1.0f),0xff000000,guide1.c_str());
|
||||||
|
window->DrawList->AddText(maxPos+ImVec2(-1.0f,-1.0f),0xff000000,guide1.c_str());
|
||||||
|
window->DrawList->AddText(maxPos,0xffffffff,guide1.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
// Return hovered index or -1 if none are hovered.
|
// Return hovered index or -1 if none are hovered.
|
||||||
// This is currently not exposed in the public API because we need a larger redesign of the whole thing, but in the short-term we are making it available in PlotEx().
|
// This is currently not exposed in the public API because we need a larger redesign of the whole thing, but in the short-term we are making it available in PlotEx().
|
||||||
return idx_hovered;
|
return idx_hovered;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode)
|
void PlotCustom(const char* label, const float* values, int values_count, int values_offset, const char* overlay_text, float scale_min, float scale_max, ImVec2 graph_size, int stride, ImVec4 color, int highlight, std::string (*hoverFunc)(int,float), bool blockMode, std::string (*guideFunc)(float))
|
||||||
{
|
{
|
||||||
FurnacePlotArrayGetterData data(values, stride);
|
FurnacePlotArrayGetterData data(values, stride);
|
||||||
PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight, hoverFunc, blockMode);
|
PlotCustomEx(ImGuiPlotType_Histogram, label, &Plot_ArrayGetter, (void*)&data, values_count, values_offset, overlay_text, scale_min, scale_max, graph_size, color, highlight, hoverFunc, blockMode, guideFunc);
|
||||||
}
|
}
|
|
@ -22,4 +22,4 @@
|
||||||
|
|
||||||
void PlotNoLerp(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float));
|
void PlotNoLerp(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float));
|
||||||
void PlotBitfield(const char* label, const int* values, int values_count, int values_offset = 0, const char** overlay_text = NULL, int bits = 8, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float));
|
void PlotBitfield(const char* label, const int* values, int values_count, int values_offset = 0, const char** overlay_text = NULL, int bits = 8, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float));
|
||||||
void PlotCustom(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float), ImVec4 fgColor = ImVec4(1.0f,1.0f,1.0f,1.0f), int highlight = 0, std::string (*hoverFunc)(int,float) = NULL, bool blockMode=false);
|
void PlotCustom(const char* label, const float* values, int values_count, int values_offset = 0, const char* overlay_text = NULL, float scale_min = FLT_MAX, float scale_max = FLT_MAX, ImVec2 graph_size = ImVec2(0, 0), int stride = sizeof(float), ImVec4 fgColor = ImVec4(1.0f,1.0f,1.0f,1.0f), int highlight = 0, std::string (*hoverFunc)(int,float) = NULL, bool blockMode=false, std::string (*guideFunc)(float) = NULL);
|
Loading…
Reference in a new issue