mirror of
https://repo.dec05eba.com/gpu-screen-recorder-ui
synced 2026-05-07 07:16:23 +09:00
Change global widget container to page
This commit is contained in:
27
include/gui/Page.hpp
Normal file
27
include/gui/Page.hpp
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace mgl {
|
||||||
|
class Event;
|
||||||
|
class Window;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace gsr {
|
||||||
|
class Widget;
|
||||||
|
|
||||||
|
class Page {
|
||||||
|
public:
|
||||||
|
Page() = default;
|
||||||
|
Page(const Page&) = delete;
|
||||||
|
Page& operator=(const Page&) = delete;
|
||||||
|
|
||||||
|
void add_widget(std::unique_ptr<Widget> widget);
|
||||||
|
|
||||||
|
void on_event(mgl::Event &event, mgl::Window &window);
|
||||||
|
void draw(mgl::Window &window);
|
||||||
|
private:
|
||||||
|
std::vector<std::unique_ptr<Widget>> widgets;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -24,6 +24,5 @@ namespace gsr {
|
|||||||
virtual mgl::vec2f get_position() const;
|
virtual mgl::vec2f get_position() const;
|
||||||
protected:
|
protected:
|
||||||
mgl::vec2f position;
|
mgl::vec2f position;
|
||||||
bool move_to_top = false;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
namespace mgl {
|
|
||||||
class Event;
|
|
||||||
class Window;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace gsr {
|
|
||||||
class Widget;
|
|
||||||
|
|
||||||
class WidgetContainer {
|
|
||||||
public:
|
|
||||||
static WidgetContainer& get_instance();
|
|
||||||
|
|
||||||
void add_widget(Widget *widget);
|
|
||||||
void remove_widget(Widget *widget);
|
|
||||||
|
|
||||||
void on_event(mgl::Event &event, mgl::Window &window);
|
|
||||||
void draw(mgl::Window &window);
|
|
||||||
private:
|
|
||||||
WidgetContainer() = default;
|
|
||||||
WidgetContainer& operator=(const WidgetContainer&) = delete;
|
|
||||||
WidgetContainer(const WidgetContainer&) = delete;
|
|
||||||
private:
|
|
||||||
std::vector<Widget*> widgets;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -40,7 +40,6 @@ namespace gsr {
|
|||||||
|
|
||||||
if(mgl::FloatRect(position, item_size).contains(mouse_pos)) {
|
if(mgl::FloatRect(position, item_size).contains(mouse_pos)) {
|
||||||
show_dropdown = !show_dropdown;
|
show_dropdown = !show_dropdown;
|
||||||
move_to_top = true;
|
|
||||||
} else {
|
} else {
|
||||||
show_dropdown = false;
|
show_dropdown = false;
|
||||||
}
|
}
|
||||||
|
|||||||
22
src/gui/Page.cpp
Normal file
22
src/gui/Page.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "../../include/gui/Page.hpp"
|
||||||
|
#include "../../include/gui/Widget.hpp"
|
||||||
|
|
||||||
|
namespace gsr {
|
||||||
|
void Page::add_widget(std::unique_ptr<Widget> widget) {
|
||||||
|
widgets.push_back(std::move(widget));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Page::on_event(mgl::Event &event, mgl::Window &window) {
|
||||||
|
// Process widgets by visibility (backwards)
|
||||||
|
for(auto it = widgets.rbegin(), end = widgets.rend(); it != end; ++it) {
|
||||||
|
if(!(*it)->on_event(event, window))
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Page::draw(mgl::Window &window) {
|
||||||
|
for(auto &widget : widgets) {
|
||||||
|
widget->draw(window);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
#include "../../include/gui/Widget.hpp"
|
#include "../../include/gui/Widget.hpp"
|
||||||
#include "../../include/gui/WidgetContainer.hpp"
|
|
||||||
|
|
||||||
namespace gsr {
|
namespace gsr {
|
||||||
Widget::Widget() {
|
Widget::Widget() {
|
||||||
WidgetContainer::get_instance().add_widget(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget::~Widget() {
|
Widget::~Widget() {
|
||||||
WidgetContainer::get_instance().remove_widget(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Widget::set_position(mgl::vec2f position) {
|
void Widget::set_position(mgl::vec2f position) {
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
#include "../../include/gui/WidgetContainer.hpp"
|
|
||||||
#include "../../include/gui/Widget.hpp"
|
|
||||||
|
|
||||||
namespace gsr {
|
|
||||||
// static
|
|
||||||
WidgetContainer& WidgetContainer::get_instance() {
|
|
||||||
static WidgetContainer instance;
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetContainer::add_widget(Widget *widget) {
|
|
||||||
// TODO: to_be_added, and remove in the draw loop
|
|
||||||
#ifdef DEBUG
|
|
||||||
for(Widget *existing_widget : widgets) {
|
|
||||||
if(existing_widget == widget)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
widgets.push_back(widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetContainer::remove_widget(Widget *widget) {
|
|
||||||
// TODO: to_be_removed, and remove in draw loop
|
|
||||||
for(auto it = widgets.begin(), end = widgets.end(); it != end; ++it) {
|
|
||||||
if(*it == widget) {
|
|
||||||
widgets.erase(it);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetContainer::on_event(mgl::Event &event, mgl::Window &window) {
|
|
||||||
// Process widgets by visibility (backwards)
|
|
||||||
for(auto it = widgets.rbegin(), end = widgets.rend(); it != end; ++it) {
|
|
||||||
if(!(*it)->on_event(event, window))
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void WidgetContainer::draw(mgl::Window &window) {
|
|
||||||
for(auto it = widgets.begin(); it != widgets.end(); ++it) {
|
|
||||||
Widget *widget = *it;
|
|
||||||
if(widget->move_to_top) {
|
|
||||||
widget->move_to_top = false;
|
|
||||||
std::swap(*it, widgets.back());
|
|
||||||
/*if(widgets.back() != widget) {
|
|
||||||
widgets.erase(it);
|
|
||||||
widgets.push_back(widget);
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Widget *widget : widgets) {
|
|
||||||
widget->draw(window);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
18
src/main.cpp
18
src/main.cpp
@@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
#include "../include/gui/WidgetContainer.hpp"
|
#include "../include/gui/Page.hpp"
|
||||||
#include "../include/gui/DropdownButton.hpp"
|
#include "../include/gui/DropdownButton.hpp"
|
||||||
#include "../include/gui/ComboBox.hpp"
|
#include "../include/gui/ComboBox.hpp"
|
||||||
#include "../include/Process.hpp"
|
#include "../include/Process.hpp"
|
||||||
@@ -235,8 +235,10 @@ int main(int argc, char **argv) {
|
|||||||
mgl::Rectangle bg_screenshot_overlay(window.get_size().to_vec2f());
|
mgl::Rectangle bg_screenshot_overlay(window.get_size().to_vec2f());
|
||||||
bg_screenshot_overlay.set_color(bg_color);
|
bg_screenshot_overlay.set_color(bg_color);
|
||||||
|
|
||||||
|
gsr::Page front_page;
|
||||||
|
|
||||||
struct MainButton {
|
struct MainButton {
|
||||||
std::unique_ptr<gsr::DropdownButton> button;
|
gsr::DropdownButton* button;
|
||||||
gsr::GsrMode mode;
|
gsr::GsrMode mode;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -273,9 +275,11 @@ int main(int argc, char **argv) {
|
|||||||
auto button = std::make_unique<gsr::DropdownButton>(&title_font, &font, titles[i], descriptions_on[i], descriptions_off[i], textures[i], mgl::vec2f(button_width, button_height));
|
auto button = std::make_unique<gsr::DropdownButton>(&title_font, &font, titles[i], descriptions_on[i], descriptions_off[i], textures[i], mgl::vec2f(button_width, button_height));
|
||||||
button->add_item("Start", "start");
|
button->add_item("Start", "start");
|
||||||
button->add_item("Settings", "settings");
|
button->add_item("Settings", "settings");
|
||||||
|
gsr::DropdownButton *button_ptr = button.get();
|
||||||
|
front_page.add_widget(std::move(button));
|
||||||
|
|
||||||
MainButton main_button = {
|
MainButton main_button = {
|
||||||
std::move(button),
|
button_ptr,
|
||||||
gsr::GsrMode::Unknown
|
gsr::GsrMode::Unknown
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -482,14 +486,12 @@ int main(int argc, char **argv) {
|
|||||||
mgl::Clock state_update_timer;
|
mgl::Clock state_update_timer;
|
||||||
const double state_update_timeout_sec = 2.0;
|
const double state_update_timeout_sec = 2.0;
|
||||||
|
|
||||||
gsr::WidgetContainer &widget_container = gsr::WidgetContainer::get_instance();
|
|
||||||
|
|
||||||
mgl::Event event;
|
mgl::Event event;
|
||||||
|
|
||||||
event.type = mgl::Event::MouseMoved;
|
event.type = mgl::Event::MouseMoved;
|
||||||
event.mouse_move.x = window.get_mouse_position().x;
|
event.mouse_move.x = window.get_mouse_position().x;
|
||||||
event.mouse_move.y = window.get_mouse_position().y;
|
event.mouse_move.y = window.get_mouse_position().y;
|
||||||
widget_container.on_event(event, window);
|
front_page.on_event(event, window);
|
||||||
|
|
||||||
auto render = [&] {
|
auto render = [&] {
|
||||||
window.clear(bg_color);
|
window.clear(bg_color);
|
||||||
@@ -503,7 +505,7 @@ int main(int argc, char **argv) {
|
|||||||
// window.draw(audio_input_title);
|
// window.draw(audio_input_title);
|
||||||
// window.draw(video_quality_title);
|
// window.draw(video_quality_title);
|
||||||
// window.draw(framerate_title);
|
// window.draw(framerate_title);
|
||||||
widget_container.draw(window);
|
front_page.draw(window);
|
||||||
window.draw(top_bar_background);
|
window.draw(top_bar_background);
|
||||||
window.draw(top_bar_text);
|
window.draw(top_bar_text);
|
||||||
window.draw(logo_sprite);
|
window.draw(logo_sprite);
|
||||||
@@ -519,7 +521,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
while(window.poll_event(event)) {
|
while(window.poll_event(event)) {
|
||||||
widget_container.on_event(event, window);
|
front_page.on_event(event, window);
|
||||||
if(event.type == mgl::Event::KeyPressed) {
|
if(event.type == mgl::Event::KeyPressed) {
|
||||||
if(event.key.code == mgl::Keyboard::Escape) {
|
if(event.key.code == mgl::Keyboard::Escape) {
|
||||||
window.set_visible(false);
|
window.set_visible(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user