From 2827533e70f4f481a2bafa0fa80afa7319358cf0 Mon Sep 17 00:00:00 2001 From: auria Date: Sun, 7 Mar 2010 00:54:07 +0000 Subject: [PATCH] Don't allow selecting ribbon grid filler items git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@4949 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/skin.cpp | 25 +++++++++++-------- .../widgets/dynamic_ribbon_widget.cpp | 5 +--- .../widgets/dynamic_ribbon_widget.hpp | 9 ++++--- src/guiengine/widgets/ribbon_widget.cpp | 12 +++++++++ src/states_screens/kart_selection.cpp | 2 +- src/states_screens/tracks_screen.cpp | 2 +- 6 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index bca14b495..3f1d8d803 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -690,15 +690,15 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const widget->m_event_handler->m_event_handler->m_properties[PROP_SQUARE] == "true") use_glow = false; /* in combo ribbons, always show selection */ - RibbonWidget* w = NULL; + RibbonWidget* parentRibbonWidget = NULL; if (widget->m_event_handler != NULL && widget->m_event_handler->m_type == WTYPE_RIBBON) { - w = dynamic_cast(widget->m_event_handler); - if(w->getRibbonType() == RIBBON_COMBO) always_show_selection = true; + parentRibbonWidget = dynamic_cast(widget->m_event_handler); + if(parentRibbonWidget->getRibbonType() == RIBBON_COMBO) always_show_selection = true; } - const bool mark_focused = focused || (parent_focused && w != NULL && w->m_mouse_focus == widget) || + const bool mark_focused = focused || (parent_focused && parentRibbonWidget != NULL && parentRibbonWidget->m_mouse_focus == widget) || (mark_selected && !always_show_selection && parent_focused); /* draw "selection bubble" if relevant */ @@ -762,18 +762,21 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const GUIEngine::getDriver()->draw2DImage(tex_ficonhighlight, rect2, source_area, 0 /* no clipping */, 0, true /* alpha */); } - /* if we're not using glow */ + // if we're not using glow, draw square focus instead else { - const bool show_focus = focused || parent_focused; + const bool show_focus = (focused || parent_focused); if (!always_show_selection && !show_focus) return; + // don't mark filler items as focused + if (widget->m_properties[PROP_ID] == DynamicRibbonWidget::NO_ITEM_ID) return; + //const int texture_w = m_tex_squarefocus->getSize().Width; //const int texture_h = m_tex_squarefocus->getSize().Height; //core::rect source_area = core::rect(0, 0, texture_w, texture_h); - drawBoxFromStretchableTexture(w, rect, SkinConfig::m_render_params["squareFocusHalo::neutral"]); + drawBoxFromStretchableTexture(parentRibbonWidget, rect, SkinConfig::m_render_params["squareFocusHalo::neutral"]); nPlayersOnThisItem++; } } // end if mark_focused @@ -796,11 +799,11 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const rect2.UpperLeftCorner.Y -= enlarge; rect2.LowerRightCorner.X += enlarge; rect2.LowerRightCorner.Y += enlarge; - drawBoxFromStretchableTexture(w, rect2, SkinConfig::m_render_params["squareFocusHalo2::neutral"]); + drawBoxFromStretchableTexture(parentRibbonWidget, rect2, SkinConfig::m_render_params["squareFocusHalo2::neutral"]); } else { - drawBoxFromStretchableTexture(w, rect, SkinConfig::m_render_params["squareFocusHalo2::neutral"]); + drawBoxFromStretchableTexture(parentRibbonWidget, rect, SkinConfig::m_render_params["squareFocusHalo2::neutral"]); } nPlayersOnThisItem++; @@ -808,13 +811,13 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const if (parentRibbon->isFocusedForPlayer(2) && parentRibbon->getSelectionIDString(2) == widget->m_properties[PROP_ID]) { - drawBoxFromStretchableTexture(w, rect, SkinConfig::m_render_params["squareFocusHalo3::neutral"]); + drawBoxFromStretchableTexture(parentRibbonWidget, rect, SkinConfig::m_render_params["squareFocusHalo3::neutral"]); nPlayersOnThisItem++; } if (parentRibbon->isFocusedForPlayer(3) && parentRibbon->getSelectionIDString(3) == widget->m_properties[PROP_ID]) { - drawBoxFromStretchableTexture(w, rect, SkinConfig::m_render_params["squareFocusHalo4::neutral"]); + drawBoxFromStretchableTexture(parentRibbonWidget, rect, SkinConfig::m_render_params["squareFocusHalo4::neutral"]); } drawIconButton(rect, widget, pressed, focused); diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.cpp b/src/guiengine/widgets/dynamic_ribbon_widget.cpp index 6cdffa52c..873a2adf6 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.cpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.cpp @@ -29,10 +29,7 @@ using namespace irr::gui; # define round(x) (floor(x+0.5f)) #endif -namespace GUIEngine -{ - const char* NO_ITEM_ID = "?"; -} +const char* DynamicRibbonWidget::NO_ITEM_ID = "?"; DynamicRibbonWidget::DynamicRibbonWidget(const bool combo, const bool multi_row) { diff --git a/src/guiengine/widgets/dynamic_ribbon_widget.hpp b/src/guiengine/widgets/dynamic_ribbon_widget.hpp index b45efc7f6..3590c278e 100644 --- a/src/guiengine/widgets/dynamic_ribbon_widget.hpp +++ b/src/guiengine/widgets/dynamic_ribbon_widget.hpp @@ -28,9 +28,6 @@ namespace GUIEngine { - /** The identifier returned for empty "cells" in the ribbon */ - extern const char* NO_ITEM_ID; - /** * Even if you have a ribbon that only acts on click/enter, you may wish to know which * item is currently highlighted. In this case, create a listener and pass it to the ribbon. @@ -154,6 +151,12 @@ namespace GUIEngine public: + + /** Internal identifier of filler items that aer added in a grid ribbon widget to fill + * lines when the number of items cannot be divided by the number of rows in the grid + */ + static const char* NO_ITEM_ID; + /** * \param combo Whether this is a "combo" ribbon, i.e. whether there is always one selected item. * If set to false, will behave more like a toolbar. diff --git a/src/guiengine/widgets/ribbon_widget.cpp b/src/guiengine/widgets/ribbon_widget.cpp index 26e5677d9..463591813 100644 --- a/src/guiengine/widgets/ribbon_widget.cpp +++ b/src/guiengine/widgets/ribbon_widget.cpp @@ -284,6 +284,12 @@ EventPropagation RibbonWidget::rightPressed(const int playerID) } } + // if we reached a filler item, move again + if (getSelectionIDString(playerID) == DynamicRibbonWidget::NO_ITEM_ID) + { + rightPressed(playerID); + } + if (m_ribbon_type != RIBBON_TOOLBAR) { //GUIEngine::transmitEvent( this, m_properties[PROP_ID], playerID ); @@ -319,6 +325,12 @@ EventPropagation RibbonWidget::leftPressed(const int playerID) } } + // if we reached a filler item, move again + if (getSelectionIDString(playerID) == DynamicRibbonWidget::NO_ITEM_ID) + { + leftPressed(playerID); + } + if (m_ribbon_type != RIBBON_TOOLBAR) { //GUIEngine::transmitEvent( this, m_properties[PROP_ID], playerID ); diff --git a/src/states_screens/kart_selection.cpp b/src/states_screens/kart_selection.cpp index 7e2a85dfe..3e475e829 100644 --- a/src/states_screens/kart_selection.cpp +++ b/src/states_screens/kart_selection.cpp @@ -1366,7 +1366,7 @@ void KartSelectionScreen::setKartsFromCurrentGroup() unlock_manager->playLockSound(); } //FIXME: what does this do there??? - else if (selected_kart_group == NO_ITEM_ID) + else if (selected_kart_group == DynamicRibbonWidget::NO_ITEM_ID) { } else diff --git a/src/states_screens/tracks_screen.cpp b/src/states_screens/tracks_screen.cpp index f926121fa..7eae6e43a 100644 --- a/src/states_screens/tracks_screen.cpp +++ b/src/states_screens/tracks_screen.cpp @@ -103,7 +103,7 @@ void TracksScreen::eventCallback(Widget* widget, const std::string& name, const { unlock_manager->playLockSound(); } - else if (selection == NO_ITEM_ID) + else if (selection == DynamicRibbonWidget::NO_ITEM_ID) { } else