Skip to content

Commit

Permalink
Renderer: cleanup pedal editing window, adjust ratio.
Browse files Browse the repository at this point in the history
  • Loading branch information
kosua20 committed Aug 11, 2023
1 parent 2f3eda3 commit 87fd7d9
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 50 deletions.
90 changes: 43 additions & 47 deletions src/rendering/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1666,11 +1666,20 @@ void Renderer::showParticlesEditor(){
ImGui::End();
}

bool Renderer::drawPedalImageSettings(GLuint tex, const glm::vec2& size, bool flipUV, PathCollection& path, unsigned int index, glm::vec3& color){
bool Renderer::drawPedalImageSettings(GLuint tex, const glm::vec2& size, bool labelsAfter, bool flipUV, PathCollection& path, unsigned int index, glm::vec3& color){
bool refresh = false;
const ImVec2 startUV(flipUV ? 1 : 0,1);
const ImVec2 endUV(flipUV ? 0 : 1,0);

ImGui::BeginGroup();

ImGui::Image((void*)(uint64_t)tex, size, ImVec2(flipUV ? 1 : 0,1), ImVec2(flipUV ? 0 : 1,0), color);
if(labelsAfter){
ImGui::Image((void*)(uint64_t)tex, size, startUV, endUV, color);
} else {
// Pad top buttons
ImGui::Dummy(ImVec2(0.3f * size.x, 5));
ImGuiSameLine(0);
}

ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f,0.0f));
ImGui::ColorEdit3("Picker", &color[0], ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
Expand All @@ -1697,6 +1706,10 @@ bool Renderer::drawPedalImageSettings(GLuint tex, const glm::vec2& size, bool fl
refresh = true;
}

if(!labelsAfter){
ImGui::Image((void*)(uint64_t)tex, size, startUV, endUV, color);
}

ImGui::EndGroup();
return refresh;
};
Expand Down Expand Up @@ -1747,31 +1760,16 @@ void Renderer::showPedalsEditor(){
const ImVec2 & screenSize = ImGui::GetIO().DisplaySize;
ImGui::SetNextWindowPos(ImVec2(screenSize.x * 0.5f, screenSize.y * 0.1f), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.0f));
const float fixedWidth = _guiScale * 300.0f;
const float fixedHeight = _guiScale * 455.0f;
const float fixedHeight = _guiScale * 440.0f;
ImGui::SetNextWindowSize({fixedWidth, fixedHeight}, ImGuiCond_Always);

if(ImGui::Begin("Pedal Images Editor", &_showPedalsEditor, ImGuiWindowFlags_NoResize)){

bool refreshTextures = false;

// Header
ImGui::TextWrapped("Load images to use as masks for each pedal. Overlap between pedals can be tweaked using offsets.");
{
ImGuiPushItemWidth(100);
if(ImGui::SliderFloat("##OffsetX", &_state.pedals.margin[0], -0.5f, 0.5f, "Horiz.: %.2f")){
_state.pedals.margin[0] = glm::clamp(_state.pedals.margin[0], -0.5f, 0.5f);
}
ImGuiSameLine();
if(ImGui::SliderFloat("##OffsetY", &_state.pedals.margin[1], -0.5f, 0.5f, "Vert.: %.2f")){
_state.pedals.margin[1] = glm::clamp(_state.pedals.margin[1], -0.5f, 0.5f);
}
ImGui::PopItemWidth();
ImGuiSameLine();
ImGui::AlignTextToFramePadding();
ImGui::Text("Offsets");
}
{
ImGui::Checkbox("Mirror right pedal", &_state.pedals.mirror);
ImGuiSameLine();
if(ImGui::Button("Clear all")){
_state.pedals.centerImagePath.clear();
_state.pedals.topImagePath.clear();
Expand All @@ -1788,7 +1786,7 @@ void Renderer::showPedalsEditor(){
ImGui::Separator();

const float scale = 0.95f;
const ImVec2 diagSize(scale * fixedWidth, scale * fixedWidth);
const ImVec2 diagSize(scale * fixedWidth, scale * fixedWidth / 1.2f /* existing pedal ratio correction */);
const float topHeight = 0.20f;
const float bottomHeight = 0.72f;
const float sideWidth = 0.32f;
Expand All @@ -1798,46 +1796,44 @@ void Renderer::showPedalsEditor(){
const glm::vec2 topSize = glm::vec2(topWidth * diagSize.x, topHeight * diagSize.y);
const glm::vec2 centerSize = glm::vec2(centerWidth * diagSize.x, bottomHeight * diagSize.y);

ImGui::BeginGroup();
// Approximately center buttons
ImGui::Dummy(ImVec2(sideSize.x, 5.0f));
ImGuiSameLine();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0.f,0.0f));
ImGui::ColorEdit3("Picker", &_state.pedals.topColor[0], ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::PopStyleVar();
ImGuiSameLine();
if(ImGui::SmallButton("Load##Top")){
char* outPath = nullptr;
int res = sr_gui_ask_load_file("Select image", "", "png,jpg,jpeg", &outPath);
System::forceLocale();
if((res == SR_GUI_VALIDATED) && outPath ){
_state.pedals.topImagePath = { std::string(outPath)};
refreshTextures = true;
}
free(outPath);
}
ImGuiSameLine();
if(ImGui::SmallButton("x##Top")){
_state.pedals.topImagePath.clear();
refreshTextures = true;
}
ImGui::Image((void*)(uint64_t)_state.pedals.texTop, topSize, ImVec2(0,1), ImVec2(1,0), _state.pedals.topColor);
ImGui::EndGroup();
ImGui::PushID("Top");
refreshTextures |= drawPedalImageSettings(_state.pedals.texTop, topSize, false, false, _state.pedals.topImagePath, 0, _state.pedals.topColor);
ImGui::PopID();

ImGui::PushID("Left");
refreshTextures |= drawPedalImageSettings(_state.pedals.texSides[0], sideSize, false, _state.pedals.sideImagePaths, 0, _state.pedals.leftColor);
refreshTextures |= drawPedalImageSettings(_state.pedals.texSides[0], sideSize, true, false, _state.pedals.sideImagePaths, 0, _state.pedals.leftColor);
ImGui::PopID();
ImGuiSameLine(0);

ImGui::PushID("Center");
refreshTextures |= drawPedalImageSettings(_state.pedals.texCenter, centerSize, false, _state.pedals.centerImagePath, 0, _state.pedals.centerColor);
refreshTextures |= drawPedalImageSettings(_state.pedals.texCenter, centerSize, true, false, _state.pedals.centerImagePath, 0, _state.pedals.centerColor);
ImGui::PopID();
ImGuiSameLine(0);

ImGui::PushID("Right");
refreshTextures |= drawPedalImageSettings(_state.pedals.texSides[1], sideSize, _state.pedals.mirror, _state.pedals.sideImagePaths, 1, _state.pedals.rightColor);
refreshTextures |= drawPedalImageSettings(_state.pedals.texSides[1], sideSize, true, _state.pedals.mirror, _state.pedals.sideImagePaths, 1, _state.pedals.rightColor);
ImGui::PopID();

ImGui::Separator();

{
ImGuiPushItemWidth(100);
if(ImGui::SliderFloat("##OffsetX", &_state.pedals.margin[0], -0.5f, 0.5f, "Horiz.: %.2f")){
_state.pedals.margin[0] = glm::clamp(_state.pedals.margin[0], -0.5f, 0.5f);
}
ImGuiSameLine();
if(ImGui::SliderFloat("##OffsetY", &_state.pedals.margin[1], -0.5f, 0.5f, "Vert.: %.2f")){
_state.pedals.margin[1] = glm::clamp(_state.pedals.margin[1], -0.5f, 0.5f);
}
ImGui::PopItemWidth();
ImGuiSameLine();
ImGui::AlignTextToFramePadding();
ImGui::Text("Offsets");

ImGui::Checkbox("Mirror right pedal", &_state.pedals.mirror);
}

// Actions
if(!_showPedalsEditor){
// If we are exiting, refresh the existing set.
Expand Down
2 changes: 1 addition & 1 deletion src/rendering/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class Renderer {

void showParticlesEditor();

bool drawPedalImageSettings(GLuint tex, const glm::vec2& size, bool flipUV, PathCollection& path, unsigned int index, glm::vec3& color);
bool drawPedalImageSettings(GLuint tex, const glm::vec2& size, bool labelsAfter, bool flipUV, PathCollection& path, unsigned int index, glm::vec3& color);

void refreshPedalTextures(State::PedalsState& pedals);

Expand Down
3 changes: 1 addition & 2 deletions src/rendering/scene/MIDIScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,7 @@ void MIDIScene::drawPedals(float time, const glm::vec2 & invScreenSize, const St
// Adjust for aspect ratio.
const float rat = invScreenSize.y/invScreenSize.x;
const glm::vec2 ratioScale = (rat < 1.0f) ? glm::vec2(1.0f, rat) : glm::vec2(1.0f/rat, 1.0f);
const glm::vec2 globalScale = 2.0f * state.size * ratioScale; // quad is [-0.5,0.5]

const glm::vec2 globalScale = 2.0f /* quad is -0.5,0.5 */ * state.size * ratioScale * glm::vec2(1.2f, 1.0f) /* existing pedal ratio correction */;
const State::PedalsState::Location mode = state.location;
const float vertSign = (mode == State::PedalsState::TOPLEFT || mode == State::PedalsState::TOPRIGHT) ? 1.0f : -1.0f;
const float horizSign = (mode == State::PedalsState::TOPLEFT || mode == State::PedalsState::BOTTOMLEFT) ? -1.0f : 1.0f;
Expand Down

0 comments on commit 87fd7d9

Please sign in to comment.