view UI code/ButtronSlider.mm @ 28:953db6518738

leap version more or less there, needs btter results feedback but thats detail. "no movement" bit is stupid cos peopel can move their hand. light flash not work.
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Thu, 30 Oct 2014 18:35:00 +0000
parents 27cdf475aa4b
children e7af34b1af83
line wrap: on
line source
//
//  ButtronSlider.cpp
//  emptyExample
//
//  Created by Robert Tubb on 22/05/2013.
//
//

#include "ButtronSlider.h"


ButtronSlider::ButtronSlider(float ax,
                             float ay,
                             float awidth,
                             float aheight,
                             float athickness,
                             float aradius,
                             ofColor aforegroundHi,
                             ofColor abackgroundHi,
                             ofColor aforegroundLo,
                             ofColor abackgroundLo,
                             SliderType type) :
Buttron(ax,ay,awidth,aheight,athickness,aradius,aforegroundHi,abackgroundHi,aforegroundLo,abackgroundLo),
sliderType(type)

{

    init();
}
ButtronSlider::ButtronSlider(float ax,
                             float ay,
                             float awidth,
                             float aheight,
                             SliderType type,
                             const UIProps& props) :
Buttron(ax,ay,awidth,aheight,props),
sliderType(type)

{
    init();
}
void  ButtronSlider::init(){
    myType = SLIDER;
    minVal = 0.;
    maxVal = 127.;
    value = 0.6;
    hintShowing = false;
}
// 
//---------------------------------------------------------------------
void ButtronSlider::drawIndicator(double proportion){
    if(!indicatorShowing) return;
    if(on){
        ofSetColor(foregroundHi);
    }else{
        ofSetColor(foregroundLo);
        
    }
    if(inactive){
        ofSetColor(fgInactive);
    }
    if(sliderType == FILL){

        double maxH = height - 2 * thickness; //
        double w = width - 2 * thickness;//
        double barheight = value*maxH;
        double top = y + height - thickness - barheight;
        ofRect(x+thickness, top, w, barheight);
        
    }else if(sliderType == LINE){
        double loc = y + thickness +  (1 -value)*(height-3*thickness);
        ofRect(x+thickness,loc, width-2*thickness,thickness);
    }
    

}

void ButtronSlider::drawHintIndicator(){

    ofSetColor(hintColor);
    float hthick = 6;
    double loc = y + hthick +  (1 - hintValue)*(height-3*hthick);
    ofRect(x-thickness,loc, width+2*thickness,hthick);

}

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

bool ButtronSlider::handleMyTouch(int tx, int ty, touchType ttype, int touchID){

    double ly = ty - y - thickness - radius;
    
    double prop;
    
    prop = 1 - ly/(height - 2 * (thickness + radius));

    if(prop > 1.) prop = 1.;                                                           
    if(prop < 0.) prop = 0.;

    setValue(prop);
    int scaleVal = int((maxVal - minVal)*prop + minVal);

    vector<int> pass;
    if(callback) callback(myParamID,scaleVal);
    
    return true;
}