diff --git a/include/gui.h b/include/gui.h index 81c4623..bf4a318 100644 --- a/include/gui.h +++ b/include/gui.h @@ -15,6 +15,7 @@ typedef struct { std::vector entries; std::vector textures; int frame_count = 0; + float zoom_factor = 1.0f; } MenuItem; namespace GUI { diff --git a/include/utils.h b/include/utils.h index 1ecb27a..fbc7684 100644 --- a/include/utils.h +++ b/include/utils.h @@ -15,7 +15,7 @@ extern unsigned int pressed; namespace Utils { int InitAppUtil(void); int EndAppUtil(void); - void ReadControls(void); + SceCtrlData ReadControls(void); int GetEnterButton(void); int GetCancelButton(void); void GetSizeString(char *string, double size); diff --git a/source/gui.cpp b/source/gui.cpp index e766ec2..1a38089 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -87,6 +87,7 @@ namespace GUI { ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f); MenuItem item; + SceCtrlData pad = { 0 }; int ret = 0; if (R_FAILED(ret = FS::GetDirList(config.cwd, item.entries))) @@ -114,7 +115,7 @@ namespace GUI { } Renderer::End(clear_color); - Utils::ReadControls(); + pad = Utils::ReadControls(); switch (item.state) { case GUI_STATE_HOME: @@ -130,10 +131,24 @@ namespace GUI { case GUI_STATE_IMAGE_PREVIEW: if (pressed & SCE_CTRL_TRIANGLE) properties = !properties; - + + if (pad.ly > 170) { + item.zoom_factor -= 0.5f * ImGui::GetIO().DeltaTime; + + if (item.zoom_factor < 0.1f) + item.zoom_factor = 0.1f; + } + else if (pad.ly < 70) { + item.zoom_factor += 0.5f * ImGui::GetIO().DeltaTime; + + if (item.zoom_factor > 5.0f) + item.zoom_factor = 5.0f; + } + if (!properties) { if (pressed & SCE_CTRL_CANCEL) { GUI::ClearTextures(&item); + item.zoom_factor = 1.0f; item.state = GUI_STATE_HOME; } diff --git a/source/utils.cpp b/source/utils.cpp index 7459a27..a31146f 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -58,11 +58,12 @@ namespace Utils { return 0; } - void ReadControls(void) { + SceCtrlData ReadControls(void) { std::memset(&pad, 0, sizeof(SceCtrlData)); sceCtrlPeekBufferPositive(0, &pad, 1); pressed = pad.buttons & ~old_pad.buttons; old_pad = pad; + return pad; } int GetEnterButton(void) { diff --git a/source/windows/image.cpp b/source/windows/image.cpp index fcdaf34..2adf0c2 100644 --- a/source/windows/image.cpp +++ b/source/windows/image.cpp @@ -12,12 +12,16 @@ namespace Windows { ImGuiWindowFlags_ filename_flag = !config.image_filename? ImGuiWindowFlags_NoTitleBar : ImGuiWindowFlags_None; if (ImGui::Begin(item->entries[item->selected].d_name, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | filename_flag)) { - if ((item->textures[0].width <= 960) && (item->textures[0].height <= 544)) - ImGui::SetCursorPos((ImGui::GetWindowSize() - ImVec2(item->textures[0].width, item->textures[0].height)) * 0.5f); + if (((item->textures[0].width * item->zoom_factor) <= 960.0f) && ((item->textures[0].height * item->zoom_factor) <= 544.0f)) + ImGui::SetCursorPos((ImGui::GetContentRegionAvail() - ImVec2((item->textures[item->frame_count].width * item->zoom_factor), + (item->textures[item->frame_count].height * item->zoom_factor))) * 0.5f); if (item->textures.size() > 1) { sceKernelDelayThread(item->textures[item->frame_count].delay * 10000); - ImGui::Image(reinterpret_cast(item->textures[item->frame_count].id), ImVec2(item->textures[item->frame_count].width, item->textures[item->frame_count].height)); + + ImGui::Image(reinterpret_cast(item->textures[item->frame_count].id), ImVec2(item->textures[item->frame_count].width * item->zoom_factor, + item->textures[item->frame_count].height * item->zoom_factor)); + item->frame_count++; // Reset frame counter @@ -25,7 +29,7 @@ namespace Windows { item->frame_count = 0; } else - ImGui::Image(reinterpret_cast(item->textures[0].id), ImVec2(item->textures[0].width, item->textures[0].height)); + ImGui::Image(reinterpret_cast(item->textures[0].id), ImVec2(item->textures[0].width * item->zoom_factor, item->textures[0].height * item->zoom_factor)); } Windows::ExitWindow();