Remove inheritances, component implementation
This commit is contained in:
parent
748644b220
commit
20835586ab
15 changed files with 375 additions and 229 deletions
|
|
@ -11,7 +11,7 @@ class Application
|
|||
{
|
||||
public:
|
||||
virtual void run() = 0;
|
||||
virtual std::weak_ptr<Window> add_window(int width, int height, const std::string& title) = 0;
|
||||
// virtual std::weak_ptr<Window> add_window(int width, int height, const std::string& title) = 0;
|
||||
|
||||
protected:
|
||||
static bool application_created;
|
||||
|
|
|
|||
|
|
@ -1,12 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <variant>
|
||||
|
||||
namespace uui
|
||||
{
|
||||
|
||||
class Component
|
||||
{
|
||||
public:
|
||||
Component(
|
||||
const std::variant<int, float> x, const std::variant<int, float> y, const std::variant<int, float> width,
|
||||
const std::variant<int, float> height):
|
||||
position_x(x),
|
||||
position_y(y), size_width(width), size_height(height)
|
||||
{
|
||||
background_color = {0.0f, 0.0f, 0.0f, 0.0f};
|
||||
}
|
||||
|
||||
virtual void render() = 0;
|
||||
|
||||
protected:
|
||||
std::variant<int, float> position_x;
|
||||
std::variant<int, float> position_y;
|
||||
std::variant<int, float> size_width;
|
||||
std::variant<int, float> size_height;
|
||||
|
||||
std::array<float, 4> background_color;
|
||||
};
|
||||
|
||||
}
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -1,17 +1,16 @@
|
|||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <variant>
|
||||
#include <vector>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "uui/application.hpp"
|
||||
#include "uui/window.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
|
||||
class GlWindow;
|
||||
class GlApplication: public Application
|
||||
class GlApplication
|
||||
{
|
||||
friend class GlWindow;
|
||||
|
||||
|
|
@ -27,23 +26,45 @@ public:
|
|||
~GlApplication();
|
||||
|
||||
void run();
|
||||
std::weak_ptr<Window> add_window(int width, int height, const std::string& title);
|
||||
std::weak_ptr<GlWindow> create_window(int width, int height, const std::string& title);
|
||||
|
||||
private:
|
||||
static bool application_created;
|
||||
};
|
||||
|
||||
class GlWindow: public Window
|
||||
class GlComponent;
|
||||
class GlWindow
|
||||
{
|
||||
friend class GlApplication;
|
||||
friend class GlComponent;
|
||||
|
||||
public:
|
||||
GlWindow(const GlApplication& app, int width, int height, const std::string& title);
|
||||
std::string title;
|
||||
std::vector<std::shared_ptr<GlComponent>> components;
|
||||
|
||||
GlWindow(const GlWindow&) = delete;
|
||||
GlWindow(GlWindow&&) = delete;
|
||||
~GlWindow();
|
||||
|
||||
void add_box();
|
||||
std::weak_ptr<GlComponent> create_component(
|
||||
const std::variant<int, float> x, const std::variant<int, float> y, const std::variant<int, float> width,
|
||||
const std::variant<int, float> height);
|
||||
|
||||
private:
|
||||
const GlApplication& app;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
GLFWwindow* glfw_window;
|
||||
|
||||
GLuint gl_program;
|
||||
|
||||
GlWindow(const GlApplication& app, int width, int height, const std::string& title);
|
||||
|
||||
void draw();
|
||||
|
||||
static void glfw_resize_callback(GLFWwindow* window, int width, int height);
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "uui/component.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlBox: public Component
|
||||
{
|
||||
public:
|
||||
GlBox();
|
||||
~GlBox();
|
||||
|
||||
void render();
|
||||
|
||||
private:
|
||||
GLuint gl_vbo;
|
||||
GLuint gl_vao;
|
||||
GLuint gl_ebo;
|
||||
GLuint gl_program;
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
48
include/uui/opengl/component.hpp
Normal file
48
include/uui/opengl/component.hpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#pragma once
|
||||
|
||||
#include <array>
|
||||
// #include <memory>
|
||||
#include <variant>
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
#include "window.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
class GlComponent
|
||||
{
|
||||
friend class GlWindow;
|
||||
|
||||
public:
|
||||
GlComponent(const GlComponent&) = delete;
|
||||
GlComponent(GlComponent&&) = delete;
|
||||
~GlComponent();
|
||||
|
||||
void render();
|
||||
|
||||
private:
|
||||
// std::weak_ptr<GlWindow> window;
|
||||
GlWindow* window;
|
||||
|
||||
std::variant<int, float> position_x;
|
||||
std::variant<int, float> position_y;
|
||||
std::variant<int, float> size_width;
|
||||
std::variant<int, float> size_height;
|
||||
|
||||
std::array<float, 4> background_color;
|
||||
|
||||
bool initialized;
|
||||
|
||||
GLuint gl_vbo;
|
||||
GLuint gl_vao;
|
||||
GLuint gl_ebo;
|
||||
|
||||
GlComponent(
|
||||
GlWindow* window, const std::variant<int, float> x, const std::variant<int, float> y,
|
||||
const std::variant<int, float> width, const std::variant<int, float> height);
|
||||
|
||||
void init();
|
||||
void deinit();
|
||||
};
|
||||
|
||||
} // namespace uui
|
||||
13
include/uui/opengl/gl_utils.hpp
Normal file
13
include/uui/opengl/gl_utils.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include "graphic_context.hpp"
|
||||
|
||||
namespace uui
|
||||
{
|
||||
namespace gl
|
||||
{
|
||||
GLenum glCheckError(const char* file, int line);
|
||||
}
|
||||
} // namespace uui
|
||||
|
||||
#define _glCheckError() uui::gl::glCheckError(__FILE__, __LINE__)
|
||||
|
|
@ -13,9 +13,8 @@ class Window
|
|||
{
|
||||
public:
|
||||
std::string title;
|
||||
std::vector<std::unique_ptr<Component>> components;
|
||||
|
||||
virtual void add_box() = 0;
|
||||
virtual void add_component(const Component& box) = 0;
|
||||
|
||||
protected:
|
||||
GLFWwindow* glfw_window;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue