-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathofApp.cpp
More file actions
173 lines (124 loc) · 4.03 KB
/
ofApp.cpp
File metadata and controls
173 lines (124 loc) · 4.03 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
171
172
173
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
int screenW = ofGetScreenWidth();
int screenH = ofGetScreenHeight();
posx=screenW/2-300/2;
posy=screenH/2-300/2;
ofSetWindowPosition(posx, posy);
// load our typeface
vagRounded.load("vag.ttf", 16);
bFullscreen = 0;
// lets set the initial window pos
// and background color
// ofSetVerticalSync(true);
ofSetFrameRate(60);
ofBackground(50,50,50);
ballPositionX = 150;
ballPositionY = 150;
ballVelocityX = ofRandom(-5,5);
ballVelocityY = ofRandom(-5,5);
}
//--------------------------------------------------------------
void ofApp::update(){
// update our window title with the framerate and the position of the window
// [zach fix] ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+":fps - pos ("+ofToString((int)windowX)+","+ofToString((int)windowY)+")");
if(bFullscreen){
ofHideCursor();
}else{
ofShowCursor();
}
ballPositionX += ballVelocityX;
ballPositionY += ballVelocityY;
if (ballPositionX < 0){
ballPositionX = 0;
ballVelocityX *= -1;
if (!bFullscreen){
posx-=10;
}
} else if (ballPositionX > ofGetWidth()){
ballPositionX = ofGetWidth();
ballVelocityX *= -1;
if (!bFullscreen){
posx+=10;
}
}
if (ballPositionY < 0){
ballPositionY = 0;
ballVelocityY *= -1;
if (!bFullscreen){
posy-=10;
}
} else if (ballPositionY > ofGetHeight()){
ballPositionY = ofGetHeight();
ballVelocityY *= -1;
if (!bFullscreen){
posy+=10;
}
}
ofSetWindowPosition(posx, posy);
}
//--------------------------------------------------------------
void ofApp::draw(){
ofSetupScreen();
ofSetHexColor(0x999999);
// lets show our window pos in pixels
// macs actually start the Y pos from 40
vagRounded.drawString("window pos ("+ofToString(ofGetWindowPositionX())+", "+ofToString( ofGetWindowPositionY())+")", 10, 25);
// vagRounded.drawString("window pos ("+ofToString(ballPositionX)+", "+ofToString(ballPositionY)+")", 10, 25);
if(!bFullscreen){
vagRounded.drawString("press f to enter fullscreen", -140 + ofGetWidth()/2, ofGetHeight()/2);
vagRounded.drawString("window is normal", -100 + ofGetWidth()/2, ofGetHeight() - 10);
} else {
vagRounded.drawString("press f to exit fullscreen", -150 + ofGetWidth()/2, ofGetHeight()/2);
vagRounded.drawString("window is fullscreen", -140 + ofGetWidth()/2, ofGetHeight() - 10);
}
ofSetHexColor(0xFFFFFF);
ofDrawCircle(ballPositionX, ballPositionY, 15);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
if(key == 'f'){
bFullscreen = !bFullscreen;
if(!bFullscreen){
ofSetWindowShape(300,300);
ofSetFullscreen(false);
// figure out how to put the window in the center:
int screenW = ofGetScreenWidth();
int screenH = ofGetScreenHeight();
ofSetWindowPosition(screenW/2-300/2, screenH/2-300/2);
} else if(bFullscreen == 1){
ofSetFullscreen(true);
}
}
}
//--------------------------------------------------------------
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){
}
//--------------------------------------------------------------
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){
}