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,28 +0,0 @@
|
||||
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',
|
||||
]
|
||||
|
||||
sources = [
|
||||
'test_panel/test_panel.cpp',
|
||||
'test_panel_2/test_panel_2.cpp',
|
||||
'local_panel/local_panel.cpp',
|
||||
'opengl_panel/opengl_panel.cpp',
|
||||
]
|
||||
|
||||
lib = library(
|
||||
'vertex_engine_sandbox',
|
||||
include_directories : inc,
|
||||
sources: [headers, sources],
|
||||
dependencies : deps,
|
||||
cpp_args: args
|
||||
)
|
||||
|
||||
deps += declare_dependency(
|
||||
include_directories: inc,
|
||||
link_with: lib,
|
||||
)
|
||||
@@ -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;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace sandbox
|
||||
{
|
||||
enum class test_event
|
||||
{
|
||||
TEST_EVEN
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user