aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-01 20:55:16 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-01 20:55:16 +0200
commit67216467d4dc43134a07f7f843a80a1adf688acd (patch)
treebdbdda36c45a01c10e6ebcb8af37d3231bb90a2f
parent27255cdb64b87c048fad70ca893f684cf61819a4 (diff)
Move to settings page on settings button pressed
-rw-r--r--include/gui/Widget.hpp3
-rw-r--r--src/gui/ComboBox.cpp1
-rw-r--r--src/gui/Page.cpp8
-rw-r--r--src/main.cpp35
4 files changed, 36 insertions, 11 deletions
diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp
index 63cb64a..6324490 100644
--- a/include/gui/Widget.hpp
+++ b/include/gui/Widget.hpp
@@ -9,7 +9,7 @@ namespace mgl {
namespace gsr {
class Widget {
- friend class WidgetContainer;
+ friend class Page;
public:
Widget();
Widget(const Widget&) = delete;
@@ -24,5 +24,6 @@ namespace gsr {
virtual mgl::vec2f get_position() const;
protected:
mgl::vec2f position;
+ bool move_to_top = false;
};
} \ No newline at end of file
diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp
index 2766797..dd683e1 100644
--- a/src/gui/ComboBox.cpp
+++ b/src/gui/ComboBox.cpp
@@ -40,6 +40,7 @@ namespace gsr {
if(mgl::FloatRect(position, item_size).contains(mouse_pos)) {
show_dropdown = !show_dropdown;
+ move_to_top = true;
} else {
show_dropdown = false;
}
diff --git a/src/gui/Page.cpp b/src/gui/Page.cpp
index 817c7fd..813c2bd 100644
--- a/src/gui/Page.cpp
+++ b/src/gui/Page.cpp
@@ -16,6 +16,14 @@ namespace gsr {
void Page::draw(mgl::Window &window) {
for(auto &widget : widgets) {
+ if(widget->move_to_top) {
+ widget->move_to_top = false;
+ std::swap(widget, widgets.back());
+ }
+ widget->draw(window);
+ }
+
+ for(auto &widget : widgets) {
widget->draw(window);
}
}
diff --git a/src/main.cpp b/src/main.cpp
index 0e7721e..dd607ea 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -236,6 +236,9 @@ int main(int argc, char **argv) {
bg_screenshot_overlay.set_color(bg_color);
gsr::Page front_page;
+ gsr::Page replay_settings_page;
+
+ gsr::Page *current_page = &front_page;
struct MainButton {
gsr::DropdownButton* button;
@@ -317,6 +320,9 @@ int main(int argc, char **argv) {
// Replay
main_buttons[0].button->on_click = [&](const std::string &id) {
+ if(id == "settings") {
+ current_page = &replay_settings_page;
+ }
/*
char window_to_record_str[32];
snprintf(window_to_record_str, sizeof(window_to_record_str), "%ld", target_window);
@@ -413,13 +419,22 @@ int main(int argc, char **argv) {
//top_bar_text.set_color(gsr::get_theme().tint_color);
top_bar_text.set_position((top_bar_background.get_position() + top_bar_background.get_size()*0.5f - top_bar_text.get_bounds().size*0.5f).floor());
- // gsr::ComboBox record_area_box(&title_font);
- // record_area_box.set_position(mgl::vec2f(300.0f, 300.0f));
- // record_area_box.add_item("Window", "window");
- // record_area_box.add_item("Focused window", "focused");
- // record_area_box.add_item("All monitors (NvFBC)", "all");
- // record_area_box.add_item("All monitors, direct mode (NvFBC, VRR workaround)", "all-direct");
- // record_area_box.add_item("Monitor DP-0 (3840x2160, NvFBC)", "DP-0");
+ auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font);
+ record_area_box->set_position(mgl::vec2f(300.0f, 300.0f));
+ if(gsr_info.supported_capture_options.window)
+ record_area_box->add_item("Window", "window");
+ if(gsr_info.supported_capture_options.focused)
+ record_area_box->add_item("Focused window", "focused");
+ if(gsr_info.supported_capture_options.screen)
+ record_area_box->add_item("All monitors", "screen");
+ for(const auto &monitor : gsr_info.supported_capture_options.monitors) {
+ char name[256];
+ snprintf(name, sizeof(name), "%s (%dx%d)", monitor.name.c_str(), monitor.size.x, monitor.size.y);
+ record_area_box->add_item(name, monitor.name);
+ }
+ if(gsr_info.supported_capture_options.portal)
+ record_area_box->add_item("Desktop portal", "portal");
+ replay_settings_page.add_widget(std::move(record_area_box));
// mgl::Text record_area_title("Record area", title_font);
// record_area_title.set_position(mgl::vec2f(record_area_box.get_position().x, record_area_box.get_position().y - title_font.get_character_size() - 10.0f));
@@ -491,7 +506,7 @@ int main(int argc, char **argv) {
event.type = mgl::Event::MouseMoved;
event.mouse_move.x = window.get_mouse_position().x;
event.mouse_move.y = window.get_mouse_position().y;
- front_page.on_event(event, window);
+ current_page->on_event(event, window);
auto render = [&] {
window.clear(bg_color);
@@ -505,7 +520,7 @@ int main(int argc, char **argv) {
// window.draw(audio_input_title);
// window.draw(video_quality_title);
// window.draw(framerate_title);
- front_page.draw(window);
+ current_page->draw(window);
window.draw(top_bar_background);
window.draw(top_bar_text);
window.draw(logo_sprite);
@@ -521,7 +536,7 @@ int main(int argc, char **argv) {
}
while(window.poll_event(event)) {
- front_page.on_event(event, window);
+ current_page->on_event(event, window);
if(event.type == mgl::Event::KeyPressed) {
if(event.key.code == mgl::Keyboard::Escape) {
window.set_visible(false);