Skip to content

Commit

Permalink
gui: Use L stick to zoom in/out of image
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel16 committed Dec 31, 2020
1 parent 22d281c commit 51e7c6a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ typedef struct {
std::vector<SceIoDirent> entries;
std::vector<Tex> textures;
int frame_count = 0;
float zoom_factor = 1.0f;
} MenuItem;

namespace GUI {
Expand Down
2 changes: 1 addition & 1 deletion include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down Expand Up @@ -114,7 +115,7 @@ namespace GUI {
}

Renderer::End(clear_color);
Utils::ReadControls();
pad = Utils::ReadControls();

switch (item.state) {
case GUI_STATE_HOME:
Expand All @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion source/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 8 additions & 4 deletions source/windows/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ 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<ImTextureID>(item->textures[item->frame_count].id), ImVec2(item->textures[item->frame_count].width, item->textures[item->frame_count].height));

ImGui::Image(reinterpret_cast<ImTextureID>(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
if (item->frame_count == item->textures.size() - 1)
item->frame_count = 0;
}
else
ImGui::Image(reinterpret_cast<ImTextureID>(item->textures[0].id), ImVec2(item->textures[0].width, item->textures[0].height));
ImGui::Image(reinterpret_cast<ImTextureID>(item->textures[0].id), ImVec2(item->textures[0].width * item->zoom_factor, item->textures[0].height * item->zoom_factor));
}

Windows::ExitWindow();
Expand Down

0 comments on commit 51e7c6a

Please sign in to comment.