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