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