author | darkvater |
Wed, 15 Dec 2004 23:33:04 +0000 | |
changeset 682 | 7f5de4abac85 |
parent 679 | e959706a3e4d |
child 763 | 8ff348acf75e |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
679
e959706a3e4d
(svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents:
651
diff
changeset
|
3 |
#include "map.h" |
0 | 4 |
#include "window.h" |
5 |
#include "gfx.h" |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
6 |
#include "viewport.h" |
126 | 7 |
#include "console.h" |
0 | 8 |
|
350 | 9 |
// delta between mouse cursor and upper left corner of dragged window |
10 |
static Point _drag_delta; |
|
11 |
||
0 | 12 |
void HandleButtonClick(Window *w, byte widget) |
13 |
{ |
|
14 |
w->click_state |= (1 << widget); |
|
15 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
16 |
InvalidateWidget(w, widget); |
|
17 |
} |
|
18 |
||
19 |
void DispatchLeftClickEvent(Window *w, int x, int y) { |
|
20 |
WindowEvent e; |
|
21 |
const Widget *wi; |
|
22 |
||
23 |
e.click.pt.x = x; |
|
24 |
e.click.pt.y = y; |
|
25 |
e.event = WE_CLICK; |
|
26 |
||
27 |
if (w->desc_flags & WDF_DEF_WIDGET) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
28 |
e.click.widget = GetWidgetFromPos(w, x, y); |
0 | 29 |
if (e.click.widget < 0) return; /* exit if clicked outside of widgets */ |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
30 |
|
0 | 31 |
wi = &w->widget[e.click.widget]; |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
211
diff
changeset
|
32 |
|
211 | 33 |
/* don't allow any interaction if the button has been disabled */ |
34 |
if (HASBIT(w->disabled_state, e.click.widget)) |
|
35 |
return; |
|
0 | 36 |
|
37 |
if (wi->type & 0xE0) { |
|
211 | 38 |
/* special widget handling for buttons*/ |
0 | 39 |
switch(wi->type) { |
211 | 40 |
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ |
41 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
|
0 | 42 |
HandleButtonClick(w, e.click.widget); |
43 |
break; |
|
44 |
case WWT_NODISTXTBTN: |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
45 |
break; |
0 | 46 |
} |
47 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_HSCROLLBAR) { |
|
48 |
ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y); |
|
49 |
} |
|
50 |
||
51 |
w->wndproc(w, &e); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
52 |
|
0 | 53 |
if (w->desc_flags & WDF_STD_BTN) { |
54 |
if (e.click.widget == 0) DeleteWindow(w); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
55 |
else { |
0 | 56 |
if (e.click.widget == 1) { |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
57 |
if (_ctrl_pressed) |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
58 |
StartWindowSizing(w); |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
59 |
else |
0 | 60 |
StartWindowDrag(w); |
61 |
} |
|
62 |
} |
|
63 |
} |
|
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
64 |
|
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
65 |
if (w->desc_flags & WDF_STICKY_BUTTON) { |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
66 |
if (e.click.widget == 2) { |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
67 |
w->click_state ^= (1 << e.click.widget); |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
68 |
w->flags4 ^= WF_STICKY; |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
69 |
InvalidateWidget(w, e.click.widget); |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
70 |
} |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
71 |
} |
0 | 72 |
} else { |
73 |
w->wndproc(w, &e); |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
void DispatchRightClickEvent(Window *w, int x, int y) { |
|
78 |
WindowEvent e; |
|
79 |
||
80 |
/* default tooltips handler? */ |
|
81 |
if (w->desc_flags & WDF_STD_TOOLTIPS) { |
|
82 |
e.click.widget = GetWidgetFromPos(w, x, y); |
|
83 |
if (e.click.widget < 0) |
|
84 |
return; /* exit if clicked outside of widgets */ |
|
85 |
||
86 |
if (w->widget[e.click.widget].tooltips != 0) { |
|
87 |
GuiShowTooltips(w->widget[e.click.widget].tooltips); |
|
88 |
return; |
|
89 |
} |
|
90 |
} |
|
91 |
||
92 |
e.event = WE_RCLICK; |
|
93 |
e.click.pt.x = x; |
|
94 |
e.click.pt.y = y; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
95 |
w->wndproc(w, &e); |
0 | 96 |
} |
97 |
||
98 |
||
99 |
void DispatchMouseWheelEvent(Window *w, int wheel) |
|
100 |
{ |
|
86
13cde394988b
(svn r87) Fix: rare mousewheel scrolling with scrollbar crash
dominik
parents:
77
diff
changeset
|
101 |
if (w->vscroll.count > w->vscroll.cap) { |
0 | 102 |
int pos = clamp(w->vscroll.pos + wheel, 0, w->vscroll.count - w->vscroll.cap); |
103 |
if (pos != w->vscroll.pos) { |
|
104 |
w->vscroll.pos = pos; |
|
105 |
SetWindowDirty(w); |
|
106 |
} |
|
107 |
} |
|
108 |
} |
|
109 |
||
110 |
||
111 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
|
112 |
{ |
|
113 |
Window *w; |
|
114 |
DrawPixelInfo bk; |
|
115 |
_cur_dpi = &bk; |
|
116 |
||
117 |
for(w=_windows; w!=_last_window; w++) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
118 |
if (right > w->left && |
0 | 119 |
bottom > w->top && |
120 |
left < w->left + w->width && |
|
121 |
top < w->top + w->height) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
122 |
DrawOverlappedWindow(w, left, top, right, bottom); |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
123 |
} |
0 | 124 |
} |
125 |
} |
|
126 |
||
127 |
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom) |
|
128 |
{ |
|
129 |
Window *v = w; |
|
130 |
int x; |
|
131 |
||
132 |
while (++v != _last_window) { |
|
133 |
if (right > v->left && |
|
134 |
bottom > v->top && |
|
135 |
left < v->left + v->width && |
|
136 |
top < v->top + v->height) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
137 |
|
0 | 138 |
if (left < (x=v->left)) { |
139 |
DrawOverlappedWindow(w, left, top, x, bottom); |
|
140 |
DrawOverlappedWindow(w, x, top, right, bottom); |
|
141 |
return; |
|
142 |
} |
|
143 |
||
144 |
if (right > (x=v->left + v->width)) { |
|
145 |
DrawOverlappedWindow(w, left, top, x, bottom); |
|
146 |
DrawOverlappedWindow(w, x, top, right, bottom); |
|
147 |
return; |
|
148 |
} |
|
149 |
||
150 |
if (top < (x=v->top)) { |
|
151 |
DrawOverlappedWindow(w, left, top, right, x); |
|
152 |
DrawOverlappedWindow(w, left, x, right, bottom); |
|
153 |
return; |
|
154 |
} |
|
155 |
||
156 |
if (bottom > (x=v->top + v->height)) { |
|
157 |
DrawOverlappedWindow(w, left, top, right, x); |
|
158 |
DrawOverlappedWindow(w, left, x, right, bottom); |
|
159 |
return; |
|
160 |
} |
|
161 |
||
162 |
return; |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
167 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 168 |
dp->width = right - left; |
169 |
dp->height = bottom - top; |
|
170 |
dp->left = left - w->left; |
|
171 |
dp->top = top - w->top; |
|
172 |
dp->pitch = _screen.pitch; |
|
173 |
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left; |
|
174 |
dp->zoom = 0; |
|
175 |
CallWindowEventNP(w, WE_PAINT); |
|
176 |
} |
|
177 |
} |
|
178 |
||
179 |
void CallWindowEventNP(Window *w, int event) |
|
180 |
{ |
|
181 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
182 |
|
0 | 183 |
e.event = event; |
184 |
w->wndproc(w, &e); |
|
185 |
} |
|
186 |
||
187 |
void SetWindowDirty(Window *w) |
|
188 |
{ |
|
189 |
if (w == NULL) |
|
190 |
return; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
191 |
|
0 | 192 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); |
193 |
} |
|
194 |
||
195 |
void DeleteWindow(Window *w) |
|
196 |
{ |
|
197 |
WindowClass wc; |
|
198 |
WindowNumber wn; |
|
199 |
ViewPort *vp; |
|
200 |
Window *v; |
|
201 |
int count; |
|
202 |
||
203 |
if (w == NULL) |
|
204 |
return; |
|
205 |
||
206 |
if (_thd.place_mode != 0 && _thd.window_class == w->window_class && _thd.window_number == w->window_number) { |
|
207 |
ResetObjectToPlace(); |
|
208 |
} |
|
209 |
||
210 |
wc = w->window_class; |
|
211 |
wn = w->window_number; |
|
212 |
||
213 |
CallWindowEventNP(w, WE_DESTROY); |
|
214 |
||
215 |
w = FindWindowById(wc, wn); |
|
216 |
||
217 |
vp = w->viewport; |
|
218 |
w->viewport = NULL; |
|
219 |
if (vp != NULL) { |
|
220 |
_active_viewports &= ~(1 << (vp - _viewports)); |
|
221 |
vp->width = 0; |
|
222 |
} |
|
223 |
||
224 |
SetWindowDirty(w); |
|
225 |
||
226 |
v = --_last_window; |
|
227 |
count = (byte*)v - (byte*)w; |
|
228 |
memcpy(w, w + 1, count); |
|
229 |
} |
|
230 |
||
231 |
Window *FindWindowById(WindowClass cls, WindowNumber number) |
|
232 |
{ |
|
233 |
Window *w; |
|
234 |
||
235 |
for(w=_windows; w!=_last_window; w++) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
236 |
if (w->window_class == cls && |
0 | 237 |
w->window_number == number) { |
238 |
return w; |
|
239 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
240 |
} |
0 | 241 |
|
242 |
return NULL; |
|
243 |
} |
|
244 |
||
245 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
|
246 |
{ |
|
247 |
DeleteWindow(FindWindowById(cls, number)); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
248 |
} |
0 | 249 |
|
250 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) |
|
251 |
{ |
|
252 |
Window *w = FindWindowById(cls, number); |
|
253 |
||
254 |
if (w != NULL) { |
|
255 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
|
256 |
SetWindowDirty(w); |
|
388
d81d1c093b17
(svn r580) Fix latent bug in BringWindowToFrontByID() - a wrong pointer was returned
tron
parents:
386
diff
changeset
|
257 |
w = BringWindowToFront(w); |
0 | 258 |
} |
259 |
||
260 |
return w; |
|
261 |
} |
|
262 |
||
263 |
Window *BringWindowToFront(Window *w) |
|
264 |
{ |
|
265 |
Window *v; |
|
386 | 266 |
Window temp; |
0 | 267 |
|
268 |
v = _last_window; |
|
269 |
do { |
|
270 |
if (--v < _windows) |
|
271 |
return w; |
|
272 |
} while (v->window_class == WC_MAIN_TOOLBAR || v->window_class == WC_STATUS_BAR || v->window_class == WC_NEWS_WINDOW); |
|
273 |
||
274 |
if (w == v) |
|
275 |
return w; |
|
276 |
||
277 |
assert(w < v); |
|
278 |
||
386 | 279 |
temp = *w; |
280 |
memmove(w, w + 1, (v - w) * sizeof(Window)); |
|
281 |
*v = temp; |
|
0 | 282 |
|
386 | 283 |
SetWindowDirty(v); |
0 | 284 |
|
386 | 285 |
return v; |
0 | 286 |
} |
287 |
||
288 |
Window *AllocateWindow( |
|
289 |
int x, |
|
290 |
int y, |
|
291 |
int width, |
|
292 |
int height, |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
293 |
WindowProc *proc, |
0 | 294 |
WindowClass cls, |
295 |
const Widget *widget) |
|
296 |
{ |
|
297 |
Window *w; |
|
298 |
||
299 |
restart:; |
|
300 |
w = _last_window; |
|
301 |
||
302 |
if (w >= endof(_windows)) { |
|
303 |
for(w=_windows; ;w++) { |
|
304 |
assert(w < _last_window); |
|
305 |
||
306 |
if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_MAIN_TOOLBAR && |
|
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
307 |
w->window_class != WC_STATUS_BAR && w->window_class != WC_NEWS_WINDOW && |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
308 |
!(w->flags4 & WF_STICKY) ) { |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
309 |
|
0 | 310 |
DeleteWindow(w); |
311 |
goto restart; |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
||
316 |
if (w != _windows && cls != WC_NEWS_WINDOW) { |
|
317 |
Window *v; |
|
318 |
||
319 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
|
320 |
if (v) { |
|
321 |
memmove(v+1, v, (byte*)w - (byte*)v); |
|
322 |
w = v; |
|
323 |
} |
|
324 |
||
325 |
v = FindWindowById(WC_STATUS_BAR, 0); |
|
326 |
if (v) { |
|
327 |
memmove(v+1, v, (byte*)w - (byte*)v); |
|
328 |
w = v; |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
/* XXX: some more code here */ |
|
333 |
w->window_class = cls; |
|
334 |
w->flags4 = WF_WHITE_BORDER_MASK; |
|
335 |
w->caption_color = 0xFF; |
|
336 |
w->window_number = 0; |
|
337 |
w->left = x; |
|
338 |
w->top = y; |
|
339 |
w->width = width; |
|
340 |
w->height = height; |
|
341 |
w->viewport = NULL; |
|
342 |
w->desc_flags = 0; |
|
343 |
// w->landscape_assoc = 0xFFFF; |
|
344 |
w->wndproc = proc; |
|
345 |
w->click_state = 0; |
|
346 |
w->disabled_state = 0; |
|
347 |
w->hidden_state = 0; |
|
348 |
// w->unk22 = 0xFFFF; |
|
349 |
w->vscroll.pos = 0; |
|
350 |
w->vscroll.count = 0; |
|
351 |
w->hscroll.pos = 0; |
|
352 |
w->hscroll.count = 0; |
|
353 |
w->widget = widget; |
|
354 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
355 |
{ |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
356 |
int i; |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
357 |
for (i=0;i<lengthof(w->custom);i++) |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
358 |
w->custom[i] = 0; |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
359 |
} |
0 | 360 |
|
361 |
_last_window++; |
|
362 |
||
363 |
SetWindowDirty(w); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
364 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
86
diff
changeset
|
365 |
CallWindowEventNP(w, WE_CREATE); |
0 | 366 |
|
367 |
return w; |
|
368 |
} |
|
369 |
||
370 |
Window *AllocateWindowAutoPlace2( |
|
371 |
WindowClass exist_class, |
|
372 |
WindowNumber exist_num, |
|
373 |
int width, |
|
374 |
int height, |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
375 |
WindowProc *proc, |
0 | 376 |
WindowClass cls, |
377 |
const Widget *widget) |
|
378 |
{ |
|
379 |
Window *w; |
|
380 |
int x; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
381 |
|
0 | 382 |
w = FindWindowById(exist_class, exist_num); |
383 |
if (w == NULL || w->left >= (_screen.width-20) || w->left <= -60 || w->top >= (_screen.height-20)) { |
|
384 |
return AllocateWindowAutoPlace(width,height,proc,cls,widget); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
385 |
} |
0 | 386 |
|
387 |
x = w->left; |
|
388 |
if (x > _screen.width - width) |
|
389 |
x = (_screen.width - width) - 20; |
|
390 |
||
391 |
return AllocateWindow(x+10,w->top+10,width,height,proc,cls,widget); |
|
392 |
} |
|
393 |
||
394 |
||
395 |
typedef struct SizeRect { |
|
396 |
int left,top,width,height; |
|
397 |
} SizeRect; |
|
398 |
||
399 |
||
400 |
static SizeRect _awap_r; |
|
401 |
||
402 |
static bool IsGoodAutoPlace1(int left, int top) |
|
403 |
{ |
|
404 |
int right,bottom; |
|
405 |
Window *w; |
|
406 |
||
407 |
_awap_r.left= left; |
|
408 |
_awap_r.top = top; |
|
409 |
right = _awap_r.width + left; |
|
410 |
bottom = _awap_r.height + top; |
|
411 |
||
412 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
413 |
return false; |
|
414 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
415 |
// Make sure it is not obscured by any window. |
0 | 416 |
for(w=_windows; w!=_last_window; w++) { |
417 |
if (w->window_class == WC_MAIN_WINDOW) |
|
418 |
continue; |
|
419 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
420 |
if (right > w->left && |
0 | 421 |
w->left + w->width > left && |
422 |
bottom > w->top && |
|
423 |
w->top + w->height > top) |
|
424 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
425 |
} |
0 | 426 |
|
427 |
return true; |
|
428 |
} |
|
429 |
||
430 |
static bool IsGoodAutoPlace2(int left, int top) |
|
431 |
{ |
|
432 |
int width,height; |
|
433 |
Window *w; |
|
434 |
||
435 |
_awap_r.left= left; |
|
436 |
_awap_r.top = top; |
|
437 |
width = _awap_r.width; |
|
438 |
height = _awap_r.height; |
|
439 |
||
440 |
if (left < -(width>>2) || left > _screen.width - (width>>1)) |
|
441 |
return false; |
|
442 |
if (top < 22 || top > _screen.height - (height>>2)) |
|
443 |
return false; |
|
444 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
445 |
// Make sure it is not obscured by any window. |
0 | 446 |
for(w=_windows; w!=_last_window; w++) { |
447 |
if (w->window_class == WC_MAIN_WINDOW) |
|
448 |
continue; |
|
449 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
450 |
if (left + width > w->left && |
0 | 451 |
w->left + w->width > left && |
452 |
top + height > w->top && |
|
453 |
w->top + w->height > top) |
|
454 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
455 |
} |
0 | 456 |
|
457 |
return true; |
|
458 |
} |
|
459 |
||
460 |
Point GetAutoPlacePosition(int width, int height) { |
|
461 |
Window *w; |
|
462 |
Point pt; |
|
463 |
||
464 |
_awap_r.width = width; |
|
465 |
_awap_r.height = height; |
|
466 |
||
467 |
if (IsGoodAutoPlace1(0, 24)) goto ok_pos; |
|
468 |
||
469 |
for(w=_windows; w!=_last_window; w++) { |
|
470 |
if (w->window_class == WC_MAIN_WINDOW) |
|
471 |
continue; |
|
472 |
||
473 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos; |
|
474 |
if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos; |
|
475 |
if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos; |
|
476 |
if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos; |
|
477 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos; |
|
478 |
if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos; |
|
479 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos; |
|
480 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top- height-2)) goto ok_pos; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
481 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
482 |
|
0 | 483 |
for(w=_windows; w!=_last_window; w++) { |
484 |
if (w->window_class == WC_MAIN_WINDOW) |
|
485 |
continue; |
|
486 |
||
487 |
if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos; |
|
488 |
if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos; |
|
489 |
if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos; |
|
490 |
if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos; |
|
491 |
} |
|
492 |
||
493 |
{ |
|
494 |
int left=0,top=24; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
495 |
|
0 | 496 |
restart:; |
497 |
for(w=_windows; w!=_last_window; w++) { |
|
498 |
if (w->left == left && w->top == top) { |
|
499 |
left += 5; |
|
500 |
top += 5; |
|
501 |
goto restart; |
|
502 |
} |
|
503 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
504 |
|
0 | 505 |
pt.x = left; |
506 |
pt.y = top; |
|
507 |
return pt; |
|
508 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
509 |
|
0 | 510 |
ok_pos:; |
511 |
pt.x = _awap_r.left; |
|
512 |
pt.y = _awap_r.top; |
|
513 |
return pt; |
|
514 |
} |
|
515 |
||
516 |
Window *AllocateWindowAutoPlace( |
|
517 |
int width, |
|
518 |
int height, |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
519 |
WindowProc *proc, |
0 | 520 |
WindowClass cls, |
521 |
const Widget *widget) { |
|
522 |
||
523 |
Point pt = GetAutoPlacePosition(width, height); |
|
524 |
return AllocateWindow(pt.x, pt.y, width, height, proc, cls, widget); |
|
525 |
} |
|
526 |
||
527 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int value) |
|
528 |
{ |
|
529 |
Window *w; |
|
530 |
||
531 |
if (BringWindowToFrontById(desc->cls, value)) |
|
532 |
return NULL; |
|
533 |
w = AllocateWindowDesc(desc); |
|
534 |
w->window_number = value; |
|
535 |
return w; |
|
536 |
} |
|
537 |
||
538 |
Window *AllocateWindowDesc(const WindowDesc *desc) |
|
539 |
{ |
|
540 |
Point pt; |
|
541 |
Window *w; |
|
542 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
543 |
if (desc->parent_cls != WC_MAIN_WINDOW && |
0 | 544 |
(w = FindWindowById(desc->parent_cls, _alloc_wnd_parent_num), _alloc_wnd_parent_num=0, w) != NULL && |
545 |
w->left < _screen.width-20 && w->left > -60 && w->top < _screen.height-20) { |
|
546 |
pt.x = w->left + 10; |
|
547 |
if (pt.x > _screen.width + 10 - desc->width) |
|
548 |
pt.x = (_screen.width + 10 - desc->width) - 20; |
|
549 |
pt.y = w->top + 10; |
|
77
855f2aaf816b
(svn r78) -Fix: [1010830] Landscape toolbar in scenario editor shown at wrong position
darkvater
parents:
70
diff
changeset
|
550 |
} else if (desc->cls == WC_BUILD_TOOLBAR) { // open Build Toolbars aligned |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
551 |
/* Override the position if a toolbar is opened according to the place of the maintoolbar |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
552 |
* The main toolbar (WC_MAIN_TOOLBAR) is 640px in width */ |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
553 |
switch (_patches.toolbar_pos) { |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
554 |
case 1: pt.x = ((_screen.width + 640) >> 1) - desc->width; break; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
555 |
case 2: pt.x = _screen.width - desc->width; break; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
556 |
default: pt.x = 640 - desc->width; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
557 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
558 |
pt.y = desc->top; |
0 | 559 |
} else { |
560 |
pt.x = desc->left; |
|
561 |
pt.y = desc->top; |
|
562 |
if (pt.x == WDP_AUTO) { |
|
563 |
pt = GetAutoPlacePosition(desc->width, desc->height); |
|
564 |
} else { |
|
565 |
if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1; |
|
566 |
if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1; |
|
649 | 567 |
else if(pt.y < 0) pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen |
0 | 568 |
} |
569 |
} |
|
570 |
||
571 |
w = AllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets); |
|
572 |
w->desc_flags = desc->flags; |
|
573 |
return w; |
|
574 |
} |
|
575 |
||
576 |
Window *FindWindowFromPt(int x, int y) |
|
577 |
{ |
|
578 |
Window *w; |
|
579 |
||
580 |
for(w=_last_window; w != _windows;) { |
|
581 |
--w; |
|
582 |
if (IS_INSIDE_1D(x, w->left, w->width) && |
|
583 |
IS_INSIDE_1D(y, w->top, w->height)) |
|
584 |
return w; |
|
585 |
} |
|
586 |
||
587 |
return NULL; |
|
588 |
} |
|
589 |
||
590 |
||
591 |
void InitWindowSystem() |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
592 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
593 |
IConsoleClose(); |
0 | 594 |
memset(&_windows, 0, sizeof(_windows)); |
595 |
_last_window = _windows; |
|
596 |
memset(_viewports, 0, sizeof(_viewports)); |
|
597 |
_active_viewports = 0; |
|
598 |
} |
|
599 |
||
410 | 600 |
static void DecreaseWindowCounters() |
0 | 601 |
{ |
602 |
Window *w; |
|
603 |
||
604 |
||
605 |
for(w=_last_window; w != _windows;) { |
|
606 |
--w; |
|
607 |
// Unclick scrollbar buttons if they are pressed. |
|
608 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
|
609 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
610 |
SetWindowDirty(w); |
|
611 |
} |
|
612 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
613 |
} |
|
614 |
||
615 |
for(w=_last_window; w != _windows;) { |
|
616 |
--w; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
617 |
|
0 | 618 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
619 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
620 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) |
|
621 |
UnclickWindowButtons(w); |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
625 |
||
626 |
Window *GetCallbackWnd() |
|
627 |
{ |
|
628 |
return FindWindowById(_thd.window_class, _thd.window_number); |
|
629 |
} |
|
630 |
||
410 | 631 |
static void HandlePlacePresize() |
0 | 632 |
{ |
633 |
Window *w; |
|
634 |
WindowEvent e; |
|
635 |
||
636 |
if (_special_mouse_mode != WSM_PRESIZE) |
|
637 |
return; |
|
638 |
||
639 |
if ((w = GetCallbackWnd()) == NULL) |
|
640 |
return; |
|
641 |
||
642 |
e.place.pt = GetTileBelowCursor(); |
|
643 |
if (e.place.pt.x == -1) { |
|
644 |
_thd.selend.x = -1; |
|
645 |
return; |
|
646 |
} |
|
647 |
e.place.tile = TILE_FROM_XY(e.place.pt.x, e.place.pt.y); |
|
648 |
e.event = WE_PLACE_PRESIZE; |
|
649 |
w->wndproc(w, &e); |
|
650 |
} |
|
651 |
||
410 | 652 |
static bool HandleDragDrop() |
0 | 653 |
{ |
654 |
Window *w; |
|
655 |
WindowEvent e; |
|
656 |
||
657 |
if (_special_mouse_mode != WSM_DRAGDROP) |
|
658 |
return true; |
|
659 |
||
660 |
if (_left_button_down) |
|
661 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
662 |
|
0 | 663 |
w = GetCallbackWnd(); |
664 |
||
665 |
ResetObjectToPlace(); |
|
666 |
||
667 |
if (w) { |
|
668 |
// send an event in client coordinates. |
|
669 |
e.event = WE_DRAGDROP; |
|
670 |
e.dragdrop.pt.x = _cursor.pos.x - w->left; |
|
671 |
e.dragdrop.pt.y = _cursor.pos.y - w->top; |
|
672 |
e.dragdrop.widget = GetWidgetFromPos(w, e.dragdrop.pt.x, e.dragdrop.pt.y); |
|
673 |
w->wndproc(w, &e); |
|
674 |
} |
|
675 |
return false; |
|
676 |
} |
|
677 |
||
410 | 678 |
static bool HandlePopupMenu() |
0 | 679 |
{ |
680 |
Window *w; |
|
681 |
WindowEvent e; |
|
682 |
||
683 |
if (!_popup_menu_active) |
|
684 |
return true; |
|
685 |
||
686 |
w = FindWindowById(WC_TOOLBAR_MENU, 0); |
|
687 |
if (w == NULL) { |
|
688 |
_popup_menu_active = false; |
|
689 |
return false; |
|
690 |
} |
|
691 |
||
692 |
if (_left_button_down) { |
|
693 |
e.event = WE_POPUPMENU_OVER; |
|
694 |
e.popupmenu.pt = _cursor.pos; |
|
695 |
w->wndproc(w, &e); |
|
696 |
} else { |
|
697 |
_popup_menu_active = false; |
|
698 |
e.event = WE_POPUPMENU_SELECT; |
|
699 |
e.popupmenu.pt = _cursor.pos; |
|
700 |
w->wndproc(w, &e); |
|
701 |
} |
|
702 |
||
703 |
return false; |
|
704 |
} |
|
705 |
||
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
706 |
bool HandleMouseOver() |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
707 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
708 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
709 |
WindowEvent e; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
710 |
static Window *last_w = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
711 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
712 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
713 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
714 |
// We changed window, put a MOUSEOVER event to the last window |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
715 |
if (last_w && last_w != w) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
716 |
e.event = WE_MOUSEOVER; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
717 |
e.mouseover.pt.x = -1; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
718 |
e.mouseover.pt.y = -1; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
719 |
if (last_w->wndproc) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
720 |
last_w->wndproc(last_w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
721 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
722 |
last_w = w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
723 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
724 |
if (w) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
725 |
// send an event in client coordinates. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
726 |
e.event = WE_MOUSEOVER; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
727 |
e.mouseover.pt.x = _cursor.pos.x - w->left; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
728 |
e.mouseover.pt.y = _cursor.pos.y - w->top; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
729 |
if (w->widget != NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
730 |
e.mouseover.widget = GetWidgetFromPos(w, e.mouseover.pt.x, e.mouseover.pt.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
731 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
732 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
733 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
734 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
735 |
// Mouseover never stops execution |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
736 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
737 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
738 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
739 |
bool HandleWindowDragging() |
0 | 740 |
{ |
741 |
Window *w; |
|
742 |
// Get out immediately if no window is being dragged at all. |
|
743 |
if (!_dragging_window) |
|
744 |
return true; |
|
745 |
||
746 |
// Otherwise find the window... |
|
350 | 747 |
for (w = _windows; w != _last_window; w++) { |
748 |
if (w->flags4 & WF_DRAGGING) { |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
749 |
const Widget *t = &w->widget[1]; // the title bar ... ugh |
350 | 750 |
const Window *v; |
751 |
int x; |
|
752 |
int y; |
|
753 |
int nx; |
|
754 |
int ny; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
755 |
|
0 | 756 |
// Stop the dragging if the left mouse button was released |
757 |
if (!_left_button_down) { |
|
350 | 758 |
w->flags4 &= ~WF_DRAGGING; |
0 | 759 |
break; |
760 |
} |
|
761 |
||
762 |
SetWindowDirty(w); |
|
763 |
||
350 | 764 |
x = _cursor.pos.x + _drag_delta.x; |
765 |
y = _cursor.pos.y + _drag_delta.y; |
|
766 |
nx = x; |
|
767 |
ny = y; |
|
768 |
||
769 |
if (_patches.window_snap_radius != 0) { |
|
353 | 770 |
int hsnap = _patches.window_snap_radius; |
771 |
int vsnap = _patches.window_snap_radius; |
|
772 |
int delta; |
|
350 | 773 |
|
774 |
for (v = _windows; v != _last_window; ++v) { |
|
775 |
if (v == w) continue; // Don't snap at yourself |
|
776 |
||
777 |
if (y + w->height > v->top && y < v->top + v->height) { |
|
778 |
// Your left border <-> other right border |
|
779 |
delta = abs(v->left + v->width - x); |
|
780 |
if (delta <= hsnap) { |
|
781 |
nx = v->left + v->width; |
|
782 |
hsnap = delta; |
|
783 |
} |
|
784 |
||
785 |
// Your right border <-> other left border |
|
786 |
delta = abs(v->left - x - w->width); |
|
787 |
if (delta <= hsnap) { |
|
788 |
nx = v->left - w->width; |
|
789 |
hsnap = delta; |
|
790 |
} |
|
791 |
} |
|
792 |
||
353 | 793 |
if (w->top + w->height >= v->top && w->top <= v->top + v->height) { |
794 |
// Your left border <-> other left border |
|
795 |
delta = abs(v->left - x); |
|
796 |
if (delta <= hsnap) { |
|
797 |
nx = v->left; |
|
798 |
hsnap = delta; |
|
799 |
} |
|
800 |
||
801 |
// Your right border <-> other right border |
|
802 |
delta = abs(v->left + v->width - x - w->width); |
|
803 |
if (delta <= hsnap) { |
|
804 |
nx = v->left + v->width - w->width; |
|
805 |
hsnap = delta; |
|
806 |
} |
|
807 |
} |
|
808 |
||
350 | 809 |
if (x + w->width > v->left && x < v->left + v->width) { |
810 |
// Your top border <-> other bottom border |
|
811 |
delta = abs(v->top + v->height - y); |
|
812 |
if (delta <= vsnap) { |
|
813 |
ny = v->top + v->height; |
|
814 |
vsnap = delta; |
|
815 |
} |
|
816 |
||
817 |
// Your bottom border <-> other top border |
|
818 |
delta = abs(v->top - y - w->height); |
|
819 |
if (delta <= vsnap) { |
|
820 |
ny = v->top - w->height; |
|
821 |
vsnap = delta; |
|
822 |
} |
|
823 |
} |
|
353 | 824 |
|
825 |
if (w->left + w->width >= v->left && w->left <= v->left + v->width) { |
|
826 |
// Your top border <-> other top border |
|
827 |
delta = abs(v->top - y); |
|
828 |
if (delta <= vsnap) { |
|
829 |
ny = v->top; |
|
830 |
vsnap = delta; |
|
831 |
} |
|
832 |
||
833 |
// Your bottom border <-> other bottom border |
|
834 |
delta = abs(v->top + v->height - y - w->height); |
|
835 |
if (delta <= vsnap) { |
|
836 |
ny = v->top + v->height - w->height; |
|
837 |
vsnap = delta; |
|
838 |
} |
|
839 |
} |
|
0 | 840 |
} |
841 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
842 |
|
350 | 843 |
// Make sure the window doesn't leave the screen |
844 |
// 13 is the height of the title bar |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
845 |
nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
350 | 846 |
ny = clamp(ny, 0, _screen.height - 13); |
847 |
||
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
848 |
// Make sure the title bar isn't hidden by behind the main tool bar |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
849 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
850 |
if (v != NULL) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
851 |
int v_bottom = v->top + v->height; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
852 |
int v_right = v->left + v->width; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
853 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
371 | 854 |
if ((v->left < 13 && nx + t->left < v->left) || |
855 |
(v_right > _screen.width - 13 && nx + t->right > v_right)) { |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
856 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
857 |
} else { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
858 |
if (nx + t->left > v->left - 13 && |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
859 |
nx + t->right < v_right + 13) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
860 |
if (w->top >= v_bottom) |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
861 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
862 |
else if (w->left < nx) |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
863 |
nx = v->left - 13 - t->left; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
864 |
else |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
865 |
nx = v_right + 13 - t->right; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
866 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
867 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
868 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
869 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
870 |
|
350 | 871 |
if (w->viewport != NULL) { |
872 |
w->viewport->left += nx - w->left; |
|
873 |
w->viewport->top += ny - w->top; |
|
874 |
} |
|
875 |
w->left = nx; |
|
876 |
w->top = ny; |
|
877 |
||
0 | 878 |
SetWindowDirty(w); |
879 |
return false; |
|
880 |
} |
|
881 |
} |
|
882 |
||
883 |
_dragging_window = false; |
|
884 |
return false; |
|
885 |
} |
|
886 |
||
887 |
Window *StartWindowDrag(Window *w) |
|
888 |
{ |
|
889 |
w->flags4 |= WF_DRAGGING; |
|
890 |
_dragging_window = true; |
|
350 | 891 |
_drag_delta.x = w->left - _cursor.pos.x; |
892 |
_drag_delta.y = w->top - _cursor.pos.y; |
|
0 | 893 |
w = BringWindowToFront(w); |
894 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
|
895 |
return w; |
|
896 |
} |
|
897 |
||
898 |
Window *StartWindowSizing(Window *w) |
|
899 |
{ |
|
900 |
w->flags4 |= WF_SIZING; |
|
901 |
_dragging_window = true; |
|
902 |
_cursorpos_drag_start = _cursor.pos; |
|
903 |
w = BringWindowToFront(w); |
|
904 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
|
905 |
return w; |
|
906 |
} |
|
907 |
||
908 |
||
410 | 909 |
static bool HandleScrollbarScrolling() |
0 | 910 |
{ |
911 |
Window *w; |
|
912 |
int i; |
|
913 |
int pos; |
|
914 |
Scrollbar *sb; |
|
915 |
||
916 |
// Get out quickly if no item is being scrolled |
|
917 |
if (!_scrolling_scrollbar) |
|
918 |
return true; |
|
919 |
||
920 |
// Find the scrolling window |
|
921 |
for(w=_windows; w != _last_window; w++) { |
|
922 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
|
923 |
// Abort if no button is clicked any more. |
|
924 |
if (!_left_button_down) { |
|
925 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
926 |
SetWindowDirty(w); |
|
927 |
break; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
928 |
} |
0 | 929 |
|
930 |
if (w->flags4 & WF_HSCROLL) { |
|
931 |
sb = &w->hscroll; |
|
932 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
933 |
} else { |
|
934 |
sb = &w->vscroll; |
|
935 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
936 |
} |
|
937 |
||
938 |
// Find the item we want to move to and make sure it's inside bounds. |
|
939 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
|
940 |
if (pos != sb->pos) { |
|
941 |
sb->pos = pos; |
|
942 |
SetWindowDirty(w); |
|
943 |
} |
|
944 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
945 |
} |
0 | 946 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
947 |
|
0 | 948 |
_scrolling_scrollbar = false; |
949 |
return false; |
|
950 |
} |
|
951 |
||
410 | 952 |
static bool HandleViewportScroll() |
0 | 953 |
{ |
954 |
Window *w; |
|
955 |
ViewPort *vp; |
|
956 |
int dx,dy, x, y, sub; |
|
957 |
||
958 |
if (!_scrolling_viewport) |
|
959 |
return true; |
|
960 |
||
961 |
if (!_right_button_down) { |
|
962 |
stop_capt:; |
|
963 |
_cursor.fix_at = false; |
|
964 |
_scrolling_viewport = false; |
|
965 |
return true; |
|
966 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
967 |
|
0 | 968 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
969 |
if (w == NULL) goto stop_capt; |
|
970 |
||
971 |
if (w->window_class != WC_SMALLMAP) { |
|
972 |
vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); |
|
973 |
if (vp == NULL) |
|
974 |
goto stop_capt; |
|
975 |
||
976 |
WP(w,vp_d).scrollpos_x += _cursor.delta.x << vp->zoom; |
|
977 |
WP(w,vp_d).scrollpos_y += _cursor.delta.y << vp->zoom; |
|
978 |
_cursor.delta.x = _cursor.delta.y = 0; |
|
979 |
return false; |
|
980 |
} else { |
|
981 |
// scroll the smallmap ? |
|
647
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
982 |
int hx; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
983 |
int hy; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
984 |
int hvx; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
985 |
int hvy; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
986 |
|
0 | 987 |
_cursor.fix_at = true; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
988 |
|
0 | 989 |
dx = _cursor.delta.x; |
990 |
dy = _cursor.delta.y; |
|
991 |
||
992 |
x = WP(w,smallmap_d).scroll_x; |
|
993 |
y = WP(w,smallmap_d).scroll_y; |
|
994 |
||
995 |
sub = WP(w,smallmap_d).subscroll + dx; |
|
996 |
||
997 |
x -= (sub >> 2) << 4; |
|
998 |
y += (sub >> 2) << 4; |
|
999 |
sub &= 3; |
|
1000 |
||
1001 |
x += (dy >> 1) << 4; |
|
1002 |
y += (dy >> 1) << 4; |
|
1003 |
||
1004 |
if (dy & 1) { |
|
1005 |
x += 16; |
|
1006 |
sub += 2; |
|
1007 |
if (sub > 3) { |
|
1008 |
sub -= 4; |
|
1009 |
x -= 16; |
|
1010 |
y += 16; |
|
1011 |
} |
|
1012 |
} |
|
1013 |
||
647
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1014 |
hx = (w->widget[4].right - w->widget[4].left) / 2; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1015 |
hy = (w->widget[4].bottom - w->widget[4].top ) / 2; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1016 |
hvx = hx * -4 + hy * 8; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1017 |
hvy = hx * 4 + hy * 8; |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1018 |
if (x < -hvx) { x = -hvx; sub = 0; } |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1019 |
if (x > TILE_X_MAX * 16 - hvx) { x = TILE_X_MAX * 16 - hvx; sub = 0; } |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1020 |
if (y < -hvy) { y = -hvy; sub = 0; } |
0a3dabcc1082
(svn r1080) Improve mini-map scrolling in a similar way as viewport scrolling (r1063): now the centre of the mini-map window is the region of interest instead some arbitrary coordinate.
tron
parents:
543
diff
changeset
|
1021 |
if (y > TILE_Y_MAX * 16 - hvy) { y = TILE_Y_MAX * 16 - hvy; sub = 0; } |
0 | 1022 |
|
1023 |
WP(w,smallmap_d).scroll_x = x; |
|
1024 |
WP(w,smallmap_d).scroll_y = y; |
|
1025 |
WP(w,smallmap_d).subscroll = sub; |
|
1026 |
||
1027 |
_cursor.delta.x = _cursor.delta.y = 0; |
|
1028 |
||
1029 |
SetWindowDirty(w); |
|
1030 |
return false; |
|
1031 |
} |
|
1032 |
} |
|
1033 |
||
1034 |
static Window *MaybeBringWindowToFront(Window *w) |
|
1035 |
{ |
|
1036 |
Window *u; |
|
1037 |
||
1038 |
if (w->window_class == WC_MAIN_WINDOW || |
|
1039 |
w->window_class == WC_MAIN_TOOLBAR || |
|
1040 |
w->window_class == WC_STATUS_BAR || |
|
1041 |
w->window_class == WC_NEWS_WINDOW || |
|
1042 |
w->window_class == WC_TOOLTIPS || |
|
1043 |
w->window_class == WC_DROPDOWN_MENU) |
|
1044 |
return w; |
|
1045 |
||
1046 |
for(u=w; ++u != _last_window;) { |
|
1047 |
if (u->window_class == WC_MAIN_WINDOW || u->window_class==WC_MAIN_TOOLBAR || u->window_class==WC_STATUS_BAR || |
|
1048 |
u->window_class == WC_NEWS_WINDOW || u->window_class == WC_TOOLTIPS || u->window_class == WC_DROPDOWN_MENU) |
|
1049 |
continue; |
|
1050 |
||
1051 |
if (w->left + w->width <= u->left || |
|
1052 |
u->left + u->width <= w->left || |
|
1053 |
w->top + w->height <= u->top || |
|
1054 |
u->top + u->height <= w->top) |
|
1055 |
continue; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1056 |
|
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1057 |
return BringWindowToFront(w); |
0 | 1058 |
} |
1059 |
||
1060 |
return w; |
|
1061 |
} |
|
1062 |
||
1063 |
static void HandleKeypress(uint32 key) |
|
1064 |
{ |
|
1065 |
Window *w; |
|
1066 |
WindowEvent we; |
|
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1067 |
/* Stores if a window with a textfield for typing is open |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1068 |
* If this is the case, keypress events are only passed to windows with text fields and |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1069 |
* to thein this main toolbar. */ |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1070 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1071 |
|
0 | 1072 |
// Setup event |
1073 |
we.keypress.event = WE_KEYPRESS; |
|
1074 |
we.keypress.ascii = key & 0xFF; |
|
1075 |
we.keypress.keycode = key >> 16; |
|
1076 |
we.keypress.cont = true; |
|
1077 |
||
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1078 |
// check if we have a query string window open before allowing hotkeys |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1079 |
if(FindWindowById(WC_QUERY_STRING, 0)!=NULL || FindWindowById(WC_SEND_NETWORK_MSG, 0)!=NULL) |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1080 |
query_open = true; |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1081 |
|
0 | 1082 |
// Call the event, start with the uppermost window. |
1083 |
for(w=_last_window; w != _windows;) { |
|
1084 |
--w; |
|
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1085 |
// if a query window is open, only call the event for certain window types |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1086 |
if(query_open && w->window_class!=WC_QUERY_STRING && w->window_class!=WC_SEND_NETWORK_MSG && w->window_class!=WC_MAIN_TOOLBAR) |
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1087 |
continue; |
0 | 1088 |
w->wndproc(w, &we); |
1089 |
if (!we.keypress.cont) |
|
1090 |
break; |
|
1091 |
} |
|
1092 |
} |
|
1093 |
||
1094 |
extern void UpdateTileSelection(); |
|
1095 |
extern bool VpHandlePlaceSizingDrag(); |
|
1096 |
||
1097 |
void MouseLoop() |
|
1098 |
{ |
|
1099 |
int x,y; |
|
1100 |
Window *w; |
|
1101 |
ViewPort *vp; |
|
1102 |
int click; |
|
1103 |
int mousewheel; |
|
1104 |
||
1105 |
_current_player = _local_player; |
|
1106 |
||
1107 |
// Handle pressed keys |
|
1108 |
if (_pressed_key) { |
|
1109 |
uint32 key = _pressed_key; _pressed_key = 0; |
|
1110 |
HandleKeypress(key); |
|
1111 |
} |
|
1112 |
||
1113 |
// Mouse event? |
|
1114 |
click = 0; |
|
1115 |
if (_left_button_down && !_left_button_clicked) { |
|
1116 |
_left_button_clicked = true; |
|
1117 |
click = 1; |
|
1118 |
} else if (_right_button_clicked) { |
|
1119 |
_right_button_clicked = false; |
|
1120 |
click = 2; |
|
1121 |
} |
|
1122 |
||
1123 |
mousewheel = 0; |
|
1124 |
if (_cursor.wheel) { |
|
1125 |
mousewheel = _cursor.wheel; |
|
1126 |
_cursor.wheel = 0; |
|
1127 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1128 |
|
0 | 1129 |
DecreaseWindowCounters(); |
1130 |
HandlePlacePresize(); |
|
1131 |
UpdateTileSelection(); |
|
1132 |
if (!VpHandlePlaceSizingDrag()) |
|
1133 |
return; |
|
1134 |
||
1135 |
if (!HandleDragDrop()) |
|
1136 |
return; |
|
1137 |
||
1138 |
if (!HandlePopupMenu()) |
|
1139 |
return; |
|
1140 |
||
1141 |
if (!HandleWindowDragging()) |
|
1142 |
return; |
|
1143 |
||
1144 |
if (!HandleScrollbarScrolling()) |
|
1145 |
return; |
|
1146 |
||
1147 |
if (!HandleViewportScroll()) |
|
1148 |
return; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1149 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1150 |
if (!HandleMouseOver()) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1151 |
return; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1152 |
|
0 | 1153 |
x = _cursor.pos.x; |
1154 |
y = _cursor.pos.y; |
|
1155 |
||
1156 |
||
1157 |
if (click == 0 && mousewheel == 0) { |
|
1158 |
if (_patches.autoscroll && _game_mode != GM_MENU) { |
|
1159 |
w = FindWindowFromPt(x, y); |
|
1160 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL ) return; |
|
1161 |
vp = IsPtInWindowViewport(w, x, y); |
|
1162 |
if (vp) { |
|
1163 |
x -= vp->left; |
|
1164 |
y -= vp->top; |
|
1165 |
//here allows scrolling in both x and y axis |
|
1166 |
#define scrollspeed 3 |
|
1167 |
if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; } |
|
1168 |
else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; } |
|
1169 |
if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; } |
|
1170 |
else if (15-(vp->height-y) > 0) { WP(w,vp_d).scrollpos_y += (15-(vp->height-y))*scrollspeed << vp->zoom; } |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1171 |
#undef scrollspeed |
0 | 1172 |
} |
1173 |
} |
|
1174 |
return; |
|
1175 |
} |
|
1176 |
||
1177 |
w = FindWindowFromPt(x, y); |
|
1178 |
if (w == NULL) |
|
1179 |
return; |
|
1180 |
w = MaybeBringWindowToFront(w); |
|
1181 |
vp = IsPtInWindowViewport(w, x, y); |
|
1182 |
if (vp != NULL) { |
|
1183 |
if (_game_mode == GM_MENU) |
|
1184 |
return; |
|
1185 |
||
178
7d91f0b06c8b
(svn r179) -Fix: [1023971] Fix for MouseWheel assert error in non-zoomable viewports. Zooming now will only occur if mousepointer is either in an extra viewport window, or main game-window (Dribbel)
darkvater
parents:
158
diff
changeset
|
1186 |
// only allow zooming in-out in main window, or in viewports |
193
0a7025304867
(svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents:
178
diff
changeset
|
1187 |
if ( mousewheel && !(w->flags4 & WF_DISABLE_VP_SCROLL) && |
178
7d91f0b06c8b
(svn r179) -Fix: [1023971] Fix for MouseWheel assert error in non-zoomable viewports. Zooming now will only occur if mousepointer is either in an extra viewport window, or main game-window (Dribbel)
darkvater
parents:
158
diff
changeset
|
1188 |
(w->window_class == WC_MAIN_WINDOW || w->window_class == WC_EXTRA_VIEW_PORT) ) { |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
1189 |
ZoomInOrOutToCursorWindow(mousewheel < 0,w); |
0 | 1190 |
} |
1191 |
||
1192 |
if (click == 1) { |
|
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
69
diff
changeset
|
1193 |
DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
0 | 1194 |
if (_thd.place_mode != 0 && |
67
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
0
diff
changeset
|
1195 |
// query button and place sign button work in pause mode |
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
0
diff
changeset
|
1196 |
!(_cursor.sprite == 0x2CF || _cursor.sprite == 0x2D2) && |
0 | 1197 |
_pause != 0 && |
67
b2b551af3d9f
(svn r68) -Fix: [1009621] build in pause is now a cheat instead of a patch (truesatan)
darkvater
parents:
0
diff
changeset
|
1198 |
!_cheats.build_in_pause.value) |
0 | 1199 |
return; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1200 |
|
0 | 1201 |
if (_thd.place_mode == 0) { |
1202 |
HandleViewportClicked(vp, x, y); |
|
1203 |
} else { |
|
1204 |
PlaceObject(); |
|
1205 |
} |
|
1206 |
} else if (click == 2) { |
|
1207 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { |
|
1208 |
_scrolling_viewport = true; |
|
1209 |
_cursor.fix_at = true; |
|
1210 |
} |
|
1211 |
} |
|
1212 |
} else { |
|
1213 |
if (mousewheel) |
|
1214 |
DispatchMouseWheelEvent(w, mousewheel); |
|
1215 |
||
1216 |
if (click == 1) |
|
1217 |
DispatchLeftClickEvent(w, x - w->left, y - w->top); |
|
1218 |
else if (click == 2) |
|
1219 |
DispatchRightClickEvent(w, x - w->left, y - w->top); |
|
1220 |
} |
|
1221 |
} |
|
1222 |
||
1223 |
static int _we4_timer; |
|
1224 |
||
1225 |
extern uint32 _pixels_redrawn; |
|
1226 |
||
1227 |
void UpdateWindows() |
|
1228 |
{ |
|
1229 |
Window *w; |
|
1230 |
int t; |
|
1231 |
||
1232 |
||
1233 |
if ((t=_we4_timer+1) >= 100) { |
|
1234 |
for(w = _last_window; w != _windows;) { |
|
1235 |
w--; |
|
1236 |
CallWindowEventNP(w, WE_4); |
|
1237 |
} |
|
1238 |
t = 0; |
|
1239 |
} |
|
1240 |
_we4_timer = t; |
|
1241 |
||
1242 |
for(w = _last_window; w != _windows;) { |
|
1243 |
w--; |
|
1244 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
|
1245 |
w->flags4 -= WF_WHITE_BORDER_ONE; |
|
1246 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) { |
|
1247 |
SetWindowDirty(w); |
|
1248 |
} |
|
1249 |
} |
|
1250 |
} |
|
1251 |
||
1252 |
DrawDirtyBlocks(); |
|
1253 |
||
1254 |
for(w = _windows; w!=_last_window; w++) { |
|
1255 |
if (w->viewport != NULL) |
|
1256 |
UpdateViewportPosition(w); |
|
1257 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1258 |
DrawTextMessage(); |
0 | 1259 |
// Redraw mouse cursor in case it was hidden |
1260 |
DrawMouseCursor(); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1261 |
} |
0 | 1262 |
|
1263 |
||
1264 |
int GetMenuItemIndex(Window *w, int x, int y) |
|
1265 |
{ |
|
1266 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
1267 |
y /= 10; |
|
1268 |
||
1269 |
if (y < WP(w,menu_d).item_count) |
|
1270 |
return y; |
|
1271 |
} |
|
1272 |
return -1; |
|
1273 |
} |
|
1274 |
||
1275 |
void InvalidateWindow(byte cls, WindowNumber number) |
|
1276 |
{ |
|
1277 |
Window *w; |
|
1278 |
||
1279 |
for(w=_windows; w!=_last_window; w++) { |
|
1280 |
if (w->window_class==cls && w->window_number==number) |
|
1281 |
SetWindowDirty(w); |
|
1282 |
} |
|
1283 |
} |
|
1284 |
||
1285 |
void InvalidateWidget(Window *w, byte widget_index) |
|
1286 |
{ |
|
1287 |
const Widget *wi = &w->widget[widget_index]; |
|
1288 |
// if (wi->left != -2) { |
|
1289 |
SetDirtyBlocks( |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1290 |
w->left + wi->left, |
0 | 1291 |
w->top + wi->top, |
1292 |
w->left + wi->right + 1, |
|
1293 |
w->top + wi->bottom + 1); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1294 |
// } |
0 | 1295 |
} |
1296 |
||
1297 |
void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index) |
|
1298 |
{ |
|
1299 |
Window *w; |
|
1300 |
||
1301 |
for(w=_windows; w!=_last_window; w++) { |
|
1302 |
if (w->window_class==cls && w->window_number==number) { |
|
1303 |
InvalidateWidget(w, widget_index); |
|
1304 |
} |
|
1305 |
} |
|
1306 |
} |
|
1307 |
||
1308 |
void InvalidateWindowClasses(byte cls) |
|
1309 |
{ |
|
1310 |
Window *w; |
|
1311 |
for(w=_windows; w!=_last_window; w++) { |
|
1312 |
if (w->window_class==cls) |
|
1313 |
SetWindowDirty(w); |
|
1314 |
} |
|
1315 |
} |
|
1316 |
||
1317 |
||
1318 |
void CallWindowTickEvent() |
|
1319 |
{ |
|
1320 |
Window *w; |
|
1321 |
for(w=_last_window; w != _windows;) { |
|
1322 |
--w; |
|
1323 |
CallWindowEventNP(w, WE_TICK); |
|
1324 |
} |
|
1325 |
} |
|
1326 |
||
1327 |
void DeleteNonVitalWindows() |
|
1328 |
{ |
|
1329 |
Window *w; |
|
1330 |
for(w=_windows; w!=_last_window;) { |
|
1331 |
if (w->window_class != WC_MAIN_WINDOW && |
|
1332 |
w->window_class != WC_SELECT_GAME && |
|
1333 |
w->window_class != WC_MAIN_TOOLBAR && |
|
1334 |
w->window_class != WC_STATUS_BAR && |
|
1335 |
w->window_class != WC_TOOLBAR_MENU && |
|
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
1336 |
w->window_class != WC_TOOLTIPS && |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
1337 |
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned' |
0 | 1338 |
DeleteWindow(w); |
1339 |
w = _windows; |
|
1340 |
} else { |
|
1341 |
w++; |
|
1342 |
} |
|
1343 |
} |
|
1344 |
} |
|
1345 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1346 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1347 |
{ |
69 | 1348 |
DEBUG(misc, 1) ("Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1349 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1350 |
if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1351 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1352 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1353 |
switch (_patches.toolbar_pos) { |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1354 |
case 1: w->left = (_screen.width - w->width) >> 1; break; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1355 |
case 2: w->left = _screen.width - w->width; break; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1356 |
default: w->left = 0; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1357 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1358 |
SetDirtyBlocks(0, 0, _screen.width, w->height); // invalidate the whole top part |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1359 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1360 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1361 |
|
0 | 1362 |
void RelocateAllWindows(int neww, int newh) |
1363 |
{ |
|
1364 |
Window *w; |
|
1365 |
||
1366 |
for(w=_windows; w!= _last_window ;w++) { |
|
1367 |
int left, top; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1368 |
|
0 | 1369 |
if (w->window_class == WC_MAIN_WINDOW) { |
1370 |
ViewPort *vp = w->viewport; |
|
1371 |
vp->width = w->width = neww; |
|
1372 |
vp->height = w->height = newh; |
|
1373 |
vp->virtual_width = neww << vp->zoom; |
|
1374 |
vp->virtual_height = newh << vp->zoom; |
|
1375 |
continue; // don't modify top,left |
|
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
1376 |
} |
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
1377 |
|
126 | 1378 |
IConsoleResize(); |
0 | 1379 |
|
1380 |
if (w->window_class == WC_MAIN_TOOLBAR) { |
|
1381 |
top = w->top; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1382 |
left = PositionMainToolbar(w); // changes toolbar orientation |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1383 |
} else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){ |
0 | 1384 |
top = (newh - w->height) >> 1; |
1385 |
left = (neww - w->width) >> 1; |
|
1386 |
} else if (w->window_class == WC_NEWS_WINDOW) { |
|
1387 |
top = newh - w->height; |
|
1388 |
left = (neww - w->width) >> 1; |
|
1389 |
} else if (w->window_class == WC_STATUS_BAR) { |
|
1390 |
top = newh - w->height; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1391 |
left = (neww - w->width) >> 1; |
649 | 1392 |
} else if (w->window_class == WC_SEND_NETWORK_MSG) { |
1393 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
|
1394 |
left = (neww - w->width) >> 1; |
|
0 | 1395 |
} else { |
1396 |
left = w->left; |
|
1397 |
if (left + (w->width>>1) >= neww) left = neww - w->width; |
|
1398 |
top = w->top; |
|
1399 |
if (top + (w->height>>1) >= newh) top = newh - w->height; |
|
1400 |
} |
|
1401 |
||
1402 |
if (w->viewport) { |
|
1403 |
w->viewport->left += left - w->left; |
|
1404 |
w->viewport->top += top - w->top; |
|
1405 |
} |
|
1406 |
||
1407 |
w->left = left; |
|
1408 |
w->top = top; |
|
1409 |
} |
|
1410 |
} |