maug
Quick and dirty C mini-augmentation library.
Loading...
Searching...
No Matches
retrodlg.h
Go to the documentation of this file.
1
2#ifndef RETRODLG_H
3#define RETRODLG_H
4
5#ifndef RETROWIN_NO_DLG
6
16
17#ifndef RETRODLG_TRACE_LVL
18# define RETRODLG_TRACE_LVL 0
19#endif /* !RETRODLG_TRACE_LVL */
20
21#ifndef RETRODLG_IDC_CHAT_LABEL
22# define RETRODLG_IDC_CHAT_LABEL 100
23#endif /* !RETRODLG_IDC_CHAT_LABEL */
24
25#ifndef RETRODLG_IDC_CHAT_PORTRAIT
26# define RETRODLG_IDC_CHAT_PORTRAIT 200
27#endif /* !RETRODLG_IDC_CHAT_PORTRAIT */
28
29MERROR_RETVAL retrodlg_chat_update(
30 const maug_path portrait_path, const char* msg, size_t msg_sz,
31 size_t chat_idc, struct MDATA_VECTOR* win_stack );
32
33MERROR_RETVAL retrodlg_chat_show_ui(
36 const maug_path font_path, size_t chat_idc, uint8_t win_flags,
37 struct MDATA_VECTOR* win_stack );
38
39#ifdef RETRODLG_C
40
41MERROR_RETVAL retrodlg_chat_update(
42 const maug_path portrait_path, const char* msg, size_t msg_sz,
43 size_t chat_idc, struct MDATA_VECTOR* win_stack
44) {
45 MERROR_RETVAL retval = MERROR_OK;
46 struct RETROWIN* win = NULL;
47 ssize_t win_idx = -1;
48
49 win_idx = retrowin_get_by_idc( chat_idc, win_stack );
50 if( 0 > win_idx ) {
51 /* Need to open chat window first! */
52 error_printf( "chat window not currently open!" );
53 retval = MERROR_GUI;
54 goto cleanup;
55 }
56
57#if RETRODLG_TRACE_LVL > 0
58 debug_printf( RETRODLG_TRACE_LVL,
59 "portrait %s: say %s", portrait_path, msg );
60#endif /* RETRODLG_TRACE_LVL */
61
62 mdata_vector_lock( win_stack );
63 win = mdata_vector_get( win_stack, win_idx, struct RETROWIN );
64 assert( NULL != win );
65 retrowin_lock_gui( win );
66
67 /* Update the GUI. */
68 if( NULL != msg && 0 < msg_sz ) {
69 retrogui_set_ctl_text(
70 win->gui_p, RETRODLG_IDC_CHAT_LABEL, msg_sz, "%s", msg );
71 } else {
72 retrogui_set_ctl_text( win->gui_p, RETRODLG_IDC_CHAT_LABEL, 0, NULL );
73 }
74
75 if( NULL != msg && 0 < msg_sz ) {
77 win->gui_p, RETRODLG_IDC_CHAT_PORTRAIT, portrait_path, 0 );
78 } else {
80 win->gui_p, RETRODLG_IDC_CHAT_PORTRAIT, NULL, 0 );
81 }
82
83 retrowin_unlock_gui( win );
84
85cleanup:
86
87 if( mdata_vector_is_locked( win_stack ) ) {
88 mdata_vector_unlock( win_stack );
89 }
90
91 return retval;
92}
93
94/* === */
95
96MERROR_RETVAL retrodlg_chat_show_ui(
99 const maug_path font_path, size_t chat_idc, uint8_t win_flags,
100 struct MDATA_VECTOR* win_stack
101) {
102 MERROR_RETVAL retval = MERROR_OK;
103 union RETROGUI_CTL ctl;
104 struct RETROWIN* win = NULL;
105 ssize_t chat_win = -1;
106
107 chat_win = retrowin_push_win(
108 NULL, /* This window should create and manage its own GUI. */
109 win_stack, chat_idc, font_path,
110 x, y, w, h, win_flags );
111 if( 0 > chat_win ) {
112 retval = merror_sz_to_retval( chat_win );
113 goto cleanup;
114 }
115
116#if RETRODLG_TRACE_LVL < 0
117 debug_printf( RETRODLG_TRACE_LVL,
118 "chat window is now idx: " SSIZE_T_FMT, chat_win );
119#endif /* RETRODLG_TRACE_LVL */
120
121 mdata_vector_lock( win_stack );
122 win = mdata_vector_get( win_stack, chat_win, struct RETROWIN );
123 assert( NULL != win );
124 retrowin_lock_gui( win );
125
126 retrogui_init_ctl(
127 &ctl, RETROGUI_CTL_TYPE_LABEL, RETRODLG_IDC_CHAT_LABEL );
128
129 ctl.base.x = 32;
130 ctl.base.y = 2;
131 ctl.base.w = w - 32;
132 ctl.base.h = 20;
133 ctl.base.fg_color = RETROFLAT_COLOR_WHITE;
134 ctl.LABEL.label = "";
135 ctl.LABEL.label_sz = 0;
136 ctl.LABEL.flags = RETROGUI_LABEL_FLAG_SHOWINC;
137
138 retval = retrogui_push_ctl( win->gui_p, &ctl );
139 maug_cleanup_if_not_ok();
140
141 /* Portrait */
142
143 retrogui_init_ctl(
144 &ctl, RETROGUI_CTL_TYPE_IMAGE, RETRODLG_IDC_CHAT_PORTRAIT );
145
146 ctl.base.x = 8;
147 ctl.base.y = 8;
148 ctl.base.w = RETROFLAT_TILE_W;
149 ctl.base.h = RETROFLAT_TILE_H;
150
151 retval = retrogui_push_ctl( win->gui_p, &ctl );
152 maug_cleanup_if_not_ok();
153
154 retrowin_unlock_gui( win );
155
156cleanup:
157
158 if( mdata_vector_is_locked( win_stack ) ) {
159 mdata_vector_unlock( win_stack );
160 }
161
162 return retval;
163}
164
165#endif /* RETRODLG_C */
166 /* maug_retrodlg */
168 /* maug_retroflt */
170
171#endif /* !RETROWIN_NO_DLG */
172
173#endif /* !RETRODLG_H */
174
uint16_t MERROR_RETVAL
Return type indicating function returns a value from this list.
Definition merror.h:28
char maug_path[MAUG_PATH_SZ_MAX]
Path/name used to load an asset from disk or access other files.
Definition mfile.h:136
size_t retroflat_pxxy_t
Type used for surface pixel coordinates.
Definition retroflt.h:875
MERROR_RETVAL retrogui_set_ctl_image(struct RETROGUI *gui, retrogui_idc_t idc, const maug_path path, uint8_t flags)
Set the image displayed by an IMAGE-type RETROGUI_CTL.
ssize_t retrowin_push_win(struct RETROGUI *gui, struct MDATA_VECTOR *win_stack, size_t idc, const char *font_filename, size_t x, size_t y, size_t w, size_t h, uint8_t flags)
Create a new window on the given win_stack.
A vector of uniformly-sized objects, stored contiguously.
Definition mdata.h:108
Definition retrowin.h:95
Definition retrogui.h:450