author | celestar |
Tue, 19 Jun 2007 07:21:01 +0000 | |
branch | gamebalance |
changeset 9913 | e79cd19772dd |
parent 9911 | 0b8b245a2391 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
3 |
/** @file window.cpp windowing system, widgets and events */ |
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
6 |
#include <stdarg.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1867
diff
changeset
|
7 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1112
diff
changeset
|
8 |
#include "debug.h" |
2163
637ec3c361f5
(svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents:
2159
diff
changeset
|
9 |
#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
|
10 |
#include "map.h" |
2154
63a6b880b4c0
(svn r2664) Remove depedency on player.h from variables.h
tron
parents:
2026
diff
changeset
|
11 |
#include "player.h" |
0 | 12 |
#include "window.h" |
13 |
#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
|
14 |
#include "viewport.h" |
126 | 15 |
#include "console.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
16 |
#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
|
17 |
#include "table/sprites.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
18 |
#include "genworld.h" |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
19 |
#include "helpers.hpp" |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
20 |
#include "blitter/factory.hpp" |
0 | 21 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
22 |
/* delta between mouse cursor and upper left corner of dragged window */ |
350 | 23 |
static Point _drag_delta; |
24 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
25 |
static Window _windows[25]; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
26 |
Window *_z_windows[lengthof(_windows)]; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
27 |
Window **_last_z_window; ///< always points to the next free space in the z-array |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
28 |
|
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
29 |
void CDECL SetWindowWidgetsDisabledState(Window *w, bool disab_stat, int widgets, ...) |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
30 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
31 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
32 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
33 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
34 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
35 |
while (widgets != WIDGET_LIST_END) { |
4757 | 36 |
SetWindowWidgetDisabledState(w, widgets, disab_stat); |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
37 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
38 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
39 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
40 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
41 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
42 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
43 |
void CDECL SetWindowWidgetsHiddenState(Window *w, bool hidden_stat, int widgets, ...) |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
44 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
45 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
46 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
47 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
48 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
49 |
while (widgets != WIDGET_LIST_END) { |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
50 |
SetWindowWidgetHiddenState(w, widgets, hidden_stat); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
51 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
52 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
53 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
54 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
55 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
56 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
57 |
void CDECL SetWindowWidgetsLoweredState(Window *w, bool lowered_stat, int widgets, ...) |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
58 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
59 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
60 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
61 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
62 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
63 |
while (widgets != WIDGET_LIST_END) { |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
64 |
SetWindowWidgetLoweredState(w, widgets, lowered_stat); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
65 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
66 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
67 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
68 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
69 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
70 |
|
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
71 |
void RaiseWindowButtons(Window *w) |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
72 |
{ |
5235
3c309f43f0a6
(svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents:
5232
diff
changeset
|
73 |
uint i; |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
74 |
|
5235
3c309f43f0a6
(svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents:
5232
diff
changeset
|
75 |
for (i = 0; i < w->widget_count; i++) { |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
76 |
if (IsWindowWidgetLowered(w, i)) { |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
77 |
RaiseWindowWidget(w, i); |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
78 |
InvalidateWidget(w, i); |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
79 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
80 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
81 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
82 |
|
0 | 83 |
void HandleButtonClick(Window *w, byte widget) |
84 |
{ |
|
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
85 |
LowerWindowWidget(w, widget); |
0 | 86 |
w->flags4 |= 5 << WF_TIMEOUT_SHL; |
87 |
InvalidateWidget(w, widget); |
|
88 |
} |
|
89 |
||
2817 | 90 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
91 |
static void StartWindowDrag(Window *w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
92 |
static void StartWindowSizing(Window *w); |
2817 | 93 |
|
4171 | 94 |
static void DispatchLeftClickEvent(Window *w, int x, int y) |
2596 | 95 |
{ |
0 | 96 |
WindowEvent e; |
97 |
const Widget *wi; |
|
98 |
||
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
99 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
100 |
e.we.click.pt.y = y; |
0 | 101 |
e.event = WE_CLICK; |
102 |
||
103 |
if (w->desc_flags & WDF_DEF_WIDGET) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
104 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
105 |
if (e.we.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
|
106 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
107 |
/* don't allow any interaction if the button has been disabled */ |
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
108 |
if (IsWindowWidgetDisabled(w, e.we.click.widget)) return; |
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
|
109 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
110 |
wi = &w->widget[e.we.click.widget]; |
0 | 111 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
112 |
if (wi->type & WWB_MASK) { |
211 | 113 |
/* special widget handling for buttons*/ |
2952 | 114 |
switch (wi->type) { |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
115 |
case WWT_PANEL | WWB_PUSHBUTTON: /* WWT_PUSHBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
116 |
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
117 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
118 |
HandleButtonClick(w, e.we.click.widget); |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
119 |
break; |
0 | 120 |
} |
842 | 121 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
122 |
ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y); |
0 | 123 |
} |
124 |
||
125 |
if (w->desc_flags & WDF_STD_BTN) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
126 |
if (e.we.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
|
127 |
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
|
128 |
return; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
129 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
130 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
131 |
if (e.we.click.widget == 1) { /* 'Title bar' */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
132 |
StartWindowDrag(w); |
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
|
133 |
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
|
134 |
} |
0 | 135 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
136 |
|
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
|
137 |
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
138 |
StartWindowSizing(w); |
5272
e27514065ed8
(svn r7414) -Fix: Immediately invalidate the resize widget when clicked, instead of when started to drag
Darkvater
parents:
5268
diff
changeset
|
139 |
InvalidateWidget(w, e.we.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
|
140 |
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
|
141 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
142 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
143 |
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
|
144 |
w->flags4 ^= WF_STICKY; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
145 |
InvalidateWidget(w, e.we.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
|
146 |
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
|
147 |
} |
0 | 148 |
} |
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
|
149 |
|
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
|
150 |
w->wndproc(w, &e); |
0 | 151 |
} |
152 |
||
4171 | 153 |
static void DispatchRightClickEvent(Window *w, int x, int y) |
2596 | 154 |
{ |
0 | 155 |
WindowEvent e; |
156 |
||
157 |
/* default tooltips handler? */ |
|
158 |
if (w->desc_flags & WDF_STD_TOOLTIPS) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
159 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
160 |
if (e.we.click.widget < 0) |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
161 |
return; // exit if clicked outside of widgets |
0 | 162 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
163 |
if (w->widget[e.we.click.widget].tooltips != 0) { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
164 |
GuiShowTooltips(w->widget[e.we.click.widget].tooltips); |
0 | 165 |
return; |
166 |
} |
|
167 |
} |
|
168 |
||
169 |
e.event = WE_RCLICK; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
170 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
171 |
e.we.click.pt.y = y; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
172 |
w->wndproc(w, &e); |
0 | 173 |
} |
174 |
||
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
|
175 |
/** 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
|
176 |
* 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
|
177 |
* @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
|
178 |
* @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
|
179 |
* @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
|
180 |
*/ |
4171 | 181 |
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel) |
0 | 182 |
{ |
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
|
183 |
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
|
184 |
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
|
185 |
|
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
|
186 |
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
|
187 |
|
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
|
188 |
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
|
189 |
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
|
190 |
|
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
|
191 |
/* 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
|
192 |
* 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
|
193 |
* 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
|
194 |
* not happening until someone rewrites the whole widget-code */ |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
195 |
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
|
196 |
(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
|
197 |
|
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
|
198 |
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
|
199 |
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
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
} |
0 | 204 |
} |
205 |
} |
|
206 |
} |
|
207 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
208 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom); |
2817 | 209 |
|
0 | 210 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
211 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
212 |
Window* const *wz; |
0 | 213 |
DrawPixelInfo bk; |
214 |
_cur_dpi = &bk; |
|
215 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
216 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
217 |
const Window *w = *wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
218 |
if (right > w->left && |
0 | 219 |
bottom > w->top && |
220 |
left < w->left + w->width && |
|
221 |
top < w->top + w->height) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
222 |
DrawOverlappedWindow(wz, left, top, right, bottom); |
2639 | 223 |
} |
0 | 224 |
} |
225 |
} |
|
226 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
227 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom) |
0 | 228 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
229 |
Window* const *vz = wz; |
0 | 230 |
int x; |
231 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
232 |
while (++vz != _last_z_window) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
233 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
234 |
|
0 | 235 |
if (right > v->left && |
2026 | 236 |
bottom > v->top && |
0 | 237 |
left < v->left + v->width && |
238 |
top < v->top + v->height) { |
|
9910
0b2aebc8283e
(svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents:
9909
diff
changeset
|
239 |
if (left < (x = v->left)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
240 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
241 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 242 |
return; |
243 |
} |
|
244 |
||
9910
0b2aebc8283e
(svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents:
9909
diff
changeset
|
245 |
if (right > (x = v->left + v->width)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
246 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
247 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 248 |
return; |
249 |
} |
|
250 |
||
9910
0b2aebc8283e
(svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents:
9909
diff
changeset
|
251 |
if (top < (x = v->top)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
252 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
253 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 254 |
return; |
255 |
} |
|
256 |
||
9910
0b2aebc8283e
(svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents:
9909
diff
changeset
|
257 |
if (bottom > (x = v->top + v->height)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
258 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
259 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 260 |
return; |
261 |
} |
|
262 |
||
263 |
return; |
|
264 |
} |
|
265 |
} |
|
266 |
||
267 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
268 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 269 |
dp->width = right - left; |
270 |
dp->height = bottom - top; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
271 |
dp->left = left - (*wz)->left; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
272 |
dp->top = top - (*wz)->top; |
0 | 273 |
dp->pitch = _screen.pitch; |
9913
e79cd19772dd
(svn r10213) [gamebalance] -Sync: r10100:10200 from trunk
celestar
parents:
9911
diff
changeset
|
274 |
dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top); |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
275 |
dp->zoom = ZOOM_LVL_NORMAL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
276 |
CallWindowEventNP(*wz, WE_PAINT); |
0 | 277 |
} |
278 |
} |
|
279 |
||
280 |
void CallWindowEventNP(Window *w, int event) |
|
281 |
{ |
|
282 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
283 |
|
0 | 284 |
e.event = event; |
285 |
w->wndproc(w, &e); |
|
286 |
} |
|
287 |
||
4171 | 288 |
void SetWindowDirty(const Window *w) |
0 | 289 |
{ |
2549 | 290 |
if (w == NULL) return; |
0 | 291 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); |
292 |
} |
|
293 |
||
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
294 |
/** Find the Window whose parent pointer points to this window |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
295 |
* @param w parent Window to find child of |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
296 |
* @return a Window pointer that is the child of w, or NULL otherwise */ |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
297 |
static Window *FindChildWindow(const Window *w) |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
298 |
{ |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
299 |
Window* const *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
300 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
301 |
FOR_ALL_WINDOWS(wz) { |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
302 |
Window *v = *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
303 |
if (v->parent == w) return v; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
304 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
305 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
306 |
return NULL; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
307 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
308 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
309 |
/** Find the z-value of a window. A window must already be open |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
310 |
* or the behaviour is undefined but function should never fail |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
311 |
* @param w window to query Z Position |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
312 |
* @return the window that matches it */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
313 |
Window **FindWindowZPosition(const Window *w) |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
314 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
315 |
Window **wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
316 |
|
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
317 |
for (wz = _z_windows; wz != _last_z_window; wz++) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
318 |
if (*wz == w) return wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
319 |
} |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
320 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
321 |
DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls", |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
322 |
w->window_class, w->window_number); |
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
323 |
return NULL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
324 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
325 |
|
0 | 326 |
void DeleteWindow(Window *w) |
327 |
{ |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
328 |
Window *v; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
329 |
Window **wz; |
2639 | 330 |
if (w == NULL) return; |
0 | 331 |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
332 |
/* Delete any children a window might have in a head-recursive manner */ |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
333 |
v = FindChildWindow(w); |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
334 |
if (v != NULL) DeleteWindow(v); |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
335 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
336 |
if (_thd.place_mode != VHM_NONE && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
337 |
_thd.window_class == w->window_class && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
338 |
_thd.window_number == w->window_number) { |
0 | 339 |
ResetObjectToPlace(); |
340 |
} |
|
341 |
||
342 |
CallWindowEventNP(w, WE_DESTROY); |
|
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
343 |
if (w->viewport != NULL) DeleteWindowViewport(w); |
0 | 344 |
|
345 |
SetWindowDirty(w); |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
346 |
free(w->widget); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
347 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
348 |
w->widget_count = 0; |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
349 |
w->parent = NULL; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
350 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
351 |
/* Find the window in the z-array, and effectively remove it |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
352 |
* by moving all windows after it one to the left */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
353 |
wz = FindWindowZPosition(w); |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
354 |
if (wz == NULL) return; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
355 |
memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
356 |
_last_z_window--; |
0 | 357 |
} |
358 |
||
359 |
Window *FindWindowById(WindowClass cls, WindowNumber number) |
|
360 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
361 |
Window* const *wz; |
0 | 362 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
363 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
364 |
Window *w = *wz; |
2639 | 365 |
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
|
366 |
} |
0 | 367 |
|
368 |
return NULL; |
|
369 |
} |
|
370 |
||
371 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
|
372 |
{ |
|
373 |
DeleteWindow(FindWindowById(cls, number)); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
374 |
} |
0 | 375 |
|
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
|
376 |
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
|
377 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
378 |
Window* const *wz; |
2639 | 379 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
380 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
381 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
382 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
383 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
384 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
385 |
Window *w = *wz; |
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
|
386 |
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
|
387 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
388 |
goto restart_search; |
2639 | 389 |
} |
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
|
390 |
} |
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
|
391 |
} |
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
|
392 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
393 |
/** Delete all windows of a player. We identify windows of a player |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
394 |
* by looking at the caption colour. If it is equal to the player ID |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
395 |
* then we say the window belongs to the player and should be deleted |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
396 |
* @param id PlayerID player identifier */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
397 |
void DeletePlayerWindows(PlayerID id) |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
398 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
399 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
400 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
401 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
402 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
403 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
404 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
405 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
406 |
Window *w = *wz; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
407 |
if (w->caption_color == id) { |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
408 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
409 |
goto restart_search; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
410 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
411 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
412 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
413 |
/* Also delete the player specific windows, that don't have a player-colour */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
414 |
DeleteWindowById(WC_BUY_COMPANY, id); |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
415 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
416 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
417 |
/** Change the owner of all the windows one player can take over from another |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
418 |
* player in the case of a company merger. Do not change ownership of windows |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
419 |
* that need to be deleted once takeover is complete |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
420 |
* @param old_player PlayerID of original owner of the window |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
421 |
* @param new_player PlayerID of the new owner of the window */ |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
422 |
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player) |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
423 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
424 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
425 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
426 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
427 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
428 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
429 |
if (w->caption_color != old_player) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
430 |
if (w->window_class == WC_PLAYER_COLOR) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
431 |
if (w->window_class == WC_FINANCES) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
432 |
if (w->window_class == WC_STATION_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
433 |
if (w->window_class == WC_TRAINS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
434 |
if (w->window_class == WC_ROADVEH_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
435 |
if (w->window_class == WC_SHIPS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
436 |
if (w->window_class == WC_AIRCRAFT_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
437 |
if (w->window_class == WC_BUY_COMPANY) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
438 |
if (w->window_class == WC_COMPANY) continue; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
439 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
440 |
w->caption_color = new_player; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
441 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
442 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
443 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
444 |
static void BringWindowToFront(const Window *w); |
2817 | 445 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
446 |
/** Find a window and make it the top-window on the screen. The window |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
447 |
* gets a white border for a brief period of time to visualize its "activation" |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
448 |
* @param cls WindowClass of the window to activate |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
449 |
* @param number WindowNumber of the window to activate |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
450 |
* @return a pointer to the window thus activated */ |
0 | 451 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) |
452 |
{ |
|
453 |
Window *w = FindWindowById(cls, number); |
|
454 |
||
455 |
if (w != NULL) { |
|
456 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
457 |
BringWindowToFront(w); |
0 | 458 |
SetWindowDirty(w); |
459 |
} |
|
460 |
||
461 |
return w; |
|
462 |
} |
|
463 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
464 |
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
|
465 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
466 |
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
|
467 |
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
|
468 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
469 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
470 |
/** 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
|
471 |
* 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
|
472 |
* - 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
|
473 |
* - New window, Chatbar (only if open) |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
474 |
* The window is marked dirty for a repaint if the window is actually moved |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
475 |
* @param w window that is put into the foreground |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
476 |
* @return pointer to the window, the same as the input pointer |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
477 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
478 |
static void BringWindowToFront(const Window *w) |
0 | 479 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
480 |
Window *tempz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
481 |
Window **wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
482 |
Window **vz = _last_z_window; |
0 | 483 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
484 |
/* Bring the window just below the vital windows */ |
0 | 485 |
do { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
486 |
if (--vz < _z_windows) return; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
487 |
} while (IsVitalWindow(*vz)); |
0 | 488 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
489 |
if (wz == vz) return; // window is already in the right position |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
490 |
assert(wz < vz); |
0 | 491 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
492 |
tempz = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
493 |
memmove(wz, wz + 1, (byte*)vz - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
494 |
*vz = tempz; |
0 | 495 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
496 |
SetWindowDirty(w); |
0 | 497 |
} |
498 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
499 |
/** 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
|
500 |
* 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
|
501 |
* - 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
|
502 |
* - 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
|
503 |
* - 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
|
504 |
* @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
|
505 |
*/ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
506 |
static Window *FindDeletableWindow() |
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
|
507 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
508 |
Window* const *wz; |
2639 | 509 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
510 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
511 |
Window *w = *wz; |
2639 | 512 |
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) { |
513 |
return w; |
|
514 |
} |
|
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
|
515 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
516 |
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
|
517 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
518 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
519 |
/** 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
|
520 |
* 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
|
521 |
* windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar) |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
522 |
* Start finding an appropiate candidate from the lowest z-values (bottom) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
523 |
* @see FindDeletableWindow() |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
524 |
* @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
|
525 |
*/ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
526 |
static Window *ForceFindDeletableWindow() |
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
|
527 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
528 |
Window* const *wz; |
2639 | 529 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
530 |
for (wz = _z_windows;; wz++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
531 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
532 |
assert(wz < _last_z_window); |
2639 | 533 |
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
|
534 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
535 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
536 |
|
4171 | 537 |
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
|
538 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
539 |
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
|
540 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
541 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
542 |
/** Copies 'widget' to 'w->widget' to allow for resizable windows |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
543 |
* @param w Window on which to attach the widget array |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
544 |
* @param widget pointer of widget array to fill the window with */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
545 |
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
|
546 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
547 |
w->original_widget = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
548 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
549 |
if (widget != NULL) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
550 |
uint index = 1; |
4171 | 551 |
const Widget *wi; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
552 |
|
2639 | 553 |
for (wi = widget; wi->type != WWT_LAST; wi++) index++; |
554 |
||
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
555 |
w->widget = ReallocT(w->widget, index); |
2639 | 556 |
memcpy(w->widget, widget, sizeof(*w->widget) * index); |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
557 |
w->widget_count = index - 1; |
2639 | 558 |
} else { |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
559 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
560 |
w->widget_count = 0; |
2639 | 561 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
562 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
563 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
564 |
static Window *FindFreeWindow() |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
565 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
566 |
Window *w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
567 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
568 |
for (w = _windows; w < endof(_windows); w++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
569 |
Window* const *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
570 |
bool window_in_use = false; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
571 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
572 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
573 |
if (*wz == w) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
574 |
window_in_use = true; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
575 |
break; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
576 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
577 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
578 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
579 |
if (!window_in_use) return w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
580 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
581 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
582 |
assert(_last_z_window == endof(_z_windows)); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
583 |
return NULL; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
584 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
585 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
586 |
/** Open a new window. |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
587 |
* This function is called from AllocateWindow() or AllocateWindowDesc() |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
588 |
* See descriptions for those functions for usage |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
589 |
* See AllocateWindow() for description of arguments. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
590 |
* Only addition here is window_number, which is the window_number being assigned to the new window |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
591 |
* @param x offset in pixels from the left of the screen |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
592 |
* @param y offset in pixels from the top of the screen |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
593 |
* @param width width in pixels of the window |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
594 |
* @param height height in pixels of the window |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
595 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
596 |
* @param cls see WindowClass class of the window, used for identification and grouping |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
597 |
* @param *widget see Widget pointer to the window layout and various elements |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
598 |
* @param window_number number being assigned to the new window |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
599 |
* @return Window pointer of the newly created window */ |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
600 |
static Window *LocalAllocateWindow( |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
601 |
int x, int y, int width, int height, |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
602 |
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number) |
0 | 603 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
604 |
Window *w = FindFreeWindow(); |
0 | 605 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
606 |
/* We have run out of windows, close one and use that as the place for our new one */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
607 |
if (w == NULL) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
608 |
w = FindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
609 |
if (w == NULL) w = ForceFindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
610 |
DeleteWindow(w); |
0 | 611 |
} |
612 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
613 |
/* Set up window properties */ |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
614 |
memset(w, 0, sizeof(*w)); |
0 | 615 |
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
|
616 |
w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border |
0 | 617 |
w->caption_color = 0xFF; |
618 |
w->left = x; |
|
619 |
w->top = y; |
|
620 |
w->width = width; |
|
621 |
w->height = height; |
|
622 |
w->wndproc = proc; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
623 |
AssignWidgetToWindow(w, widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
624 |
w->resize.width = width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
625 |
w->resize.height = height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
626 |
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
|
627 |
w->resize.step_height = 1; |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
628 |
w->window_number = window_number; |
0 | 629 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
630 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
631 |
Window **wz = _last_z_window; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
632 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
633 |
/* Hacky way of specifying always-on-top windows. These windows are |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
634 |
* always above other windows because they are moved below them. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
635 |
* status-bar is above news-window because it has been created earlier. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
636 |
* Also, as the chat-window is excluded from this, it will always be |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
637 |
* the last window, thus always on top. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
638 |
* XXX - Yes, ugly, probably needs something like w->always_on_top flag |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
639 |
* to implement correctly, but even then you need some kind of distinction |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
640 |
* between on-top of chat/news and status windows, because these conflict */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
641 |
if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
642 |
if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
643 |
if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
644 |
if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
645 |
if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
646 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
647 |
assert(wz >= _z_windows); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
648 |
if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
649 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
650 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
651 |
*wz = w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
652 |
_last_z_window++; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
653 |
} |
0 | 654 |
|
655 |
SetWindowDirty(w); |
|
116
ca4332a9ec1d
(svn r117) Feature: Performance details window in company league menu (TrueLight)
dominik
parents:
86
diff
changeset
|
656 |
CallWindowEventNP(w, WE_CREATE); |
0 | 657 |
|
658 |
return w; |
|
659 |
} |
|
660 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
661 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
662 |
* Open a new window. If there is no space for a new window, close an open |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
663 |
* window. Try to avoid stickied windows, but if there is no else, close one of |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
664 |
* those as well. Then make sure all created windows are below some always-on-top |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
665 |
* ones. Finally set all variables and call the WE_CREATE event |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
666 |
* @param x offset in pixels from the left of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
667 |
* @param y offset in pixels from the top of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
668 |
* @param width width in pixels of the window |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
669 |
* @param height height in pixels of the window |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
670 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
671 |
* @param cls see WindowClass class of the window, used for identification and grouping |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
672 |
* @param *widget see Widget pointer to the window layout and various elements |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
673 |
* @return Window pointer of the newly created window */ |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
674 |
Window *AllocateWindow( |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
675 |
int x, int y, int width, int height, |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
676 |
WindowProc *proc, WindowClass cls, const Widget *widget) |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
677 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
678 |
return LocalAllocateWindow(x, y, width, height, proc, cls, widget, 0); |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
679 |
} |
0 | 680 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
681 |
struct SizeRect { |
0 | 682 |
int left,top,width,height; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
683 |
}; |
0 | 684 |
|
685 |
||
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
686 |
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos) |
0 | 687 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
688 |
Window* const *wz; |
0 | 689 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
690 |
int right = width + left; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
691 |
int bottom = height + top; |
0 | 692 |
|
693 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
694 |
return false; |
|
695 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
696 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
697 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
698 |
const Window *w = *wz; |
2639 | 699 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 700 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
701 |
if (right > w->left && |
2639 | 702 |
w->left + w->width > left && |
0 | 703 |
bottom > w->top && |
2639 | 704 |
w->top + w->height > top) { |
705 |
return false; |
|
706 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
707 |
} |
0 | 708 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
709 |
pos.x = left; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
710 |
pos.y = top; |
0 | 711 |
return true; |
712 |
} |
|
713 |
||
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
714 |
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos) |
0 | 715 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
716 |
Window* const *wz; |
0 | 717 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
718 |
if (left < -(width>>2) || left > _screen.width - (width>>1)) return false; |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
719 |
if (top < 22 || top > _screen.height - (height>>2)) return false; |
0 | 720 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
721 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
722 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
723 |
const Window *w = *wz; |
2639 | 724 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 725 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
726 |
if (left + width > w->left && |
2639 | 727 |
w->left + w->width > left && |
0 | 728 |
top + height > w->top && |
2639 | 729 |
w->top + w->height > top) { |
730 |
return false; |
|
731 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
732 |
} |
0 | 733 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
734 |
pos.x = left; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
735 |
pos.y = top; |
0 | 736 |
return true; |
737 |
} |
|
738 |
||
1095 | 739 |
static Point GetAutoPlacePosition(int width, int height) |
740 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
741 |
Window* const *wz; |
0 | 742 |
Point pt; |
743 |
||
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
744 |
if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt; |
0 | 745 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
746 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
747 |
const Window *w = *wz; |
2639 | 748 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 749 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
750 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
751 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
752 |
if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
753 |
if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
754 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
755 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
756 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
757 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pt)) return pt; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
758 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
759 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
760 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
761 |
const Window *w = *wz; |
2639 | 762 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 763 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
764 |
if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
765 |
if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
766 |
if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
767 |
if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pt)) return pt; |
0 | 768 |
} |
769 |
||
770 |
{ |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
771 |
int left = 0, top = 24; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
772 |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
773 |
restart: |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
774 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
775 |
const Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
776 |
|
0 | 777 |
if (w->left == left && w->top == top) { |
778 |
left += 5; |
|
779 |
top += 5; |
|
780 |
goto restart; |
|
781 |
} |
|
782 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
783 |
|
0 | 784 |
pt.x = left; |
785 |
pt.y = top; |
|
786 |
return pt; |
|
787 |
} |
|
788 |
} |
|
789 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
790 |
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number) |
0 | 791 |
{ |
792 |
Point pt; |
|
793 |
Window *w; |
|
794 |
||
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
795 |
/* By default position a child window at an offset of 10/10 of its parent. |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
796 |
* However if it falls too extremely outside window positions, reposition |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
797 |
* it to an automatic place */ |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
798 |
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
799 |
(w = FindWindowById(desc->parent_cls, window_number)) != NULL && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
800 |
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) { |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
801 |
|
0 | 802 |
pt.x = w->left + 10; |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
803 |
if (pt.x > _screen.width + 10 - desc->width) { |
0 | 804 |
pt.x = (_screen.width + 10 - desc->width) - 20; |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
805 |
} |
0 | 806 |
pt.y = w->top + 10; |
807 |
} else { |
|
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
808 |
switch (desc->left) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
809 |
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
810 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
811 |
pt.x = (w->left + w->width) - desc->width; |
9910
0b2aebc8283e
(svn r10134) [gamebalance] -Sync: r9670:9700 from trunk
celestar
parents:
9909
diff
changeset
|
812 |
} break; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
813 |
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
814 |
pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
815 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
816 |
case WDP_AUTO: /* Find a good automatic position for the window */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
817 |
pt = GetAutoPlacePosition(desc->width, desc->height); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
818 |
goto allocate_window; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
819 |
case WDP_CENTER: /* Centre the window horizontally */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
820 |
pt.x = (_screen.width - desc->width) / 2; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
821 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
822 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
823 |
pt.x = desc->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
824 |
if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
825 |
} |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
826 |
|
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
827 |
switch (desc->top) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
828 |
case WDP_CENTER: /* Centre the window vertically */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
829 |
pt.y = (_screen.height - desc->height) / 2; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
830 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
831 |
/* WDP_AUTO sets the position at once and is controlled by desc->left. |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
832 |
* Both left and top must be set to WDP_AUTO */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
833 |
case WDP_AUTO: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
834 |
NOT_REACHED(); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
835 |
assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
836 |
/* fallthrough */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
837 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
838 |
pt.y = desc->top; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
839 |
if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
840 |
break; |
0 | 841 |
} |
842 |
} |
|
843 |
||
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
844 |
allocate_window: |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
845 |
w = LocalAllocateWindow(pt.x, pt.y, desc->width, desc->height, desc->proc, desc->cls, desc->widgets, window_number); |
0 | 846 |
w->desc_flags = desc->flags; |
847 |
return w; |
|
848 |
} |
|
849 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
850 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
851 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
852 |
* @param *desc The pointer to the WindowDesc to be created |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
853 |
* @return Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
854 |
*/ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
855 |
Window *AllocateWindowDesc(const WindowDesc *desc) |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
856 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
857 |
return LocalAllocateWindowDesc(desc, 0); |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
858 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
859 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
860 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
861 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
862 |
* @param *desc The pointer to the WindowDesc to be created |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
863 |
* @param window_number the window number of the new window |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
864 |
* @return see Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
865 |
*/ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
866 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number) |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
867 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
868 |
Window *w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
869 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
870 |
if (BringWindowToFrontById(desc->cls, window_number)) return NULL; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
871 |
w = LocalAllocateWindowDesc(desc, window_number); |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
872 |
return w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
873 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
874 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
875 |
/** Do a search for a window at specific coordinates. For this we start |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
876 |
* at the topmost window, obviously and work our way down to the bottom |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
877 |
* @param x position x to query |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
878 |
* @param y position y to query |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
879 |
* @return a pointer to the found window if any, NULL otherwise */ |
0 | 880 |
Window *FindWindowFromPt(int x, int y) |
881 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
882 |
Window* const *wz; |
0 | 883 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
884 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
885 |
Window *w = *--wz; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
886 |
if (IS_INSIDE_1D(x, w->left, w->width) && IS_INSIDE_1D(y, w->top, w->height)) { |
2639 | 887 |
return w; |
888 |
} |
|
0 | 889 |
} |
890 |
||
891 |
return NULL; |
|
892 |
} |
|
893 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
894 |
void InitWindowSystem() |
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
|
895 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
896 |
IConsoleClose(); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
897 |
|
0 | 898 |
memset(&_windows, 0, sizeof(_windows)); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
899 |
_last_z_window = _z_windows; |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
900 |
InitViewports(); |
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
|
901 |
_no_scroll = 0; |
0 | 902 |
} |
903 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
904 |
void UnInitWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
905 |
{ |
5664 | 906 |
Window **wz; |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
907 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
908 |
restart_search: |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
909 |
/* Delete all windows, reset z-array. |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
910 |
*When we find the window to delete, we need to restart the search |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
911 |
* as deleting this window could cascade in deleting (many) others |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
912 |
* anywhere in the z-array. We call DeleteWindow() so that it can properly |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
913 |
* release own alloc'd memory, which otherwise could result in memleaks */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
914 |
FOR_ALL_WINDOWS(wz) { |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
915 |
DeleteWindow(*wz); |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
916 |
goto restart_search; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
917 |
} |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
918 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
919 |
assert(_last_z_window == _z_windows); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
920 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
921 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
922 |
void ResetWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
923 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
924 |
UnInitWindowSystem(); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
925 |
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
|
926 |
_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
|
927 |
_thd.pos.y = 0; |
2877
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
928 |
_thd.new_pos.x = 0; |
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
929 |
_thd.new_pos.y = 0; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
930 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
931 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
932 |
static void DecreaseWindowCounters() |
0 | 933 |
{ |
934 |
Window *w; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
935 |
Window* const *wz; |
0 | 936 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
937 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
938 |
w = *--wz; |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
939 |
/* Unclick scrollbar buttons if they are pressed. */ |
0 | 940 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
941 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
942 |
SetWindowDirty(w); |
|
943 |
} |
|
944 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
945 |
} |
|
946 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
947 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
948 |
w = *--wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
949 |
|
0 | 950 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
951 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
952 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) RaiseWindowButtons(w); |
0 | 953 |
} |
954 |
} |
|
955 |
} |
|
956 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
957 |
Window *GetCallbackWnd() |
0 | 958 |
{ |
959 |
return FindWindowById(_thd.window_class, _thd.window_number); |
|
960 |
} |
|
961 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
962 |
static void HandlePlacePresize() |
0 | 963 |
{ |
964 |
Window *w; |
|
965 |
WindowEvent e; |
|
966 |
||
2639 | 967 |
if (_special_mouse_mode != WSM_PRESIZE) return; |
0 | 968 |
|
2639 | 969 |
w = GetCallbackWnd(); |
970 |
if (w == NULL) return; |
|
0 | 971 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
972 |
e.we.place.pt = GetTileBelowCursor(); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
973 |
if (e.we.place.pt.x == -1) { |
0 | 974 |
_thd.selend.x = -1; |
975 |
return; |
|
976 |
} |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
977 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
0 | 978 |
e.event = WE_PLACE_PRESIZE; |
979 |
w->wndproc(w, &e); |
|
980 |
} |
|
981 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
982 |
static bool HandleDragDrop() |
0 | 983 |
{ |
984 |
Window *w; |
|
985 |
WindowEvent e; |
|
986 |
||
2639 | 987 |
if (_special_mouse_mode != WSM_DRAGDROP) return true; |
0 | 988 |
|
2639 | 989 |
if (_left_button_down) return false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
990 |
|
0 | 991 |
w = GetCallbackWnd(); |
992 |
||
993 |
ResetObjectToPlace(); |
|
994 |
||
2639 | 995 |
if (w != NULL) { |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
996 |
/* send an event in client coordinates. */ |
0 | 997 |
e.event = WE_DRAGDROP; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
998 |
e.we.dragdrop.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
999 |
e.we.dragdrop.pt.y = _cursor.pos.y - w->top; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1000 |
e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y); |
0 | 1001 |
w->wndproc(w, &e); |
1002 |
} |
|
1003 |
return false; |
|
1004 |
} |
|
1005 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1006 |
static bool HandlePopupMenu() |
0 | 1007 |
{ |
1008 |
Window *w; |
|
1009 |
WindowEvent e; |
|
1010 |
||
2639 | 1011 |
if (!_popup_menu_active) return true; |
0 | 1012 |
|
1013 |
w = FindWindowById(WC_TOOLBAR_MENU, 0); |
|
1014 |
if (w == NULL) { |
|
1015 |
_popup_menu_active = false; |
|
1016 |
return false; |
|
1017 |
} |
|
1018 |
||
1019 |
if (_left_button_down) { |
|
1020 |
e.event = WE_POPUPMENU_OVER; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1021 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1022 |
} else { |
1023 |
_popup_menu_active = false; |
|
1024 |
e.event = WE_POPUPMENU_SELECT; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1025 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1026 |
} |
1027 |
||
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
|
1028 |
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
|
1029 |
|
0 | 1030 |
return false; |
1031 |
} |
|
1032 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1033 |
static bool HandleMouseOver() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1034 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1035 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1036 |
WindowEvent e; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1037 |
static Window *last_w = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1038 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1039 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1040 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1041 |
/* We changed window, put a MOUSEOVER event to the last window */ |
2639 | 1042 |
if (last_w != NULL && last_w != w) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1043 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1044 |
e.we.mouseover.pt.x = -1; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1045 |
e.we.mouseover.pt.y = -1; |
2639 | 1046 |
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
|
1047 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1048 |
last_w = w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1049 |
|
2639 | 1050 |
if (w != NULL) { |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1051 |
/* send an event in client coordinates. */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1052 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1053 |
e.we.mouseover.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1054 |
e.we.mouseover.pt.y = _cursor.pos.y - w->top; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1055 |
if (w->widget != NULL) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1056 |
e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1057 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1058 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1059 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1060 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1061 |
/* Mouseover never stops execution */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1062 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1063 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1064 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1065 |
/** Update all the widgets of a window based on their resize flags |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1066 |
* Both the areas of the old window and the new sized window are set dirty |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1067 |
* ensuring proper redrawal. |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1068 |
* @param w Window to resize |
9909
dce9a6923bb7
(svn r10133) [gamebalance] -Sync: r9620:9670 from trunk
celestar
parents:
9908
diff
changeset
|
1069 |
* @param x delta x-size of changed window (positive if larger, etc.) |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1070 |
* @param y delta y-size of changed window */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1071 |
void ResizeWindow(Window *w, int x, int y) |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1072 |
{ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1073 |
Widget *wi; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1074 |
bool resize_height = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1075 |
bool resize_width = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1076 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1077 |
if (x == 0 && y == 0) return; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1078 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1079 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1080 |
for (wi = w->widget; wi->type != WWT_LAST; wi++) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1081 |
/* Isolate the resizing flags */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1082 |
byte rsizeflag = GB(wi->display_flags, 0, 4); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1083 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1084 |
if (rsizeflag == RESIZE_NONE) continue; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1085 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1086 |
/* Resize the widget based on its resize-flag */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1087 |
if (rsizeflag & RESIZE_LEFT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1088 |
wi->left += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1089 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1090 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1091 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1092 |
if (rsizeflag & RESIZE_RIGHT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1093 |
wi->right += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1094 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1095 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1096 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1097 |
if (rsizeflag & RESIZE_TOP) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1098 |
wi->top += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1099 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1100 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1101 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1102 |
if (rsizeflag & RESIZE_BOTTOM) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1103 |
wi->bottom += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1104 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1105 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1106 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1107 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1108 |
/* We resized at least 1 widget, so let's resize the window totally */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1109 |
if (resize_width) w->width += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1110 |
if (resize_height) w->height += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1111 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1112 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1113 |
} |
2596 | 1114 |
|
1115 |
static bool _dragging_window; |
|
1116 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1117 |
static bool HandleWindowDragging() |
0 | 1118 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1119 |
Window* const *wz; |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1120 |
/* Get out immediately if no window is being dragged at all. */ |
2639 | 1121 |
if (!_dragging_window) return true; |
0 | 1122 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1123 |
/* Otherwise find the window... */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1124 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1125 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1126 |
|
350 | 1127 |
if (w->flags4 & WF_DRAGGING) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1128 |
const Widget *t = &w->widget[1]; // the title bar ... ugh |
350 | 1129 |
const Window *v; |
1130 |
int x; |
|
1131 |
int y; |
|
1132 |
int nx; |
|
1133 |
int ny; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1134 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1135 |
/* Stop the dragging if the left mouse button was released */ |
0 | 1136 |
if (!_left_button_down) { |
350 | 1137 |
w->flags4 &= ~WF_DRAGGING; |
0 | 1138 |
break; |
1139 |
} |
|
1140 |
||
1141 |
SetWindowDirty(w); |
|
1142 |
||
350 | 1143 |
x = _cursor.pos.x + _drag_delta.x; |
1144 |
y = _cursor.pos.y + _drag_delta.y; |
|
1145 |
nx = x; |
|
1146 |
ny = y; |
|
1147 |
||
1148 |
if (_patches.window_snap_radius != 0) { |
|
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1149 |
Window* const *vz; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1150 |
|
353 | 1151 |
int hsnap = _patches.window_snap_radius; |
1152 |
int vsnap = _patches.window_snap_radius; |
|
1153 |
int delta; |
|
350 | 1154 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1155 |
FOR_ALL_WINDOWS(vz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1156 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1157 |
|
350 | 1158 |
if (v == w) continue; // Don't snap at yourself |
1159 |
||
1160 |
if (y + w->height > v->top && y < v->top + v->height) { |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1161 |
/* Your left border <-> other right border */ |
350 | 1162 |
delta = abs(v->left + v->width - x); |
1163 |
if (delta <= hsnap) { |
|
1164 |
nx = v->left + v->width; |
|
1165 |
hsnap = delta; |
|
1166 |
} |
|
1167 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1168 |
/* Your right border <-> other left border */ |
350 | 1169 |
delta = abs(v->left - x - w->width); |
1170 |
if (delta <= hsnap) { |
|
1171 |
nx = v->left - w->width; |
|
1172 |
hsnap = delta; |
|
1173 |
} |
|
1174 |
} |
|
1175 |
||
353 | 1176 |
if (w->top + w->height >= v->top && w->top <= v->top + v->height) { |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1177 |
/* Your left border <-> other left border */ |
353 | 1178 |
delta = abs(v->left - x); |
1179 |
if (delta <= hsnap) { |
|
1180 |
nx = v->left; |
|
1181 |
hsnap = delta; |
|
1182 |
} |
|
1183 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1184 |
/* Your right border <-> other right border */ |
353 | 1185 |
delta = abs(v->left + v->width - x - w->width); |
1186 |
if (delta <= hsnap) { |
|
1187 |
nx = v->left + v->width - w->width; |
|
1188 |
hsnap = delta; |
|
1189 |
} |
|
1190 |
} |
|
1191 |
||
350 | 1192 |
if (x + w->width > v->left && x < v->left + v->width) { |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1193 |
/* Your top border <-> other bottom border */ |
350 | 1194 |
delta = abs(v->top + v->height - y); |
1195 |
if (delta <= vsnap) { |
|
1196 |
ny = v->top + v->height; |
|
1197 |
vsnap = delta; |
|
1198 |
} |
|
1199 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1200 |
/* Your bottom border <-> other top border */ |
350 | 1201 |
delta = abs(v->top - y - w->height); |
1202 |
if (delta <= vsnap) { |
|
1203 |
ny = v->top - w->height; |
|
1204 |
vsnap = delta; |
|
1205 |
} |
|
1206 |
} |
|
353 | 1207 |
|
1208 |
if (w->left + w->width >= v->left && w->left <= v->left + v->width) { |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1209 |
/* Your top border <-> other top border */ |
353 | 1210 |
delta = abs(v->top - y); |
1211 |
if (delta <= vsnap) { |
|
1212 |
ny = v->top; |
|
1213 |
vsnap = delta; |
|
1214 |
} |
|
1215 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1216 |
/* Your bottom border <-> other bottom border */ |
353 | 1217 |
delta = abs(v->top + v->height - y - w->height); |
1218 |
if (delta <= vsnap) { |
|
1219 |
ny = v->top + v->height - w->height; |
|
1220 |
vsnap = delta; |
|
1221 |
} |
|
1222 |
} |
|
0 | 1223 |
} |
1224 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1225 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1226 |
/* Make sure the window doesn't leave the screen |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1227 |
* 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
|
1228 |
nx = clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
350 | 1229 |
ny = clamp(ny, 0, _screen.height - 13); |
1230 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1231 |
/* Make sure the title bar isn't hidden by behind the main tool bar */ |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1232 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1233 |
if (v != NULL) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1234 |
int v_bottom = v->top + v->height; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1235 |
int v_right = v->left + v->width; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1236 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
371 | 1237 |
if ((v->left < 13 && nx + t->left < v->left) || |
1238 |
(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
|
1239 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1240 |
} else { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1241 |
if (nx + t->left > v->left - 13 && |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1242 |
nx + t->right < v_right + 13) { |
2639 | 1243 |
if (w->top >= v_bottom) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1244 |
ny = v_bottom; |
2639 | 1245 |
} else if (w->left < nx) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1246 |
nx = v->left - 13 - t->left; |
2639 | 1247 |
} else { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1248 |
nx = v_right + 13 - t->right; |
2639 | 1249 |
} |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1250 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1251 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1252 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1253 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1254 |
|
350 | 1255 |
if (w->viewport != NULL) { |
1256 |
w->viewport->left += nx - w->left; |
|
1257 |
w->viewport->top += ny - w->top; |
|
1258 |
} |
|
1259 |
w->left = nx; |
|
1260 |
w->top = ny; |
|
1261 |
||
0 | 1262 |
SetWindowDirty(w); |
1263 |
return false; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1264 |
} 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
|
1265 |
WindowEvent e; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1266 |
int x, y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1267 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1268 |
/* 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
|
1269 |
if (!_left_button_down) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1270 |
w->flags4 &= ~WF_SIZING; |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1648
diff
changeset
|
1271 |
SetWindowDirty(w); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1272 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1273 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1274 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1275 |
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
|
1276 |
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
|
1277 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1278 |
/* 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
|
1279 |
* 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
|
1280 |
* unsigned int, which won't work. */ |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1281 |
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
|
1282 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1283 |
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
|
1284 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1285 |
/* 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
|
1286 |
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
|
1287 |
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
|
1288 |
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
|
1289 |
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
|
1290 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1291 |
/* Window already on size */ |
2639 | 1292 |
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
|
1293 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1294 |
/* 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
|
1295 |
we move in steps. */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1296 |
_drag_delta.x += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1297 |
_drag_delta.y += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1298 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1299 |
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1300 |
ResizeWindow(w, x, y); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1301 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1302 |
e.event = WE_RESIZE; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1303 |
e.we.sizing.size.x = x + w->width; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1304 |
e.we.sizing.size.y = y + w->height; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1305 |
e.we.sizing.diff.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1306 |
e.we.sizing.diff.y = y; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1307 |
w->wndproc(w, &e); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1308 |
return false; |
0 | 1309 |
} |
1310 |
} |
|
1311 |
||
1312 |
_dragging_window = false; |
|
1313 |
return false; |
|
1314 |
} |
|
1315 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1316 |
static void StartWindowDrag(Window *w) |
0 | 1317 |
{ |
1318 |
w->flags4 |= WF_DRAGGING; |
|
1319 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1320 |
|
350 | 1321 |
_drag_delta.x = w->left - _cursor.pos.x; |
1322 |
_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
|
1323 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1324 |
BringWindowToFront(w); |
0 | 1325 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1326 |
} |
|
1327 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1328 |
static void StartWindowSizing(Window *w) |
0 | 1329 |
{ |
1330 |
w->flags4 |= WF_SIZING; |
|
1331 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1332 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1333 |
_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
|
1334 |
_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
|
1335 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1336 |
BringWindowToFront(w); |
0 | 1337 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1338 |
} |
|
1339 |
||
1340 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1341 |
static bool HandleScrollbarScrolling() |
0 | 1342 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1343 |
Window* const *wz; |
0 | 1344 |
int i; |
1345 |
int pos; |
|
1346 |
Scrollbar *sb; |
|
1347 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1348 |
/* Get out quickly if no item is being scrolled */ |
2639 | 1349 |
if (!_scrolling_scrollbar) return true; |
0 | 1350 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1351 |
/* Find the scrolling window */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1352 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1353 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1354 |
|
0 | 1355 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1356 |
/* Abort if no button is clicked any more. */ |
0 | 1357 |
if (!_left_button_down) { |
1358 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
1359 |
SetWindowDirty(w); |
|
1360 |
break; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1361 |
} |
0 | 1362 |
|
1363 |
if (w->flags4 & WF_HSCROLL) { |
|
1364 |
sb = &w->hscroll; |
|
1365 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
842 | 1366 |
} else if (w->flags4 & WF_SCROLL2){ |
1367 |
sb = &w->vscroll2; |
|
1368 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
0 | 1369 |
} else { |
1370 |
sb = &w->vscroll; |
|
1371 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
1372 |
} |
|
1373 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1374 |
/* Find the item we want to move to and make sure it's inside bounds. */ |
0 | 1375 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
1376 |
if (pos != sb->pos) { |
|
1377 |
sb->pos = pos; |
|
1378 |
SetWindowDirty(w); |
|
1379 |
} |
|
1380 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1381 |
} |
0 | 1382 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1383 |
|
0 | 1384 |
_scrolling_scrollbar = false; |
1385 |
return false; |
|
1386 |
} |
|
1387 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1388 |
static bool HandleViewportScroll() |
0 | 1389 |
{ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1390 |
WindowEvent e; |
0 | 1391 |
Window *w; |
1392 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1393 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1394 |
|
2639 | 1395 |
if (!_scrolling_viewport) return true; |
0 | 1396 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1397 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1398 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1399 |
if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) { |
0 | 1400 |
_cursor.fix_at = false; |
1401 |
_scrolling_viewport = false; |
|
1402 |
return true; |
|
1403 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1404 |
|
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1405 |
if (_patches.reverse_scroll) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1406 |
e.we.scroll.delta.x = -_cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1407 |
e.we.scroll.delta.y = -_cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1408 |
} else { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1409 |
e.we.scroll.delta.x = _cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1410 |
e.we.scroll.delta.y = _cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1411 |
} |
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1412 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1413 |
if (scrollwheel_scrolling) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1414 |
/* We are using scrollwheels for scrolling */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1415 |
e.we.scroll.delta.x = _cursor.h_wheel; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1416 |
e.we.scroll.delta.y = _cursor.v_wheel; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1417 |
_cursor.v_wheel = 0; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1418 |
_cursor.h_wheel = 0; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1419 |
} |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1420 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1421 |
/* Create a scroll-event and send it to the window */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1422 |
e.event = WE_SCROLL; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1423 |
w->wndproc(w, &e); |
0 | 1424 |
|
2989 | 1425 |
_cursor.delta.x = 0; |
1426 |
_cursor.delta.y = 0; |
|
1427 |
return false; |
|
0 | 1428 |
} |
1429 |
||
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1430 |
/** Check if a window can be made top-most window, and if so do |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1431 |
* it. If a window does not obscure any other windows, it will not |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1432 |
* be brought to the foreground. Also if the only obscuring windows |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1433 |
* are so-called system-windows, the window will not be moved. |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1434 |
* The function will return false when a child window of this window is a |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1435 |
* modal-popup; function returns a false and child window gets a white border |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1436 |
* @param w Window to bring on-top |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1437 |
* @return false if the window has an active modal child, true otherwise */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1438 |
static bool MaybeBringWindowToFront(const Window *w) |
0 | 1439 |
{ |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1440 |
bool bring_to_front = false; |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1441 |
Window* const *wz; |
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1442 |
Window* const *uz; |
0 | 1443 |
|
2639 | 1444 |
if (w->window_class == WC_MAIN_WINDOW || |
1445 |
IsVitalWindow(w) || |
|
1446 |
w->window_class == WC_TOOLTIPS || |
|
1447 |
w->window_class == WC_DROPDOWN_MENU) { |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1448 |
return true; |
2639 | 1449 |
} |
0 | 1450 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1451 |
wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1452 |
for (uz = wz; ++uz != _last_z_window;) { |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1453 |
Window *u = *uz; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1454 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1455 |
/* A modal child will prevent the activation of the parent window */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1456 |
if (u->parent == w && (u->desc_flags & WDF_MODAL)) { |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1457 |
u->flags4 |= WF_WHITE_BORDER_MASK; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1458 |
SetWindowDirty(u); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1459 |
return false; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1460 |
} |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1461 |
|
2639 | 1462 |
if (u->window_class == WC_MAIN_WINDOW || |
1463 |
IsVitalWindow(u) || |
|
1464 |
u->window_class == WC_TOOLTIPS || |
|
1465 |
u->window_class == WC_DROPDOWN_MENU) { |
|
1466 |
continue; |
|
1467 |
} |
|
0 | 1468 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1469 |
/* Window sizes don't interfere, leave z-order alone */ |
0 | 1470 |
if (w->left + w->width <= u->left || |
1471 |
u->left + u->width <= w->left || |
|
1472 |
w->top + w->height <= u->top || |
|
2639 | 1473 |
u->top + u->height <= w->top) { |
1474 |
continue; |
|
1475 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1476 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1477 |
bring_to_front = true; |
0 | 1478 |
} |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1479 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1480 |
if (bring_to_front) BringWindowToFront(w); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1481 |
return true; |
0 | 1482 |
} |
1483 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1484 |
/** Send a message from one window to another. The receiving window is found by |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1485 |
* @param w Window pointer pointing to the other window |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1486 |
* @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
|
1487 |
* @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
|
1488 |
* @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
|
1489 |
*/ |
4171 | 1490 |
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
|
1491 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1492 |
WindowEvent e; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1493 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1494 |
e.event = WE_MESSAGE; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1495 |
e.we.message.msg = msg; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1496 |
e.we.message.wparam = wparam; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1497 |
e.we.message.lparam = lparam; |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1498 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1499 |
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
|
1500 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1501 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1502 |
/** Send a message from one window to another. The receiving window is found by |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1503 |
* @param wnd_class see WindowClass class AND |
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1504 |
* @param wnd_num see WindowNumber number, mostly 0 |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1505 |
* @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
|
1506 |
* @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
|
1507 |
* @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
|
1508 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1509 |
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1510 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1511 |
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
|
1512 |
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
|
1513 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1514 |
|
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1515 |
/** Send a message from one window to another. The message will be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1516 |
* to ALL windows of the windowclass specified in the first parameter |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1517 |
* @param wnd_class see WindowClass class |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1518 |
* @param msg Specifies the message to be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1519 |
* @param wparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1520 |
* @param lparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1521 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1522 |
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam) |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1523 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1524 |
Window* const *wz; |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1525 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1526 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1527 |
if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam); |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1528 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1529 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1530 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1531 |
/** Handle keyboard input. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1532 |
* @param key Lower 8 bits contain the ASCII character, the higher |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1533 |
* 16 bits the keycode */ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1534 |
void HandleKeypress(uint32 key) |
0 | 1535 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1536 |
Window* const *wz; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1537 |
WindowEvent e; |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1538 |
/* Stores if a window with a textfield for typing is open |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1539 |
* If this is the case, keypress events are only passed to windows with text fields and |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1540 |
* to thein this main toolbar. */ |
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
|
1541 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1542 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1543 |
/* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1544 |
* During the generation of the world, there might be |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1545 |
* another thread that is currently building for example |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1546 |
* a road. To not interfere with those tasks, we should |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1547 |
* NOT change the _current_player here. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1548 |
* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1549 |
* This is not necessary either, as the only events that |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1550 |
* can be handled are the 'close application' events |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1551 |
*/ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1552 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1553 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1554 |
/* Setup event */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1555 |
e.event = WE_KEYPRESS; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5090
diff
changeset
|
1556 |
e.we.keypress.key = GB(key, 0, 16); |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1557 |
e.we.keypress.keycode = GB(key, 16, 16); |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1558 |
e.we.keypress.cont = true; |
0 | 1559 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1560 |
/* check if we have a query string window open before allowing hotkeys */ |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1561 |
if (FindWindowById(WC_QUERY_STRING, 0) != NULL || |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1562 |
FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL || |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1563 |
FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL || |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1564 |
FindWindowById(WC_CONSOLE, 0) != NULL || |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1565 |
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
|
1566 |
query_open = true; |
2639 | 1567 |
} |
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
|
1568 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1569 |
/* Call the event, start with the uppermost window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1570 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1571 |
Window *w = *--wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1572 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1573 |
/* if a query window is open, only call the event for certain window types */ |
2639 | 1574 |
if (query_open && |
1575 |
w->window_class != WC_QUERY_STRING && |
|
1576 |
w->window_class != WC_SEND_NETWORK_MSG && |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1577 |
w->window_class != WC_GENERATE_LANDSCAPE && |
2639 | 1578 |
w->window_class != WC_CONSOLE && |
1579 |
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
|
1580 |
continue; |
2639 | 1581 |
} |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1582 |
w->wndproc(w, &e); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1583 |
if (!e.we.keypress.cont) break; |
0 | 1584 |
} |
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
|
1585 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1586 |
if (e.we.keypress.cont) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1587 |
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1588 |
/* When there is no toolbar w is null, check for that */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1589 |
if (w != NULL) w->wndproc(w, &e); |
1642
593a9b750b91
(svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents:
1637
diff
changeset
|
1590 |
} |
0 | 1591 |
} |
1592 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1593 |
extern void UpdateTileSelection(); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1594 |
extern bool VpHandlePlaceSizingDrag(); |
0 | 1595 |
|
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1596 |
static int _input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1597 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1598 |
static void HandleAutoscroll() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1599 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1600 |
Window *w; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1601 |
ViewPort *vp; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1602 |
int x = _cursor.pos.x; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1603 |
int y = _cursor.pos.y; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1604 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1605 |
if (_input_events_this_tick != 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1606 |
/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1607 |
_input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1608 |
/* there were some inputs this tick, don't scroll ??? */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1609 |
return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1610 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1611 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1612 |
if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1613 |
w = FindWindowFromPt(x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1614 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1615 |
vp = IsPtInWindowViewport(w, x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1616 |
if (vp != NULL) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1617 |
x -= vp->left; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1618 |
y -= vp->top; |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1619 |
/* here allows scrolling in both x and y axis */ |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1620 |
#define scrollspeed 3 |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1621 |
if (x - 15 < 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1622 |
WP(w, vp_d).scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1623 |
} else if (15 - (vp->width - x) > 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1624 |
WP(w, vp_d).scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1625 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1626 |
if (y - 15 < 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1627 |
WP(w, vp_d).scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1628 |
} else if (15 - (vp->height - y) > 0) { |
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1629 |
WP(w,vp_d).scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1630 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1631 |
#undef scrollspeed |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1632 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1633 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1634 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1635 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1636 |
void MouseLoop(int click, int mousewheel) |
0 | 1637 |
{ |
1638 |
int x,y; |
|
1639 |
Window *w; |
|
1640 |
ViewPort *vp; |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1641 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1642 |
|
0 | 1643 |
DecreaseWindowCounters(); |
1644 |
HandlePlacePresize(); |
|
1645 |
UpdateTileSelection(); |
|
2639 | 1646 |
if (!VpHandlePlaceSizingDrag()) return; |
1647 |
if (!HandleDragDrop()) return; |
|
1648 |
if (!HandlePopupMenu()) return; |
|
1649 |
if (!HandleWindowDragging()) return; |
|
1650 |
if (!HandleScrollbarScrolling()) return; |
|
1651 |
if (!HandleViewportScroll()) return; |
|
1652 |
if (!HandleMouseOver()) return; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1653 |
|
0 | 1654 |
x = _cursor.pos.x; |
1655 |
y = _cursor.pos.y; |
|
1656 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1657 |
if (click == 0 && mousewheel == 0 && !scrollwheel_scrolling) return; |
0 | 1658 |
|
1659 |
w = FindWindowFromPt(x, y); |
|
2639 | 1660 |
if (w == NULL) return; |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1661 |
if (!MaybeBringWindowToFront(w)) return; |
0 | 1662 |
vp = IsPtInWindowViewport(w, x, y); |
1663 |
||
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1664 |
/* Don't allow any action in a viewport if either in menu of in generating world */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1665 |
if (vp != NULL && (_game_mode == GM_MENU || IsGeneratingWorld())) return; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1666 |
|
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1667 |
if (mousewheel != 0) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1668 |
if (_patches.scrollwheel_scrolling == 0) { |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1669 |
/* Scrollwheel is in zoom mode. Make the zoom event. */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1670 |
WindowEvent e; |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1671 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1672 |
/* Send WE_MOUSEWHEEL event to window */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1673 |
e.event = WE_MOUSEWHEEL; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1674 |
e.we.wheel.wheel = mousewheel; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1675 |
w->wndproc(w, &e); |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1676 |
} |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1677 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1678 |
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1679 |
if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1680 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1681 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1682 |
if (vp != NULL) { |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1683 |
if (scrollwheel_scrolling) click = 2; // we are using the scrollwheel in a viewport, so we emulate right mouse button |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1684 |
switch (click) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1685 |
case 1: |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1686 |
DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1687 |
if (_thd.place_mode != 0 && |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1688 |
/* query button and place sign button work in pause mode */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1689 |
_cursor.sprite != SPR_CURSOR_QUERY && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1690 |
_cursor.sprite != SPR_CURSOR_SIGN && |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1691 |
_pause_game != 0 && |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1692 |
!_cheats.build_in_pause.value) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1693 |
return; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1694 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1695 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1696 |
if (_thd.place_mode == 0) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1697 |
HandleViewportClicked(vp, x, y); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1698 |
} else { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1699 |
PlaceObject(); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1700 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1701 |
break; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1702 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1703 |
case 2: |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1704 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1705 |
_scrolling_viewport = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1706 |
_cursor.fix_at = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1707 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1708 |
break; |
0 | 1709 |
} |
1710 |
} else { |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1711 |
switch (click) { |
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1712 |
case 1: DispatchLeftClickEvent(w, x - w->left, y - w->top); break; |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1713 |
default: |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1714 |
if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break; |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1715 |
/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons. |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1716 |
* Simulate a right button click so we can get started. */ |
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1717 |
/* fallthough */ |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1718 |
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
|
1719 |
} |
0 | 1720 |
} |
1721 |
} |
|
1722 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1723 |
void HandleMouseEvents() |
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
|
1724 |
{ |
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
|
1725 |
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
|
1726 |
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
|
1727 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1728 |
/* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1729 |
* During the generation of the world, there might be |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1730 |
* another thread that is currently building for example |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1731 |
* a road. To not interfere with those tasks, we should |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1732 |
* NOT change the _current_player here. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1733 |
* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1734 |
* This is not necessary either, as the only events that |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1735 |
* can be handled are the 'close application' events |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1736 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1737 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
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
|
1738 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1739 |
/* Mouse event? */ |
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
|
1740 |
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
|
1741 |
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
|
1742 |
_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
|
1743 |
click = 1; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1744 |
_input_events_this_tick++; |
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
|
1745 |
} 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
|
1746 |
_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
|
1747 |
click = 2; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1748 |
_input_events_this_tick++; |
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
|
1749 |
} |
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
|
1750 |
|
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
|
1751 |
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
|
1752 |
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
|
1753 |
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
|
1754 |
_cursor.wheel = 0; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1755 |
_input_events_this_tick++; |
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
|
1756 |
} |
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
|
1757 |
|
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
|
1758 |
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
|
1759 |
} |
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
|
1760 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1761 |
void InputLoop() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1762 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1763 |
HandleMouseEvents(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1764 |
HandleAutoscroll(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1765 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1766 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1767 |
void UpdateWindows() |
0 | 1768 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1769 |
Window* const *wz; |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1770 |
static int we4_timer = 0; |
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1771 |
int t = we4_timer + 1; |
0 | 1772 |
|
2639 | 1773 |
if (t >= 100) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1774 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1775 |
CallWindowEventNP(*--wz, WE_4); |
0 | 1776 |
} |
1777 |
t = 0; |
|
1778 |
} |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1779 |
we4_timer = t; |
0 | 1780 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1781 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1782 |
Window *w = *--wz; |
0 | 1783 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
1784 |
w->flags4 -= WF_WHITE_BORDER_ONE; |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1785 |
|
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1786 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w); |
0 | 1787 |
} |
1788 |
} |
|
1789 |
||
1790 |
DrawDirtyBlocks(); |
|
1791 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1792 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1793 |
if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz); |
0 | 1794 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1795 |
DrawTextMessage(); |
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1796 |
/* Redraw mouse cursor in case it was hidden */ |
0 | 1797 |
DrawMouseCursor(); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1798 |
} |
0 | 1799 |
|
1800 |
||
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
|
1801 |
int GetMenuItemIndex(const Window *w, int x, int y) |
0 | 1802 |
{ |
1803 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
1804 |
y /= 10; |
|
1805 |
||
2639 | 1806 |
if (y < WP(w, const menu_d).item_count && |
1807 |
!HASBIT(WP(w, const menu_d).disabled_items, y)) { |
|
0 | 1808 |
return y; |
2639 | 1809 |
} |
0 | 1810 |
} |
1811 |
return -1; |
|
1812 |
} |
|
1813 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1814 |
void InvalidateWindow(WindowClass cls, WindowNumber number) |
0 | 1815 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1816 |
Window* const *wz; |
0 | 1817 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1818 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1819 |
const Window *w = *wz; |
2639 | 1820 |
if (w->window_class == cls && w->window_number == number) SetWindowDirty(w); |
0 | 1821 |
} |
1822 |
} |
|
1823 |
||
4171 | 1824 |
void InvalidateWidget(const Window *w, byte widget_index) |
0 | 1825 |
{ |
1826 |
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
|
1827 |
|
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
|
1828 |
/* Don't redraw the window if the widget is invisible or of no-type */ |
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
1829 |
if (wi->type == WWT_EMPTY || IsWindowWidgetHidden(w, widget_index)) return; |
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
|
1830 |
|
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
|
1831 |
SetDirtyBlocks(w->left + wi->left, w->top + wi->top, w->left + wi->right + 1, w->top + wi->bottom + 1); |
0 | 1832 |
} |
1833 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1834 |
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index) |
0 | 1835 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1836 |
Window* const *wz; |
0 | 1837 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1838 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1839 |
const Window *w = *wz; |
2639 | 1840 |
if (w->window_class == cls && w->window_number == number) { |
0 | 1841 |
InvalidateWidget(w, widget_index); |
1842 |
} |
|
1843 |
} |
|
1844 |
} |
|
1845 |
||
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
1846 |
void InvalidateWindowClasses(WindowClass cls) |
0 | 1847 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1848 |
Window* const *wz; |
2639 | 1849 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1850 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1851 |
if ((*wz)->window_class == cls) SetWindowDirty(*wz); |
0 | 1852 |
} |
1853 |
} |
|
1854 |
||
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1855 |
void InvalidateThisWindowData(Window *w) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1856 |
{ |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1857 |
CallWindowEventNP(w, WE_INVALIDATE_DATA); |
5198
2547d72f2db4
(svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents:
5143
diff
changeset
|
1858 |
SetWindowDirty(w); |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1859 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1860 |
|
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1861 |
void InvalidateWindowData(WindowClass cls, WindowNumber number) |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1862 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1863 |
Window* const *wz; |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1864 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1865 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1866 |
Window *w = *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1867 |
if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w); |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1868 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1869 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1870 |
|
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1871 |
void InvalidateWindowClassesData(WindowClass cls) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1872 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1873 |
Window* const *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
1874 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1875 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1876 |
if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1877 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
1878 |
} |
0 | 1879 |
|
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1880 |
void CallWindowTickEvent() |
0 | 1881 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1882 |
Window* const *wz; |
2639 | 1883 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1884 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1885 |
CallWindowEventNP(*--wz, WE_TICK); |
0 | 1886 |
} |
1887 |
} |
|
1888 |
||
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1889 |
void DeleteNonVitalWindows() |
0 | 1890 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1891 |
Window* const *wz; |
2639 | 1892 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1893 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1894 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1895 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1896 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1897 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1898 |
Window *w = *wz; |
0 | 1899 |
if (w->window_class != WC_MAIN_WINDOW && |
1900 |
w->window_class != WC_SELECT_GAME && |
|
1901 |
w->window_class != WC_MAIN_TOOLBAR && |
|
1902 |
w->window_class != WC_STATUS_BAR && |
|
1903 |
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
|
1904 |
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
|
1905 |
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned' |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1906 |
|
0 | 1907 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1908 |
goto restart_search; |
0 | 1909 |
} |
1910 |
} |
|
1911 |
} |
|
1912 |
||
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1913 |
/** 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
|
1914 |
* '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
|
1915 |
* 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
|
1916 |
* 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
|
1917 |
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1918 |
void DeleteAllNonVitalWindows() |
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
|
1919 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1920 |
Window* const *wz; |
2639 | 1921 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1922 |
/* Delete every window except for stickied ones, then sticky ones as well */ |
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
|
1923 |
DeleteNonVitalWindows(); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1924 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1925 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1926 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1927 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1928 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1929 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1930 |
if ((*wz)->flags4 & WF_STICKY) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1931 |
DeleteWindow(*wz); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
1932 |
goto restart_search; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1933 |
} |
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
|
1934 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1935 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
1936 |
|
9908
0fa543611bbe
(svn r10112) [gamebalance] -Sync: r9520:9620 from trunk
celestar
parents:
9895
diff
changeset
|
1937 |
/** Delete all always on-top windows to get an empty screen */ |
9895
7bd07f43b0e3
(svn r9321) [gamebalance] -Sync: r9025:9314 from trunk
celestar
parents:
6443
diff
changeset
|
1938 |
void HideVitalWindows() |
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
|
1939 |
{ |
6158
ca1471170695
(svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
rubidium
parents:
5893
diff
changeset
|
1940 |
DeleteWindowById(WC_TOOLBAR_MENU, 0); |
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
|
1941 |
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
|
1942 |
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
|
1943 |
} |
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
|
1944 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1945 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1946 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1947 |
DEBUG(misc, 5, "Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1948 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1949 |
if (w == NULL || w->window_class != WC_MAIN_TOOLBAR) { |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1950 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
1951 |
} |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1952 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1953 |
switch (_patches.toolbar_pos) { |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
1954 |
case 1: w->left = (_screen.width - w->width) / 2; break; |
2026 | 1955 |
case 2: w->left = _screen.width - w->width; break; |
1956 |
default: w->left = 0; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1957 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1958 |
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
|
1959 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1960 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
1961 |
|
0 | 1962 |
void RelocateAllWindows(int neww, int newh) |
1963 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1964 |
Window* const *wz; |
0 | 1965 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1966 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1967 |
Window *w = *wz; |
0 | 1968 |
int left, top; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1969 |
|
0 | 1970 |
if (w->window_class == WC_MAIN_WINDOW) { |
1971 |
ViewPort *vp = w->viewport; |
|
1972 |
vp->width = w->width = neww; |
|
1973 |
vp->height = w->height = newh; |
|
9911
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1974 |
vp->virtual_width = ScaleByZoom(neww, vp->zoom); |
0b8b245a2391
(svn r10135) [gamebalance] -Sync: r9700:9900 from trunk
celestar
parents:
9910
diff
changeset
|
1975 |
vp->virtual_height = ScaleByZoom(newh, vp->zoom); |
0 | 1976 |
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
|
1977 |
} |
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
|
1978 |
|
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
1979 |
/* XXX - this probably needs something more sane. For example specying |
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
1980 |
* in a 'backup'-desc that the window should always be centred. */ |
2989 | 1981 |
switch (w->window_class) { |
1982 |
case WC_MAIN_TOOLBAR: |
|
1983 |
top = w->top; |
|
1984 |
left = PositionMainToolbar(w); // changes toolbar orientation |
|
1985 |
break; |
|
1986 |
||
1987 |
case WC_SELECT_GAME: |
|
1988 |
case WC_GAME_OPTIONS: |
|
1989 |
case WC_NETWORK_WINDOW: |
|
1990 |
top = (newh - w->height) >> 1; |
|
1991 |
left = (neww - w->width) >> 1; |
|
1992 |
break; |
|
1993 |
||
1994 |
case WC_NEWS_WINDOW: |
|
1995 |
top = newh - w->height; |
|
1996 |
left = (neww - w->width) >> 1; |
|
1997 |
break; |
|
1998 |
||
1999 |
case WC_STATUS_BAR: |
|
2000 |
top = newh - w->height; |
|
2001 |
left = (neww - w->width) >> 1; |
|
2002 |
break; |
|
2003 |
||
2004 |
case WC_SEND_NETWORK_MSG: |
|
2005 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
|
2006 |
left = (neww - w->width) >> 1; |
|
2007 |
break; |
|
2008 |
||
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2009 |
case WC_CONSOLE: |
5143
a78072872bff
(svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents:
5137
diff
changeset
|
2010 |
IConsoleResize(w); |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2011 |
continue; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2012 |
|
2989 | 2013 |
default: |
2014 |
left = w->left; |
|
2015 |
if (left + (w->width >> 1) >= neww) left = neww - w->width; |
|
2016 |
top = w->top; |
|
2017 |
if (top + (w->height >> 1) >= newh) top = newh - w->height; |
|
2018 |
break; |
|
0 | 2019 |
} |
2020 |
||
2639 | 2021 |
if (w->viewport != NULL) { |
0 | 2022 |
w->viewport->left += left - w->left; |
2023 |
w->viewport->top += top - w->top; |
|
2024 |
} |
|
2025 |
||
2026 |
w->left = left; |
|
2027 |
w->top = top; |
|
2028 |
} |
|
2029 |
} |