rt300@0
|
1 //
|
rt300@0
|
2 // globalUI.mm
|
rt300@0
|
3 // Wablet
|
rt300@0
|
4 //
|
rt300@0
|
5 // Created by Robert Tubb on 19/03/2012.
|
rt300@0
|
6 // Copyright (c) 2012 __MyCompanyName__. All rights reserved.
|
rt300@0
|
7 //
|
rt300@0
|
8
|
rt300@0
|
9 #include <iostream>
|
rt300@0
|
10 #include "globalUI.h"
|
rt300@0
|
11
|
rt300@0
|
12 GlobalUI::GlobalUI(){
|
rt300@0
|
13 // array of buttons,
|
rt300@0
|
14
|
rt300@0
|
15
|
rt300@0
|
16 numButtons = 12;
|
rt300@0
|
17 borderSize = 128;
|
rt300@0
|
18 buttonSize = 100;
|
rt300@0
|
19
|
rt300@0
|
20 buttons = new ControlButton *[numButtons];
|
rt300@0
|
21
|
rt300@0
|
22 touchMode = GRAB;
|
rt300@0
|
23
|
rt300@0
|
24 }
|
rt300@0
|
25
|
rt300@0
|
26 void GlobalUI::passCallBack(UIFunctor specFuncA){
|
rt300@0
|
27
|
rt300@0
|
28 }
|
rt300@0
|
29 void GlobalUI::makeButtons(Mesh *atheMeshPtr){
|
rt300@0
|
30
|
rt300@0
|
31 // set up button size depending on screen resolution
|
rt300@0
|
32
|
rt300@0
|
33 int w = ofGetWidth();
|
rt300@0
|
34 cout << "width = " << w << "\n";
|
rt300@0
|
35 if (w == 768){ // ipad
|
rt300@0
|
36
|
rt300@0
|
37 }else if (w == 480){ // iphone
|
rt300@0
|
38 borderSize = 80;
|
rt300@0
|
39 buttonSize = 70;
|
rt300@0
|
40
|
rt300@0
|
41 }else if (w == 1234){ // retinass?
|
rt300@0
|
42
|
rt300@0
|
43 }else{
|
rt300@0
|
44 // default to what?
|
rt300@0
|
45
|
rt300@0
|
46 }
|
rt300@0
|
47
|
rt300@0
|
48 theMeshPtr = atheMeshPtr;
|
rt300@0
|
49
|
rt300@0
|
50 ofColor red(250,0,0);
|
rt300@0
|
51 ofColor blue(0,0,250);
|
rt300@0
|
52 ofColor green(0,250,0);
|
rt300@0
|
53
|
rt300@0
|
54 buttons[0] = new ControlButton(2,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,(borderSize-buttonSize)*0.5,"still",atheMeshPtr,green);
|
rt300@0
|
55 buttons[1] = new ControlButton(0,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,borderSize+(borderSize-buttonSize)*0.5,"smooth",atheMeshPtr,green);
|
rt300@0
|
56 buttons[2] = new ControlButton(1,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,borderSize*2+(borderSize-buttonSize)*0.5,"drift",atheMeshPtr,green);
|
rt300@0
|
57 buttons[3] = new ControlButton(3,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,borderSize*3+(borderSize-buttonSize)*0.5,"gravity",atheMeshPtr,green);
|
rt300@0
|
58 buttons[4] = new ControlButton(4,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,borderSize*4+(borderSize-buttonSize)*0.5,"free",atheMeshPtr,green);
|
rt300@0
|
59 buttons[5] = new ControlButton(5,buttonSize,buttonSize,(borderSize-buttonSize)*0.5,borderSize*5+(borderSize-buttonSize)*0.5,"something",atheMeshPtr,green);
|
rt300@0
|
60
|
rt300@0
|
61 // touch mode buttons
|
rt300@0
|
62 buttons[6] = new ControlButton(6,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,(borderSize-buttonSize)*0.5,"grab",atheMeshPtr, blue);
|
rt300@0
|
63 buttons[7] = new ControlButton(7,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,borderSize+(borderSize-buttonSize)*0.5,"force",atheMeshPtr, blue);
|
rt300@0
|
64 buttons[8] = new ControlButton(8,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,borderSize*2+(borderSize-buttonSize)*0.5,"stick",atheMeshPtr, blue);
|
rt300@0
|
65 buttons[9] = new ControlButton(9,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,borderSize*3+(borderSize-buttonSize)*0.5,"unstick",atheMeshPtr, blue);
|
rt300@0
|
66 buttons[10] = new ControlButton(10,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,borderSize*4+(borderSize-buttonSize)*0.5,"drawscan",atheMeshPtr, red);
|
rt300@0
|
67 buttons[11] = new ControlButton(11,buttonSize,buttonSize,borderSize+ofGetHeight()+(borderSize-buttonSize)*0.5,borderSize*5+(borderSize-buttonSize)*0.5,"reset",atheMeshPtr, red);
|
rt300@0
|
68 }
|
rt300@0
|
69
|
rt300@0
|
70 //--------------------------------------------------------------
|
rt300@0
|
71 void GlobalUI::draw(){
|
rt300@0
|
72
|
rt300@0
|
73
|
rt300@0
|
74 for(int i=0; i<numButtons;i++){
|
rt300@0
|
75 buttons[i]->draw();
|
rt300@0
|
76 }
|
rt300@0
|
77
|
rt300@0
|
78 //ofSetColor(blue);
|
rt300@0
|
79 //ofDrawBitmapString("touch mode", 670, 25);
|
rt300@0
|
80 }
|
rt300@0
|
81 //--------------------------------------------------------------
|
rt300@0
|
82 bool GlobalUI::inUIZone(float x, float y){
|
rt300@0
|
83 if (x < borderSize || x > borderSize + ofGetHeight()){
|
rt300@0
|
84 return true;
|
rt300@0
|
85
|
rt300@0
|
86 }else{
|
rt300@0
|
87 return false;
|
rt300@0
|
88 }
|
rt300@0
|
89 }
|
rt300@0
|
90
|
rt300@0
|
91 //--------------------------------------------------------------
|
rt300@0
|
92 bool GlobalUI::handleTouchDown(int ax, int ay){
|
rt300@0
|
93 // returns true if touch is not to be left to the mesh
|
rt300@0
|
94 if(inUIZone(ax,ay)){
|
rt300@0
|
95
|
rt300@0
|
96 /* not needed now we are using ofxUI
|
rt300@0
|
97
|
rt300@0
|
98 for(int i=0; i < numButtons;i++){
|
rt300@0
|
99 if(buttons[i]->checkTouchArea(ax,ay)){
|
rt300@0
|
100 buttons[i]->press();
|
rt300@0
|
101 }
|
rt300@0
|
102 }
|
rt300@0
|
103 */
|
rt300@0
|
104 return true;
|
rt300@0
|
105 }else{
|
rt300@0
|
106
|
rt300@0
|
107 return false;
|
rt300@0
|
108 }
|
rt300@0
|
109 }
|
rt300@0
|
110 //--------------------------------------------------------------
|
rt300@0
|
111 bool GlobalUI::handleTouchUp(int ax, int ay){
|
rt300@0
|
112 // returns true if touch is not to be left to the mesh
|
rt300@0
|
113 if(inUIZone(ax,ay)){
|
rt300@0
|
114 /* not needed now we are using ofxUI
|
rt300@0
|
115
|
rt300@0
|
116 for(int i=0; i < numButtons;i++){
|
rt300@0
|
117 if(buttons[i]->checkTouchArea(ax,ay)){
|
rt300@0
|
118 buttons[i]->press();
|
rt300@0
|
119 }
|
rt300@0
|
120 }
|
rt300@0
|
121 */
|
rt300@0
|
122 return true;
|
rt300@0
|
123 }else{
|
rt300@0
|
124
|
rt300@0
|
125 return false;
|
rt300@0
|
126 }
|
rt300@0
|
127 }
|
rt300@0
|
128 //--------------------------------------------------------------
|
rt300@0
|
129 bool GlobalUI::handleTouchMove(int ax, int ay){
|
rt300@0
|
130 // returns true if touch is not to be left to the mesh
|
rt300@0
|
131 if(inUIZone(ax,ay)){
|
rt300@0
|
132
|
rt300@0
|
133 return true;
|
rt300@0
|
134 }else{
|
rt300@0
|
135
|
rt300@0
|
136 return false;
|
rt300@0
|
137 }
|
rt300@0
|
138 }
|
rt300@0
|
139
|
rt300@0
|
140
|