add new struct and events
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
#include "local_panel.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
void local_panel::on_attach()
|
||||
{
|
||||
VE::CONNECT(this);
|
||||
}
|
||||
|
||||
void local_panel::render()
|
||||
{
|
||||
|
||||
if (ImGui::Button(VE_NAME("RUN thread"), ImVec2(128, 130)))
|
||||
{
|
||||
auto f = []()
|
||||
{
|
||||
VE::EMIT(test_event::TEST_EVEN, std::string("test event message from thread"));
|
||||
};
|
||||
std::thread th(f);
|
||||
th.detach();
|
||||
}
|
||||
|
||||
VE_PUSH_FONT(ICON, 18);
|
||||
|
||||
if (ImGui::Button(VE::style::icon::ICON_STOP, ImVec2(28, 30)))
|
||||
{
|
||||
VE::EMIT(test_event::TEST_EVEN, std::string("test icon button"));
|
||||
}
|
||||
|
||||
ImGui::Text(VE::style::icon::ICON_PAINT_BRUSH, " Paint" );
|
||||
ImGui::Text("\xef\x87\xbc");
|
||||
|
||||
VE_POP_FONT();
|
||||
}
|
||||
|
||||
void local_panel::on_event(VE::event e)
|
||||
{
|
||||
// для событий от перефирии
|
||||
// if (e.m_type.type() == typeid(VE::event_type))
|
||||
// {
|
||||
// auto t = std::any_cast<VE::event_type>(e.m_type);
|
||||
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
|
||||
// hack::log()((int)t);
|
||||
// }
|
||||
|
||||
if (e.m_type.type() == typeid(test_event))
|
||||
{
|
||||
auto t = std::any_cast<test_event>(e.m_type);
|
||||
if (t == test_event::TEST_EVEN)
|
||||
hack::log()(std::any_cast<std::string>(e.m_data));
|
||||
}
|
||||
}
|
||||
|
||||
void local_panel::update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <VE.hpp>
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class local_panel : public VE::layer
|
||||
{
|
||||
VE_FN_OVERIDE();
|
||||
|
||||
ImVec2 m_size = ImVec2{ 800.f, 400.f };
|
||||
ImVec2 m_pos = ImVec2{ 400.f, 400.f };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
#include "opengl_panel.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
cube::cube()
|
||||
{
|
||||
hack::log()("create cube");
|
||||
|
||||
const std::filesystem::path vsp { "/mnt/raid/projects/vertex_engine/vertex_engine/bin/layers/opengl_panel/shaders/vertes.shader" };
|
||||
const std::filesystem::path fsp { "/mnt/raid/projects/vertex_engine/vertex_engine/bin/layers/opengl_panel/shaders/frag.shader" };
|
||||
add_shader(GL_VERTEX_SHADER, vsp);
|
||||
add_shader(GL_FRAGMENT_SHADER, fsp);
|
||||
shader_program::link();
|
||||
|
||||
m_vertices =
|
||||
{
|
||||
-0.1f, 0.0f, 0.7f,
|
||||
0.1f, 0.0f, 0.7f,
|
||||
0.1f, 0.0f, -0.7f,
|
||||
-0.1f, 0.0f, -0.7f,
|
||||
0.0f, 0.3f, 0.0f
|
||||
};
|
||||
|
||||
m_indices =
|
||||
{
|
||||
0, 1, 1, 4, 4, 0,
|
||||
0, 3, 3, 4, 4, 2,
|
||||
2, 1, 3, 2
|
||||
};
|
||||
|
||||
buffer::link();
|
||||
}
|
||||
|
||||
void cube::use() { shader_program::use(); }
|
||||
|
||||
void cube::set_scale(float val) { set("scale", val); }
|
||||
|
||||
void cube::set_position(glm::vec3 val) { set("position", val); }
|
||||
|
||||
void cube::set_color(glm::vec4 val) { set("color", val); }
|
||||
|
||||
void cube::render() { buffer::render(); }
|
||||
|
||||
|
||||
// OPENGL_PANEL_LAYER
|
||||
|
||||
void opengl_panel::on_attach()
|
||||
{
|
||||
hack::log()("on_attach");
|
||||
}
|
||||
|
||||
void opengl_panel::update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void opengl_panel::render()
|
||||
{
|
||||
m_cb_1.use();
|
||||
m_cam.update(m_cb_1);
|
||||
|
||||
float r = std::sin(glfwGetTime());
|
||||
float g = std::cos(glfwGetTime());
|
||||
m_cb_1.set_color(glm::vec4{ 0.85f, 0.45f, 0.95f, 0.f }); // розовый
|
||||
m_cb_1.set_scale(1.0f + std::sin(glfwGetTime()) * 0.2f);
|
||||
m_cb_1.set_position(glm::vec3{ 0.f, 0.5, 0.f });
|
||||
m_cb_1.render();
|
||||
|
||||
r = std::cos(glfwGetTime());
|
||||
g = std::sin(glfwGetTime());
|
||||
m_cb_2.use();
|
||||
|
||||
m_cam.update(m_cb_2);
|
||||
|
||||
m_cb_2.set_color(glm::vec4{ 0.66f, 0.66f, 0.66f, 0.f }); // серый/белый
|
||||
m_cb_2.set_scale(1.0f - std::cos(glfwGetTime()) * 0.2f);
|
||||
m_cb_2.set_position(glm::vec3{ r, g, 0.f });
|
||||
m_cb_2.render();
|
||||
}
|
||||
|
||||
void opengl_panel::on_event(VE::event e)
|
||||
{
|
||||
// для событий от перефирии
|
||||
if (e.m_type.type() == typeid(VE::event_type))
|
||||
{
|
||||
auto t = std::any_cast<VE::event_type>(e.m_type);
|
||||
if (t == VE::event_type::MOUSE_CURSOR_POSITION)
|
||||
{
|
||||
auto [pos_x, pos_y] = std::any_cast<std::pair<float, float>>(e.m_data);
|
||||
m_cam.mouse_callback(pos_x, pos_y);
|
||||
}
|
||||
|
||||
if (t == VE::event_type::KEY_REPEATE || t == VE::event_type::KEY_PRESSED)
|
||||
{
|
||||
auto key = std::any_cast<int>(e.m_data);
|
||||
if (key == VE::key::W)
|
||||
m_cam.up();
|
||||
if (key == VE::key::S)
|
||||
m_cam.down();
|
||||
if (key == VE::key::A)
|
||||
m_cam.left();
|
||||
if (key == VE::key::D)
|
||||
m_cam.right();
|
||||
}
|
||||
}
|
||||
|
||||
if (e.m_type.type() == typeid(test_event))
|
||||
{
|
||||
auto t = std::any_cast<test_event>(e.m_type);
|
||||
if (t == test_event::TEST_EVEN)
|
||||
hack::log()(std::any_cast<std::string>(e.m_data));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <VE.hpp>
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class cube : public VE::opengl
|
||||
{
|
||||
public:
|
||||
cube();
|
||||
~cube() = default;
|
||||
|
||||
public:
|
||||
void set_scale(float val);
|
||||
void set_position(glm::vec3 val);
|
||||
void set_color(glm::vec4 val);
|
||||
void use();
|
||||
void render();
|
||||
};
|
||||
|
||||
struct camera
|
||||
{
|
||||
// Начальное положение камеры
|
||||
glm::vec3 m_pos = glm::vec3{ 0.0f, 0.0f, 3.0f };
|
||||
glm::vec3 m_front = glm::vec3{ 0.0f, 0.0f, -1.0f };
|
||||
glm::vec3 m_up = glm::vec3{ 0.0f, 1.0f, 0.0f };
|
||||
float m_speed = 0.05f;
|
||||
|
||||
glm::mat4 m_view, m_projection;
|
||||
|
||||
void up() { m_pos += m_speed * m_front; }
|
||||
void down() { m_pos -= m_speed * m_front; }
|
||||
void left() { m_pos -= glm::normalize(glm::cross(m_front, m_up)) * m_speed; }
|
||||
void right() { m_pos += glm::normalize(glm::cross(m_front, m_up)) * m_speed; }
|
||||
|
||||
template<typename T>
|
||||
void update(const T& obj)
|
||||
{
|
||||
m_view = glm::lookAt(m_pos, m_pos + m_front, m_up);
|
||||
m_projection = glm::perspective(glm::radians(45.0f),
|
||||
static_cast<float>(VE::application::get()->get_glfw()->width()) / VE::application::get()->get_glfw()->height(),
|
||||
0.1f, 100.0f);
|
||||
|
||||
glUniformMatrix4fv(glGetUniformLocation(obj.get_id(), "view"), 1, GL_FALSE, glm::value_ptr(m_view));
|
||||
glUniformMatrix4fv(glGetUniformLocation(obj.get_id(), "projection"), 1, GL_FALSE, glm::value_ptr(m_projection));
|
||||
}
|
||||
|
||||
// Управление камерой через мышь
|
||||
bool m_first = true;
|
||||
float m_yaw = -90.0f;
|
||||
float m_pitch = 0.0f;
|
||||
float m_last_x = 400, m_last_y = 300;
|
||||
|
||||
void mouse_callback(double xpos, double ypos)
|
||||
{
|
||||
if (m_first)
|
||||
{
|
||||
m_last_x = xpos;
|
||||
m_last_y = ypos;
|
||||
m_first = false;
|
||||
}
|
||||
|
||||
float x_offset = xpos - m_last_x;
|
||||
float y_offset = m_last_y - ypos;
|
||||
m_last_x = xpos;
|
||||
m_last_y = ypos;
|
||||
|
||||
float sensitivity = 0.1f;
|
||||
x_offset *= sensitivity;
|
||||
y_offset *= sensitivity;
|
||||
|
||||
m_yaw += x_offset;
|
||||
m_pitch += y_offset;
|
||||
|
||||
if (m_pitch > 89.0f) m_pitch = 89.0f;
|
||||
if (m_pitch < -89.0f) m_pitch = -89.0f;
|
||||
|
||||
glm::vec3 front;
|
||||
front.x = std::cos(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
|
||||
front.y = std::sin(glm::radians(m_pitch));
|
||||
front.z = std::sin(glm::radians(m_yaw)) * std::cos(glm::radians(m_pitch));
|
||||
m_front = glm::normalize(front);
|
||||
}
|
||||
};
|
||||
|
||||
class opengl_panel : public VE::layer
|
||||
{
|
||||
VE_FN_OVERIDE();
|
||||
|
||||
cube m_cb_1;
|
||||
cube m_cb_2;
|
||||
camera m_cam;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
in vec4 v_color;
|
||||
out vec4 f_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
f_color = v_color;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
#version 330 core
|
||||
|
||||
layout (location = 0) in vec3 base_position;
|
||||
|
||||
uniform float scale;
|
||||
uniform vec4 color;
|
||||
uniform vec3 position;
|
||||
|
||||
uniform mat4 view;
|
||||
uniform mat4 model;
|
||||
uniform mat4 projection;
|
||||
|
||||
out vec4 v_color;
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 p = base_position + position * scale ;
|
||||
gl_Position = projection * view * vec4(p, 1.0);
|
||||
v_color = color;
|
||||
}
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
#include "test_panel.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
void test_panel::on_attach()
|
||||
{
|
||||
VE::CONNECT(this);
|
||||
hack::log()("on_attach", VE::application::get()->get_glfw()->width());
|
||||
}
|
||||
|
||||
void test_panel::render()
|
||||
{
|
||||
ImGui::SetNextWindowPos(m_pos);
|
||||
ImGui::SetNextWindowSize(m_size);
|
||||
|
||||
if (!ImGui::Begin("#test_panel_1", &m_p_open, m_window_flags)) ImGui::End();
|
||||
|
||||
if (ImGui::Button("RUN test_panel_1", ImVec2(128, 130)))
|
||||
{
|
||||
VE::EMIT(test_event::TEST_EVEN, std::string("test event message tp 1"));
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void test_panel::on_event(VE::event e)
|
||||
{
|
||||
if (e.m_type.type() == typeid(VE::event_type))
|
||||
{
|
||||
auto t = std::any_cast<VE::event_type>(e.m_type);
|
||||
if (t == VE::event_type::MOUSE_BUTTON_DOUBLE_PRESSED) hack::log()("double");
|
||||
if (t == VE::event_type::MOUSE_BUTTON_PRESSED) hack::log()("once");
|
||||
}
|
||||
|
||||
if (e.m_type.type() == typeid(test_event))
|
||||
{
|
||||
auto t = std::any_cast<test_event>(e.m_type);
|
||||
if (t == test_event::TEST_EVEN)
|
||||
hack::log()(std::any_cast<std::string>(e.m_data));
|
||||
}
|
||||
}
|
||||
|
||||
void test_panel::update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <VE.hpp>
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class test_panel : public VE::layer
|
||||
{
|
||||
VE_FN_OVERIDE();
|
||||
|
||||
ImVec2 m_size = ImVec2{ 600.f, 100.f };
|
||||
ImVec2 m_pos = ImVec2{ 100.f, 100.f };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
#include "test_panel_2.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
void test_panel_2::on_attach()
|
||||
{
|
||||
VE::CONNECT(this);
|
||||
|
||||
// ATTENTION: активировать сигнальную систему в детях-компонентах
|
||||
m_local_panel.on_attach();
|
||||
|
||||
// for (int i = 0; i < 200; ++i)
|
||||
// {
|
||||
// auto lp = std::make_shared<local_panel>();
|
||||
// lp->on_attach();
|
||||
// m_local_panel_hub.push_back(lp);
|
||||
// }
|
||||
|
||||
auto lp = std::make_shared<local_panel>();
|
||||
lp->on_attach();
|
||||
m_local_panel_hub.push_back(lp);
|
||||
|
||||
hack::log()("on_attach");
|
||||
}
|
||||
|
||||
void test_panel_2::render()
|
||||
{
|
||||
ImGui::SetNextWindowPos(m_pos);
|
||||
ImGui::SetNextWindowSize(m_size);
|
||||
|
||||
if (!ImGui::Begin("#test_panel_2", &m_p_open, m_window_flags)) ImGui::End();
|
||||
|
||||
m_local_panel.render();
|
||||
|
||||
for(auto& lp : m_local_panel_hub) lp->render();
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void test_panel_2::on_event(VE::event e)
|
||||
{
|
||||
// для событий от перефирии
|
||||
// if (e.m_type.type() == typeid(VE::event_type))
|
||||
// {
|
||||
// auto t = std::any_cast<VE::event_type>(e.m_type);
|
||||
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
|
||||
// hack::log()((int)t);
|
||||
// }
|
||||
|
||||
if (e.m_type.type() == typeid(test_event))
|
||||
{
|
||||
auto t = std::any_cast<test_event>(e.m_type);
|
||||
if (t == test_event::TEST_EVEN)
|
||||
hack::log()(std::any_cast<std::string>(e.m_data));
|
||||
}
|
||||
}
|
||||
|
||||
void test_panel_2::update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <VE.hpp>
|
||||
|
||||
#include "local_panel/local_panel.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class test_panel_2 : public VE::layer
|
||||
{
|
||||
VE_FN_OVERIDE();
|
||||
|
||||
ImVec2 m_size = ImVec2{ 400.f, 400.f };
|
||||
ImVec2 m_pos = ImVec2{ 400.f, 400.f };
|
||||
|
||||
local_panel m_local_panel;
|
||||
|
||||
std::vector<std::shared_ptr<local_panel>> m_local_panel_hub;
|
||||
};
|
||||
}
|
||||
|
||||
39
bin/main.cpp
39
bin/main.cpp
@@ -1,39 +0,0 @@
|
||||
#include "layers/test_panel/test_panel.hpp"
|
||||
#include "layers/test_panel_2/test_panel_2.hpp"
|
||||
#include "layers/opengl_panel/opengl_panel.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class test_app : public VE::application
|
||||
{
|
||||
public:
|
||||
test_app(std::string app_name) : VE::application{ app_name } {};
|
||||
~test_app() = default;
|
||||
};
|
||||
}
|
||||
|
||||
namespace VE
|
||||
{
|
||||
inline application& create()
|
||||
{
|
||||
static sandbox::test_app app{ "vertex_engine_sandbox" };
|
||||
|
||||
// ATTENTEION: это слои для отрисовки.
|
||||
// если делается компонент, который является составляющей этих компонентов, то
|
||||
// нужно вызывать метод on_attach внутри хозяев для работы сигнальной системы.
|
||||
// см. пример в test_panel_2
|
||||
app.push_layer(
|
||||
new sandbox::test_panel{},
|
||||
new sandbox::test_panel_2{},
|
||||
new sandbox::opengl_panel{}
|
||||
);
|
||||
|
||||
return app;
|
||||
}
|
||||
}
|
||||
|
||||
auto main(int argc, char* args[]) -> int
|
||||
{
|
||||
decltype(auto) app = VE::create();
|
||||
app.run();
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
inc += include_directories('.')
|
||||
|
||||
headers = [
|
||||
'test_panel/test_panel.hpp',
|
||||
'test_panel_2/test_panel_2.hpp',
|
||||
'local_panel/local_panel.hpp',
|
||||
'opengl_panel/opengl_panel.hpp',
|
||||
'ui_layer/ui_layer.hpp',
|
||||
]
|
||||
|
||||
sources = [
|
||||
'test_panel/test_panel.cpp',
|
||||
'test_panel_2/test_panel_2.cpp',
|
||||
'local_panel/local_panel.cpp',
|
||||
'opengl_panel/opengl_panel.cpp',
|
||||
'ui_layer/ui_layer.cpp',
|
||||
]
|
||||
|
||||
lib = library(
|
||||
46
example/layers/ui_layer/ui_layer.cpp
Executable file
46
example/layers/ui_layer/ui_layer.cpp
Executable file
@@ -0,0 +1,46 @@
|
||||
#include "ui_layer.hpp"
|
||||
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
void ui_layer::on_attach()
|
||||
{
|
||||
VE::CONNECT(this);
|
||||
|
||||
hack::log()("on_attach");
|
||||
}
|
||||
|
||||
void ui_layer::render()
|
||||
{
|
||||
// VE::WinPos(m_pos);
|
||||
// VE::WinSize(m_pos);
|
||||
|
||||
VE::Begin("name", m_pos, m_size, m_win_flags);
|
||||
VE::End();
|
||||
}
|
||||
|
||||
void ui_layer::on_event(VE::event e)
|
||||
{
|
||||
// для событий от перефирии
|
||||
// if (e.m_type.type() == typeid(VE::event_type))
|
||||
// {
|
||||
// auto t = std::any_cast<VE::event_type>(e.m_type);
|
||||
// if (t != VE::event_type::MOUSE_CURSOR_POSITION)
|
||||
// hack::log()((int)t);
|
||||
// }
|
||||
|
||||
if (e.m_type.type() == typeid(test_event))
|
||||
{
|
||||
auto t = std::any_cast<test_event>(e.m_type);
|
||||
if (t == test_event::TEST_EVEN)
|
||||
hack::log()(std::any_cast<std::string>(e.m_data));
|
||||
}
|
||||
}
|
||||
|
||||
void ui_layer::update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
15
example/layers/ui_layer/ui_layer.hpp
Executable file
15
example/layers/ui_layer/ui_layer.hpp
Executable file
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <VE.hpp>
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class ui_layer : public VE::layer, public VE::flags
|
||||
{
|
||||
VE_OVERIDE();
|
||||
|
||||
ImVec2 m_size = ImVec2{ 400.f, 400.f };
|
||||
ImVec2 m_pos = ImVec2{ 400.f, 400.f };
|
||||
};
|
||||
}
|
||||
|
||||
21
example/main.cpp
Executable file
21
example/main.cpp
Executable file
@@ -0,0 +1,21 @@
|
||||
#include "layers/ui_layer/ui_layer.hpp"
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
class app : public VE::application
|
||||
{
|
||||
public:
|
||||
app(std::string app_name) : VE::application{ app_name } {};
|
||||
~app() = default;
|
||||
};
|
||||
}
|
||||
|
||||
auto main(int argc, char* args[]) -> int
|
||||
{
|
||||
sandbox::app app{ "vertex_engine_sandbox" };
|
||||
|
||||
app.push_layer(
|
||||
new sandbox::ui_layer{}
|
||||
);
|
||||
app.run();
|
||||
}
|
||||
@@ -50,6 +50,5 @@ inc = []
|
||||
#############################################################
|
||||
|
||||
subdir('src')
|
||||
subdir('bin/layers')
|
||||
subdir('bin')
|
||||
#subdir('tests')
|
||||
subdir('example/layers')
|
||||
subdir('example')
|
||||
|
||||
2
run.sh
2
run.sh
@@ -6,7 +6,7 @@ run() {
|
||||
command meson compile -C build
|
||||
if [[ -z "$1" ]]; then
|
||||
cd build
|
||||
./bin/$PROJECT_NAME
|
||||
./example/$PROJECT_NAME
|
||||
cd ..
|
||||
else
|
||||
meson test $1 -C build
|
||||
|
||||
15
src/VE.hpp
15
src/VE.hpp
@@ -1,11 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include "event/event.hpp" // IWYU pragma: keep
|
||||
#include "event/api.hpp" // IWYU pragma: keep
|
||||
#include "event/event_manager.hpp" // IWYU pragma: keep
|
||||
#include "event/type.hpp" // IWYU pragma: keep
|
||||
|
||||
#include "gui/gui.hpp" // IWYU pragma: keep
|
||||
#include "gui/flags.hpp" // IWYU pragma: keep
|
||||
#include "gui/api/win.hpp" // IWYU pragma: keep
|
||||
#include "gui/style/icons.hpp" // IWYU pragma: keep
|
||||
#include "gui/style/fonts.hpp" // IWYU pragma: keep
|
||||
|
||||
#include "utils/utils.hpp" // IWYU pragma: keep
|
||||
#include "application/application.hpp" // IWYU pragma: keep
|
||||
#include "event/event.hpp" // IWYU pragma: keep
|
||||
#include "layer/layer.hpp" // IWYU pragma: keep
|
||||
#include "glfw/glfw.hpp" // IWYU pragma: keep
|
||||
#include "gui/gui.hpp" // IWYU pragma: keep
|
||||
#include "gui/style/icons.hpp" // IWYU pragma: keep
|
||||
#include "gui/style/fonts.hpp" // IWYU pragma: keep
|
||||
#include "opengl/opengl.hpp" // IWYU pragma: keep
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "application.hpp"
|
||||
|
||||
#include "utils/utils.hpp" // IWYU pragma: keep
|
||||
#include "utils/utils.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
|
||||
23
src/event/api.hpp
Executable file
23
src/event/api.hpp
Executable file
@@ -0,0 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "event_manager.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
template <typename T>
|
||||
void CONNECT(T* obj)
|
||||
{
|
||||
event_manager::instance().connect(obj, &T::on_event);
|
||||
}
|
||||
|
||||
template <typename TYPE, typename DATA>
|
||||
void EMIT(TYPE t, DATA d, int id = -1)
|
||||
{
|
||||
event_manager::instance().emit(event{ t, d, id });
|
||||
}
|
||||
|
||||
inline void EMIT(event e)
|
||||
{
|
||||
event_manager::instance().emit(e);
|
||||
}
|
||||
}
|
||||
@@ -1,32 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "utils/utils.hpp" // IWYU pragma: keep
|
||||
#include <any>
|
||||
|
||||
namespace VE
|
||||
{
|
||||
enum class event_type
|
||||
{
|
||||
KEY_PRESSED,
|
||||
KEY_RELEASED,
|
||||
KEY_REPEATE,
|
||||
|
||||
MOUSE_BUTTON_PRESSED,
|
||||
MOUSE_BUTTON_DOUBLE_PRESSED,
|
||||
MOUSE_BUTTON_RELEASED,
|
||||
|
||||
MOUSE_CURSOR_POSITION,
|
||||
MOUSE_SCROLL,
|
||||
|
||||
WINDOW_RESIZE,
|
||||
WINDOW_CLOSE,
|
||||
WINDOW_FOCUS,
|
||||
};
|
||||
|
||||
enum class event_target
|
||||
{
|
||||
VE
|
||||
};
|
||||
|
||||
struct event
|
||||
{
|
||||
event(std::any type, std::any data, int id) : m_type{ type }, m_data{ data }, m_id { id } {}
|
||||
@@ -36,52 +13,4 @@ namespace VE
|
||||
std::any m_data;
|
||||
int m_id;
|
||||
};
|
||||
|
||||
struct event_manager : public hack::patterns::singleton<event_manager>
|
||||
{
|
||||
std::vector<VE::event_fn<VE::event>> m_funcs;
|
||||
|
||||
template<typename T>
|
||||
void connect(T* obj, void (T::*method)(event))
|
||||
{
|
||||
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void emit(event e)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (std::size_t i = 0; i < m_funcs.size(); ++i)
|
||||
{
|
||||
m_funcs[i](e);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
hack::error()(ex.what());
|
||||
hack::log()("size funcs", m_funcs.size());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
hack::error()("ooops...");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void CONNECT(T* obj)
|
||||
{
|
||||
VE::event_manager::instance().connect(obj, &T::on_event);
|
||||
}
|
||||
|
||||
template <typename TYPE, typename DATA>
|
||||
void EMIT(TYPE t, DATA d, int id = -1)
|
||||
{
|
||||
VE::event_manager::instance().emit(VE::event{ t, d, id });
|
||||
}
|
||||
|
||||
inline void EMIT(VE::event e)
|
||||
{
|
||||
VE::event_manager::instance().emit(e);
|
||||
}
|
||||
}
|
||||
|
||||
41
src/event/event_manager.hpp
Executable file
41
src/event/event_manager.hpp
Executable file
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <hack/patterns/singleton.hpp>
|
||||
#include <hack/logger/logger.hpp>
|
||||
|
||||
#include "event.hpp"
|
||||
#include "utils/using.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
struct event_manager : public hack::patterns::singleton<event_manager>
|
||||
{
|
||||
std::vector<event_fn<event>> m_funcs;
|
||||
|
||||
template<typename T>
|
||||
void connect(T* obj, void (T::*method)(event))
|
||||
{
|
||||
m_funcs.push_back(std::bind(method, obj, std::placeholders::_1));
|
||||
}
|
||||
|
||||
void emit(event e)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (std::size_t i = 0; i < m_funcs.size(); ++i)
|
||||
{
|
||||
m_funcs[i](e);
|
||||
}
|
||||
}
|
||||
catch(const std::exception& ex)
|
||||
{
|
||||
hack::error()(ex.what());
|
||||
hack::log()("size funcs", m_funcs.size());
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
hack::error()("ooops...");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
28
src/event/type.hpp
Normal file
28
src/event/type.hpp
Normal file
@@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
namespace VE
|
||||
{
|
||||
enum class event_type
|
||||
{
|
||||
KEY_PRESSED,
|
||||
KEY_RELEASED,
|
||||
KEY_REPEATE,
|
||||
|
||||
MOUSE_BUTTON_PRESSED,
|
||||
MOUSE_BUTTON_DOUBLE_PRESSED,
|
||||
MOUSE_BUTTON_RELEASED,
|
||||
|
||||
MOUSE_CURSOR_POSITION,
|
||||
MOUSE_SCROLL,
|
||||
|
||||
WINDOW_RESIZE,
|
||||
WINDOW_CLOSE,
|
||||
WINDOW_FOCUS,
|
||||
};
|
||||
|
||||
enum class event_target
|
||||
{
|
||||
VE
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "glfw.hpp"
|
||||
|
||||
#include "event/event.hpp"
|
||||
#include "event/type.hpp"
|
||||
#include "event/api.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
|
||||
@@ -8,8 +8,6 @@ namespace VE
|
||||
class glfw
|
||||
{
|
||||
public:
|
||||
// HERE
|
||||
// реализовать остальные конструкторы
|
||||
glfw();
|
||||
~glfw();
|
||||
|
||||
|
||||
43
src/gui/api/win.hpp
Normal file
43
src/gui/api/win.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
|
||||
namespace VE
|
||||
{
|
||||
inline void WinPos(ImVec2 pos)
|
||||
{
|
||||
ImGui::SetNextWindowPos(pos);
|
||||
}
|
||||
|
||||
inline void WinSize(ImVec2 size)
|
||||
{
|
||||
ImGui::SetNextWindowSize(size);
|
||||
}
|
||||
|
||||
inline void End()
|
||||
{
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
inline void Begin(std::string name, ImVec2 pos, ImVec2 size, bool& open, ImGuiWindowFlags win_flags)
|
||||
{
|
||||
WinPos(pos);
|
||||
WinSize(size);
|
||||
|
||||
if (!ImGui::Begin(name.c_str(), &open, win_flags)) End();
|
||||
}
|
||||
|
||||
inline void Begin(std::string name, ImVec2 pos, ImVec2 size, ImGuiWindowFlags win_flags)
|
||||
{
|
||||
WinPos(pos);
|
||||
WinSize(size);
|
||||
|
||||
if (!ImGui::Begin(name.c_str(), nullptr, win_flags)) End();
|
||||
}
|
||||
|
||||
inline void Begin(std::string name, ImGuiWindowFlags win_flags)
|
||||
{
|
||||
if (!ImGui::Begin(name.c_str(), nullptr, win_flags)) End();
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,20 @@ namespace VE
|
||||
{
|
||||
flags()
|
||||
{
|
||||
if (m_no_titlebar) m_window_flags |= ImGuiWindowFlags_NoTitleBar;
|
||||
if (m_no_scrollbar) m_window_flags |= ImGuiWindowFlags_NoScrollbar;
|
||||
if (!m_no_menu) m_window_flags |= ImGuiWindowFlags_MenuBar;
|
||||
if (m_no_move) m_window_flags |= ImGuiWindowFlags_NoMove;
|
||||
if (m_no_resize) m_window_flags |= ImGuiWindowFlags_NoResize;
|
||||
if (m_no_collapse) m_window_flags |= ImGuiWindowFlags_NoCollapse;
|
||||
if (m_no_nav) m_window_flags |= ImGuiWindowFlags_NoNav;
|
||||
if (m_no_background) m_window_flags |= ImGuiWindowFlags_NoBackground;
|
||||
if (m_no_bring_to_front) m_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
if (m_no_titlebar) m_win_flags |= ImGuiWindowFlags_NoTitleBar;
|
||||
if (m_no_scrollbar) m_win_flags |= ImGuiWindowFlags_NoScrollbar;
|
||||
if (!m_no_menu) m_win_flags |= ImGuiWindowFlags_MenuBar;
|
||||
if (m_no_move) m_win_flags |= ImGuiWindowFlags_NoMove;
|
||||
if (m_no_resize) m_win_flags |= ImGuiWindowFlags_NoResize;
|
||||
if (m_no_collapse) m_win_flags |= ImGuiWindowFlags_NoCollapse;
|
||||
if (m_no_nav) m_win_flags |= ImGuiWindowFlags_NoNav;
|
||||
if (m_no_background) m_win_flags |= ImGuiWindowFlags_NoBackground;
|
||||
if (m_no_bring_to_front) m_win_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus;
|
||||
}
|
||||
|
||||
virtual ~flags() = default;
|
||||
|
||||
bool m_p_open = false;
|
||||
bool m_open = false;
|
||||
|
||||
bool m_no_titlebar = true;
|
||||
bool m_no_scrollbar = true;
|
||||
@@ -34,6 +34,6 @@ namespace VE
|
||||
bool m_no_bring_to_front = false;
|
||||
bool m_no_docking = true;
|
||||
|
||||
ImGuiWindowFlags m_window_flags = 0;
|
||||
ImGuiWindowFlags m_win_flags = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "event/event.hpp"
|
||||
#include "gui/flags.hpp"
|
||||
#include "utils/using.hpp"
|
||||
|
||||
namespace VE
|
||||
{
|
||||
class layer : public flags
|
||||
class layer
|
||||
{
|
||||
using time = time::timestep<float>;
|
||||
|
||||
public:
|
||||
layer() = default;
|
||||
virtual ~layer() = default;
|
||||
|
||||
@@ -17,7 +17,7 @@ headers = [
|
||||
'utils/define.hpp',
|
||||
'utils/include.hpp',
|
||||
'utils/keycode.hpp',
|
||||
'utils/time.hpp',
|
||||
# 'utils/time.hpp',
|
||||
'utils/using.hpp',
|
||||
'utils/var.hpp',
|
||||
'utils/utils.hpp',
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#define BIT(x)\
|
||||
(1 << x)
|
||||
|
||||
#define VE_FN_OVERIDE()\
|
||||
#define VE_OVERIDE()\
|
||||
public:\
|
||||
void on_attach() override;\
|
||||
void render() override;\
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
#include <glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <hack/logger/logger.hpp>
|
||||
#include <hack/patterns/singleton.hpp>
|
||||
#include <imgui.h>
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include "using.hpp" // IWYU pragma: keep
|
||||
#include <glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
namespace VE::time
|
||||
namespace VE
|
||||
{
|
||||
template<typename Time>
|
||||
template<typename Type = float>
|
||||
class timestep
|
||||
{
|
||||
public:
|
||||
timestep(Time data_ = 0.0f) : data { data_ } {}
|
||||
timestep(Type data_ = 0.0f) : data { data_ } {}
|
||||
|
||||
operator Time() const { return data; }
|
||||
operator Type() const { return data; }
|
||||
|
||||
Time get_seconds() const { return data; }
|
||||
Time get_milliseconds() const { return data * 1000.0f; }
|
||||
Type get_seconds() const { return data; }
|
||||
Type get_milliseconds() const { return data * 1000.0f; }
|
||||
|
||||
private:
|
||||
Time data;
|
||||
Type data;
|
||||
};
|
||||
}
|
||||
|
||||
namespace VE::time
|
||||
namespace VE
|
||||
{
|
||||
inline timestep<float> get_time()
|
||||
{
|
||||
@@ -28,7 +29,6 @@ namespace VE::time
|
||||
float t = (float)glfwGetTime();
|
||||
timestep<float> ts = t - frame_time;
|
||||
frame_time = t;
|
||||
|
||||
return ts;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "include.hpp" // IWYU pragma: keep
|
||||
#include <functional>
|
||||
|
||||
namespace VE
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user