SuperTuxKart
label_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_LABEL_HPP
21 #define HEADER_LABEL_HPP
22 
23 #include <irrString.h>
24 #include <SColor.h>
25 
26 #include "guiengine/widget.hpp"
27 #include "utils/leak_check.hpp"
28 #include "utils/ptr_vector.hpp"
29 
30 namespace irr
31 {
32  namespace gui { class IGUIFont; }
33 }
34 
35 namespace GUIEngine
36 {
40  class LabelWidget : public Widget
41  {
42  public:
43 
44  enum LabelType
45  {
46  NORMAL,
47  BRIGHT,
48  TITLE,
49  SMALL_TITLE,
50  TINY_TITLE,
51  COUNT
52  };
53 
54  private:
55 
56  LabelType m_type;
57  irr::video::SColor m_color;
58  bool m_has_color;
59  bool m_expand_if_needed;
60  bool m_word_wrap;
61 
62  irr::gui::IGUIFont* getCurrentFont() const;
63  void updateExpandedText(const irr::core::stringw& text);
64 
67 
68  float m_per_character_size;
69 
72 
73  // Hide overloaded methods
74  using Widget::setText;
75 
76  public:
77 
78  LEAK_CHECK()
79 
80 
83  LabelWidget(LabelType type = NORMAL);
84 
85  virtual ~LabelWidget() {}
86 
88  virtual void add();
89 
92  void setColor(const irr::video::SColor& color);
93  void setErrorColor();
94  void setDefaultColor();
95 
97  virtual void update(float dt);
98 
113  virtual void setText(const irr::core::stringw& text, bool expandAsNeeded);
114 
115  // --------------------------------------------------------------------
116 
118  void setScrollSpeed(float speed);
119 
120  // --------------------------------------------------------------------
121  float getScrollSpeed() const { return m_scroll_speed; }
122  // --------------------------------------------------------------------
128  bool scrolledOff() const;
129 
130  virtual void resize();
131  };
132 }
133 
134 #endif
A simple label widget.
Definition: label_widget.hpp:41
float m_scroll_speed
Scroll speed in characters/seconds (0 if no scrolling).
Definition: label_widget.hpp:66
void setScrollSpeed(float speed)
Sets horizontal scroll speed.
Definition: label_widget.cpp:197
virtual void update(float dt)
Callback from base class Widget.
Definition: label_widget.cpp:175
virtual void setText(const irr::core::stringw &s)
Sets the text of a widget from a wchar_t.
Definition: widget.cpp:143
bool scrolledOff() const
Check if the current has been fully scrolled.
Definition: label_widget.cpp:187
virtual void resize()
Call to resize the widget after its coordinates are updated.
Definition: label_widget.cpp:204
virtual void add()
Callback from base class Widget.
Definition: label_widget.cpp:62
void setColor(const irr::video::SColor &color)
Sets the color of the widget.
Definition: label_widget.cpp:238
float m_scroll_offset
Current scroll offset.
Definition: label_widget.hpp:71
The nearly-abstract base of all widgets (not fully abstract since a bare Widget can be created for th...
Definition: widget.hpp:147
virtual void setText(const irr::core::stringw &s)
Sets the text of a widget from a wchar_t.
Definition: widget.cpp:143
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33