view UI code/ButtronXY.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 a223551fdc1f
children
line wrap: on
line source
//
//  ButtronXY.h
//  tweakathlon
//
//  Created by Robert Tubb on 25/06/2013.
//
//

#ifndef __tweakathlon__ButtronXY__
#define __tweakathlon__ButtronXY__

#include <iostream>
#include "buttron.h"

class ButtronXY: public Buttron {
    
public:
    
    UICallbackFunction callback;
    
    double xvalue, yvalue; // [0. 1.]
    ~ButtronXY(){};
    ButtronXY(float ax,
              float ay,
              const UIProps& props);
    ButtronXY(float ax,
                  float ay,
                  float awidth,
                  float athickness,
                  float aradius,
                  ofColor aforegroundHi,
                  ofColor abackgroundHi,
                  ofColor aforegroundLo,
                  ofColor abackgroundLo);
    
    void draw(){
        if(hidden) return;
        Buttron::draw();
        drawIndicator();
        drawLabels();
    }
    void drawLabels(){
        // where?
        ofColor fg,bg;
        
        if(on){
            fg = foregroundHi;
            bg = backgroundHi;
        }else{
            fg = foregroundLo;
            bg = backgroundLo;
        }
        ofSetColor(fg);
        verdana16.drawString(labelNamex, x + width/2, y + thickness*4);
        verdana16.drawString(labelNamey,   x + thickness*2, y + height/2+7);
    }
    void init();
    
    void setValue(double axvalue, double ayvalue){
        xvalue = axvalue;
        yvalue = ayvalue;
    };
    void setValueAndScale(double axvalue, double ayvalue){
        xvalue =  (axvalue - minVal)/(maxVal - minVal);
        yvalue =  (ayvalue - minVal)/(maxVal - minVal);
    }
    void setHintValue(double hvalx, double hvaly){
        hintValuex = (hvalx - minVal)/(maxVal - minVal);
        hintValuey = (hvaly - minVal)/(maxVal - minVal);
        
    };
    void setHintColor(ofColor c){
        // TODO somehow set the fill ? 
    };
    void setLabel(string xlabel, string ylabel){
        labelNamex = xlabel;
        labelNamey = ylabel;
    }

    
    void showHint(bool tf){
        hintShowing = tf;
    };
    virtual bool handleMyTouch(int x, int y, touchType ttype, int touchID);
    
    virtual void addHandler(UICallbackFunction handlerFunction, int paramIDX, int paramIDY) // virtual?
    {
        cout << "handler added to XYUIElement " << endl;
        callback = handlerFunction;
        myParamIDX = paramIDX;
        myParamIDY = paramIDY;
    };

    
private:
    void drawIndicator();
    void drawHintIndicator();
    float maxVal;
    float minVal;
    int myParamIDX;
    int myParamIDY;
    float hintValuex;
    float hintValuey;
    bool hintShowing;
    string labelNamex;
    string labelNamey;
};

#endif /* defined(__tweakathlon__ButtronXY__) */