forked from galsasson/ofxInterface
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathofApp.cpp
More file actions
165 lines (124 loc) · 3.46 KB
/
Copy pathofApp.cpp
File metadata and controls
165 lines (124 loc) · 3.46 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
#include "ofApp.h"
using namespace ofxInterface;
//--------------------------------------------------------------
void ofApp::setup(){
ofEnableAlphaBlending();
ofEnableSmoothing();
ofBackground(0);
/******
* setup the scene with width and height
*/
scene = new Node();
scene->setSize(ofGetWidth(), ofGetHeight());
scene->setName("Scene");
/******
* this is the touch manager, give him the scene to set it up
*/
TouchManager::one().setup(scene);
/******
* create custom gui components in a grid and add them to the scene
*/
populateScene();
}
void ofApp::populateScene()
{
float size = 40;
float pad = 40;
int perRow = 10;
for (int i=0; i<perRow*4; i++) {
// setup them in a grid
float x = 150 + (i%perRow)*(size+pad);
float y = 250 + (i/perRow)*(size+pad);
// create a ButtonExample node
ButtonExample *btn = new ButtonExample();
btn->setup(x, y, 40+size-ofRandom(20), size+ofRandom(30));
btn->setName("btn" + ofToString(i));
// add it to the scene
scene->addChild(btn);
if (i%perRow>0) {
// this can be called to place nodes next to each other
btn->placeNextTo(*buttons[i-1], Node::RIGHT);
}
// keep reference (we need it to update the nodes)
buttons.push_back(btn);
}
}
//--------------------------------------------------------------
void ofApp::update(){
/******
* update the touch manager,
*/
TouchManager::one().update();
/******
* update the nodes (optional, only if you have an update)
*/
for (int i=0; i<buttons.size(); i++) {
buttons[i]->update();
}
}
//--------------------------------------------------------------
void ofApp::draw(){
/******
* this will render the scene
* 1. this function takes all the visible nodes
* 2. sort them by 'plane' float
* 3. transform into the local space of each node
* 4. calls the 'draw' function on each node
*/
scene->render();
/******
* if you want debug rendering
*/
if (bShowDebug) {
scene->renderDebug();
}
ofSetColor(255);
ofDrawBitmapString("hit 'd' to toggle debug rendering", 5, ofGetHeight()-8);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
/******
* toggle debug render
*/
switch (key) {
case 'd':
bShowDebug = !bShowDebug;
break;
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y ){
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button){
/******
* pass touch/mouse events to the touch manager
*/
TouchManager::one().touchMove(button, ofVec2f(x, y));
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button){
/******
* pass touch/mouse events to the touch manager
*/
TouchManager::one().touchDown(button, ofVec2f(x, y));
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button){
/******
* pass touch/mouse events to the touch manager
*/
TouchManager::one().touchUp(button, ofVec2f(x, y));
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h){
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg){
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo){
}