author | dominik |
Mon, 16 Aug 2004 13:09:52 +0000 | |
changeset 62 | 2bdd81b8adcc |
parent 0 | 29654efe3188 |
child 68 | 4051f3c8efa2 |
permissions | -rw-r--r-- |
0 | 1 |
#ifndef WINDOW_H |
2 |
#define WINDOW_H |
|
3 |
||
4 |
typedef union WindowEvent WindowEvent; |
|
5 |
||
6 |
//typedef void WindowProc(Window *w, int event, int wparam, long lparam); |
|
7 |
||
8 |
typedef void WindowProc(Window *w, WindowEvent *e); |
|
9 |
||
10 |
typedef struct Widget { |
|
11 |
byte type; |
|
12 |
byte color; |
|
13 |
uint16 left, right, top, bottom; |
|
14 |
uint16 unkA; |
|
15 |
uint16 tooltips; |
|
16 |
} Widget; |
|
17 |
||
18 |
union WindowEvent { |
|
19 |
byte event; |
|
20 |
struct { |
|
21 |
byte event; |
|
22 |
Point pt; |
|
23 |
int widget; |
|
24 |
} click; |
|
25 |
||
26 |
struct { |
|
27 |
byte event; |
|
28 |
Point pt; |
|
29 |
uint tile; |
|
30 |
uint starttile; |
|
31 |
int userdata; |
|
32 |
} place; |
|
33 |
||
34 |
struct { |
|
35 |
byte event; |
|
36 |
Point pt; |
|
37 |
int widget; |
|
38 |
} dragdrop; |
|
39 |
||
40 |
struct { |
|
41 |
byte event; |
|
42 |
byte *str; |
|
43 |
} edittext; |
|
44 |
||
45 |
struct { |
|
46 |
byte event; |
|
47 |
Point pt; |
|
48 |
} popupmenu; |
|
49 |
||
50 |
struct { |
|
51 |
byte event; |
|
52 |
int button; |
|
53 |
int index; |
|
54 |
} dropdown; |
|
55 |
||
56 |
struct { |
|
57 |
byte event; |
|
58 |
bool cont; // continue the search? (default true) |
|
59 |
byte ascii; // 8-bit ASCII-value of the key |
|
60 |
uint16 keycode;// untranslated key (including shift-state) |
|
61 |
} keypress; |
|
62 |
}; |
|
63 |
||
64 |
enum WindowKeyCodes { |
|
65 |
WKC_SHIFT = 0x8000, |
|
66 |
WKC_CTRL = 0x4000, |
|
67 |
WKC_ALT = 0x2000, |
|
68 |
WKC_META = 0x1000, |
|
69 |
||
70 |
// Special ones |
|
71 |
WKC_NONE = 0, |
|
72 |
WKC_ESC=1, |
|
73 |
WKC_BACKSPACE = 2, |
|
74 |
WKC_INSERT = 3, |
|
75 |
WKC_DELETE = 4, |
|
76 |
||
77 |
WKC_PAGEUP = 5, |
|
78 |
WKC_PAGEDOWN = 6, |
|
79 |
WKC_END = 7, |
|
80 |
WKC_HOME = 8, |
|
81 |
||
82 |
// Arrow keys |
|
83 |
WKC_LEFT = 9, |
|
84 |
WKC_UP = 10, |
|
85 |
WKC_RIGHT = 11, |
|
86 |
WKC_DOWN = 12, |
|
87 |
||
88 |
// Return & tab |
|
89 |
WKC_RETURN = 13, |
|
90 |
WKC_TAB = 14, |
|
91 |
||
92 |
// Numerical keyboard |
|
93 |
WKC_NUM_0 = 16, |
|
94 |
WKC_NUM_1 = 17, |
|
95 |
WKC_NUM_2 = 18, |
|
96 |
WKC_NUM_3 = 19, |
|
97 |
WKC_NUM_4 = 20, |
|
98 |
WKC_NUM_5 = 21, |
|
99 |
WKC_NUM_6 = 22, |
|
100 |
WKC_NUM_7 = 23, |
|
101 |
WKC_NUM_8 = 24, |
|
102 |
WKC_NUM_9 = 25, |
|
103 |
WKC_NUM_DIV = 26, |
|
104 |
WKC_NUM_MUL = 27, |
|
105 |
WKC_NUM_MINUS = 28, |
|
106 |
WKC_NUM_PLUS = 29, |
|
107 |
WKC_NUM_ENTER = 30, |
|
108 |
WKC_NUM_DECIMAL = 31, |
|
109 |
||
110 |
// Space |
|
111 |
WKC_SPACE = 32, |
|
112 |
||
113 |
// Function keys |
|
114 |
WKC_F1 = 33, |
|
115 |
WKC_F2 = 34, |
|
116 |
WKC_F3 = 35, |
|
117 |
WKC_F4 = 36, |
|
118 |
WKC_F5 = 37, |
|
119 |
WKC_F6 = 38, |
|
120 |
WKC_F7 = 39, |
|
121 |
WKC_F8 = 40, |
|
122 |
WKC_F9 = 41, |
|
123 |
WKC_F10 = 42, |
|
124 |
WKC_F11 = 43, |
|
125 |
WKC_F12 = 44, |
|
126 |
||
127 |
// Required for french keyboard |
|
128 |
WKC_AMPERSAND = 45, |
|
129 |
||
130 |
// 0-9 are mapped to 48-57 |
|
131 |
// A-Z are mapped to 65-90 |
|
132 |
// a-z are mapped to 97-122 |
|
133 |
||
134 |
||
135 |
//WKC_UNKNOWN = 0xFF, |
|
136 |
||
137 |
}; |
|
138 |
||
139 |
typedef struct WindowDesc { |
|
140 |
int16 left, top, width, height; |
|
141 |
byte cls; |
|
142 |
byte parent_cls; |
|
143 |
uint32 flags; |
|
144 |
const Widget *widgets; |
|
145 |
WindowProc *proc; |
|
146 |
} WindowDesc; |
|
147 |
||
148 |
enum { |
|
149 |
WDF_STD_TOOLTIPS = 1, /* use standard routine when displaying tooltips */ |
|
150 |
WDF_DEF_WIDGET = 2, /* default widget control for some widgets in the on click event */ |
|
151 |
WDF_STD_BTN = 4, /* default handling for close and drag widgets (widget no 0 and 1) */ |
|
152 |
WDF_RESTORE_DPARAM = 8, /* when drawing widgets, restore the dparam so all widgets recieve the same set of them */ |
|
153 |
WDF_UNCLICK_BUTTONS=16, /* Unclick buttons when the window event times out */ |
|
154 |
}; |
|
155 |
||
156 |
/* can be used as x or y coordinates to cause a specific placement */ |
|
157 |
enum { |
|
158 |
WDP_AUTO = -1, |
|
159 |
WDP_CENTER = -2, |
|
160 |
}; |
|
161 |
||
162 |
#define WP(ptr,str) (*(str*)(ptr)->custom) |
|
163 |
||
164 |
typedef struct { |
|
62
2bdd81b8adcc
(svn r63) Fix: [ 1009385 ] Too many save games prevented loading
dominik
parents:
0
diff
changeset
|
165 |
uint16 count, cap, pos; |
0 | 166 |
} Scrollbar; |
167 |
||
168 |
struct Window { |
|
169 |
uint16 flags4; |
|
170 |
WindowClass window_class; |
|
171 |
WindowNumber window_number; |
|
172 |
||
173 |
int left,top; |
|
174 |
int width,height; |
|
175 |
||
176 |
Scrollbar hscroll, vscroll; |
|
177 |
||
178 |
byte caption_color; |
|
179 |
||
180 |
uint32 click_state, disabled_state, hidden_state; |
|
181 |
WindowProc *wndproc; |
|
182 |
ViewPort *viewport; |
|
183 |
const Widget *widget; |
|
184 |
//const WindowDesc *desc; |
|
185 |
uint32 desc_flags; |
|
186 |
||
187 |
byte custom[16]; |
|
188 |
}; |
|
189 |
||
190 |
typedef struct { |
|
191 |
byte item_count; /* follow_vehicle */ |
|
192 |
byte sel_index; /* scrollpos_x */ |
|
193 |
byte main_button; /* scrollpos_y */ |
|
194 |
byte action_id; |
|
195 |
StringID string_id; /* unk30 */ |
|
196 |
uint16 checked_items; /* unk32 */ |
|
197 |
} menu_d; |
|
198 |
||
199 |
typedef struct { |
|
200 |
int16 data_1, data_2, data_3; |
|
201 |
int16 data_4, data_5; |
|
202 |
bool close; /* scrollpos_y */ |
|
203 |
byte byte_1; |
|
204 |
} def_d; |
|
205 |
||
206 |
typedef struct { |
|
207 |
void *data; |
|
208 |
} void_d; |
|
209 |
||
210 |
typedef struct { |
|
211 |
uint16 base; /* follow_vehicle */ |
|
212 |
uint16 count;/* scrollpos_x */ |
|
213 |
} tree_d; |
|
214 |
||
215 |
typedef struct { |
|
216 |
byte refresh_counter; /* follow_vehicle */ |
|
217 |
} plstations_d; |
|
218 |
||
219 |
typedef struct { |
|
220 |
StringID string_id; |
|
221 |
} tooltips_d; |
|
222 |
||
223 |
typedef struct { |
|
224 |
byte railtype; |
|
225 |
byte sel_index; |
|
226 |
int16 sel_engine; |
|
227 |
int16 rename_engine; |
|
228 |
} buildtrain_d; |
|
229 |
||
230 |
typedef struct { |
|
231 |
VehicleID sel; |
|
232 |
} traindepot_d; |
|
233 |
||
234 |
typedef struct { |
|
235 |
int sel; |
|
236 |
} order_d; |
|
237 |
||
238 |
typedef struct { |
|
239 |
byte tab; |
|
240 |
} traindetails_d; |
|
241 |
||
242 |
typedef struct { |
|
243 |
int16 scroll_x, scroll_y, subscroll; |
|
244 |
} smallmap_d; |
|
245 |
||
246 |
typedef struct { |
|
247 |
uint32 face; |
|
248 |
byte gender; |
|
249 |
} facesel_d; |
|
250 |
||
251 |
typedef struct { |
|
252 |
StringID caption; |
|
253 |
bool caret; |
|
254 |
WindowClass wnd_class; |
|
255 |
WindowNumber wnd_num; |
|
256 |
uint16 maxlen, maxwidth; |
|
257 |
byte *buf; |
|
258 |
} querystr_d; |
|
259 |
||
260 |
typedef struct { |
|
261 |
int sel; |
|
262 |
byte cargo; |
|
263 |
} refit_d; |
|
264 |
||
265 |
typedef struct { |
|
266 |
uint16 follow_vehicle; |
|
267 |
int16 scrollpos_x, scrollpos_y; |
|
268 |
} vp_d; |
|
269 |
||
270 |
typedef struct { |
|
271 |
uint16 follow_vehicle; |
|
272 |
int16 scrollpos_x, scrollpos_y; |
|
273 |
NewsItem *ni; |
|
274 |
} news_d; |
|
275 |
||
276 |
enum WindowEvents { |
|
277 |
WE_CLICK = 0, |
|
278 |
WE_PAINT = 1, |
|
279 |
WE_MOUSELOOP = 2, |
|
280 |
WE_TICK = 3, |
|
281 |
WE_4 = 4, |
|
282 |
WE_TIMEOUT = 5, |
|
283 |
WE_PLACE_OBJ = 6, |
|
284 |
WE_ABORT_PLACE_OBJ = 7, |
|
285 |
WE_DESTROY = 8, |
|
286 |
WE_ON_EDIT_TEXT = 9, |
|
287 |
WE_POPUPMENU_SELECT = 10, |
|
288 |
WE_POPUPMENU_OVER = 11, |
|
289 |
WE_DRAGDROP = 12, |
|
290 |
WE_PLACE_DRAG = 13, |
|
291 |
WE_PLACE_MOUSEUP = 14, |
|
292 |
WE_PLACE_PRESIZE = 15, |
|
293 |
WE_DROPDOWN_SELECT = 16, |
|
294 |
WE_RCLICK = 17, |
|
295 |
WE_KEYPRESS = 18, |
|
296 |
}; |
|
297 |
||
298 |
||
299 |
/****************** THESE ARE NOT WIDGET TYPES!!!!! *******************/ |
|
300 |
enum WindowWidgetBehaviours { |
|
301 |
WWB_PUSHBUTTON = 1 << 5, |
|
302 |
WWB_NODISBUTTON = 2 << 5, |
|
303 |
}; |
|
304 |
||
305 |
||
306 |
enum WindowWidgetTypes { |
|
307 |
WWT_EMPTY = 0, |
|
308 |
||
309 |
WWT_IMGBTN = 1, /* button with image */ |
|
310 |
WWT_PANEL = WWT_IMGBTN, |
|
311 |
WWT_PANEL_2 = 2,/* button with diff image when clicked */ |
|
312 |
||
313 |
WWT_TEXTBTN = 3,/* button with text */ |
|
314 |
WWT_CLOSEBOX = WWT_TEXTBTN, |
|
315 |
WWT_4 = 4, /* button with diff text when clicked */ |
|
316 |
WWT_5 = 5, /* label */ |
|
317 |
WWT_6 = 6, /* combo box text area */ |
|
318 |
WWT_MATRIX = 7, |
|
319 |
WWT_SCROLLBAR = 8, |
|
320 |
WWT_FRAME = 9, /* frame */ |
|
321 |
WWT_CAPTION = 10, |
|
322 |
||
323 |
WWT_HSCROLLBAR = 11, |
|
324 |
WWT_LAST = 12, |
|
325 |
||
326 |
WWT_MASK = 31, |
|
327 |
||
328 |
WWT_PUSHTXTBTN = WWT_TEXTBTN | WWB_PUSHBUTTON, |
|
329 |
WWT_PUSHIMGBTN = WWT_IMGBTN | WWB_PUSHBUTTON, |
|
330 |
WWT_NODISTXTBTN = WWT_TEXTBTN | WWB_NODISBUTTON, |
|
331 |
}; |
|
332 |
||
333 |
enum WindowFlags { |
|
334 |
WF_TIMEOUT_SHL = 0, |
|
335 |
WF_TIMEOUT_MASK = 7, |
|
336 |
WF_DRAGGING = 1 << 3, |
|
337 |
WF_SCROLL_UP = 1 << 4, |
|
338 |
WF_SCROLL_DOWN = 1 << 5, |
|
339 |
WF_SCROLL_MIDDLE = 1 << 6, |
|
340 |
WF_HSCROLL = 1 << 7, |
|
341 |
WF_SIZING = 1 << 8, |
|
342 |
||
343 |
WF_DISABLE_VP_SCROLL = 1 << 10, |
|
344 |
||
345 |
WF_WHITE_BORDER_ONE = 1 << 11, |
|
346 |
WF_WHITE_BORDER_MASK = 3 << 11, |
|
347 |
}; |
|
348 |
||
349 |
||
350 |
void DispatchLeftClickEvent(Window *w, int x, int y); |
|
351 |
void DispatchRightClickEvent(Window *w, int x, int y); |
|
352 |
void DispatchMouseWheelEvent(Window *w, int wheel); |
|
353 |
||
354 |
/* window.c */ |
|
355 |
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom); |
|
356 |
void CallWindowEventNP(Window *w, int event); |
|
357 |
void CallWindowTickEvent(); |
|
358 |
void DrawDirtyBlocks(); |
|
359 |
void SetDirtyBlocks(int left, int top, int right, int bottom); |
|
360 |
void SetWindowDirty(Window *w); |
|
361 |
||
362 |
Window *FindWindowById(WindowClass cls, WindowNumber number); |
|
363 |
void DeleteWindow(Window *w); |
|
364 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number); |
|
365 |
Window *BringWindowToFront(Window *w); |
|
366 |
Window *StartWindowDrag(Window *w); |
|
367 |
Window *StartWindowSizing(Window *w); |
|
368 |
Window *FindWindowFromPt(int x, int y); |
|
369 |
||
370 |
Window *AllocateWindow( |
|
371 |
int x, |
|
372 |
int y, |
|
373 |
int width, |
|
374 |
int height, |
|
375 |
WindowProc *proc, |
|
376 |
WindowClass cls, |
|
377 |
const Widget *widget); |
|
378 |
||
379 |
Window *AllocateWindowDesc(const WindowDesc *desc); |
|
380 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int value); |
|
381 |
||
382 |
Window *AllocateWindowAutoPlace( |
|
383 |
int width, |
|
384 |
int height, |
|
385 |
WindowProc *proc, |
|
386 |
WindowClass cls, |
|
387 |
const Widget *widget); |
|
388 |
||
389 |
Window *AllocateWindowAutoPlace2( |
|
390 |
WindowClass exist_class, |
|
391 |
WindowNumber exist_num, |
|
392 |
int width, |
|
393 |
int height, |
|
394 |
WindowProc *proc, |
|
395 |
WindowClass cls, |
|
396 |
const Widget *widget); |
|
397 |
||
398 |
void DrawWindowViewport(Window *w); |
|
399 |
||
400 |
void InitWindowSystem(); |
|
401 |
int GetMenuItemIndex(Window *w, int x, int y); |
|
402 |
void MouseLoop(); |
|
403 |
void UpdateWindows(); |
|
404 |
void InvalidateWidget(Window *w, byte widget_index); |
|
405 |
||
406 |
void GuiShowTooltips(uint16 string_id); |
|
407 |
||
408 |
void UnclickWindowButtons(Window *w); |
|
409 |
void UnclickSomeWindowButtons(Window *w, uint32 mask); |
|
410 |
void RelocateAllWindows(int neww, int newh); |
|
411 |
||
412 |
/* widget.c */ |
|
413 |
int GetWidgetFromPos(Window *w, int x, int y); |
|
414 |
void DrawWindowWidgets(Window *w); |
|
415 |
||
416 |
void HandleButtonClick(Window *w, byte widget); |
|
417 |
||
418 |
Window *GetCallbackWnd(); |
|
419 |
void DeleteNonVitalWindows(); |
|
420 |
||
421 |
/* window.c */ |
|
422 |
VARDEF Window _windows[20]; |
|
423 |
VARDEF Window *_last_window; |
|
424 |
||
425 |
VARDEF Point _cursorpos_drag_start; |
|
426 |
||
427 |
VARDEF bool _left_button_down; |
|
428 |
VARDEF bool _left_button_clicked; |
|
429 |
||
430 |
VARDEF bool _right_button_down; |
|
431 |
VARDEF bool _right_button_clicked; |
|
432 |
||
433 |
VARDEF int _alloc_wnd_parent_num; |
|
434 |
||
435 |
VARDEF int _scrollbar_start_pos; |
|
436 |
VARDEF int _scrollbar_size; |
|
437 |
VARDEF bool _demo_mode; |
|
438 |
VARDEF byte _scroller_click_timeout; |
|
439 |
||
440 |
VARDEF bool _dragging_window; |
|
441 |
VARDEF bool _scrolling_scrollbar; |
|
442 |
VARDEF bool _scrolling_viewport; |
|
443 |
VARDEF bool _popup_menu_active; |
|
444 |
//VARDEF bool _dragdrop_active; |
|
445 |
||
446 |
VARDEF Point _fix_mouse_at; |
|
447 |
||
448 |
VARDEF byte _special_mouse_mode; |
|
449 |
enum SpecialMouseMode { |
|
450 |
WSM_NONE = 0, |
|
451 |
WSM_DRAGDROP = 1, |
|
452 |
WSM_SIZING = 2, |
|
453 |
WSM_PRESIZE = 3, |
|
454 |
}; |
|
455 |
||
456 |
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y); |
|
457 |
||
458 |
#endif /* WINDOW_H */ |