view UI code/ButtronXY.h @ 37:52dbd5b4cfa9

slider feedback and textures
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Wed, 03 Dec 2014 11:38:26 +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__) */