This commit is contained in:
dec05eba
2022-09-25 17:29:17 +02:00
parent 663a36df4a
commit 497217a3e0
14 changed files with 609 additions and 393 deletions

View File

@@ -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;

36
include/gui/ComboBox.hpp Normal file
View File

@@ -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;
};
}

View File

@@ -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;
};
}

View File

@@ -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;
};
}

View File

@@ -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 */