0
|
1 |
#include "stdafx.h"
|
|
2 |
#include "ttd.h"
|
|
3 |
#include "window.h"
|
|
4 |
#include "gfx.h"
|
|
5 |
#include "viewport.h"
|
|
6 |
|
|
7 |
void HandleButtonClick(Window *w, byte widget)
|
|
8 |
{
|
|
9 |
w->click_state |= (1 << widget);
|
|
10 |
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
11 |
InvalidateWidget(w, widget);
|
|
12 |
}
|
|
13 |
|
|
14 |
void DispatchLeftClickEvent(Window *w, int x, int y) {
|
|
15 |
WindowEvent e;
|
|
16 |
const Widget *wi;
|
|
17 |
|
|
18 |
e.click.pt.x = x;
|
|
19 |
e.click.pt.y = y;
|
|
20 |
e.event = WE_CLICK;
|
|
21 |
|
|
22 |
if (w->desc_flags & WDF_DEF_WIDGET) {
|
|
23 |
e.click.widget = GetWidgetFromPos(w, x, y);
|
|
24 |
if (e.click.widget < 0) return; /* exit if clicked outside of widgets */
|
|
25 |
|
|
26 |
wi = &w->widget[e.click.widget];
|
|
27 |
|
|
28 |
if (wi->type & 0xE0) {
|
|
29 |
/* special widget handling */
|
|
30 |
switch(wi->type) {
|
|
31 |
case WWT_IMGBTN | WWB_PUSHBUTTON:
|
|
32 |
case WWT_TEXTBTN | WWB_PUSHBUTTON:
|
|
33 |
if (HASBIT(w->disabled_state, e.click.widget))
|
|
34 |
return; /* don't allow click if disabled */
|
|
35 |
HandleButtonClick(w, e.click.widget);
|
|
36 |
break;
|
|
37 |
case WWT_NODISTXTBTN:
|
|
38 |
if (HASBIT(w->disabled_state, e.click.widget))
|
|
39 |
return; /* don't allow click if disabled */
|
|
40 |
break;
|
|
41 |
}
|
|
42 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_HSCROLLBAR) {
|
|
43 |
ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y);
|
|
44 |
}
|
|
45 |
|
|
46 |
w->wndproc(w, &e);
|
|
47 |
|
|
48 |
if (w->desc_flags & WDF_STD_BTN) {
|
|
49 |
if (e.click.widget == 0) DeleteWindow(w);
|
|
50 |
else {
|
|
51 |
if (e.click.widget == 1) {
|
|
52 |
if (_ctrl_pressed)
|
|
53 |
StartWindowSizing(w);
|
|
54 |
else
|
|
55 |
StartWindowDrag(w);
|
|
56 |
}
|
|
57 |
}
|
|
58 |
}
|
|
59 |
} else {
|
|
60 |
w->wndproc(w, &e);
|
|
61 |
}
|
|
62 |
}
|
|
63 |
|
|
64 |
void DispatchRightClickEvent(Window *w, int x, int y) {
|
|
65 |
WindowEvent e;
|
|
66 |
|
|
67 |
/* default tooltips handler? */
|
|
68 |
if (w->desc_flags & WDF_STD_TOOLTIPS) {
|
|
69 |
e.click.widget = GetWidgetFromPos(w, x, y);
|
|
70 |
if (e.click.widget < 0)
|
|
71 |
return; /* exit if clicked outside of widgets */
|
|
72 |
|
|
73 |
if (w->widget[e.click.widget].tooltips != 0) {
|
|
74 |
GuiShowTooltips(w->widget[e.click.widget].tooltips);
|
|
75 |
return;
|
|
76 |
}
|
|
77 |
}
|
|
78 |
|
|
79 |
e.event = WE_RCLICK;
|
|
80 |
e.click.pt.x = x;
|
|
81 |
e.click.pt.y = y;
|
|
82 |
w->wndproc(w, &e);
|
|
83 |
}
|
|
84 |
|
|
85 |
|
|
86 |
void DispatchMouseWheelEvent(Window *w, int wheel)
|
|
87 |
{
|
|
88 |
|
|
89 |
if (w->vscroll.count) {
|
|
90 |
int pos = clamp(w->vscroll.pos + wheel, 0, w->vscroll.count - w->vscroll.cap);
|
|
91 |
if (pos != w->vscroll.pos) {
|
|
92 |
w->vscroll.pos = pos;
|
|
93 |
SetWindowDirty(w);
|
|
94 |
}
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
|
|
99 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
|
|
100 |
{
|
|
101 |
Window *w;
|
|
102 |
DrawPixelInfo bk;
|
|
103 |
_cur_dpi = &bk;
|
|
104 |
|
|
105 |
for(w=_windows; w!=_last_window; w++) {
|
|
106 |
if (right > w->left &&
|
|
107 |
bottom > w->top &&
|
|
108 |
left < w->left + w->width &&
|
|
109 |
top < w->top + w->height) {
|
|
110 |
DrawOverlappedWindow(w, left, top, right, bottom);
|
|
111 |
}
|
|
112 |
}
|
|
113 |
}
|
|
114 |
|
|
115 |
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom)
|
|
116 |
{
|
|
117 |
Window *v = w;
|
|
118 |
int x;
|
|
119 |
|
|
120 |
while (++v != _last_window) {
|
|
121 |
if (right > v->left &&
|
|
122 |
bottom > v->top &&
|
|
123 |
left < v->left + v->width &&
|
|
124 |
top < v->top + v->height) {
|
|
125 |
|
|
126 |
if (left < (x=v->left)) {
|
|
127 |
DrawOverlappedWindow(w, left, top, x, bottom);
|
|
128 |
DrawOverlappedWindow(w, x, top, right, bottom);
|
|
129 |
return;
|
|
130 |
}
|
|
131 |
|
|
132 |
if (right > (x=v->left + v->width)) {
|
|
133 |
DrawOverlappedWindow(w, left, top, x, bottom);
|
|
134 |
DrawOverlappedWindow(w, x, top, right, bottom);
|
|
135 |
return;
|
|
136 |
}
|
|
137 |
|
|
138 |
if (top < (x=v->top)) {
|
|
139 |
DrawOverlappedWindow(w, left, top, right, x);
|
|
140 |
DrawOverlappedWindow(w, left, x, right, bottom);
|
|
141 |
return;
|
|
142 |
}
|
|
143 |
|
|
144 |
if (bottom > (x=v->top + v->height)) {
|
|
145 |
DrawOverlappedWindow(w, left, top, right, x);
|
|
146 |
DrawOverlappedWindow(w, left, x, right, bottom);
|
|
147 |
return;
|
|
148 |
}
|
|
149 |
|
|
150 |
return;
|
|
151 |
}
|
|
152 |
}
|
|
153 |
|
|
154 |
{
|
|
155 |
DrawPixelInfo *dp = _cur_dpi;
|
|
156 |
dp->width = right - left;
|
|
157 |
dp->height = bottom - top;
|
|
158 |
dp->left = left - w->left;
|
|
159 |
dp->top = top - w->top;
|
|
160 |
dp->pitch = _screen.pitch;
|
|
161 |
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left;
|
|
162 |
dp->zoom = 0;
|
|
163 |
CallWindowEventNP(w, WE_PAINT);
|
|
164 |
}
|
|
165 |
}
|
|
166 |
|
|
167 |
void CallWindowEventNP(Window *w, int event)
|
|
168 |
{
|
|
169 |
WindowEvent e;
|
|
170 |
e.event = event;
|
|
171 |
w->wndproc(w, &e);
|
|
172 |
}
|
|
173 |
|
|
174 |
void SetWindowDirty(Window *w)
|
|
175 |
{
|
|
176 |
if (w == NULL)
|
|
177 |
return;
|
|
178 |
|
|
179 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
|
|
180 |
}
|
|
181 |
|
|
182 |
void DeleteWindow(Window *w)
|
|
183 |
{
|
|
184 |
WindowClass wc;
|
|
185 |
WindowNumber wn;
|
|
186 |
ViewPort *vp;
|
|
187 |
Window *v;
|
|
188 |
int count;
|
|
189 |
|
|
190 |
if (w == NULL)
|
|
191 |
return;
|
|
192 |
|
|
193 |
if (_thd.place_mode != 0 && _thd.window_class == w->window_class && _thd.window_number == w->window_number) {
|
|
194 |
ResetObjectToPlace();
|
|
195 |
}
|
|
196 |
|
|
197 |
wc = w->window_class;
|
|
198 |
wn = w->window_number;
|
|
199 |
|
|
200 |
CallWindowEventNP(w, WE_DESTROY);
|
|
201 |
|
|
202 |
w = FindWindowById(wc, wn);
|
|
203 |
|
|
204 |
vp = w->viewport;
|
|
205 |
w->viewport = NULL;
|
|
206 |
if (vp != NULL) {
|
|
207 |
_active_viewports &= ~(1 << (vp - _viewports));
|
|
208 |
vp->width = 0;
|
|
209 |
}
|
|
210 |
|
|
211 |
SetWindowDirty(w);
|
|
212 |
|
|
213 |
v = --_last_window;
|
|
214 |
count = (byte*)v - (byte*)w;
|
|
215 |
memcpy(w, w + 1, count);
|
|
216 |
}
|
|
217 |
|
|
218 |
Window *FindWindowById(WindowClass cls, WindowNumber number)
|
|
219 |
{
|
|
220 |
Window *w;
|
|
221 |
|
|
222 |
for(w=_windows; w!=_last_window; w++) {
|
|
223 |
if (w->window_class == cls &&
|
|
224 |
w->window_number == number) {
|
|
225 |
return w;
|
|
226 |
}
|
|
227 |
}
|
|
228 |
|
|
229 |
return NULL;
|
|
230 |
}
|
|
231 |
|
|
232 |
void DeleteWindowById(WindowClass cls, WindowNumber number)
|
|
233 |
{
|
|
234 |
DeleteWindow(FindWindowById(cls, number));
|
|
235 |
}
|
|
236 |
|
|
237 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
|
|
238 |
{
|
|
239 |
Window *w = FindWindowById(cls, number);
|
|
240 |
|
|
241 |
if (w != NULL) {
|
|
242 |
w->flags4 |= WF_WHITE_BORDER_MASK;
|
|
243 |
SetWindowDirty(w);
|
|
244 |
BringWindowToFront(w);
|
|
245 |
}
|
|
246 |
|
|
247 |
return w;
|
|
248 |
}
|
|
249 |
|
|
250 |
Window *BringWindowToFront(Window *w)
|
|
251 |
{
|
|
252 |
Window *v;
|
|
253 |
|
|
254 |
v = _last_window;
|
|
255 |
do {
|
|
256 |
if (--v < _windows)
|
|
257 |
return w;
|
|
258 |
} while (v->window_class == WC_MAIN_TOOLBAR || v->window_class == WC_STATUS_BAR || v->window_class == WC_NEWS_WINDOW);
|
|
259 |
|
|
260 |
if (w == v)
|
|
261 |
return w;
|
|
262 |
|
|
263 |
assert(w < v);
|
|
264 |
|
|
265 |
do {
|
|
266 |
memswap(w, w+1, sizeof(Window));
|
|
267 |
w++;
|
|
268 |
} while (v != w);
|
|
269 |
|
|
270 |
SetWindowDirty(w);
|
|
271 |
|
|
272 |
return w;
|
|
273 |
}
|
|
274 |
|
|
275 |
Window *AllocateWindow(
|
|
276 |
int x,
|
|
277 |
int y,
|
|
278 |
int width,
|
|
279 |
int height,
|
|
280 |
WindowProc *proc,
|
|
281 |
WindowClass cls,
|
|
282 |
const Widget *widget)
|
|
283 |
{
|
|
284 |
Window *w;
|
|
285 |
|
|
286 |
restart:;
|
|
287 |
w = _last_window;
|
|
288 |
|
|
289 |
if (w >= endof(_windows)) {
|
|
290 |
for(w=_windows; ;w++) {
|
|
291 |
assert(w < _last_window);
|
|
292 |
|
|
293 |
if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_MAIN_TOOLBAR &&
|
|
294 |
w->window_class != WC_STATUS_BAR && w->window_class != WC_NEWS_WINDOW) {
|
|
295 |
|
|
296 |
DeleteWindow(w);
|
|
297 |
goto restart;
|
|
298 |
}
|
|
299 |
}
|
|
300 |
}
|
|
301 |
|
|
302 |
if (w != _windows && cls != WC_NEWS_WINDOW) {
|
|
303 |
Window *v;
|
|
304 |
|
|
305 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0);
|
|
306 |
if (v) {
|
|
307 |
memmove(v+1, v, (byte*)w - (byte*)v);
|
|
308 |
w = v;
|
|
309 |
}
|
|
310 |
|
|
311 |
v = FindWindowById(WC_STATUS_BAR, 0);
|
|
312 |
if (v) {
|
|
313 |
memmove(v+1, v, (byte*)w - (byte*)v);
|
|
314 |
w = v;
|
|
315 |
}
|
|
316 |
}
|
|
317 |
|
|
318 |
/* XXX: some more code here */
|
|
319 |
w->window_class = cls;
|
|
320 |
w->flags4 = WF_WHITE_BORDER_MASK;
|
|
321 |
w->caption_color = 0xFF;
|
|
322 |
w->window_number = 0;
|
|
323 |
w->left = x;
|
|
324 |
w->top = y;
|
|
325 |
w->width = width;
|
|
326 |
w->height = height;
|
|
327 |
w->viewport = NULL;
|
|
328 |
w->desc_flags = 0;
|
|
329 |
// w->landscape_assoc = 0xFFFF;
|
|
330 |
w->wndproc = proc;
|
|
331 |
w->click_state = 0;
|
|
332 |
w->disabled_state = 0;
|
|
333 |
w->hidden_state = 0;
|
|
334 |
// w->unk22 = 0xFFFF;
|
|
335 |
w->vscroll.pos = 0;
|
|
336 |
w->vscroll.count = 0;
|
|
337 |
w->hscroll.pos = 0;
|
|
338 |
w->hscroll.count = 0;
|
|
339 |
w->widget = widget;
|
|
340 |
|
|
341 |
((uint32*)w->custom)[0] = 0;
|
|
342 |
((uint32*)w->custom)[1] = 0;
|
|
343 |
((uint32*)w->custom)[2] = 0;
|
|
344 |
((uint32*)w->custom)[3] = 0;
|
|
345 |
|
|
346 |
|
|
347 |
_last_window++;
|
|
348 |
|
|
349 |
SetWindowDirty(w);
|
|
350 |
|
|
351 |
return w;
|
|
352 |
}
|
|
353 |
|
|
354 |
Window *AllocateWindowAutoPlace2(
|
|
355 |
WindowClass exist_class,
|
|
356 |
WindowNumber exist_num,
|
|
357 |
int width,
|
|
358 |
int height,
|
|
359 |
WindowProc *proc,
|
|
360 |
WindowClass cls,
|
|
361 |
const Widget *widget)
|
|
362 |
{
|
|
363 |
Window *w;
|
|
364 |
int x;
|
|
365 |
|
|
366 |
w = FindWindowById(exist_class, exist_num);
|
|
367 |
if (w == NULL || w->left >= (_screen.width-20) || w->left <= -60 || w->top >= (_screen.height-20)) {
|
|
368 |
return AllocateWindowAutoPlace(width,height,proc,cls,widget);
|
|
369 |
}
|
|
370 |
|
|
371 |
x = w->left;
|
|
372 |
if (x > _screen.width - width)
|
|
373 |
x = (_screen.width - width) - 20;
|
|
374 |
|
|
375 |
return AllocateWindow(x+10,w->top+10,width,height,proc,cls,widget);
|
|
376 |
}
|
|
377 |
|
|
378 |
|
|
379 |
typedef struct SizeRect {
|
|
380 |
int left,top,width,height;
|
|
381 |
} SizeRect;
|
|
382 |
|
|
383 |
|
|
384 |
static SizeRect _awap_r;
|
|
385 |
|
|
386 |
static bool IsGoodAutoPlace1(int left, int top)
|
|
387 |
{
|
|
388 |
int right,bottom;
|
|
389 |
Window *w;
|
|
390 |
|
|
391 |
_awap_r.left= left;
|
|
392 |
_awap_r.top = top;
|
|
393 |
right = _awap_r.width + left;
|
|
394 |
bottom = _awap_r.height + top;
|
|
395 |
|
|
396 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
|
|
397 |
return false;
|
|
398 |
|
|
399 |
// Make sure it is not obscured by any window.
|
|
400 |
for(w=_windows; w!=_last_window; w++) {
|
|
401 |
if (w->window_class == WC_MAIN_WINDOW)
|
|
402 |
continue;
|
|
403 |
|
|
404 |
if (right > w->left &&
|
|
405 |
w->left + w->width > left &&
|
|
406 |
bottom > w->top &&
|
|
407 |
w->top + w->height > top)
|
|
408 |
return false;
|
|
409 |
}
|
|
410 |
|
|
411 |
return true;
|
|
412 |
}
|
|
413 |
|
|
414 |
static bool IsGoodAutoPlace2(int left, int top)
|
|
415 |
{
|
|
416 |
int width,height;
|
|
417 |
Window *w;
|
|
418 |
|
|
419 |
_awap_r.left= left;
|
|
420 |
_awap_r.top = top;
|
|
421 |
width = _awap_r.width;
|
|
422 |
height = _awap_r.height;
|
|
423 |
|
|
424 |
if (left < -(width>>2) || left > _screen.width - (width>>1))
|
|
425 |
return false;
|
|
426 |
if (top < 22 || top > _screen.height - (height>>2))
|
|
427 |
return false;
|
|
428 |
|
|
429 |
// Make sure it is not obscured by any window.
|
|
430 |
for(w=_windows; w!=_last_window; w++) {
|
|
431 |
if (w->window_class == WC_MAIN_WINDOW)
|
|
432 |
continue;
|
|
433 |
|
|
434 |
if (left + width > w->left &&
|
|
435 |
w->left + w->width > left &&
|
|
436 |
top + height > w->top &&
|
|
437 |
w->top + w->height > top)
|
|
438 |
return false;
|
|
439 |
}
|
|
440 |
|
|
441 |
return true;
|
|
442 |
}
|
|
443 |
|
|
444 |
Point GetAutoPlacePosition(int width, int height) {
|
|
445 |
Window *w;
|
|
446 |
Point pt;
|
|
447 |
|
|
448 |
_awap_r.width = width;
|
|
449 |
_awap_r.height = height;
|
|
450 |
|
|
451 |
if (IsGoodAutoPlace1(0, 24)) goto ok_pos;
|
|
452 |
|
|
453 |
for(w=_windows; w!=_last_window; w++) {
|
|
454 |
if (w->window_class == WC_MAIN_WINDOW)
|
|
455 |
continue;
|
|
456 |
|
|
457 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos;
|
|
458 |
if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos;
|
|
459 |
if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos;
|
|
460 |
if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos;
|
|
461 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos;
|
|
462 |
if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos;
|
|
463 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos;
|
|
464 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos;
|
|
465 |
}
|
|
466 |
|
|
467 |
for(w=_windows; w!=_last_window; w++) {
|
|
468 |
if (w->window_class == WC_MAIN_WINDOW)
|
|
469 |
continue;
|
|
470 |
|
|
471 |
if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos;
|
|
472 |
if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos;
|
|
473 |
if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos;
|
|
474 |
if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos;
|
|
475 |
}
|
|
476 |
|
|
477 |
{
|
|
478 |
int left=0,top=24;
|
|
479 |
|
|
480 |
restart:;
|
|
481 |
for(w=_windows; w!=_last_window; w++) {
|
|
482 |
if (w->left == left && w->top == top) {
|
|
483 |
left += 5;
|
|
484 |
top += 5;
|
|
485 |
goto restart;
|
|
486 |
}
|
|
487 |
}
|
|
488 |
|
|
489 |
pt.x = left;
|
|
490 |
pt.y = top;
|
|
491 |
return pt;
|
|
492 |
}
|
|
493 |
|
|
494 |
ok_pos:;
|
|
495 |
pt.x = _awap_r.left;
|
|
496 |
pt.y = _awap_r.top;
|
|
497 |
return pt;
|
|
498 |
}
|
|
499 |
|
|
500 |
Window *AllocateWindowAutoPlace(
|
|
501 |
int width,
|
|
502 |
int height,
|
|
503 |
WindowProc *proc,
|
|
504 |
WindowClass cls,
|
|
505 |
const Widget *widget) {
|
|
506 |
|
|
507 |
Point pt = GetAutoPlacePosition(width, height);
|
|
508 |
return AllocateWindow(pt.x, pt.y, width, height, proc, cls, widget);
|
|
509 |
}
|
|
510 |
|
|
511 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int value)
|
|
512 |
{
|
|
513 |
Window *w;
|
|
514 |
|
|
515 |
if (BringWindowToFrontById(desc->cls, value))
|
|
516 |
return NULL;
|
|
517 |
w = AllocateWindowDesc(desc);
|
|
518 |
w->window_number = value;
|
|
519 |
return w;
|
|
520 |
}
|
|
521 |
|
|
522 |
Window *AllocateWindowDesc(const WindowDesc *desc)
|
|
523 |
{
|
|
524 |
Point pt;
|
|
525 |
Window *w;
|
|
526 |
|
|
527 |
if (desc->parent_cls != WC_MAIN_WINDOW &&
|
|
528 |
(w = FindWindowById(desc->parent_cls, _alloc_wnd_parent_num), _alloc_wnd_parent_num=0, w) != NULL &&
|
|
529 |
w->left < _screen.width-20 && w->left > -60 && w->top < _screen.height-20) {
|
|
530 |
pt.x = w->left + 10;
|
|
531 |
if (pt.x > _screen.width + 10 - desc->width)
|
|
532 |
pt.x = (_screen.width + 10 - desc->width) - 20;
|
|
533 |
pt.y = w->top + 10;
|
|
534 |
} else {
|
|
535 |
pt.x = desc->left;
|
|
536 |
pt.y = desc->top;
|
|
537 |
if (pt.x == WDP_AUTO) {
|
|
538 |
pt = GetAutoPlacePosition(desc->width, desc->height);
|
|
539 |
} else {
|
|
540 |
if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1;
|
|
541 |
if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1;
|
|
542 |
}
|
|
543 |
}
|
|
544 |
|
|
545 |
w = AllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets);
|
|
546 |
w->desc_flags = desc->flags;
|
|
547 |
return w;
|
|
548 |
}
|
|
549 |
|
|
550 |
Window *FindWindowFromPt(int x, int y)
|
|
551 |
{
|
|
552 |
Window *w;
|
|
553 |
|
|
554 |
for(w=_last_window; w != _windows;) {
|
|
555 |
--w;
|
|
556 |
if (IS_INSIDE_1D(x, w->left, w->width) &&
|
|
557 |
IS_INSIDE_1D(y, w->top, w->height))
|
|
558 |
return w;
|
|
559 |
}
|
|
560 |
|
|
561 |
return NULL;
|
|
562 |
}
|
|
563 |
|
|
564 |
|
|
565 |
void InitWindowSystem()
|
|
566 |
{
|
|
567 |
memset(&_windows, 0, sizeof(_windows));
|
|
568 |
_last_window = _windows;
|
|
569 |
memset(_viewports, 0, sizeof(_viewports));
|
|
570 |
_active_viewports = 0;
|
|
571 |
}
|
|
572 |
|
|
573 |
void DecreaseWindowCounters()
|
|
574 |
{
|
|
575 |
Window *w;
|
|
576 |
|
|
577 |
|
|
578 |
for(w=_last_window; w != _windows;) {
|
|
579 |
--w;
|
|
580 |
// Unclick scrollbar buttons if they are pressed.
|
|
581 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
|
|
582 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
|
|
583 |
SetWindowDirty(w);
|
|
584 |
}
|
|
585 |
CallWindowEventNP(w, WE_MOUSELOOP);
|
|
586 |
}
|
|
587 |
|
|
588 |
for(w=_last_window; w != _windows;) {
|
|
589 |
--w;
|
|
590 |
|
|
591 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) {
|
|
592 |
CallWindowEventNP(w, WE_TIMEOUT);
|
|
593 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS)
|
|
594 |
UnclickWindowButtons(w);
|
|
595 |
}
|
|
596 |
}
|
|
597 |
}
|
|
598 |
|
|
599 |
Window *GetCallbackWnd()
|
|
600 |
{
|
|
601 |
return FindWindowById(_thd.window_class, _thd.window_number);
|
|
602 |
}
|
|
603 |
|
|
604 |
void HandlePlacePresize()
|
|
605 |
{
|
|
606 |
Window *w;
|
|
607 |
WindowEvent e;
|
|
608 |
|
|
609 |
if (_special_mouse_mode != WSM_PRESIZE)
|
|
610 |
return;
|
|
611 |
|
|
612 |
if ((w = GetCallbackWnd()) == NULL)
|
|
613 |
return;
|
|
614 |
|
|
615 |
e.place.pt = GetTileBelowCursor();
|
|
616 |
if (e.place.pt.x == -1) {
|
|
617 |
_thd.selend.x = -1;
|
|
618 |
return;
|
|
619 |
}
|
|
620 |
e.place.tile = TILE_FROM_XY(e.place.pt.x, e.place.pt.y);
|
|
621 |
e.event = WE_PLACE_PRESIZE;
|
|
622 |
w->wndproc(w, &e);
|
|
623 |
}
|
|
624 |
|
|
625 |
bool HandleDragDrop()
|
|
626 |
{
|
|
627 |
Window *w;
|
|
628 |
WindowEvent e;
|
|
629 |
|
|
630 |
if (_special_mouse_mode != WSM_DRAGDROP)
|
|
631 |
return true;
|
|
632 |
|
|
633 |
if (_left_button_down)
|
|
634 |
return false;
|
|
635 |
|
|
636 |
w = GetCallbackWnd();
|
|
637 |
|
|
638 |
ResetObjectToPlace();
|
|
639 |
|
|
640 |
if (w) {
|
|
641 |
// send an event in client coordinates.
|
|
642 |
e.event = WE_DRAGDROP;
|
|
643 |
e.dragdrop.pt.x = _cursor.pos.x - w->left;
|
|
644 |
e.dragdrop.pt.y = _cursor.pos.y - w->top;
|
|
645 |
e.dragdrop.widget = GetWidgetFromPos(w, e.dragdrop.pt.x, e.dragdrop.pt.y);
|
|
646 |
w->wndproc(w, &e);
|
|
647 |
}
|
|
648 |
return false;
|
|
649 |
}
|
|
650 |
|
|
651 |
bool HandlePopupMenu()
|
|
652 |
{
|
|
653 |
Window *w;
|
|
654 |
WindowEvent e;
|
|
655 |
|
|
656 |
if (!_popup_menu_active)
|
|
657 |
return true;
|
|
658 |
|
|
659 |
w = FindWindowById(WC_TOOLBAR_MENU, 0);
|
|
660 |
if (w == NULL) {
|
|
661 |
_popup_menu_active = false;
|
|
662 |
return false;
|
|
663 |
}
|
|
664 |
|
|
665 |
if (_left_button_down) {
|
|
666 |
e.event = WE_POPUPMENU_OVER;
|
|
667 |
e.popupmenu.pt = _cursor.pos;
|
|
668 |
w->wndproc(w, &e);
|
|
669 |
} else {
|
|
670 |
_popup_menu_active = false;
|
|
671 |
e.event = WE_POPUPMENU_SELECT;
|
|
672 |
e.popupmenu.pt = _cursor.pos;
|
|
673 |
w->wndproc(w, &e);
|
|
674 |
}
|
|
675 |
|
|
676 |
return false;
|
|
677 |
}
|
|
678 |
|
|
679 |
bool HandleWindowDragging()
|
|
680 |
{
|
|
681 |
Window *w;
|
|
682 |
int x, y, t;
|
|
683 |
|
|
684 |
// Get out immediately if no window is being dragged at all.
|
|
685 |
if (!_dragging_window)
|
|
686 |
return true;
|
|
687 |
|
|
688 |
// Otherwise find the window...
|
|
689 |
for(w=_windows; w != _last_window; w++) {
|
|
690 |
if (w->flags4&(WF_DRAGGING|WF_SIZING)) {
|
|
691 |
|
|
692 |
// Stop the dragging if the left mouse button was released
|
|
693 |
if (!_left_button_down) {
|
|
694 |
w->flags4 &= ~(WF_DRAGGING | WF_SIZING);
|
|
695 |
break;
|
|
696 |
}
|
|
697 |
|
|
698 |
// Otherwise calculate the delta position.
|
|
699 |
x = _cursor.pos.x;
|
|
700 |
y = clamp2(_cursor.pos.y, 23, _screen.height-12);
|
|
701 |
t = _cursorpos_drag_start.x; _cursorpos_drag_start.x = x; x-=t;
|
|
702 |
t = _cursorpos_drag_start.y; _cursorpos_drag_start.y = y; y-=t;
|
|
703 |
|
|
704 |
// No movement?
|
|
705 |
if (x == 0 && y == 0)
|
|
706 |
return false;
|
|
707 |
|
|
708 |
// Mark the old position dirty
|
|
709 |
SetWindowDirty(w);
|
|
710 |
|
|
711 |
if (w->flags4 & WF_SIZING) {
|
|
712 |
// Size the window
|
|
713 |
w->width += x;
|
|
714 |
w->height += y;
|
|
715 |
} else {
|
|
716 |
// Move the window and viewport
|
|
717 |
w->left += x;
|
|
718 |
w->top += y;
|
|
719 |
if (w->viewport) {
|
|
720 |
w->viewport->left += x;
|
|
721 |
w->viewport->top += y;
|
|
722 |
}
|
|
723 |
}
|
|
724 |
|
|
725 |
// And also mark the new position dirty.
|
|
726 |
SetWindowDirty(w);
|
|
727 |
return false;
|
|
728 |
}
|
|
729 |
}
|
|
730 |
|
|
731 |
_dragging_window = false;
|
|
732 |
return false;
|
|
733 |
}
|
|
734 |
|
|
735 |
Window *StartWindowDrag(Window *w)
|
|
736 |
{
|
|
737 |
w->flags4 |= WF_DRAGGING;
|
|
738 |
_dragging_window = true;
|
|
739 |
_cursorpos_drag_start = _cursor.pos;
|
|
740 |
w = BringWindowToFront(w);
|
|
741 |
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
742 |
return w;
|
|
743 |
}
|
|
744 |
|
|
745 |
Window *StartWindowSizing(Window *w)
|
|
746 |
{
|
|
747 |
w->flags4 |= WF_SIZING;
|
|
748 |
_dragging_window = true;
|
|
749 |
_cursorpos_drag_start = _cursor.pos;
|
|
750 |
w = BringWindowToFront(w);
|
|
751 |
DeleteWindowById(WC_DROPDOWN_MENU, 0);
|
|
752 |
return w;
|
|
753 |
}
|
|
754 |
|
|
755 |
|
|
756 |
bool HandleScrollbarScrolling()
|
|
757 |
{
|
|
758 |
Window *w;
|
|
759 |
int i;
|
|
760 |
int pos;
|
|
761 |
Scrollbar *sb;
|
|
762 |
|
|
763 |
// Get out quickly if no item is being scrolled
|
|
764 |
if (!_scrolling_scrollbar)
|
|
765 |
return true;
|
|
766 |
|
|
767 |
// Find the scrolling window
|
|
768 |
for(w=_windows; w != _last_window; w++) {
|
|
769 |
if (w->flags4 & WF_SCROLL_MIDDLE) {
|
|
770 |
// Abort if no button is clicked any more.
|
|
771 |
if (!_left_button_down) {
|
|
772 |
w->flags4 &= ~WF_SCROLL_MIDDLE;
|
|
773 |
SetWindowDirty(w);
|
|
774 |
break;
|
|
775 |
}
|
|
776 |
|
|
777 |
if (w->flags4 & WF_HSCROLL) {
|
|
778 |
sb = &w->hscroll;
|
|
779 |
i = _cursor.pos.x - _cursorpos_drag_start.x;
|
|
780 |
} else {
|
|
781 |
sb = &w->vscroll;
|
|
782 |
i = _cursor.pos.y - _cursorpos_drag_start.y;
|
|
783 |
}
|
|
784 |
|
|
785 |
// Find the item we want to move to and make sure it's inside bounds.
|
|
786 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
|
|
787 |
if (pos != sb->pos) {
|
|
788 |
sb->pos = pos;
|
|
789 |
SetWindowDirty(w);
|
|
790 |
}
|
|
791 |
return false;
|
|
792 |
}
|
|
793 |
}
|
|
794 |
|
|
795 |
_scrolling_scrollbar = false;
|
|
796 |
return false;
|
|
797 |
}
|
|
798 |
|
|
799 |
bool HandleViewportScroll()
|
|
800 |
{
|
|
801 |
Window *w;
|
|
802 |
ViewPort *vp;
|
|
803 |
int dx,dy, x, y, sub;
|
|
804 |
|
|
805 |
if (!_scrolling_viewport)
|
|
806 |
return true;
|
|
807 |
|
|
808 |
if (!_right_button_down) {
|
|
809 |
stop_capt:;
|
|
810 |
_cursor.fix_at = false;
|
|
811 |
_scrolling_viewport = false;
|
|
812 |
return true;
|
|
813 |
}
|
|
814 |
|
|
815 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
|
|
816 |
if (w == NULL) goto stop_capt;
|
|
817 |
|
|
818 |
if (w->window_class != WC_SMALLMAP) {
|
|
819 |
vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y);
|
|
820 |
if (vp == NULL)
|
|
821 |
goto stop_capt;
|
|
822 |
|
|
823 |
WP(w,vp_d).scrollpos_x += _cursor.delta.x << vp->zoom;
|
|
824 |
WP(w,vp_d).scrollpos_y += _cursor.delta.y << vp->zoom;
|
|
825 |
_cursor.delta.x = _cursor.delta.y = 0;
|
|
826 |
return false;
|
|
827 |
} else {
|
|
828 |
// scroll the smallmap ?
|
|
829 |
|
|
830 |
_cursor.fix_at = true;
|
|
831 |
|
|
832 |
dx = _cursor.delta.x;
|
|
833 |
dy = _cursor.delta.y;
|
|
834 |
|
|
835 |
x = WP(w,smallmap_d).scroll_x;
|
|
836 |
y = WP(w,smallmap_d).scroll_y;
|
|
837 |
|
|
838 |
sub = WP(w,smallmap_d).subscroll + dx;
|
|
839 |
|
|
840 |
x -= (sub >> 2) << 4;
|
|
841 |
y += (sub >> 2) << 4;
|
|
842 |
sub &= 3;
|
|
843 |
|
|
844 |
x += (dy >> 1) << 4;
|
|
845 |
y += (dy >> 1) << 4;
|
|
846 |
|
|
847 |
if (dy & 1) {
|
|
848 |
x += 16;
|
|
849 |
sub += 2;
|
|
850 |
if (sub > 3) {
|
|
851 |
sub -= 4;
|
|
852 |
x -= 16;
|
|
853 |
y += 16;
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
if (x < 16) { x = 16; sub = 0; }
|
|
858 |
if (x > (TILES_X-2)*16) { x = (TILES_X-2)*16; sub = 0; }
|
|
859 |
if (y < -1120) { y = -1120; sub = 0; }
|
|
860 |
if (y > (TILE_X_MAX-40) * 16) { y = (TILE_X_MAX-40) * 16; sub = 0; }
|
|
861 |
|
|
862 |
WP(w,smallmap_d).scroll_x = x;
|
|
863 |
WP(w,smallmap_d).scroll_y = y;
|
|
864 |
WP(w,smallmap_d).subscroll = sub;
|
|
865 |
|
|
866 |
_cursor.delta.x = _cursor.delta.y = 0;
|
|
867 |
|
|
868 |
SetWindowDirty(w);
|
|
869 |
return false;
|
|
870 |
}
|
|
871 |
}
|
|
872 |
|
|
873 |
static Window *MaybeBringWindowToFront(Window *w)
|
|
874 |
{
|
|
875 |
Window *u;
|
|
876 |
|
|
877 |
if (w->window_class == WC_MAIN_WINDOW ||
|
|
878 |
w->window_class == WC_MAIN_TOOLBAR ||
|
|
879 |
w->window_class == WC_STATUS_BAR ||
|
|
880 |
w->window_class == WC_NEWS_WINDOW ||
|
|
881 |
w->window_class == WC_TOOLTIPS ||
|
|
882 |
w->window_class == WC_DROPDOWN_MENU)
|
|
883 |
return w;
|
|
884 |
|
|
885 |
for(u=w; ++u != _last_window;) {
|
|
886 |
if (u->window_class == WC_MAIN_WINDOW || u->window_class==WC_MAIN_TOOLBAR || u->window_class==WC_STATUS_BAR ||
|
|
887 |
u->window_class == WC_NEWS_WINDOW || u->window_class == WC_TOOLTIPS || u->window_class == WC_DROPDOWN_MENU)
|
|
888 |
continue;
|
|
889 |
|
|
890 |
if (w->left + w->width <= u->left ||
|
|
891 |
u->left + u->width <= w->left ||
|
|
892 |
w->top + w->height <= u->top ||
|
|
893 |
u->top + u->height <= w->top)
|
|
894 |
continue;
|
|
895 |
|
|
896 |
return BringWindowToFront(w);
|
|
897 |
}
|
|
898 |
|
|
899 |
return w;
|
|
900 |
}
|
|
901 |
|
|
902 |
static void HandleKeypress(uint32 key)
|
|
903 |
{
|
|
904 |
Window *w;
|
|
905 |
WindowEvent we;
|
|
906 |
|
|
907 |
// Setup event
|
|
908 |
we.keypress.event = WE_KEYPRESS;
|
|
909 |
we.keypress.ascii = key & 0xFF;
|
|
910 |
we.keypress.keycode = key >> 16;
|
|
911 |
we.keypress.cont = true;
|
|
912 |
|
|
913 |
// Call the event, start with the uppermost window.
|
|
914 |
for(w=_last_window; w != _windows;) {
|
|
915 |
--w;
|
|
916 |
w->wndproc(w, &we);
|
|
917 |
if (!we.keypress.cont)
|
|
918 |
break;
|
|
919 |
}
|
|
920 |
}
|
|
921 |
|
|
922 |
extern void UpdateTileSelection();
|
|
923 |
extern bool VpHandlePlaceSizingDrag();
|
|
924 |
|
|
925 |
void MouseLoop()
|
|
926 |
{
|
|
927 |
int x,y;
|
|
928 |
Window *w;
|
|
929 |
ViewPort *vp;
|
|
930 |
int click;
|
|
931 |
int mousewheel;
|
|
932 |
|
|
933 |
_current_player = _local_player;
|
|
934 |
|
|
935 |
// Handle pressed keys
|
|
936 |
if (_pressed_key) {
|
|
937 |
uint32 key = _pressed_key; _pressed_key = 0;
|
|
938 |
HandleKeypress(key);
|
|
939 |
}
|
|
940 |
|
|
941 |
// Mouse event?
|
|
942 |
click = 0;
|
|
943 |
if (_left_button_down && !_left_button_clicked) {
|
|
944 |
_left_button_clicked = true;
|
|
945 |
click = 1;
|
|
946 |
} else if (_right_button_clicked) {
|
|
947 |
_right_button_clicked = false;
|
|
948 |
click = 2;
|
|
949 |
}
|
|
950 |
|
|
951 |
mousewheel = 0;
|
|
952 |
if (_cursor.wheel) {
|
|
953 |
mousewheel = _cursor.wheel;
|
|
954 |
_cursor.wheel = 0;
|
|
955 |
}
|
|
956 |
|
|
957 |
DecreaseWindowCounters();
|
|
958 |
HandlePlacePresize();
|
|
959 |
UpdateTileSelection();
|
|
960 |
if (!VpHandlePlaceSizingDrag())
|
|
961 |
return;
|
|
962 |
|
|
963 |
if (!HandleDragDrop())
|
|
964 |
return;
|
|
965 |
|
|
966 |
if (!HandlePopupMenu())
|
|
967 |
return;
|
|
968 |
|
|
969 |
if (!HandleWindowDragging())
|
|
970 |
return;
|
|
971 |
|
|
972 |
if (!HandleScrollbarScrolling())
|
|
973 |
return;
|
|
974 |
|
|
975 |
if (!HandleViewportScroll())
|
|
976 |
return;
|
|
977 |
|
|
978 |
x = _cursor.pos.x;
|
|
979 |
y = _cursor.pos.y;
|
|
980 |
|
|
981 |
|
|
982 |
if (click == 0 && mousewheel == 0) {
|
|
983 |
if (_patches.autoscroll && _game_mode != GM_MENU) {
|
|
984 |
w = FindWindowFromPt(x, y);
|
|
985 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL ) return;
|
|
986 |
vp = IsPtInWindowViewport(w, x, y);
|
|
987 |
if (vp) {
|
|
988 |
x -= vp->left;
|
|
989 |
y -= vp->top;
|
|
990 |
//here allows scrolling in both x and y axis
|
|
991 |
#define scrollspeed 3
|
|
992 |
if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; }
|
|
993 |
else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; }
|
|
994 |
if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; }
|
|
995 |
else if (15-(vp->height-y) > 0) { WP(w,vp_d).scrollpos_y += (15-(vp->height-y))*scrollspeed << vp->zoom; }
|
|
996 |
#undef scrollspeed
|
|
997 |
}
|
|
998 |
}
|
|
999 |
return;
|
|
1000 |
}
|
|
1001 |
|
|
1002 |
w = FindWindowFromPt(x, y);
|
|
1003 |
if (w == NULL)
|
|
1004 |
return;
|
|
1005 |
w = MaybeBringWindowToFront(w);
|
|
1006 |
vp = IsPtInWindowViewport(w, x, y);
|
|
1007 |
if (vp != NULL) {
|
|
1008 |
if (_game_mode == GM_MENU)
|
|
1009 |
return;
|
|
1010 |
|
|
1011 |
if (mousewheel && !(w->flags4 & WF_DISABLE_VP_SCROLL)) {
|
|
1012 |
ZoomInOrOutToCursor(mousewheel < 0);
|
|
1013 |
}
|
|
1014 |
|
|
1015 |
if (click == 1) {
|
|
1016 |
if (_thd.place_mode != 0 &&
|
|
1017 |
_cursor.sprite != 0x2CF &&
|
|
1018 |
_pause != 0 &&
|
|
1019 |
!_patches.build_in_pause)
|
|
1020 |
return;
|
|
1021 |
|
|
1022 |
if (_thd.place_mode == 0) {
|
|
1023 |
HandleViewportClicked(vp, x, y);
|
|
1024 |
} else {
|
|
1025 |
PlaceObject();
|
|
1026 |
}
|
|
1027 |
} else if (click == 2) {
|
|
1028 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
|
|
1029 |
_scrolling_viewport = true;
|
|
1030 |
_cursor.fix_at = true;
|
|
1031 |
}
|
|
1032 |
}
|
|
1033 |
} else {
|
|
1034 |
if (mousewheel)
|
|
1035 |
DispatchMouseWheelEvent(w, mousewheel);
|
|
1036 |
|
|
1037 |
if (click == 1)
|
|
1038 |
DispatchLeftClickEvent(w, x - w->left, y - w->top);
|
|
1039 |
else if (click == 2)
|
|
1040 |
DispatchRightClickEvent(w, x - w->left, y - w->top);
|
|
1041 |
}
|
|
1042 |
}
|
|
1043 |
|
|
1044 |
static int _we4_timer;
|
|
1045 |
|
|
1046 |
extern uint32 _pixels_redrawn;
|
|
1047 |
|
|
1048 |
void UpdateWindows()
|
|
1049 |
{
|
|
1050 |
Window *w;
|
|
1051 |
int t;
|
|
1052 |
|
|
1053 |
|
|
1054 |
if ((t=_we4_timer+1) >= 100) {
|
|
1055 |
for(w = _last_window; w != _windows;) {
|
|
1056 |
w--;
|
|
1057 |
CallWindowEventNP(w, WE_4);
|
|
1058 |
}
|
|
1059 |
t = 0;
|
|
1060 |
}
|
|
1061 |
_we4_timer = t;
|
|
1062 |
|
|
1063 |
for(w = _last_window; w != _windows;) {
|
|
1064 |
w--;
|
|
1065 |
if (w->flags4 & WF_WHITE_BORDER_MASK) {
|
|
1066 |
w->flags4 -= WF_WHITE_BORDER_ONE;
|
|
1067 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) {
|
|
1068 |
SetWindowDirty(w);
|
|
1069 |
}
|
|
1070 |
}
|
|
1071 |
}
|
|
1072 |
|
|
1073 |
DrawDirtyBlocks();
|
|
1074 |
|
|
1075 |
for(w = _windows; w!=_last_window; w++) {
|
|
1076 |
if (w->viewport != NULL)
|
|
1077 |
UpdateViewportPosition(w);
|
|
1078 |
}
|
|
1079 |
// Redraw mouse cursor in case it was hidden
|
|
1080 |
DrawMouseCursor();
|
|
1081 |
}
|
|
1082 |
|
|
1083 |
|
|
1084 |
int GetMenuItemIndex(Window *w, int x, int y)
|
|
1085 |
{
|
|
1086 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
|
|
1087 |
y /= 10;
|
|
1088 |
|
|
1089 |
if (y < WP(w,menu_d).item_count)
|
|
1090 |
return y;
|
|
1091 |
}
|
|
1092 |
return -1;
|
|
1093 |
}
|
|
1094 |
|
|
1095 |
void InvalidateWindow(byte cls, WindowNumber number)
|
|
1096 |
{
|
|
1097 |
Window *w;
|
|
1098 |
|
|
1099 |
for(w=_windows; w!=_last_window; w++) {
|
|
1100 |
if (w->window_class==cls && w->window_number==number)
|
|
1101 |
SetWindowDirty(w);
|
|
1102 |
}
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
void InvalidateWidget(Window *w, byte widget_index)
|
|
1106 |
{
|
|
1107 |
const Widget *wi = &w->widget[widget_index];
|
|
1108 |
// if (wi->left != -2) {
|
|
1109 |
SetDirtyBlocks(
|
|
1110 |
w->left + wi->left,
|
|
1111 |
w->top + wi->top,
|
|
1112 |
w->left + wi->right + 1,
|
|
1113 |
w->top + wi->bottom + 1);
|
|
1114 |
// }
|
|
1115 |
}
|
|
1116 |
|
|
1117 |
void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index)
|
|
1118 |
{
|
|
1119 |
Window *w;
|
|
1120 |
|
|
1121 |
for(w=_windows; w!=_last_window; w++) {
|
|
1122 |
if (w->window_class==cls && w->window_number==number) {
|
|
1123 |
InvalidateWidget(w, widget_index);
|
|
1124 |
}
|
|
1125 |
}
|
|
1126 |
}
|
|
1127 |
|
|
1128 |
void InvalidateWindowClasses(byte cls)
|
|
1129 |
{
|
|
1130 |
Window *w;
|
|
1131 |
for(w=_windows; w!=_last_window; w++) {
|
|
1132 |
if (w->window_class==cls)
|
|
1133 |
SetWindowDirty(w);
|
|
1134 |
}
|
|
1135 |
}
|
|
1136 |
|
|
1137 |
|
|
1138 |
void CallWindowTickEvent()
|
|
1139 |
{
|
|
1140 |
Window *w;
|
|
1141 |
for(w=_last_window; w != _windows;) {
|
|
1142 |
--w;
|
|
1143 |
CallWindowEventNP(w, WE_TICK);
|
|
1144 |
}
|
|
1145 |
}
|
|
1146 |
|
|
1147 |
void DeleteNonVitalWindows()
|
|
1148 |
{
|
|
1149 |
Window *w;
|
|
1150 |
for(w=_windows; w!=_last_window;) {
|
|
1151 |
if (w->window_class != WC_MAIN_WINDOW &&
|
|
1152 |
w->window_class != WC_SELECT_GAME &&
|
|
1153 |
w->window_class != WC_MAIN_TOOLBAR &&
|
|
1154 |
w->window_class != WC_STATUS_BAR &&
|
|
1155 |
w->window_class != WC_TOOLBAR_MENU &&
|
|
1156 |
w->window_class != WC_TOOLTIPS) {
|
|
1157 |
DeleteWindow(w);
|
|
1158 |
w = _windows;
|
|
1159 |
} else {
|
|
1160 |
w++;
|
|
1161 |
}
|
|
1162 |
}
|
|
1163 |
}
|
|
1164 |
|
|
1165 |
void RelocateAllWindows(int neww, int newh)
|
|
1166 |
{
|
|
1167 |
Window *w;
|
|
1168 |
|
|
1169 |
for(w=_windows; w!= _last_window ;w++) {
|
|
1170 |
int left, top;
|
|
1171 |
|
|
1172 |
if (w->window_class == WC_MAIN_WINDOW) {
|
|
1173 |
ViewPort *vp = w->viewport;
|
|
1174 |
vp->width = w->width = neww;
|
|
1175 |
vp->height = w->height = newh;
|
|
1176 |
vp->virtual_width = neww << vp->zoom;
|
|
1177 |
vp->virtual_height = newh << vp->zoom;
|
|
1178 |
continue; // don't modify top,left
|
|
1179 |
}
|
|
1180 |
|
|
1181 |
if (w->window_class == WC_MAIN_TOOLBAR) {
|
|
1182 |
top = w->top;
|
|
1183 |
left = (neww - w->width) >> 1;
|
|
1184 |
} else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){
|
|
1185 |
top = (newh - w->height) >> 1;
|
|
1186 |
left = (neww - w->width) >> 1;
|
|
1187 |
} else if (w->window_class == WC_NEWS_WINDOW) {
|
|
1188 |
top = newh - w->height;
|
|
1189 |
left = (neww - w->width) >> 1;
|
|
1190 |
} else if (w->window_class == WC_STATUS_BAR) {
|
|
1191 |
top = newh - w->height;
|
|
1192 |
left = (neww - w->width) >> 1;
|
|
1193 |
} else {
|
|
1194 |
left = w->left;
|
|
1195 |
if (left + (w->width>>1) >= neww) left = neww - w->width;
|
|
1196 |
top = w->top;
|
|
1197 |
if (top + (w->height>>1) >= newh) top = newh - w->height;
|
|
1198 |
}
|
|
1199 |
|
|
1200 |
if (w->viewport) {
|
|
1201 |
w->viewport->left += left - w->left;
|
|
1202 |
w->viewport->top += top - w->top;
|
|
1203 |
}
|
|
1204 |
|
|
1205 |
w->left = left;
|
|
1206 |
w->top = top;
|
|
1207 |
}
|
|
1208 |
}
|
|
1209 |
|