Simulant  21.12-574
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
keyboard.h
1 #pragma once
2 
3 #include <map>
4 #include "widget.h"
5 #include "../../keycodes.h"
6 
7 namespace smlt {
8 
9 class EventListener;
10 
11 namespace ui {
12 
16 class Frame;
17 class TextEntry;
18 
20  KeyboardCode code;
21  char16_t chr;
22 
23  bool cancelled = false;
24 
25  void cancel() {
26  cancelled = true;
27  }
28 };
29 
31 typedef sig::signal<void (const unicode&)> KeyboardDoneSignal;
32 typedef sig::signal<void ()> KeyboardCancelledSignal;
33 
34 enum KeyboardMode {
35  KEYBOARD_MODE_UPPERCASE,
36  KEYBOARD_MODE_LOWERCASE,
37  KEYBOARD_MODE_NUMERICAL,
38  KEYBOARD_MODE_ACCENT_LOWERCASE,
39  KEYBOARD_MODE_ACCENT_UPPERCASE
40 };
41 
42 class KeyboardPanel;
43 
44 /* A keyboard is combined of a TextInput and a KeyboardPanel */
45 class Keyboard:
46  public Widget {
47 
48  DEFINE_SIGNAL(KeyboardKeyPressedSignal, signal_key_pressed);
49  DEFINE_SIGNAL(KeyboardDoneSignal, signal_done);
50  DEFINE_SIGNAL(KeyboardCancelledSignal, signal_cancelled);
51 public:
52  using Widget::init; // Pull in init to satisfy TwoPhaseConstructed<Keyboard>
53  using Widget::clean_up;
54 
55  Keyboard(UIManager* owner, UIConfig* config, Stage *stage, KeyboardMode mode, const unicode& initial_text="");
56  ~Keyboard();
57 
58  void cursor_up();
59  void cursor_down();
60  void cursor_right();
61  void cursor_left();
62  bool cursor_to_char(uint16_t displayed_char);
63  void cursor_to_return();
64  void cursor_to_case_toggle();
65  void cursor_to_backspace();
66  void cursor_to_ok();
67  void cursor_to_space();
68 
70  void activate();
71  void cancel();
72 
73  void set_mode(KeyboardMode mode);
74  KeyboardMode mode() const;
75 
76  bool is_keyboard_integration_enabled() const {
77  return bool(keyboard_listener_);
78  }
79 
80  void set_keyboard_integration_enabled(bool value);
81 
82  using Widget::set_font;
83 
84  void set_font(FontPtr font) override;
85 
86  TextEntry* entry() {
87  return entry_.get();
88  }
89 private:
90  void on_transformation_change_attempted() override;
91 
92  UIDim calculate_content_dimensions(Px text_width, Px text_height) override;
93 
94  std::shared_ptr<KeyboardPanel> panel_;
95  std::shared_ptr<TextEntry> entry_;
96  std::shared_ptr<Frame> info_row_;
97 
98  Frame* main_frame_ = nullptr;
99 
100  std::shared_ptr<EventListener> keyboard_listener_;
101 
102  bool pre_set_text(const unicode& text) override;
103 
104  const unicode& calc_text() const override;
105 };
106 
107 }
108 }
smlt::ui::Keyboard
Definition: keyboard.h:46
smlt::ui::UIManager
Definition: ui_manager.h:55
smlt::ui::SoftKeyPressedEvent
Definition: keyboard.h:19
smlt::Stage
Definition: stage.h:80
smlt
Definition: animation.cpp:25
smlt::ui::Widget
Definition: widget.h:85
smlt::ui::Keyboard::activate
void activate()
Definition: keyboard.cpp:1240
smlt::ui::UIConfig
Definition: ui_config.h:244
smlt::ui::Px
Definition: ui_config.h:42
smlt::ui::Frame
Definition: frame.h:29
unicode
Definition: unicode.h:36
smlt::ui::TextEntry
Definition: text_entry.h:11
smlt::ui::UIDim
Definition: ui_config.h:192
smlt::sig::signal
Definition: signal.h:330