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