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