Mercurial > hg > tweakathon2ios
diff UI code/UIElementContainer.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 | 2bd658b44c2d |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI code/UIElementContainer.h Fri Oct 10 11:46:42 2014 +0100 @@ -0,0 +1,107 @@ +// +// 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__) */