author | tron |
Sat, 05 Feb 2005 15:58:59 +0000 | |
changeset 1299 | 0a6510cc889b |
parent 1112 | 32f3e7a98095 |
child 1397 | b04402b901cd |
permissions | -rw-r--r-- |
0 | 1 |
#include "stdafx.h" |
2 |
#include "ttd.h" |
|
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1112
diff
changeset
|
3 |
#include "debug.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
|
4 |
#include "map.h" |
0 | 5 |
#include "window.h" |
6 |
#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
|
7 |
#include "viewport.h" |
126 | 8 |
#include "console.h" |
0 | 9 |
|
350 | 10 |
// delta between mouse cursor and upper left corner of dragged window |
11 |
static Point _drag_delta; |
|
12 |
||
0 | 13 |
void HandleButtonClick(Window *w, byte widget) |
14 |
{ |
|
15 |
w->click_state |= (1 << widget); |
|
16 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
|
17 |
InvalidateWidget(w, widget); |
|
18 |
} |
|
19 |
||
20 |
void DispatchLeftClickEvent(Window *w, int x, int y) { |
|
21 |
WindowEvent e; |
|
22 |
const Widget *wi; |
|
23 |
||
24 |
e.click.pt.x = x; |
|
25 |
e.click.pt.y = y; |
|
26 |
e.event = WE_CLICK; |
|
27 |
||
28 |
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
|
29 |
e.click.widget = GetWidgetFromPos(w, x, y); |
0 | 30 |
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
|
31 |
|
0 | 32 |
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
|
33 |
|
211 | 34 |
/* don't allow any interaction if the button has been disabled */ |
35 |
if (HASBIT(w->disabled_state, e.click.widget)) |
|
36 |
return; |
|
0 | 37 |
|
38 |
if (wi->type & 0xE0) { |
|
211 | 39 |
/* special widget handling for buttons*/ |
0 | 40 |
switch(wi->type) { |
211 | 41 |
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ |
42 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
|
0 | 43 |
HandleButtonClick(w, e.click.widget); |
44 |
break; |
|
45 |
case WWT_NODISTXTBTN: |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
46 |
break; |
0 | 47 |
} |
842 | 48 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) { |
0 | 49 |
ScrollbarClickHandler(w, wi, e.click.pt.x, e.click.pt.y); |
50 |
} |
|
51 |
||
52 |
if (w->desc_flags & WDF_STD_BTN) { |
|
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
53 |
if (e.click.widget == 0) { /* 'X' */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
54 |
DeleteWindow(w); |
984
a50e131688d2
(svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents:
983
diff
changeset
|
55 |
return; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
56 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
57 |
|
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
58 |
if (e.click.widget == 1) { /* 'Title bar' */ |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
59 |
StartWindowDrag(w); // if not return then w = StartWindowDrag(w); to get correct pointer |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
60 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
61 |
} |
0 | 62 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
63 |
|
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
64 |
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) { |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
65 |
StartWindowSizing(w); // if not return then w = StartWindowSizing(w); to get correct pointer |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
66 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
67 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
68 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
69 |
if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) { |
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
70 |
TOGGLEBIT(w->click_state, e.click.widget); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
71 |
w->flags4 ^= WF_STICKY; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
72 |
InvalidateWidget(w, e.click.widget); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
73 |
return; |
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
|
74 |
} |
0 | 75 |
} |
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
76 |
|
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
77 |
w->wndproc(w, &e); |
0 | 78 |
} |
79 |
||
80 |
void DispatchRightClickEvent(Window *w, int x, int y) { |
|
81 |
WindowEvent e; |
|
82 |
||
83 |
/* default tooltips handler? */ |
|
84 |
if (w->desc_flags & WDF_STD_TOOLTIPS) { |
|
85 |
e.click.widget = GetWidgetFromPos(w, x, y); |
|
86 |
if (e.click.widget < 0) |
|
87 |
return; /* exit if clicked outside of widgets */ |
|
88 |
||
89 |
if (w->widget[e.click.widget].tooltips != 0) { |
|
90 |
GuiShowTooltips(w->widget[e.click.widget].tooltips); |
|
91 |
return; |
|
92 |
} |
|
93 |
} |
|
94 |
||
95 |
e.event = WE_RCLICK; |
|
96 |
e.click.pt.x = x; |
|
97 |
e.click.pt.y = y; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
98 |
w->wndproc(w, &e); |
0 | 99 |
} |
100 |
||
101 |
||
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
102 |
void DispatchMouseWheelEvent(Window *w, uint widget, int wheel) |
0 | 103 |
{ |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
104 |
const Widget *wi1 = &w->widget[widget]; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
105 |
const Widget *wi2 = &w->widget[widget + 1]; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
106 |
Scrollbar *sb; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
107 |
|
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
108 |
/* The listbox can only scroll if scrolling was done on the scrollbar itself, |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
109 |
* or on the listbox (and the next item is (must be) the scrollbar) |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
110 |
* XXX - should be rewritten as a widget-dependent scroller but that's |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
111 |
* not happening until someone rewrites the whole widget-code */ |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
112 |
if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) || |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
113 |
(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
114 |
|
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
115 |
if (sb->count > sb->cap) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
116 |
int pos = clamp(sb->pos + wheel, 0, sb->count - sb->cap); |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
117 |
if (pos != sb->pos) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
118 |
sb->pos = pos; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
119 |
SetWindowDirty(w); |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
120 |
} |
0 | 121 |
} |
122 |
} |
|
123 |
} |
|
124 |
||
125 |
||
126 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
|
127 |
{ |
|
128 |
Window *w; |
|
129 |
DrawPixelInfo bk; |
|
130 |
_cur_dpi = &bk; |
|
131 |
||
132 |
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
|
133 |
if (right > w->left && |
0 | 134 |
bottom > w->top && |
135 |
left < w->left + w->width && |
|
136 |
top < w->top + w->height) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
137 |
DrawOverlappedWindow(w, left, top, right, bottom); |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
138 |
} |
0 | 139 |
} |
140 |
} |
|
141 |
||
142 |
void DrawOverlappedWindow(Window *w, int left, int top, int right, int bottom) |
|
143 |
{ |
|
144 |
Window *v = w; |
|
145 |
int x; |
|
146 |
||
147 |
while (++v != _last_window) { |
|
148 |
if (right > v->left && |
|
149 |
bottom > v->top && |
|
150 |
left < v->left + v->width && |
|
151 |
top < v->top + v->height) { |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
152 |
|
0 | 153 |
if (left < (x=v->left)) { |
154 |
DrawOverlappedWindow(w, left, top, x, bottom); |
|
155 |
DrawOverlappedWindow(w, x, top, right, bottom); |
|
156 |
return; |
|
157 |
} |
|
158 |
||
159 |
if (right > (x=v->left + v->width)) { |
|
160 |
DrawOverlappedWindow(w, left, top, x, bottom); |
|
161 |
DrawOverlappedWindow(w, x, top, right, bottom); |
|
162 |
return; |
|
163 |
} |
|
164 |
||
165 |
if (top < (x=v->top)) { |
|
166 |
DrawOverlappedWindow(w, left, top, right, x); |
|
167 |
DrawOverlappedWindow(w, left, x, right, bottom); |
|
168 |
return; |
|
169 |
} |
|
170 |
||
171 |
if (bottom > (x=v->top + v->height)) { |
|
172 |
DrawOverlappedWindow(w, left, top, right, x); |
|
173 |
DrawOverlappedWindow(w, left, x, right, bottom); |
|
174 |
return; |
|
175 |
} |
|
176 |
||
177 |
return; |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
182 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 183 |
dp->width = right - left; |
184 |
dp->height = bottom - top; |
|
185 |
dp->left = left - w->left; |
|
186 |
dp->top = top - w->top; |
|
187 |
dp->pitch = _screen.pitch; |
|
188 |
dp->dst_ptr = _screen.dst_ptr + top * _screen.pitch + left; |
|
189 |
dp->zoom = 0; |
|
190 |
CallWindowEventNP(w, WE_PAINT); |
|
191 |
} |
|
192 |
} |
|
193 |
||
194 |
void CallWindowEventNP(Window *w, int event) |
|
195 |
{ |
|
196 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
197 |
|
0 | 198 |
e.event = event; |
199 |
w->wndproc(w, &e); |
|
200 |
} |
|
201 |
||
202 |
void SetWindowDirty(Window *w) |
|
203 |
{ |
|
204 |
if (w == NULL) |
|
205 |
return; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
206 |
|
0 | 207 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); |
208 |
} |
|
209 |
||
210 |
void DeleteWindow(Window *w) |
|
211 |
{ |
|
212 |
WindowClass wc; |
|
213 |
WindowNumber wn; |
|
214 |
ViewPort *vp; |
|
215 |
Window *v; |
|
216 |
int count; |
|
217 |
||
218 |
if (w == NULL) |
|
219 |
return; |
|
220 |
||
221 |
if (_thd.place_mode != 0 && _thd.window_class == w->window_class && _thd.window_number == w->window_number) { |
|
222 |
ResetObjectToPlace(); |
|
223 |
} |
|
224 |
||
225 |
wc = w->window_class; |
|
226 |
wn = w->window_number; |
|
227 |
||
228 |
CallWindowEventNP(w, WE_DESTROY); |
|
229 |
||
230 |
w = FindWindowById(wc, wn); |
|
231 |
||
232 |
vp = w->viewport; |
|
233 |
w->viewport = NULL; |
|
234 |
if (vp != NULL) { |
|
235 |
_active_viewports &= ~(1 << (vp - _viewports)); |
|
236 |
vp->width = 0; |
|
237 |
} |
|
238 |
||
239 |
SetWindowDirty(w); |
|
240 |
||
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
241 |
free(w->widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
242 |
|
0 | 243 |
v = --_last_window; |
244 |
count = (byte*)v - (byte*)w; |
|
1033
d7eac041c97f
(svn r1534) Use memmove() instead of memcpy() when copying overlapping memory (tamlin)
tron
parents:
1019
diff
changeset
|
245 |
memmove(w, w + 1, count); |
0 | 246 |
} |
247 |
||
248 |
Window *FindWindowById(WindowClass cls, WindowNumber number) |
|
249 |
{ |
|
250 |
Window *w; |
|
251 |
||
252 |
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
|
253 |
if (w->window_class == cls && |
0 | 254 |
w->window_number == number) { |
255 |
return w; |
|
256 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
257 |
} |
0 | 258 |
|
259 |
return NULL; |
|
260 |
} |
|
261 |
||
262 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
|
263 |
{ |
|
264 |
DeleteWindow(FindWindowById(cls, number)); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
265 |
} |
0 | 266 |
|
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
267 |
void DeleteWindowByClass(WindowClass cls) |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
268 |
{ |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
269 |
Window *w; |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
270 |
for (w = _windows; w != _last_window;) { |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
271 |
if (w->window_class == cls) { |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
272 |
DeleteWindow(w); |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
273 |
w = _windows; |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
274 |
} else |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
275 |
w++; |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
276 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
277 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
278 |
|
0 | 279 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) |
280 |
{ |
|
281 |
Window *w = FindWindowById(cls, number); |
|
282 |
||
283 |
if (w != NULL) { |
|
284 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
|
285 |
SetWindowDirty(w); |
|
388
d81d1c093b17
(svn r580) Fix latent bug in BringWindowToFrontByID() - a wrong pointer was returned
tron
parents:
386
diff
changeset
|
286 |
w = BringWindowToFront(w); |
0 | 287 |
} |
288 |
||
289 |
return w; |
|
290 |
} |
|
291 |
||
292 |
Window *BringWindowToFront(Window *w) |
|
293 |
{ |
|
294 |
Window *v; |
|
386 | 295 |
Window temp; |
0 | 296 |
|
297 |
v = _last_window; |
|
298 |
do { |
|
299 |
if (--v < _windows) |
|
300 |
return w; |
|
301 |
} while (v->window_class == WC_MAIN_TOOLBAR || v->window_class == WC_STATUS_BAR || v->window_class == WC_NEWS_WINDOW); |
|
302 |
||
303 |
if (w == v) |
|
304 |
return w; |
|
305 |
||
306 |
assert(w < v); |
|
307 |
||
386 | 308 |
temp = *w; |
309 |
memmove(w, w + 1, (v - w) * sizeof(Window)); |
|
310 |
*v = temp; |
|
0 | 311 |
|
386 | 312 |
SetWindowDirty(v); |
0 | 313 |
|
386 | 314 |
return v; |
0 | 315 |
} |
316 |
||
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
317 |
/* We have run out of windows, so find a suitable candidate for replacement. |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
318 |
* Keep all important windows intact */ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
319 |
static Window *FindDeletableWindow(void) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
320 |
{ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
321 |
Window *w; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
322 |
for (w = _windows; w < endof(_windows); w++) { |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
323 |
if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_MAIN_TOOLBAR && |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
324 |
w->window_class != WC_STATUS_BAR && w->window_class != WC_NEWS_WINDOW && |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
325 |
!(w->flags4 & WF_STICKY) ) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
326 |
return w; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
327 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
328 |
return NULL; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
329 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
330 |
|
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
331 |
/* A window must be freed, and all are marked as important windows. Ease the |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
332 |
* restriction a bit by allowing to delete sticky windows */ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
333 |
static Window *ForceFindDeletableWindow(void) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
334 |
{ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
335 |
Window *w; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
336 |
for (w = _windows;; w++) { |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
337 |
assert(w < _last_window); |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
338 |
|
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
339 |
if (w->window_class != WC_MAIN_WINDOW && w->window_class != WC_MAIN_TOOLBAR && |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
340 |
w->window_class != WC_STATUS_BAR && w->window_class != WC_NEWS_WINDOW) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
341 |
return w; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
342 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
343 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
344 |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
345 |
bool IsWindowOfPrototype(Window *w, const Widget *widget) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
346 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
347 |
return (w->original_widget == widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
348 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
349 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
350 |
/* Copies 'widget' to 'w->widget' */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
351 |
void AssignWidgetToWindow(Window *w, const Widget *widget) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
352 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
353 |
w->original_widget = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
354 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
355 |
if (widget != NULL) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
356 |
const Widget *wi = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
357 |
uint index = 1; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
358 |
while (wi->type != WWT_LAST) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
359 |
wi++; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
360 |
index++; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
361 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
362 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
363 |
w->widget = malloc(sizeof(Widget) * index); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
364 |
memcpy(w->widget, widget, sizeof(Widget) * index); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
365 |
} else { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
366 |
w->widget = NULL; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
367 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
368 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
369 |
|
0 | 370 |
Window *AllocateWindow( |
371 |
int x, |
|
372 |
int y, |
|
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 |
||
381 |
w = _last_window; |
|
382 |
||
383 |
if (w >= endof(_windows)) { |
|
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
384 |
w = FindDeletableWindow(); |
0 | 385 |
|
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
386 |
if (w == NULL) // no window found, force it! |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
387 |
w = ForceFindDeletableWindow(); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
388 |
|
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
389 |
DeleteWindow(w); |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
390 |
w = _last_window; |
0 | 391 |
} |
392 |
||
393 |
if (w != _windows && cls != WC_NEWS_WINDOW) { |
|
394 |
Window *v; |
|
395 |
||
396 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
|
397 |
if (v) { |
|
398 |
memmove(v+1, v, (byte*)w - (byte*)v); |
|
399 |
w = v; |
|
400 |
} |
|
401 |
||
402 |
v = FindWindowById(WC_STATUS_BAR, 0); |
|
403 |
if (v) { |
|
404 |
memmove(v+1, v, (byte*)w - (byte*)v); |
|
405 |
w = v; |
|
406 |
} |
|
407 |
} |
|
408 |
||
409 |
/* XXX: some more code here */ |
|
410 |
w->window_class = cls; |
|
411 |
w->flags4 = WF_WHITE_BORDER_MASK; |
|
412 |
w->caption_color = 0xFF; |
|
413 |
w->window_number = 0; |
|
414 |
w->left = x; |
|
415 |
w->top = y; |
|
416 |
w->width = width; |
|
417 |
w->height = height; |
|
418 |
w->viewport = NULL; |
|
419 |
w->desc_flags = 0; |
|
420 |
// w->landscape_assoc = 0xFFFF; |
|
421 |
w->wndproc = proc; |
|
422 |
w->click_state = 0; |
|
423 |
w->disabled_state = 0; |
|
424 |
w->hidden_state = 0; |
|
425 |
// w->unk22 = 0xFFFF; |
|
426 |
w->vscroll.pos = 0; |
|
427 |
w->vscroll.count = 0; |
|
428 |
w->hscroll.pos = 0; |
|
429 |
w->hscroll.count = 0; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
430 |
AssignWidgetToWindow(w, widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
431 |
w->resize.width = width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
432 |
w->resize.height = height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
433 |
w->resize.step_width = 1; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
434 |
w->resize.step_height = 1; |
0 | 435 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
436 |
{ |
959
b031d88c76f3
(svn r1451) Fix some of the signed/unsigned comparison warnings
tron
parents:
867
diff
changeset
|
437 |
uint i; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
438 |
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
|
439 |
w->custom[i] = 0; |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
440 |
} |
0 | 441 |
|
442 |
_last_window++; |
|
443 |
||
444 |
SetWindowDirty(w); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
445 |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
86
diff
changeset
|
446 |
CallWindowEventNP(w, WE_CREATE); |
0 | 447 |
|
448 |
return w; |
|
449 |
} |
|
450 |
||
451 |
Window *AllocateWindowAutoPlace2( |
|
452 |
WindowClass exist_class, |
|
453 |
WindowNumber exist_num, |
|
454 |
int width, |
|
455 |
int height, |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
456 |
WindowProc *proc, |
0 | 457 |
WindowClass cls, |
458 |
const Widget *widget) |
|
459 |
{ |
|
460 |
Window *w; |
|
461 |
int x; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
462 |
|
0 | 463 |
w = FindWindowById(exist_class, exist_num); |
464 |
if (w == NULL || w->left >= (_screen.width-20) || w->left <= -60 || w->top >= (_screen.height-20)) { |
|
465 |
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
|
466 |
} |
0 | 467 |
|
468 |
x = w->left; |
|
469 |
if (x > _screen.width - width) |
|
470 |
x = (_screen.width - width) - 20; |
|
471 |
||
472 |
return AllocateWindow(x+10,w->top+10,width,height,proc,cls,widget); |
|
473 |
} |
|
474 |
||
475 |
||
476 |
typedef struct SizeRect { |
|
477 |
int left,top,width,height; |
|
478 |
} SizeRect; |
|
479 |
||
480 |
||
481 |
static SizeRect _awap_r; |
|
482 |
||
483 |
static bool IsGoodAutoPlace1(int left, int top) |
|
484 |
{ |
|
485 |
int right,bottom; |
|
486 |
Window *w; |
|
487 |
||
488 |
_awap_r.left= left; |
|
489 |
_awap_r.top = top; |
|
490 |
right = _awap_r.width + left; |
|
491 |
bottom = _awap_r.height + top; |
|
492 |
||
493 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
494 |
return false; |
|
495 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
496 |
// Make sure it is not obscured by any window. |
0 | 497 |
for(w=_windows; w!=_last_window; w++) { |
498 |
if (w->window_class == WC_MAIN_WINDOW) |
|
499 |
continue; |
|
500 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
501 |
if (right > w->left && |
0 | 502 |
w->left + w->width > left && |
503 |
bottom > w->top && |
|
504 |
w->top + w->height > top) |
|
505 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
506 |
} |
0 | 507 |
|
508 |
return true; |
|
509 |
} |
|
510 |
||
511 |
static bool IsGoodAutoPlace2(int left, int top) |
|
512 |
{ |
|
513 |
int width,height; |
|
514 |
Window *w; |
|
515 |
||
516 |
_awap_r.left= left; |
|
517 |
_awap_r.top = top; |
|
518 |
width = _awap_r.width; |
|
519 |
height = _awap_r.height; |
|
520 |
||
521 |
if (left < -(width>>2) || left > _screen.width - (width>>1)) |
|
522 |
return false; |
|
523 |
if (top < 22 || top > _screen.height - (height>>2)) |
|
524 |
return false; |
|
525 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
526 |
// Make sure it is not obscured by any window. |
0 | 527 |
for(w=_windows; w!=_last_window; w++) { |
528 |
if (w->window_class == WC_MAIN_WINDOW) |
|
529 |
continue; |
|
530 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
531 |
if (left + width > w->left && |
0 | 532 |
w->left + w->width > left && |
533 |
top + height > w->top && |
|
534 |
w->top + w->height > top) |
|
535 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
536 |
} |
0 | 537 |
|
538 |
return true; |
|
539 |
} |
|
540 |
||
1095 | 541 |
static Point GetAutoPlacePosition(int width, int height) |
542 |
{ |
|
0 | 543 |
Window *w; |
544 |
Point pt; |
|
545 |
||
546 |
_awap_r.width = width; |
|
547 |
_awap_r.height = height; |
|
548 |
||
549 |
if (IsGoodAutoPlace1(0, 24)) goto ok_pos; |
|
550 |
||
551 |
for(w=_windows; w!=_last_window; w++) { |
|
552 |
if (w->window_class == WC_MAIN_WINDOW) |
|
553 |
continue; |
|
554 |
||
555 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top)) goto ok_pos; |
|
556 |
if (IsGoodAutoPlace1(w->left- width-2,w->top)) goto ok_pos; |
|
557 |
if (IsGoodAutoPlace1(w->left,w->top+w->height+2)) goto ok_pos; |
|
558 |
if (IsGoodAutoPlace1(w->left,w->top- height-2)) goto ok_pos; |
|
559 |
if (IsGoodAutoPlace1(w->left+w->width+2,w->top+w->height-height)) goto ok_pos; |
|
560 |
if (IsGoodAutoPlace1(w->left- width-2,w->top+w->height-height)) goto ok_pos; |
|
561 |
if (IsGoodAutoPlace1(w->left+w->width-width,w->top+w->height+2)) goto ok_pos; |
|
562 |
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
|
563 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
564 |
|
0 | 565 |
for(w=_windows; w!=_last_window; w++) { |
566 |
if (w->window_class == WC_MAIN_WINDOW) |
|
567 |
continue; |
|
568 |
||
569 |
if (IsGoodAutoPlace2(w->left+w->width+2,w->top)) goto ok_pos; |
|
570 |
if (IsGoodAutoPlace2(w->left- width-2,w->top)) goto ok_pos; |
|
571 |
if (IsGoodAutoPlace2(w->left,w->top+w->height+2)) goto ok_pos; |
|
572 |
if (IsGoodAutoPlace2(w->left,w->top- height-2)) goto ok_pos; |
|
573 |
} |
|
574 |
||
575 |
{ |
|
576 |
int left=0,top=24; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
577 |
|
0 | 578 |
restart:; |
579 |
for(w=_windows; w!=_last_window; w++) { |
|
580 |
if (w->left == left && w->top == top) { |
|
581 |
left += 5; |
|
582 |
top += 5; |
|
583 |
goto restart; |
|
584 |
} |
|
585 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
586 |
|
0 | 587 |
pt.x = left; |
588 |
pt.y = top; |
|
589 |
return pt; |
|
590 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
591 |
|
0 | 592 |
ok_pos:; |
593 |
pt.x = _awap_r.left; |
|
594 |
pt.y = _awap_r.top; |
|
595 |
return pt; |
|
596 |
} |
|
597 |
||
598 |
Window *AllocateWindowAutoPlace( |
|
599 |
int width, |
|
600 |
int height, |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
601 |
WindowProc *proc, |
0 | 602 |
WindowClass cls, |
603 |
const Widget *widget) { |
|
604 |
||
605 |
Point pt = GetAutoPlacePosition(width, height); |
|
606 |
return AllocateWindow(pt.x, pt.y, width, height, proc, cls, widget); |
|
607 |
} |
|
608 |
||
609 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int value) |
|
610 |
{ |
|
611 |
Window *w; |
|
612 |
||
613 |
if (BringWindowToFrontById(desc->cls, value)) |
|
614 |
return NULL; |
|
615 |
w = AllocateWindowDesc(desc); |
|
616 |
w->window_number = value; |
|
617 |
return w; |
|
618 |
} |
|
619 |
||
620 |
Window *AllocateWindowDesc(const WindowDesc *desc) |
|
621 |
{ |
|
622 |
Point pt; |
|
623 |
Window *w; |
|
624 |
||
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
625 |
if (desc->parent_cls != WC_MAIN_WINDOW && |
0 | 626 |
(w = FindWindowById(desc->parent_cls, _alloc_wnd_parent_num), _alloc_wnd_parent_num=0, w) != NULL && |
627 |
w->left < _screen.width-20 && w->left > -60 && w->top < _screen.height-20) { |
|
628 |
pt.x = w->left + 10; |
|
629 |
if (pt.x > _screen.width + 10 - desc->width) |
|
630 |
pt.x = (_screen.width + 10 - desc->width) - 20; |
|
631 |
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
|
632 |
} 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
|
633 |
/* 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
|
634 |
* 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
|
635 |
switch (_patches.toolbar_pos) { |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
636 |
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
|
637 |
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
|
638 |
default: pt.x = 640 - desc->width; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
639 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
640 |
pt.y = desc->top; |
0 | 641 |
} else { |
642 |
pt.x = desc->left; |
|
643 |
pt.y = desc->top; |
|
644 |
if (pt.x == WDP_AUTO) { |
|
645 |
pt = GetAutoPlacePosition(desc->width, desc->height); |
|
646 |
} else { |
|
647 |
if (pt.x == WDP_CENTER) pt.x = (_screen.width - desc->width) >> 1; |
|
648 |
if (pt.y == WDP_CENTER) pt.y = (_screen.height - desc->height) >> 1; |
|
649 | 649 |
else if(pt.y < 0) pt.y = _screen.height + pt.y; // if y is negative, it's from the bottom of the screen |
0 | 650 |
} |
651 |
} |
|
652 |
||
653 |
w = AllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets); |
|
654 |
w->desc_flags = desc->flags; |
|
655 |
return w; |
|
656 |
} |
|
657 |
||
658 |
Window *FindWindowFromPt(int x, int y) |
|
659 |
{ |
|
660 |
Window *w; |
|
661 |
||
662 |
for(w=_last_window; w != _windows;) { |
|
663 |
--w; |
|
664 |
if (IS_INSIDE_1D(x, w->left, w->width) && |
|
665 |
IS_INSIDE_1D(y, w->top, w->height)) |
|
666 |
return w; |
|
667 |
} |
|
668 |
||
669 |
return NULL; |
|
670 |
} |
|
671 |
||
672 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
673 |
void InitWindowSystem(void) |
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
|
674 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
675 |
IConsoleClose(); |
0 | 676 |
memset(&_windows, 0, sizeof(_windows)); |
677 |
_last_window = _windows; |
|
678 |
memset(_viewports, 0, sizeof(_viewports)); |
|
679 |
_active_viewports = 0; |
|
680 |
} |
|
681 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
682 |
static void DecreaseWindowCounters(void) |
0 | 683 |
{ |
684 |
Window *w; |
|
685 |
||
686 |
||
687 |
for(w=_last_window; w != _windows;) { |
|
688 |
--w; |
|
689 |
// Unclick scrollbar buttons if they are pressed. |
|
690 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
|
691 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
692 |
SetWindowDirty(w); |
|
693 |
} |
|
694 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
695 |
} |
|
696 |
||
697 |
for(w=_last_window; w != _windows;) { |
|
698 |
--w; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
699 |
|
0 | 700 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
701 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
702 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) |
|
703 |
UnclickWindowButtons(w); |
|
704 |
} |
|
705 |
} |
|
706 |
} |
|
707 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
708 |
Window *GetCallbackWnd(void) |
0 | 709 |
{ |
710 |
return FindWindowById(_thd.window_class, _thd.window_number); |
|
711 |
} |
|
712 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
713 |
static void HandlePlacePresize(void) |
0 | 714 |
{ |
715 |
Window *w; |
|
716 |
WindowEvent e; |
|
717 |
||
718 |
if (_special_mouse_mode != WSM_PRESIZE) |
|
719 |
return; |
|
720 |
||
721 |
if ((w = GetCallbackWnd()) == NULL) |
|
722 |
return; |
|
723 |
||
724 |
e.place.pt = GetTileBelowCursor(); |
|
725 |
if (e.place.pt.x == -1) { |
|
726 |
_thd.selend.x = -1; |
|
727 |
return; |
|
728 |
} |
|
729 |
e.place.tile = TILE_FROM_XY(e.place.pt.x, e.place.pt.y); |
|
730 |
e.event = WE_PLACE_PRESIZE; |
|
731 |
w->wndproc(w, &e); |
|
732 |
} |
|
733 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
734 |
static bool HandleDragDrop(void) |
0 | 735 |
{ |
736 |
Window *w; |
|
737 |
WindowEvent e; |
|
738 |
||
739 |
if (_special_mouse_mode != WSM_DRAGDROP) |
|
740 |
return true; |
|
741 |
||
742 |
if (_left_button_down) |
|
743 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
744 |
|
0 | 745 |
w = GetCallbackWnd(); |
746 |
||
747 |
ResetObjectToPlace(); |
|
748 |
||
749 |
if (w) { |
|
750 |
// send an event in client coordinates. |
|
751 |
e.event = WE_DRAGDROP; |
|
752 |
e.dragdrop.pt.x = _cursor.pos.x - w->left; |
|
753 |
e.dragdrop.pt.y = _cursor.pos.y - w->top; |
|
754 |
e.dragdrop.widget = GetWidgetFromPos(w, e.dragdrop.pt.x, e.dragdrop.pt.y); |
|
755 |
w->wndproc(w, &e); |
|
756 |
} |
|
757 |
return false; |
|
758 |
} |
|
759 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
760 |
static bool HandlePopupMenu(void) |
0 | 761 |
{ |
762 |
Window *w; |
|
763 |
WindowEvent e; |
|
764 |
||
765 |
if (!_popup_menu_active) |
|
766 |
return true; |
|
767 |
||
768 |
w = FindWindowById(WC_TOOLBAR_MENU, 0); |
|
769 |
if (w == NULL) { |
|
770 |
_popup_menu_active = false; |
|
771 |
return false; |
|
772 |
} |
|
773 |
||
774 |
if (_left_button_down) { |
|
775 |
e.event = WE_POPUPMENU_OVER; |
|
776 |
e.popupmenu.pt = _cursor.pos; |
|
777 |
} else { |
|
778 |
_popup_menu_active = false; |
|
779 |
e.event = WE_POPUPMENU_SELECT; |
|
780 |
e.popupmenu.pt = _cursor.pos; |
|
781 |
} |
|
782 |
||
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
783 |
w->wndproc(w, &e); |
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
784 |
|
0 | 785 |
return false; |
786 |
} |
|
787 |
||
1095 | 788 |
static bool HandleMouseOver(void) |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
789 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
790 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
791 |
WindowEvent e; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
792 |
static Window *last_w = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
793 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
794 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
795 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
796 |
// 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
|
797 |
if (last_w && last_w != w) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
798 |
e.event = WE_MOUSEOVER; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
799 |
e.mouseover.pt.x = -1; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
800 |
e.mouseover.pt.y = -1; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
801 |
if (last_w->wndproc) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
802 |
last_w->wndproc(last_w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
803 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
804 |
last_w = w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
805 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
806 |
if (w) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
807 |
// send an event in client coordinates. |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
808 |
e.event = WE_MOUSEOVER; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
809 |
e.mouseover.pt.x = _cursor.pos.x - w->left; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
810 |
e.mouseover.pt.y = _cursor.pos.y - w->top; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
811 |
if (w->widget != NULL) { |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
812 |
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
|
813 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
814 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
815 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
816 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
817 |
// Mouseover never stops execution |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
818 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
819 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
820 |
|
1095 | 821 |
static bool HandleWindowDragging(void) |
0 | 822 |
{ |
823 |
Window *w; |
|
824 |
// Get out immediately if no window is being dragged at all. |
|
825 |
if (!_dragging_window) |
|
826 |
return true; |
|
827 |
||
828 |
// Otherwise find the window... |
|
350 | 829 |
for (w = _windows; w != _last_window; w++) { |
830 |
if (w->flags4 & WF_DRAGGING) { |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
831 |
const Widget *t = &w->widget[1]; // the title bar ... ugh |
350 | 832 |
const Window *v; |
833 |
int x; |
|
834 |
int y; |
|
835 |
int nx; |
|
836 |
int ny; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
837 |
|
0 | 838 |
// Stop the dragging if the left mouse button was released |
839 |
if (!_left_button_down) { |
|
350 | 840 |
w->flags4 &= ~WF_DRAGGING; |
0 | 841 |
break; |
842 |
} |
|
843 |
||
844 |
SetWindowDirty(w); |
|
845 |
||
350 | 846 |
x = _cursor.pos.x + _drag_delta.x; |
847 |
y = _cursor.pos.y + _drag_delta.y; |
|
848 |
nx = x; |
|
849 |
ny = y; |
|
850 |
||
851 |
if (_patches.window_snap_radius != 0) { |
|
353 | 852 |
int hsnap = _patches.window_snap_radius; |
853 |
int vsnap = _patches.window_snap_radius; |
|
854 |
int delta; |
|
350 | 855 |
|
856 |
for (v = _windows; v != _last_window; ++v) { |
|
857 |
if (v == w) continue; // Don't snap at yourself |
|
858 |
||
859 |
if (y + w->height > v->top && y < v->top + v->height) { |
|
860 |
// Your left border <-> other right border |
|
861 |
delta = abs(v->left + v->width - x); |
|
862 |
if (delta <= hsnap) { |
|
863 |
nx = v->left + v->width; |
|
864 |
hsnap = delta; |
|
865 |
} |
|
866 |
||
867 |
// Your right border <-> other left border |
|
868 |
delta = abs(v->left - x - w->width); |
|
869 |
if (delta <= hsnap) { |
|
870 |
nx = v->left - w->width; |
|
871 |
hsnap = delta; |
|
872 |
} |
|
873 |
} |
|
874 |
||
353 | 875 |
if (w->top + w->height >= v->top && w->top <= v->top + v->height) { |
876 |
// Your left border <-> other left border |
|
877 |
delta = abs(v->left - x); |
|
878 |
if (delta <= hsnap) { |
|
879 |
nx = v->left; |
|
880 |
hsnap = delta; |
|
881 |
} |
|
882 |
||
883 |
// Your right border <-> other right border |
|
884 |
delta = abs(v->left + v->width - x - w->width); |
|
885 |
if (delta <= hsnap) { |
|
886 |
nx = v->left + v->width - w->width; |
|
887 |
hsnap = delta; |
|
888 |
} |
|
889 |
} |
|
890 |
||
350 | 891 |
if (x + w->width > v->left && x < v->left + v->width) { |
892 |
// Your top border <-> other bottom border |
|
893 |
delta = abs(v->top + v->height - y); |
|
894 |
if (delta <= vsnap) { |
|
895 |
ny = v->top + v->height; |
|
896 |
vsnap = delta; |
|
897 |
} |
|
898 |
||
899 |
// Your bottom border <-> other top border |
|
900 |
delta = abs(v->top - y - w->height); |
|
901 |
if (delta <= vsnap) { |
|
902 |
ny = v->top - w->height; |
|
903 |
vsnap = delta; |
|
904 |
} |
|
905 |
} |
|
353 | 906 |
|
907 |
if (w->left + w->width >= v->left && w->left <= v->left + v->width) { |
|
908 |
// Your top border <-> other top border |
|
909 |
delta = abs(v->top - y); |
|
910 |
if (delta <= vsnap) { |
|
911 |
ny = v->top; |
|
912 |
vsnap = delta; |
|
913 |
} |
|
914 |
||
915 |
// Your bottom border <-> other bottom border |
|
916 |
delta = abs(v->top + v->height - y - w->height); |
|
917 |
if (delta <= vsnap) { |
|
918 |
ny = v->top + v->height - w->height; |
|
919 |
vsnap = delta; |
|
920 |
} |
|
921 |
} |
|
0 | 922 |
} |
923 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
924 |
|
350 | 925 |
// Make sure the window doesn't leave the screen |
926 |
// 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
|
927 |
nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
350 | 928 |
ny = clamp(ny, 0, _screen.height - 13); |
929 |
||
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
930 |
// 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
|
931 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
932 |
if (v != NULL) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
933 |
int v_bottom = v->top + v->height; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
934 |
int v_right = v->left + v->width; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
935 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
371 | 936 |
if ((v->left < 13 && nx + t->left < v->left) || |
937 |
(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
|
938 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
939 |
} else { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
940 |
if (nx + t->left > v->left - 13 && |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
941 |
nx + t->right < v_right + 13) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
942 |
if (w->top >= v_bottom) |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
943 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
944 |
else if (w->left < nx) |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
945 |
nx = v->left - 13 - t->left; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
946 |
else |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
947 |
nx = v_right + 13 - t->right; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
948 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
949 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
950 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
951 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
952 |
|
350 | 953 |
if (w->viewport != NULL) { |
954 |
w->viewport->left += nx - w->left; |
|
955 |
w->viewport->top += ny - w->top; |
|
956 |
} |
|
957 |
w->left = nx; |
|
958 |
w->top = ny; |
|
959 |
||
0 | 960 |
SetWindowDirty(w); |
961 |
return false; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
962 |
} else if (w->flags4 & WF_SIZING) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
963 |
WindowEvent e; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
964 |
int x, y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
965 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
966 |
/* Stop the sizing if the left mouse button was released */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
967 |
if (!_left_button_down) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
968 |
w->flags4 &= ~WF_SIZING; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
969 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
970 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
971 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
972 |
x = _cursor.pos.x - _drag_delta.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
973 |
y = _cursor.pos.y - _drag_delta.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
974 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
975 |
/* X and Y has to go by step.. calculate it */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
976 |
if (w->resize.step_width > 1) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
977 |
x = x - (x % (int)w->resize.step_width); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
978 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
979 |
if (w->resize.step_height > 1) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
980 |
y = y - (y % (int)w->resize.step_height); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
981 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
982 |
/* Check if we don't go below the minimum set size */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
983 |
if ((int)w->width + x < (int)w->resize.width) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
984 |
x = w->resize.width - w->width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
985 |
if ((int)w->height + y < (int)w->resize.height) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
986 |
y = w->resize.height - w->height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
987 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
988 |
/* Window already on size */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
989 |
if (x == 0 && y == 0) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
990 |
return false; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
991 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
992 |
/* Now find the new cursor pos.. this is NOT _cursor, because |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
993 |
we move in steps. */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
994 |
_drag_delta.x += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
995 |
_drag_delta.y += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
996 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
997 |
SetWindowDirty(w); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
998 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
999 |
/* Scroll through all the windows and update the widgets if needed */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1000 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1001 |
Widget *wi = w->widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1002 |
bool resize_height = false; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1003 |
bool resize_width = false; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1004 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1005 |
while (wi->type != WWT_LAST) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1006 |
if (wi->resize_flag != RESIZE_NONE) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1007 |
/* Resize this widget */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1008 |
if (wi->resize_flag & RESIZE_LEFT) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1009 |
wi->left += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1010 |
resize_width = true; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1011 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1012 |
if (wi->resize_flag & RESIZE_RIGHT) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1013 |
wi->right += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1014 |
resize_width = true; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1015 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1016 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1017 |
if (wi->resize_flag & RESIZE_TOP) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1018 |
wi->top += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1019 |
resize_height = true; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1020 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1021 |
if (wi->resize_flag & RESIZE_BOTTOM) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1022 |
wi->bottom += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1023 |
resize_height = true; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1024 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1025 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1026 |
wi++; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1027 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1028 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1029 |
/* We resized at least 1 widget, so let's rezise the window totally */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1030 |
if (resize_width) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1031 |
w->width = x + w->width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1032 |
if (resize_height) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1033 |
w->height = y + w->height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1034 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1035 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1036 |
e.event = WE_RESIZE; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1037 |
e.sizing.size.x = x + w->width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1038 |
e.sizing.size.y = y + w->height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1039 |
e.sizing.diff.x = x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1040 |
e.sizing.diff.y = y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1041 |
w->wndproc(w, &e); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1042 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1043 |
SetWindowDirty(w); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1044 |
return false; |
0 | 1045 |
} |
1046 |
} |
|
1047 |
||
1048 |
_dragging_window = false; |
|
1049 |
return false; |
|
1050 |
} |
|
1051 |
||
1052 |
Window *StartWindowDrag(Window *w) |
|
1053 |
{ |
|
1054 |
w->flags4 |= WF_DRAGGING; |
|
1055 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1056 |
|
350 | 1057 |
_drag_delta.x = w->left - _cursor.pos.x; |
1058 |
_drag_delta.y = w->top - _cursor.pos.y; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1059 |
|
0 | 1060 |
w = BringWindowToFront(w); |
1061 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
|
1062 |
return w; |
|
1063 |
} |
|
1064 |
||
1065 |
Window *StartWindowSizing(Window *w) |
|
1066 |
{ |
|
1067 |
w->flags4 |= WF_SIZING; |
|
1068 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1069 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1070 |
_drag_delta.x = _cursor.pos.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1071 |
_drag_delta.y = _cursor.pos.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1072 |
|
0 | 1073 |
w = BringWindowToFront(w); |
1074 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
|
1075 |
return w; |
|
1076 |
} |
|
1077 |
||
1078 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1079 |
static bool HandleScrollbarScrolling(void) |
0 | 1080 |
{ |
1081 |
Window *w; |
|
1082 |
int i; |
|
1083 |
int pos; |
|
1084 |
Scrollbar *sb; |
|
1085 |
||
1086 |
// Get out quickly if no item is being scrolled |
|
1087 |
if (!_scrolling_scrollbar) |
|
1088 |
return true; |
|
1089 |
||
1090 |
// Find the scrolling window |
|
1091 |
for(w=_windows; w != _last_window; w++) { |
|
1092 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
|
1093 |
// Abort if no button is clicked any more. |
|
1094 |
if (!_left_button_down) { |
|
1095 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
1096 |
SetWindowDirty(w); |
|
1097 |
break; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1098 |
} |
0 | 1099 |
|
1100 |
if (w->flags4 & WF_HSCROLL) { |
|
1101 |
sb = &w->hscroll; |
|
1102 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
842 | 1103 |
} else if (w->flags4 & WF_SCROLL2){ |
1104 |
sb = &w->vscroll2; |
|
1105 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
0 | 1106 |
} else { |
1107 |
sb = &w->vscroll; |
|
1108 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
1109 |
} |
|
1110 |
||
1111 |
// Find the item we want to move to and make sure it's inside bounds. |
|
1112 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
|
1113 |
if (pos != sb->pos) { |
|
1114 |
sb->pos = pos; |
|
1115 |
SetWindowDirty(w); |
|
1116 |
} |
|
1117 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1118 |
} |
0 | 1119 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1120 |
|
0 | 1121 |
_scrolling_scrollbar = false; |
1122 |
return false; |
|
1123 |
} |
|
1124 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1125 |
static bool HandleViewportScroll(void) |
0 | 1126 |
{ |
1127 |
Window *w; |
|
1128 |
ViewPort *vp; |
|
1129 |
int dx,dy, x, y, sub; |
|
1130 |
||
1131 |
if (!_scrolling_viewport) |
|
1132 |
return true; |
|
1133 |
||
1134 |
if (!_right_button_down) { |
|
1135 |
stop_capt:; |
|
1136 |
_cursor.fix_at = false; |
|
1137 |
_scrolling_viewport = false; |
|
1138 |
return true; |
|
1139 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1140 |
|
0 | 1141 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
1142 |
if (w == NULL) goto stop_capt; |
|
1143 |
||
1144 |
if (w->window_class != WC_SMALLMAP) { |
|
1145 |
vp = IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y); |
|
1146 |
if (vp == NULL) |
|
1147 |
goto stop_capt; |
|
1148 |
||
1149 |
WP(w,vp_d).scrollpos_x += _cursor.delta.x << vp->zoom; |
|
1150 |
WP(w,vp_d).scrollpos_y += _cursor.delta.y << vp->zoom; |
|
1151 |
_cursor.delta.x = _cursor.delta.y = 0; |
|
1152 |
return false; |
|
1153 |
} else { |
|
1154 |
// 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
|
1155 |
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
|
1156 |
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
|
1157 |
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
|
1158 |
int hvy; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1159 |
|
0 | 1160 |
_cursor.fix_at = true; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1161 |
|
0 | 1162 |
dx = _cursor.delta.x; |
1163 |
dy = _cursor.delta.y; |
|
1164 |
||
1165 |
x = WP(w,smallmap_d).scroll_x; |
|
1166 |
y = WP(w,smallmap_d).scroll_y; |
|
1167 |
||
1168 |
sub = WP(w,smallmap_d).subscroll + dx; |
|
1169 |
||
1170 |
x -= (sub >> 2) << 4; |
|
1171 |
y += (sub >> 2) << 4; |
|
1172 |
sub &= 3; |
|
1173 |
||
1174 |
x += (dy >> 1) << 4; |
|
1175 |
y += (dy >> 1) << 4; |
|
1176 |
||
1177 |
if (dy & 1) { |
|
1178 |
x += 16; |
|
1179 |
sub += 2; |
|
1180 |
if (sub > 3) { |
|
1181 |
sub -= 4; |
|
1182 |
x -= 16; |
|
1183 |
y += 16; |
|
1184 |
} |
|
1185 |
} |
|
1186 |
||
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
|
1187 |
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
|
1188 |
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
|
1189 |
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
|
1190 |
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
|
1191 |
if (x < -hvx) { x = -hvx; sub = 0; } |
857
0fbb53269a10
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
1192 |
if (x > (int)MapMaxX() * 16 - hvx) { x = MapMaxX() * 16 - hvx; sub = 0; } |
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
|
1193 |
if (y < -hvy) { y = -hvy; sub = 0; } |
857
0fbb53269a10
(svn r1338) -Fix: fix signed/unsigned warnings introduced when ditching the macros for map querying.
darkvater
parents:
856
diff
changeset
|
1194 |
if (y > (int)MapMaxY() * 16 - hvy) { y = MapMaxY() * 16 - hvy; sub = 0; } |
0 | 1195 |
|
1196 |
WP(w,smallmap_d).scroll_x = x; |
|
1197 |
WP(w,smallmap_d).scroll_y = y; |
|
1198 |
WP(w,smallmap_d).subscroll = sub; |
|
1199 |
||
1200 |
_cursor.delta.x = _cursor.delta.y = 0; |
|
1201 |
||
1202 |
SetWindowDirty(w); |
|
1203 |
return false; |
|
1204 |
} |
|
1205 |
} |
|
1206 |
||
1207 |
static Window *MaybeBringWindowToFront(Window *w) |
|
1208 |
{ |
|
1209 |
Window *u; |
|
1210 |
||
1211 |
if (w->window_class == WC_MAIN_WINDOW || |
|
1212 |
w->window_class == WC_MAIN_TOOLBAR || |
|
1213 |
w->window_class == WC_STATUS_BAR || |
|
1214 |
w->window_class == WC_NEWS_WINDOW || |
|
1215 |
w->window_class == WC_TOOLTIPS || |
|
1216 |
w->window_class == WC_DROPDOWN_MENU) |
|
1217 |
return w; |
|
1218 |
||
1219 |
for(u=w; ++u != _last_window;) { |
|
1220 |
if (u->window_class == WC_MAIN_WINDOW || u->window_class==WC_MAIN_TOOLBAR || u->window_class==WC_STATUS_BAR || |
|
1221 |
u->window_class == WC_NEWS_WINDOW || u->window_class == WC_TOOLTIPS || u->window_class == WC_DROPDOWN_MENU) |
|
1222 |
continue; |
|
1223 |
||
1224 |
if (w->left + w->width <= u->left || |
|
1225 |
u->left + u->width <= w->left || |
|
1226 |
w->top + w->height <= u->top || |
|
1227 |
u->top + u->height <= w->top) |
|
1228 |
continue; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1229 |
|
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1230 |
return BringWindowToFront(w); |
0 | 1231 |
} |
1232 |
||
1233 |
return w; |
|
1234 |
} |
|
1235 |
||
1236 |
static void HandleKeypress(uint32 key) |
|
1237 |
{ |
|
1238 |
Window *w; |
|
1239 |
WindowEvent we; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1240 |
/* Stores if a window with a textfield for typing is open |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1241 |
* If this is the case, keypress events are only passed to windows with text fields and |
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
|
1242 |
* 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
|
1243 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1244 |
|
0 | 1245 |
// Setup event |
1246 |
we.keypress.event = WE_KEYPRESS; |
|
1247 |
we.keypress.ascii = key & 0xFF; |
|
1248 |
we.keypress.keycode = key >> 16; |
|
1249 |
we.keypress.cont = true; |
|
1250 |
||
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
|
1251 |
// 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
|
1252 |
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
|
1253 |
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
|
1254 |
|
0 | 1255 |
// Call the event, start with the uppermost window. |
1256 |
for(w=_last_window; w != _windows;) { |
|
1257 |
--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
|
1258 |
// 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
|
1259 |
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
|
1260 |
continue; |
0 | 1261 |
w->wndproc(w, &we); |
1262 |
if (!we.keypress.cont) |
|
1263 |
break; |
|
1264 |
} |
|
1265 |
} |
|
1266 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1267 |
extern void UpdateTileSelection(void); |
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1268 |
extern bool VpHandlePlaceSizingDrag(void); |
0 | 1269 |
|
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1270 |
void MouseLoop(void) |
0 | 1271 |
{ |
1272 |
int x,y; |
|
1273 |
Window *w; |
|
1274 |
ViewPort *vp; |
|
1275 |
int click; |
|
1276 |
int mousewheel; |
|
1277 |
||
1278 |
_current_player = _local_player; |
|
1279 |
||
1280 |
// Handle pressed keys |
|
1281 |
if (_pressed_key) { |
|
1282 |
uint32 key = _pressed_key; _pressed_key = 0; |
|
1283 |
HandleKeypress(key); |
|
1284 |
} |
|
1285 |
||
1286 |
// Mouse event? |
|
1287 |
click = 0; |
|
1288 |
if (_left_button_down && !_left_button_clicked) { |
|
1289 |
_left_button_clicked = true; |
|
1290 |
click = 1; |
|
1291 |
} else if (_right_button_clicked) { |
|
1292 |
_right_button_clicked = false; |
|
1293 |
click = 2; |
|
1294 |
} |
|
1295 |
||
1296 |
mousewheel = 0; |
|
1297 |
if (_cursor.wheel) { |
|
1298 |
mousewheel = _cursor.wheel; |
|
1299 |
_cursor.wheel = 0; |
|
1300 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1301 |
|
0 | 1302 |
DecreaseWindowCounters(); |
1303 |
HandlePlacePresize(); |
|
1304 |
UpdateTileSelection(); |
|
1305 |
if (!VpHandlePlaceSizingDrag()) |
|
1306 |
return; |
|
1307 |
||
1308 |
if (!HandleDragDrop()) |
|
1309 |
return; |
|
1310 |
||
1311 |
if (!HandlePopupMenu()) |
|
1312 |
return; |
|
1313 |
||
1314 |
if (!HandleWindowDragging()) |
|
1315 |
return; |
|
1316 |
||
1317 |
if (!HandleScrollbarScrolling()) |
|
1318 |
return; |
|
1319 |
||
1320 |
if (!HandleViewportScroll()) |
|
1321 |
return; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1322 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1323 |
if (!HandleMouseOver()) |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1324 |
return; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1325 |
|
0 | 1326 |
x = _cursor.pos.x; |
1327 |
y = _cursor.pos.y; |
|
1328 |
||
1329 |
||
1330 |
if (click == 0 && mousewheel == 0) { |
|
1331 |
if (_patches.autoscroll && _game_mode != GM_MENU) { |
|
1332 |
w = FindWindowFromPt(x, y); |
|
1333 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL ) return; |
|
1334 |
vp = IsPtInWindowViewport(w, x, y); |
|
1335 |
if (vp) { |
|
1336 |
x -= vp->left; |
|
1337 |
y -= vp->top; |
|
1338 |
//here allows scrolling in both x and y axis |
|
1339 |
#define scrollspeed 3 |
|
1340 |
if (x-15<0) { WP(w,vp_d).scrollpos_x += (x-15) * scrollspeed << vp->zoom; } |
|
1341 |
else if (15-(vp->width-x) > 0) { WP(w,vp_d).scrollpos_x += (15-(vp->width-x))*scrollspeed << vp->zoom; } |
|
1342 |
if (y-15<0) { WP(w,vp_d).scrollpos_y += (y-15)*scrollspeed << vp->zoom; } |
|
1343 |
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
|
1344 |
#undef scrollspeed |
0 | 1345 |
} |
1346 |
} |
|
1347 |
return; |
|
1348 |
} |
|
1349 |
||
1350 |
w = FindWindowFromPt(x, y); |
|
1351 |
if (w == NULL) |
|
1352 |
return; |
|
1353 |
w = MaybeBringWindowToFront(w); |
|
1354 |
vp = IsPtInWindowViewport(w, x, y); |
|
1355 |
if (vp != NULL) { |
|
1356 |
if (_game_mode == GM_MENU) |
|
1357 |
return; |
|
1358 |
||
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
|
1359 |
// 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
|
1360 |
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
|
1361 |
(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
|
1362 |
ZoomInOrOutToCursorWindow(mousewheel < 0,w); |
0 | 1363 |
} |
1364 |
||
1365 |
if (click == 1) { |
|
70
60216d94f7c1
(svn r71) -Cheat: [976127] no extra frequent jet crash on small airports (truesatan)
darkvater
parents:
69
diff
changeset
|
1366 |
DEBUG(misc, 2) ("cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
0 | 1367 |
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
|
1368 |
// 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
|
1369 |
!(_cursor.sprite == 0x2CF || _cursor.sprite == 0x2D2) && |
0 | 1370 |
_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
|
1371 |
!_cheats.build_in_pause.value) |
0 | 1372 |
return; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1373 |
|
0 | 1374 |
if (_thd.place_mode == 0) { |
1375 |
HandleViewportClicked(vp, x, y); |
|
1376 |
} else { |
|
1377 |
PlaceObject(); |
|
1378 |
} |
|
1379 |
} else if (click == 2) { |
|
1380 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { |
|
1381 |
_scrolling_viewport = true; |
|
1382 |
_cursor.fix_at = true; |
|
1383 |
} |
|
1384 |
} |
|
1385 |
} else { |
|
1386 |
if (mousewheel) |
|
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
1387 |
DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel); |
0 | 1388 |
|
1389 |
if (click == 1) |
|
1390 |
DispatchLeftClickEvent(w, x - w->left, y - w->top); |
|
1391 |
else if (click == 2) |
|
1392 |
DispatchRightClickEvent(w, x - w->left, y - w->top); |
|
1393 |
} |
|
1394 |
} |
|
1395 |
||
1396 |
static int _we4_timer; |
|
1397 |
||
1398 |
extern uint32 _pixels_redrawn; |
|
1399 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1400 |
void UpdateWindows(void) |
0 | 1401 |
{ |
1402 |
Window *w; |
|
1403 |
int t; |
|
1404 |
||
1405 |
||
1406 |
if ((t=_we4_timer+1) >= 100) { |
|
1407 |
for(w = _last_window; w != _windows;) { |
|
1408 |
w--; |
|
1409 |
CallWindowEventNP(w, WE_4); |
|
1410 |
} |
|
1411 |
t = 0; |
|
1412 |
} |
|
1413 |
_we4_timer = t; |
|
1414 |
||
1415 |
for(w = _last_window; w != _windows;) { |
|
1416 |
w--; |
|
1417 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
|
1418 |
w->flags4 -= WF_WHITE_BORDER_ONE; |
|
1419 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) { |
|
1420 |
SetWindowDirty(w); |
|
1421 |
} |
|
1422 |
} |
|
1423 |
} |
|
1424 |
||
1425 |
DrawDirtyBlocks(); |
|
1426 |
||
1427 |
for(w = _windows; w!=_last_window; w++) { |
|
1428 |
if (w->viewport != NULL) |
|
1429 |
UpdateViewportPosition(w); |
|
1430 |
} |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1431 |
DrawTextMessage(); |
0 | 1432 |
// Redraw mouse cursor in case it was hidden |
1433 |
DrawMouseCursor(); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1434 |
} |
0 | 1435 |
|
1436 |
||
1437 |
int GetMenuItemIndex(Window *w, int x, int y) |
|
1438 |
{ |
|
1439 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
1440 |
y /= 10; |
|
1441 |
||
1442 |
if (y < WP(w,menu_d).item_count) |
|
1443 |
return y; |
|
1444 |
} |
|
1445 |
return -1; |
|
1446 |
} |
|
1447 |
||
1448 |
void InvalidateWindow(byte cls, WindowNumber number) |
|
1449 |
{ |
|
1450 |
Window *w; |
|
1451 |
||
1452 |
for(w=_windows; w!=_last_window; w++) { |
|
1453 |
if (w->window_class==cls && w->window_number==number) |
|
1454 |
SetWindowDirty(w); |
|
1455 |
} |
|
1456 |
} |
|
1457 |
||
1458 |
void InvalidateWidget(Window *w, byte widget_index) |
|
1459 |
{ |
|
1460 |
const Widget *wi = &w->widget[widget_index]; |
|
1461 |
// if (wi->left != -2) { |
|
1462 |
SetDirtyBlocks( |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1463 |
w->left + wi->left, |
0 | 1464 |
w->top + wi->top, |
1465 |
w->left + wi->right + 1, |
|
1466 |
w->top + wi->bottom + 1); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1467 |
// } |
0 | 1468 |
} |
1469 |
||
1470 |
void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index) |
|
1471 |
{ |
|
1472 |
Window *w; |
|
1473 |
||
1474 |
for(w=_windows; w!=_last_window; w++) { |
|
1475 |
if (w->window_class==cls && w->window_number==number) { |
|
1476 |
InvalidateWidget(w, widget_index); |
|
1477 |
} |
|
1478 |
} |
|
1479 |
} |
|
1480 |
||
1481 |
void InvalidateWindowClasses(byte cls) |
|
1482 |
{ |
|
1483 |
Window *w; |
|
1484 |
for(w=_windows; w!=_last_window; w++) { |
|
1485 |
if (w->window_class==cls) |
|
1486 |
SetWindowDirty(w); |
|
1487 |
} |
|
1488 |
} |
|
1489 |
||
1490 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1491 |
void CallWindowTickEvent(void) |
0 | 1492 |
{ |
1493 |
Window *w; |
|
1494 |
for(w=_last_window; w != _windows;) { |
|
1495 |
--w; |
|
1496 |
CallWindowEventNP(w, WE_TICK); |
|
1497 |
} |
|
1498 |
} |
|
1499 |
||
1093
e8d26c7dc42f
(svn r1594) Convert all undefined parameter lists to (void) and add the appropriate warning flags in the Makefile
tron
parents:
1038
diff
changeset
|
1500 |
void DeleteNonVitalWindows(void) |
0 | 1501 |
{ |
1502 |
Window *w; |
|
1503 |
for(w=_windows; w!=_last_window;) { |
|
1504 |
if (w->window_class != WC_MAIN_WINDOW && |
|
1505 |
w->window_class != WC_SELECT_GAME && |
|
1506 |
w->window_class != WC_MAIN_TOOLBAR && |
|
1507 |
w->window_class != WC_STATUS_BAR && |
|
1508 |
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
|
1509 |
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
|
1510 |
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned' |
0 | 1511 |
DeleteWindow(w); |
1512 |
w = _windows; |
|
1513 |
} else { |
|
1514 |
w++; |
|
1515 |
} |
|
1516 |
} |
|
1517 |
} |
|
1518 |
||
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1519 |
/* It is possible that a stickied window gets to a position where the |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1520 |
* 'close' button is outside the gaming area. You cannot close it then; except |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1521 |
* with this function. It closes all windows calling the standard function, |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1522 |
* then, does a little hacked loop of closing all stickied windows. Note |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1523 |
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1524 |
void DeleteAllNonVitalWindows(void) |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1525 |
{ |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1526 |
Window *w; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1527 |
// Delete every window except for stickied ones |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1528 |
DeleteNonVitalWindows(); |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1529 |
// Delete all sticked windows |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1530 |
for (w = _windows; w != _last_window;) { |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1531 |
if (w->flags4 & WF_STICKY) { |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1532 |
DeleteWindow(w); |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1533 |
w = _windows; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1534 |
} else |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1535 |
w++; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1536 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1537 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1538 |
|
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1539 |
/* Delete all always on-top windows to get an empty screen */ |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1540 |
void HideVitalWindows(void) |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1541 |
{ |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1542 |
DeleteWindowById(WC_MAIN_TOOLBAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1543 |
DeleteWindowById(WC_STATUS_BAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1544 |
} |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
1545 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1546 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1547 |
{ |
69 | 1548 |
DEBUG(misc, 1) ("Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1549 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1550 |
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
|
1551 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1552 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1553 |
switch (_patches.toolbar_pos) { |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1554 |
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
|
1555 |
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
|
1556 |
default: w->left = 0; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1557 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1558 |
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
|
1559 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1560 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1561 |
|
0 | 1562 |
void RelocateAllWindows(int neww, int newh) |
1563 |
{ |
|
1564 |
Window *w; |
|
1565 |
||
1566 |
for(w=_windows; w!= _last_window ;w++) { |
|
1567 |
int left, top; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1568 |
|
0 | 1569 |
if (w->window_class == WC_MAIN_WINDOW) { |
1570 |
ViewPort *vp = w->viewport; |
|
1571 |
vp->width = w->width = neww; |
|
1572 |
vp->height = w->height = newh; |
|
1573 |
vp->virtual_width = neww << vp->zoom; |
|
1574 |
vp->virtual_height = newh << vp->zoom; |
|
1575 |
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
|
1576 |
} |
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
|
1577 |
|
126 | 1578 |
IConsoleResize(); |
0 | 1579 |
|
1580 |
if (w->window_class == WC_MAIN_TOOLBAR) { |
|
1581 |
top = w->top; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1582 |
left = PositionMainToolbar(w); // changes toolbar orientation |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1583 |
} else if (w->window_class == WC_SELECT_GAME || w->window_class == WC_GAME_OPTIONS || w->window_class == WC_NETWORK_WINDOW){ |
0 | 1584 |
top = (newh - w->height) >> 1; |
1585 |
left = (neww - w->width) >> 1; |
|
1586 |
} else if (w->window_class == WC_NEWS_WINDOW) { |
|
1587 |
top = newh - w->height; |
|
1588 |
left = (neww - w->width) >> 1; |
|
1589 |
} else if (w->window_class == WC_STATUS_BAR) { |
|
1590 |
top = newh - w->height; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1591 |
left = (neww - w->width) >> 1; |
649 | 1592 |
} else if (w->window_class == WC_SEND_NETWORK_MSG) { |
1593 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
|
1594 |
left = (neww - w->width) >> 1; |
|
0 | 1595 |
} else { |
1596 |
left = w->left; |
|
1597 |
if (left + (w->width>>1) >= neww) left = neww - w->width; |
|
1598 |
top = w->top; |
|
1599 |
if (top + (w->height>>1) >= newh) top = newh - w->height; |
|
1600 |
} |
|
1601 |
||
1602 |
if (w->viewport) { |
|
1603 |
w->viewport->left += left - w->left; |
|
1604 |
w->viewport->top += top - w->top; |
|
1605 |
} |
|
1606 |
||
1607 |
w->left = left; |
|
1608 |
w->top = top; |
|
1609 |
} |
|
1610 |
} |