aboutsummaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2025-03-18 19:13:16 +0100
committerdec05eba <dec05eba@protonmail.com>2025-03-18 19:13:16 +0100
commitdc70bd27f217413bbda33b4092a3a52a6f1905d5 (patch)
tree15b8316a8f5ec0bfa01d92451ac2d56174b0a763 /src/gui
parent44e7f57d21680de28a5ccd7b6556697666061fe7 (diff)
Add controller button icons in hotkeys, separate keyboard hotkeys and controller hotkeys
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/GlobalSettingsPage.cpp39
-rw-r--r--src/gui/Image.cpp39
-rw-r--r--src/gui/Utils.cpp7
3 files changed, 76 insertions, 9 deletions
diff --git a/src/gui/GlobalSettingsPage.cpp b/src/gui/GlobalSettingsPage.cpp
index 44c5a1c..3574d57 100644
--- a/src/gui/GlobalSettingsPage.cpp
+++ b/src/gui/GlobalSettingsPage.cpp
@@ -10,6 +10,7 @@
#include "../../include/gui/Subsection.hpp"
#include "../../include/gui/List.hpp"
#include "../../include/gui/Label.hpp"
+#include "../../include/gui/Image.hpp"
#include "../../include/gui/RadioButton.hpp"
#include "../../include/gui/LineSeparator.hpp"
#include "../../include/gui/CustomRendererWidget.hpp"
@@ -325,29 +326,48 @@ namespace gsr {
return list;
}
- std::unique_ptr<Subsection> GlobalSettingsPage::create_hotkey_subsection(ScrollablePage *parent_page) {
+ static std::unique_ptr<List> create_joystick_hotkey_text(mgl::Texture *image1, mgl::Texture *image2, float max_height, const char *suffix) {
+ auto list = std::make_unique<List>(List::Orientation::HORIZONTAL, List::Alignment::CENTER);
+ list->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press", get_color_theme().text_color));
+ list->add_widget(std::make_unique<Image>(image1, mgl::vec2f{max_height, 1000.0f}, Image::ScaleBehavior::SCALE));
+ list->add_widget(std::make_unique<Label>(&get_theme().body_font, "and", get_color_theme().text_color));
+ list->add_widget(std::make_unique<Image>(image2, mgl::vec2f{max_height, 1000.0f}, Image::ScaleBehavior::SCALE));
+ list->add_widget(std::make_unique<Label>(&get_theme().body_font, suffix, get_color_theme().text_color));
+ return list;
+ }
+
+ std::unique_ptr<Subsection> GlobalSettingsPage::create_keyboard_hotkey_subsection(ScrollablePage *parent_page) {
auto list = std::make_unique<List>(List::Orientation::VERTICAL);
List *list_ptr = list.get();
- auto subsection = std::make_unique<Subsection>("Hotkeys", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
+ auto subsection = std::make_unique<Subsection>("Keyboard hotkeys", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Enable keyboard hotkeys?", get_color_theme().text_color));
list_ptr->add_widget(create_enable_keyboard_hotkeys_button());
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Enable controller hotkeys?", get_color_theme().text_color));
- list_ptr->add_widget(create_enable_joystick_hotkeys_button());
list_ptr->add_widget(std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, subsection->get_inner_size().x));
list_ptr->add_widget(create_show_hide_hotkey_options());
list_ptr->add_widget(create_replay_hotkey_options());
list_ptr->add_widget(create_record_hotkey_options());
list_ptr->add_widget(create_stream_hotkey_options());
list_ptr->add_widget(create_screenshot_hotkey_options());
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad up to take a screenshot", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad down to save a replay", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad left to start/stop recording", get_color_theme().text_color));
- list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Press the PlayStation button and d-pad right to start/stop replay", get_color_theme().text_color));
list_ptr->add_widget(create_hotkey_control_buttons());
return subsection;
}
+ std::unique_ptr<Subsection> GlobalSettingsPage::create_controller_hotkey_subsection(ScrollablePage *parent_page) {
+ auto list = std::make_unique<List>(List::Orientation::VERTICAL);
+ List *list_ptr = list.get();
+ auto subsection = std::make_unique<Subsection>("Controller hotkeys", std::move(list), mgl::vec2f(parent_page->get_inner_size().x, 0.0f));
+
+ list_ptr->add_widget(std::make_unique<Label>(&get_theme().body_font, "Enable controller hotkeys?", get_color_theme().text_color));
+ list_ptr->add_widget(create_enable_joystick_hotkeys_button());
+ list_ptr->add_widget(std::make_unique<LineSeparator>(LineSeparator::Orientation::HORIZONTAL, subsection->get_inner_size().x));
+ list_ptr->add_widget(create_joystick_hotkey_text(&get_theme().ps4_home_texture, &get_theme().ps4_dpad_up_texture, get_theme().body_font.get_character_size(), "to take a screenshot"));
+ list_ptr->add_widget(create_joystick_hotkey_text(&get_theme().ps4_home_texture, &get_theme().ps4_dpad_down_texture, get_theme().body_font.get_character_size(), "to save a replay"));
+ list_ptr->add_widget(create_joystick_hotkey_text(&get_theme().ps4_home_texture, &get_theme().ps4_dpad_left_texture, get_theme().body_font.get_character_size(), "to start/stop recording"));
+ list_ptr->add_widget(create_joystick_hotkey_text(&get_theme().ps4_home_texture, &get_theme().ps4_dpad_right_texture, get_theme().body_font.get_character_size(), "to turn replay on/off"));
+ return subsection;
+ }
+
std::unique_ptr<Button> GlobalSettingsPage::create_exit_program_button() {
auto exit_program_button = std::make_unique<Button>(&get_theme().body_font, "Exit program", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
exit_program_button->on_click = [&]() {
@@ -405,7 +425,8 @@ namespace gsr {
settings_list->set_spacing(0.018f);
settings_list->add_widget(create_appearance_subsection(scrollable_page.get()));
settings_list->add_widget(create_startup_subsection(scrollable_page.get()));
- settings_list->add_widget(create_hotkey_subsection(scrollable_page.get()));
+ settings_list->add_widget(create_keyboard_hotkey_subsection(scrollable_page.get()));
+ settings_list->add_widget(create_controller_hotkey_subsection(scrollable_page.get()));
settings_list->add_widget(create_application_options_subsection(scrollable_page.get()));
settings_list->add_widget(create_application_info_subsection(scrollable_page.get()));
scrollable_page->add_widget(std::move(settings_list));
diff --git a/src/gui/Image.cpp b/src/gui/Image.cpp
new file mode 100644
index 0000000..b6cec9a
--- /dev/null
+++ b/src/gui/Image.cpp
@@ -0,0 +1,39 @@
+#include "../../include/gui/Image.hpp"
+#include "../../include/gui/Utils.hpp"
+
+#include <mglpp/window/Window.hpp>
+#include <mglpp/graphics/Texture.hpp>
+
+namespace gsr {
+ Image::Image(mgl::Texture *texture, mgl::vec2f size, ScaleBehavior scale_behavior) :
+ sprite(texture), size(size), scale_behavior(scale_behavior)
+ {
+
+ }
+
+ bool Image::on_event(mgl::Event&, mgl::Window&, mgl::vec2f) {
+ return true;
+ }
+
+ void Image::draw(mgl::Window &window, mgl::vec2f offset) {
+ if(!visible)
+ return;
+
+ sprite.set_size(get_size());
+ sprite.set_position((position + offset).floor());
+ window.draw(sprite);
+ }
+
+ mgl::vec2f Image::get_size() {
+ if(!visible || !sprite.get_texture())
+ return {0.0f, 0.0f};
+
+ const mgl::vec2f sprite_size = sprite.get_texture()->get_size().to_vec2f();
+ if(size.x < 0.001f && size.y < 0.001f)
+ return sprite_size;
+ else if(scale_behavior == ScaleBehavior::SCALE)
+ return scale_keep_aspect_ratio(sprite_size, size);
+ else
+ return clamp_keep_aspect_ratio(sprite_size, size);
+ }
+} \ No newline at end of file
diff --git a/src/gui/Utils.cpp b/src/gui/Utils.cpp
index d1643f2..8f77f17 100644
--- a/src/gui/Utils.cpp
+++ b/src/gui/Utils.cpp
@@ -67,4 +67,11 @@ namespace gsr {
return from;
}
+
+ mgl::vec2f clamp_keep_aspect_ratio(mgl::vec2f from, mgl::vec2f to) {
+ if(from.x > to.x || from.y > to.y)
+ return scale_keep_aspect_ratio(from, to);
+ else
+ return from;
+ }
} \ No newline at end of file