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