SuperTuxKart
screen_keyboard.hpp
1 //
2 // SuperTuxKart - a fun racing game with go-kart
3 // Copyright (C) 2013-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 #ifndef HEADER_SCREEN_KEYBOARD_HPP
20 #define HEADER_SCREEN_KEYBOARD_HPP
21 
22 #include <IGUIButton.h>
23 #include <IGUIWindow.h>
24 
25 #include "guiengine/abstract_top_level_container.hpp"
26 #include "guiengine/skin.hpp"
27 #include "input/input_manager.hpp"
28 #include "utils/leak_check.hpp"
29 
30 
31 class CGUIEditBox;
32 
36 namespace GUIEngine
37 {
38  class ButtonWidget;
39 
49  {
50  protected:
51  typedef std::vector<std::vector<std::string> > KeyboardLayout;
52  typedef std::vector<std::vector<int> > KeyboardLayoutProportions;
53  enum ButtonsType
54  {
55  BUTTONS_NONE,
56  BUTTONS_LOWER,
57  BUTTONS_UPPER,
58  BUTTONS_DIGITS,
59  BUTTONS_DIGITS2,
60  BUTTONS_EMOJI
61  };
62  private:
65 
69 
73 
75  unsigned int m_repeat_time;
76 
79 
82 
85 
87  irr::gui::IGUIButton* m_back_button;
88 
90  ButtonsType m_buttons_type;
91 
93  irr::gui::IGUIWindow* m_irrlicht_window;
94 
96  irr::core::rect<irr::s32> m_area;
97 
99  std::vector<ButtonWidget*> m_buttons;
100 
102  InputManager::InputDriverMode m_previous_mode;
103 
104  void initButtons();
105  void assignButtons(ButtonsType buttons_type);
106  core::stringw getKeyName(std::string key_id);
107 
108  public:
109  LEAK_CHECK()
110 
111  ScreenKeyboard(float percent_width, float percent_height,
112  CGUIEditBox* edit_box);
113  ~ScreenKeyboard();
114 
115  void setArea();
116  void init();
117 
118  virtual EventPropagation processEvent(const std::string& eventSource);
119 
120  static void dismiss();
121  static bool onEscapePressed();
125 
127  static bool isActive() {return m_screen_keyboard != NULL;}
128 
129  static bool shouldUseScreenKeyboard();
130  static bool hasSystemScreenKeyboard();
131 
133  virtual void onUpdate(float dt);
134 
135  bool onEvent(const SEvent &event);
136 
138  irr::gui::IGUIWindow* getIrrlichtElement() {return m_irrlicht_window;}
139 
144  bool isMyIrrChild(irr::gui::IGUIElement* widget) const
145  {return m_irrlicht_window->isMyChild(widget);}
146 
148  int getWidth() {return m_area.getWidth();}
149 
151  int getHeight() {return m_area.getHeight();}
152 
155 
156  virtual KeyboardLayoutProportions getKeyboardLayoutProportions() const;
157 
158  virtual KeyboardLayout* getKeyboardLayout(ButtonsType bt) const;
159 
160  virtual ButtonsType getDefaultButtonsType() const
161  {
162  return BUTTONS_LOWER;
163  }
164 
165  virtual void onResize();
166  };
167 }
168 
169 #endif
Definition: CGUIEditBox.hpp:33
Represents a GUI widgets container.
Definition: abstract_top_level_container.hpp:43
Class representing a screen keyboard.
Definition: screen_keyboard.hpp:49
ButtonsType m_buttons_type
Remembers currently selected button type.
Definition: screen_keyboard.hpp:90
static bool isActive()
Returns true if keyboard is created.
Definition: screen_keyboard.hpp:127
virtual void onUpdate(float dt)
Override to be notified of updates.
Definition: screen_keyboard.cpp:363
bool m_back_button_pressed
True if backspace button was pressed.
Definition: screen_keyboard.hpp:78
InputManager::InputDriverMode m_previous_mode
Remembered input mode that was used before keyboard creation.
Definition: screen_keyboard.hpp:102
static bool shouldUseScreenKeyboard()
A function that determines if (native) screen keyboard should be activated.
Definition: screen_keyboard.cpp:559
CGUIEditBox * m_edit_box
The edit box that is assigned to the keyboard.
Definition: screen_keyboard.hpp:84
unsigned int m_repeat_time
A time for repeat key feature.
Definition: screen_keyboard.hpp:75
static bool hasSystemScreenKeyboard()
Returns true if system screen keyboard is available.
Definition: screen_keyboard.cpp:567
std::vector< ButtonWidget * > m_buttons
Contans the pointers to all button widgets.
Definition: screen_keyboard.hpp:99
float m_percent_width
A value in range of 0.0 to 1.0 that determines width of the screen that is used by the keyboard.
Definition: screen_keyboard.hpp:68
irr::gui::IGUIButton * m_back_button
A button that is used as backspace key.
Definition: screen_keyboard.hpp:87
static bool onEscapePressed()
A function that handles escape pressed event.
Definition: screen_keyboard.cpp:550
irr::gui::IGUIWindow * m_irrlicht_window
Irrlicht window used by the keyboard widget.
Definition: screen_keyboard.hpp:93
irr::gui::IGUIWindow * getIrrlichtElement()
Get irrlicht window used by the keyboard widget.
Definition: screen_keyboard.hpp:138
irr::core::rect< irr::s32 > m_area
Contains position and dimensions of the keyboard.
Definition: screen_keyboard.hpp:96
bool isMyIrrChild(irr::gui::IGUIElement *widget) const
Checks if the screen keyboard is a parent of the selected item.
Definition: screen_keyboard.hpp:144
static void dismiss()
A function that closes the keyboard.
Definition: screen_keyboard.cpp:541
CGUIEditBox * getEditBox()
Returns assigned edit box.
Definition: screen_keyboard.hpp:154
int getHeight()
Returns height of the screen keyboard.
Definition: screen_keyboard.hpp:151
int getWidth()
Returns width of the screen keyboard.
Definition: screen_keyboard.hpp:148
float m_percent_height
A value in range of 0.0 to 1.0 that determines height of the screen that is used by the keyboard.
Definition: screen_keyboard.hpp:72
virtual EventPropagation processEvent(const std::string &eventSource)
A function that handles buttons events.
Definition: screen_keyboard.cpp:451
static ScreenKeyboard * getCurrent()
Returns pointer to the created keyboard or NULL if keyboard was not created.
Definition: screen_keyboard.hpp:124
void initButtons()
Initializes all button widgets.
Definition: screen_keyboard.cpp:209
bool m_schedule_close
True if screen keyboard is going to be closed.
Definition: screen_keyboard.hpp:81
void assignButtons(ButtonsType buttons_type)
A function that allows to select one of the available buttons layout.
Definition: screen_keyboard.cpp:323
void init()
Screen keyboard initialization, needs to be called after new to take into account for runtime polymor...
Definition: screen_keyboard.cpp:182
static ScreenKeyboard * m_screen_keyboard
Global instance of the current screen keyboard.
Definition: screen_keyboard.hpp:64
bool onEvent(const SEvent &event)
A function that handles irrlicht events.
Definition: screen_keyboard.cpp:404
In order to avoid calculating render information every frame, it's stored in a SkinWidgetContainer fo...
Definition: skin.hpp:142
Contains all GUI engine related classes and functions.
Definition: abstract_state_manager.hpp:33