aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/gui/Button.hpp7
-rw-r--r--include/gui/ComboBox.hpp36
-rw-r--r--include/gui/Widget.hpp12
-rw-r--r--include/gui/WidgetContainer.hpp30
-rw-r--r--include/window_texture.h38
5 files changed, 82 insertions, 41 deletions
diff --git a/include/gui/Button.hpp b/include/gui/Button.hpp
index 84098b2..972e5c9 100644
--- a/include/gui/Button.hpp
+++ b/include/gui/Button.hpp
@@ -8,9 +8,14 @@ namespace gsr {
class Button : public Widget {
public:
Button(mgl::vec2f size);
- void on_event(mgl::Event &event, mgl::Window &window) override;
+ Button(const Button&) = delete;
+ Button& operator=(const Button&) = delete;
+
+ bool on_event(mgl::Event &event, mgl::Window &window) override;
void draw(mgl::Window &window) override;
+ mgl::vec2f get_size() const { return size; }
+
std::function<void()> on_click;
private:
mgl::vec2f size;
diff --git a/include/gui/ComboBox.hpp b/include/gui/ComboBox.hpp
new file mode 100644
index 0000000..5c899a7
--- /dev/null
+++ b/include/gui/ComboBox.hpp
@@ -0,0 +1,36 @@
+#pragma once
+
+#include "Widget.hpp"
+#include <mglpp/graphics/Text.hpp>
+#include <string>
+#include <vector>
+
+namespace gsr {
+ class ComboBox : public Widget {
+ public:
+ ComboBox(mgl::Font *font);
+ ComboBox(const ComboBox&) = delete;
+ ComboBox& operator=(const ComboBox&) = delete;
+
+ bool on_event(mgl::Event &event, mgl::Window &window) override;
+ void draw(mgl::Window &window) override;
+
+ void add_item(const std::string &text, const std::string &id);
+
+ mgl::vec2f get_size();
+ private:
+ void update_if_dirty();
+ private:
+ struct Item {
+ mgl::Text text;
+ std::string id;
+ };
+
+ mgl::vec2f max_size;
+ mgl::Font *font;
+ std::vector<Item> items;
+ bool dirty = true;
+ bool show_dropdown = false;
+ size_t selected_item = 0;
+ };
+} \ No newline at end of file
diff --git a/include/gui/Widget.hpp b/include/gui/Widget.hpp
index cf81d69..81f47b5 100644
--- a/include/gui/Widget.hpp
+++ b/include/gui/Widget.hpp
@@ -9,13 +9,21 @@ namespace mgl {
namespace gsr {
class Widget {
+ friend class WidgetContainer;
public:
- virtual ~Widget() = default;
+ Widget();
+ Widget(const Widget&) = delete;
+ Widget& operator=(const Widget&) = delete;
+ virtual ~Widget();
- virtual void on_event(mgl::Event &event, mgl::Window &window) = 0;
+ // Return true to allow other widgets to also process the event
+ virtual bool on_event(mgl::Event &event, mgl::Window &window) = 0;
virtual void draw(mgl::Window &window) = 0;
virtual void set_position(mgl::vec2f position);
+
+ virtual mgl::vec2f get_position() const;
protected:
mgl::vec2f position;
+ bool move_to_top = false;
};
} \ No newline at end of file
diff --git a/include/gui/WidgetContainer.hpp b/include/gui/WidgetContainer.hpp
new file mode 100644
index 0000000..e40ffb9
--- /dev/null
+++ b/include/gui/WidgetContainer.hpp
@@ -0,0 +1,30 @@
+#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;
+ };
+} \ No newline at end of file
diff --git a/include/window_texture.h b/include/window_texture.h
deleted file mode 100644
index ea3ff10..0000000
--- a/include/window_texture.h
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef WINDOW_TEXTURE_H
-#define WINDOW_TEXTURE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define GLX_GLXEXT_PROTOTYPES
-#include <GL/glx.h>
-#include <GL/glxext.h>
-#include <X11/Xlib.h>
-
-typedef struct {
- Display *display;
- Window window;
- Pixmap pixmap;
- GLXPixmap glx_pixmap;
- GLuint texture_id;
- int redirected;
-} WindowTexture;
-
-/* Returns 0 on success */
-int window_texture_init(WindowTexture *window_texture, Display *display, Window window);
-void window_texture_deinit(WindowTexture *self);
-
-/*
- This should ONLY be called when the target window is resized.
- Returns 0 on success.
-*/
-int window_texture_on_resize(WindowTexture *self);
-
-GLuint window_texture_get_opengl_texture_id(WindowTexture *self);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* WINDOW_TEXTURE_H */