| 1 |
/* |
| 2 |
* Portions of this file are copyright Rebirth contributors and licensed as |
| 3 |
* described in COPYING.txt. |
| 4 |
* Portions of this file are copyright Parallax Software and licensed |
| 5 |
* according to the Parallax license below. |
| 6 |
* See COPYING.txt for license details. |
| 7 |
|
| 8 |
THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX |
| 9 |
SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO |
| 10 |
END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A |
| 11 |
ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS |
| 12 |
IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS |
| 13 |
SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE |
| 14 |
FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE |
| 15 |
CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS |
| 16 |
AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE. |
| 17 |
COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* |
| 22 |
* Header file for user interface |
| 23 |
* |
| 24 |
*/ |
| 25 |
|
| 26 |
#pragma once |
| 27 |
|
| 28 |
#include <type_traits> |
| 29 |
#include "dxxsconf.h" |
| 30 |
#include "dsx-ns.h" |
| 31 |
#include "fwd-event.h" |
| 32 |
#include "fmtcheck.h" |
| 33 |
#include "u_mem.h" |
| 34 |
|
| 35 |
#ifdef __cplusplus |
| 36 |
#include <cstdint> |
| 37 |
#include <string> |
| 38 |
#include "fwd-gr.h" |
| 39 |
#include "varutil.h" |
| 40 |
#include "window.h" |
| 41 |
#include "ntstring.h" |
| 42 |
#include <array> |
| 43 |
#include <memory> |
| 44 |
|
| 45 |
namespace dcx { |
| 46 |
|
| 47 |
struct UI_DIALOG; |
| 48 |
|
| 49 |
struct UI_KEYPAD { |
| 50 |
using buttontext_element_t = std::array<char, 100>; |
| 51 |
using buttontext_t = std::array<buttontext_element_t, 17>; |
| 52 |
UI_KEYPAD(); |
| 53 |
unsigned numkeys; |
| 54 |
ntstring<99> description; |
| 55 |
std::array<short, 100> keycode; |
| 56 |
std::array<int, 100> function_number; |
| 57 |
buttontext_t buttontext; |
| 58 |
}; |
| 59 |
|
| 60 |
struct UI_EVENT |
| 61 |
{ |
| 62 |
unsigned int frame; |
| 63 |
int type; |
| 64 |
int data; |
| 65 |
}; |
| 66 |
|
| 67 |
struct UI_GADGET |
| 68 |
{ |
| 69 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &) = 0; |
| 70 |
const uint8_t kind; |
| 71 |
short x1,y1,x2,y2; |
| 72 |
int hotkey = -1; |
| 73 |
struct UI_GADGET * prev; \ |
| 74 |
struct UI_GADGET * next; \ |
| 75 |
struct UI_GADGET *when_tab = nullptr; |
| 76 |
struct UI_GADGET *when_btab = nullptr; |
| 77 |
struct UI_GADGET *when_up = nullptr; |
| 78 |
struct UI_GADGET *when_down = nullptr; |
| 79 |
struct UI_GADGET *when_left = nullptr; |
| 80 |
struct UI_GADGET *when_right = nullptr; |
| 81 |
struct UI_GADGET *parent = nullptr; |
| 82 |
grs_subcanvas_ptr canvas; \ |
| 83 |
UI_GADGET(UI_GADGET *&link, uint8_t kind); |
| 84 |
protected: |
| 85 |
~UI_GADGET() = default; |
| 86 |
}; |
| 87 |
|
| 88 |
struct UI_GADGET_USERBOX final : UI_GADGET |
| 89 |
{ |
| 90 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 7>{}; |
| 91 |
using UI_GADGET::UI_GADGET; |
| 92 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 93 |
short width, height; |
| 94 |
short b1_held_down; |
| 95 |
short b1_clicked; |
| 96 |
short b1_double_clicked; |
| 97 |
short b1_dragging; |
| 98 |
short b1_drag_x1, b1_drag_y1; |
| 99 |
short b1_drag_x2, b1_drag_y2; |
| 100 |
short b1_done_dragging; |
| 101 |
short mouse_onme; |
| 102 |
short mouse_x, mouse_y; |
| 103 |
int keypress; |
| 104 |
grs_bitmap * bitmap; |
| 105 |
}; |
| 106 |
|
| 107 |
struct UI_GADGET_BUTTON final : UI_GADGET |
| 108 |
{ |
| 109 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 1>{}; |
| 110 |
using UI_GADGET::UI_GADGET; |
| 111 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 112 |
std::string text; |
| 113 |
short width, height; |
| 114 |
short position; |
| 115 |
short oldposition; |
| 116 |
short pressed; |
| 117 |
uint8_t dim_if_no_function; |
| 118 |
int hotkey1; |
| 119 |
int (*user_function)(void); |
| 120 |
int (*user_function1)(void); |
| 121 |
}; |
| 122 |
|
| 123 |
struct UI_GADGET_INPUTBOX final : UI_GADGET |
| 124 |
{ |
| 125 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 6>{}; |
| 126 |
using UI_GADGET::UI_GADGET; |
| 127 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 128 |
std::unique_ptr<char[]> text; |
| 129 |
short width, height; |
| 130 |
short length; |
| 131 |
short position; |
| 132 |
short oldposition; |
| 133 |
short pressed; |
| 134 |
short first_time; |
| 135 |
}; |
| 136 |
|
| 137 |
struct UI_GADGET_RADIO final : UI_GADGET |
| 138 |
{ |
| 139 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 4>{}; |
| 140 |
using UI_GADGET::UI_GADGET; |
| 141 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 142 |
std::unique_ptr<char[]> text; |
| 143 |
short width, height; |
| 144 |
short position; |
| 145 |
short oldposition; |
| 146 |
short pressed; |
| 147 |
short group; |
| 148 |
short flag; |
| 149 |
}; |
| 150 |
|
| 151 |
struct UI_GADGET_ICON final : UI_GADGET |
| 152 |
{ |
| 153 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 9>{}; |
| 154 |
using UI_GADGET::UI_GADGET; |
| 155 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 156 |
RAIIdmem<char[]> text; |
| 157 |
short width, height; |
| 158 |
sbyte flag; |
| 159 |
sbyte pressed; |
| 160 |
sbyte position; |
| 161 |
sbyte oldposition; |
| 162 |
int trap_key; |
| 163 |
int (*user_function)(void); |
| 164 |
}; |
| 165 |
|
| 166 |
struct UI_GADGET_CHECKBOX final : UI_GADGET |
| 167 |
{ |
| 168 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 5>{}; |
| 169 |
using UI_GADGET::UI_GADGET; |
| 170 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 171 |
RAIIdmem<char[]> text; |
| 172 |
short width, height; |
| 173 |
short position; |
| 174 |
short oldposition; |
| 175 |
short pressed; |
| 176 |
short group; |
| 177 |
short flag; |
| 178 |
}; |
| 179 |
|
| 180 |
struct UI_GADGET_SCROLLBAR final : UI_GADGET |
| 181 |
{ |
| 182 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 3>{}; |
| 183 |
using UI_GADGET::UI_GADGET; |
| 184 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 185 |
short horz; |
| 186 |
short width, height; |
| 187 |
int start; |
| 188 |
int stop; |
| 189 |
int position; |
| 190 |
int window_size; |
| 191 |
int fake_length; |
| 192 |
int fake_position; |
| 193 |
int fake_size; |
| 194 |
std::unique_ptr<UI_GADGET_BUTTON> up_button, down_button; |
| 195 |
fix64 last_scrolled; |
| 196 |
short drag_x, drag_y; |
| 197 |
int drag_starting; |
| 198 |
int dragging; |
| 199 |
int moved; |
| 200 |
}; |
| 201 |
|
| 202 |
struct UI_GADGET_LISTBOX final : UI_GADGET |
| 203 |
{ |
| 204 |
static constexpr auto s_kind = std::integral_constant<uint8_t, 2>{}; |
| 205 |
using UI_GADGET::UI_GADGET; |
| 206 |
virtual window_event_result event_handler(UI_DIALOG &dlg, const d_event &event) override; |
| 207 |
const char *const *list; |
| 208 |
short width, height; |
| 209 |
int num_items; |
| 210 |
int num_items_displayed; |
| 211 |
int first_item; |
| 212 |
int old_first_item; |
| 213 |
int current_item; |
| 214 |
int selected_item; |
| 215 |
int old_current_item; |
| 216 |
int dragging; |
| 217 |
int textheight; |
| 218 |
int moved; |
| 219 |
std::unique_ptr<UI_GADGET_SCROLLBAR> scrollbar; |
| 220 |
fix64 last_scrolled; |
| 221 |
}; |
| 222 |
|
| 223 |
enum dialog_flags |
| 224 |
{ |
| 225 |
DF_FILLED = 2, |
| 226 |
DF_SAVE_BG = 4, |
| 227 |
DF_DIALOG = (4+2+1), |
| 228 |
DF_MODAL = 8 // modal = accept all user input exclusively |
| 229 |
}; |
| 230 |
|
| 231 |
template <typename T> |
| 232 |
using ui_subfunction_t = window_event_result (*)(struct UI_DIALOG *,const d_event &, T *); |
| 233 |
|
| 234 |
struct UI_DIALOG : window |
| 235 |
{ |
| 236 |
// TODO: Make these private |
| 237 |
UI_GADGET *gadget = nullptr; |
| 238 |
UI_GADGET *keyboard_focus_gadget = nullptr; |
| 239 |
short d_width, d_height; |
| 240 |
enum dialog_flags d_flags; |
| 241 |
|
| 242 |
public: |
| 243 |
explicit UI_DIALOG(short x, short y, short w, short h, enum dialog_flags flags); |
| 244 |
|
| 245 |
~UI_DIALOG(); |
| 246 |
virtual window_event_result event_handler(const d_event &) override; |
| 247 |
virtual window_event_result callback_handler(const d_event &) = 0; |
| 248 |
}; |
| 249 |
|
| 250 |
#define B1_JUST_PRESSED (event.type == event_type::mouse_button_down && event_mouse_get_button(event) == mbtn::left) |
| 251 |
#define B1_JUST_RELEASED (event.type == event_type::mouse_button_up && event_mouse_get_button(event) == mbtn::left) |
| 252 |
#define B1_DOUBLE_CLICKED (event.type == event_type::mouse_double_clicked && event_mouse_get_button(event) == mbtn::left) |
| 253 |
|
| 254 |
extern grs_font_ptr ui_small_font; |
| 255 |
|
| 256 |
extern unsigned char CBLACK,CGREY,CWHITE,CBRIGHT,CRED; |
| 257 |
extern UI_GADGET * selected_gadget; |
| 258 |
|
| 259 |
#define Hline(C,x1,x2,y,c) Hline(C,x1,y,x2,c) |
| 260 |
#define Vline(C,y1,y2,x,c) Vline(C,x,y1,y2,c) |
| 261 |
void Hline(grs_canvas &, fix x1, fix x2, fix y, color_palette_index color); |
| 262 |
void Vline(grs_canvas &, fix y1, fix y2, fix x, color_palette_index color); |
| 263 |
void ui_string_centered(grs_canvas &, unsigned x, unsigned y, const char *s); |
| 264 |
void ui_draw_box_out(grs_canvas &, unsigned x1, unsigned y1, unsigned x2, unsigned y2); |
| 265 |
void ui_draw_box_in(grs_canvas &, unsigned x1, unsigned y1, unsigned x2, unsigned y2); |
| 266 |
void ui_draw_shad(grs_canvas &, unsigned x1, unsigned y1, unsigned x2, unsigned y2, color_palette_index c1, color_palette_index c2); |
| 267 |
|
| 268 |
int ui_init(); |
| 269 |
void ui_close(); |
| 270 |
|
| 271 |
typedef cstring_tie<10> ui_messagebox_tie; |
| 272 |
int ui_messagebox( short xc, short yc, const char * text, const ui_messagebox_tie &Button ); |
| 273 |
#define ui_messagebox(X,Y,N,T,...) ((ui_messagebox)((X),(Y),(T), ui_messagebox_tie(__VA_ARGS__))) |
| 274 |
|
| 275 |
void ui_dialog_set_current_canvas(UI_DIALOG &dlg); |
| 276 |
void ui_close_dialog(UI_DIALOG &dlg); |
| 277 |
|
| 278 |
#define GADGET_PRESSED(g) (event.type == event_type::ui_gadget_pressed && &ui_event_get_gadget(event) == g) |
| 279 |
|
| 280 |
void ui_gadget_add(UI_DIALOG &dlg, short x1, short y1, short x2, short y2, UI_GADGET &); |
| 281 |
|
| 282 |
template <typename T> |
| 283 |
[[nodiscard]] |
| 284 |
static std::unique_ptr<T> ui_gadget_add(UI_DIALOG &dlg, short x1, short y1, short x2, short y2) |
| 285 |
{ |
| 286 |
auto t = std::make_unique<T>(dlg.gadget, T::s_kind); |
| 287 |
ui_gadget_add(dlg, x1, y1, x2, y2, *t); |
| 288 |
return t; |
| 289 |
} |
| 290 |
|
| 291 |
[[nodiscard]] |
| 292 |
std::unique_ptr<UI_GADGET_BUTTON> ui_add_gadget_button(UI_DIALOG &dlg, short x, short y, short w, short h, const char *text, int (*function_to_call)()); |
| 293 |
|
| 294 |
window_event_result ui_gadget_send_event(UI_DIALOG &dlg, enum event_type type, UI_GADGET &gadget); |
| 295 |
UI_GADGET &ui_event_get_gadget(const d_event &event); |
| 296 |
window_event_result ui_dialog_do_gadgets(UI_DIALOG &dlg, const d_event &event); |
| 297 |
|
| 298 |
int ui_mouse_on_gadget(UI_GADGET &gadget); |
| 299 |
|
| 300 |
std::unique_ptr<UI_GADGET_LISTBOX> ui_add_gadget_listbox(UI_DIALOG &dlg, short x, short y, short w, short h, short numitems, char **list); |
| 301 |
|
| 302 |
extern void ui_mega_process(); |
| 303 |
|
| 304 |
gr_string_size ui_get_button_size(const grs_font &, const char *text); |
| 305 |
|
| 306 |
[[nodiscard]] |
| 307 |
std::unique_ptr<UI_GADGET_SCROLLBAR> ui_add_gadget_scrollbar(UI_DIALOG &dlg, short x, short y, short w, short h, int start, int stop, int position, int window_size); |
| 308 |
|
| 309 |
void ui_dputs_at( UI_DIALOG * dlg, short x, short y, const char * str ); |
| 310 |
void ui_dprintf_at(UI_DIALOG * dlg, short x, short y, const char *) = delete; |
| 311 |
extern void ui_dprintf_at( UI_DIALOG * dlg, short x, short y, const char * format, ... ) dxx_compiler_attribute_format_printf(4, 5); |
| 312 |
|
| 313 |
[[nodiscard]] |
| 314 |
std::unique_ptr<UI_GADGET_RADIO> ui_add_gadget_radio(UI_DIALOG &dlg, short x, short y, short w, short h, short group, const char *text); |
| 315 |
|
| 316 |
void ui_radio_set_value(UI_GADGET_RADIO &radio, int value); |
| 317 |
|
| 318 |
[[nodiscard]] |
| 319 |
std::unique_ptr<UI_GADGET_CHECKBOX> ui_add_gadget_checkbox(UI_DIALOG &dlg, short x, short y, short w, short h, short group, const char *text); |
| 320 |
|
| 321 |
extern void ui_checkbox_check(UI_GADGET_CHECKBOX * checkbox, int check); |
| 322 |
|
| 323 |
UI_GADGET &ui_gadget_get_next(UI_GADGET &gadget); |
| 324 |
void ui_gadget_calc_keys(UI_DIALOG &dlg); |
| 325 |
|
| 326 |
void ui_listbox_change(UI_DIALOG *dlg, UI_GADGET_LISTBOX *listbox, uint_fast32_t numitems, const char *const *list); |
| 327 |
|
| 328 |
[[nodiscard]] |
| 329 |
std::unique_ptr<UI_GADGET_INPUTBOX> ui_add_gadget_inputbox(UI_DIALOG &dlg, short x, short y, uint_fast32_t length_of_initial_text, uint_fast32_t maximum_allowed_text_length, const char *text); |
| 330 |
|
| 331 |
template <std::size_t SL, std::size_t L> |
| 332 |
[[nodiscard]] |
| 333 |
static inline std::unique_ptr<UI_GADGET_INPUTBOX> ui_add_gadget_inputbox(UI_DIALOG &dlg, short x, short y, const char (&text)[L]) |
| 334 |
{ |
| 335 |
static_assert(SL <= L, "SL too large"); |
| 336 |
return ui_add_gadget_inputbox(dlg, x, y, L, SL, text); |
| 337 |
} |
| 338 |
|
| 339 |
extern void ui_inputbox_set_text(UI_GADGET_INPUTBOX *inputbox, const char *text); |
| 340 |
|
| 341 |
[[nodiscard]] |
| 342 |
std::unique_ptr<UI_GADGET_USERBOX> ui_add_gadget_userbox(UI_DIALOG &dlg, short x, short y, short w, short h); |
| 343 |
|
| 344 |
int MenuX( int x, int y, int NumButtons, const char *const text[] ); |
| 345 |
|
| 346 |
#if DXX_USE_EDITOR |
| 347 |
int ui_get_filename(std::array<char, PATH_MAX> &filename, const char *filespec, const char *message); |
| 348 |
#endif |
| 349 |
|
| 350 |
|
| 351 |
void * ui_malloc( int size ); |
| 352 |
void ui_free( void * buffer ); |
| 353 |
|
| 354 |
#define UI_RECORD_MOUSE 1 |
| 355 |
#define UI_RECORD_KEYS 2 |
| 356 |
#define UI_STATUS_NORMAL 0 |
| 357 |
#define UI_STATUS_RECORDING 1 |
| 358 |
#define UI_STATUS_PLAYING 2 |
| 359 |
#define UI_STATUS_FASTPLAY 3 |
| 360 |
|
| 361 |
int ui_get_file( char * filename, const char * Filespec ); |
| 362 |
|
| 363 |
[[nodiscard]] |
| 364 |
std::unique_ptr<UI_GADGET_ICON> ui_add_gadget_icon(UI_DIALOG &dlg, const char *text, short x, short y, short w, short h, int k,int (*f)()); |
| 365 |
|
| 366 |
int DecodeKeyText( const char * text ); |
| 367 |
void GetKeyDescription(char (&text)[100], uint_fast32_t keypress); |
| 368 |
|
| 369 |
int menubar_init(grs_canvas &canvas, const char * filename ); |
| 370 |
extern void menubar_close(); |
| 371 |
extern void menubar_hide(); |
| 372 |
extern void menubar_show(); |
| 373 |
|
| 374 |
void ui_pad_init(); |
| 375 |
void ui_pad_close(); |
| 376 |
void ui_pad_activate(UI_DIALOG &dlg, uint_fast32_t x, uint_fast32_t y); |
| 377 |
void ui_pad_deactivate(); |
| 378 |
void ui_pad_goto(int n); |
| 379 |
void ui_pad_goto_next(); |
| 380 |
void ui_pad_goto_prev(); |
| 381 |
int ui_pad_read( int n, const char * filename ); |
| 382 |
int ui_pad_get_current(); |
| 383 |
void ui_pad_draw(UI_DIALOG *dlg, int x, int y); |
| 384 |
|
| 385 |
void ui_barbox_open( const char * text, int length ); |
| 386 |
void ui_barbox_update( int position ); |
| 387 |
void ui_barbox_close(); |
| 388 |
|
| 389 |
extern int ui_button_any_drawn; |
| 390 |
|
| 391 |
} |
| 392 |
|
| 393 |
#endif |