当前位置: 首页>>代码示例>>C++>>正文


C++ MenuItem::GetType方法代码示例

本文整理汇总了C++中MenuItem::GetType方法的典型用法代码示例。如果您正苦于以下问题:C++ MenuItem::GetType方法的具体用法?C++ MenuItem::GetType怎么用?C++ MenuItem::GetType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在MenuItem的用法示例。


在下文中一共展示了MenuItem::GetType方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: ClickItem

/**
*  @brief
*    Click on a menu item
*/
void AbstractMenu::ClickItem(int nItem)
{
	// Get currently selected item
	MenuItem *pItem = m_pMenu->GetItems().Get(nItem);
	bool bCloseOnly = (m_pSelectedItem != nullptr && m_pSelectedItem == pItem);

	// Close currently open item
	if (m_pSelectedItem) {
		// Close submenu
		if (m_pSelectedItem->GetType() == TypeMenu) {
			CloseSubmenu();
		}

		// Close submenu
		m_pSelectedItem = nullptr;
	}

	// Check clicked item
	if (pItem) {
		// Open new submenu?
		if (pItem->GetType() == TypeMenu && !bCloseOnly) {
			// Set open item
			m_pSelectedItem = pItem;

			// Open submenu
			OpenSubmenu(m_pSelectedItem, nItem);
		} else if (pItem->GetType() == TypeMenuItem) {
			// Item clicked
			m_pController->OnItemClicked(pItem);
			m_pController->SetSelection(-1);
		}
	}

	// Reset selection?
	if (nItem == -1) {
		SetSelection(-1);
	}

	// Redraw menu
	Redraw();
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:45,代码来源:AbstractMenu.cpp

示例2: SetSelection

/**
*  @brief
*    Set currently selected menu item
*/
void AbstractMenu::SetSelection(int nItem)
{
	// Has the selection changed?
	int nNumOfItems = (m_pMenu ? m_pMenu->GetItems().GetNumOfElements() : 0);
	if (m_nSelection != nItem && nItem >= -1 && nItem < nNumOfItems) {
		// Get currently selected item
		MenuItem *pItem = m_pMenu->GetItems().Get(nItem);
		bool bOpenSubmenu = (m_pSelectedItem != nullptr);

		// Close currently open item
		if (m_pSelectedItem) {
			// Close submenu
			if (m_pSelectedItem->GetType() == TypeMenu) {
				CloseSubmenu();
			}

			// Close submenu
			m_pSelectedItem = nullptr;
		}

		// Set selection
		m_nSelection = nItem;

		// Emit signal
		SignalItemSelected(m_nSelection);

		// Check selected item
		if (pItem && bOpenSubmenu) {
			// Set new open submenu (or item)
			m_pSelectedItem = pItem;

			// Open new submenu?
			if (pItem->GetType() == TypeMenu) {
				// Open submenu
				OpenSubmenu(m_pSelectedItem, nItem);
			}
		}

		// Redraw menu
		Redraw();
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:46,代码来源:AbstractMenu.cpp

示例3: OnKeyDown

void AbstractMenu::OnKeyDown(uint32 nKey, uint32 nModifiers)
{
	// Check pointer
	if (m_pControlMenu) {
		// Previous item
		if ( m_pControlMenu->GetSelection() > -1 &&
			 ((m_pControlMenu->GetOrientation() == Horizontal && nKey == PLGUIKEY_LEFT) ||
			  (m_pControlMenu->GetOrientation() == Vertical   && nKey == PLGUIKEY_UP)) )
		{
			// Select previous item
			int nSelection = m_pControlMenu->GetSelection() - 1;
			if (nSelection < 0) nSelection = m_pControlMenu->m_nItems-1;

			// Ignore separators
			MenuItem *pItem = (m_pMenu ? m_pMenu->GetItems().Get(nSelection) : nullptr);
			if (pItem && pItem->GetType() == TypeSeparator) {
				nSelection--;
				if (nSelection < 0) nSelection = m_pControlMenu->m_nItems-1;
			}

			// Update selection
			m_pControlMenu->SetSelection(nSelection);
			m_pControlMenu->m_nIgnoreMouse = 5;
		}

		// Next item
		if ( m_pControlMenu->GetSelection() > -1 &&
			 ((m_pControlMenu->GetOrientation() == Horizontal && nKey == PLGUIKEY_RIGHT) ||
			  (m_pControlMenu->GetOrientation() == Vertical   && nKey == PLGUIKEY_DOWN)) )
		{
			// Select next item
			int nSelection = m_pControlMenu->GetSelection() + 1;
			if (nSelection >= m_pControlMenu->m_nItems) nSelection = 0;

			// Ignore separators
			MenuItem *pItem = (m_pMenu ? m_pMenu->GetItems().Get(nSelection) : nullptr);
			if (pItem && pItem->GetType() == TypeSeparator) {
				nSelection++;
				if (nSelection >= m_pControlMenu->m_nItems) nSelection = 0;
			}

			// Update selection
			m_pControlMenu->SetSelection(nSelection);
			m_pControlMenu->m_nIgnoreMouse = 5;
		}

		// Select current item
		if ((nKey == PLGUIKEY_SPACE || nKey == PLGUIKEY_RETURN) && m_pControlMenu->GetSelection() > -1) {
			m_pControlMenu->ClickItem(m_pControlMenu->GetSelection());
		}

		// Open next popup-menu
		if ( !m_pControlMenu->m_pSelectedItem &&
			 ((m_pControlMenu->GetOrientation() == Horizontal && nKey == PLGUIKEY_DOWN) ||
			  (m_pControlMenu->GetOrientation() == Vertical   && nKey == PLGUIKEY_RIGHT)) )
		{
			// Must be a sub-menu
			MenuItem *pItem = (m_pControlMenu->m_pMenu ? m_pControlMenu->m_pMenu->GetItems().Get(m_pControlMenu->GetSelection()) : nullptr);
			if (pItem && pItem->GetType() == TypeMenu) {
				m_pControlMenu->ClickItem(m_pControlMenu->GetSelection());
			}
		}

		// Close current popup-menu
		if (m_pControlMenu->GetOrientation() == Vertical && nKey == PLGUIKEY_LEFT && m_pControlMenu->m_pParentMenu) {
			m_pControlMenu = m_pControlMenu->m_pParentMenu;
			m_pControlMenu->ClickItem(m_pControlMenu->GetSelection());
		}

		// Keyboard shortcut
		if (nKey >= PLGUIKEY_A && nKey <= PLGUIKEY_Z) {
			// Get character
			char nChar = static_cast<char>('a' + (nKey - PLGUIKEY_A));
			m_pControlMenu->PressShortcut(nChar);
			m_pControlMenu->m_nIgnoreMouse = 5;
		}
	}

	// Close entire menu
	if (nKey == PLGUIKEY_ESCAPE) {
		if (m_pSelectedItem) ClickItem(GetSelection());
		else				 ClickItem(-1);
	}
}
开发者ID:ByeDream,项目名称:pixellight,代码行数:84,代码来源:AbstractMenu.cpp


注:本文中的MenuItem::GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。