view UI code/3Dbox.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 8d7ae43b2edd
children
line wrap: on
line source
//
//  3Dbox.h
//  tweakathlon
//
//  Created by Robert Tubb on 13/02/2014.
//
//

#ifndef __tweakathlon___Dbox__
#define __tweakathlon___Dbox__

#include <iostream>
#include "UIElement.h"
#include "ofMain.h"


class Leap3DBox : public UIElement {
    
public:
    Leap3DBox(float ax,
              float ay,
              float awidth,
              float aheight,
              float azx,
              float azy,
              const UIProps& props);
    void init(const UIProps& props);
    
    virtual void setValueAndScale(int which, int val){
        if(which == 0)      xVal =  (val - minVal)/(maxVal - minVal);
        if(which == 1)      yVal =  (val - minVal)/(maxVal - minVal);
        if(which == 2)      zVal =  (val - minVal)/(maxVal - minVal);
        //cout << zVal << endl;
    }
    
    virtual void setHintValue(int which, int val){
        if(which == 0)      hintX =  (val - minVal)/(maxVal - minVal);
        if(which == 1)      hintY =  (val - minVal)/(maxVal - minVal);
        if(which == 2)      hintZ =  (val - minVal)/(maxVal - minVal);
        
    };

    virtual void draw(){
        if(hidden)return;
        if(on){
            ofSetColor(foregroundHi);
        }else{
            ofSetColor(foregroundLo);
            
        }
        if(inactive){
            ofSetColor(fgInactive);
        }
        

        // draw rear face zy+
        ofLine(zx+x,zy+y,zx+x,zy+y+height); // left
        ofLine(zx+x,zy+y,zx+x+width,zy+y); // top
        ofLine(zx+x+width,zy+y,zx+x+width,zy+y+height); //right
        ofLine(zx+x+width,zy+y+height,zx+x,zy+y+height); // bottom
        
        // draw indicators
        drawIndicator();
        
        ofSetColor(foregroundHi);
        
        // draw connectors
        ofLine(x,y,zx+x,zy+y); // top left
        ofLine(x+width,y,zx+x+width,zy+y); // top right
        ofLine(x,y+height,zx+x,zy+y+height); // bot left
        ofLine(x+width,y+height,zx+x+width,zy+y+height); // bot right

        
        // draw front face
        ofLine(x,y,x,y+height); // left
        ofLine(x,y,x+width,y); // top
        ofLine(x+width,y,x+width,y+height); //right
        ofLine(x+width,y+height,x,y+height); // bottom
        
        //drawLabels();
        
    };
    
    void drawLabels(){
        ofColor fg,bg;
        
        if(on){
            fg = foregroundHi;
            bg = backgroundHi;
        }else{
            fg = foregroundLo;
            bg = backgroundLo;
        }
        if(inactive){
            fg = fgInactive;
        }
        ofSetColor(fg);
        verdana16.drawString(labelNameX + " (L/R)", ofGetWidth()/2 - 120, y + height + 50 );
        verdana16.drawString(labelNameY + " (Up/Dn)", ofGetWidth()/2 - width + 50, y + height/2 );
        verdana16.drawString(labelNameZ + " Fwd/Bck)", ofGetWidth()/2 + width - 20, y+height);
        
        // TODO up down etc
    };
    void setLabels(string ax, string ay, string az){
        labelNameX = ax;
        labelNameY = ay;
        labelNameZ = az;
    }
    
    bool handleMyTouch(int x, int y, touchType ttype, int touchID){
        return false;
    };
    void showHint(bool show){
        hintShowing = show;
    }
    void setHintColor(ofColor c){
        hintColor = c;
    };

protected:
    virtual void drawIndicator(){
        ofSetColor(foregroundHi);
        float px,py;
        px = x + xVal*width + zx*zVal;
        py = y + (1-yVal)*height + zy*zVal;
        
        // line to left wall (no x)
        ofLine(px , py , x+zx*zVal, py);
        
        ofEllipse(px,py,thickness,thickness);
        

        // line to bottom wall (no y)
        ofLine(px , py , px, y+height+zy*zVal);
        // line to front wall ( no z)
        ofLine(px , py , x+ width*xVal, y + height*(1-yVal));

        if(hintShowing) drawHintIndicator();
    };
    virtual void drawHintIndicator(){
        ofSetColor(hintColor);
        float px,py;
        px = x + hintX*width + zx*hintZ;
        py = y + (1-hintY)*height + zy*hintZ;
        
        // line to left wall (no x)
        ofLine(px , py , x+zx*hintZ, py);
        
        ofEllipse(px,py,thickness,thickness);
        
        
        // line to bottom wall (no y)
        ofLine(px , py , px, y+height+zy*hintZ);
        // line to front wall ( no z)
        ofLine(px , py , x+ width*hintX, y + height*(1-hintY));
    
    };
    

    float xVal,yVal,zVal;
    
    ofVec3f posVals;
    float zx,zy; // how much of z and x shows up in diagonal x and y
    
    
    float minVal;
    float maxVal;
    
    
    float hintX;
    float hintY;
    float hintZ;
    bool hintShowing;
    
    string labelNameX;
    string labelNameY;
    string labelNameZ;
    
    float thickness; // width of border and indicator
    ofColor foregroundHi;
    ofColor backgroundHi;
    ofColor foregroundLo;
    ofColor backgroundLo;
    ofColor fgInactive;
    ofColor hintColor;
    
    
};
#endif /* defined(__tweakathlon___Dbox__) */