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