view Controls.h @ 1:2ca5d7440b5c tip

added README
author Fiore Martin <f.martin@qmul.ac.uk>
date Fri, 26 Feb 2016 16:11:20 +0000
parents 3004dd663202
children
line wrap: on
line source
//
//  Controls.h
//  AccessibleSpectrumAnalyser
//
//  Created by Fiore Martin on 18/01/2016.
//
//

#ifndef Controls_h
#define Controls_h


/* Knob with a text label and a text displaying the current value */
class IKnobMultiControlText : public IKnobControl
{
private:
    IRECT mDisplayRECT, mImgRECT, mNameRECT, mLabelRECT;
    IBitmap mBitmap;
    
public:
    IKnobMultiControlText(IPlugBase* pPlug, IRECT pR, int paramIdx, IBitmap* pBitmap, IText* pText, int indent = 10)
    : IKnobControl(pPlug, pR, paramIdx), mBitmap(*pBitmap)
    {
        mText = *pText;
        /* mRECT is the bounding rectangle of the whole KnobMultiControlText */
        mNameRECT = IRECT(mRECT.L, mRECT.T,mRECT.R, mRECT.T+16);
        mDisplayRECT = IRECT(mRECT.L, mRECT.B-25, mRECT.R-21, mRECT.B); // left, top, right, bottom
        mLabelRECT = mDisplayRECT;
        mLabelRECT.L = mDisplayRECT.R; // shift it to the right of the diplay RECT
        mLabelRECT.R = mLabelRECT.L+indent; // how much the display is indented
        mImgRECT = IRECT(mRECT.L, mRECT.T+16, &mBitmap);
        mDisablePrompt = false;
    }
    
    ~IKnobMultiControlText() {}
    
    bool Draw(IGraphics* pGraphics)
    {
        int i = 1 + int(0.5 + mValue * (double) (mBitmap.N - 1));
        i = BOUNDED(i, 1, mBitmap.N);
        
        /* draw the knob */
        pGraphics->DrawBitmap(&mBitmap, &mImgRECT, i, &mBlend);
        
        /* draw displayed value for host, that is the value as represented in the host */
        char displayedValue[20];
        mPlug->GetParam(mParamIdx)->GetDisplayForHost(displayedValue);
        
        bool dispDrawn = true;
        if (CSTR_NOT_EMPTY(displayedValue)) {
            dispDrawn = pGraphics->DrawIText(&mText, displayedValue, &mDisplayRECT);
        }
        
        /* name of the parameter */
        if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetNameForHost())){
            char nameDisp[MAX_PARAM_NAME_LEN];
            strcpy(nameDisp, mPlug->GetParam(mParamIdx)->GetNameForHost());
            
            if (CSTR_NOT_EMPTY(mPlug->GetParam(mParamIdx)->GetLabelForHost())){
                char label[MAX_PARAM_LABEL_LEN];
                strcpy(label, mPlug->GetParam(mParamIdx)->GetLabelForHost());
                pGraphics->DrawIText(&mText, label, &mLabelRECT);
            }
            
            return dispDrawn && pGraphics->DrawIText(&mText, nameDisp, &mNameRECT);
        }
        
        return dispDrawn;
    }
    
    void OnMouseDown(int x, int y, IMouseMod* pMod)
    {
        OnMouseDrag(x, y, 0, 0, pMod);	  
    }
    
    /* double click puts it back to default value */
    void OnMouseDblClick(int x, int y, IMouseMod* pMod)
    {
        if (mDefaultValue >= 0.0)
        {
            mValue = mDefaultValue;
            SetDirty();
        }
    }
    
};


#endif /* Controls_h */