Commit e174ec52 authored by Johannes Braun's avatar Johannes Braun
Browse files

Move mouse button callback to editor class

parent 24dc7a1b
......@@ -932,6 +932,41 @@ void Editor::processInputsMain()
{
saveScene();
}
bool leftDownFirst = !m_mouseBtnDown[0] && glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
bool rightDownFirst = !m_mouseBtnDown[1] && glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS;
const bool wasFocussed = m_mainFocussed;
m_mainFocussed = glfwGetWindowAttrib(*m_window, GLFW_FOCUSED);
m_mouseBtnDown[0] = glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS;
m_mouseBtnDown[1] = glfwGetMouseButton(*m_window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS;
if (wasFocussed && !ImGui::GetIO().WantCaptureMouse)
{
double x, y;
int width, height;
glfwGetCursorPos(*m_window, &x, &y);
if (leftDownFirst)
{
glfwGetFramebufferSize(*m_window, &width, &height);
const auto selected = m_renderer->getPixelObjectID(glm::ivec2(x, height - y - 1));
if (!((!m_activeFieldIndex && selected == -1) || (m_activeFieldIndex && m_allFieldIds[*m_activeFieldIndex] == selected)))
{
select(selected == -1 ? std::nullopt : std::optional<uint32_t>(selected), true, true);
dino::getLogger()->info("Selected ObjectId: {}", selected);
}
}
if (rightDownFirst)
{
glfwGetFramebufferSize(*m_window, &width, &height);
const auto selected = m_renderer->getPixelObjectID(glm::ivec2(x, height - y - 1));
if (!((!m_activeFieldIndex && selected == -1) || (m_activeFieldIndex && m_allFieldIds[*m_activeFieldIndex] == selected)))
{
select(selected == -1 ? std::nullopt : std::optional<uint32_t>(selected), false, true);
}
}
}
}
void Editor::processInputsLights()
......
......@@ -4,8 +4,8 @@
#include <dino/editor/Blueprints.h>
#include <dino/input/Window.h>
#include <optional>
#include <unordered_set>
#include <set>
#include <unordered_set>
#include <vector>
namespace dino
......@@ -59,8 +59,8 @@ private:
void drawPreview();
void processInputsEditor();
void processInputsMain();
void processInputsFields();
void processInputsLights();
void processInputsFields();
void processInputsLights();
void selectByIndex(uint32_t index);
void deleteField(uint32_t index);
......@@ -80,6 +80,7 @@ private:
dino::TextureResource m_textureResourceHatching;
dino::TextureResource m_textureResourceBrick;
bool m_mainFocussed = false;
float m_previewScale = 200.f;
float m_windowAspect = 9.f / 16.f;
std::unique_ptr<dino::FrameBuffer> m_previewFramebuffer;
......@@ -87,21 +88,22 @@ private:
std::shared_ptr<Window> m_window = nullptr;
std::shared_ptr<RendererDeferred> m_renderer;
std::unique_ptr<Window> m_editorWindow;
std::set<uint32_t> m_selectedFieldIndices;
std::set<uint32_t> m_selectedLightIndices;
std::set<uint32_t> m_selectedFieldIndices;
std::set<uint32_t> m_selectedLightIndices;
std::vector<uint32_t> m_selectedLightIds;
std::vector<std::optional<uint32_t>> m_allFieldIds;
std::vector<uint32_t> m_allLightIds;
std::optional<uint32_t> m_activeFieldIndex = std::nullopt;
std::optional<uint32_t> m_activeLightIndex = std::nullopt;
std::vector<std::unique_ptr<Blueprints>> m_blueprints;
KeyboardButton m_ctrlC = KeyboardButton(GLFW_KEY_C, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlV = KeyboardButton(GLFW_KEY_V, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlSEditor = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlSMain = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlO = KeyboardButton(GLFW_KEY_O, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlA = KeyboardButton(GLFW_KEY_A, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_shiftTabEditor = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
KeyboardButton m_shiftTabMain = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
KeyboardButton m_ctrlC = KeyboardButton(GLFW_KEY_C, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlV = KeyboardButton(GLFW_KEY_V, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlSEditor = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlSMain = KeyboardButton(GLFW_KEY_S, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlO = KeyboardButton(GLFW_KEY_O, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_ctrlA = KeyboardButton(GLFW_KEY_A, GLFW_KEY_LEFT_CONTROL);
KeyboardButton m_shiftTabEditor = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
KeyboardButton m_shiftTabMain = KeyboardButton(GLFW_KEY_LEFT_SHIFT, GLFW_KEY_TAB);
bool m_mouseBtnDown[2] = {false, false};
};
} // namespace dino
\ No newline at end of file
......@@ -9,42 +9,6 @@
std::shared_ptr<dino::RendererDeferred> renderer;
std::shared_ptr<dino::Window> mainWindow;
bool mainHasFocus = true;
int pixelObjectId = -1;
bool didSelect = false;
bool openBlueprint = false;
void mouseButtonCallback(GLFWwindow* window, int button, int action, int mods)
{
if(mainHasFocus && !ImGui::GetIO().WantCaptureMouse)
{
double x, y;
int width, height;
glfwGetCursorPos(window, &x, &y);
if(button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS)
{
glfwGetFramebufferSize(window, &width, &height);
pixelObjectId = renderer->getPixelObjectID(glm::ivec2(x, height - y - 1));
dino::getLogger()->info("Selected ObjectId: {}", pixelObjectId);
didSelect = true;
openBlueprint = true;
}
if(button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS)
{
glfwGetFramebufferSize(window, &width, &height);
int temp = renderer->getPixelObjectID(glm::ivec2(x, height - y - 1));
if(temp != -1)
pixelObjectId = temp;
else
renderer->setActivePixelObjectId(pixelObjectId);
didSelect = true;
openBlueprint = false;
}
}
}
void onResize(GLFWwindow* w, int x, int y)
{
......@@ -141,13 +105,6 @@ int main()
auto deserialized = dino::Function::deserialize(x)->as<dino::OpBlendPolynomial>();
/**************************************** Callbacks ****************************************/
/*glfwSetKeyCallback(*mainWindow, [](GLFWwindow*, int key, int sc, int ac, int md) {
if(key == GLFW_KEY_F5 && ac == GLFW_PRESS)
dino::Program::reloadAll();
if(key == GLFW_KEY_ESCAPE && ac == GLFW_PRESS)
mainWindow->close();
});*/
glfwSetMouseButtonCallback(*mainWindow, mouseButtonCallback);
glfwSetFramebufferSizeCallback(*mainWindow, onResize);
/************************************** Build Buffers **************************************/
......@@ -203,18 +160,10 @@ int main()
/*TODO:
- Main Menu Bar
- Light panel
- Rendering panel
*/
editor.drawSettings();
if (didSelect)
{
editor.select(pixelObjectId != -1 ? std::optional<uint32_t>(pixelObjectId) : std::nullopt, openBlueprint);
didSelect = false;
openBlueprint = false;
}
#if 0
ImGui::Begin("I am a Window");
......@@ -374,7 +323,7 @@ int main()
mainWindow->endContent();
}
mainHasFocus = glfwGetWindowAttrib(*mainWindow, GLFW_FOCUSED);
//mainHasFocus = glfwGetWindowAttrib(*mainWindow, GLFW_FOCUSED);
editor.drawBlueprint();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment