aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2024-08-01 22:41:07 +0200
committerdec05eba <dec05eba@protonmail.com>2024-08-01 22:41:07 +0200
commitbe0ad41e745c3e6177d1159e25f7d23e45b02738 (patch)
treec1845a43e3b3c67c9fadc067f2ff851e668b4213
parent10a5669330ba978c37d984a312ba1de7a2542503 (diff)
Use scissor for pages
-rw-r--r--include/gui/StaticPage.hpp6
-rw-r--r--src/gui/Button.cpp4
-rw-r--r--src/gui/ComboBox.cpp3
-rw-r--r--src/gui/DropdownButton.cpp11
-rw-r--r--src/gui/ScrollablePage.cpp14
-rw-r--r--src/gui/StaticPage.cpp16
-rw-r--r--src/main.cpp13
7 files changed, 50 insertions, 17 deletions
diff --git a/include/gui/StaticPage.hpp b/include/gui/StaticPage.hpp
index cc15531..4280684 100644
--- a/include/gui/StaticPage.hpp
+++ b/include/gui/StaticPage.hpp
@@ -5,11 +5,15 @@
namespace gsr {
class StaticPage : public Page {
public:
- StaticPage() = default;
+ StaticPage(mgl::vec2f size);
StaticPage(const StaticPage&) = delete;
StaticPage& operator=(const StaticPage&) = delete;
bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
void draw(mgl::Window &window, mgl::vec2f offset) override;
+
+ mgl::vec2f get_size() const { return size; }
+ private:
+ mgl::vec2f size;
};
} \ No newline at end of file
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index 48ab085..ad516b5 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -28,8 +28,8 @@ namespace gsr {
}
void Button::draw(mgl::Window &window, mgl::vec2f offset) {
- mgl::Rectangle background(size);
- background.set_position(position + offset);
+ mgl::Rectangle background(size.floor());
+ background.set_position((position + offset).floor());
background.set_color(bg_color);
window.draw(background);
diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp
index 6b8ec26..81c804f 100644
--- a/src/gui/ComboBox.cpp
+++ b/src/gui/ComboBox.cpp
@@ -41,7 +41,8 @@ namespace gsr {
if(mgl::FloatRect(draw_pos, item_size).contains(mouse_pos)) {
show_dropdown = !show_dropdown;
- move_to_top = true;
+ if(show_dropdown)
+ move_to_top = true;
} else {
show_dropdown = false;
}
diff --git a/src/gui/DropdownButton.cpp b/src/gui/DropdownButton.cpp
index ecc284a..bfda834 100644
--- a/src/gui/DropdownButton.cpp
+++ b/src/gui/DropdownButton.cpp
@@ -38,8 +38,13 @@ namespace gsr {
} else if(event.type == mgl::Event::MouseButtonPressed) {
const bool clicked_inside = mouse_inside;
show_dropdown = clicked_inside;
- if(on_click && mouse_inside_item >= 0 && mouse_inside_item < (int)items.size())
- on_click(items[mouse_inside_item].id);
+ if(show_dropdown)
+ move_to_top = true;
+ if(mouse_inside_item >= 0 && mouse_inside_item < (int)items.size()) {
+ if(on_click)
+ on_click(items[mouse_inside_item].id);
+ return false;
+ }
}
return true;
}
@@ -82,7 +87,7 @@ namespace gsr {
// Background
mgl::Rectangle rect(size);
rect.set_position(draw_pos);
- rect.set_color(mgl::Color(0, 0, 0, 120));
+ rect.set_color(mgl::Color(0, 0, 0, 180));
window.draw(rect);
}
diff --git a/src/gui/ScrollablePage.cpp b/src/gui/ScrollablePage.cpp
index 4a4f88b..7394ec3 100644
--- a/src/gui/ScrollablePage.cpp
+++ b/src/gui/ScrollablePage.cpp
@@ -24,7 +24,16 @@ namespace gsr {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos + mgl::vec2f(0.0f, get_border_size(window)).floor();
- mgl::Rectangle background(size);
+ mgl_scissor prev_scissor;
+ mgl_window_get_scissor(window.internal_window(), &prev_scissor);
+
+ mgl_scissor new_scissor = {
+ mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y},
+ mgl_vec2i{(int)size.x, (int)size.y}
+ };
+ mgl_window_set_scissor(window.internal_window(), &new_scissor);
+
+ mgl::Rectangle background(size.floor());
background.set_position(draw_pos);
background.set_color(get_theme().scrollable_page_bg_color);
window.draw(background);
@@ -39,12 +48,13 @@ namespace gsr {
widget->move_to_top = false;
std::swap(widget, widgets.back());
}
- widget->draw(window, offset);
}
for(auto &widget : widgets) {
widget->draw(window, offset);
}
+
+ mgl_window_set_scissor(window.internal_window(), &prev_scissor);
}
float ScrollablePage::get_border_size(mgl::Window &window) const {
diff --git a/src/gui/StaticPage.cpp b/src/gui/StaticPage.cpp
index 78fa497..a5b89cd 100644
--- a/src/gui/StaticPage.cpp
+++ b/src/gui/StaticPage.cpp
@@ -1,6 +1,10 @@
#include "../../include/gui/StaticPage.hpp"
+#include <mglpp/window/Window.hpp>
+
namespace gsr {
+ StaticPage::StaticPage(mgl::vec2f size) : size(size) {}
+
bool StaticPage::on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos;
@@ -18,16 +22,26 @@ namespace gsr {
const mgl::vec2f draw_pos = position + offset;
offset = draw_pos;
+ mgl_scissor prev_scissor;
+ mgl_window_get_scissor(window.internal_window(), &prev_scissor);
+
+ mgl_scissor new_scissor = {
+ mgl_vec2i{(int)draw_pos.x, (int)draw_pos.y},
+ mgl_vec2i{(int)size.x, (int)size.y}
+ };
+ mgl_window_set_scissor(window.internal_window(), &new_scissor);
+
for(auto &widget : widgets) {
if(widget->move_to_top) {
widget->move_to_top = false;
std::swap(widget, widgets.back());
}
- widget->draw(window, offset);
}
for(auto &widget : widgets) {
widget->draw(window, offset);
}
+
+ mgl_window_set_scissor(window.internal_window(), &prev_scissor);
}
} \ No newline at end of file
diff --git a/src/main.cpp b/src/main.cpp
index dcb7bbe..aaffba2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -44,7 +44,7 @@ extern "C" {
#include <mgl/mgl.h>
}
-const mgl::Color bg_color(0, 0, 0, 180);
+const mgl::Color bg_color(0, 0, 0, 160);
static void usage() {
fprintf(stderr, "usage: window-overlay\n");
@@ -237,7 +237,7 @@ int main(int argc, char **argv) {
mgl::Rectangle bg_screenshot_overlay(window.get_size().to_vec2f());
bg_screenshot_overlay.set_color(bg_color);
- gsr::StaticPage front_page;
+ gsr::StaticPage front_page(window_size.to_vec2f());
const mgl::vec2f settings_page_size(window_size.x * 0.3333f, window_size.y * 0.7f);
const mgl::vec2f settings_page_position = (window_size.to_vec2f() * 0.5f - settings_page_size * 0.5f).floor();
@@ -254,13 +254,13 @@ int main(int argc, char **argv) {
gsr::ScrollablePage *stream_settings_content_ptr = stream_settings_content.get();
stream_settings_content->set_position(settings_page_position);
- gsr::StaticPage replay_settings_page;
+ gsr::StaticPage replay_settings_page(window_size.to_vec2f());
replay_settings_page.add_widget(std::move(replay_settings_content));
- gsr::StaticPage record_settings_page;
+ gsr::StaticPage record_settings_page(window_size.to_vec2f());
record_settings_page.add_widget(std::move(record_settings_content));
- gsr::StaticPage stream_settings_page;
+ gsr::StaticPage stream_settings_page(window_size.to_vec2f());
stream_settings_page.add_widget(std::move(stream_settings_content));
gsr::Page *current_page = &front_page;
@@ -453,7 +453,7 @@ int main(int argc, char **argv) {
//XGrabServer(display);
mgl::Rectangle top_bar_background(mgl::vec2f(window.get_size().x, window.get_size().y*0.06f).floor());
- top_bar_background.set_color(mgl::Color(0, 0, 0, 200));
+ top_bar_background.set_color(mgl::Color(0, 0, 0, 180));
mgl::Text top_bar_text("GPU Screen Recorder", top_bar_font);
//top_bar_text.set_color(gsr::get_theme().tint_color);
@@ -482,7 +482,6 @@ int main(int argc, char **argv) {
gsr::Page *settings_content_page = settings_content_pages[i];
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)