Skip to content

Commit c36e067

Browse files
committed
Update v2.1.4
1 parent 6f034eb commit c36e067

13 files changed

+201
-58
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# my pattern
2-
bin/*.zip
32
bin/data/backup
43
bin/data/settings.xml
4+
bin/releases/*.zip
55

66
#########################
77
# openFrameworks patterns

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Virtual Mapper <!--VERSION-->v2.1.3<!--/VERSION-->
1+
# Virtual Mapper <!--VERSION-->v2.1.4<!--/VERSION-->
22

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

openFrameworks-Info.plist

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundleSignature</key>
1616
<string>????</string>
1717
<key>CFBundleVersion</key>
18-
<string>2.1.3</string>
18+
<string>2.1.4</string>
1919
<key>CFBundleIconFile</key>
2020
<string>virtual-mapper.icns</string>
2121
</dict>

src/Manager/BaseManager.h

+6
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,10 @@ class BaseManager {
1616
virtual void saveSettings(ofxXmlSettings &settings) {}
1717
virtual void drawImGui() {}
1818

19+
virtual void dragEvent(ofDragInfo dragInfo) {}
20+
21+
protected:
22+
23+
bool isGuiOpened = true;
24+
1925
};

src/Manager/MiscManager.h

+38-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ class MiscManager : public BaseManager {
1111

1212
void drawImGui() {
1313

14-
if (ImGui::CollapsingHeader("Misc")) {
14+
ImGui::SetNextTreeNodeOpen(isGuiOpened);
15+
16+
if ((isGuiOpened = ImGui::CollapsingHeader("Misc"))) {
1517

1618
if (ImGui::Checkbox("Show Window On Top", &showWindowTop)) {
1719
WindowUtils::setWindowOnTop(showWindowTop);
@@ -29,12 +31,37 @@ class MiscManager : public BaseManager {
2931
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 2);
3032
ImGui::Begin("Help", &showHelp, ImGuiWindowFlags_AlwaysAutoResize);
3133

32-
ImGui::Text("Left click drag: Rotate camera\n"
33-
"Right click drag: Zoom camera\n"
34-
"Hold [H] whilst left click drag: Pan camera\n"
35-
"[R]: Reset camera\n"
36-
"[C]: Toggle control panel\n"
37-
"[1-9]: Switch cameras in the scene file");
34+
static const vector<pair<string, string>> helpTexts = {
35+
{"Left click drag", "Rotate camera"},
36+
{"Right click drag", "Zoom camera"},
37+
{"Middle click drag", "Pan camera"},
38+
{"[H] + Left click drag", ""},
39+
{"[R]", "Reset camera"},
40+
{"[1-9]", "Switch cameras in the scene file"},
41+
{"", ""},
42+
{"[F]", "Toggle fullscreen"},
43+
{"[C]", "Toggle control panel"},
44+
{"[G]", "Toggle showing guides"},
45+
{"[W]", "Toggle showing wireframe"}
46+
};
47+
48+
static stringstream sskey, ssdesc;
49+
50+
sskey.str("");
51+
ssdesc.str("");
52+
53+
for (auto& line : helpTexts) {
54+
sskey << line.first << "\n";
55+
ssdesc << line.second << "\n";
56+
}
57+
58+
ImGui::Columns(2, NULL, true);
59+
60+
ImGui::Text("%s", sskey.str().c_str());
61+
ImGui::NextColumn();
62+
ImGui::Text("%s", ssdesc.str().c_str());
63+
64+
ImGui::Columns(1);
3865

3966
ImGui::End();
4067
ImGui::PopStyleVar();
@@ -48,6 +75,8 @@ class MiscManager : public BaseManager {
4875

4976
settings.pushTag("misc");
5077

78+
isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);
79+
5180
showWindowTop = settings.getValue("showWindowTop", showWindowTop);
5281
WindowUtils::setWindowOnTop(showWindowTop);
5382

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

93+
settings.setValue("isGuiOpened", isGuiOpened);
94+
6495
settings.setValue("showWindowTop", showWindowTop);
6596

6697
settings.popTag();

src/Manager/SceneManager.h

+18-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ class SceneManager : public BaseManager {
8282

8383
void drawImGui() {
8484

85-
if (ImGui::CollapsingHeader("Scene")) {
85+
ImGui::SetNextTreeNodeOpen(isGuiOpened);
86+
87+
if ((isGuiOpened = ImGui::CollapsingHeader("Scene"))) {
8688
if (ImGui::Button("Open Scene")) {
8789

8890
ofFileDialogResult result = ImOf::SystemLoadDialog("Load Scene File (.fbx)", false, "");
@@ -117,6 +119,8 @@ class SceneManager : public BaseManager {
117119
void loadSettings(ofxXmlSettings &settings) {
118120
settings.pushTag("scene");
119121

122+
isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);
123+
120124
if (settings.tagExists("fbxPath")) {
121125
openFBX(settings.getValue("fbxPath", ""));
122126
}
@@ -128,13 +132,26 @@ class SceneManager : public BaseManager {
128132
settings.addTag("scene");
129133
settings.pushTag("scene");
130134

135+
settings.setValue("isGuiOpened", isGuiOpened);
136+
131137
if (isFBXLoaded) {
132138
settings.setValue("fbxPath", fbxScene->getFbxFilePath());
133139
}
134140

135141
settings.popTag();
136142
}
137143

144+
void dragEvent(ofDragInfo dragInfo) {
145+
146+
if (dragInfo.files.size() == 1) {
147+
string path = dragInfo.files[0];
148+
149+
if (ofFilePath::getFileExt(path) == "fbx") {
150+
openFBX(path);
151+
}
152+
}
153+
}
154+
138155
private:
139156

140157
void openFBX(string path) {

src/Manager/SourceManager.h

+36-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,14 @@ class SourceManager : public BaseManager {
3232
void loadSettings(ofxXmlSettings& settings) {
3333
settings.pushTag("sources");
3434

35+
isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);
36+
3537
selected = settings.getValue("selected", 0);
3638

3739
for (auto& source : sources) {
3840
source->loadSettings(settings);
3941
}
42+
sources[selected]->onActivated();
4043

4144
isFlipTexture = settings.getValue("isFlipTexture", false);
4245

@@ -47,6 +50,8 @@ class SourceManager : public BaseManager {
4750
settings.addTag("sources");
4851
settings.pushTag("sources");
4952

53+
settings.setValue("isGuiOpened", isGuiOpened);
54+
5055
settings.setValue("selected", selected);
5156

5257
for (auto& source : sources) {
@@ -61,11 +66,20 @@ class SourceManager : public BaseManager {
6166

6267
void drawImGui() {
6368

64-
if (ImGui::CollapsingHeader("Source", true)) {
69+
ImGui::SetNextTreeNodeOpen(isGuiOpened);
70+
71+
if ((isGuiOpened = ImGui::CollapsingHeader("Source"))) {
6572

6673
for (int i = 0; i < sources.size(); i++) {
6774

68-
ImGui::RadioButton(sources[i]->getName().c_str(), &selected, i);
75+
static int prevSelected;
76+
77+
prevSelected = selected;
78+
79+
if (ImGui::RadioButton(sources[i]->getName().c_str(), &selected, i)) {
80+
sources[prevSelected]->onDeactivated();
81+
sources[selected]->onActivated();
82+
}
6983

7084
if (i < sources.size() - 1) {
7185
ImGui::SameLine();
@@ -104,6 +118,26 @@ class SourceManager : public BaseManager {
104118
sources[selected]->unbind(textureLocation);
105119
}
106120

121+
void dragEvent(ofDragInfo dragInfo) {
122+
123+
if (dragInfo.files.size() == 1) {
124+
string path = dragInfo.files[0];
125+
126+
int i = 0;
127+
128+
for (auto& source : sources) {
129+
if (source->openPath(path)) {
130+
sources[selected]->onDeactivated();
131+
sources[i]->onActivated();
132+
133+
selected = i;
134+
135+
break;
136+
}
137+
++i;
138+
}
139+
}
140+
}
107141

108142
private:
109143

src/Manager/ViewManager.h

+20-5
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,9 @@ class ViewManager : public BaseManager {
133133

134134
void drawImGui() {
135135

136-
if (ImGui::CollapsingHeader("View")) {
136+
ImGui::SetNextTreeNodeOpen(isGuiOpened);
137+
138+
if ((isGuiOpened = ImGui::CollapsingHeader("View"))) {
137139

138140
if (ImGui::TreeNode("Cameras")) {
139141

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

216+
isGuiOpened = settings.getValue("isGuiOpened", isGuiOpened);
214217

215218
settings.pushTag("visibility");
216219
for (auto &kv : visibility) {
217220
settings.getValue(kv.first, kv.second);
218221
}
219222
settings.popTag();
220223

221-
222-
223224
settings.pushTag("camera");
224225
{
225226
cameraIndex = settings.getValue("index", 0);
@@ -252,6 +253,8 @@ class ViewManager : public BaseManager {
252253
settings.addTag("view");
253254
settings.pushTag("view");
254255

256+
settings.setValue("isGuiOpened", isGuiOpened);
257+
255258
settings.addTag("visibility");
256259
settings.pushTag("visibility");
257260
for (auto& kv : visibility) {
@@ -416,8 +419,20 @@ class ViewManager : public BaseManager {
416419
cameraIndex = ci;
417420
applyCurrentCameraInfo();
418421

419-
} else if (args.key == 'r') {
420-
resetCamera();
422+
} else {
423+
424+
switch (args.key) {
425+
case 'r':
426+
resetCamera();
427+
break;
428+
case 'w':
429+
visibility["wireframe"] = !visibility["wireframe"];
430+
break;
431+
case 'g':
432+
visibility["guides"] = !visibility["guides"];
433+
break;
434+
435+
}
421436
}
422437
}
423438

src/Source/BaseSource.h

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class BaseSource {
1717
virtual void loadSettings(ofxXmlSettings &settings) {}
1818
virtual void saveSettings(ofxXmlSettings &settings) {}
1919

20+
virtual void onActivated() {}
21+
virtual void onDeactivated() {}
22+
2023
virtual void bind(int textureLocation) {}
2124
virtual void unbind(int textureLocation) {}
2225

@@ -28,6 +31,10 @@ class BaseSource {
2831

2932
virtual string getName() {}
3033
virtual bool isFlipped() {}
34+
35+
virtual bool openPath(string path) {
36+
return false;
37+
}
3138

3239
protected:
3340
ofTexture DefaultTexture;

src/Source/ImageSource.h

+18-16
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ class ImageSource : public BaseSource {
1414

1515
settings.pushTag("image");
1616

17-
if (settings.tagExists("path")) {
18-
load(settings.getValue("path", ""));
19-
}
17+
string _path = settings.getValue("path", "");
18+
load(_path, false);
2019

2120
settings.popTag();
2221

@@ -28,7 +27,7 @@ class ImageSource : public BaseSource {
2827
settings.pushTag("image");
2928

3029
if (texture.isAllocated()) {
31-
settings.setValue("path", file.getAbsolutePath());
30+
settings.setValue("path", path);
3231
}
3332

3433
settings.popTag();
@@ -66,11 +65,15 @@ class ImageSource : public BaseSource {
6665
}
6766

6867
ImGui::SameLine();
69-
ImGui::Text("%s", texture.isAllocated() ? file.getFileName().c_str() : "(No Image)");
68+
ImGui::Text("%s", texture.isAllocated() ? path.c_str() : "(No Image)");
7069

7170
ImOf::Alert("Unkown Image Foramt", "Failed to load the image as texture.", &showFailedModal);
7271
}
7372

73+
bool openPath(string _path) {
74+
return load(_path, false);
75+
}
76+
7477
//--------------------------------------------------------------
7578
// custom methods
7679

@@ -79,25 +82,24 @@ class ImageSource : public BaseSource {
7982

8083
private:
8184

82-
void load(string path) {
83-
bool succeed = ofLoadImage(texture, path);
85+
bool load(string _path, bool showModal = true) {
8486

85-
if (!succeed) {
86-
texture.clear();
87-
88-
if (!willLoad) {
87+
bool succeed = false;
88+
89+
if ((succeed = ofLoadImage(texture, _path))) {
90+
path = _path;
91+
92+
} else {
93+
if (showModal) {
8994
showFailedModal = true;
9095
}
91-
} else {
92-
file.open(path);
9396
}
9497

95-
willLoad = false;
98+
return succeed;
9699
}
97100

98-
bool willLoad = true;
99101
bool showFailedModal = false;
100102

101-
ofFile file;
103+
string path;
102104
ofTexture texture;
103105
};

0 commit comments

Comments
 (0)