SuperTuxKart
Loading...
Searching...
No Matches
icon_button_widget.hpp
1// SuperTuxKart - a fun racing game with go-kart
2// Copyright (C) 2009-2015 Marianne Gagnon
3//
4// This program is free software; you can redistribute it and/or
5// modify it under the terms of the GNU General Public License
6// as published by the Free Software Foundation; either version 3
7// of the License, or (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program; if not, write to the Free Software
16// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18
19
20#ifndef HEADER_IBTN_HPP
21#define HEADER_IBTN_HPP
22
23#include <irrString.h>
24namespace irr
25{
26 namespace gui
27 {
28 class IGUIStaticText;
29 class ScalableFont;
30 }
31 namespace video { class ITexture; }
32}
33
34#include "guiengine/widget.hpp"
35#include "utils/leak_check.hpp"
36#include "utils/cpp2011.hpp"
37
38namespace GUIEngine
39{
43 class IconButtonWidget : public Widget
44 {
45 private:
46 irr::core::rect<s32> m_list_header_icon_rect;
47 irr::video::ITexture* m_texture;
48 irr::video::ITexture* m_deactivated_texture;
49 irr::video::ITexture* m_highlight_texture;
50 int m_texture_w, m_texture_h;
51
52 video::ITexture* getDeactivatedTexture(video::ITexture* texture);
53 void setLabelFont();
54
55 public:
56 enum ScaleMode
57 {
58 SCALE_MODE_STRETCH,
59 SCALE_MODE_LIST_WIDGET,
60 SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO,
61 SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO
62 };
64 {
65 ICON_PATH_TYPE_ABSOLUTE,
71 };
72
73 protected:
74
75 IconPathType m_icon_path_type;
76
77 friend class Skin;
78
79 irr::gui::IGUIStaticText* m_label;
81
82 ScaleMode m_scale_mode;
83 float m_custom_aspect_ratio;
84
85 void setTexture(video::ITexture* texture);
86
87 public:
88
89 LEAK_CHECK()
90
91
93
94 IconButtonWidget(ScaleMode scale_mode=SCALE_MODE_KEEP_TEXTURE_ASPECT_RATIO, const bool tab_stop=true,
95 const bool focusable=true, IconPathType pathType=ICON_PATH_TYPE_RELATIVE);
96 virtual ~IconButtonWidget() {};
97
99 virtual void add() OVERRIDE;
100
105 void setCustomAspectRatio(float custom_aspect_ratio) { m_custom_aspect_ratio = custom_aspect_ratio; }
106
115 void setLabel(const irr::core::stringw& new_label);
116
122 void setLabelFont(irr::gui::ScalableFont* font);
123
131 void setImage(const char* path_to_texture,
133 // --------------------------------------------------------------------
135 void setImage(const std::string &path_to_texture,
137 {
138 setImage(path_to_texture.c_str(), path_type);
139 }
140
141 // --------------------------------------------------------------------
149 void setImage(irr::video::ITexture* texture);
150
151 // --------------------------------------------------------------------
152 void setHighlightedImage(irr::video::ITexture* texture)
153 {
154 m_highlight_texture = texture;
155 }
156
157 // --------------------------------------------------------------------
159 virtual EventPropagation focused(const int playerID) OVERRIDE;
160
161 // --------------------------------------------------------------------
163 virtual void unfocused(const int playerID, Widget* new_focus) OVERRIDE;
164 // --------------------------------------------------------------------
166 const video::ITexture* getTexture();
167 // --------------------------------------------------------------------
168 virtual void setVisible(bool visible) OVERRIDE;
169 // --------------------------------------------------------------------
170 virtual void elementRemoved() OVERRIDE
171 {
173 m_label = NULL;
174 }
175 // --------------------------------------------------------------------
176 const irr::core::rect<s32>& getListHeaderIconRect() const
177 {
178 return m_list_header_icon_rect;
179 }
180 };
181}
182
183#endif
A button widget with an icon and optionnaly a label beneath.
Definition: icon_button_widget.hpp:44
const video::ITexture * getTexture()
Returns the texture of this button.
Definition: icon_button_widget.cpp:354
virtual EventPropagation focused(const int playerID) OVERRIDE
override from base class
Definition: icon_button_widget.cpp:334
virtual void unfocused(const int playerID, Widget *new_focus) OVERRIDE
override from base class
Definition: icon_button_widget.cpp:345
void setLabel(const irr::core::stringw &new_label)
Temporarily change the text label if there is a label (next time this screen is visited,...
Definition: icon_button_widget.cpp:321
void setCustomAspectRatio(float custom_aspect_ratio)
Call this if scale mode is SCALE_MODE_KEEP_CUSTOM_ASPECT_RATIO.
Definition: icon_button_widget.hpp:105
virtual void setVisible(bool visible) OVERRIDE
Sets the widget (and its children, if any) visible or not.
Definition: icon_button_widget.cpp:455
void setImage(irr::video::ITexture *texture)
Change the texture used for this icon.
virtual void elementRemoved() OVERRIDE
Called when irrLicht widgets cleared.
Definition: icon_button_widget.hpp:170
bool m_tab_stop
Whether to make the widget included in keyboard navigation order when adding.
Definition: icon_button_widget.hpp:92
void setImage(const std::string &path_to_texture, IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE)
Convenience function taking std::string.
Definition: icon_button_widget.hpp:135
virtual void add() OVERRIDE
Implement callback from base class Widget.
Definition: icon_button_widget.cpp:66
void setImage(const char *path_to_texture, IconPathType path_type=ICON_PATH_TYPE_NO_CHANGE)
Change the texture used for this icon.
Definition: icon_button_widget.cpp:276
IconPathType
Definition: icon_button_widget.hpp:64
@ ICON_PATH_TYPE_NO_CHANGE
not a valid value per se, but can be passed as argument to leave the path type as it currently is
Definition: icon_button_widget.hpp:70
@ ICON_PATH_TYPE_RELATIVE
relative to the data dir
Definition: icon_button_widget.hpp:67
Object used to render the GUI widgets see Overview of GUI skin for more information about skinning in...
Definition: skin.hpp:269
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:143
virtual void elementRemoved()
Called when irrLicht widgets cleared.
Definition: widget.cpp:148
Definition: scalable_font.hpp:35
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33