Mercurial > hg > tweakathon2ios
diff UI code/Buttron.mm @ 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 | 8124f46eda65 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/UI code/Buttron.mm Fri Oct 10 11:46:42 2014 +0100 @@ -0,0 +1,179 @@ +// +// buttron.cpp +// emptyExample +// +// Created by Robert Tubb on 30/04/2013. +// +// + +#include "buttron.h" + +//------------------------------------------------------------------ + +Buttron::Buttron(){ + // + //cout << " buttron default constructur\n"; +} +//------------------------------------------------------------------ +Buttron::Buttron( + float ax, + float ay, + float awidth, + float aheight, + float athickness, + float aradius, + ofColor aforegroundHi, + ofColor abackgroundHi, + ofColor aforegroundLo, + ofColor abackgroundLo) : + UIElement(ax,ay,awidth,aheight,abackgroundLo), + thickness(athickness), + radius(aradius), + foregroundHi(aforegroundHi), + backgroundHi(abackgroundHi), + foregroundLo(aforegroundLo), + backgroundLo(abackgroundLo) { + //cout << "phew, buttron big constructur\n"; + on = false; +} +//------------------------------------------------------------------ +Buttron::Buttron(float ax, + float ay, + const UIProps& props): + UIElement(ax,ay,props.buttonWidth,props.buttonHeight, props) + +{ + + thickness = props.borderThickness; + radius = props.cornerRadius; + foregroundHi = props.buttonHi; + backgroundHi = props.generalBackground; + foregroundLo = props.buttonLo; + backgroundLo = props.generalBackground; + + on = false; +} +//------------------------------------------------------------------ +Buttron::Buttron(float ax, + float ay, + float awidth, + float aheight, + const UIProps& props): + UIElement(ax,ay,awidth,aheight, props) + +{ + //cout << "slider (meh) recommended constructor\n"; + + thickness = props.borderThickness; + radius = props.cornerRadius; + foregroundHi = props.buttonHi; + backgroundHi = props.generalBackground; + foregroundLo = props.buttonLo; + backgroundLo = props.generalBackground; + fgInactive = props.inactiveGreyedOut; + + on = false; +} +//------------------------------------------------------------------ +void Buttron::draw(){ + if(hidden) return; + //cout << "drawing button" << endl; + ofFill(); + UIElement::draw(); // should do background + drawOutline(); + drawTextLabel(); +} +//------------------------------------------------------------------ +void Buttron::drawTextLabel(){ + ofColor fg,bg; + + if(on){ + fg = foregroundHi; + bg = backgroundHi; + }else{ + fg = foregroundLo; + bg = backgroundLo; + } + if(inactive){ + fg = fgInactive; + } + ofSetColor(fg); + verdana16.drawString(labelName, x + thickness*2, y + 35); + +} +//------------------------------------------------------------------ +void Buttron::drawOutline(){ + + // draw bars + ofColor fg,bg; + + if(on){ + fg = foregroundHi; + bg = backgroundHi; + }else{ + fg = foregroundLo; + bg = backgroundLo; + } + ofSetColor(fg); + + float cornerSize = thickness + radius; + // left + ofRect(x, y+cornerSize, thickness, height - 2*(cornerSize)); + //right + ofRect(x + width - thickness, y+cornerSize, thickness, height - 2*(cornerSize)); + // top + ofRect(x+cornerSize, y, width-2*(cornerSize), thickness); + // bottom + ofRect(x+cornerSize, y+height-thickness, width-2*(cornerSize), thickness); + + // draw corner foreground circles + + //tl + ofCircle(x+cornerSize, y+cornerSize, cornerSize); + + + //tr + + ofCircle(x+width-cornerSize, y+cornerSize, cornerSize); + + //bl + + ofCircle(x+cornerSize, y+height-cornerSize, cornerSize); + + //br + + ofCircle(x+width-cornerSize, y+height-cornerSize, cornerSize); + + // draw corner inner bg circles + ofSetColor(bg); + ofCircle(x+cornerSize, y+cornerSize, radius); + + ofCircle(x+width-cornerSize, y+cornerSize, radius); + + ofCircle(x+cornerSize, y+height-cornerSize, radius); + + ofCircle(x+width-cornerSize, y+height-cornerSize, radius); + + // fill in background + ofRect(x+cornerSize,y+thickness,width-2*cornerSize,height-2*thickness); + ofRect(x+thickness, y+cornerSize, radius, height-2*cornerSize); + ofRect(x+width-cornerSize, y+cornerSize, radius, height-2*cornerSize); +} +//------------------------------------------------------------------------------ +bool Buttron::handleMyTouch(int tx, int ty, touchType ttype, int touchID){ + + //cout << "buttron handling touch\n"; + if(ttype == TOUCH_DOWN){ + on = true; + if(callback) callback(myParamID,1); + + }else if(ttype == TOUCH_MOVED){ + + }else if(ttype == TOUCH_UP){ + on = false; + } + return true; // necessary? + +} + +//------------------------------------------------------------------------------