Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Recent roms and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
OFFTKP committed Jan 14, 2024
1 parent ac79932 commit 7f11267
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 23 deletions.
15 changes: 15 additions & 0 deletions include/imgui_helper.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include <IconsMaterialDesign.h>
#include <imgui/imgui.h>

extern ImFont* big_font;

namespace hydra
{
struct ImGuiHelper
Expand All @@ -18,5 +20,18 @@ namespace hydra
static float text_height = ImGui::CalcTextSize("A").y;
return text_height;
}

static float BigTextHeight()
{
static float text_height = 0;
if (text_height == 0)
{
ImGui::PushFont(big_font);
text_height = ImGui::CalcTextSize("A").y;
ImGui::PopFont();
}

return text_height;
}
};
} // namespace hydra
15 changes: 15 additions & 0 deletions include/mainwindow.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

#include "filepicker.hxx"
#include "gamewindow.hxx"
#include "settings.hxx"
#include <array>
#include <deque>
#include <filesystem>
#include <functional>
#include <imgui/imgui.h>
Expand Down Expand Up @@ -34,7 +36,14 @@ private:
void draw_about();
void draw_settings();
void draw_stars(ImVec2 center, float radius);
void draw_pending_rom_load();
std::tuple<bool, ImVec2, ImVec2> draw_custom_button(const std::string& text,
uint32_t color = 0x40404040,
uint32_t hover_color = 0x80808080);
void update_impl();
void load_rom_impl(const std::filesystem::path& core_path,
const std::filesystem::path& rom_path);
void save_recents();

float selected_y = 0.0f;
int selected_tab = 0;
Expand All @@ -45,6 +54,12 @@ private:
size_t open_core_settings = -1;
std::unordered_map<std::string, std::vector<std::function<void()>>> settings_functions;
std::unique_ptr<GameWindow> game_window;
std::deque<std::filesystem::path> recent_roms;
std::vector<ImVec2> recent_roms_offsets;

bool pending_rom_load = false;
std::filesystem::path pending_rom_path;
std::vector<CoreInfo> pending_available_cores;

FilePicker rom_picker;
};
14 changes: 12 additions & 2 deletions include/settings.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,24 @@ public:
return map()[key];
}

static void Set(const std::string& key, const std::string& value)
static void Save()
{
map()[key] = value;
json j_map(map());
std::string data = j_map.dump(4);
hydra::fwrite(save_path(), std::span<const uint8_t>((uint8_t*)data.data(), data.size()));
}

static void SetNoSave(const std::string& key, const std::string& value)
{
map()[key] = value;
}

static void Set(const std::string& key, const std::string& value)
{
SetNoSave(key, value);
Save();
}

static bool IsEmpty()
{
return map().empty();
Expand Down
18 changes: 9 additions & 9 deletions src/gamewindow.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,18 @@ GameWindow::GameWindow(const std::string& core_path, const std::string& game_pat
GameWindow::instance = this;
emulator = hydra::EmulatorFactory::Create(core_path);
texture_size = emulator->shell->getNativeSize();
pixel_format = emulator->shell->asISoftwareRendered()->getPixelFormat();
gl_format = get_gl_format(pixel_format);

if (emulator->shell->hasInterface(hydra::InterfaceType::ISoftwareRendered))
{
pixel_format = emulator->shell->asISoftwareRendered()->getPixelFormat();
gl_format = get_gl_format(pixel_format);
hydra::ISoftwareRendered* shell_sw = emulator->shell->asISoftwareRendered();
shell_sw->setVideoCallback(video_callback);
}

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_size.width, texture_size.height, 0, GL_RGBA,
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texture_size.width, texture_size.height, 0, gl_format,
GL_UNSIGNED_BYTE, nullptr);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
Expand All @@ -50,12 +56,6 @@ GameWindow::GameWindow(const std::string& core_path, const std::string& game_pat
printf("Framebuffer error: %d\n", status);
}

if (emulator->shell->hasInterface(hydra::InterfaceType::ISoftwareRendered))
{
hydra::ISoftwareRendered* shell_sw = emulator->shell->asISoftwareRendered();
shell_sw->setVideoCallback(video_callback);
}

loaded = emulator->LoadGame(game_path);
}

Expand Down
Loading

0 comments on commit 7f11267

Please sign in to comment.