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