-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathofApp.cpp
More file actions
170 lines (140 loc) · 3.98 KB
/
ofApp.cpp
File metadata and controls
170 lines (140 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include "ofApp.h"
using namespace frames;
using namespace synapse;
//--------------------------------------------------------------
ofApp::ofApp()
{
cout << "construction............................" << endl;
viewsMap.insert(pair<VIEW_TYPES, AbstractViewerPtr>(VIEW_TYPES::ONE_ARTWORK, OneArtViewerPtr(new OneArtViewer())));
viewsMap.insert(pair<VIEW_TYPES, AbstractViewerPtr>(VIEW_TYPES::THREE_ARTWORKS, ThreeArtsViewerPtr(new ThreeArtsViewer())));
viewsMap.insert(pair<VIEW_TYPES, AbstractViewerPtr>(VIEW_TYPES::ONE_LARGE_ARTWORK, OneLargeArtworkPtr(new OneLargeArtwork())));
viewsMap.insert(pair<VIEW_TYPES, AbstractViewerPtr>(VIEW_TYPES::MIXED, MixedArtViwerPtr(new MixedArtViwer())));
}
AbstractViewerPtr ofApp::createViewer(VIEW_TYPES type)
{
switch (type)
{
case frames::VIEW_TYPES::ONE_ARTWORK:
return OneArtViewerPtr(new OneArtViewer());
case frames::VIEW_TYPES::THREE_ARTWORKS:
return ThreeArtsViewerPtr(new ThreeArtsViewer());
case frames::VIEW_TYPES::ONE_LARGE_ARTWORK:
return OneLargeArtworkPtr(new OneLargeArtwork());
case frames::VIEW_TYPES::MIXED:
return MixedArtViwerPtr(new MixedArtViwer());
}
}
void ofApp::setCommandLineArgs(const vector<string>& args)
{
cout << "args printed " << endl;
if (args.size() > 1)
{
for (size_t i = 0; i < args.size(); i++)
{
auto data = tools().splitString(args[i], '=');
if (data.size() > 1)
{
if (data[0].find("config") != -1)
{
configPath = data[1];
}
}
}
}
loadConfig();
}
void ofApp::loadConfig()
{
ofAddListener(configController.configSuccessEvent, this, &ofApp::onConfigSuccess);
ofAddListener(configController.configErrorEvent, this, &ofApp::onConfigError);
configController.init(configPath);
}
void ofApp::onConfigSuccess()
{
configPtr = configController.getConfig();
startApp();
}
void ofApp::onConfigError()
{
// error message
}
//--------------------------------------------------------------
void ofApp::startApp()
{
cout << "startApp............................" << endl;
// system init
ofSetFullscreen(configPtr->getFullscreen());
ofEnableAlphaBlending();
//ofSetVerticalSync(true);
//ofSetFrameRate(60);
configPtr->getShowCursor() ? ofShowCursor() : ofHideCursor();
// force exit field activate by click
const int closeSquareSide = 200;
exitRectangle = ofRectangle(ofGetWindowWidth() - closeSquareSide, 0, ofGetWindowWidth(), closeSquareSide);
// logger init
logger().init(configPtr->getAppData().logPath);
logger().log(Logger::LogType::Message, "message test");
logger().log(Logger::LogType::Error, "error message test");
// art init
auto artCreator = MainArtCreatorPtr(new MainArtCreator());
artCreator->create(configPtr);
forceUpdateArt = artCreator->getAllForceUpdateArt();
for (size_t i = 0; i < forceUpdateArt.size(); i++)
{
ofAddListener(forceUpdateArt[i]->showMeForce, this, &ofApp::showForceHandler);
}
auto viewType = configPtr->getViewType();
viewer = createViewer(viewType);
if (viewer)
{
viewer->setup(artCreator, configPtr);
}
// tcp init
ofAddListener(tcpAppMessageClient.newCommandEvent, this, &ofApp::onNewCommand);
ofAddListener(tcpAppMessageClient.nextArtEvent, this, &ofApp::onNextArtEvent);
tcpAppMessageClient.connect(configPtr);
}
void ofApp::onNewCommand(TCPAppMessageClient::CommandType& command)
{
}
void ofApp::onNextArtEvent()
{
viewer->nextArt();
}
void ofApp::update()
{
tcpAppMessageClient.update();
if (viewer)
{
viewer->update();
}
for (size_t i = 0; i < forceUpdateArt.size(); i++)
{
forceUpdateArt[i]->forceUpdate();
}
}
void ofApp::draw()
{
if (viewer)
{
viewer->draw();
}
}
//--------------------------------------------------------------
void ofApp::showForceHandler(frames::FRAME_TYPES& type)
{
viewer->setForceArt(type);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
viewer->nextArt();
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button)
{
if (exitRectangle.inside(x, y))
{
ofExit();
}
}