annotate UI code/UIElement.h @ 0:a223551fdc1f

First commit - copy from tweakathlon.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 10 Oct 2014 11:46:42 +0100
parents
children af71bf84660f
rev   line source
rt300@0 1 //
rt300@0 2 // UIElement.h
rt300@0 3 // emptyExample
rt300@0 4 //
rt300@0 5 // Created by Robert Tubb on 22/05/2013.
rt300@0 6 //
rt300@0 7 // literally just an area of the screen that is a ui element
rt300@0 8
rt300@0 9 #ifndef __emptyExample__UIElement__
rt300@0 10 #define __emptyExample__UIElement__
rt300@0 11 #include "ofMain.h"
rt300@0 12 #include "globalVariables.h"
rt300@0 13 #include <iostream>
rt300@0 14 #include <string>
rt300@0 15 #include "boost/function.hpp"
rt300@0 16 #include "UIProperties.h"
rt300@0 17
rt300@0 18 typedef boost::function<void(int, int)> UICallbackFunction;
rt300@0 19
rt300@0 20 class MessageOrganiser;
rt300@0 21
rt300@0 22 class UIElement{
rt300@0 23 public:
rt300@0 24
rt300@0 25
rt300@0 26 UICallbackFunction callback;
rt300@0 27
rt300@0 28 UIElement();
rt300@0 29 virtual ~UIElement(){};
rt300@0 30 // recommended
rt300@0 31 UIElement(float ax,
rt300@0 32 float ay,
rt300@0 33 float awidth,
rt300@0 34 float aheight,
rt300@0 35 const UIProps& props);
rt300@0 36
rt300@0 37 UIElement(float ax,
rt300@0 38 float ay,
rt300@0 39 float awidth,
rt300@0 40 float aheight,
rt300@0 41 ofColor bg);
rt300@0 42
rt300@0 43 virtual void setLabel(string label){
rt300@0 44 labelName = label;
rt300@0 45 }
rt300@0 46 virtual void draw();
rt300@0 47 void hide(){
rt300@0 48 hidden = true;
rt300@0 49 on = false;
rt300@0 50
rt300@0 51 };
rt300@0 52 void show(){
rt300@0 53 hidden = false;
rt300@0 54 on = true;
rt300@0 55
rt300@0 56 };
rt300@0 57 bool touch(int x, int y, touchType ttype, int touchID);
rt300@0 58
rt300@0 59 virtual void addHandler(UICallbackFunction handlerFunction, int paramID) // virtual?
rt300@0 60 {
rt300@0 61 cout << "handler added to UIElement " << endl;
rt300@0 62 callback = handlerFunction;
rt300@0 63 myParamID = paramID;
rt300@0 64 };
rt300@0 65
rt300@0 66 virtual void setValue(float value){
rt300@0 67 cout << "not valid to set value on this?" << endl;
rt300@0 68 };
rt300@0 69 virtual void setHintValue(float value){
rt300@0 70 cout << "not valid to set value on this?" << endl;
rt300@0 71 };
rt300@0 72 virtual void showHint(bool value){
rt300@0 73 cout << "not valid to set value on this?" << endl;
rt300@0 74 };
rt300@0 75 virtual void setHintColor(ofColor c){
rt300@0 76 cout << "not valid to set value on this?" << endl;
rt300@0 77 };
rt300@0 78 controllerType getType() const {
rt300@0 79 return myType;
rt300@0 80 }
rt300@0 81 float getWidth() const {return width;};
rt300@0 82 virtual void setHighlight(bool hion){
rt300@0 83 // ?
rt300@0 84 on = hion;
rt300@0 85 };
rt300@0 86 void setActive(bool isActive){
rt300@0 87 inactive = !isActive; // thats logic right?
rt300@0 88 }
rt300@0 89 void setX(float ax){
rt300@0 90 x = ax;
rt300@0 91 };
rt300@0 92 void setY(float ay){
rt300@0 93 y = ay;
rt300@0 94 };
rt300@0 95 protected:
rt300@0 96
rt300@0 97 float x;
rt300@0 98 float y;
rt300@0 99 float width;
rt300@0 100 float height;
rt300@0 101 bool on;
rt300@0 102 int myParamID;
rt300@0 103 list<int> myTouchIDs;
rt300@0 104
rt300@0 105 ofColor background;
rt300@0 106
rt300@0 107 string labelName;
rt300@0 108 ofTrueTypeFont verdana16;
rt300@0 109 ofTrueTypeFont bigFont;
rt300@0 110 ofTrueTypeFont smallFont;
rt300@0 111 controllerType myType;
rt300@0 112
rt300@0 113 bool hidden; // don't draw dont touch
rt300@0 114 bool inactive; // dont touch, draw dimmed
rt300@0 115
rt300@0 116 void init();
rt300@0 117
rt300@0 118 bool isExistingTouchID(int touchID){
rt300@0 119 // is id in list
rt300@0 120 std::list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 121 if (findIter == myTouchIDs.end()){
rt300@0 122 return false;
rt300@0 123 }else{
rt300@0 124 return true;
rt300@0 125 }
rt300@0 126 };
rt300@0 127
rt300@0 128 void addTouchID(int touchID){
rt300@0 129 //list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 130 //if(findIter == myTouchIDs.end()){ // checks for duplicates
rt300@0 131 myTouchIDs.insert(myTouchIDs.begin(), touchID);
rt300@0 132 //}
rt300@0 133 };
rt300@0 134 void removeTouchID(int touchID){
rt300@0 135 list<int>::iterator findIter = std::find(myTouchIDs.begin(), myTouchIDs.end(), touchID);
rt300@0 136 if(findIter != myTouchIDs.end()){
rt300@0 137 myTouchIDs.erase(findIter);
rt300@0 138 }
rt300@0 139 };
rt300@0 140 static float sumWidth(float total, UIElement* element){
rt300@0 141 return total + element->getWidth();
rt300@0 142 }
rt300@0 143 bool isMyTouch(int x, int y, touchType ttype, int touchID);
rt300@0 144 bool touchIsInMyArea(int tx, int ty);
rt300@0 145 virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID) = 0; // subclass handles it
rt300@0 146
rt300@0 147 bool isCoordInMyRegion(double x, double y); // not used
rt300@0 148
rt300@0 149
rt300@0 150 };
rt300@0 151 #endif /* defined(__emptyExample__UIElement__) */