add ability to view images
This commit is contained in:
@@ -52,6 +52,7 @@ add_executable(ezremote_client
|
||||
source/main.cpp
|
||||
source/orbis_jbc.c
|
||||
source/system.cpp
|
||||
source/textures.cpp
|
||||
source/windows.cpp
|
||||
source/zip_util.cpp
|
||||
)
|
||||
@@ -64,9 +65,12 @@ target_link_libraries(ezremote_client
|
||||
c
|
||||
c++
|
||||
png
|
||||
webp
|
||||
jpeg
|
||||
z
|
||||
pthread
|
||||
SDL2
|
||||
SDL2_image
|
||||
samplerate
|
||||
jbc
|
||||
crypto
|
||||
|
||||
@@ -141,3 +141,4 @@ STR_PASTE_LINE=Paste into selected line
|
||||
STR_SHOW_HIDDEN_FILES=Show hidden files
|
||||
STR_SET_DEFAULT_DIRECTORY=Set Default Folder
|
||||
STR_SET_DEFAULT_DIRECTORY_MSG=has being set as default direcotry
|
||||
STR_VIEW_IMAGE=View Image
|
||||
|
||||
+2
-1
@@ -52,7 +52,8 @@ enum ACTIONS
|
||||
ACTION_NEW_LOCAL_FILE,
|
||||
ACTION_NEW_REMOTE_FILE,
|
||||
ACTION_SET_DEFAULT_LOCAL_FOLDER,
|
||||
ACTION_SET_DEFAULT_REMOTE_FOLDER
|
||||
ACTION_SET_DEFAULT_REMOTE_FOLDER,
|
||||
ACTION_VIEW_IMAGE
|
||||
};
|
||||
|
||||
enum OverWriteType
|
||||
|
||||
@@ -155,6 +155,7 @@ char lang_strings[LANG_STRINGS_NUM][LANG_STR_SIZE] = {
|
||||
"Show hidden files", // STR_SHOW_HIDDEN_FILES
|
||||
"Set Default Folder", // STR_SET_DEFAULT_DIRECTORY
|
||||
"has being set as default direcotry", // STR_SET_DEFAULT_DIRECTORY_MSG
|
||||
"View Image", // STR_VIEW_IMAGE
|
||||
};
|
||||
|
||||
bool needs_extended_font = false;
|
||||
|
||||
+3
-2
@@ -146,7 +146,8 @@
|
||||
FUNC(STR_PASTE_LINE) \
|
||||
FUNC(STR_SHOW_HIDDEN_FILES) \
|
||||
FUNC(STR_SET_DEFAULT_DIRECTORY) \
|
||||
FUNC(STR_SET_DEFAULT_DIRECTORY_MSG)
|
||||
FUNC(STR_SET_DEFAULT_DIRECTORY_MSG) \
|
||||
FUNC(STR_VIEW_IMAGE)
|
||||
|
||||
#define GET_VALUE(x) x,
|
||||
#define GET_STRING(x) #x,
|
||||
@@ -156,7 +157,7 @@ enum
|
||||
FOREACH_STR(GET_VALUE)
|
||||
};
|
||||
|
||||
#define LANG_STRINGS_NUM 143
|
||||
#define LANG_STRINGS_NUM 144
|
||||
#define LANG_ID_SIZE 64
|
||||
#define LANG_STR_SIZE 384
|
||||
extern char lang_identifiers[LANG_STRINGS_NUM][LANG_ID_SIZE];
|
||||
|
||||
+5
-1
@@ -11,7 +11,7 @@
|
||||
#include <orbis/Pad.h>
|
||||
#include <orbis/AudioOut.h>
|
||||
#include <orbis/Net.h>
|
||||
// #include <dbglogger.h>
|
||||
#include <dbglogger.h>
|
||||
|
||||
#include "imgui.h"
|
||||
#include "SDL2/SDL.h"
|
||||
@@ -25,6 +25,8 @@
|
||||
#include "util.h"
|
||||
#include "installer.h"
|
||||
#include "system.h"
|
||||
#include "textures.h"
|
||||
// #include "dbglogger.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -308,6 +310,7 @@ int main()
|
||||
if (renderer == NULL)
|
||||
return 0;
|
||||
|
||||
Textures::Init(renderer);
|
||||
InitImgui();
|
||||
|
||||
// Setup Platform/Renderer backends
|
||||
@@ -328,6 +331,7 @@ int main()
|
||||
GUI::RenderLoop(renderer);
|
||||
SDL_DestroyRenderer(renderer);
|
||||
SDL_DestroyWindow(window);
|
||||
Textures::Exit();
|
||||
|
||||
ImGui::DestroyContext();
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "textures.h"
|
||||
|
||||
static SDL_Renderer *renderer;
|
||||
|
||||
namespace Textures {
|
||||
|
||||
bool LoadImageFile(const std::string filename, Tex *texture)
|
||||
{
|
||||
// Load from file
|
||||
SDL_Surface *image = IMG_Load(filename.c_str());
|
||||
if (image == nullptr)
|
||||
return false;
|
||||
image = SDL_ConvertSurfaceFormat(image, SDL_PIXELFORMAT_RGBA8888, 0);
|
||||
SDL_Texture *sdl_texture = SDL_CreateTextureFromSurface(renderer, image);
|
||||
if (sdl_texture == nullptr)
|
||||
{
|
||||
SDL_FreeSurface(image);
|
||||
return false;
|
||||
}
|
||||
texture->id = sdl_texture;
|
||||
texture->height = image->h;
|
||||
texture->width = image->w;
|
||||
SDL_FreeSurface(image);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Init(SDL_Renderer *p_renderer) {
|
||||
renderer = p_renderer;
|
||||
IMG_Init(IMG_INIT_JPG | IMG_INIT_PNG | IMG_INIT_WEBP);
|
||||
}
|
||||
|
||||
void Exit(void) {
|
||||
IMG_Quit();
|
||||
}
|
||||
|
||||
void Free(Tex *texture) {
|
||||
if (texture->id != nullptr)
|
||||
{
|
||||
SDL_DestroyTexture(texture->id);
|
||||
texture->id = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef LAUNCHER_TEXTURES_H
|
||||
#define LAUNCHER_TEXTURES_H
|
||||
|
||||
#include <string>
|
||||
#include <SDL2/SDL.h>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
typedef struct {
|
||||
SDL_Texture *id;
|
||||
int width;
|
||||
int height;
|
||||
} Tex;
|
||||
|
||||
namespace Textures {
|
||||
bool LoadImageFile(const std::string filename, Tex *texture);
|
||||
void Init(SDL_Renderer *renderer);
|
||||
void Exit(void);
|
||||
void Free(Tex *texture);
|
||||
}
|
||||
|
||||
#endif
|
||||
+85
-3
@@ -3,6 +3,8 @@
|
||||
#include <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <set>
|
||||
#include "clients/gdrive.h"
|
||||
#include "server/http_server.h"
|
||||
#include "imgui.h"
|
||||
#include "windows.h"
|
||||
#include "fs.h"
|
||||
@@ -14,8 +16,10 @@
|
||||
#include "ime_dialog.h"
|
||||
#include "IconsFontAwesome6.h"
|
||||
#include "OpenFontIcons.h"
|
||||
#include "server/http_server.h"
|
||||
#include "clients/gdrive.h"
|
||||
#include "textures.h"
|
||||
|
||||
#define MAX_IMAGE_HEIGHT 980
|
||||
#define MAX_IMAGE_WIDTH 1820
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@@ -80,6 +84,10 @@ char edit_file[256];
|
||||
int edit_line_to_select = -1;
|
||||
std::string copy_text;
|
||||
|
||||
// Images varaibles
|
||||
bool view_image;
|
||||
Tex texture;
|
||||
|
||||
// Overwrite dialog variables
|
||||
bool dont_prompt_overwrite = false;
|
||||
bool dont_prompt_overwrite_cb = false;
|
||||
@@ -567,11 +575,25 @@ namespace Windows
|
||||
}
|
||||
if (ImGui::Selectable(item.name, false, ImGuiSelectableFlags_SpanAllColumns, ImVec2(919, 0)))
|
||||
{
|
||||
selected_local_file = item;
|
||||
if (item.isDir)
|
||||
{
|
||||
selected_local_file = item;
|
||||
selected_action = ACTION_CHANGE_LOCAL_DIRECTORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string filename = Util::ToLower(selected_local_file.name);
|
||||
size_t dot_pos = filename.find_last_of(".");
|
||||
if (dot_pos != std::string::npos)
|
||||
{
|
||||
std::string ext = filename.substr(dot_pos);
|
||||
if (ext.compare(".bmp") == 0 || ext.compare(".jpg") == 0 || ext.compare(".png") == 0 ||
|
||||
ext.compare(".jpeg") == 0 || ext.compare(".webp") == 0)
|
||||
{
|
||||
selected_action = ACTION_VIEW_IMAGE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
if (ImGui::IsItemFocused())
|
||||
@@ -1659,6 +1681,58 @@ namespace Windows
|
||||
}
|
||||
}
|
||||
|
||||
void ShowImageDialog()
|
||||
{
|
||||
if (view_image)
|
||||
{
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
(void)io;
|
||||
ImGuiStyle *style = &ImGui::GetStyle();
|
||||
ImVec4 *colors = style->Colors;
|
||||
|
||||
ImVec2 image_size;
|
||||
ImVec2 image_pos;
|
||||
ImVec2 view_size;
|
||||
image_size.x = texture.width;
|
||||
image_size.y = texture.height;
|
||||
if (texture.width > MAX_IMAGE_WIDTH || texture.height > MAX_IMAGE_HEIGHT)
|
||||
{
|
||||
if (texture.width > texture.height)
|
||||
{
|
||||
image_size.x = MAX_IMAGE_WIDTH;
|
||||
image_size.y = (texture.height * 1.0f / texture.width * 1.0f) * MAX_IMAGE_WIDTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
image_size.y = MAX_IMAGE_HEIGHT;
|
||||
image_size.x = (texture.width * 1.0f / texture.height * 1.0f) * MAX_IMAGE_HEIGHT;
|
||||
}
|
||||
}
|
||||
view_size.x = image_size.x + 50;
|
||||
view_size.y = image_size.y + 50;
|
||||
image_pos.x = (1920 - view_size.x) / 2;
|
||||
image_pos.y = (1080 - view_size.y) / 2;
|
||||
|
||||
SetModalMode(true);
|
||||
ImGui::OpenPopup(lang_strings[STR_VIEW_IMAGE]);
|
||||
|
||||
ImGui::SetNextWindowPos(image_pos);
|
||||
ImGui::SetNextWindowSizeConstraints(image_size, view_size, NULL, NULL);
|
||||
if (ImGui::BeginPopupModal(lang_strings[STR_VIEW_IMAGE], NULL, ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_AlwaysAutoResize))
|
||||
{
|
||||
ImGui::Image(texture.id, image_size);
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_GamepadFaceRight, false))
|
||||
{
|
||||
view_image = false;
|
||||
SetModalMode(false);
|
||||
Textures::Free(&texture);
|
||||
ImGui::CloseCurrentPopup();
|
||||
}
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow()
|
||||
{
|
||||
Windows::SetupWindow();
|
||||
@@ -1678,6 +1752,7 @@ namespace Windows
|
||||
ShowFavoriteUrlsDialog();
|
||||
ShowEditorDialog();
|
||||
ShowSettingsDialog();
|
||||
ShowImageDialog();
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
@@ -1947,6 +2022,13 @@ namespace Windows
|
||||
sprintf(status_message, "\"%s\" %s", remote_directory, lang_strings[STR_SET_DEFAULT_DIRECTORY_MSG]);
|
||||
selected_action = ACTION_NONE;
|
||||
break;
|
||||
case ACTION_VIEW_IMAGE:
|
||||
if (Textures::LoadImageFile(selected_local_file.path, &texture))
|
||||
{
|
||||
view_image = true;
|
||||
}
|
||||
selected_action = ACTION_NONE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user