annotate UI code/UIElement.mm @ 52:89944ab3e129 tip

fix oF linker errors ios8
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 03 Feb 2015 13:18:23 +0000
parents 4ad0d218f890
children
rev   line source
rt300@0 1 //
rt300@0 2 // UIElement.cpp
rt300@0 3 // emptyExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 22/05/2013.
rt300@0 6 //
rt300@0 7 //
rt300@0 8
rt300@0 9 #include "UIElement.h"
rt300@12 10
rt300@0 11 //----------------------------------------------------------------------
rt300@0 12 UIElement::UIElement(){
rt300@0 13 //
rt300@0 14 //cout << " UIElement default constructur BAD !!!\n";
rt300@0 15 init();
rt300@0 16 }
rt300@0 17 //----------------------------------------------------------------------
rt300@12 18
rt300@12 19
rt300@12 20 //----------------------------------------------------------------------
rt300@0 21 UIElement::UIElement(float ax,
rt300@0 22 float ay,
rt300@0 23 float awidth,
rt300@0 24 float aheight,
rt300@0 25 const UIProps& props) :
rt300@0 26 x(ax),
rt300@0 27 y(ay),
rt300@0 28 width(awidth),
rt300@0 29 height(aheight),
rt300@0 30 background(props.generalBackground)
rt300@0 31 {
rt300@0 32 //cout << " UIElement constructur with defs \n";
rt300@0 33 init();
rt300@0 34 verdana16 = props.verdana16;
rt300@0 35 bigFont = props.bigFont;
rt300@0 36
rt300@0 37 }
rt300@0 38 //----------------------------------------------------------------------
rt300@0 39 UIElement::UIElement(float ax,
rt300@0 40 float ay,
rt300@0 41 float awidth,
rt300@0 42 float aheight,
rt300@0 43 ofColor bg) :
rt300@0 44 x(ax),
rt300@0 45 y(ay),
rt300@0 46 width(awidth),
rt300@0 47 height(aheight),
rt300@0 48 background(bg)
rt300@0 49 {
rt300@0 50 init();
rt300@0 51
rt300@0 52 }
rt300@0 53 //----------------------------------------------------------------------
rt300@0 54 void UIElement::init(){
rt300@0 55
rt300@0 56
rt300@0 57 hidden = false;
rt300@0 58 inactive = false;
rt300@26 59 zLayer = 0;
rt300@41 60 onlyOneTouchAllowed = false;
rt300@0 61 }
rt300@0 62 //----------------------------------------------------------------------
rt300@0 63 void UIElement::draw(){
rt300@0 64 if(hidden) return;
rt300@0 65 //cout<<"element draw\n";
rt300@0 66 ofSetColor(background);
rt300@0 67 ofRect(x,y,width,height);
rt300@0 68
rt300@0 69
rt300@0 70 };
rt300@0 71 //----------------------------------------------------------------------
rt300@0 72 bool UIElement::touch(int tx, int ty, touchType ttype, int touchID){
rt300@0 73 if(isMyTouch(tx,ty,ttype,touchID)){
rt300@0 74 handleMyTouch(tx, ty, ttype,touchID);
rt300@0 75 return true;
rt300@0 76 }else{
rt300@0 77 return false;
rt300@0 78 }
rt300@0 79 }
rt300@41 80 bool UIElement::atLeastOneTouchAlready(){
rt300@41 81 if (myTouchIDs.size() >= 1){
rt300@41 82 return true;
rt300@41 83 }else{
rt300@41 84 return false;
rt300@41 85 }
rt300@41 86 }
rt300@0 87 //----------------------------------------------------------------------
rt300@0 88 // called first from all subclasses
rt300@0 89 bool UIElement::isMyTouch(int tx, int ty, touchType ttype, int touchID){
rt300@43 90 if(hidden || inactive){
rt300@43 91 // what if get made hidden or inactive when you're touching it ?
rt300@43 92 myTouchIDs.clear(); // just release them all
rt300@43 93 return false;
rt300@43 94 }
rt300@0 95
rt300@0 96 if(ttype == TOUCH_DOWN){
rt300@0 97 if (touchIsInMyArea(tx, ty)){
rt300@0 98 if (!isExistingTouchID(touchID)){
rt300@0 99 //cout << "Touchdown in area, grabbing focus " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@41 100 if (onlyOneTouchAllowed && atLeastOneTouchAlready()){
rt300@41 101 cout << "ignoring xtra touch" << endl;
rt300@42 102 return false;
rt300@41 103 }else{
rt300@41 104 addTouchID(touchID);
rt300@42 105 return true;
rt300@41 106 }
rt300@42 107
rt300@0 108
rt300@0 109 }else{
rt300@0 110 //shouldn't happen?
rt300@0 111 return true;
rt300@0 112 }
rt300@0 113
rt300@0 114 }else{
rt300@0 115 //cout << "Touchdown outside area, ignoring " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@0 116 return false;
rt300@0 117
rt300@0 118 }
rt300@0 119 }
rt300@0 120 if(ttype == TOUCH_UP){
rt300@0 121 if (isExistingTouchID(touchID)){
rt300@0 122 //cout << "Touch Up for my ID, handling " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@0 123 //myTouchID = -1;
rt300@0 124 removeTouchID(touchID);
rt300@0 125 return true;
rt300@0 126 }else{
rt300@0 127 //cout << "Touch Up NOT my ID, ignoring " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@0 128 return false;
rt300@0 129 }
rt300@0 130 }
rt300@0 131
rt300@0 132 if(ttype == TOUCH_MOVED){
rt300@0 133 if(isExistingTouchID(touchID)){
rt300@0 134 //cout << "Touch moved for my ID, handling " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@0 135 return true;
rt300@0 136 }else{
rt300@0 137 //cout << "Touch moved NOT my ID, ignore " << labelName << " mytouchID: " << myTouchID << " finger ID: " << touchID << endl;
rt300@0 138 return false;
rt300@0 139 }
rt300@0 140 }
rt300@0 141
rt300@0 142 cout << "UNHANDLED SITUATION!" << labelName << endl;
rt300@0 143 return false;
rt300@0 144
rt300@0 145 }
rt300@0 146
rt300@0 147 //----------------------------------------------------------------------
rt300@0 148 bool UIElement::touchIsInMyArea(int tx, int ty){
rt300@0 149
rt300@0 150 // work out relative coords
rt300@0 151 double relx = tx - x;
rt300@0 152 double rely = ty - y;
rt300@0 153 return !(relx < 0 || relx > width || rely < 0 || rely > height);
rt300@0 154 }
rt300@0 155 //----------------------------------------------------------------------
rt300@0 156 bool UIElement::isCoordInMyRegion(double ax, double ay){
rt300@0 157 if(hidden) return false;
rt300@0 158
rt300@0 159 if( (ax > x && ax < x+width) && (ay > y && ay < y+height)){
rt300@0 160 return true;
rt300@0 161 }else{
rt300@0 162 return false;
rt300@0 163 }
rt300@0 164
rt300@0 165 }
rt300@0 166 //----------------------------------------------------------------------
rt300@0 167 //----------------------------------------------------------------------
rt300@0 168 //----------------------------------------------------------------------
rt300@0 169 //----------------------------------------------------------------------
rt300@0 170 //----------------------------------------------------------------------