1 // SuperTuxKart - a fun racing game with go-kart
2 //
3 // Copyright (C) 2006-2015 SuperTuxKart-Team
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 3
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 #include "guiengine/widgets/player_name_spinner.hpp"
20 #include "guiengine/engine.hpp"
21 #include "graphics/irr_driver.hpp"
22 #include "io/file_manager.hpp"
23 #include <IGUIEnvironment.h>
24
25 using namespace GUIEngine;
26
PlayerNameSpinner(KartSelectionScreen * parent,const int player_id)27 PlayerNameSpinner::PlayerNameSpinner(KartSelectionScreen* parent,
28 const int player_id)
29 {
30 m_player_id = player_id;
31 m_incorrect = false;
32 m_red_mark_widget = NULL;
33 m_parent = parent;
34 setUseBackgroundColor();//except for multiplayer kart selection, this is false
35 setSpinnerWidgetPlayerID(m_player_id);
36 } // PlayerNameSpinner
37 // ------------------------------------------------------------------------
setID(const int m_player_id)38 void PlayerNameSpinner::setID(const int m_player_id)
39 {
40 PlayerNameSpinner::m_player_id = m_player_id;
41 setSpinnerWidgetPlayerID(m_player_id);
42 } // setID
43 // ------------------------------------------------------------------------
44 /** Add a red mark on the spinner to mean "invalid choice" */
markAsIncorrect()45 void PlayerNameSpinner::markAsIncorrect()
46 {
47 if (m_incorrect) return; // already flagged as incorrect
48
49 m_incorrect = true;
50
51 irr::video::ITexture* texture = irr_driver->getTexture(FileManager::GUI_ICON,
52 "red_mark.png" );
53 const int mark_size = m_h;
54 const int mark_x = m_w - mark_size*2;
55 const int mark_y = 0;
56 core::recti red_mark_area(mark_x, mark_y, mark_x + mark_size,
57 mark_y + mark_size);
58 m_red_mark_widget = GUIEngine::getGUIEnv()->addImage( red_mark_area,
59 /* parent */ m_element );
60 m_red_mark_widget->setImage(texture);
61 m_red_mark_widget->setScaleImage(true);
62 m_red_mark_widget->setTabStop(false);
63 m_red_mark_widget->setUseAlphaChannel(true);
64 } // markAsIncorrect
65
66 // ------------------------------------------------------------------------
67 /** Remove any red mark set with 'markAsIncorrect' */
markAsCorrect()68 void PlayerNameSpinner::markAsCorrect()
69 {
70 if (m_incorrect)
71 {
72 m_red_mark_widget->remove();
73 m_red_mark_widget = NULL;
74 m_incorrect = false;
75 }
76 } // markAsCorrect
77
78