fix some tasks and rebase code

This commit is contained in:
chatlanin 2023-10-04 14:04:03 +03:00
parent 81fbfeffbb
commit 1c3d8189e8
27 changed files with 173 additions and 161 deletions

View File

@ -1,7 +1,5 @@
#include "test_panel.hpp" #include "test_panel.hpp"
#include "try_engine/utils/keycode.hpp"
namespace tr::layers namespace tr::layers
{ {
void test_panel::on_attach() void test_panel::on_attach()
@ -16,22 +14,22 @@ namespace tr::layers
void test_panel::gui_render() void test_panel::gui_render()
{ {
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y)); ImGui::SetNextWindowPos(ImVec2(m_pos_x, m_pos_y));
ImGui::SetNextWindowSize(ImVec2(width, height)); ImGui::SetNextWindowSize(ImVec2(m_width, m_height));
BEGIN_IMGUI_WIN("test_win"); BEGIN_IMGUI_WIN("test_win");
if (ImGui::Button("RUN", ImVec2(28, 30))) { if (ImGui::Button("RUN", ImVec2(28, 30))) {
em->execute(std::string("asdf"), "asdf"); m_event_manager->execute(std::string("test signal key"), "value params run");
} }
TR_PUSH_FONT(ICON, 18); TR_PUSH_FONT(ICON, 18);
if (ImGui::Button(try_engine::style::icon::ICON_STOP, ImVec2(28, 30))) { if (ImGui::Button(try_engine::style::icon::ICON_STOP, ImVec2(28, 30))) {
em->execute(std::string("asdf"), "asdf"); m_event_manager->execute(std::string("test signal key"), "value paramsl stop");
} }
// ImGui::Text(try_engine::style::icon::ICON_PAINT_BRUSH " Paint" ); ImGui::Text(try_engine::style::icon::ICON_PAINT_BRUSH, " Paint" );
ImGui::Text("\xef\x87\xbc"); ImGui::Text("\xef\x87\xbc");
TR_POP_FONT(); TR_POP_FONT();

View File

@ -9,13 +9,13 @@ namespace tr::layers
BASE_IMPL(test_panel); BASE_IMPL(test_panel);
private: private:
bool show = true; bool m_open = true;
float width = 720.f; float m_width = 720.f;
float height = 480.f; float m_height = 480.f;
float pos_x = 212.f; float m_pos_x = 212.f;
float pos_y = 35.f; float m_pos_y = 35.f;
}; };
} }

View File

@ -1,5 +1,3 @@
#include "try_engine/try_engine.hpp"
#include "layers/test_panel/test_panel.hpp" #include "layers/test_panel/test_panel.hpp"
namespace try_engine_sandbox namespace try_engine_sandbox
@ -16,12 +14,12 @@ namespace try_engine_sandbox
template<typename... Args> template<typename... Args>
void push_layer(Args... args) void push_layer(Args... args)
{ {
(args->set_event_manager(&em), ...); (args->set_event_manager(&m_event_manager), ...);
try_engine::application::push_layer(args...); try_engine::application::push_layer(args...);
} }
private: private:
event_manager em; event_manager m_event_manager;
}; };
} }

View File

@ -1,6 +1,6 @@
#include "application.hpp" #include "application.hpp"
#include "try_engine/utils/define.hpp" #include "try_engine/utils/utils.hpp"
namespace try_engine namespace try_engine
{ {
@ -8,33 +8,33 @@ namespace try_engine
{ {
instance = std::unique_ptr<application>(this); instance = std::unique_ptr<application>(this);
win = std::make_unique<window>(app_name); m_win = std::make_unique<window>(app_name);
win->set_event_callback(BIND_EVENT_FN(application, on_event)); m_win->set_event_callback(BIND_EVENT_FN(application, on_event));
ui = std::make_unique<gui>(); m_gui = std::make_unique<gui>();
} }
void application::run() void application::run()
{ {
while(!glfwWindowShouldClose(win->glfw_window())) while(!glfwWindowShouldClose(m_win->glfw_window()))
{ {
win->clear(); m_win->clear();
for (auto l : l_stack) for (auto l : m_layers_stack)
l->on_update(time::get_time()); l->on_update(time::get_time());
ui->begin_frame(); m_gui->begin_frame();
for (auto l : l_stack) for (auto l : m_layers_stack)
l->gui_render(); l->gui_render();
ui->end_frame(); m_gui->end_frame();
win->update(); m_win->update();
} }
} }
std::unique_ptr<window>& application::get_window() std::unique_ptr<window>& application::get_window()
{ {
return win; return m_win;
} }
std::unique_ptr<application>& application::get() std::unique_ptr<application>& application::get()
@ -44,11 +44,11 @@ namespace try_engine
void application::attach_layers() void application::attach_layers()
{ {
for (auto l : l_stack) l->on_attach(); for (auto l : m_layers_stack) l->on_attach();
} }
void application::on_event(system_event::event& e) void application::on_event(system_event::event& e)
{ {
for(const auto l : l_stack) l->on_event(e); for(const auto l : m_layers_stack) l->on_event(e);
} }
} }

View File

@ -14,6 +14,13 @@ namespace try_engine
application(std::string); application(std::string);
virtual ~application() = default; virtual ~application() = default;
private:
inline static std::unique_ptr<application> instance = nullptr;
std::unique_ptr<window> m_win;
layers_stack m_layers_stack;
std::unique_ptr<gui> m_gui;
public: public:
void run(); void run();
void attach_layers(); void attach_layers();
@ -22,16 +29,10 @@ namespace try_engine
public: public:
template<typename... Args> template<typename... Args>
void push_layer(Args*... args) { (l_stack.push_back(args), ...); } void push_layer(Args*... args) { (m_layers_stack.push_back(args), ...); }
private:
inline static std::unique_ptr<application> instance = nullptr;
std::unique_ptr<window> win;
layers_stack l_stack;
private: private:
void clear(); void clear();
std::unique_ptr<gui> ui;
void on_event(system_event::event& e); void on_event(system_event::event& e);
}; };

View File

@ -1,9 +1,11 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
namespace try_engine::system_event::classificator namespace try_engine::system_event::classificator
{ {
// HERE
// переменныейц вынести в кофиг
inline std::string WINDOW_RESIZE() { return "WINDOW_RESIZE"; } inline std::string WINDOW_RESIZE() { return "WINDOW_RESIZE"; }
inline std::string WINDOW_CLOSE() { return "WINDOW_CLOSE"; } inline std::string WINDOW_CLOSE() { return "WINDOW_CLOSE"; }
inline std::string WINDOW_FOCUS() { return "WINDOW_FOCUS"; } inline std::string WINDOW_FOCUS() { return "WINDOW_FOCUS"; }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/define.hpp" #include "try_engine/utils/utils.hpp"
#include "try_engine/event/system_event/event.hpp" #include "try_engine/event/system_event/event.hpp"
#include "try_engine/event/event_classificator.hpp" #include "try_engine/event/event_classificator.hpp"
@ -8,14 +8,16 @@ namespace try_engine::system_event
{ {
class key_event : public event class key_event : public event
{ {
// HERE
// ???
protected: protected:
key_event(int kc) : keycode { kc } {} key_event(int kc) : m_keycode { kc } {}
protected:
int m_keycode;
public: public:
inline int get_keycode() const { return keycode; } inline int get_keycode() const { return m_keycode; }
protected:
int keycode;
}; };
class key_pressed_event : public key_event class key_pressed_event : public key_event

View File

@ -1,16 +1,11 @@
#pragma once #pragma once
#include "try_engine/utils/define.hpp" #include "try_engine/utils/utils.hpp"
#include "try_engine/event/system_event/event.hpp" #include "try_engine/event/system_event/event.hpp"
#include "try_engine/event/event_classificator.hpp" #include "try_engine/event/event_classificator.hpp"
namespace try_engine::system_event namespace try_engine::system_event
{ {
// Разобрать и привести в порядок по подобию
// key_event.hpp
//
// class MouseMovedEvent : public Event // class MouseMovedEvent : public Event
// { // {
// public: // public:

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/define.hpp" #include "try_engine/utils/utils.hpp"
#include "try_engine/event/system_event/event.hpp" #include "try_engine/event/system_event/event.hpp"
#include "try_engine/event/event_classificator.hpp" #include "try_engine/event/event_classificator.hpp"
@ -9,17 +9,17 @@ namespace try_engine::system_event
class window_resize_event : public event class window_resize_event : public event
{ {
public: public:
window_resize_event(int w, int h) : width { w }, height { h } {} window_resize_event(int w, int h) : m_width { w }, m_height { h } {}
private:
int m_width, m_height;
public: public:
EVENT_CLASS_TYPE_FN(classificator::WINDOW_RESIZE()) EVENT_CLASS_TYPE_FN(classificator::WINDOW_RESIZE())
public: public:
inline unsigned int get_width() const { return width; } inline unsigned int get_width() const { return m_width; }
inline unsigned int get_height() const { return height; } inline unsigned int get_height() const { return m_height; }
private:
int width, height;
}; };
class window_close_event : public event class window_close_event : public event
@ -34,16 +34,16 @@ namespace try_engine::system_event
class window_focus_event : public event class window_focus_event : public event
{ {
public: public:
window_focus_event(int f) : focused { f } {} window_focus_event(int f) : m_focused { f } {}
private:
int m_focused;
public: public:
EVENT_CLASS_TYPE_FN(classificator::WINDOW_FOCUS()) EVENT_CLASS_TYPE_FN(classificator::WINDOW_FOCUS())
public: public:
inline int get_focused() { return focused; } inline int get_focused() { return m_focused; }
private:
int focused;
}; };
} }

View File

@ -8,7 +8,6 @@ namespace try_engine::system_event
{ {
event() = default; event() = default;
virtual ~event() = default; virtual ~event() = default;
virtual std::string get_name() const = 0; virtual std::string get_name() const = 0;
}; };
} }

View File

@ -7,6 +7,8 @@ namespace try_engine
{ {
gui::gui() gui::gui()
{ {
// HERE
// откуда она ???
IMGUI_CHECKVERSION(); IMGUI_CHECKVERSION();
ImGui::CreateContext(); ImGui::CreateContext();

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
namespace try_engine namespace try_engine
{ {

View File

@ -11,8 +11,7 @@
namespace try_engine::style::fonts namespace try_engine::style::fonts
{ {
inline std::string font_name = "Montserrat/Montserrat-"; inline std::string font_name = "Montserrat/Montserrat-";
inline std::vector<float> font_size = { 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, inline std::vector<float> font_size = { 8.f, 9.f, 10.f, 11.f, 12.f, 13.f, 14.f, 15.f, 16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f };
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.f };
enum font_type enum font_type
{ {

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
#include "try_engine/event/system_event/event.hpp" #include "try_engine/event/system_event/event.hpp"
namespace try_engine namespace try_engine
@ -16,6 +16,9 @@ namespace try_engine
layer(const layer&) = delete; layer(const layer&) = delete;
layer(layer&) = delete; layer(layer&) = delete;
// HERE
// реализовать перемещение слоев
public: public:
virtual void on_attach() {}; virtual void on_attach() {};
virtual void on_detach() {}; virtual void on_detach() {};

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
/* /*
renderer - некий объект отрисовки и разукраски всей сцены. renderer - некий объект отрисовки и разукраски всей сцены.

View File

@ -4,15 +4,15 @@ namespace try_engine
{ {
texture::~texture() texture::~texture()
{ {
glDeleteTextures(1, &texture_id); glDeleteTextures(1, &m_texture_id);
} }
void texture::make() void texture::make()
{ {
if (!texture_id) if (!m_texture_id)
{ {
glGenTextures(1, &texture_id); glGenTextures(1, &m_texture_id);
glBindTexture(GL_TEXTURE_2D, texture_id); glBindTexture(GL_TEXTURE_2D, m_texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
@ -21,12 +21,12 @@ namespace try_engine
void texture::clear() void texture::clear()
{ {
glDeleteTextures(1, &texture_id); glDeleteTextures(1, &m_texture_id);
} }
void texture::draw(ImVec2 pos, ImVec2 size) void texture::draw(ImVec2 pos, ImVec2 size)
{ {
// ImGui::Image(reinterpret_cast<void*>(static_cast<intptr_t>(texture)), ImVec2(pos.x + 100, pos.y + 100)); // ImGui::Image(reinterpret_cast<void*>(static_cast<intptr_t>(texture)), ImVec2(pos.x + 100, pos.y + 100));
ImGui::GetWindowDrawList()->AddImage(reinterpret_cast<void*>(static_cast<intptr_t>(texture_id)), pos, size); ImGui::GetWindowDrawList()->AddImage(reinterpret_cast<void*>(static_cast<intptr_t>(m_texture_id)), pos, size);
} }
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
namespace try_engine namespace try_engine
{ {
@ -9,7 +9,10 @@ namespace try_engine
public: public:
texture() = default; texture() = default;
~texture(); ~texture();
private:
GLuint m_texture_id = 0;
public: public:
template<typename Image> template<typename Image>
void bind(Image& image) void bind(Image& image)
@ -23,9 +26,6 @@ namespace try_engine
void draw(ImVec2 pos, ImVec2 size); void draw(ImVec2 pos, ImVec2 size);
void make(); void make();
void clear(); void clear();
private:
GLuint texture_id = 0;
}; };
} }

View File

@ -1,9 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
#include "try_engine/utils/timestap.hpp"
#include "try_engine/utils/define.hpp"
#include "try_engine/utils/keycode.hpp"
#include "try_engine/gui/style/style.hpp" #include "try_engine/gui/style/style.hpp"
@ -17,4 +14,3 @@
#include "try_engine/renderer/renderer.hpp" #include "try_engine/renderer/renderer.hpp"
#include "try_engine/renderer/texture/texture.hpp" #include "try_engine/renderer/texture/texture.hpp"

View File

@ -26,10 +26,10 @@
if (f.no_bring_to_front) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus if (f.no_bring_to_front) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus
#define SET_EVENT_MANAGER_IMPL()\ #define SET_EVENT_MANAGER_IMPL()\
void set_event_manager(event_manager* em_)\ void set_event_manager(event_manager* in_event_manager)\
{\ {\
em = em_;\ m_event_manager = in_event_manager;\
em->set_event_callback(this);\ m_event_manager->set_event_callback(this);\
} }
#define BASE_OVERIDE_IMPL()\ #define BASE_OVERIDE_IMPL()\
@ -73,7 +73,7 @@
private:\ private:\
FLAGS_STRUCT_DEFINED();\ FLAGS_STRUCT_DEFINED();\
private:\ private:\
event_manager* em event_manager* m_event_manager
#define BEGIN_IMGUI_WIN(name) if (!ImGui::Begin(name, &f.p_open, window_flags)) ImGui::End() #define BEGIN_IMGUI_WIN(name) if (!ImGui::Begin(name, &f.p_open, window_flags)) ImGui::End()

View File

@ -17,23 +17,4 @@
#include "imgui_impl_glfw.h" #include "imgui_impl_glfw.h"
#include "imgui_impl_opengl3.h" #include "imgui_impl_opengl3.h"
#include "timestap.hpp"
template<typename Event>
using event_callback = std::function<void(Event&)>;
#include "nlohmann/json.hpp" #include "nlohmann/json.hpp"
using JSON = nlohmann::json;
namespace try_engine::time
{
inline timestep<float> get_time()
{
static float frame_time = 0.0f;
float t = (float)glfwGetTime();
timestep<float> ts = t - frame_time;
frame_time = t;
return ts;
}
}

View File

@ -1,5 +1,7 @@
#pragma once #pragma once
#include "using.hpp"
namespace try_engine::time namespace try_engine::time
{ {
template<typename Time> template<typename Time>
@ -18,5 +20,16 @@ namespace try_engine::time
}; };
} }
namespace try_engine::time
{
inline timestep<float> get_time()
{
static float frame_time = 0.0f;
float t = (float)glfwGetTime();
timestep<float> ts = t - frame_time;
frame_time = t;
return ts;
}
}

View File

@ -0,0 +1,14 @@
#pragma once
#include "include.hpp"
namespace try_engine
{
template<typename Event>
using event_callback = std::function<void(Event&)>;
using JSON = nlohmann::json;
}

View File

@ -0,0 +1,5 @@
#pragma once
#include "keycode.hpp"
#include "define.hpp"
#include "time.hpp"

View File

@ -2,11 +2,11 @@
namespace try_engine namespace try_engine
{ {
graphic_context::graphic_context(GLFWwindow* w) : win { w } {} graphic_context::graphic_context(GLFWwindow* w) : m_win { w } {}
void graphic_context::init() void graphic_context::init()
{ {
glfwMakeContextCurrent(win); glfwMakeContextCurrent(m_win);
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress); int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
hack::log(": ")("Glad loader status", status == 1 ? "true" : "false"); hack::log(": ")("Glad loader status", status == 1 ? "true" : "false");
@ -21,7 +21,7 @@ namespace try_engine
void graphic_context::swap_buffers() void graphic_context::swap_buffers()
{ {
glfwSwapBuffers(win); glfwSwapBuffers(m_win);
} }
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
namespace try_engine namespace try_engine
{ {
@ -9,10 +9,11 @@ namespace try_engine
public: public:
graphic_context(GLFWwindow*); graphic_context(GLFWwindow*);
private:
GLFWwindow* m_win;
public:
void init(); void init();
void swap_buffers(); void swap_buffers();
private:
GLFWwindow* win;
}; };
} }

View File

@ -1,6 +1,5 @@
#include "window.hpp" #include "window.hpp"
#include "GLFW/glfw3.h"
#include "renderer/renderer.hpp" #include "renderer/renderer.hpp"
#include "event/system_event/category/key_event.hpp" #include "event/system_event/category/key_event.hpp"
#include "event/system_event/category/window_event.hpp" #include "event/system_event/category/window_event.hpp"
@ -12,7 +11,7 @@ namespace try_engine
if (!glfwInit()) if (!glfwInit())
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
win_data.title = app_name; m_window_data.m_name = app_name;
set_hint(); set_hint();
set_window(); set_window();
@ -21,16 +20,16 @@ namespace try_engine
set_key_callback(); set_key_callback();
set_window_callback(); set_window_callback();
hack::log(": ")("Creating window", win_data.title); hack::log(": ")("Creating window", m_window_data.m_name);
hack::log(" = ")("w", win_data.width); hack::log(" = ")("w", m_window_data.m_width);
hack::log(" = ")("h", win_data.height); hack::log(" = ")("h", m_window_data.m_height);
} }
window::~window() window::~window()
{ {
glfwDestroyWindow(win); glfwDestroyWindow(m_win);
glfwTerminate(); glfwTerminate();
hack::warn(": ")("destroy", "window", win_data.title); hack::warn(": ")("destroy", "window", m_window_data.m_name);
} }
void window::set_hint() void window::set_hint()
@ -44,58 +43,58 @@ namespace try_engine
void window::set_window() void window::set_window()
{ {
win = glfwCreateWindow( m_win = glfwCreateWindow(
glfwGetVideoMode(glfwGetPrimaryMonitor())->width, glfwGetVideoMode(glfwGetPrimaryMonitor())->width,
glfwGetVideoMode(glfwGetPrimaryMonitor())->height, glfwGetVideoMode(glfwGetPrimaryMonitor())->height,
win_data.title.c_str(), m_window_data.m_name.c_str(),
nullptr, nullptr nullptr, nullptr
); );
if(win == NULL) if(m_win == NULL)
{ {
hack::error()("Failed to create GLFW window"); hack::error()("Failed to create GLFW window");
glfwTerminate(); glfwTerminate();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
glfwGetWindowSize(win, &win_data.width, &win_data.height); glfwGetWindowSize(m_win, &m_window_data.m_width, &m_window_data.m_height);
} }
void window::set_context() void window::set_context()
{ {
context = std::make_unique<graphic_context>(win); m_graphic_context = std::make_unique<graphic_context>(m_win);
context->init(); m_graphic_context->init();
} }
void window::set_pointer() void window::set_pointer()
{ {
glfwSetWindowUserPointer(win, &win_data); glfwSetWindowUserPointer(m_win, &m_window_data);
} }
void window::set_event_callback(const event_callback<system_event::event>& cb) void window::set_event_callback(const event_callback<system_event::event>& cb)
{ {
win_data.callback = cb; m_window_data.on_callback = cb;
} }
GLFWwindow* window::glfw_window() const GLFWwindow* window::glfw_window() const
{ {
return win; return m_win;
} }
int window::width() const int window::width() const
{ {
return win_data.width; return m_window_data.m_width;
} }
int window::height() const int window::height() const
{ {
return win_data.height; return m_window_data.m_height;
} }
void window::update() void window::update()
{ {
glfwPollEvents(); glfwPollEvents();
context->swap_buffers(); m_graphic_context->swap_buffers();
} }
void window::clear() const void window::clear() const
@ -106,7 +105,7 @@ namespace try_engine
void window::set_key_callback() void window::set_key_callback()
{ {
glfwSetKeyCallback(win, [](GLFWwindow* w, int key, int scancode, int action, int mods) glfwSetKeyCallback(m_win, [](GLFWwindow* w, int key, int scancode, int action, int mods)
{ {
auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w)); auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w));
@ -115,19 +114,19 @@ namespace try_engine
case GLFW_PRESS: case GLFW_PRESS:
{ {
system_event::key_pressed_event e { key }; system_event::key_pressed_event e { key };
data->callback(e); data->on_callback(e);
break; break;
} }
case GLFW_RELEASE: case GLFW_RELEASE:
{ {
system_event::key_released_event e { key }; system_event::key_released_event e { key };
data->callback(e); data->on_callback(e);
break; break;
} }
case GLFW_REPEAT: case GLFW_REPEAT:
{ {
system_event::key_pressed_event e { key }; system_event::key_pressed_event e { key };
data->callback(e); data->on_callback(e);
break; break;
} }
} }
@ -177,30 +176,30 @@ namespace try_engine
void window::set_window_callback() void window::set_window_callback()
{ {
glfwSetWindowSizeLimits(win, win_data.width, win_data.height, GLFW_DONT_CARE, GLFW_DONT_CARE); glfwSetWindowSizeLimits(m_win, m_window_data.m_width, m_window_data.m_height, GLFW_DONT_CARE, GLFW_DONT_CARE);
glfwSetWindowSizeCallback(win, [](GLFWwindow* w, int width, int height) glfwSetWindowSizeCallback(m_win, [](GLFWwindow* w, int width, int height)
{ {
auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w)); auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w));
data->width = width; data->m_width = width;
data->height = height; data->m_height = height;
system_event::window_resize_event e { width, height }; system_event::window_resize_event e { width, height };
data->callback(e); data->on_callback(e);
}); });
glfwSetWindowCloseCallback(win, [](GLFWwindow* w) glfwSetWindowCloseCallback(m_win, [](GLFWwindow* w)
{ {
auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w)); auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w));
system_event::window_close_event e; system_event::window_close_event e;
data->callback(e); data->on_callback(e);
}); });
glfwSetWindowFocusCallback(win, [](GLFWwindow* w, int focused) glfwSetWindowFocusCallback(m_win, [](GLFWwindow* w, int focused)
{ {
auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w)); auto data = static_cast<window_data*>(glfwGetWindowUserPointer(w));
system_event::window_focus_event e { focused }; system_event::window_focus_event e { focused };
data->callback(e); data->on_callback(e);
}); });
} }
} }

View File

@ -1,6 +1,6 @@
#pragma once #pragma once
#include "try_engine/utils/include.hpp" #include "try_engine/utils/utils.hpp"
#include "graphic_context/graphic_context.hpp" #include "graphic_context/graphic_context.hpp"
#include "try_engine/event/system_event/event.hpp" #include "try_engine/event/system_event/event.hpp"
@ -12,6 +12,24 @@ namespace try_engine
window(std::string); window(std::string);
~window(); ~window();
// HERE
// реализовать остальные конструкторы
private:
// ни каких unique_ptr тут неполучится
// т.к. glfwCreateWindow maloc-ом выделяет память
// что не есть хорошо для умных указателей
GLFWwindow* m_win;
std::unique_ptr<graphic_context> m_graphic_context;
struct window_data
{
std::string m_name;
int m_width, m_height;
event_callback<system_event::event> on_callback;
} m_window_data;
public: public:
void update(); void update();
GLFWwindow* glfw_window() const; GLFWwindow* glfw_window() const;
@ -21,20 +39,6 @@ namespace try_engine
void set_event_callback(const event_callback<system_event::event>&); void set_event_callback(const event_callback<system_event::event>&);
void set_window_callback(); void set_window_callback();
private:
// ни каких unique_ptr тут неполучится
// т.к. glfwCreateWindow maloc-ом выделяет память
// что не есть хорошо для умных указателей
GLFWwindow* win;
std::unique_ptr<graphic_context> context;
struct window_data
{
std::string title;
int width, height;
event_callback<system_event::event> callback;
} win_data;
private: private:
void set_hint(); void set_hint();
void set_window(); void set_window();