annotate UI code/UIElementContainer.h @ 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 a62e033117fa
children
rev   line source
rt300@0 1 //
rt300@0 2 // UIElementContainer.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 //
rt300@0 8
rt300@0 9
rt300@0 10 // a meta button, with border.
rt300@0 11
rt300@0 12 #ifndef __emptyExample__UIElementContainer__
rt300@0 13 #define __emptyExample__UIElementContainer__
rt300@0 14
rt300@0 15 #include <iostream>
rt300@0 16 #include "globalVariables.h"
rt300@0 17 #include "ofMain.h"
rt300@0 18 #include "UIElement.h"
rt300@0 19 #include "boost/bind.hpp"
rt300@0 20 #include "boost/function.hpp"
rt300@0 21 #include "timeController.h"
rt300@0 22 // is a UI "panel" containing sub elements
rt300@0 23 // helps control the focus of the touch event
rt300@0 24
rt300@0 25
rt300@0 26 extern TimeController timeController;
rt300@0 27
rt300@0 28 class UIElementContainer: public UIElement{
rt300@0 29 public:
rt300@0 30 UIProps myProps;
rt300@0 31 vector<UIElement *> subElements;
rt300@0 32 UIElementContainer();
rt300@0 33 ~UIElementContainer(){
rt300@0 34 removeAllSubelements();
rt300@0 35 };
rt300@0 36 UIElementContainer(float ax,
rt300@0 37 float ay,
rt300@0 38 float awidth,
rt300@0 39 float aheight,
rt300@0 40 const UIProps& props); // constructor 1 : we add stuff later
rt300@0 41
rt300@0 42 void addElement(UIElement *elm){
rt300@0 43 subElements.push_back(elm);
rt300@0 44
rt300@0 45 };
rt300@0 46 void removeAllSubelements();
rt300@0 47
rt300@0 48 int getNumberOfControls();
rt300@0 49 UIElement* getElement(int idx){
rt300@0 50 if (idx < subElements.size()){
rt300@0 51 return subElements[idx];
rt300@0 52 }else{
rt300@0 53 cout << "ERROR ERROR: index too big for subelemens" << endl;
rt300@0 54 }
rt300@0 55
rt300@0 56 }
rt300@0 57 void showBorder(bool s){
rt300@0 58 if(s){
rt300@0 59 cthickness = 1;
rt300@0 60
rt300@0 61 }
rt300@0 62 }
rt300@0 63 virtual void draw();
rt300@0 64 bool handleMyTouch(int x, int y, touchType ttype, int touchID){
rt300@0 65 vector<UIElement *>::iterator UIitr;
rt300@0 66 for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){
rt300@0 67 (*UIitr)->touch(x,y,ttype,touchID);
rt300@0 68 }
rt300@0 69 return true;
rt300@0 70 }
rt300@0 71
rt300@0 72 void setActive(bool isActive){
rt300@0 73 vector<UIElement *>::iterator UIitr;
rt300@0 74 for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){
rt300@0 75 (*UIitr)->setActive(isActive);
rt300@0 76 }
rt300@0 77 }
rt300@0 78
rt300@0 79 void autoArrangeRow(){
rt300@0 80 // goes thru subelements and sets x and y pos to something sensible
rt300@0 81
rt300@0 82 // add up all element widths
rt300@0 83 float sum = accumulate(subElements.begin(), subElements.end(), 0.0, &UIElement::sumWidth);
rt300@0 84
rt300@0 85 float spaceLeft = width - sum;
rt300@0 86
rt300@0 87 float spac = spaceLeft/(getNumberOfControls()+1);
rt300@0 88
rt300@0 89 if (spac <= 0){
rt300@0 90 cout << "ERROR: not enough space for controls" << endl;
rt300@0 91
rt300@0 92 }
rt300@0 93 float pos = spac;
rt300@0 94 vector<UIElement *>::iterator ei;
rt300@0 95 for(ei = subElements.begin(); ei < subElements.end(); ei++){
rt300@0 96 (*ei)->setX(pos);
rt300@0 97 pos = pos + (*ei)->getWidth() + spac;
rt300@0 98 }
rt300@0 99 // TODO y set to centred
rt300@0 100 }
rt300@42 101
rt300@42 102
rt300@42 103 void showHideElementWithName(string label, bool show){
rt300@42 104
rt300@42 105 for( auto eit = subElements.begin(); eit < subElements.end(); eit++){
rt300@42 106 if( (*eit)->getLabel() == label ){
rt300@42 107 if (show){
rt300@42 108 (*eit)->show();
rt300@42 109 }else{
rt300@42 110 (*eit)->hide();
rt300@42 111 }
rt300@42 112 }
rt300@42 113 }
rt300@42 114 }
rt300@42 115 void showOnlyElementNamed(string label){
rt300@42 116 for( auto eit = subElements.begin(); eit < subElements.end(); eit++){
rt300@42 117 if( (*eit)->getLabel() == label ){
rt300@42 118
rt300@42 119 (*eit)->show();
rt300@42 120 }else{
rt300@42 121 (*eit)->hide();
rt300@42 122 }
rt300@42 123 }
rt300@42 124 }
rt300@42 125 void showAllElements(){
rt300@42 126 for( auto eit = subElements.begin(); eit < subElements.end(); eit++){
rt300@42 127
rt300@42 128 (*eit)->show();
rt300@49 129 (*eit)->setOn(false);
rt300@49 130
rt300@42 131 }
rt300@42 132 }
rt300@0 133 private:
rt300@0 134 void drawBorder();
rt300@0 135 double cthickness;
rt300@0 136 bool flashing;
rt300@0 137 };
rt300@0 138
rt300@0 139 #endif /* defined(__emptyExample__UIElementContainer__) */