ScummVM API documentation
msg_scroll.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef NUVIE_CORE_MSG_SCROLL_H
23 #define NUVIE_CORE_MSG_SCROLL_H
24 
25 #include "ultima/nuvie/misc/call_back.h"
26 #include "ultima/nuvie/gui/widgets/gui_widget.h"
27 #include "ultima/shared/std/containers.h"
28 
29 #define MSGSCROLL_U6_WIDTH 17
30 #define MSGSCROLL_U6_HEIGHT 10
31 
32 #define MSGSCROLL_MD_WIDTH 16
33 #define MSGSCROLL_MD_HEIGHT 8
34 
35 #define MSGSCROLL_SE_WIDTH 16
36 #define MSGSCROLL_SE_HEIGHT 8
37 
38 #define MSGSCROLL_CURSOR_DELAY 6 // used to slow down the animated cursor
39 
40 #define MSGSCROLL_SCROLLBACK_HEIGHT 100
41 
42 #define MSGSCROLL_NO_MAP_DISPLAY false
43 
44 namespace Ultima {
45 namespace Nuvie {
46 
47 
48 class Configuration;
49 class Font;
50 class Actor;
51 
52 class MsgText {
53 public:
54 
55  Font *font;
57  uint8 color;
58 
59  MsgText();
60  MsgText(const Common::String &new_string, Font *f);
61  ~MsgText();
62 
63  void append(const Common::String &new_string);
64  void copy(MsgText *msg_text);
65  uint32 length();
66 
67  uint16 getDisplayWidth();
68  bool operator<(const MsgText &rhs) const {
69  return (s < rhs.s);
70  }
71 };
72 
73 class MsgLine {
74 public:
75 
77  uint32 total_length;
78 
79  MsgLine() {
80  total_length = 0;
81  };
82  ~MsgLine();
83 
84  void append(MsgText *new_text);
85  void remove_char();
86  uint32 length();
87  MsgText *get_text_at_pos(uint16 pos);
88  uint16 get_display_width();
89 };
90 
91 class MsgScroll: public GUI_Widget, public CallBack {
92 protected:
93  const Configuration *config;
94  int game_type;
95  Font *font;
96  uint8 font_color;
97  uint8 font_highlight_color;
98  uint16 scroll_height;
99  uint16 scroll_width;
100  uint8 left_margin; // margin width in pixels
101 
102 // set by request_input()
103  CallBack *callback_target;
104  char *callback_user_data;
105  uint8 input_char;
106  bool input_mode;
107  const char *permit_input; // character list, or 0 = any string
108  bool yes_no_only, aye_nay_only, numbers_only; // limited input selection
109 
110  bool page_break;
111  bool just_finished_page_break;
112  bool just_displayed_prompt;
113  virtual void process_page_break();
114  Common::List<MsgLine *> msg_buf;
115 
116  Common::String input_buf;
117  bool permit_inputescape; // can RETURN or ESCAPE be used to escape input entry
118 
119  uint16 cursor_wait;
120 
121  uint16 scrollback_height;
122  bool discard_whitespace;
123  bool using_target_cursor;
124 
125  uint8 bg_color;
126  bool talking;
127 
128 private:
129  uint16 screen_x; //x offset to top left corner of MsgScroll
130  uint16 screen_y; //y offset to top left corner of MsgScroll
131 
132  bool keyword_highlight;
133 
134  MsgText prompt;
135  Common::List<MsgText *> holding_buffer;
136 
137  bool show_cursor;
138  bool autobreak; // if true, a page break will be added when the scroll is full
139 
140  bool scroll_updated;
141  uint8 cursor_char;
142  uint16 cursor_x, cursor_y;
143 
144  uint16 line_count; // count the number of lines since last page break.
145 
146  uint16 display_pos;
147 
148  bool capitalise_next_letter;
149 
150 public:
151 
152  MsgScroll(const Configuration *cfg, Font *f);
153  MsgScroll() : GUI_Widget(nullptr, 0, 0, 0, 0),
154  config(nullptr), game_type(0), font(nullptr), scroll_height(0),
155  scroll_width(0), callback_target(nullptr), callback_user_data(nullptr),
156  input_mode(false), permit_input(nullptr), page_break(false),
157  just_finished_page_break(false), permit_inputescape(false),
158  cursor_wait(0), screen_x(0), screen_y(0), bg_color(0),
159  keyword_highlight(true), talking(false), show_cursor(false),
160  autobreak(false), scroll_updated(false), cursor_char(0),
161  cursor_x(0), cursor_y(0), line_count(0), display_pos(0),
162  capitalise_next_letter(false), just_displayed_prompt(false),
163  scrollback_height(MSGSCROLL_SCROLLBACK_HEIGHT), discard_whitespace(false),
164  left_margin(0), font_color(0), font_highlight_color(0), input_char(0),
165  yes_no_only(false), aye_nay_only(false), numbers_only(false),
166  using_target_cursor(false) {
167  }
168  ~MsgScroll() override;
169 
170  void init(const Configuration *cfg, Font *f);
171 
172  bool init(const char *player_name);
173  void page_up();
174  void page_down();
175  virtual void move_scroll_down();
176  virtual void move_scroll_up();
177  void set_using_target_cursor(bool val) {
178  using_target_cursor = val;
179  }
180 
181  void process_holding_buffer();
182 
183  MsgText *holding_buffer_get_token();
184  bool is_holding_buffer_empty() const {
185  return holding_buffer.empty();
186  }
187  virtual bool can_display_prompt() const {
188  return !just_displayed_prompt;
189  }
190 
191  virtual bool parse_token(MsgText *token);
192  void add_token(MsgText *token);
193  bool remove_char();
194 
195  virtual void set_font(uint8 font_type);
196  virtual bool is_garg_font();
197 
198  template<class... TParam>
199  int print(const Common::String &format, TParam... param);
200 
201  virtual void display_string(const Common::String &s, Font *f, bool include_on_map_window);
202  void display_string(const Common::String &s, Font *f, uint8 color, bool include_on_map_window);
203  void display_string(const Common::String &s, uint16 length, uint8 lang_num);
204  void display_string(const Common::String &s, bool include_on_map_window = true);
205  void display_string(const Common::String &s, uint8 color, bool include_on_map_window);
206  void display_fmt_string(const char *format, ...);
207  void message(const char *string) {
208  display_string(string);
209  display_prompt();
210  }
211 
212  bool set_prompt(const char *new_prompt, Font *f = nullptr);
213  virtual void display_prompt();
214  virtual void display_converse_prompt();
215 
216  void set_keyword_highlight(bool state);
217 
218  void set_input_mode(bool state, const char *allowed = nullptr,
219  bool can_escape = true, bool use_target_cursor = false,
220  bool set_numbers_only_to_true = false);
221  virtual void set_talking(bool state, Actor *actor = nullptr) {
222  talking = state;
223  input_char = 0;
224  }
225  bool is_talking() const {
226  return talking;
227  }
228  void set_show_cursor(bool state) {
229  show_cursor = state;
230  }
231 
232  void set_autobreak(bool state) {
233  autobreak = state;
234  }
235  void set_discard_whitespace(bool discard) {
236  discard_whitespace = discard;
237  }
238 
239  bool get_page_break() const {
240  return page_break;
241  }
242 
243  GUI_status KeyDown(const Common::KeyState &key) override;
244  GUI_status MouseUp(int x, int y, Events::MouseButton button) override;
245  GUI_status MouseWheel(sint32 x, sint32 y) override;
246  virtual Common::String get_token_string_at_pos(uint16 x, uint16 y);
247 //void updateScroll();
248  void Display(bool full_redraw) override;
249 
250  void clearCursor(uint16 x, uint16 y);
251  virtual void drawCursor(uint16 x, uint16 y);
252 
253  void set_page_break();
254 
255  virtual bool input_buf_add_char(char c);
256  virtual bool input_buf_remove_char();
257 
258  /* Converse uses this to tell if the scroll has finished displaying the converse dialog */
259  virtual bool is_converse_finished() {
260  return true;
261  }
262 
263  bool has_input();
264  Common::String get_input();
265  const char *peek_at_input();
266  void request_input(CallBack *caller, void *user_data);
267  void cancel_input_request() {
268  request_input(nullptr, nullptr);
269  }
270  void clear_scroll();
271 
272 protected:
273 
274  void set_scroll_dimensions(uint16 w, uint16 h);
275  void delete_front_line();
276  virtual MsgLine *add_new_line();
277  void drawLine(Screen *screen, MsgLine *msg_line, uint16 line_y);
278  inline void clear_page_break();
279 
280  virtual void set_permitted_input(const char *allowed);
281  virtual void clear_permitted_input();
282  virtual bool can_fit_token_on_msgline(MsgLine *msg_line, MsgText *token);
283  void increase_input_char();
284  void decrease_input_char();
285  uint8 get_char_from_input_char();
286  virtual uint8 get_input_font_color() const {
287  return font_color;
288  }
289 
290 private:
291  int print_internal(const Common::String *format, ...);
292 };
293 
294 template<class... TParam>
295 inline int MsgScroll::print(const Common::String &format, TParam... param) {
296  return print_internal(&format, Common::forward<TParam>(param)...);
297 }
298 
299 } // End of namespace Nuvie
300 } // End of namespace Ultima
301 
302 #endif
Definition: actor.h:174
Definition: str.h:59
Definition: msg_scroll.h:91
Definition: gui_widget.h:38
Definition: configuration.h:61
Definition: list.h:44
Definition: msg_scroll.h:73
Definition: screen.h:41
Definition: detection.h:27
Definition: call_back.h:50
Definition: msg_scroll.h:52
Definition: keyboard.h:294
bool empty() const
Definition: list.h:258
Definition: font.h:42