Mercurial > hg > tweakathon2ios
view UI code/UIElementContainer.h @ 37:52dbd5b4cfa9
slider feedback and textures
author | Robert Tubb <rt300@eecs.qmul.ac.uk> |
---|---|
date | Wed, 03 Dec 2014 11:38:26 +0000 |
parents | a223551fdc1f |
children | 2bd658b44c2d |
line wrap: on
line source
// // UIElementContainer.h // emptyExample // // Created by Robert Tubb on 22/05/2013. // // // a meta button, with border. #ifndef __emptyExample__UIElementContainer__ #define __emptyExample__UIElementContainer__ #include <iostream> #include "globalVariables.h" #include "ofMain.h" #include "UIElement.h" #include "boost/bind.hpp" #include "boost/function.hpp" #include "timeController.h" // is a UI "panel" containing sub elements // helps control the focus of the touch event extern TimeController timeController; class UIElementContainer: public UIElement{ public: UIProps myProps; vector<UIElement *> subElements; UIElementContainer(); ~UIElementContainer(){ removeAllSubelements(); }; UIElementContainer(float ax, float ay, float awidth, float aheight, const UIProps& props); // constructor 1 : we add stuff later void addElement(UIElement *elm){ subElements.push_back(elm); }; void removeAllSubelements(); int getNumberOfControls(); UIElement* getElement(int idx){ if (idx < subElements.size()){ return subElements[idx]; }else{ cout << "ERROR ERROR: index too big for subelemens" << endl; } } void showBorder(bool s){ if(s){ cthickness = 1; } } virtual void draw(); bool handleMyTouch(int x, int y, touchType ttype, int touchID){ vector<UIElement *>::iterator UIitr; for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ (*UIitr)->touch(x,y,ttype,touchID); } return true; } void setActive(bool isActive){ vector<UIElement *>::iterator UIitr; for(UIitr = subElements.begin(); UIitr < subElements.end(); UIitr++){ (*UIitr)->setActive(isActive); } } void autoArrangeRow(){ // goes thru subelements and sets x and y pos to something sensible // add up all element widths float sum = accumulate(subElements.begin(), subElements.end(), 0.0, &UIElement::sumWidth); float spaceLeft = width - sum; float spac = spaceLeft/(getNumberOfControls()+1); if (spac <= 0){ cout << "ERROR: not enough space for controls" << endl; } float pos = spac; vector<UIElement *>::iterator ei; for(ei = subElements.begin(); ei < subElements.end(); ei++){ (*ei)->setX(pos); pos = pos + (*ei)->getWidth() + spac; } // TODO y set to centred } private: void drawBorder(); double cthickness; bool flashing; }; #endif /* defined(__emptyExample__UIElementContainer__) */