view UI code/ButtronSlider.h @ 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.h
//  emptyExample
//
//  Created by Robert Tubb on 22/05/2013.
//
//

#ifndef __emptyExample__ButtronSlider__
#define __emptyExample__ButtronSlider__
#include "Buttron.h"
#include <iostream>

class ButtronSlider : public Buttron{
public:

    ~ButtronSlider(){};
    ButtronSlider(float ax,
                  float ay,
                  float awidth,
                  float aheight,
                  float athickness,
                  float aradius,
                  ofColor aforegroundHi,
                  ofColor abackgroundHi,
                  ofColor aforegroundLo,
                  ofColor abackgroundLo,
                  SliderType type);
    
    ButtronSlider(float ax,
                  float ay,
                  float awidth,
                  float aheight,
                  SliderType type,
                  const UIProps& props);
    
    void init();
    void draw(){
        Buttron::draw();
        ofDisableDepthTest();
        drawIndicator(value);
        if(hintShowing) drawHintIndicator();
        ofEnableDepthTest();
    }
    
    void setHintValue(double hval){
        hintValue = (hval - minVal)/(maxVal - minVal);
    };
    void setHintColor(ofColor c){
        hintColor = c;
    };
    void setColor(ofColor c){
        foregroundHi = c;
        foregroundLo = c;
    }
    void showHint(bool tf){
        hintShowing = tf;
    };
    void setValue(double avalue){
        // scale appropriately to 0-1   (maxVal - minVal)*prop + minVal
        value = avalue; // (avalue - minVal)/(maxVal - minVal);
    };
    
    void setValueAndScale(double avalue){
        // scale appropriately to 0-1   (maxVal - minVal)*prop + minVal
        value =  (avalue - minVal)/(maxVal - minVal);
    };
    void showValueIndicator(bool show){
        indicatorShowing = show;
    }
    virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID);
    
    void setRange(float lo, float hi){
        minVal = lo;
        maxVal = hi;
    }
    
private:
    void drawIndicator(double proportion);
    float minVal;
    float maxVal;
    void drawHintIndicator();
    SliderType sliderType;
    float value; // [0. 1.]
    float hintValue;
    bool hintShowing;
    bool indicatorShowing;
    ofColor hintColor;
};

#endif /* defined(__emptyExample__ButtronSlider__) */