Commit 3ea91018 authored by Felix Schröder's avatar Felix Schröder
Browse files

Merge branch 'renderLayerGui' of...

Merge branch 'renderLayerGui' of https://gitlab.uni-koblenz.de/CVFP_DF18/Framework into renderLayerGui
parents 74a780c3 7ca4cde9
......@@ -506,7 +506,7 @@ void Editor::drawLightsTab()
m_selectedLightIndices.end(),
[&](uint32_t index) { return index == light_index; });
bool sel = it != m_selectedLightIndices.end();
ImGui::PushID((std::string("light") + std::to_string(light_index)).c_str());
ImGui::PushID((std::string("light") + std::to_string(light_id)).c_str());
std::string lightName = "";
auto currentLight = m_renderer->getLights().at(light_id);
......@@ -566,7 +566,7 @@ void Editor::drawLightsTab()
bool temp_sel = sel;
if(ImGui::Selectable(
(lightName + std::string(" Light [ID: ") + std::to_string(light_index) + "]")
(lightName + std::string(" Light [ID: ") + std::to_string(light_id) + "]")
.c_str(),
&temp_sel))
{
......@@ -708,6 +708,7 @@ void Editor::drawPreview()
void Editor::drawSettings()
{
drawMenuBar();
int w, h;
glfwGetFramebufferSize(*m_window, &w, &h);
glBlitNamedFramebuffer(
......@@ -932,6 +933,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()
......@@ -942,7 +978,7 @@ void Editor::processInputsLights()
for (auto index : m_selectedLightIndices)
{
m_renderer->removeLight(m_allLightIds[index - erased]);
m_allLightIds.erase(m_allLightIds.begin() + index - erased);
m_allLightIds.erase(m_allLightIds.begin() + (index - erased));
++erased;
}
m_selectedLightIndices.clear();
......@@ -975,9 +1011,11 @@ void Editor::processInputsFields()
{
if (glfwGetKey(*m_window, GLFW_KEY_DELETE) == GLFW_PRESS)
{
int erased = 0;
for (auto index : m_selectedFieldIndices)
{
deleteField(0);
deleteField(index - erased);
++erased;
}
m_selectedFieldIndices.clear();
select(std::nullopt, false);
......@@ -1005,6 +1043,28 @@ void Editor::processInputsFields()
}
}
void Editor::drawMenuBar()
{
if (ImGui::BeginMainMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Open Scene", "Ctrl+O"))
loadScene();
if (ImGui::MenuItem("Save Scene", "Ctrl+S"))
saveScene();
ImGui::Separator();
if (ImGui::MenuItem("Exit", "Alt+F4"))
{
}
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
}
void Editor::saveScene()
{
const std::filesystem::path p = "./../resources/distanceFields/";
......
......@@ -4,6 +4,7 @@
#include <dino/editor/Blueprints.h>
#include <dino/input/Window.h>
#include <optional>
#include <set>
#include <unordered_set>
#include <vector>
......@@ -56,10 +57,11 @@ private:
void drawLightsTab();
void drawRenderingTab();
void drawPreview();
void drawMenuBar();
void processInputsEditor();
void processInputsMain();
void processInputsFields();
void processInputsLights();
void processInputsFields();
void processInputsLights();
void selectByIndex(uint32_t index);
void deleteField(uint32_t index);
......@@ -79,6 +81,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;
......@@ -86,21 +89,22 @@ private:
std::shared_ptr<Window> m_window = nullptr;
std::shared_ptr<Renderer> m_renderer;
std::unique_ptr<Window> m_editorWindow;
std::unordered_set<uint32_t> m_selectedFieldIndices;
std::unordered_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::Renderer> 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