Skip to content

Commit

Permalink
Update v2.1.4
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Feb 27, 2017
1 parent 6f034eb commit c36e067
Show file tree
Hide file tree
Showing 13 changed files with 201 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,7 +1,7 @@
# my pattern
bin/*.zip
bin/data/backup
bin/data/settings.xml
bin/releases/*.zip

#########################
# openFrameworks patterns
Expand Down
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
# Virtual Mapper <!--VERSION-->v2.1.3<!--/VERSION-->
# Virtual Mapper <!--VERSION-->v2.1.4<!--/VERSION-->

![](./doc/thumbnail.png)

Expand Down
2 changes: 1 addition & 1 deletion openFrameworks-Info.plist
Expand Up @@ -15,7 +15,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2.1.3</string>
<string>2.1.4</string>
<key>CFBundleIconFile</key>
<string>virtual-mapper.icns</string>
</dict>
Expand Down
6 changes: 6 additions & 0 deletions src/Manager/BaseManager.h
Expand Up @@ -16,4 +16,10 @@ class BaseManager {
virtual void saveSettings(ofxXmlSettings &settings) {}
virtual void drawImGui() {}

virtual void dragEvent(ofDragInfo dragInfo) {}

protected:

bool isGuiOpened = true;

};
45 changes: 38 additions & 7 deletions src/Manager/MiscManager.h
Expand Up @@ -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);
Expand All @@ -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<pair<string, string>> 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();
Expand All @@ -48,6 +75,8 @@ class MiscManager : public BaseManager {

settings.pushTag("misc");

isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);

showWindowTop = settings.getValue("showWindowTop", showWindowTop);
WindowUtils::setWindowOnTop(showWindowTop);

Expand All @@ -61,6 +90,8 @@ class MiscManager : public BaseManager {
settings.addTag("misc");
settings.pushTag("misc");

settings.setValue("isGuiOpened", isGuiOpened);

settings.setValue("showWindowTop", showWindowTop);

settings.popTag();
Expand Down
19 changes: 18 additions & 1 deletion src/Manager/SceneManager.h
Expand Up @@ -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, "");
Expand Down Expand Up @@ -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", ""));
}
Expand All @@ -128,13 +132,26 @@ class SceneManager : public BaseManager {
settings.addTag("scene");
settings.pushTag("scene");

settings.setValue("isGuiOpened", isGuiOpened);

if (isFBXLoaded) {
settings.setValue("fbxPath", fbxScene->getFbxFilePath());
}

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) {
Expand Down
38 changes: 36 additions & 2 deletions src/Manager/SourceManager.h
Expand Up @@ -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);

Expand All @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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:

Expand Down
25 changes: 20 additions & 5 deletions src/Manager/ViewManager.h
Expand Up @@ -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")) {

Expand Down Expand Up @@ -211,15 +213,14 @@ class ViewManager : public BaseManager {
void loadSettings(ofxXmlSettings &settings) {
settings.pushTag("view");

isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);

settings.pushTag("visibility");
for (auto &kv : visibility) {
settings.getValue(kv.first, kv.second);
}
settings.popTag();



settings.pushTag("camera");
{
cameraIndex = settings.getValue("index", 0);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

}
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/Source/BaseSource.h
Expand Up @@ -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) {}

Expand All @@ -28,6 +31,10 @@ class BaseSource {

virtual string getName() {}
virtual bool isFlipped() {}

virtual bool openPath(string path) {
return false;
}

protected:
ofTexture DefaultTexture;
Expand Down
34 changes: 18 additions & 16 deletions src/Source/ImageSource.h
Expand Up @@ -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();

Expand All @@ -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();
Expand Down Expand Up @@ -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

Expand All @@ -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;
};

0 comments on commit c36e067

Please sign in to comment.