Save Views config in Settings

This commit is contained in:
brunoherbelin
2020-04-29 11:07:35 +02:00
parent 79e9b70fa2
commit 7aaaa37e4b
6 changed files with 109 additions and 137 deletions

View File

@@ -1,10 +1,10 @@
#include "Settings.h" #include "Settings.h"
#include "tinyxml2Toolkit.h"
#include <iostream> #include <iostream>
using namespace std; using namespace std;
#include <tinyxml2.h> #include <tinyxml2.h>
#include "tinyxml2Toolkit.h"
using namespace tinyxml2; using namespace tinyxml2;
@@ -56,6 +56,33 @@ void Settings::Save()
applicationNode->SetAttribute("shader_editor", application.shader_editor); applicationNode->SetAttribute("shader_editor", application.shader_editor);
pRoot->InsertEndChild(applicationNode); pRoot->InsertEndChild(applicationNode);
// block: views
{
XMLElement *viewsNode = xmlDoc.NewElement( "Views" );
viewsNode->SetAttribute("current", application.current_view);
map<int, Settings::ViewConfig>::iterator iter;
for (iter=application.views.begin(); iter != application.views.end(); iter++)
{
const Settings::ViewConfig& v = iter->second;
XMLElement *view = xmlDoc.NewElement( "View" );
view->SetAttribute("name", v.name.c_str());
view->SetAttribute("id", iter->first);
XMLElement *scale = xmlDoc.NewElement("scale");
scale->InsertEndChild( XMLElementFromGLM(&xmlDoc, v.scale) );
view->InsertEndChild(scale);
XMLElement *translation = xmlDoc.NewElement("translation");
translation->InsertEndChild( XMLElementFromGLM(&xmlDoc, v.translation) );
view->InsertEndChild(translation);
viewsNode->InsertEndChild(view);
}
pRoot->InsertEndChild(viewsNode);
}
XMLError eResult = xmlDoc.SaveFile(filename.c_str()); XMLError eResult = xmlDoc.SaveFile(filename.c_str());
XMLCheckResult(eResult); XMLCheckResult(eResult);
} }
@@ -85,17 +112,17 @@ void Settings::Load()
XMLElement * pElement = pRoot->FirstChildElement("Windows"); XMLElement * pElement = pRoot->FirstChildElement("Windows");
if (pElement == nullptr) return; if (pElement == nullptr) return;
XMLElement* pWindowNode = pElement->FirstChildElement("Window"); XMLElement* windowNode = pElement->FirstChildElement("Window");
for( ; pWindowNode ; pWindowNode=pWindowNode->NextSiblingElement()) for( ; windowNode ; windowNode=windowNode->NextSiblingElement())
{ {
const char *pName = pWindowNode->Attribute("name"); const char *pName = windowNode->Attribute("name");
Settings::WindowConfig w(pName); Settings::WindowConfig w(pName);
pWindowNode->QueryIntAttribute("x", &w.x); // If this fails, original value is left as-is windowNode->QueryIntAttribute("x", &w.x); // If this fails, original value is left as-is
pWindowNode->QueryIntAttribute("y", &w.y); windowNode->QueryIntAttribute("y", &w.y);
pWindowNode->QueryIntAttribute("w", &w.w); windowNode->QueryIntAttribute("w", &w.w);
pWindowNode->QueryIntAttribute("h", &w.h); windowNode->QueryIntAttribute("h", &w.h);
pWindowNode->QueryBoolAttribute("f", &w.fullscreen); windowNode->QueryBoolAttribute("f", &w.fullscreen);
application.windows.push_back(w); application.windows.push_back(w);
} }
@@ -109,6 +136,32 @@ void Settings::Load()
pElement->QueryBoolAttribute("media_player", &application.media_player); pElement->QueryBoolAttribute("media_player", &application.media_player);
pElement->QueryBoolAttribute("shader_editor", &application.shader_editor); pElement->QueryBoolAttribute("shader_editor", &application.shader_editor);
// block: views
{
application.views.clear(); // trash existing list
XMLElement * pElement = pRoot->FirstChildElement("Views");
if (pElement == nullptr) return;
pElement->QueryIntAttribute("current", &application.current_view);
XMLElement* viewNode = pElement->FirstChildElement("View");
for( ; viewNode ; viewNode=viewNode->NextSiblingElement())
{
int id = 0;
viewNode->QueryIntAttribute("id", &id);
application.views[id].name = viewNode->Attribute("name");
XMLElement* scaleNode = viewNode->FirstChildElement("scale");
tinyxml2::XMLElementToGLM( scaleNode->FirstChildElement("vec3"),
application.views[id].scale);
XMLElement* translationNode = viewNode->FirstChildElement("translation");
tinyxml2::XMLElementToGLM( translationNode->FirstChildElement("vec3"),
application.views[id].translation);
}
}
} }

View File

@@ -4,7 +4,9 @@
#include "defines.h" #include "defines.h"
#include <string> #include <string>
#include <map>
#include <vector> #include <vector>
#include <glm/glm.hpp>
namespace Settings { namespace Settings {
@@ -21,8 +23,13 @@ struct WindowConfig
struct ViewConfig struct ViewConfig
{ {
std::string name; std::string name;
glm::vec3 scale;
glm::vec3 translation;
ViewConfig(std::string n) : name(n) { } ViewConfig() : name("") {
scale = glm::vec3(1.f);
translation = glm::vec3(0.f);
}
}; };
@@ -40,7 +47,7 @@ struct Application
// Settings of Views // Settings of Views
int current_view; int current_view;
std::vector<ViewConfig> views; std::map<int, ViewConfig> views;
// multiple windows handling // multiple windows handling
std::vector<WindowConfig> windows; std::vector<WindowConfig> windows;

View File

@@ -605,17 +605,17 @@ void MainWindow::Render()
// if ( ImGuiToolkit::ButtonToggle()) // if ( ImGuiToolkit::ButtonToggle())
float width = ImGui::GetContentRegionAvail().x / 3; float width = ImGui::GetContentRegionAvail().x / 3;
ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.50f, 0.50f)); ImGui::PushStyleVar(ImGuiStyleVar_SelectableTextAlign, ImVec2(0.50f, 0.50f));
if (ImGui::Selectable( ICON_FA_BULLSEYE " Mixing View", &selected_view[1], 0, ImVec2(width,50))) if (ImGui::Selectable( ICON_FA_BULLSEYE " Mixing", &selected_view[1], 0, ImVec2(width,50)))
{ {
Mixer::manager().setCurrentView(View::MIXING); Mixer::manager().setCurrentView(View::MIXING);
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Selectable( ICON_FA_SIGN " Geometry View", &selected_view[2], 0, ImVec2(width,50))) if (ImGui::Selectable( ICON_FA_SIGN " Geometry", &selected_view[2], 0, ImVec2(width,50)))
{ {
Mixer::manager().setCurrentView(View::GEOMETRY); Mixer::manager().setCurrentView(View::GEOMETRY);
} }
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Selectable( ICON_FA_BARS " Layers View", &selected_view[3], 0, ImVec2(width,50))) if (ImGui::Selectable( ICON_FA_BARS " Layers", &selected_view[3], 0, ImVec2(width,50)))
{ {
} }
@@ -642,6 +642,7 @@ void MainWindow::Render()
Log::ShowLogWindow(&show_logs_window); Log::ShowLogWindow(&show_logs_window);
if (show_overlay_stats) if (show_overlay_stats)
ShowStats(&show_overlay_stats); ShowStats(&show_overlay_stats);
if (show_icons_window) if (show_icons_window)
ImGuiToolkit::ShowIconsWindow(&show_icons_window); ImGuiToolkit::ShowIconsWindow(&show_icons_window);
if (show_demo_window) if (show_demo_window)

View File

@@ -7,6 +7,7 @@
#include <string.h> #include <string.h>
#include "defines.h" #include "defines.h"
#include "Settings.h"
#include "View.h" #include "View.h"
#include "Source.h" #include "Source.h"
#include "Primitives.h" #include "Primitives.h"
@@ -32,7 +33,15 @@ void View::update(float dt)
MixingView::MixingView() : View() MixingView::MixingView() : View()
{ {
// default settings // default settings
scene.root()->scale_ = glm::vec3(1.6f, 1.6f, 1.0f); if ( Settings::application.views[View::MIXING].name.empty() ) {
Settings::application.views[View::MIXING].name = "Mixing";
scene.root()->scale_ = glm::vec3(1.6f, 1.6f, 1.0f);
}
// restore settings
else {
scene.root()->scale_ = Settings::application.views[View::MIXING].scale;
scene.root()->translation_ = Settings::application.views[View::MIXING].translation;
}
// Mixing scene // Mixing scene
Mesh *disk = new Mesh("mesh/disk.ply"); Mesh *disk = new Mesh("mesh/disk.ply");
@@ -66,6 +75,7 @@ void MixingView::zoom( float factor )
scene.root()->scale_.x = z; scene.root()->scale_.x = z;
scene.root()->scale_.y = z; scene.root()->scale_.y = z;
Settings::application.views[View::MIXING].scale = scene.root()->scale_;
} }
void MixingView::drag (glm::vec2 from, glm::vec2 to) void MixingView::drag (glm::vec2 from, glm::vec2 to)
@@ -84,7 +94,7 @@ void MixingView::drag (glm::vec2 from, glm::vec2 to)
// compute delta translation // compute delta translation
scene.root()->translation_ = start_translation + gl_Position_to - gl_Position_from; scene.root()->translation_ = start_translation + gl_Position_to - gl_Position_from;
Settings::application.views[View::MIXING].translation = scene.root()->translation_;
} }
@@ -164,6 +174,11 @@ uint MixingView::textureMixingQuadratic()
RenderView::RenderView() : View(), frame_buffer_(nullptr) RenderView::RenderView() : View(), frame_buffer_(nullptr)
{ {
setResolution(1280, 720); setResolution(1280, 720);
// default settings
if ( Settings::application.views[View::RENDERING].name.empty() ) {
Settings::application.views[View::RENDERING].name = "Render";
}
} }
RenderView::~RenderView() RenderView::~RenderView()
@@ -193,6 +208,18 @@ void RenderView::draw()
GeometryView::GeometryView() : View() GeometryView::GeometryView() : View()
{ {
// default settings
if ( Settings::application.views[View::GEOMETRY].name.empty() ) {
Settings::application.views[View::GEOMETRY].name = "Geometry";
scene.root()->scale_ = glm::vec3(1.2f, 1.2f, 1.0f);
}
// restore settings
else {
scene.root()->scale_ = Settings::application.views[View::GEOMETRY].scale;
scene.root()->translation_ = Settings::application.views[View::GEOMETRY].translation;
}
// Scene // Scene
Surface *rect = new Surface; Surface *rect = new Surface;
backgound_.addChild(rect); backgound_.addChild(rect);
@@ -205,8 +232,6 @@ GeometryView::GeometryView() : View()
scene.root()->addChild(&backgound_); scene.root()->addChild(&backgound_);
// default settings
scene.root()->scale_ = glm::vec3(1.2f, 1.2f, 1.f);
} }
@@ -237,6 +262,7 @@ void GeometryView::zoom( float factor )
scene.root()->scale_.x = z; scene.root()->scale_.x = z;
scene.root()->scale_.y = z; scene.root()->scale_.y = z;
Settings::application.views[View::GEOMETRY].scale = scene.root()->scale_;
} }
void GeometryView::drag (glm::vec2 from, glm::vec2 to) void GeometryView::drag (glm::vec2 from, glm::vec2 to)
@@ -255,7 +281,7 @@ void GeometryView::drag (glm::vec2 from, glm::vec2 to)
// compute delta translation // compute delta translation
scene.root()->translation_ = start_translation + gl_Position_to - gl_Position_from; scene.root()->translation_ = start_translation + gl_Position_to - gl_Position_from;
Settings::application.views[View::GEOMETRY].translation = scene.root()->translation_;
} }

View File

@@ -1,115 +0,0 @@
ply
format ascii 1.0
comment Created by Blender 2.82 (sub 7) - www.blender.org, source file: 'border.blend'
element vertex 45
property float x
property float y
property float z
property uchar red
property uchar green
property uchar blue
property uchar alpha
element face 56
property list uchar uint vertex_indices
end_header
-0.950647 -1.000000 0.000000 255 255 255 255
-0.000071 -1.013523 0.000000 255 255 255 255
-0.000077 -1.000000 0.000000 255 255 255 255
-0.962557 -1.013523 0.000000 255 255 255 255
-0.000064 -1.027167 0.000000 255 255 255 255
0.963176 -1.013523 0.000000 255 255 255 255
0.951244 -1.000000 0.000000 255 255 255 255
0.971677 -1.000395 0.000000 255 255 255 255
0.982502 -1.011536 0.000000 255 255 255 255
0.991868 -0.991539 0.000000 255 255 255 255
1.011320 -0.981739 0.000000 255 255 255 255
1.002918 -1.002581 0.000000 255 255 255 255
1.013443 -0.963042 0.000000 255 255 255 255
1.000178 -0.970926 0.000000 255 255 255 255
1.027092 -0.976006 0.000000 255 255 255 255
1.024939 -0.994955 0.000000 255 255 255 255
1.016425 -1.016078 0.000000 255 255 255 255
0.995733 -1.025153 0.000000 255 255 255 255
0.976147 -1.027167 0.000000 255 255 255 255
1.027092 -0.000011 0.000000 255 255 255 255
1.013443 0.963025 0.000000 255 255 255 255
1.013443 -0.000008 0.000000 255 255 255 255
1.027092 0.975985 0.000000 255 255 255 255
1.011158 0.987628 0.000000 255 255 255 255
1.000017 0.976754 0.000000 255 255 255 255
1.000000 0.951104 0.000000 255 255 255 255
0.991530 0.992067 0.000000 255 255 255 255
0.984469 1.011229 0.000000 255 255 255 255
1.002576 1.003111 0.000000 255 255 255 255
0.962232 1.013506 0.000000 255 255 255 255
0.973622 1.000095 0.000000 255 255 255 255
0.975191 1.027145 0.000000 255 255 255 255
0.997727 1.024837 0.000000 255 255 255 255
1.016078 1.016610 0.000000 255 255 255 255
1.024775 1.000919 0.000000 255 255 255 255
1.000889 -0.951116 0.000000 255 255 255 255
-0.951593 1.000000 0.000000 255 255 255 255
-0.000071 1.013506 0.000000 255 255 255 255
-0.963515 1.013506 0.000000 255 255 255 255
0.950312 1.000000 0.000000 255 255 255 255
-0.000064 1.027145 0.000000 255 255 255 255
-0.975505 -1.027167 0.000000 255 255 255 255
1.000000 0.000000 0.000000 255 255 255 255
-0.000064 1.000000 0.000000 255 255 255 255
-0.976476 1.027145 0.000000 255 255 255 255
3 0 1 2
3 3 4 1
3 4 5 1
3 1 6 2
3 5 7 6
3 8 9 7
3 10 9 11
3 12 13 10
3 10 14 12
3 15 11 16
3 11 17 16
3 8 18 17
3 19 12 14
3 19 20 21
3 22 23 20
3 20 24 25
3 23 26 24
3 27 26 28
3 29 30 27
3 27 31 29
3 32 28 33
3 28 34 33
3 25 21 20
3 21 35 12
3 36 37 38
3 37 39 29
3 29 40 37
3 40 38 37
3 0 3 1
3 3 41 4
3 4 18 5
3 1 5 6
3 5 8 7
3 8 11 9
3 10 13 9
3 12 35 13
3 10 15 14
3 15 10 11
3 11 8 17
3 8 5 18
3 19 21 12
3 19 22 20
3 22 34 23
3 20 23 24
3 23 28 26
3 27 30 26
3 29 39 30
3 27 32 31
3 32 27 28
3 28 23 34
3 25 42 21
3 21 42 35
3 36 43 37
3 37 43 39
3 29 31 40
3 40 44 38

View File

@@ -43,7 +43,7 @@ XMLElement *tinyxml2::XMLElementFromGLM(XMLDocument *doc, glm::mat4 matrix)
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec3 &vector) void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec3 &vector)
{ {
if ( std::string(elem->Name()).find("vec3") == std::string::npos ) if ( !elem || std::string(elem->Name()).find("vec3") == std::string::npos )
return; return;
elem->QueryFloatAttribute("x", &vector.x); // If this fails, original value is left as-is elem->QueryFloatAttribute("x", &vector.x); // If this fails, original value is left as-is
elem->QueryFloatAttribute("y", &vector.y); elem->QueryFloatAttribute("y", &vector.y);
@@ -52,7 +52,7 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec3 &vector)
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec4 &vector) void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec4 &vector)
{ {
if ( std::string(elem->Name()).find("vec4") == std::string::npos ) if ( !elem || std::string(elem->Name()).find("vec4") == std::string::npos )
return; return;
elem->QueryFloatAttribute("x", &vector.x); // If this fails, original value is left as-is elem->QueryFloatAttribute("x", &vector.x); // If this fails, original value is left as-is
elem->QueryFloatAttribute("y", &vector.y); elem->QueryFloatAttribute("y", &vector.y);
@@ -62,7 +62,7 @@ void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::vec4 &vector)
void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::mat4 &matrix) void tinyxml2::XMLElementToGLM(XMLElement *elem, glm::mat4 &matrix)
{ {
if ( std::string(elem->Name()).find("mat4") == std::string::npos ) if ( !elem || std::string(elem->Name()).find("mat4") == std::string::npos )
return; return;
// loop over rows of vec4 // loop over rows of vec4