Skip to content
Snippets Groups Projects
Commit e464e8b3 authored by Pascal Engeler's avatar Pascal Engeler
Browse files

Added Imgui windows and selection manager

parent ffdd9374
No related branches found
No related tags found
No related merge requests found
......@@ -25,6 +25,8 @@ public:
int selectObject(unsigned x, unsigned y, glm::mat4 projection, glm::mat4 view, glm::mat4 model);
std::string name() const;
private:
std::string _name;
std::vector<std::pair<size_t, size_t>> _objectIndexRanges; //contains _objectIndexRanges[k] = [i_k, i_k+N)
......
#pragma once
#include <string>
struct SelectionManager {
//data of click-selected object
static int selectedIndex;
static std::string selectedLayerName;
//data of hover-selected object
static int hoveredIndex;
static std::string hoveredLayerName;
};
\ No newline at end of file
......@@ -169,4 +169,8 @@ int Layer::selectObject(unsigned x, unsigned y, glm::mat4 projection, glm::mat4
}
return index;
}
}
std::string Layer::name() const {
return _name;
}
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include <layer.hpp>
#include <imgui_bundle.hpp>
#include <input_state.hpp>
#include <selection_manager.hpp>
#include <screendefs.hpp>
......@@ -26,7 +27,7 @@ int main(int argc, char** argv) {
glm::vec3 lookAt(0., 0., 0.);
glm::vec3 eye(0., 0., 99.);
glm::vec3 eye(0., 0., 130.1415);
glm::vec3 upVector(0., 1., 0.);
Camera camera (eye, lookAt, upVector);
......@@ -47,7 +48,6 @@ int main(int argc, char** argv) {
glm::mat4 model = glm::mat4(1.0f);
size_t count = 0;
int index_selected = -1;
auto start = std::chrono::high_resolution_clock::now();
while (!InputState::should_quit) {
++count; //number of frames processed
......@@ -55,21 +55,32 @@ int main(int argc, char** argv) {
InputState::update(WIDTH, HEIGHT);
if (InputState::rmb_pressed) {
#ifndef NDEBUG
//std::cout << "Panning" << std::endl;
std::cout << "Panning" << std::endl;
#endif
camera.ProcessMousePan(-InputState::mmot_x, InputState::mmot_y);
}
else if (InputState::esc_click) {
//reset view and selection
camera.SetCameraView(eye, lookAt, upVector);
}
else if (InputState::lmb_click) {
//select object
index_selected = bottom_metal.selectObject(InputState::umpos_x, HEIGHT - InputState::umpos_y, projection, view, model);
std::cout << "Selected object: " << index_selected << std::endl;
int selected_index = bottom_metal.selectObject(InputState::umpos_x, HEIGHT - InputState::umpos_y, projection, view, model);
if (selected_index != -1) {
SelectionManager::selectedIndex = selected_index;
SelectionManager::selectedLayerName = bottom_metal.name();
}
else {
SelectionManager::selectedIndex = -1;
SelectionManager::selectedLayerName = "";
}
#ifndef NDEBUG
std::cout << "Selected object: " << SelectionManager::selectedIndex << std::endl;
#endif
}
else if (InputState::mwheelmot_y != 0.f) {
#ifndef NDEBUG
//std::cout << "Zooming" << std::endl;
std::cout << "Zooming" << std::endl;
#endif
camera.ProcessMouseZoom(InputState::mwheelmot_y);
}
......@@ -79,6 +90,49 @@ int main(int argc, char** argv) {
ImGui_ImplSDL2_NewFrame(infra.window());
ImGui::NewFrame();
/*ImGui Windows*/
//Info Window
ImGui::Begin("Info");
std::string text = "Selected Layer: " + SelectionManager::selectedLayerName;
ImGui::Text(text.c_str());
text = "Selected Object: " + std::to_string(SelectionManager::selectedIndex);
ImGui::Text(text.c_str());
int object_status;
text = "Status: ";
ImGui::Text(text.c_str());
ImGui::SameLine();
ImGui::RadioButton("Good", &object_status, 0);
ImGui::SameLine();
ImGui::RadioButton("Sketch", &object_status, 1);
ImGui::SameLine();
ImGui::RadioButton("Broken", &object_status, 2);
ImGui::End();
//Data Window
ImGui::Begin("Data");
char input_text[256];
ImGui::InputText("Filename", input_text, IM_ARRAYSIZE(input_text));
if (ImGui::Button("Save")) {
//save file here
}
ImGui::SameLine();
if (ImGui::Button("Load")) {
//load file here
}
ImGui::End();
//Draw Window
ImGui::Begin("Draw");
int draw_mode;
ImGui::RadioButton("Realistic", &draw_mode, 0);
ImGui::RadioButton("Identification", &draw_mode, 1);
ImGui::RadioButton("Good", &draw_mode, 2);
ImGui::RadioButton("Bad", &draw_mode, 3);
ImGui::RadioButton("Sketch", &draw_mode, 4);
ImGui::RadioButton("Good-Bad-Sketch", &draw_mode, 5);
ImGui::RadioButton("Normal-Bad", &draw_mode, 6);
ImGui::RadioButton("Highlight", &draw_mode, 7);
ImGui::End();
glClearColor(78./255, 97./255., 117./255., 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
......@@ -89,18 +143,22 @@ int main(int argc, char** argv) {
/*Draw here*/
int drawing_mode = 0;
//layer 0
int selected_index = -1;
if (SelectionManager::selectedLayerName == bottom_metal.name()) {
selected_index = SelectionManager::selectedIndex;
}
if (InputState::space_pressed) { //highlight selection
int tempDrawingMode = 7;
bottom_metal.draw(projection, view, model, tempDrawingMode, index_selected);
bottom_metal.draw(projection, view, model, tempDrawingMode, selected_index);
}
else {
bottom_metal.draw(projection, view, model, drawing_mode, index_selected);
bottom_metal.draw(projection, view, model, drawing_mode, selected_index);
}
/*End GUI Frame*/
ImGui::Render();
glViewport(0, 0, WIDTH, HEIGHT);
......
#include <selection_manager.hpp>
int SelectionManager::selectedIndex = -1;
std::string SelectionManager::selectedLayerName = "";
int SelectionManager::hoveredIndex = -1;
std::string SelectionManager::hoveredLayerName = "";
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment