COCKOS
CONFEDERATED FORUMS
Cockos : REAPER : NINJAM : Forums
Forum Home : Register : FAQ : Members List : Search :
Old 06-20-2016, 05:35 AM   #1
Jansku
Human being with feelings
 
Join Date: May 2013
Location: Oulu
Posts: 36
Default IPopUpMenu with multiple columns?

Hi gurus,

I have a ICaptionControl for patch selection in plugin UI from values 0-100. I have two questions:

1. How can this menu be columnized to lets say 4*25 items?
It's quite annoying to scroll to the bottom of the list if you want to check items from there.

In cakewalk z3ta you can see this kind of menu in action when choosing different presets from the menu and I would like to implement this functionality to my works as well

Thanks for your help!
Jansku is offline   Reply With Quote
Old 06-20-2016, 09:59 AM   #2
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

You need to create IPopupMenu menus for each submenue and add it to the corresponding parent menue. Take a look at IPopupMenu.cpp. There're several overloaded functions for adding menu items. Guess you'd want to use
Code:
IPopupMenuItem* IPopupMenu::AddItem(const char* text, int index, IPopupMenu* submenu)
or
Code:
IPopupMenuItem* IPopupMenu::AddItem(const char* text, IPopupMenu* submenu)
You can treat these submenues the same way as your main menue.
IIRC you have to track the selected menue and item to implement proper item checks since they're all indepedent and each menue could hold checked items even though you set "CheckItemAlone".
stw is offline   Reply With Quote
Old 06-20-2016, 02:15 PM   #3
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

He's not talking about a hierarchical menu, but a pop-up selector with a matrix of choices.

I haven't written such a control. It could be done with text, but simpler (and less potential font-difference issues cross-platform) to use a graphic with the choices, and a highlight method during tracking (a colored rectangular outline, for instance).

I've done similar selectors, where a button control pops up another control that handles the mouse-drag to select from a vertical or horizontal graphical list (could be image or rendered text—for example, I have a "note" button that pops up horizontal list of notes (whole, half, quarter, eight...), and a horizontal drag highlights the note that the mouse is over, selecting it on release. It can be super easy for a one-dimensional (horizontal or vertical) list, because you can pre-render the highlights for each note. (If there are six choices, for instance, you can image the entire list six times, with each image having the next choice highlighted. Then it's just a trivial override of IKnobMultiControl.)

It would be a little more complicated with a matrix, but not much. Obviously, if your item names change, you couldn't use a pre-rendered graphic and the drawing part becomes more complicated, but the tracking and highlighting is pretty simple.
earlevel is offline   Reply With Quote
Old 06-20-2016, 02:39 PM   #4
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Quote:
Originally Posted by earlevel View Post
He's not talking about a hierarchical menu, but a pop-up selector with a matrix of choices.
oops...should have read more carefully

EDIT: However for my current project i've done this:
Quote:
Originally Posted by earlevel View Post
It could be done with text, but simpler (and less potential font-difference issues cross-platform) to use a graphic with the choices, and a highlight method during tracking (a colored rectangular outline, for instance).
So if one is interested...

Last edited by stw; 06-20-2016 at 02:48 PM.
stw is offline   Reply With Quote
Old 06-20-2016, 03:03 PM   #5
earlevel
Human being with feelings
 
Join Date: Dec 2015
Posts: 331
Default

Quote:
Originally Posted by stw View Post
So if one is interested...
I can give more code details, or even submit the addition as a pull request...but not right now, sorry, severe time deficit...
earlevel is offline   Reply With Quote
Old 06-20-2016, 11:53 PM   #6
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

Quote:
Originally Posted by earlevel View Post
I can give more code details, or even submit the addition as a pull request...but not right now, sorry, severe time deficit...
I don't need it, i have it working (at least the bitmap version)...
stw is offline   Reply With Quote
Old 06-21-2016, 12:54 AM   #7
Jansku
Human being with feelings
 
Join Date: May 2013
Location: Oulu
Posts: 36
Default

Yeah I meant matrix / columns of names which can be chosen

Any advice would be great to get out from that old-school dropdown with scrolling.

Image as attachment.
Attached Images
File Type: jpg patchlist-popup2.jpg (49.2 KB, 208 views)
Jansku is offline   Reply With Quote
Old 06-21-2016, 12:57 AM   #8
Jansku
Human being with feelings
 
Join Date: May 2013
Location: Oulu
Posts: 36
Default

Quote:
Originally Posted by earlevel View Post
Obviously, if your item names change, you couldn't use a pre-rendered graphic and the drawing part becomes more complicated, but the tracking and highlighting is pretty simple.
The items would be static with Program 1, Program 2 etc.
Jansku is offline   Reply With Quote
Old 06-22-2016, 01:12 PM   #9
stw
Human being with feelings
 
stw's Avatar
 
Join Date: Apr 2012
Posts: 279
Default

This is my IControl which has a bitmap as matrix source and returns the number of the selected cell. You'd need to init the param with the corresponding amount of items.
Code:
.h

class IGridOverlayControl : public ISwitchControl

// Based on IBitmapOverlayControl
// Returns the selected cell nr.
// Cell order from left->right and top->bottom

{
public:
    IGridOverlayControl(IPlugBase* pPlug, int x, int y, int paramIdx, IBitmap* pBitmap, IRECT pTargetArea, int cols = 1, int rows = 1)
    : ISwitchControl(pPlug, x, y, paramIdx, pBitmap), mTargetArea(pTargetArea), mCols(cols), mRows(rows), close(false)
    {
        width = mRECT.R - mRECT.L;
        hight = mRECT.B - mRECT.T;
        mCellHight = hight / mRows;
        mCellWidth = width / mCols;
        mCells = mRows * mCols;
    }
    
    ~IGridOverlayControl() {}
    
    bool close;
    void OnMouseOver(int x, int y, IMouseMod* pMod);
    void OnMouseDown(int x, int y, IMouseMod* pMod);
    void OnMouseUp(int x, int y, IMouseMod* pMod);
    bool Draw(IGraphics* pGraphics);
    
private:
    
    int mCol, mCols, mRow, mRows, mCells, width, hight;
    int mCellWidth, mCellHight;
    const int margin = 4;
    IRECT lastRect;
    
protected:
    IRECT mTargetArea;  // Keep this around to swap in & out.
};
Code:
.cpp


void IGridOverlayControl::OnMouseOver(int x, int y, IMouseMod* pMod){
    
    mCol = mCols * (x - mRECT.L) / width;
    mRow = mRows * (y - mRECT.T) / hight;
    Redraw();
}

void IGridOverlayControl::OnMouseDown(int x, int y, IMouseMod* pMod){
    
    int cell = mValue * mCells;
    int row =  cell / mCols;
    int col = cell - row * mCols;
    x = mCellWidth * col + mRECT.L + margin;
    y = mCellHight * row + mRECT.T + margin;
    lastRect = IRECT(x, y, x + mCellWidth - 2 * margin, y + mCellHight - 2 * margin);
    Redraw();
}

void IGridOverlayControl::OnMouseUp(int x, int y, IMouseMod* pMod){
    
    if(close){     // change val only on bitmap close
        mValue = (double) (mCol + mCols * mRow) / mCells;
        SetDirty();
    }
    else Redraw();
    close = !close;
}

bool IGridOverlayControl::Draw(IGraphics* pGraphics)
{
    if (!close)
    {
        mTargetRECT = mTargetArea;
        return true;  // Don't draw anything.
    }
    else
    {
        int x = mCol * mCellWidth + mRECT.L + margin;
        int y = mRow * mCellHight + mRECT.T + margin;
        IRECT rect = IRECT(x, y, x + mCellWidth - 2 * margin, y + mCellHight - 2 * margin);
        
        mTargetRECT = mRECT;
        IBitmapControl::Draw(pGraphics);
        
        pGraphics->RoundRect(&COLOR_GRAY, &lastRect, 0, 3, true);      // Draw Rect at last selected cell
        pGraphics->RoundRect(&COLOR_WHITE, &rect, 0, 3, true);         // Draw Rect at hovered cell
        return true;
    }
    return true;
}
stw is offline   Reply With Quote
Old 07-06-2016, 03:40 PM   #10
Jansku
Human being with feelings
 
Join Date: May 2013
Location: Oulu
Posts: 36
Default

Ok I will give this a shot later on to see how I can get it up and running!
Will post my questions / findings later on.
Jansku is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 09:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.