view UI code/sliderPanel.mm @ 26:8d7ae43b2edd

BLOODY FIIDDLY MOFO THIS ONE
author Robert Tubb <rt300@eecs.qmul.ac.uk>
date Tue, 28 Oct 2014 19:15:28 +0000
parents a223551fdc1f
children 27cdf475aa4b
line wrap: on
line source
//
//  sliderPanel.cpp
//  tweakathlon
//
//  Created by Robert Tubb on 11/02/2014.
//
//

#include "sliderPanel.h"

//-----------------------------------------------------------------------------
SliderPanel::SliderPanel(float ax,
                         float ay,
                         float awidth,
                         float aheight,
                         const UIProps& aprops,
                         vector<controllerType> elemList) :
UIElementContainer(ax,ay,awidth,aheight,aprops)
{
    cout << "SliderPanel auto layout contructor\n";

    // generateControls(elemList);// called from messageorganiser
}

// NOT GENERIC
//-----------------------------------------------------------------------------
vector<UIElement*> SliderPanel::generateControls(vector<controllerType> elemList, controlPanelType panelType){
    removeAllSubelements();
    vector<controllerType>::iterator i;
    
    // 10 cm is 520 pixels
    
    // calc positions
    int top  = y + myProps.spacerSize;
    
    float pixPerElem = width/(float)elemList.size();
    if (pixPerElem < myProps.sliderWidth ){
        cout << "error not enough room for sliders" << endl;
    }
    
    int n=0;
    for(i=elemList.begin(); i<elemList.end();i++){
        if(*i == SLIDER){
            // add a slider
            float c = (n + 0.5) * pixPerElem;
            float l = c - myProps.sliderWidth/2;
            if(n==1){
                cout << "centre " << c << endl;
                cout << l << endl;
            }
            
            ButtronSlider * revslider = new ButtronSlider(l , top , myProps.sliderWidth, myProps.sliderHeight,FILL, myProps);
            revslider->setLabel("unassigned");
            subElements.push_back(revslider);
            revslider->showHint(false);
            // grey out all but first
            if(panelType == SEQUENTIAL && i != elemList.begin()){
                revslider->setActive(false);
            }
            
            n++;
            
        }else if(*i == XYPAD){
            // add a xy
            float c = (n + 0.5) * pixPerElem;
            float left = c - myProps.XYsize/2;
            ButtronXY * xyp = new ButtronXY(left , top , myProps);
            xyp->setLabel("unassigned","unassigned");
            xyp->showHint(false);
            subElements.push_back(xyp);
            n++;
        }else if(*i == LEAP3D){
            // add a threed box
            float c = x+width*0.5;
            float left = c - myProps.XYsize;
            
            //Leap3DBox * l3d = new Leap3DBox(left , top+50 , myProps.XYsize*0.75,myProps.XYsize*0.75,150,50, myProps);

            Leap3DBoxGL * l3d = new Leap3DBoxGL(left , top+50 , myProps.XYsize*0.75,myProps.XYsize*0.75,150,50, myProps);
            

            
            subElements.push_back(l3d);
            n++;
        
        }else{
            cout << "ERROR: slider panel only handles xy pads and sliders" << endl;
        }
        

    }
    
    autoArrangeRow(); // will set positions
    


    return subElements;
}