-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathofApp.cpp
219 lines (171 loc) · 6.7 KB
/
ofApp.cpp
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup() {
ofSetFrameRate(60);
ofSetVerticalSync(true);
ofSetCircleResolution(100);
Tweenzor::init();
// filmene loades, husk at tage højde for om det er VideoPlayer eller HapPlayer
one.loadMovie("1.mov");
two.loadMovie("2.mov");
one.setLoopState(OF_LOOP_NONE);
two.setLoopState(OF_LOOP_NONE);
// filmenes banner loades, husk at tage højde for filtype
// banneret er sat til at have aspektet ofGetWindowsWidth * ofGetWindowHeight / 2
bannerOne.loadImage("1.png");
bannerTwo.loadImage("2.png");
// hvis aspekt er vigtigt
oneAspect = one.getWidth() / one.getHeight();
twoAspect = two.getWidth() / two.getHeight();
bannerOneAspect = bannerOne.getWidth() / bannerOne.getHeight();
bannerTwoAspect = bannerTwo.getWidth() / bannerTwo.getHeight();
// sætter filmenes y-pos
yOne = 0;
yTarget = ofGetWindowHeight() / 2;
one.play();
two.play();
one.stop();
two.stop();
// home button
screenHome = true;
homeButton.loadImage("homeButton.png");
homeX = ofGetWindowWidth() - 125;
homeY = ofGetWindowHeight() - 125;
homeRadius = 100;
// play button
playAlpha = 200.f;
playButton.loadImage("playButton.png");
}
//--------------------------------------------------------------
void ofApp::update() {
one.update();
two.update();
Tweenzor::update(ofGetElapsedTimeMillis());
if (one.getIsMovieDone() || two.getIsMovieDone()) {
if (!screenHome) {
homePressed();
}
}
}
//--------------------------------------------------------------
void ofApp::draw() {
ofBackground(0);
// filmen og animationen opdateres
ofSetColor(255);
if (!one.isPlaying() && !two.isPlaying()) {
bannerOne.draw(0, yOne);
bannerTwo.draw(0, yOne + ofGetWindowHeight() / 2);
} else if (one.isPlaying() && !two.isPlaying()) {
one.draw((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * oneAspect) / 2), yOne - ofGetWindowHeight() / 2, ofGetWindowHeight() * oneAspect, ofGetWindowHeight());
bannerTwo.draw(0, yOne + ofGetWindowHeight() / 2);
} else if (!one.isPlaying() && two.isPlaying()) {
bannerOne.draw(0, yOne);
two.draw((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * twoAspect) / 2), yOne + ofGetWindowHeight() / 2, ofGetWindowHeight() * twoAspect, ofGetWindowHeight());
}
// home button
ofSetColor(255, 255, 255, ceil(homeAlpha));
homeButton.draw(homeX - homeButton.getHeight() / 2, homeY - homeButton.getHeight() / 2);
// play buttons
ofSetColor(255, 255, 255, ceil(playAlpha));
playButton.draw(ofGetWindowWidth() / 2 - playButton.getWidth() / 2, ofGetWindowHeight() / 4 - playButton.getHeight() / 2);
playButton.draw(ofGetWindowWidth() / 2 - playButton.getWidth() / 2, ofGetWindowHeight() - (ofGetWindowHeight() / 4) - playButton.getWidth() / 2);
if (one.isPlaying() && !screenHome) {
ofSetColor(0, 0, 0, 75);
ofRect((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * oneAspect) / 2), ofGetWindowHeight() - 4, ofGetWindowHeight() * oneAspect, ofGetWindowHeight());
ofSetColor(255);
ofRect((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * oneAspect) / 2), ofGetWindowHeight() - 4, ofGetWindowHeight() * oneAspect * one.getCurrentFrame() / one.getTotalNumFrames(), ofGetWindowHeight());
}
if (two.isPlaying() && !screenHome) {
ofSetColor(0, 100);
ofRect((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * twoAspect) / 2), ofGetWindowHeight() - 4, ofGetWindowHeight() * twoAspect, ofGetWindowHeight());
ofSetColor(255, 200);
ofRect((ofGetWindowWidth() / 2) - ((ofGetWindowHeight() * twoAspect) / 2), ofGetWindowHeight() - 4, ofGetWindowHeight() * twoAspect * two.getCurrentFrame() / two.getTotalNumFrames(), ofGetWindowHeight());
}
// debug
//ofSetColor(255);
//fpsStr = "frame rate: " + ofToString(ofGetFrameRate(), 2);
//ofDrawBitmapString(fpsStr, 5, 13);
}
//==============================================================
void ofApp::oneStarted() {
screenHome = false;
if (yTarget < 0) {
yTarget *= -1;
}
Tweenzor::add(&playAlpha, playAlpha, 0.f, 0.f, 0.5f, EASE_IN_OUT_ELASTIC);
Tweenzor::add(&yOne, yOne, yTarget, 0.f, 0.5f, EASE_IN_OUT_QUINT);
Tweenzor::add(&homeAlpha, homeAlpha, 200.f, 0.f, 0.5f, EASE_IN_OUT_QUINT);
one.play();
}
void ofApp::twoStarted() {
screenHome = false;
if (yTarget > 0) {
yTarget *= -1;
}
Tweenzor::add(&playAlpha, playAlpha, 0.f, 0.f, 0.5f, EASE_IN_OUT_ELASTIC);
Tweenzor::add(&yOne, yOne, yTarget, 0.f, 0.5f, EASE_IN_OUT_QUINT);
Tweenzor::add(&homeAlpha, homeAlpha, 200.f, 0.f, 0.5f, EASE_IN_OUT_QUINT);
two.play();
}
void ofApp::homePressed() {
screenHome = true;
Tweenzor::add(&yOne, yOne, 0.f, 0.f, 0.5f, EASE_IN_OUT_QUINT);
Tweenzor::addCompleteListener(Tweenzor::getTween(&yOne), this, &ofApp::onComplete);
Tweenzor::add(&homeAlpha, homeAlpha, 0.f, 0.f, 0.5f, EASE_IN_OUT_ELASTIC);
}
void ofApp::onComplete(float* arg) {
Tweenzor::add(&playAlpha, playAlpha, 200.f, 0.f, 0.5f, EASE_IN_OUT_QUINT);
one.setFrame(0);
two.setFrame(0);
one.stop();
two.stop();
}
void ofApp::exit() {
Tweenzor::destroy();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key) {
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key) {
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button) {
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button) {
if (!one.isPlaying() && !two.isPlaying()) {
if (y < ofGetWindowHeight() / 2) {
oneStarted();
}
else {
twoStarted();
}
}
else if (one.isPlaying() || two.isPlaying()) {
if (x > homeX - homeRadius && x < homeX + homeRadius && y > homeY - homeRadius && y < homeY + homeRadius) {
homePressed();
}
}
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y) {
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h) {
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg) {
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo) {
}