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


C++ ListWidget::getSelectionID方法代码示例

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


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

示例1: navigateDown

void EventHandler::navigateDown(const int playerID, Input::InputType type, const bool pressedDown)
{
    //std::cout << "Naviagte down!\n";

    IGUIElement *el = NULL, *closest = NULL;

    if (type == Input::IT_STICKBUTTON && !pressedDown)
        return;

    Widget* w = GUIEngine::getFocusForPlayer(playerID);
    if (w != NULL)
    {
        el = w->getIrrlichtElement();
    }
    //std::cout << "!!! Player " << playerID << " navigating down of " << w->m_element->getID() << std::endl;

    // list widgets are a bit special, because up/down keys are also used
    // to navigate between various list items, not only to navigate between
    // components
    if (w != NULL && w->m_type == WTYPE_LIST)
    {
        ListWidget* list = (ListWidget*)w;

        const bool stay_within_list = list->getSelectionID() < list->getItemCount()-1;

        if (stay_within_list)
        {
            list->setSelectionID(list->getSelectionID()+1);
            return;
        }
        else
        {
            list->setSelectionID(-1);
        }
    }

    if (w != NULL && w->m_tab_down_root != -1)
    {
        Widget* down = GUIEngine::getWidget( w->m_tab_down_root );
        assert(down != NULL);
        el = down->getIrrlichtElement();

        if (el == NULL)
        {
            std::cerr << "WARNING : m_tab_down_root is set to an ID for which I can't find the widget\n";
            return;
        }
    }

    // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog
    if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyIrrChild(el))
    {
        el = NULL;
    }

    bool found = false;

    if (el != NULL && el->getTabGroup() != NULL)
    {
        // if the current widget is e.g. 5, search for widget 6, 7, 8, 9, ..., 15 (up to 10 IDs may be missing)
        for (int n=1; n<10 && !found; n++)
        {
            closest = GUIEngine::getGUIEnv()->getRootGUIElement()->getElementFromId(el->getTabOrder() + n, true);

            if (closest != NULL && Widget::isFocusableId(closest->getID()))
            {

                Widget* closestWidget = GUIEngine::getWidget( closest->getID() );
                if (playerID != PLAYER_ID_GAME_MASTER && !closestWidget->m_supports_multiplayer) return;

                // if a dialog is shown, restrict to items in the dialog
                if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(closestWidget))
                {
                    continue;
                }

                if (NAVIGATION_DEBUG)
                {
                    std::cout << "Navigating down to " << closestWidget->getID() << "\n";
                }

                assert( closestWidget != NULL );
                closestWidget->setFocusForPlayer(playerID);

                // another list exception : when entering a list, select the first item
                if (closestWidget->m_type == WTYPE_LIST)
                {
                    IGUIListBox* list = (IGUIListBox*)(closestWidget->m_element);
                    assert(list != NULL);

                    list->setSelected(0);
                }

                found = true;
            }
        } // end for
    }

    if (!found)
    {
//.........这里部分代码省略.........
开发者ID:Berulacks,项目名称:stk-code,代码行数:101,代码来源:event_handler.cpp

示例2: navigate

/**
 * Focus the next widget either downwards or upwards.
 *
 * \param reverse True means navigating up, false means down.
 */
void EventHandler::navigate(const int playerID, Input::InputType type, const bool pressedDown, const bool reverse)
{
    IGUIElement *el = NULL, *closest = NULL;

    if (type == Input::IT_STICKBUTTON && !pressedDown)
        return;

    Widget* w = GUIEngine::getFocusForPlayer(playerID);
    if (w != NULL)
    {
        el = w->getIrrlichtElement();
    }

    // list widgets are a bit special, because up/down keys are also used
    // to navigate between various list items, not only to navigate between
    // components
    if (w != NULL && w->m_type == WTYPE_LIST)
    {
        ListWidget* list = (ListWidget*) w;

        const bool stay_within_list = reverse ? list->getSelectionID() > 0 :
            list->getSelectionID() < list->getItemCount() - 1;

        if (stay_within_list)
        {
            if (reverse)
                list->setSelectionID(list->getSelectionID() - 1);
            else
                list->setSelectionID(list->getSelectionID() + 1);
            return;
        }
        else
        {
            list->setSelectionID(-1);
        }
    }

    if (w != NULL && ((reverse && w->m_tab_up_root != -1) || (!reverse && w->m_tab_down_root != -1)))
    {
        Widget* next = GUIEngine::getWidget(reverse ? w->m_tab_up_root : w->m_tab_down_root);
        assert(next != NULL);
        el = next->getIrrlichtElement();

        if (el == NULL)
        {
            std::cerr << "WARNING : m_tab_down/up_root is set to an ID for which I can't find the widget\n";
            return;
        }
    }

    // don't allow navigating to any widget when a dialog is shown; only navigate to widgets in the dialog
    if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyIrrChild(el))
    {
        el = NULL;
    }

    bool found = false;

    // find closest widget
    if (el != NULL && el->getTabGroup() != NULL)
    {
        // Up: if the current widget is e.g. 15, search for widget 14, 13, 12, ... (up to 10 IDs may be missing)
        // Down: if the current widget is e.g. 5, search for widget 6, 7, 8, 9, ..., 15 (up to 10 IDs may be missing)
        for (int n = 1; n < 10 && !found; n++)
        {
            closest = GUIEngine::getGUIEnv()->getRootGUIElement()->getElementFromId(el->getTabOrder() + (reverse ? -n : n), true);

            if (closest != NULL && Widget::isFocusableId(closest->getID()))
            {
                Widget* closestWidget = GUIEngine::getWidget( closest->getID() );

                if (playerID != PLAYER_ID_GAME_MASTER && !closestWidget->m_supports_multiplayer) return;

                // if a dialog is shown, restrict to items in the dialog
                if (ModalDialog::isADialogActive() && !ModalDialog::getCurrent()->isMyChild(closestWidget))
                    continue;

                if (NAVIGATION_DEBUG)
                {
                    std::cout << "Navigating " << (reverse ? "up" : "down") << " to " << closest->getID() << std::endl;
                }

                assert(closestWidget != NULL);

                if (!closestWidget->isVisible() || !closestWidget->isActivated())
                    continue;

                closestWidget->setFocusForPlayer(playerID);

                // another list exception : when entering a list by going down, select the first item
                // when focusing a list by going up, select the last item of the list
                if (closestWidget->m_type == WTYPE_LIST)
                {
                    ListWidget* list = (ListWidget*) closestWidget;
                    assert(list != NULL);
//.........这里部分代码省略.........
开发者ID:krishnabm,项目名称:stk-code,代码行数:101,代码来源:event_handler.cpp


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