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