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