view UI code/Buttron.mm @ 41:ba426cc4e6e1

better sequence gen , same for easy (1) and hard (many ) seq fixed judder on sliders
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Fri, 05 Dec 2014 18:36:05 +0000
parents fea11c3d1d94
children d810aa9ca03a
line wrap: on
line source
//
//  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";
    behaviourMode = MOMENTARY;
    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.backgroundHi;
    foregroundLo = props.buttonLo;
    backgroundLo = props.generalBackground;
    behaviourMode = MOMENTARY;
    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.backgroundHi;
    foregroundLo = props.buttonLo;
    backgroundLo = props.generalBackground;
    fgInactive = props.inactiveGreyedOut;
    
    on = false;
    behaviourMode = MOMENTARY;
}
//------------------------------------------------------------------
void Buttron::draw(){
    if(hidden) return;
    
    ofDisableDepthTest();
    //cout << "drawing button" << endl;
    ofFill();
    UIElement::draw(); // should do background
    drawOutline();
    drawTextLabel();
    
    ofEnableDepthTest();
}
//------------------------------------------------------------------
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;
    }
    if(inactive){
        ofSetColor(fgInactive);
    }
    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(behaviourMode == MOMENTARY){
        if(ttype == TOUCH_DOWN){
            on = true;
            if(callback) callback(myParamID,1);
            
        }else if(ttype == TOUCH_MOVED){
            
        }else if(ttype == TOUCH_UP){
            on = false;
        }
    }
    if(behaviourMode == TOGGLE)
        if(ttype == TOUCH_DOWN){
            on = !on;
            if(callback) callback(myParamID,1);
        }
    return true; // necessary?
    
}

//------------------------------------------------------------------------------