From d3dddc901bff69a680e6829d06aad90355fe5fdb Mon Sep 17 00:00:00 2001 From: auria Date: Fri, 28 Aug 2009 15:36:26 +0000 Subject: [PATCH] Temporarly show focus on spinners for players > 0 git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3937 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/guiengine/event_handler.cpp | 4 ++ src/guiengine/skin.cpp | 92 ++++++++++++++++++++++++--------- src/guiengine/skin.hpp | 5 ++ src/guiengine/widget.cpp | 4 +- 4 files changed, 78 insertions(+), 27 deletions(-) diff --git a/src/guiengine/event_handler.cpp b/src/guiengine/event_handler.cpp index a405caa54..af45ab635 100644 --- a/src/guiengine/event_handler.cpp +++ b/src/guiengine/event_handler.cpp @@ -201,6 +201,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp { Widget* w = NULL; + // TODO : unify player 0 and players > 0 focus navigation to eliminate this kind of branching if (playerID == 0) { IGUIElement *el = GUIEngine::getGUIEnv()->getFocus(); @@ -237,6 +238,7 @@ void EventHandler::processAction(const int action, const unsigned int value, Inp { Widget* w = NULL; + // TODO : unify player 0 and players > 0 focus navigation to eliminate this kind of branching if (playerID == 0) { IGUIElement *el = GUIEngine::getGUIEnv()->getFocus(); @@ -313,6 +315,7 @@ void EventHandler::navigateUp(const int playerID, Input::InputType type, const b { IGUIElement *el, *first=NULL, *closest=NULL; + // TODO : unify player 0 and players > 0 focus navigation to eliminate this kind of branching if (playerID == 0) el = GUIEngine::getGUIEnv()->getFocus(); else @@ -393,6 +396,7 @@ void EventHandler::navigateDown(const int playerID, Input::InputType type, const { IGUIElement *el, *first = NULL, *closest = NULL; + // TODO : unify player 0 and players > 0 focus navigation to eliminate this kind of branching if (playerID == 0) el = GUIEngine::getGUIEnv()->getFocus(); else diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index bc31fa8c6..721d77255 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -502,54 +502,71 @@ X##_yflip.LowerRightCorner.Y = w->dest_y + (w->dest_y2 - w->dest_y) - y1;} core::rect& GET_AREA(dest_area_bottom_right); #undef GET_AREA - if((areas & BoxRenderParams::LEFT) != 0) + SColor* colorptr = NULL; + + if (w->r != -1 && w->g != -1 && w->b != -1) + { + SColor thecolor(255, w->r, w->g, w->b); + colorptr = new SColor[4](); + colorptr[0] = thecolor; + colorptr[1] = thecolor; + colorptr[2] = thecolor; + colorptr[3] = thecolor; + } + + if ((areas & BoxRenderParams::LEFT) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_left, source_area_left, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if((areas & BoxRenderParams::BODY) != 0) + if ((areas & BoxRenderParams::BODY) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_center, source_area_center, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if((areas & BoxRenderParams::RIGHT) != 0) + if ((areas & BoxRenderParams::RIGHT) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_right, source_area_right, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if((areas & BoxRenderParams::TOP) != 0) + if ((areas & BoxRenderParams::TOP) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top, source_area_top, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if((areas & BoxRenderParams::BOTTOM) != 0) + if ((areas & BoxRenderParams::BOTTOM) != 0) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom, source_area_bottom, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) + if ( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top_left, source_area_top_left, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) + if ( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::TOP) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_top_right, source_area_top_right, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) + if ( ((areas & BoxRenderParams::LEFT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom_left, source_area_bottom_left, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); } - if( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) + if ( ((areas & BoxRenderParams::RIGHT) != 0) && ((areas & BoxRenderParams::BOTTOM) != 0) ) { GUIEngine::getDriver()->draw2DImage(source, dest_area_bottom_right, source_area_bottom_right, - 0 /* no clipping */, 0, true /* alpha */); + 0 /* no clipping */, colorptr, true /* alpha */); + } + + if (colorptr != NULL) + { + delete[] colorptr; } } @@ -749,15 +766,15 @@ void Skin::drawRibbonChild(const core::rect< s32 > &rect, Widget* widget, const void Skin::drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget, const bool pressed, bool focused) { - if(!focused) + if (!focused) { IGUIElement* focused_widget = GUIEngine::getGUIEnv()->getFocus(); - if(focused_widget != NULL && widget->m_children.size()>2) + if (focused_widget != NULL && widget->m_children.size()>2) { - if(widget->m_children[0].id == focused_widget->getID() || - widget->m_children[1].id == focused_widget->getID() || - widget->m_children[2].id == focused_widget->getID()) + if (widget->m_children[0].id == focused_widget->getID() || + widget->m_children[1].id == focused_widget->getID() || + widget->m_children[2].id == focused_widget->getID()) { focused = true; } @@ -767,10 +784,37 @@ void Skin::drawSpinnerBody(const core::rect< s32 > &rect, Widget* widget, const BoxRenderParams& params = (focused || pressed) ? SkinConfig::m_render_params["spinner::focused"] : SkinConfig::m_render_params["spinner::neutral"]; + + // FIXME: temporary only + if (widget->isFocusedForPlayer(1)) + { + widget->r = 0; + widget->g = 200; + widget->b = 255; + } + else if (widget->isFocusedForPlayer(2)) + { + widget->r = 120; + widget->g = 0; + widget->b = 120; + } + else if (widget->isFocusedForPlayer(3)) + { + widget->r = 255; + widget->g = 0; + widget->b = 0; + } + else + { + widget->r = -1; + widget->g = -1; + widget->b = -1; + } + drawBoxFromStretchableTexture(widget, rect, params); const SpinnerWidget* w = dynamic_cast(widget); - if( w->isGauge() ) + if (w->isGauge()) { const int handle_size = (int)( widget->h*params.left_border/(float)params.getImage()->getSize().Height ); const float value = (float)(w->getValue() - w->getMin()) / (w->getMax() - w->getMin()); diff --git a/src/guiengine/skin.hpp b/src/guiengine/skin.hpp index 3817dfac6..46f861246 100644 --- a/src/guiengine/skin.hpp +++ b/src/guiengine/skin.hpp @@ -141,6 +141,8 @@ namespace GUIEngine core::rect dest_area_bottom_left_yflip; core::rect dest_area_bottom_right_yflip; + short r, g, b; + SkinWidgetContainer() { dest_areas_inited = false; @@ -149,6 +151,9 @@ namespace GUIEngine y = -1; w = -1; h = -1; + r = -1; + g = -1; + b = -1; } }; diff --git a/src/guiengine/widget.cpp b/src/guiengine/widget.cpp index 70dfb8ed6..9ccb5e59c 100644 --- a/src/guiengine/widget.cpp +++ b/src/guiengine/widget.cpp @@ -101,9 +101,7 @@ Widget::Widget(bool reserve_id) * for additionnal players */ void Widget::setFocusForPlayer(const int playerID) -{ - std::cout << "=========== setFocusForPlayer " << playerID << " : " << m_properties[PROP_ID].c_str() << " =============\n"; - +{ // Unset focus flag on previous widget that had focus if (GUIEngine::g_focus_for_player[playerID] != NULL) {