diff --git a/.gitignore b/.gitignore index f37de98..f682f4f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # my pattern -bin/*.zip bin/data/backup bin/data/settings.xml +bin/releases/*.zip ######################### # openFrameworks patterns diff --git a/README.md b/README.md index c115d7c..60a0219 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Virtual Mapper v2.1.3 +# Virtual Mapper v2.1.4 ![](./doc/thumbnail.png) diff --git a/openFrameworks-Info.plist b/openFrameworks-Info.plist index fb42f5e..0abd41d 100644 --- a/openFrameworks-Info.plist +++ b/openFrameworks-Info.plist @@ -15,7 +15,7 @@ CFBundleSignature ???? CFBundleVersion - 2.1.3 + 2.1.4 CFBundleIconFile virtual-mapper.icns diff --git a/src/Manager/BaseManager.h b/src/Manager/BaseManager.h index 7034090..6dacce8 100644 --- a/src/Manager/BaseManager.h +++ b/src/Manager/BaseManager.h @@ -16,4 +16,10 @@ class BaseManager { virtual void saveSettings(ofxXmlSettings &settings) {} virtual void drawImGui() {} + virtual void dragEvent(ofDragInfo dragInfo) {} + +protected: + + bool isGuiOpened = true; + }; diff --git a/src/Manager/MiscManager.h b/src/Manager/MiscManager.h index e5de303..933c7da 100644 --- a/src/Manager/MiscManager.h +++ b/src/Manager/MiscManager.h @@ -11,7 +11,9 @@ class MiscManager : public BaseManager { void drawImGui() { - if (ImGui::CollapsingHeader("Misc")) { + ImGui::SetNextTreeNodeOpen(isGuiOpened); + + if ((isGuiOpened = ImGui::CollapsingHeader("Misc"))) { if (ImGui::Checkbox("Show Window On Top", &showWindowTop)) { WindowUtils::setWindowOnTop(showWindowTop); @@ -29,12 +31,37 @@ class MiscManager : public BaseManager { ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 2); ImGui::Begin("Help", &showHelp, ImGuiWindowFlags_AlwaysAutoResize); - ImGui::Text("Left click drag: Rotate camera\n" - "Right click drag: Zoom camera\n" - "Hold [H] whilst left click drag: Pan camera\n" - "[R]: Reset camera\n" - "[C]: Toggle control panel\n" - "[1-9]: Switch cameras in the scene file"); + static const vector> helpTexts = { + {"Left click drag", "Rotate camera"}, + {"Right click drag", "Zoom camera"}, + {"Middle click drag", "Pan camera"}, + {"[H] + Left click drag", ""}, + {"[R]", "Reset camera"}, + {"[1-9]", "Switch cameras in the scene file"}, + {"", ""}, + {"[F]", "Toggle fullscreen"}, + {"[C]", "Toggle control panel"}, + {"[G]", "Toggle showing guides"}, + {"[W]", "Toggle showing wireframe"} + }; + + static stringstream sskey, ssdesc; + + sskey.str(""); + ssdesc.str(""); + + for (auto& line : helpTexts) { + sskey << line.first << "\n"; + ssdesc << line.second << "\n"; + } + + ImGui::Columns(2, NULL, true); + + ImGui::Text("%s", sskey.str().c_str()); + ImGui::NextColumn(); + ImGui::Text("%s", ssdesc.str().c_str()); + + ImGui::Columns(1); ImGui::End(); ImGui::PopStyleVar(); @@ -48,6 +75,8 @@ class MiscManager : public BaseManager { settings.pushTag("misc"); + isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened); + showWindowTop = settings.getValue("showWindowTop", showWindowTop); WindowUtils::setWindowOnTop(showWindowTop); @@ -61,6 +90,8 @@ class MiscManager : public BaseManager { settings.addTag("misc"); settings.pushTag("misc"); + settings.setValue("isGuiOpened", isGuiOpened); + settings.setValue("showWindowTop", showWindowTop); settings.popTag(); diff --git a/src/Manager/SceneManager.h b/src/Manager/SceneManager.h index c4e6405..9453e1f 100644 --- a/src/Manager/SceneManager.h +++ b/src/Manager/SceneManager.h @@ -82,7 +82,9 @@ class SceneManager : public BaseManager { void drawImGui() { - if (ImGui::CollapsingHeader("Scene")) { + ImGui::SetNextTreeNodeOpen(isGuiOpened); + + if ((isGuiOpened = ImGui::CollapsingHeader("Scene"))) { if (ImGui::Button("Open Scene")) { ofFileDialogResult result = ImOf::SystemLoadDialog("Load Scene File (.fbx)", false, ""); @@ -117,6 +119,8 @@ class SceneManager : public BaseManager { void loadSettings(ofxXmlSettings &settings) { settings.pushTag("scene"); + isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened); + if (settings.tagExists("fbxPath")) { openFBX(settings.getValue("fbxPath", "")); } @@ -128,6 +132,8 @@ class SceneManager : public BaseManager { settings.addTag("scene"); settings.pushTag("scene"); + settings.setValue("isGuiOpened", isGuiOpened); + if (isFBXLoaded) { settings.setValue("fbxPath", fbxScene->getFbxFilePath()); } @@ -135,6 +141,17 @@ class SceneManager : public BaseManager { settings.popTag(); } + void dragEvent(ofDragInfo dragInfo) { + + if (dragInfo.files.size() == 1) { + string path = dragInfo.files[0]; + + if (ofFilePath::getFileExt(path) == "fbx") { + openFBX(path); + } + } + } + private: void openFBX(string path) { diff --git a/src/Manager/SourceManager.h b/src/Manager/SourceManager.h index 6e54273..11d06e0 100644 --- a/src/Manager/SourceManager.h +++ b/src/Manager/SourceManager.h @@ -32,11 +32,14 @@ class SourceManager : public BaseManager { void loadSettings(ofxXmlSettings& settings) { settings.pushTag("sources"); + isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened); + selected = settings.getValue("selected", 0); for (auto& source : sources) { source->loadSettings(settings); } + sources[selected]->onActivated(); isFlipTexture = settings.getValue("isFlipTexture", false); @@ -47,6 +50,8 @@ class SourceManager : public BaseManager { settings.addTag("sources"); settings.pushTag("sources"); + settings.setValue("isGuiOpened", isGuiOpened); + settings.setValue("selected", selected); for (auto& source : sources) { @@ -61,11 +66,20 @@ class SourceManager : public BaseManager { void drawImGui() { - if (ImGui::CollapsingHeader("Source", true)) { + ImGui::SetNextTreeNodeOpen(isGuiOpened); + + if ((isGuiOpened = ImGui::CollapsingHeader("Source"))) { for (int i = 0; i < sources.size(); i++) { - ImGui::RadioButton(sources[i]->getName().c_str(), &selected, i); + static int prevSelected; + + prevSelected = selected; + + if (ImGui::RadioButton(sources[i]->getName().c_str(), &selected, i)) { + sources[prevSelected]->onDeactivated(); + sources[selected]->onActivated(); + } if (i < sources.size() - 1) { ImGui::SameLine(); @@ -104,6 +118,26 @@ class SourceManager : public BaseManager { sources[selected]->unbind(textureLocation); } + void dragEvent(ofDragInfo dragInfo) { + + if (dragInfo.files.size() == 1) { + string path = dragInfo.files[0]; + + int i = 0; + + for (auto& source : sources) { + if (source->openPath(path)) { + sources[selected]->onDeactivated(); + sources[i]->onActivated(); + + selected = i; + + break; + } + ++i; + } + } + } private: diff --git a/src/Manager/ViewManager.h b/src/Manager/ViewManager.h index 0bb1ade..7696964 100644 --- a/src/Manager/ViewManager.h +++ b/src/Manager/ViewManager.h @@ -133,7 +133,9 @@ class ViewManager : public BaseManager { void drawImGui() { - if (ImGui::CollapsingHeader("View")) { + ImGui::SetNextTreeNodeOpen(isGuiOpened); + + if ((isGuiOpened = ImGui::CollapsingHeader("View"))) { if (ImGui::TreeNode("Cameras")) { @@ -211,6 +213,7 @@ class ViewManager : public BaseManager { void loadSettings(ofxXmlSettings &settings) { settings.pushTag("view"); + isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened); settings.pushTag("visibility"); for (auto &kv : visibility) { @@ -218,8 +221,6 @@ class ViewManager : public BaseManager { } settings.popTag(); - - settings.pushTag("camera"); { cameraIndex = settings.getValue("index", 0); @@ -252,6 +253,8 @@ class ViewManager : public BaseManager { settings.addTag("view"); settings.pushTag("view"); + settings.setValue("isGuiOpened", isGuiOpened); + settings.addTag("visibility"); settings.pushTag("visibility"); for (auto& kv : visibility) { @@ -416,8 +419,20 @@ class ViewManager : public BaseManager { cameraIndex = ci; applyCurrentCameraInfo(); - } else if (args.key == 'r') { - resetCamera(); + } else { + + switch (args.key) { + case 'r': + resetCamera(); + break; + case 'w': + visibility["wireframe"] = !visibility["wireframe"]; + break; + case 'g': + visibility["guides"] = !visibility["guides"]; + break; + + } } } diff --git a/src/Source/BaseSource.h b/src/Source/BaseSource.h index 6cc5e98..f3f5eeb 100644 --- a/src/Source/BaseSource.h +++ b/src/Source/BaseSource.h @@ -17,6 +17,9 @@ class BaseSource { virtual void loadSettings(ofxXmlSettings &settings) {} virtual void saveSettings(ofxXmlSettings &settings) {} + virtual void onActivated() {} + virtual void onDeactivated() {} + virtual void bind(int textureLocation) {} virtual void unbind(int textureLocation) {} @@ -28,6 +31,10 @@ class BaseSource { virtual string getName() {} virtual bool isFlipped() {} + + virtual bool openPath(string path) { + return false; + } protected: ofTexture DefaultTexture; diff --git a/src/Source/ImageSource.h b/src/Source/ImageSource.h index 3b9eba7..7652348 100644 --- a/src/Source/ImageSource.h +++ b/src/Source/ImageSource.h @@ -14,9 +14,8 @@ class ImageSource : public BaseSource { settings.pushTag("image"); - if (settings.tagExists("path")) { - load(settings.getValue("path", "")); - } + string _path = settings.getValue("path", ""); + load(_path, false); settings.popTag(); @@ -28,7 +27,7 @@ class ImageSource : public BaseSource { settings.pushTag("image"); if (texture.isAllocated()) { - settings.setValue("path", file.getAbsolutePath()); + settings.setValue("path", path); } settings.popTag(); @@ -66,11 +65,15 @@ class ImageSource : public BaseSource { } ImGui::SameLine(); - ImGui::Text("%s", texture.isAllocated() ? file.getFileName().c_str() : "(No Image)"); + ImGui::Text("%s", texture.isAllocated() ? path.c_str() : "(No Image)"); ImOf::Alert("Unkown Image Foramt", "Failed to load the image as texture.", &showFailedModal); } + bool openPath(string _path) { + return load(_path, false); + } + //-------------------------------------------------------------- // custom methods @@ -79,25 +82,24 @@ class ImageSource : public BaseSource { private: - void load(string path) { - bool succeed = ofLoadImage(texture, path); + bool load(string _path, bool showModal = true) { - if (!succeed) { - texture.clear(); - - if (!willLoad) { + bool succeed = false; + + if ((succeed = ofLoadImage(texture, _path))) { + path = _path; + + } else { + if (showModal) { showFailedModal = true; } - } else { - file.open(path); } - willLoad = false; + return succeed; } - bool willLoad = true; bool showFailedModal = false; - ofFile file; + string path; ofTexture texture; }; diff --git a/src/Source/VideoSource.h b/src/Source/VideoSource.h index 442e875..1d5d86f 100644 --- a/src/Source/VideoSource.h +++ b/src/Source/VideoSource.h @@ -18,10 +18,8 @@ class VideoSource : public BaseSource { settings.pushTag("video"); - file.open( settings.getValue("path", "") ); - if (file.exists()) { - willOpen = true; - } + path = settings.getValue("path", ""); + isWaitingOpen = true; settings.popTag(); } @@ -31,19 +29,29 @@ class VideoSource : public BaseSource { settings.addTag("video"); settings.pushTag("video"); - if (player.isLoaded()) { - settings.setValue("path", file.getAbsolutePath()); + if (player.isLoaded() || isWaitingOpen) { + settings.setValue("path", path); } settings.popTag(); } - void update() { - if (willOpen) { - load(file.getAbsolutePath()); + void onActivated() { + if (isWaitingOpen) { + load(path, false); } - + } + + void onDeactivated() { + player.stop(); + } + + void update() { if (player.isLoaded()) { + if (isWaitingPlay) { + player.play(); + isWaitingPlay = false; + } player.update(); } } @@ -84,7 +92,7 @@ class VideoSource : public BaseSource { } ImGui::SameLine(); - ImGui::Text("%s", player.isLoaded() ? file.getFileName().c_str() : "(No Source)"); + ImGui::Text("%s", player.isLoaded() ? player.getMoviePath().c_str() : "(No Source)"); if (player.isLoaded()) { float pos = player.getPosition(); @@ -119,25 +127,37 @@ class VideoSource : public BaseSource { ImOf::Alert("Unkown Video Foramt", "Failed to load the video as texture.", &showFailedModal); } + bool isFlipped() { return false; } + + bool openPath(string path) { + return load(path, false); + } + //-------------------------------------------------------------- // custom methods string getName() { return "Video"; } - bool isFlipped() { return false; } + + private: - void load(string path) { - player.load(path); - file.open(path); + bool load(string _path, bool showModal = true) { - if (player.isLoaded()) { - player.play(); - } else if (!willOpen) { - showFailedModal = true; + isWaitingOpen = false; + + bool succeed = false; + + if ((succeed = player.load(_path))) { + isWaitingPlay = true; + path = _path; + } else { + if (showModal) { + showFailedModal = true; + } } - willOpen = false; + return succeed; } void keyPressed(ofKeyEventArgs & args) { @@ -158,10 +178,11 @@ class VideoSource : public BaseSource { } } - bool showFailedModal = false; + bool showFailedModal = false; - bool willOpen = false; + bool isWaitingOpen = false; + bool isWaitingPlay = false; + string path = ""; - ofFile file; - ofVideoPlayer player; + ofVideoPlayer player; }; diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 7db16b1..8454354 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -141,3 +141,12 @@ void ofApp::mouseReleased(int x, int y, int button) { } + +//-------------------------------------------------------------- +void ofApp::dragEvent(ofDragInfo dragInfo) { + + for (auto& manager : managers) { + manager->dragEvent(dragInfo); + } + +} diff --git a/src/ofApp.h b/src/ofApp.h index a9f9c69..995255c 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -32,6 +32,7 @@ class ofApp : public ofBaseApp{ void keyReleased(int key); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); + void dragEvent(ofDragInfo dragInfo); void cameraListUpdated(vector &cameraList);