Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update editor_ui #80

Merged
merged 1 commit into from
Apr 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions engine/source/editor/include/editor_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ namespace Pilot
void createComponentUI(Reflection::ReflectionInstance& instance);
void createLeafNodeUI(Reflection::ReflectionInstance& instance);
std::string getLeafUINodeParentLabel();
bool isCursorInRect(Vector2 pos, Vector2 size) const;

void showEditorUI();
void showEditorMenu(bool* p_open);
Expand Down
14 changes: 8 additions & 6 deletions engine/source/editor/source/editor_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ namespace Pilot
return parent_label;
}

bool EditorUI::isCursorInRect(Vector2 pos, Vector2 size) const
{
return pos.x <= m_mouse_x && m_mouse_x <= pos.x + size.x && pos.y <= m_mouse_y && m_mouse_y <= pos.y + size.y;
}

GObject* EditorUI::getSelectedGObject() const
{
GObject* selected_object = nullptr;
Expand Down Expand Up @@ -923,8 +928,7 @@ namespace Pilot
{
glfwSetInputMode(m_io->m_window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);

if (m_mouse_x > m_engine_window_pos.x && m_mouse_x < (m_engine_window_pos.x + m_engine_window_size.x) &&
m_mouse_y > m_engine_window_pos.y && m_mouse_y < (m_engine_window_pos.y + m_engine_window_size.y))
if (isCursorInRect(m_engine_window_pos, m_engine_window_size))
{
Vector2 cursor_uv = Vector2((m_mouse_x - m_engine_window_pos.x) / m_engine_window_size.x,
(m_mouse_y - m_engine_window_pos.y) / m_engine_window_size.y);
Expand All @@ -951,8 +955,7 @@ namespace Pilot
return;
}
// wheel scrolled up = zoom in by 2 extra degrees
if (m_mouse_x > m_engine_window_pos.x && m_mouse_x < (m_engine_window_pos.x + m_engine_window_size.x) &&
m_mouse_y > m_engine_window_pos.y && m_mouse_y < (m_engine_window_pos.y + m_engine_window_size.y))
if (isCursorInRect(m_engine_window_pos, m_engine_window_size))
{
m_tmp_uistate->m_editor_camera->zoom((float)yoffset * 2.0f);
}
Expand All @@ -969,8 +972,7 @@ namespace Pilot
if (current_active_level == nullptr)
return;

if (m_mouse_x > m_engine_window_pos.x && m_mouse_x < (m_engine_window_pos.x + m_engine_window_size.x) &&
m_mouse_y > m_engine_window_pos.y && m_mouse_y < (m_engine_window_pos.y + m_engine_window_size.y))
if (isCursorInRect(m_engine_window_pos, m_engine_window_size))
{
if (key == GLFW_MOUSE_BUTTON_LEFT)
{
Expand Down