fix some tasks and rebase code
This commit is contained in:
parent
81fbfeffbb
commit
1c3d8189e8
@ -1,7 +1,5 @@
|
||||
#include "test_panel.hpp"
|
||||
|
||||
#include "try_engine/utils/keycode.hpp"
|
||||
|
||||
namespace tr::layers
|
||||
{
|
||||
void test_panel::on_attach()
|
||||
@ -16,22 +14,22 @@ namespace tr::layers
|
||||
|
||||
void test_panel::gui_render()
|
||||
{
|
||||
ImGui::SetNextWindowPos(ImVec2(pos_x, pos_y));
|
||||
ImGui::SetNextWindowSize(ImVec2(width, height));
|
||||
ImGui::SetNextWindowPos(ImVec2(m_pos_x, m_pos_y));
|
||||
ImGui::SetNextWindowSize(ImVec2(m_width, m_height));
|
||||
|
||||
BEGIN_IMGUI_WIN("test_win");
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
|
||||
TR_POP_FONT();
|
||||
|
@ -9,13 +9,13 @@ namespace tr::layers
|
||||
BASE_IMPL(test_panel);
|
||||
|
||||
private:
|
||||
bool show = true;
|
||||
bool m_open = true;
|
||||
|
||||
float width = 720.f;
|
||||
float height = 480.f;
|
||||
float m_width = 720.f;
|
||||
float m_height = 480.f;
|
||||
|
||||
float pos_x = 212.f;
|
||||
float pos_y = 35.f;
|
||||
float m_pos_x = 212.f;
|
||||
float m_pos_y = 35.f;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,3 @@
|
||||
#include "try_engine/try_engine.hpp"
|
||||
|
||||
#include "layers/test_panel/test_panel.hpp"
|
||||
|
||||
namespace try_engine_sandbox
|
||||
@ -16,12 +14,12 @@ namespace try_engine_sandbox
|
||||
template<typename... Args>
|
||||
void push_layer(Args... args)
|
||||
{
|
||||
(args->set_event_manager(&em), ...);
|
||||
(args->set_event_manager(&m_event_manager), ...);
|
||||
try_engine::application::push_layer(args...);
|
||||
}
|
||||
|
||||
private:
|
||||
event_manager em;
|
||||
event_manager m_event_manager;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "application.hpp"
|
||||
|
||||
#include "try_engine/utils/define.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
namespace try_engine
|
||||
{
|
||||
@ -8,33 +8,33 @@ namespace try_engine
|
||||
{
|
||||
instance = std::unique_ptr<application>(this);
|
||||
|
||||
win = std::make_unique<window>(app_name);
|
||||
win->set_event_callback(BIND_EVENT_FN(application, on_event));
|
||||
m_win = std::make_unique<window>(app_name);
|
||||
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()
|
||||
{
|
||||
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());
|
||||
|
||||
ui->begin_frame();
|
||||
for (auto l : l_stack)
|
||||
m_gui->begin_frame();
|
||||
for (auto l : m_layers_stack)
|
||||
l->gui_render();
|
||||
ui->end_frame();
|
||||
m_gui->end_frame();
|
||||
|
||||
win->update();
|
||||
m_win->update();
|
||||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<window>& application::get_window()
|
||||
{
|
||||
return win;
|
||||
return m_win;
|
||||
}
|
||||
|
||||
std::unique_ptr<application>& application::get()
|
||||
@ -44,11 +44,11 @@ namespace try_engine
|
||||
|
||||
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)
|
||||
{
|
||||
for(const auto l : l_stack) l->on_event(e);
|
||||
for(const auto l : m_layers_stack) l->on_event(e);
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,13 @@ namespace try_engine
|
||||
application(std::string);
|
||||
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:
|
||||
void run();
|
||||
void attach_layers();
|
||||
@ -22,16 +29,10 @@ namespace try_engine
|
||||
|
||||
public:
|
||||
template<typename... Args>
|
||||
void push_layer(Args*... args) { (l_stack.push_back(args), ...); }
|
||||
|
||||
private:
|
||||
inline static std::unique_ptr<application> instance = nullptr;
|
||||
std::unique_ptr<window> win;
|
||||
layers_stack l_stack;
|
||||
void push_layer(Args*... args) { (m_layers_stack.push_back(args), ...); }
|
||||
|
||||
private:
|
||||
void clear();
|
||||
std::unique_ptr<gui> ui;
|
||||
void on_event(system_event::event& e);
|
||||
};
|
||||
|
||||
|
@ -1,9 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
namespace try_engine::system_event::classificator
|
||||
{
|
||||
// HERE
|
||||
// переменныейц вынести в кофиг
|
||||
inline std::string WINDOW_RESIZE() { return "WINDOW_RESIZE"; }
|
||||
inline std::string WINDOW_CLOSE() { return "WINDOW_CLOSE"; }
|
||||
inline std::string WINDOW_FOCUS() { return "WINDOW_FOCUS"; }
|
||||
|
@ -1,6 +1,6 @@
|
||||
#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/event_classificator.hpp"
|
||||
|
||||
@ -8,14 +8,16 @@ namespace try_engine::system_event
|
||||
{
|
||||
class key_event : public event
|
||||
{
|
||||
// HERE
|
||||
// ???
|
||||
protected:
|
||||
key_event(int kc) : keycode { kc } {}
|
||||
key_event(int kc) : m_keycode { kc } {}
|
||||
|
||||
protected:
|
||||
int m_keycode;
|
||||
|
||||
public:
|
||||
inline int get_keycode() const { return keycode; }
|
||||
|
||||
protected:
|
||||
int keycode;
|
||||
inline int get_keycode() const { return m_keycode; }
|
||||
};
|
||||
|
||||
class key_pressed_event : public key_event
|
||||
|
@ -1,16 +1,11 @@
|
||||
#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/event_classificator.hpp"
|
||||
|
||||
namespace try_engine::system_event
|
||||
{
|
||||
|
||||
|
||||
// Разобрать и привести в порядок по подобию
|
||||
// key_event.hpp
|
||||
//
|
||||
// class MouseMovedEvent : public Event
|
||||
// {
|
||||
// public:
|
||||
|
@ -1,6 +1,6 @@
|
||||
#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/event_classificator.hpp"
|
||||
|
||||
@ -9,17 +9,17 @@ namespace try_engine::system_event
|
||||
class window_resize_event : public event
|
||||
{
|
||||
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:
|
||||
EVENT_CLASS_TYPE_FN(classificator::WINDOW_RESIZE())
|
||||
|
||||
public:
|
||||
inline unsigned int get_width() const { return width; }
|
||||
inline unsigned int get_height() const { return height; }
|
||||
|
||||
private:
|
||||
int width, height;
|
||||
inline unsigned int get_width() const { return m_width; }
|
||||
inline unsigned int get_height() const { return m_height; }
|
||||
};
|
||||
|
||||
class window_close_event : public event
|
||||
@ -34,16 +34,16 @@ namespace try_engine::system_event
|
||||
class window_focus_event : public event
|
||||
{
|
||||
public:
|
||||
window_focus_event(int f) : focused { f } {}
|
||||
window_focus_event(int f) : m_focused { f } {}
|
||||
|
||||
private:
|
||||
int m_focused;
|
||||
|
||||
public:
|
||||
EVENT_CLASS_TYPE_FN(classificator::WINDOW_FOCUS())
|
||||
|
||||
public:
|
||||
inline int get_focused() { return focused; }
|
||||
|
||||
private:
|
||||
int focused;
|
||||
inline int get_focused() { return m_focused; }
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -8,7 +8,6 @@ namespace try_engine::system_event
|
||||
{
|
||||
event() = default;
|
||||
virtual ~event() = default;
|
||||
|
||||
virtual std::string get_name() const = 0;
|
||||
};
|
||||
}
|
||||
|
@ -7,6 +7,8 @@ namespace try_engine
|
||||
{
|
||||
gui::gui()
|
||||
{
|
||||
// HERE
|
||||
// откуда она ???
|
||||
IMGUI_CHECKVERSION();
|
||||
|
||||
ImGui::CreateContext();
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
namespace try_engine
|
||||
{
|
||||
|
@ -11,8 +11,7 @@
|
||||
namespace try_engine::style::fonts
|
||||
{
|
||||
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,
|
||||
16.f, 17.f, 18.f, 19.f, 20.f, 21.f, 22.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 };
|
||||
|
||||
enum font_type
|
||||
{
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
#include "try_engine/event/system_event/event.hpp"
|
||||
|
||||
namespace try_engine
|
||||
@ -16,6 +16,9 @@ namespace try_engine
|
||||
layer(const layer&) = delete;
|
||||
layer(layer&) = delete;
|
||||
|
||||
// HERE
|
||||
// реализовать перемещение слоев
|
||||
|
||||
public:
|
||||
virtual void on_attach() {};
|
||||
virtual void on_detach() {};
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
/*
|
||||
renderer - некий объект отрисовки и разукраски всей сцены.
|
||||
|
@ -4,15 +4,15 @@ namespace try_engine
|
||||
{
|
||||
texture::~texture()
|
||||
{
|
||||
glDeleteTextures(1, &texture_id);
|
||||
glDeleteTextures(1, &m_texture_id);
|
||||
}
|
||||
|
||||
void texture::make()
|
||||
{
|
||||
if (!texture_id)
|
||||
if (!m_texture_id)
|
||||
{
|
||||
glGenTextures(1, &texture_id);
|
||||
glBindTexture(GL_TEXTURE_2D, texture_id);
|
||||
glGenTextures(1, &m_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_MAG_FILTER, GL_LINEAR);
|
||||
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||
@ -21,12 +21,12 @@ namespace try_engine
|
||||
|
||||
void texture::clear()
|
||||
{
|
||||
glDeleteTextures(1, &texture_id);
|
||||
glDeleteTextures(1, &m_texture_id);
|
||||
}
|
||||
|
||||
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::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);
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
namespace try_engine
|
||||
{
|
||||
@ -10,6 +10,9 @@ namespace try_engine
|
||||
texture() = default;
|
||||
~texture();
|
||||
|
||||
private:
|
||||
GLuint m_texture_id = 0;
|
||||
|
||||
public:
|
||||
template<typename Image>
|
||||
void bind(Image& image)
|
||||
@ -23,9 +26,6 @@ namespace try_engine
|
||||
void draw(ImVec2 pos, ImVec2 size);
|
||||
void make();
|
||||
void clear();
|
||||
|
||||
private:
|
||||
GLuint texture_id = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/timestap.hpp"
|
||||
#include "try_engine/utils/define.hpp"
|
||||
#include "try_engine/utils/keycode.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
#include "try_engine/gui/style/style.hpp"
|
||||
|
||||
@ -17,4 +14,3 @@
|
||||
|
||||
#include "try_engine/renderer/renderer.hpp"
|
||||
#include "try_engine/renderer/texture/texture.hpp"
|
||||
|
||||
|
@ -26,10 +26,10 @@
|
||||
if (f.no_bring_to_front) window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus
|
||||
|
||||
#define SET_EVENT_MANAGER_IMPL()\
|
||||
void set_event_manager(event_manager* em_)\
|
||||
void set_event_manager(event_manager* in_event_manager)\
|
||||
{\
|
||||
em = em_;\
|
||||
em->set_event_callback(this);\
|
||||
m_event_manager = in_event_manager;\
|
||||
m_event_manager->set_event_callback(this);\
|
||||
}
|
||||
|
||||
#define BASE_OVERIDE_IMPL()\
|
||||
@ -73,7 +73,7 @@
|
||||
private:\
|
||||
FLAGS_STRUCT_DEFINED();\
|
||||
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()
|
||||
|
@ -17,23 +17,4 @@
|
||||
#include "imgui_impl_glfw.h"
|
||||
#include "imgui_impl_opengl3.h"
|
||||
|
||||
#include "timestap.hpp"
|
||||
|
||||
template<typename Event>
|
||||
using event_callback = std::function<void(Event&)>;
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
||||
|
13
src/try_engine/utils/timestap.hpp → src/try_engine/utils/time.hpp
Executable file → Normal file
13
src/try_engine/utils/timestap.hpp → src/try_engine/utils/time.hpp
Executable file → Normal file
@ -1,5 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "using.hpp"
|
||||
|
||||
namespace try_engine::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;
|
||||
}
|
||||
}
|
||||
|
14
src/try_engine/utils/using.hpp
Normal file
14
src/try_engine/utils/using.hpp
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
5
src/try_engine/utils/utils.hpp
Normal file
5
src/try_engine/utils/utils.hpp
Normal file
@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "keycode.hpp"
|
||||
#include "define.hpp"
|
||||
#include "time.hpp"
|
@ -2,11 +2,11 @@
|
||||
|
||||
namespace try_engine
|
||||
{
|
||||
graphic_context::graphic_context(GLFWwindow* w) : win { w } {}
|
||||
graphic_context::graphic_context(GLFWwindow* w) : m_win { w } {}
|
||||
|
||||
void graphic_context::init()
|
||||
{
|
||||
glfwMakeContextCurrent(win);
|
||||
glfwMakeContextCurrent(m_win);
|
||||
int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
|
||||
|
||||
hack::log(": ")("Glad loader status", status == 1 ? "true" : "false");
|
||||
@ -21,7 +21,7 @@ namespace try_engine
|
||||
|
||||
void graphic_context::swap_buffers()
|
||||
{
|
||||
glfwSwapBuffers(win);
|
||||
glfwSwapBuffers(m_win);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
|
||||
namespace try_engine
|
||||
{
|
||||
@ -9,10 +9,11 @@ namespace try_engine
|
||||
public:
|
||||
graphic_context(GLFWwindow*);
|
||||
|
||||
private:
|
||||
GLFWwindow* m_win;
|
||||
|
||||
public:
|
||||
void init();
|
||||
void swap_buffers();
|
||||
|
||||
private:
|
||||
GLFWwindow* win;
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
#include "window.hpp"
|
||||
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "renderer/renderer.hpp"
|
||||
#include "event/system_event/category/key_event.hpp"
|
||||
#include "event/system_event/category/window_event.hpp"
|
||||
@ -12,7 +11,7 @@ namespace try_engine
|
||||
if (!glfwInit())
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
win_data.title = app_name;
|
||||
m_window_data.m_name = app_name;
|
||||
|
||||
set_hint();
|
||||
set_window();
|
||||
@ -21,16 +20,16 @@ namespace try_engine
|
||||
set_key_callback();
|
||||
set_window_callback();
|
||||
|
||||
hack::log(": ")("Creating window", win_data.title);
|
||||
hack::log(" = ")("w", win_data.width);
|
||||
hack::log(" = ")("h", win_data.height);
|
||||
hack::log(": ")("Creating window", m_window_data.m_name);
|
||||
hack::log(" = ")("w", m_window_data.m_width);
|
||||
hack::log(" = ")("h", m_window_data.m_height);
|
||||
}
|
||||
|
||||
window::~window()
|
||||
{
|
||||
glfwDestroyWindow(win);
|
||||
glfwDestroyWindow(m_win);
|
||||
glfwTerminate();
|
||||
hack::warn(": ")("destroy", "window", win_data.title);
|
||||
hack::warn(": ")("destroy", "window", m_window_data.m_name);
|
||||
}
|
||||
|
||||
void window::set_hint()
|
||||
@ -44,58 +43,58 @@ namespace try_engine
|
||||
|
||||
void window::set_window()
|
||||
{
|
||||
win = glfwCreateWindow(
|
||||
m_win = glfwCreateWindow(
|
||||
glfwGetVideoMode(glfwGetPrimaryMonitor())->width,
|
||||
glfwGetVideoMode(glfwGetPrimaryMonitor())->height,
|
||||
win_data.title.c_str(),
|
||||
m_window_data.m_name.c_str(),
|
||||
nullptr, nullptr
|
||||
);
|
||||
|
||||
if(win == NULL)
|
||||
if(m_win == NULL)
|
||||
{
|
||||
hack::error()("Failed to create GLFW window");
|
||||
glfwTerminate();
|
||||
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()
|
||||
{
|
||||
context = std::make_unique<graphic_context>(win);
|
||||
context->init();
|
||||
m_graphic_context = std::make_unique<graphic_context>(m_win);
|
||||
m_graphic_context->init();
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
win_data.callback = cb;
|
||||
m_window_data.on_callback = cb;
|
||||
}
|
||||
|
||||
GLFWwindow* window::glfw_window() const
|
||||
{
|
||||
return win;
|
||||
return m_win;
|
||||
}
|
||||
|
||||
int window::width() const
|
||||
{
|
||||
return win_data.width;
|
||||
return m_window_data.m_width;
|
||||
}
|
||||
|
||||
int window::height() const
|
||||
{
|
||||
return win_data.height;
|
||||
return m_window_data.m_height;
|
||||
}
|
||||
|
||||
void window::update()
|
||||
{
|
||||
glfwPollEvents();
|
||||
context->swap_buffers();
|
||||
m_graphic_context->swap_buffers();
|
||||
}
|
||||
|
||||
void window::clear() const
|
||||
@ -106,7 +105,7 @@ namespace try_engine
|
||||
|
||||
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));
|
||||
|
||||
@ -115,19 +114,19 @@ namespace try_engine
|
||||
case GLFW_PRESS:
|
||||
{
|
||||
system_event::key_pressed_event e { key };
|
||||
data->callback(e);
|
||||
data->on_callback(e);
|
||||
break;
|
||||
}
|
||||
case GLFW_RELEASE:
|
||||
{
|
||||
system_event::key_released_event e { key };
|
||||
data->callback(e);
|
||||
data->on_callback(e);
|
||||
break;
|
||||
}
|
||||
case GLFW_REPEAT:
|
||||
{
|
||||
system_event::key_pressed_event e { key };
|
||||
data->callback(e);
|
||||
data->on_callback(e);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -177,30 +176,30 @@ namespace try_engine
|
||||
|
||||
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));
|
||||
data->width = width;
|
||||
data->height = height;
|
||||
data->m_width = width;
|
||||
data->m_height = 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));
|
||||
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));
|
||||
system_event::window_focus_event e { focused };
|
||||
data->callback(e);
|
||||
data->on_callback(e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "try_engine/utils/include.hpp"
|
||||
#include "try_engine/utils/utils.hpp"
|
||||
#include "graphic_context/graphic_context.hpp"
|
||||
#include "try_engine/event/system_event/event.hpp"
|
||||
|
||||
@ -12,6 +12,24 @@ namespace try_engine
|
||||
window(std::string);
|
||||
~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:
|
||||
void update();
|
||||
GLFWwindow* glfw_window() const;
|
||||
@ -21,20 +39,6 @@ namespace try_engine
|
||||
void set_event_callback(const event_callback<system_event::event>&);
|
||||
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:
|
||||
void set_hint();
|
||||
void set_window();
|
||||
|
Reference in New Issue
Block a user