mirror of
https://github.com/joel16/NX-Shell.git
synced 2024-11-23 11:49:46 +00:00
textures: Add support for zooming into images using left stick and movement with right
This commit is contained in:
parent
ffb5e812a7
commit
cf0567a020
@ -31,6 +31,7 @@ typedef struct {
|
||||
s64 total_storage = 0;
|
||||
std::vector<Tex> textures;
|
||||
long unsigned int frame_count = 0;
|
||||
float zoom_factor = 1.0f;
|
||||
} MenuItem;
|
||||
|
||||
typedef struct {
|
||||
|
@ -9019,7 +9019,7 @@ static void ImGui::NavUpdate()
|
||||
// *Normal* Manual scroll with NavScrollXXX keys
|
||||
// Next movement request will clamp the NavId reference rectangle to the visible area, so navigation will resume within those bounds.
|
||||
ImVec2 scroll_dir = GetNavInputAmount2d(ImGuiNavDirSourceFlags_PadLStick, ImGuiInputReadMode_Down, 1.0f / 10.0f, 10.0f);
|
||||
if (scroll_dir.x != 0.0f && window->ScrollbarX)
|
||||
if (scroll_dir.x != 0.0f /*&& window->ScrollbarX*/)
|
||||
SetScrollX(window, ImFloor(window->Scroll.x + scroll_dir.x * scroll_speed));
|
||||
if (scroll_dir.y != 0.0f)
|
||||
SetScrollY(window, ImFloor(window->Scroll.y + scroll_dir.y * scroll_speed));
|
||||
|
@ -330,10 +330,10 @@ static void ImGui_ImplSDL2_UpdateGamepads()
|
||||
MAP_BUTTON(ImGuiNavInput_FocusNext, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakSlow, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); // L1 / LB
|
||||
MAP_BUTTON(ImGuiNavInput_TweakFast, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); // R1 / RB
|
||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_LEFTX, -thumb_dead_zone, -32768);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_LEFTX, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_LEFTY, -thumb_dead_zone, -32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_LEFTY, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickLeft, SDL_CONTROLLER_AXIS_RIGHTX, -thumb_dead_zone, -32768);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickRight, SDL_CONTROLLER_AXIS_RIGHTX, +thumb_dead_zone, +32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickUp, SDL_CONTROLLER_AXIS_RIGHTY, -thumb_dead_zone, -32767);
|
||||
MAP_ANALOG(ImGuiNavInput_LStickDown, SDL_CONTROLLER_AXIS_RIGHTY, +thumb_dead_zone, +32767);
|
||||
|
||||
io.BackendFlags |= ImGuiBackendFlags_HasGamepad;
|
||||
#undef MAP_BUTTON
|
||||
|
@ -57,6 +57,7 @@ namespace GUI {
|
||||
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||
if (event.type == SDL_JOYBUTTONDOWN) {
|
||||
Uint8 button = event.jbutton.button;
|
||||
|
||||
if (button == SDL_KEY_A) {
|
||||
if (item.state == MENU_STATE_FILEBROWSER) {
|
||||
if (item.entries[item.selected].type == FsDirEntryType_Dir) {
|
||||
@ -95,6 +96,7 @@ namespace GUI {
|
||||
|
||||
item.textures.clear();
|
||||
item.frame_count = 0;
|
||||
item.zoom_factor = 1.0f;
|
||||
item.state = MENU_STATE_FILEBROWSER;
|
||||
}
|
||||
}
|
||||
@ -140,6 +142,23 @@ namespace GUI {
|
||||
item.state = MENU_STATE_SETTINGS;
|
||||
else if (button == SDL_KEY_PLUS)
|
||||
done = true;
|
||||
// TODO fix this so that it's continous or just scrap SDL events
|
||||
else if (button == SDL_KEY_LSTICK_DOWN) {
|
||||
if (item.state == MENU_STATE_IMAGEVIEWER) {
|
||||
item.zoom_factor -= 0.5f * ImGui::GetIO().DeltaTime;
|
||||
|
||||
if (item.zoom_factor < 0.1f)
|
||||
item.zoom_factor = 0.1f;
|
||||
}
|
||||
}
|
||||
else if (button == SDL_KEY_LSTICK_UP) {
|
||||
if (item.state == MENU_STATE_IMAGEVIEWER) {
|
||||
item.zoom_factor += 0.5f * ImGui::GetIO().DeltaTime;
|
||||
|
||||
if (item.zoom_factor > 5.0f)
|
||||
item.zoom_factor = 5.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (event.type == SDL_QUIT)
|
||||
|
@ -14,12 +14,13 @@ namespace Windows {
|
||||
ImGuiWindowFlags_ filename_flag = !cfg.image_filename? ImGuiWindowFlags_NoTitleBar : ImGuiWindowFlags_None;
|
||||
|
||||
if (ImGui::Begin(item.entries[item.selected].name, nullptr, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse | filename_flag)) {
|
||||
if ((item.textures[0].width <= 1280) && (item.textures[0].height <= 720))
|
||||
ImGui::SetCursorPos((ImGui::GetWindowSize() - ImVec2(item.textures[0].width, item.textures[0].height)) * 0.5f);
|
||||
if (((item.textures[0].width * item.zoom_factor) <= 1280) && ((item.textures[0].height * item.zoom_factor) <= 720))
|
||||
ImGui::SetCursorPos((ImGui::GetWindowSize() - ImVec2((item.textures[0].width * item.zoom_factor), (item.textures[0].height * item.zoom_factor))) * 0.5f);
|
||||
|
||||
if (item.textures.size() > 1) {
|
||||
svcSleepThread(item.textures[item.frame_count].delay * 10000000);
|
||||
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
|
||||
@ -27,7 +28,7 @@ namespace Windows {
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user