Ejemplo n.º 1
0
/**
 * Move the cursor to the previous option, wrapping around if on first.
 * <p>
 * If decrementing the cursor causes the cursor to fall outside of the visible window of options, also decrement the
 * visible window of options.
 */
void MenuView::decrementCursor() {
    long newCursorIndex = getCursorIndex() - 1;
    if (newCursorIndex < 0) {
        newCursorIndex = buttons.size() - 1;
    }

    setCursorIndex(static_cast<uint16_t>(newCursorIndex));

    if (isCursorOutsideWindow()) {
        decrementWindowTopIndex();
    }

    sizeButtons();
}
Ejemplo n.º 2
0
void MenuView::addOption(std::string optionText, const std::function<void(SDL_Event)> &callBack) {
    SDL_Rect rect = {0, 0, 0, 0};
    auto button = new ButtonView(nullptr, rect);
    button->setText(optionText);
    button->setFontPath(FONT_CELTIC_HAND);
    button->setFontSize(0);
    button->setOnMouseUpCallback(callBack);
    button->setColor(getOptionBackgroundColor());
    button->setTextColor(getOptionTextColor());
    button->setFontSize(getOptionFontSize());
    buttons.push_back(button);

    sizeButtons();
    setCursorIndex(getCursorIndex());

}
Ejemplo n.º 3
0
BOOL CToolBarDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here

//	We create our toolbar (this is in a standard dialog box)
//	with the CToolBarCtrl.Create() function. This function takes 
//	a RECT structure as a parameter, but the RECT structure is ignored
//	and not used.

	int ButtonBitmap = 0;
	int ButtonString = 0;
	int ButtonCount = 0;

	RECT	rect;
	rect.top = 0;
	rect.left = 0;
	rect.bottom = 60;
	rect.right = 100;
	
	m_ToolBarCtrl.Create(
		WS_CHILD | WS_VISIBLE | CCS_TOP | TBSTYLE_TOOLTIPS | CCS_ADJUSTABLE, 
		rect, this, 0);

	ButtonBitmap = m_ToolBarCtrl.AddBitmap(20, IDB_TOOLBAR);
	ButtonString = m_ToolBarCtrl.AddString(IDS_FIRST_BUTTON);

	m_Buttons[ButtonCount].iBitmap = NULL;
	m_Buttons[ButtonCount].idCommand = 0;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_SEP;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;
	
	++ButtonCount;

//	Move everything over to leave room for the combobox
//	which will be on the far left of the toolbar.
//	The combobox could be anywhere, but putting it on the 
//	left is easier for the programmer. Most applications with 
//	stock implementations of CToolBarCtrl do it this way.

	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;
	m_Buttons[ButtonCount] = m_Buttons[ButtonCount - 1]; 
	++ButtonCount;

	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 0;
	m_Buttons[ButtonCount].idCommand = IDOK;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_BUTTON;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = ButtonString;

	++ButtonCount;
	
	m_Buttons[ButtonCount].iBitmap = NULL;
	m_Buttons[ButtonCount].idCommand = 0;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_SEP;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;
	
	++ButtonCount;

	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 1;
	m_Buttons[ButtonCount].idCommand = IDCANCEL;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_BUTTON;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;

	++ButtonCount;

	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 2;
	m_Buttons[ButtonCount].idCommand = IDC_CHECK1;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_CHECK;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;

	++ButtonCount;
	
	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 3;
	m_Buttons[ButtonCount].idCommand = IDC_OTHER_BUTTON;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_BUTTON;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;

	++ButtonCount;
	
	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 4;
	m_Buttons[ButtonCount].idCommand = 0;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_SEP;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = NULL;
	
	++ButtonCount;

	m_Buttons[ButtonCount].iBitmap = ButtonBitmap + 5;
	m_Buttons[ButtonCount].idCommand = IDC_LAST_BUTTON;
	m_Buttons[ButtonCount].fsState = TBSTATE_ENABLED;
	m_Buttons[ButtonCount].fsStyle = TBSTYLE_BUTTON;
	m_Buttons[ButtonCount].dwData = 0;
	m_Buttons[ButtonCount].iString = ButtonString;

	++ButtonCount;

//	Once the m_Buttons[] array is filled in, then we add
//	the buttons to the toolbar.

	m_ToolBarCtrl.AddButtons(ButtonCount, m_Buttons);

//	Since our bitmaps are non-standard in size, we resize
//	the toolbar's buttons to fit the bitmaps:

	CSize sizeButtons(55, 65);

	m_ToolBarCtrl.SetButtonSize(sizeButtons);

//	Since our bitmaps are non-standard in size, we tell
//	the toolbar the real size of our images:

	CSize sizeBitmap(48, 45);

	m_ToolBarCtrl.SetBitmapSize(sizeBitmap);

//	Finally, we resize the toolbar for our non-standard
//	button sizes:

	m_ToolBarCtrl.AutoSize();

//	Finally, add our ComboBox to the toolbar. We add it to the 
//	left edge to make things easy. The buttons are spaced over
//      using a bunch of TBSTYLE_SEP buttons.
// 
//	The ComboBox will be created with a standard string height for the 
//	visible portion. The rect.bottom specifies the dropdown part.
//	We set the height of the top part later...

	rect.top = 2; rect.left = 5; rect.bottom = 200; rect.right = 100;

	if (m_ComboBox.Create( WS_CHILD | WS_BORDER | WS_VISIBLE |
		CBS_HASSTRINGS | CBS_DROPDOWN, rect, (CWnd *)&m_ToolBarCtrl, 124) == 0)
	{// Real applications would have to perhaps recover from this error:
                TRACE("Could not create combobox\n");
	}
	else
	{
//		Set the ComboBox's edit area's height to the height of 
//		the button's bitmap size!

		m_ComboBox.SetItemHeight(-1, 45);

//		Add (some dummy) strings to the ComboBox: 

		m_ComboBox.AddString("asdf");
		m_ComboBox.AddString("qwer");
		m_ComboBox.AddString("zxcv");

//		Set the current selection to the (zero based) second item

		m_ComboBox.SetCurSel(1);
	}

	rect.top = 2; rect.left = 5; rect.bottom = 45; rect.right = 100;
	CToolTipCtrl * tt;
	tt = m_ToolBarCtrl.GetToolTips();

	if (tt->AddTool(&m_ComboBox, IDC_COMBO_BOX) == 0)
	{
		TRACE("AddTool() failed!!!!!\n");
	}


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
Ejemplo n.º 4
0
/**
 * Sets the count of visible options.
 * <p>
 * If 0, it will attempt to display all options on the menu. Options not displayed may still be accessed.
 * <p>
 * This triggers the options to be re-sized to fit inside the area of the menu.
 * @param count
 */
void MenuView::setVisibleOptionCount(uint16_t count) {
    visibleOptionCount = count;
    sizeButtons();
}