aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--images/combobox_arrow.pngbin0 -> 330 bytes
-rw-r--r--include/Theme.hpp19
-rw-r--r--include/gui/Button.hpp4
-rw-r--r--include/gui/ComboBox.hpp3
-rw-r--r--include/gui/List.hpp9
-rw-r--r--include/gui/Page.hpp2
-rw-r--r--include/gui/Widget.hpp2
-rw-r--r--src/Theme.cpp41
-rw-r--r--src/gui/Button.cpp31
-rw-r--r--src/gui/ComboBox.cpp22
-rw-r--r--src/gui/DropdownButton.cpp8
-rw-r--r--src/gui/List.cpp53
-rw-r--r--src/gui/Page.cpp9
-rw-r--r--src/gui/Widget.cpp4
-rw-r--r--src/main.cpp124
15 files changed, 239 insertions, 92 deletions
diff --git a/images/combobox_arrow.png b/images/combobox_arrow.png
new file mode 100644
index 0000000..889b288
--- /dev/null
+++ b/images/combobox_arrow.png
Binary files differ
diff --git a/include/Theme.hpp b/include/Theme.hpp
index 37c9e82..a28c249 100644
--- a/include/Theme.hpp
+++ b/include/Theme.hpp
@@ -1,6 +1,11 @@
#pragma once
+#include <mglpp/system/MemoryMappedFile.hpp>
#include <mglpp/graphics/Color.hpp>
+#include <mglpp/graphics/Font.hpp>
+#include <mglpp/graphics/Texture.hpp>
+
+#include <string>
namespace gsr {
struct GsrInfo;
@@ -10,12 +15,22 @@ namespace gsr {
Theme(const Theme&) = delete;
Theme& operator=(const Theme&) = delete;
+ float window_height = 0.0f;
+
mgl::Color tint_color = mgl::Color(118, 185, 0);
mgl::Color scrollable_page_bg_color = mgl::Color(38, 43, 47);
mgl::Color text_color = mgl::Color(255, 255, 255);
+
+ mgl::MemoryMappedFile body_font_file;
+ mgl::MemoryMappedFile title_font_file;
+ mgl::Font body_font;
+ mgl::Font title_font;
+ mgl::Font top_bar_font;
+
+ mgl::Texture combobox_arrow;
};
- void init_theme(const gsr::GsrInfo &gsr_info);
+ bool init_theme(const gsr::GsrInfo &gsr_info, mgl::vec2i window_size, const std::string &resources_path);
void deinit_theme();
- const Theme& get_theme();
+ Theme& get_theme();
} \ No newline at end of file
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index c9a933b..0a07423 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -9,6 +9,8 @@
namespace gsr {
class Button : public Widget {
public:
+ // If width is 0 then the width of the text is used instead (with padding).
+ // If height is 0 then the height of the text is used instead (with padding).
Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color);
Button(const Button&) = delete;
Button& operator=(const Button&) = delete;
@@ -16,7 +18,7 @@ namespace gsr {
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() override { return size; }
+ mgl::vec2f get_size() override;
std::function<void()> on_click;
private:
diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp
index 70a79a7..b4e7b78 100644
--- a/include/gui/ComboBox.hpp
+++ b/include/gui/ComboBox.hpp
@@ -2,6 +2,7 @@
#include "Widget.hpp"
#include <mglpp/graphics/Text.hpp>
+#include <mglpp/graphics/Sprite.hpp>
#include <string>
#include <vector>
@@ -21,6 +22,7 @@ namespace gsr {
mgl::vec2f get_size() override;
private:
void update_if_dirty();
+ float get_dropdown_arrow_height() const;
private:
struct Item {
mgl::Text text;
@@ -30,6 +32,7 @@ namespace gsr {
mgl::vec2f max_size;
mgl::Font *font;
std::vector<Item> items;
+ mgl::Sprite dropdown_arrow;
bool dirty = true;
bool show_dropdown = false;
size_t selected_item = 0;
diff --git a/include/gui/List.hpp b/include/gui/List.hpp
index 8c4e1fc..0b1350c 100644
--- a/include/gui/List.hpp
+++ b/include/gui/List.hpp
@@ -25,10 +25,19 @@ namespace gsr {
bool on_event(mgl::Event &event, mgl::Window &window, mgl::vec2f offset) override;
void draw(mgl::Window &window, mgl::vec2f offset) override;
+ //void remove_child_widget(Widget *widget) override;
+
void add_widget(std::unique_ptr<Widget> widget);
+ void remove_widget(Widget *widget);
+
mgl::vec2f get_size() override;
+ private:
+ void update();
+ void remove_widget_immediate(Widget *widget);
protected:
std::vector<std::unique_ptr<Widget>> widgets;
+ std::vector<std::unique_ptr<Widget>> add_queue;
+ std::vector<Widget*> remove_queue;
Orientation orientation;
Alignment content_alignment;
};
diff --git a/include/gui/Page.hpp b/include/gui/Page.hpp
index a5cfaf9..47aa02b 100644
--- a/include/gui/Page.hpp
+++ b/include/gui/Page.hpp
@@ -12,6 +12,8 @@ namespace gsr {
Page& operator=(const Page&) = delete;
virtual ~Page() = default;
+ //void remove_child_widget(Widget *widget) override;
+
void add_widget(std::unique_ptr<Widget> widget);
protected:
std::vector<std::unique_ptr<Widget>> widgets;
diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp
index 1d52033..6c4a1cb 100644
--- a/include/gui/Widget.hpp
+++ b/include/gui/Widget.hpp
@@ -24,6 +24,8 @@ namespace gsr {
virtual void draw(mgl::Window &window, mgl::vec2f offset) = 0;
virtual void set_position(mgl::vec2f position);
+ //virtual void remove_child_widget(Widget *widget) { (void)widget; }
+
virtual mgl::vec2f get_position() const;
virtual mgl::vec2f get_size() = 0;
protected:
diff --git a/src/Theme.cpp b/src/Theme.cpp
index 0c99320..7db16aa 100644
--- a/src/Theme.cpp
+++ b/src/Theme.cpp
@@ -5,10 +5,14 @@
namespace gsr {
static Theme *theme = nullptr;
- void init_theme(const gsr::GsrInfo &gsr_info) {
- assert(!theme);
+ bool init_theme(const gsr::GsrInfo &gsr_info, mgl::vec2i window_size, const std::string &resources_path) {
+ if(theme)
+ return true;
+
theme = new Theme();
+ theme->window_height = window_size.y;
+
switch(gsr_info.gpu_info.vendor) {
case gsr::GpuVendor::UNKNOWN: {
break;
@@ -26,15 +30,40 @@ namespace gsr {
break;
}
}
+
+ if(!theme->body_font_file.load("/usr/share/fonts/noto/NotoSans-Regular.ttf", mgl::MemoryMappedFile::LoadOptions{true, false}))
+ goto error;
+
+ if(!theme->title_font_file.load("/usr/share/fonts/noto/NotoSans-Bold.ttf", mgl::MemoryMappedFile::LoadOptions{true, false}))
+ goto error;
+
+ if(!theme->title_font.load_from_file(theme->title_font_file, window_size.y * 0.019f))
+ goto error;
+
+ if(!theme->top_bar_font.load_from_file(theme->title_font_file, window_size.y * 0.03f))
+ goto error;
+
+ if(!theme->body_font.load_from_file(theme->body_font_file, window_size.y * 0.015f))
+ goto error;
+
+ if(!theme->combobox_arrow.load_from_file((resources_path + "images/combobox_arrow.png").c_str(), {false, false, false}))
+ goto error;
+
+ return true;
+
+ error:
+ deinit_theme();
+ return false;
}
void deinit_theme() {
- assert(theme);
- delete theme;
- theme = nullptr;
+ if(theme) {
+ delete theme;
+ theme = nullptr;
+ }
}
- const Theme& get_theme() {
+ Theme& get_theme() {
assert(theme);
return *theme;
}
diff --git a/src/gui/Button.cpp b/src/gui/Button.cpp
index eb5932b..e8137c9 100644
--- a/src/gui/Button.cpp
+++ b/src/gui/Button.cpp
@@ -7,15 +7,21 @@
#include <mglpp/system/FloatRect.hpp>
namespace gsr {
+ static const float padding_top = 10.0f;
+ static const float padding_bottom = 10.0f;
+ static const float padding_left = 10.0f;
+ static const float padding_right = 10.0f;
+
Button::Button(mgl::Font *font, const char *text, mgl::vec2f size, mgl::Color bg_color) : size(size), bg_color(bg_color), text(text, *font) {
}
bool Button::on_event(mgl::Event &event, mgl::Window&, mgl::vec2f offset) {
+ const mgl::vec2f item_size = get_size().floor();
if(event.type == mgl::Event::MouseMoved) {
- mouse_inside = mgl::FloatRect(position + offset, size).contains({ (float)event.mouse_move.x, (float)event.mouse_move.y });
+ mouse_inside = mgl::FloatRect(position + offset, item_size).contains({ (float)event.mouse_move.x, (float)event.mouse_move.y });
} else if(event.type == mgl::Event::MouseButtonPressed && event.mouse_button.button == mgl::Mouse::Left) {
- const bool clicked_inside = mouse_inside;
+ const bool clicked_inside = mgl::FloatRect(position + offset, item_size).contains({ (float)event.mouse_button.x, (float)event.mouse_button.y });;
if(clicked_inside && on_click)
on_click();
}
@@ -23,18 +29,31 @@ namespace gsr {
}
void Button::draw(mgl::Window &window, mgl::vec2f offset) {
- mgl::Rectangle background(size.floor());
- background.set_position((position + offset).floor());
+ const mgl::vec2f draw_pos = position + offset;
+ const mgl::vec2f item_size = get_size().floor();
+ mgl::Rectangle background(item_size);
+ background.set_position(draw_pos.floor());
background.set_color(bg_color);
window.draw(background);
- text.set_position((position + offset + size * 0.5f - text.get_bounds().size * 0.5f).floor());
+ text.set_position((draw_pos + item_size * 0.5f - text.get_bounds().size * 0.5f).floor());
window.draw(text);
+ const bool mouse_inside = mgl::FloatRect(draw_pos, item_size).contains(window.get_mouse_position().to_vec2f());
if(mouse_inside) {
const int border_size = 5;
const mgl::Color border_color = gsr::get_theme().tint_color;
- draw_rectangle_outline(window, position, size, border_color, border_size);
+ draw_rectangle_outline(window, position, item_size, border_color, border_size);
}
}
+
+ mgl::vec2f Button::get_size() {
+ const mgl::vec2f text_bounds = text.get_bounds().size;
+ mgl::vec2f s = size;
+ if(s.x < 0.0001f)
+ s.x = padding_left + text_bounds.x + padding_right;
+ if(s.y < 0.0001f)
+ s.y = padding_top + text_bounds.y + padding_bottom;
+ return s;
+ }
} \ No newline at end of file
diff --git a/src/gui/ComboBox.cpp b/src/gui/ComboBox.cpp
index 3aa4439..851e3da 100644
--- a/src/gui/ComboBox.cpp
+++ b/src/gui/ComboBox.cpp
@@ -13,7 +13,7 @@ namespace gsr {
static const float padding_left = 10.0f;
static const float padding_right = 10.0f;
- ComboBox::ComboBox(mgl::Font *font) : font(font) {
+ ComboBox::ComboBox(mgl::Font *font) : font(font), dropdown_arrow(&get_theme().combobox_arrow) {
assert(font);
}
@@ -60,21 +60,28 @@ namespace gsr {
if(items.empty())
return;
- const mgl::vec2f draw_pos = position + offset;
+ const mgl::vec2f draw_pos = (position + offset).floor();
const mgl::vec2f item_size(max_size.x, font->get_character_size() + padding_top + padding_bottom);
const mgl::vec2i mouse_pos = window.get_mouse_position();
bool inside = false;
- mgl::Rectangle background(draw_pos, mgl::vec2f(max_size.x, item_size.y));
+ mgl::Rectangle background(draw_pos, item_size.floor());
if(show_dropdown) {
- background.set_size(max_size);
+ background.set_size(max_size.floor());
background.set_color(mgl::Color(0, 0, 0));
} else {
background.set_color(mgl::Color(0, 0, 0, 120));
}
window.draw(background);
+ if(!show_dropdown) {
+ dropdown_arrow.set_height(get_dropdown_arrow_height());
+ dropdown_arrow.set_position(draw_pos + mgl::vec2f(item_size.x - dropdown_arrow.get_size().x - padding_right, item_size.y * 0.5f - dropdown_arrow.get_size().y * 0.5f).floor());
+ dropdown_arrow.set_color(mgl::Color(255, 255, 255, 30));
+ window.draw(dropdown_arrow);
+ }
+
mgl::vec2f pos = draw_pos + mgl::vec2f(padding_left, padding_top);
Item &item = items[selected_item];
@@ -82,7 +89,7 @@ namespace gsr {
if(show_dropdown) {
const int border_size = 3;
const mgl::Color border_color = gsr::get_theme().tint_color;
- draw_rectangle_outline(window, pos - mgl::vec2f(padding_left, padding_top), item_size, border_color, border_size);
+ draw_rectangle_outline(window, pos - mgl::vec2f(padding_left, padding_top), item_size.floor(), border_color, border_size);
}
window.draw(item.text);
pos.y += item.text.get_bounds().size.y + padding_top + padding_bottom;
@@ -136,6 +143,7 @@ namespace gsr {
max_size.x = std::max(max_size.x, bounds.x + padding_left + padding_right);
max_size.y += bounds.y + padding_top + padding_bottom;
}
+ max_size.x += padding_left + get_dropdown_arrow_height();
dirty = false;
}
@@ -143,4 +151,8 @@ namespace gsr {
update_if_dirty();
return { max_size.x, font->get_character_size() + padding_top + padding_bottom };
}
+
+ float ComboBox::get_dropdown_arrow_height() const {
+ return (font->get_character_size() + padding_top + padding_bottom) * 0.4f;
+ }
} \ No newline at end of file
diff --git a/src/gui/DropdownButton.cpp b/src/gui/DropdownButton.cpp
index fa51aac..9fb4803 100644
--- a/src/gui/DropdownButton.cpp
+++ b/src/gui/DropdownButton.cpp
@@ -8,10 +8,10 @@
#include <mglpp/system/FloatRect.hpp>
namespace gsr {
- static const float padding_top = 10.0f;
- static const float padding_bottom = 10.0f;
- static const float padding_left = 10.0f;
- static const float padding_right = 10.0f;
+ static const float padding_top = 15.0f;
+ static const float padding_bottom = 15.0f;
+ static const float padding_left = 20.0f;
+ static const float padding_right = 20.0f;
static const int border_size = 5;
DropdownButton::DropdownButton(mgl::Font *title_font, mgl::Font *description_font, const char *title, const char *description_activated, const char *description_deactivated, mgl::Texture *icon_texture, mgl::vec2f size) :
diff --git a/src/gui/List.cpp b/src/gui/List.cpp
index 4a74f62..e8c02e0 100644
--- a/src/gui/List.cpp
+++ b/src/gui/List.cpp
@@ -1,13 +1,13 @@
#include "../../include/gui/List.hpp"
+#include "../../include/Theme.hpp"
static float floor(float f) {
return (int)f;
}
namespace gsr {
- // TODO: Make this modifiable, multiple by window size.
// TODO: Add homogeneous option, using a specified max size of this list.
- static const mgl::vec2f spacing(30.0f, 10.0f);
+ static const mgl::vec2f spacing_scale(0.009f, 0.009f);
List::List(Orientation orientation, Alignment content_alignment) : orientation(orientation), content_alignment(content_alignment) {}
@@ -31,7 +31,30 @@ namespace gsr {
return true;
}
+ // TODO: Maybe call this from main on all widgets instead of from draw
+ void List::update() {
+ //widgets.insert(widgets.back(), std::make_move_iterator(add_queue.begin()), std::make_move_iterator(add_queue.end()));
+ std::move(add_queue.begin(), add_queue.end(), std::back_inserter(widgets));
+ add_queue.clear();
+
+ for(Widget *widget_to_remove : remove_queue) {
+ remove_widget_immediate(widget_to_remove);
+ }
+ remove_queue.clear();
+ }
+
+ void List::remove_widget_immediate(Widget *widget) {
+ for(auto it = widgets.begin(), end = widgets.end(); it != end; ++it) {
+ if(it->get() == widget) {
+ widgets.erase(it);
+ return;
+ }
+ }
+ }
+
void List::draw(mgl::Window &window, mgl::vec2f offset) {
+ update();
+
mgl::vec2f draw_pos = position + offset;
offset = {0.0f, 0.0f};
Widget *selected_widget = selected_child_widget;
@@ -39,6 +62,7 @@ namespace gsr {
// TODO: Handle start/end alignment
const mgl::vec2f size = get_size();
+ const mgl::vec2f spacing = (spacing_scale * get_theme().window_height).floor();
switch(orientation) {
case Orientation::VERTICAL: {
for(auto &widget : widgets) {
@@ -68,14 +92,37 @@ namespace gsr {
selected_widget->draw(window, mgl::vec2f(0.0f, 0.0f));
}
+ // void List::remove_child_widget(Widget *widget) {
+ // for(auto it = widgets.begin(), end = widgets.end(); it != end; ++it) {
+ // if(it->get() == widget) {
+ // widgets.erase(it);
+ // return;
+ // }
+ // }
+ // }
+
void List::add_widget(std::unique_ptr<Widget> widget) {
widget->parent_widget = this;
- widgets.push_back(std::move(widget));
+ // TODO: Maybe only do this if this is called inside an event handler
+ //widgets.push_back(std::move(widget));
+ add_queue.push_back(std::move(widget));
+ }
+
+ void List::remove_widget(Widget *widget) {
+ for(auto it = add_queue.begin(), end = add_queue.end(); it != end; ++it) {
+ if(it->get() == widget) {
+ add_queue.erase(it);
+ return;
+ }
+ }
+ // TODO: Maybe only do this if this is called inside an event handler
+ remove_queue.push_back(widget);
}
// TODO: Cache result
mgl::vec2f List::get_size() {
mgl::vec2f size;
+ const mgl::vec2f spacing = (spacing_scale * get_theme().window_height).floor();
switch(orientation) {
case Orientation::VERTICAL: {
for(auto &widget : widgets) {
diff --git a/src/gui/Page.cpp b/src/gui/Page.cpp
index 7d43c00..ae13d82 100644
--- a/src/gui/Page.cpp
+++ b/src/gui/Page.cpp
@@ -1,6 +1,15 @@
#include "../../include/gui/Page.hpp"
namespace gsr {
+ // void Page::remove_child_widget(Widget *widget) {
+ // for(auto it = widgets.begin(), end = widgets.end(); it != end; ++it) {
+ // if(it->get() == widget) {
+ // widgets.erase(it);
+ // return;
+ // }
+ // }
+ // }
+
void Page::add_widget(std::unique_ptr<Widget> widget) {
widget->parent_widget = this;
widgets.push_back(std::move(widget));
diff --git a/src/gui/Widget.cpp b/src/gui/Widget.cpp
index 3e966e5..4baeff1 100644
--- a/src/gui/Widget.cpp
+++ b/src/gui/Widget.cpp
@@ -6,7 +6,9 @@ namespace gsr {
}
Widget::~Widget() {
-
+ remove_widget_as_selected_in_parent();
+ // if(parent_widget)
+ // parent_widget->remove_child_widget(this);
}
void Widget::set_position(mgl::vec2f position) {
diff --git a/src/main.cpp b/src/main.cpp
index ed8fba7..a6ca0d8 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -29,14 +29,12 @@
#include <X11/Xutil.h>
#include <mglpp/mglpp.hpp>
-#include <mglpp/graphics/Font.hpp>
#include <mglpp/graphics/Text.hpp>
#include <mglpp/graphics/Texture.hpp>
#include <mglpp/graphics/Sprite.hpp>
#include <mglpp/graphics/Rectangle.hpp>
#include <mglpp/window/Window.hpp>
#include <mglpp/window/Event.hpp>
-#include <mglpp/system/MemoryMappedFile.hpp>
#include <mglpp/system/Clock.hpp>
// TODO: If no compositor is running but a fullscreen application is running (on the focused monitor)
@@ -58,7 +56,7 @@ extern "C" {
#include <mgl/mgl.h>
}
-const mgl::Color bg_color(0, 0, 0, 160);
+const mgl::Color bg_color(0, 0, 0, 100);
static void usage() {
fprintf(stderr, "usage: window-overlay\n");
@@ -207,8 +205,8 @@ static const mgl_monitor* find_monitor_by_cursor_position(mgl::Window &window) {
}
*/
-static void add_widgets_to_settings_page(mgl::Font &title_font, mgl::vec2i window_size, mgl::vec2f settings_page_position, mgl::vec2f settings_page_size, gsr::Page *settings_page, gsr::Page *settings_content_page, const gsr::GsrInfo &gsr_info, const std::vector<gsr::AudioDevice> &audio_devices, std::function<void()> settings_back_button_callback) {
-auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color);
+static void add_widgets_to_settings_page(mgl::vec2i window_size, mgl::vec2f settings_page_position, mgl::vec2f settings_page_size, gsr::Page *settings_page, gsr::Page *settings_content_page, const gsr::GsrInfo &gsr_info, const std::vector<gsr::AudioDevice> &audio_devices, std::function<void()> settings_back_button_callback) {
+ auto back_button = std::make_unique<gsr::Button>(&gsr::get_theme().title_font, "Back", mgl::vec2f(window_size.x / 10, window_size.y / 15), gsr::get_theme().scrollable_page_bg_color);
back_button->set_position(settings_page_position + mgl::vec2f(settings_page_size.x + window_size.x / 50, 0.0f).floor());
back_button->on_click = settings_back_button_callback;
settings_page->add_widget(std::move(back_button));
@@ -218,8 +216,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
{
auto record_area_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- record_area_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Record area:", gsr::get_theme().text_color));
- auto record_area_box = std::make_unique<gsr::ComboBox>(&title_font);
+ record_area_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Record area:", gsr::get_theme().text_color));
+ auto record_area_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
// TODO: Show options not supported but disable them
if(gsr_info.supported_capture_options.window)
record_area_box->add_item("Window", "window");
@@ -246,19 +244,34 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
auto audio_device_section_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- audio_device_section_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Audio:", gsr::get_theme().text_color));
+ audio_device_section_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Audio:", gsr::get_theme().text_color));
auto audio_devices_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
- for(int i = 0; i < 3; ++i) {
+ gsr::List *audio_devices_list_ptr = audio_devices_list.get();
+
+ auto add_audio_track_button = std::make_unique<gsr::Button>(&gsr::get_theme().body_font, "Add audio track", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
+ auto add_audio_track = [&audio_devices, audio_devices_list_ptr]() {
auto audio_device_list = std::make_unique<gsr::List>(gsr::List::Orientation::HORIZONTAL, gsr::List::Alignment::CENTER);
+ gsr::List *audio_device_list_ptr = audio_device_list.get();
{
- audio_device_list->add_widget(std::make_unique<gsr::Label>(&title_font, (std::to_string(1 + i) + ":").c_str(), gsr::get_theme().text_color));
- auto audio_device_box = std::make_unique<gsr::ComboBox>(&title_font);
+ audio_device_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "*", gsr::get_theme().text_color));
+ auto audio_device_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
for(const auto &audio_device : audio_devices) {
audio_device_box->add_item(audio_device.description, audio_device.name);
}
audio_device_list->add_widget(std::move(audio_device_box));
+ auto remove_audio_track_button = std::make_unique<gsr::Button>(&gsr::get_theme().body_font, "Remove", mgl::vec2f(0.0f, 0.0f), mgl::Color(0, 0, 0, 120));
+ remove_audio_track_button->on_click = [=]() {
+ audio_devices_list_ptr->remove_widget(audio_device_list_ptr);
+ };
+ audio_device_list->add_widget(std::move(remove_audio_track_button));
}
- audio_devices_list->add_widget(std::move(audio_device_list));
+ audio_devices_list_ptr->add_widget(std::move(audio_device_list));
+ };
+ add_audio_track_button->on_click = add_audio_track;
+ audio_device_section_list->add_widget(std::move(add_audio_track_button));
+
+ for(int i = 0; i < 3; ++i) {
+ add_audio_track();
}
audio_device_section_list->add_widget(std::move(audio_devices_list));
}
@@ -268,8 +281,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
{
auto video_quality_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- video_quality_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Video quality:", gsr::get_theme().text_color));
- auto video_quality_box = std::make_unique<gsr::ComboBox>(&title_font);
+ video_quality_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Video quality:", gsr::get_theme().text_color));
+ auto video_quality_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
video_quality_box->add_item("Medium", "medium");
video_quality_box->add_item("High (Recommended for live streaming)", "high");
video_quality_box->add_item("Very high (Recommended)", "very_high");
@@ -281,8 +294,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
auto color_range_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- color_range_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Color range:", gsr::get_theme().text_color));
- auto color_range_box = std::make_unique<gsr::ComboBox>(&title_font);
+ color_range_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Color range:", gsr::get_theme().text_color));
+ auto color_range_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
color_range_box->add_item("Limited", "limited");
color_range_box->add_item("Full", "full");
color_range_list->add_widget(std::move(color_range_box));
@@ -291,8 +304,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
auto framerate_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- framerate_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Frame rate:", gsr::get_theme().text_color));
- auto framerate_entry = std::make_unique<gsr::Entry>(&title_font, "60", title_font.get_character_size() * 2);
+ framerate_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Frame rate:", gsr::get_theme().text_color));
+ auto framerate_entry = std::make_unique<gsr::Entry>(&gsr::get_theme().body_font, "60", gsr::get_theme().body_font.get_character_size() * 2);
framerate_entry->validate_handler = gsr::create_entry_validator_integer_in_range(1, 500);
framerate_list->add_widget(std::move(framerate_entry));
}
@@ -304,8 +317,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
{
auto video_codec_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- video_codec_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Video codec:", gsr::get_theme().text_color));
- auto video_codec_box = std::make_unique<gsr::ComboBox>(&title_font);
+ video_codec_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Video codec:", gsr::get_theme().text_color));
+ auto video_codec_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
// TODO: Show options not supported but disable them
video_codec_box->add_item("Auto (Recommended)", "auto");
if(gsr_info.supported_video_codecs.h264)
@@ -327,8 +340,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
auto audio_codec_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- audio_codec_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Audio codec:", gsr::get_theme().text_color));
- auto audio_codec_box = std::make_unique<gsr::ComboBox>(&title_font);
+ audio_codec_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Audio codec:", gsr::get_theme().text_color));
+ auto audio_codec_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
audio_codec_box->add_item("Opus (Recommended)", "opus");
audio_codec_box->add_item("AAC", "aac");
audio_codec_list->add_widget(std::move(audio_codec_box));
@@ -339,8 +352,8 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
auto framerate_mode_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- framerate_mode_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Frame rate mode:", gsr::get_theme().text_color));
- auto framerate_mode_box = std::make_unique<gsr::ComboBox>(&title_font);
+ framerate_mode_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Frame rate mode:", gsr::get_theme().text_color));
+ auto framerate_mode_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
framerate_mode_box->add_item("Auto (Recommended)", "auto");
framerate_mode_box->add_item("Constant", "cfr");
framerate_mode_box->add_item("Variable", "vfr");
@@ -352,16 +365,16 @@ auto back_button = std::make_unique<gsr::Button>(&title_font, "Back", mgl::vec2f
{
auto save_directory_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- save_directory_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Directory to save the video:", gsr::get_theme().text_color));
+ save_directory_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Directory to save the video:", gsr::get_theme().text_color));
// TODO:
- save_directory_list->add_widget(std::make_unique<gsr::Entry>(&title_font, "/home/dec05eba/Videos", title_font.get_character_size() * 20));
+ save_directory_list->add_widget(std::make_unique<gsr::Entry>(&gsr::get_theme().body_font, "/home/dec05eba/Videos", gsr::get_theme().body_font.get_character_size() * 20));
}
file_list->add_widget(std::move(save_directory_list));
auto container_list = std::make_unique<gsr::List>(gsr::List::Orientation::VERTICAL);
{
- container_list->add_widget(std::make_unique<gsr::Label>(&title_font, "Container:", gsr::get_theme().text_color));
- auto container_box = std::make_unique<gsr::ComboBox>(&title_font);
+ container_list->add_widget(std::make_unique<gsr::Label>(&gsr::get_theme().body_font, "Container:", gsr::get_theme().text_color));
+ auto container_box = std::make_unique<gsr::ComboBox>(&gsr::get_theme().body_font);
container_box->add_item("mp4", "mp4");
container_box->add_item("mkv", "matroska");
container_box->add_item("flv", "flv");
@@ -393,16 +406,14 @@ int main(int argc, char **argv) {
const std::vector<gsr::AudioDevice> audio_devices = gsr::get_audio_devices();
- gsr::init_theme(gsr_info);
-
- std::string project_dir;
+ std::string resources_path;
if(access("images/gpu_screen_recorder_logo.png", F_OK) == 0) {
- project_dir = "./";
+ resources_path = "./";
} else {
#ifdef GSR_OVERLAY_RESOURCES_PATH
- project_dir = GSR_OVERLAY_RESOURCES_PATH "/";
+ resources_path = GSR_OVERLAY_RESOURCES_PATH "/";
#else
- project_dir = "/usr/share/gsr-overlay/";
+ resources_path = "/usr/share/gsr-overlay/";
#endif
}
@@ -446,42 +457,27 @@ int main(int argc, char **argv) {
window.set_size(window_size);
window.set_position(window_pos);
+ if(!gsr::init_theme(gsr_info, window_size, resources_path)) {
+ fprintf(stderr, "Error: failed to load theme\n");
+ exit(1);
+ }
+
unsigned char data = 2; // Prefer being composed to allow transparency
XChangeProperty(display, window.get_system_handle(), XInternAtom(display, "_NET_WM_BYPASS_COMPOSITOR", False), XA_CARDINAL, 32, PropModeReplace, &data, 1);
data = 1;
XChangeProperty(display, window.get_system_handle(), XInternAtom(display, "GAMESCOPE_EXTERNAL_OVERLAY", False), XA_CARDINAL, 32, PropModeReplace, &data, 1);
- mgl::MemoryMappedFile title_font_file;
- if(!title_font_file.load("/usr/share/fonts/noto/NotoSans-Bold.ttf", mgl::MemoryMappedFile::LoadOptions{true, false}))
- startup_error("failed to load file: fonts/Orbitron-Bold.ttf");
-
- mgl::MemoryMappedFile font_file;
- if(!font_file.load("/usr/share/fonts/noto/NotoSans-Regular.ttf", mgl::MemoryMappedFile::LoadOptions{true, false}))
- startup_error("failed to load file: fonts/Orbitron-Regular.ttf");
-
- mgl::Font top_bar_font;
- if(!top_bar_font.load_from_file(title_font_file, window_size.y * 0.03f))
- startup_error("failed to load font: fonts/NotoSans-Bold.ttf");
-
- mgl::Font title_font;
- if(!title_font.load_from_file(title_font_file, window_size.y * 0.019f))
- startup_error("failed to load font: fonts/NotoSans-Regular.ttf");
-
- mgl::Font font;
- if(!font.load_from_file(font_file, window_size.y * 0.015f))
- startup_error("failed to load font: fonts/NotoSans-Regular.ttf");
-
mgl::Texture replay_button_texture;
- if(!replay_button_texture.load_from_file((project_dir + "images/replay.png").c_str()))
+ if(!replay_button_texture.load_from_file((resources_path + "images/replay.png").c_str()))
startup_error("failed to load texture: images/replay.png");
mgl::Texture record_button_texture;
- if(!record_button_texture.load_from_file((project_dir + "images/record.png").c_str()))
+ if(!record_button_texture.load_from_file((resources_path + "images/record.png").c_str()))
startup_error("failed to load texture: images/record.png");
mgl::Texture stream_button_texture;
- if(!stream_button_texture.load_from_file((project_dir + "images/stream.png").c_str()))
+ if(!stream_button_texture.load_from_file((resources_path + "images/stream.png").c_str()))
startup_error("failed to load texture: images/stream.png");
mgl::Texture screenshot_texture;
@@ -569,7 +565,7 @@ int main(int argc, char **argv) {
std::vector<MainButton> main_buttons;
for(int i = 0; i < num_frontpage_buttons; ++i) {
- 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>(&gsr::get_theme().title_font, &gsr::get_theme().body_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("Settings", "settings");
gsr::DropdownButton *button_ptr = button.get();
@@ -671,7 +667,7 @@ int main(int argc, char **argv) {
main_buttons[1].button->set_item_label(id, "Start");
// TODO: Show this with a slight delay to make sure it doesn't show up in the video
- const std::string record_image_filepath = project_dir + "images/record.png";
+ const std::string record_image_filepath = resources_path + "images/record.png";
const char *notification_args[] = {
"gsr-notify", "--text", "Recording has been saved", "--timeout", "3.0",
"--icon", record_image_filepath.c_str(),
@@ -707,7 +703,7 @@ int main(int argc, char **argv) {
// TODO: Do not run this is a daemon. Instead get the pid and when launching another notification close the current notification
// program and start another one. This can also be used to check when the notification has finished by checking with waitpid NOWAIT
// to see when the program has exit.
- const std::string record_image_filepath = project_dir + "images/record.png";
+ const std::string record_image_filepath = resources_path + "images/record.png";
const char *notification_args[] = {
"gsr-notify", "--text", "Recording has started", "--timeout", "3.0",
"--icon", record_image_filepath.c_str(),
@@ -759,7 +755,7 @@ int main(int argc, char **argv) {
mgl::Rectangle top_bar_background(mgl::vec2f(window_size.x, window_size.y*0.06f).floor());
top_bar_background.set_color(mgl::Color(0, 0, 0, 180));
- mgl::Text top_bar_text("GPU Screen Recorder", top_bar_font);
+ mgl::Text top_bar_text("GPU Screen Recorder", gsr::get_theme().top_bar_font);
//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());
@@ -784,11 +780,11 @@ int main(int argc, char **argv) {
for(int i = 0; i < num_settings_pages; ++i) {
gsr::Page *settings_page = settings_pages[i];
gsr::Page *settings_content_page = settings_content_pages[i];
- add_widgets_to_settings_page(title_font, window_size, settings_page_position, settings_page_size, settings_page, settings_content_page, gsr_info, audio_devices, settings_back_button_callback);
+ add_widgets_to_settings_page(window_size, settings_page_position, settings_page_size, settings_page, settings_content_page, gsr_info, audio_devices, settings_back_button_callback);
}
mgl::Texture close_texture;
- if(!close_texture.load_from_file((project_dir + "images/cross.png").c_str()))
+ if(!close_texture.load_from_file((resources_path + "images/cross.png").c_str()))
startup_error("failed to load texture: images/cross.png");
mgl::Sprite close_sprite(&close_texture);
@@ -796,7 +792,7 @@ int main(int argc, char **argv) {
close_sprite.set_position(mgl::vec2f(window_size.x - close_sprite.get_size().x - 50.0f, top_bar_background.get_size().y * 0.5f - close_sprite.get_size().y * 0.5f).floor());
mgl::Texture logo_texture;
- if(!logo_texture.load_from_file((project_dir + "images/gpu_screen_recorder_logo.png").c_str()))
+ if(!logo_texture.load_from_file((resources_path + "images/gpu_screen_recorder_logo.png").c_str()))
startup_error("failed to load texture: images/gpu_screen_recorder_logo.png");
mgl::Sprite logo_sprite(&logo_texture);