author | rubidium |
Sat, 12 Apr 2008 21:38:49 +0000 | |
branch | noai |
changeset 10142 | 56ee7da4ad56 |
parent 9826 | 9707ad4c9b60 |
child 10181 | 54df587fef5d |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6443
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
3 |
/** @file window.cpp windowing system, widgets and events */ |
b8f06d8eb7be
(svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents:
6158
diff
changeset
|
4 |
|
0 | 5 |
#include "stdafx.h" |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
6 |
#include <stdarg.h> |
1891
92a3b0aa0946
(svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents:
1867
diff
changeset
|
7 |
#include "openttd.h" |
1299
0a6510cc889b
(svn r1803) Move debugging stuff into files of it's own
tron
parents:
1112
diff
changeset
|
8 |
#include "debug.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
9 |
#include "player_func.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
10 |
#include "gfx_func.h" |
126 | 11 |
#include "console.h" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
12 |
#include "viewport_func.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
2154
diff
changeset
|
13 |
#include "variables.h" |
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
14 |
#include "genworld.h" |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
15 |
#include "blitter/factory.hpp" |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
16 |
#include "window_gui.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
17 |
#include "zoom_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
18 |
#include "core/alloc_func.hpp" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
19 |
#include "map_func.h" |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
20 |
#include "vehicle_base.h" |
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
21 |
#include "settings_type.h" |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
22 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
23 |
#include "table/sprites.h" |
0 | 24 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
25 |
/** delta between mouse cursor and upper left corner of dragged window */ |
350 | 26 |
static Point _drag_delta; |
27 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
28 |
static Window _windows[MAX_NUMBER_OF_WINDOWS]; |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
29 |
|
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
30 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
31 |
* List of windows opened at the screen. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
32 |
* Uppermost window is at _z_windows[_last_z_window - 1], |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
33 |
* bottom window is at _z_windows[0] |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
34 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
35 |
Window *_z_windows[lengthof(_windows)]; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
36 |
Window **_last_z_window; ///< always points to the next free space in the z-array |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
37 |
|
9724
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
38 |
Point _cursorpos_drag_start; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
39 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
40 |
int _scrollbar_start_pos; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
41 |
int _scrollbar_size; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
42 |
byte _scroller_click_timeout; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
43 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
44 |
bool _scrolling_scrollbar; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
45 |
bool _scrolling_viewport; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
46 |
bool _popup_menu_active; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
47 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
48 |
byte _special_mouse_mode; |
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
49 |
|
b39bc69bb2f2
(svn r12051) [NoAI] -Sync: with trunk (r11795:12050).
rubidium
parents:
9723
diff
changeset
|
50 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
51 |
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...) |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
52 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
53 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
54 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
55 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
56 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
57 |
while (widgets != WIDGET_LIST_END) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
58 |
SetWidgetDisabledState(widgets, disab_stat); |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
59 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
60 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
61 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
62 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
63 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
64 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
65 |
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...) |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
66 |
{ |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
67 |
va_list wdg_list; |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
68 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
69 |
va_start(wdg_list, widgets); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
70 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
71 |
while (widgets != WIDGET_LIST_END) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
72 |
SetWidgetHiddenState(widgets, hidden_stat); |
4755
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
73 |
widgets = va_arg(wdg_list, int); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
74 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
75 |
|
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
76 |
va_end(wdg_list); |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
77 |
} |
4a3564952554
(svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents:
4749
diff
changeset
|
78 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
79 |
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
80 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
81 |
va_list wdg_list; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
82 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
83 |
va_start(wdg_list, widgets); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
84 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
85 |
while (widgets != WIDGET_LIST_END) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
86 |
SetWidgetLoweredState(widgets, lowered_stat); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
87 |
widgets = va_arg(wdg_list, int); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
88 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
89 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
90 |
va_end(wdg_list); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
91 |
} |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
92 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
93 |
void Window::RaiseButtons() |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
94 |
{ |
5235
3c309f43f0a6
(svn r7355) -Codechange: replace 'for (i = 0; w->widget[i].type != WWT_TYPE; i++)'-type for loops with 'for (i = 0; i < w->widget_count; i++)'-type for loops
rubidium
parents:
5232
diff
changeset
|
95 |
uint i; |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
96 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
97 |
for (i = 0; i < this->widget_count; i++) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
98 |
if (this->IsWidgetLowered(i)) { |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
99 |
this->RaiseWidget(i); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
100 |
this->InvalidateWidget(i); |
4719
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
101 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
102 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
103 |
} |
413b21513ef7
(svn r6631) -Codechange: Use accessors for click_state.
belugas
parents:
4634
diff
changeset
|
104 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
105 |
void Window::InvalidateWidget(byte widget_index) const |
0 | 106 |
{ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
107 |
const Widget *wi = &this->widget[widget_index]; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
108 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
109 |
/* Don't redraw the window if the widget is invisible or of no-type */ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
110 |
if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
111 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
112 |
SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1); |
0 | 113 |
} |
114 |
||
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
115 |
void Window::HandleButtonClick(byte widget) |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
116 |
{ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
117 |
this->LowerWidget(widget); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
118 |
this->flags4 |= 5 << WF_TIMEOUT_SHL; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
119 |
this->InvalidateWidget(widget); |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
120 |
} |
2817 | 121 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
122 |
static void StartWindowDrag(Window *w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
123 |
static void StartWindowSizing(Window *w); |
2817 | 124 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
125 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
126 |
* Dispatch left mouse-button (possibly double) click in window. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
127 |
* @param w Window to dispatch event in |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
128 |
* @param x X coordinate of the click |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
129 |
* @param y Y coordinate of the click |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
130 |
* @param double_click Was it a double click? |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
131 |
*/ |
9629 | 132 |
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click) |
2596 | 133 |
{ |
0 | 134 |
WindowEvent e; |
135 |
const Widget *wi; |
|
136 |
||
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
137 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
138 |
e.we.click.pt.y = y; |
9629 | 139 |
e.event = double_click ? WE_DOUBLE_CLICK : WE_CLICK; |
0 | 140 |
|
141 |
if (w->desc_flags & WDF_DEF_WIDGET) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
142 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
9574 | 143 |
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
|
144 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
145 |
/* don't allow any interaction if the button has been disabled */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
146 |
if (w->IsWidgetDisabled(e.we.click.widget)) return; |
222
b88456001397
(svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents:
211
diff
changeset
|
147 |
|
5236
e959e132a78e
(svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents:
5235
diff
changeset
|
148 |
wi = &w->widget[e.we.click.widget]; |
0 | 149 |
|
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
150 |
if (wi->type & WWB_MASK) { |
211 | 151 |
/* special widget handling for buttons*/ |
2952 | 152 |
switch (wi->type) { |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
153 |
case WWT_PANEL | WWB_PUSHBUTTON: /* WWT_PUSHBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
154 |
case WWT_IMGBTN | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */ |
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
155 |
case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
156 |
w->HandleButtonClick(e.we.click.widget); |
4938
074f734a91ca
(svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents:
4766
diff
changeset
|
157 |
break; |
0 | 158 |
} |
842 | 159 |
} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
160 |
ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y); |
0 | 161 |
} |
162 |
||
163 |
if (w->desc_flags & WDF_STD_BTN) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
164 |
if (e.we.click.widget == 0) { /* 'X' */ |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
165 |
DeleteWindow(w); |
984
a50e131688d2
(svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents:
983
diff
changeset
|
166 |
return; |
1109
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
167 |
} |
1bab892228cd
(svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents:
1101
diff
changeset
|
168 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
169 |
if (e.we.click.widget == 1) { /* 'Title bar' */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
170 |
StartWindowDrag(w); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
171 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
172 |
} |
0 | 173 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
174 |
|
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
175 |
if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
176 |
StartWindowSizing(w); |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
177 |
w->InvalidateWidget(e.we.click.widget); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
178 |
return; |
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
179 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
180 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
181 |
if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
182 |
w->flags4 ^= WF_STICKY; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
183 |
w->InvalidateWidget(e.we.click.widget); |
1112
32f3e7a98095
(svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents:
1109
diff
changeset
|
184 |
return; |
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
185 |
} |
0 | 186 |
} |
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
187 |
|
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
188 |
w->wndproc(w, &e); |
0 | 189 |
} |
190 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
191 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
192 |
* Dispatch right mouse-button click in window. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
193 |
* @param w Window to dispatch event in |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
194 |
* @param x X coordinate of the click |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
195 |
* @param y Y coordinate of the click |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
196 |
*/ |
4171 | 197 |
static void DispatchRightClickEvent(Window *w, int x, int y) |
2596 | 198 |
{ |
0 | 199 |
WindowEvent e; |
200 |
||
201 |
/* default tooltips handler? */ |
|
202 |
if (w->desc_flags & WDF_STD_TOOLTIPS) { |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
203 |
e.we.click.widget = GetWidgetFromPos(w, x, y); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
204 |
if (e.we.click.widget < 0) |
9574 | 205 |
return; // exit if clicked outside of widgets |
0 | 206 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
207 |
if (w->widget[e.we.click.widget].tooltips != 0) { |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
208 |
GuiShowTooltips(w->widget[e.we.click.widget].tooltips); |
0 | 209 |
return; |
210 |
} |
|
211 |
} |
|
212 |
||
213 |
e.event = WE_RCLICK; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
214 |
e.we.click.pt.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
215 |
e.we.click.pt.y = y; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
216 |
w->wndproc(w, &e); |
0 | 217 |
} |
218 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
219 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
220 |
* Dispatch the mousewheel-action to the window. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
221 |
* The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
222 |
* @param w Window |
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
223 |
* @param widget the widget where the scrollwheel was used |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
224 |
* @param wheel scroll up or down |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
225 |
*/ |
4171 | 226 |
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel) |
0 | 227 |
{ |
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
228 |
const Widget *wi1, *wi2; |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
229 |
Scrollbar *sb; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
230 |
|
2021
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
231 |
if (widget < 0) return; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
232 |
|
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
233 |
wi1 = &w->widget[widget]; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
234 |
wi2 = &w->widget[widget + 1]; |
3be628c59488
(svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents:
1980
diff
changeset
|
235 |
|
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
236 |
/* The listbox can only scroll if scrolling was done on the scrollbar itself, |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
237 |
* or on the listbox (and the next item is (must be) the scrollbar) |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
238 |
* XXX - should be rewritten as a widget-dependent scroller but that's |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
239 |
* not happening until someone rewrites the whole widget-code */ |
1019
6363b8a4273e
(svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents:
999
diff
changeset
|
240 |
if ((sb = &w->vscroll, wi1->type == WWT_SCROLLBAR) || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR) || |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
241 |
(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
242 |
|
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
243 |
if (sb->count > sb->cap) { |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
244 |
int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap); |
982
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
245 |
if (pos != sb->pos) { |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
246 |
sb->pos = pos; |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
247 |
SetWindowDirty(w); |
be834034b331
(svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents:
959
diff
changeset
|
248 |
} |
0 | 249 |
} |
250 |
} |
|
251 |
} |
|
252 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
253 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom); |
2817 | 254 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
255 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
256 |
* From a rectangle that needs redrawing, find the windows that intersect with the rectangle. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
257 |
* These windows should be re-painted. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
258 |
* @param left Left edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
259 |
* @param top Top edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
260 |
* @param right Right edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
261 |
* @param bottom Bottom edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
262 |
*/ |
0 | 263 |
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom) |
264 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
265 |
Window* const *wz; |
0 | 266 |
DrawPixelInfo bk; |
267 |
_cur_dpi = &bk; |
|
268 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
269 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
270 |
const Window *w = *wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
271 |
if (right > w->left && |
0 | 272 |
bottom > w->top && |
273 |
left < w->left + w->width && |
|
274 |
top < w->top + w->height) { |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
275 |
DrawOverlappedWindow(wz, left, top, right, bottom); |
2639 | 276 |
} |
0 | 277 |
} |
278 |
} |
|
279 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
280 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
281 |
* Generate repaint events for the visible part of window *wz within the rectangle. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
282 |
* |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
283 |
* The function goes recursively upwards in the window stack, and splits the rectangle |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
284 |
* into multiple pieces at the window edges, so obscured parts are not redrawn. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
285 |
* |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
286 |
* @param wz Pointer into window stack, pointing at the window that needs to be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
287 |
* @param left Left edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
288 |
* @param top Top edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
289 |
* @param right Right edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
290 |
* @param bottom Bottom edge of the rectangle that should be repainted |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
291 |
* |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
292 |
* @todo Swap this function to above DrawOverlappedWindowForAll() to eliminate the forward declaration |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
293 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
294 |
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom) |
0 | 295 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
296 |
Window* const *vz = wz; |
0 | 297 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
298 |
while (++vz != _last_z_window) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
299 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
300 |
|
0 | 301 |
if (right > v->left && |
2026 | 302 |
bottom > v->top && |
0 | 303 |
left < v->left + v->width && |
304 |
top < v->top + v->height) { |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
305 |
/* v and rectangle intersect with eeach other */ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
306 |
int x; |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
307 |
|
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
308 |
if (left < (x = v->left)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
309 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
310 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 311 |
return; |
312 |
} |
|
313 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
314 |
if (right > (x = v->left + v->width)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
315 |
DrawOverlappedWindow(wz, left, top, x, bottom); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
316 |
DrawOverlappedWindow(wz, x, top, right, bottom); |
0 | 317 |
return; |
318 |
} |
|
319 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
320 |
if (top < (x = v->top)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
321 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
322 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 323 |
return; |
324 |
} |
|
325 |
||
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
326 |
if (bottom > (x = v->top + v->height)) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
327 |
DrawOverlappedWindow(wz, left, top, right, x); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
328 |
DrawOverlappedWindow(wz, left, x, right, bottom); |
0 | 329 |
return; |
330 |
} |
|
331 |
||
332 |
return; |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
{ |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
337 |
DrawPixelInfo *dp = _cur_dpi; |
0 | 338 |
dp->width = right - left; |
339 |
dp->height = bottom - top; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
340 |
dp->left = left - (*wz)->left; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
341 |
dp->top = top - (*wz)->top; |
0 | 342 |
dp->pitch = _screen.pitch; |
9628
b5c2449616b5
(svn r10195) [NoAI] -Sync: with trunk r10119:10194.
rubidium
parents:
9624
diff
changeset
|
343 |
dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top); |
9624 | 344 |
dp->zoom = ZOOM_LVL_NORMAL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
345 |
CallWindowEventNP(*wz, WE_PAINT); |
0 | 346 |
} |
347 |
} |
|
348 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
349 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
350 |
* Dispatch an event to a possibly non-existing window. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
351 |
* If the window pointer w is \c NULL, the event is not dispatched |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
352 |
* @param w Window to dispatch the event to, may be \c NULL |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
353 |
* @param event Event to dispatch |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
354 |
*/ |
0 | 355 |
void CallWindowEventNP(Window *w, int event) |
356 |
{ |
|
357 |
WindowEvent e; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
358 |
|
0 | 359 |
e.event = event; |
360 |
w->wndproc(w, &e); |
|
361 |
} |
|
362 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
363 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
364 |
* Mark entire window as dirty (in need of re-paint) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
365 |
* @param w Window to redraw |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
366 |
* @ingroup dirty |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
367 |
*/ |
4171 | 368 |
void SetWindowDirty(const Window *w) |
0 | 369 |
{ |
2549 | 370 |
if (w == NULL) return; |
0 | 371 |
SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height); |
372 |
} |
|
373 |
||
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
374 |
/** Find the Window whose parent pointer points to this window |
9599 | 375 |
* @param w parent Window to find child of |
376 |
* @return a Window pointer that is the child of w, or NULL otherwise */ |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
377 |
static Window *FindChildWindow(const Window *w) |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
378 |
{ |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
379 |
Window* const *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
380 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
381 |
FOR_ALL_WINDOWS(wz) { |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
382 |
Window *v = *wz; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
383 |
if (v->parent == w) return v; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
384 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
385 |
|
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
386 |
return NULL; |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
387 |
} |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
388 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
389 |
/** Find the z-value of a window. A window must already be open |
9599 | 390 |
* or the behaviour is undefined but function should never fail |
391 |
* @param w window to query Z Position |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
392 |
* @return Pointer into the window-list at the position of \a w |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
393 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
394 |
Window **FindWindowZPosition(const Window *w) |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
395 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
396 |
Window **wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
397 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
398 |
FOR_ALL_WINDOWS(wz) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
399 |
if (*wz == w) return wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
400 |
} |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
401 |
|
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
402 |
DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls", |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
403 |
w->window_class, w->window_number); |
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
404 |
return NULL; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
405 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
406 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
407 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
408 |
* Remove window and all its child windows from the window stack |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
409 |
*/ |
0 | 410 |
void DeleteWindow(Window *w) |
411 |
{ |
|
2639 | 412 |
if (w == NULL) return; |
0 | 413 |
|
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
414 |
/* Delete any children a window might have in a head-recursive manner */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
415 |
Window *v = FindChildWindow(w); |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
416 |
if (v != NULL) DeleteWindow(v); |
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
417 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
418 |
if (_thd.place_mode != VHM_NONE && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
419 |
_thd.window_class == w->window_class && |
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
420 |
_thd.window_number == w->window_number) { |
0 | 421 |
ResetObjectToPlace(); |
422 |
} |
|
423 |
||
424 |
CallWindowEventNP(w, WE_DESTROY); |
|
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
425 |
if (w->viewport != NULL) DeleteWindowViewport(w); |
0 | 426 |
|
427 |
SetWindowDirty(w); |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
428 |
free(w->widget); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
429 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
430 |
w->widget_count = 0; |
5666
1af12f02bf17
(svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents:
5664
diff
changeset
|
431 |
w->parent = NULL; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
432 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
433 |
/* Find the window in the z-array, and effectively remove it |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
434 |
* by moving all windows after it one to the left */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
435 |
Window **wz = FindWindowZPosition(w); |
5680
b0bae92a1620
(svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents:
5667
diff
changeset
|
436 |
if (wz == NULL) return; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
437 |
memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
438 |
_last_z_window--; |
0 | 439 |
} |
440 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
441 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
442 |
* Find a window by its class and window number |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
443 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
444 |
* @param number Number of the window within the window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
445 |
* @return Pointer to the found window, or \c NULL if not available |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
446 |
*/ |
0 | 447 |
Window *FindWindowById(WindowClass cls, WindowNumber number) |
448 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
449 |
Window* const *wz; |
0 | 450 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
451 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
452 |
Window *w = *wz; |
2639 | 453 |
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
|
454 |
} |
0 | 455 |
|
456 |
return NULL; |
|
457 |
} |
|
458 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
459 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
460 |
* Delete a window by its class and window number (if it is open). |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
461 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
462 |
* @param number Number of the window within the window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
463 |
*/ |
0 | 464 |
void DeleteWindowById(WindowClass cls, WindowNumber number) |
465 |
{ |
|
466 |
DeleteWindow(FindWindowById(cls, number)); |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
467 |
} |
0 | 468 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
469 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
470 |
* Delete all windows of a given class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
471 |
* @param cls Window class of windows to delete |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
472 |
*/ |
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
473 |
void DeleteWindowByClass(WindowClass cls) |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
474 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
475 |
Window* const *wz; |
2639 | 476 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
477 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
478 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
479 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
480 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
481 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
482 |
Window *w = *wz; |
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
483 |
if (w->window_class == cls) { |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
484 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
485 |
goto restart_search; |
2639 | 486 |
} |
999
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
487 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
488 |
} |
8b2a34061963
(svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents:
984
diff
changeset
|
489 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
490 |
/** Delete all windows of a player. We identify windows of a player |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
491 |
* by looking at the caption colour. If it is equal to the player ID |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
492 |
* then we say the window belongs to the player and should be deleted |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
493 |
* @param id PlayerID player identifier */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
494 |
void DeletePlayerWindows(PlayerID id) |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
495 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
496 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
497 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
498 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
499 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
500 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
501 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
502 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
503 |
Window *w = *wz; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
504 |
if (w->caption_color == id) { |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
505 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
506 |
goto restart_search; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
507 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
508 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
509 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
510 |
/* Also delete the player specific windows, that don't have a player-colour */ |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
511 |
DeleteWindowById(WC_BUY_COMPANY, id); |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
512 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
513 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
514 |
/** Change the owner of all the windows one player can take over from another |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
515 |
* player in the case of a company merger. Do not change ownership of windows |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
516 |
* that need to be deleted once takeover is complete |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
517 |
* @param old_player PlayerID of original owner of the window |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
518 |
* @param new_player PlayerID of the new owner of the window */ |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
519 |
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player) |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
520 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
521 |
Window* const *wz; |
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
522 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
523 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
524 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
525 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
526 |
if (w->caption_color != old_player) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
527 |
if (w->window_class == WC_PLAYER_COLOR) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
528 |
if (w->window_class == WC_FINANCES) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
529 |
if (w->window_class == WC_STATION_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
530 |
if (w->window_class == WC_TRAINS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
531 |
if (w->window_class == WC_ROADVEH_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
532 |
if (w->window_class == WC_SHIPS_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
533 |
if (w->window_class == WC_AIRCRAFT_LIST) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
534 |
if (w->window_class == WC_BUY_COMPANY) continue; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
535 |
if (w->window_class == WC_COMPANY) continue; |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
536 |
|
5077
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
537 |
w->caption_color = new_player; |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
538 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
539 |
} |
587701a06b6a
(svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents:
5072
diff
changeset
|
540 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
541 |
static void BringWindowToFront(const Window *w); |
2817 | 542 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
543 |
/** Find a window and make it the top-window on the screen. The window |
9599 | 544 |
* gets a white border for a brief period of time to visualize its "activation" |
545 |
* @param cls WindowClass of the window to activate |
|
546 |
* @param number WindowNumber of the window to activate |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
547 |
* @return a pointer to the window thus activated */ |
0 | 548 |
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number) |
549 |
{ |
|
550 |
Window *w = FindWindowById(cls, number); |
|
551 |
||
552 |
if (w != NULL) { |
|
553 |
w->flags4 |= WF_WHITE_BORDER_MASK; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
554 |
BringWindowToFront(w); |
0 | 555 |
SetWindowDirty(w); |
556 |
} |
|
557 |
||
558 |
return w; |
|
559 |
} |
|
560 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
561 |
static inline bool IsVitalWindow(const Window *w) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
562 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
563 |
WindowClass wc = w->window_class; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
564 |
return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
565 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
566 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
567 |
/** On clicking on a window, make it the frontmost window of all. However |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
568 |
* there are certain windows that always need to be on-top; these include |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
569 |
* - Toolbar, Statusbar (always on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
570 |
* - New window, Chatbar (only if open) |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
571 |
* The window is marked dirty for a repaint if the window is actually moved |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
572 |
* @param w window that is put into the foreground |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
573 |
* @return pointer to the window, the same as the input pointer |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
574 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
575 |
static void BringWindowToFront(const Window *w) |
0 | 576 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
577 |
Window *tempz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
578 |
Window **wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
579 |
Window **vz = _last_z_window; |
0 | 580 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
581 |
/* Bring the window just below the vital windows */ |
0 | 582 |
do { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
583 |
if (--vz < _z_windows) return; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
584 |
} while (IsVitalWindow(*vz)); |
0 | 585 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
586 |
if (wz == vz) return; // window is already in the right position |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
587 |
assert(wz < vz); |
0 | 588 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
589 |
tempz = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
590 |
memmove(wz, wz + 1, (byte*)vz - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
591 |
*vz = tempz; |
0 | 592 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
593 |
SetWindowDirty(w); |
0 | 594 |
} |
595 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
596 |
/** We have run out of windows, so find a suitable candidate for replacement. |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
597 |
* Keep all important windows intact. These are |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
598 |
* - Main window (gamefield), Toolbar, Statusbar (always on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
599 |
* - News window, Chatbar (when on) |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
600 |
* - Any sticked windows since we wanted to keep these |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
601 |
* @return w pointer to the window that is going to be deleted |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
602 |
*/ |
6573 | 603 |
static Window *FindDeletableWindow() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
604 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
605 |
Window* const *wz; |
2639 | 606 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
607 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
608 |
Window *w = *wz; |
2639 | 609 |
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) { |
610 |
return w; |
|
611 |
} |
|
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
612 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
613 |
return NULL; |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
614 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
615 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
616 |
/** A window must be freed, and all are marked as important windows. Ease the |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
617 |
* restriction a bit by allowing to delete sticky windows. Keep important/vital |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
618 |
* windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar) |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
619 |
* Start finding an appropiate candidate from the lowest z-values (bottom) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
620 |
* @see FindDeletableWindow() |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
621 |
* @return w Pointer to the window that is being deleted |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
622 |
*/ |
6573 | 623 |
static Window *ForceFindDeletableWindow() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
624 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
625 |
Window* const *wz; |
2639 | 626 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
627 |
for (wz = _z_windows;; wz++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
628 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
629 |
assert(wz < _last_z_window); |
2639 | 630 |
if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w; |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
631 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
632 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
633 |
|
4171 | 634 |
bool IsWindowOfPrototype(const Window *w, const Widget *widget) |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
635 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
636 |
return (w->original_widget == widget); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
637 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
638 |
|
9599 | 639 |
/** Copies 'widget' to 'w->widget' to allow for resizable windows |
640 |
* @param w Window on which to attach the widget array |
|
641 |
* @param widget pointer of widget array to fill the window with */ |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
642 |
void AssignWidgetToWindow(Window *w, const Widget *widget) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
643 |
{ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
644 |
w->original_widget = widget; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
645 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
646 |
if (widget != NULL) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
647 |
uint index = 1; |
4171 | 648 |
const Widget *wi; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
649 |
|
2639 | 650 |
for (wi = widget; wi->type != WWT_LAST; wi++) index++; |
651 |
||
5860
7fdc9b423ba1
(svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents:
5838
diff
changeset
|
652 |
w->widget = ReallocT(w->widget, index); |
2639 | 653 |
memcpy(w->widget, widget, sizeof(*w->widget) * index); |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
654 |
w->widget_count = index - 1; |
2639 | 655 |
} else { |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
656 |
w->widget = NULL; |
5232
0ba6acdc527f
(svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents:
5198
diff
changeset
|
657 |
w->widget_count = 0; |
2639 | 658 |
} |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
659 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
660 |
|
6573 | 661 |
static Window *FindFreeWindow() |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
662 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
663 |
Window *w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
664 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
665 |
for (w = _windows; w < endof(_windows); w++) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
666 |
Window* const *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
667 |
bool window_in_use = false; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
668 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
669 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
670 |
if (*wz == w) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
671 |
window_in_use = true; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
672 |
break; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
673 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
674 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
675 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
676 |
if (!window_in_use) return w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
677 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
678 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
679 |
assert(_last_z_window == endof(_z_windows)); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
680 |
return NULL; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
681 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
682 |
|
9599 | 683 |
/** Open a new window. |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
684 |
* This function is called from AllocateWindow() or AllocateWindowDesc() |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
685 |
* See descriptions for those functions for usage |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
686 |
* See AllocateWindow() for description of arguments. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
687 |
* Only addition here is window_number, which is the window_number being assigned to the new window |
9599 | 688 |
* @param x offset in pixels from the left of the screen |
689 |
* @param y offset in pixels from the top of the screen |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
690 |
* @param min_width minimum width in pixels of the window |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
691 |
* @param min_height minimum height in pixels of the window |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
692 |
* @param def_width default width in pixels of the window |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
693 |
* @param def_height default height in pixels of the window |
9599 | 694 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
695 |
* @param cls see WindowClass class of the window, used for identification and grouping |
|
696 |
* @param *widget see Widget pointer to the window layout and various elements |
|
697 |
* @param window_number number being assigned to the new window |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
698 |
* @param data the data to be given during the WE_CREATE message |
9599 | 699 |
* @return Window pointer of the newly created window */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
700 |
static Window *LocalAllocateWindow(int x, int y, int min_width, int min_height, int def_width, int def_height, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
701 |
WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data) |
0 | 702 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
703 |
Window *w = FindFreeWindow(); |
0 | 704 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
705 |
/* We have run out of windows, close one and use that as the place for our new one */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
706 |
if (w == NULL) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
707 |
w = FindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
708 |
if (w == NULL) w = ForceFindDeletableWindow(); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
709 |
DeleteWindow(w); |
0 | 710 |
} |
711 |
||
9574 | 712 |
/* Set up window properties */ |
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
713 |
memset(w, 0, sizeof(*w)); |
0 | 714 |
w->window_class = cls; |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
715 |
w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border |
0 | 716 |
w->caption_color = 0xFF; |
717 |
w->left = x; |
|
718 |
w->top = y; |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
719 |
w->width = min_width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
720 |
w->height = min_height; |
0 | 721 |
w->wndproc = proc; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
722 |
AssignWidgetToWindow(w, widget); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
723 |
w->resize.width = min_width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
724 |
w->resize.height = min_height; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
725 |
w->resize.step_width = 1; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
726 |
w->resize.step_height = 1; |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
727 |
w->window_number = window_number; |
0 | 728 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
729 |
{ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
730 |
Window **wz = _last_z_window; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
731 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
732 |
/* Hacky way of specifying always-on-top windows. These windows are |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
733 |
* always above other windows because they are moved below them. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
734 |
* status-bar is above news-window because it has been created earlier. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
735 |
* Also, as the chat-window is excluded from this, it will always be |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
736 |
* the last window, thus always on top. |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
737 |
* XXX - Yes, ugly, probably needs something like w->always_on_top flag |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
738 |
* to implement correctly, but even then you need some kind of distinction |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
739 |
* between on-top of chat/news and status windows, because these conflict */ |
9629 | 740 |
if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
741 |
if (FindWindowById(WC_MAIN_TOOLBAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
742 |
if (FindWindowById(WC_STATUS_BAR, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
743 |
if (FindWindowById(WC_NEWS_WINDOW, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
744 |
if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
745 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
746 |
assert(wz >= _z_windows); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
747 |
if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
748 |
} |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
749 |
|
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
750 |
*wz = w; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
751 |
_last_z_window++; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
752 |
} |
0 | 753 |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
754 |
WindowEvent e; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
755 |
e.event = WE_CREATE; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
756 |
e.we.create.data = data; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
757 |
w->wndproc(w, &e); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
758 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
759 |
/* Try to make windows smaller when our window is too small. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
760 |
* w->(width|height) is normally the same as min_(width|height), |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
761 |
* but this way the GUIs can be made a little more dynamic; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
762 |
* one can use the same spec for multiple windows and those |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
763 |
* can then determine the real minimum size of the window. */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
764 |
if (w->width != def_width || w->height != def_height) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
765 |
/* Think about the overlapping toolbars when determining the minimum window size */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
766 |
int free_height = _screen.height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
767 |
const Window *wt = FindWindowById(WC_STATUS_BAR, 0); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
768 |
if (wt != NULL) free_height -= wt->height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
769 |
wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
770 |
if (wt != NULL) free_height -= wt->height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
771 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
772 |
int enlarge_x = max(min(def_width - w->width, _screen.width - w->width), 0); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
773 |
int enlarge_y = max(min(def_height - w->height, free_height - w->height), 0); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
774 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
775 |
/* X and Y has to go by step.. calculate it. |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
776 |
* The cast to int is necessary else x/y are implicitly casted to |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
777 |
* unsigned int, which won't work. */ |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
778 |
if (w->resize.step_width > 1) enlarge_x -= enlarge_x % (int)w->resize.step_width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
779 |
if (w->resize.step_height > 1) enlarge_y -= enlarge_y % (int)w->resize.step_height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
780 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
781 |
ResizeWindow(w, enlarge_x, enlarge_y); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
782 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
783 |
WindowEvent e; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
784 |
e.event = WE_RESIZE; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
785 |
e.we.sizing.size.x = w->width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
786 |
e.we.sizing.size.y = w->height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
787 |
e.we.sizing.diff.x = enlarge_x; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
788 |
e.we.sizing.diff.y = enlarge_y; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
789 |
w->wndproc(w, &e); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
790 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
791 |
|
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
792 |
int nx = w->left; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
793 |
int ny = w->top; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
794 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
795 |
if (nx + w->width > _screen.width) nx -= (nx + w->width - _screen.width); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
796 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
797 |
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
798 |
ny = max(ny, (wt == NULL || w == wt || y == 0) ? 0 : wt->height); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
799 |
nx = max(nx, 0); |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
800 |
|
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
801 |
if (w->viewport != NULL) { |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
802 |
w->viewport->left += nx - w->left; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
803 |
w->viewport->top += ny - w->top; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
804 |
} |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
805 |
w->left = nx; |
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
806 |
w->top = ny; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
807 |
|
0 | 808 |
SetWindowDirty(w); |
809 |
||
810 |
return w; |
|
811 |
} |
|
812 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
813 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
814 |
* Open a new window. If there is no space for a new window, close an open |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
815 |
* window. Try to avoid stickied windows, but if there is no else, close one of |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
816 |
* those as well. Then make sure all created windows are below some always-on-top |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
817 |
* ones. Finally set all variables and call the WE_CREATE event |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
818 |
* @param x offset in pixels from the left of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
819 |
* @param y offset in pixels from the top of the screen |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
820 |
* @param width width in pixels of the window |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
821 |
* @param height height in pixels of the window |
9599 | 822 |
* @param *proc see WindowProc function to call when any messages/updates happen to the window |
823 |
* @param cls see WindowClass class of the window, used for identification and grouping |
|
824 |
* @param *widget see Widget pointer to the window layout and various elements |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
825 |
* @return Window pointer of the newly created window |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
826 |
*/ |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
827 |
Window *AllocateWindow(int x, int y, int width, int height, |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
828 |
WindowProc *proc, WindowClass cls, const Widget *widget, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
829 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
830 |
return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
831 |
} |
0 | 832 |
|
833 |
||
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
834 |
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos) |
0 | 835 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
836 |
Window* const *wz; |
0 | 837 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
838 |
int right = width + left; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
839 |
int bottom = height + top; |
0 | 840 |
|
841 |
if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) |
|
842 |
return false; |
|
843 |
||
9574 | 844 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
845 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
846 |
const Window *w = *wz; |
2639 | 847 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 848 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
849 |
if (right > w->left && |
2639 | 850 |
w->left + w->width > left && |
0 | 851 |
bottom > w->top && |
2639 | 852 |
w->top + w->height > top) { |
853 |
return false; |
|
854 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
855 |
} |
0 | 856 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
857 |
pos.x = left; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
858 |
pos.y = top; |
0 | 859 |
return true; |
860 |
} |
|
861 |
||
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
862 |
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos) |
0 | 863 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
864 |
Window* const *wz; |
0 | 865 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
866 |
if (left < -(width>>2) || left > _screen.width - (width>>1)) return false; |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
867 |
if (top < 22 || top > _screen.height - (height>>2)) return false; |
0 | 868 |
|
9574 | 869 |
/* Make sure it is not obscured by any window. */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
870 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
871 |
const Window *w = *wz; |
2639 | 872 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 873 |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
874 |
if (left + width > w->left && |
2639 | 875 |
w->left + w->width > left && |
0 | 876 |
top + height > w->top && |
2639 | 877 |
w->top + w->height > top) { |
878 |
return false; |
|
879 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
880 |
} |
0 | 881 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
882 |
pos.x = left; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
883 |
pos.y = top; |
0 | 884 |
return true; |
885 |
} |
|
886 |
||
1095 | 887 |
static Point GetAutoPlacePosition(int width, int height) |
888 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
889 |
Window* const *wz; |
0 | 890 |
Point pt; |
891 |
||
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
892 |
if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt; |
0 | 893 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
894 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
895 |
const Window *w = *wz; |
2639 | 896 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 897 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
898 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
899 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
900 |
if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
901 |
if (IsGoodAutoPlace1(w->left, w->top - height - 2, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
902 |
if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
903 |
if (IsGoodAutoPlace1(w->left - width - 2, w->top + w->height - height, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
904 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
905 |
if (IsGoodAutoPlace1(w->left + w->width - width, w->top - height - 2, width, height, pt)) return pt; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
906 |
} |
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
907 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
908 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
909 |
const Window *w = *wz; |
2639 | 910 |
if (w->window_class == WC_MAIN_WINDOW) continue; |
0 | 911 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
912 |
if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
913 |
if (IsGoodAutoPlace2(w->left - width - 2, w->top, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
914 |
if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt; |
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
915 |
if (IsGoodAutoPlace2(w->left, w->top - height - 2, width, height, pt)) return pt; |
0 | 916 |
} |
917 |
||
918 |
{ |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
919 |
int left = 0, top = 24; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
920 |
|
9620
31e38d28a0af
(svn r9816) [NoAI] -Sync with trunk r9712:9815 except r9759 (MorphOS threading) because that needs special attention.
rubidium
parents:
9601
diff
changeset
|
921 |
restart: |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
922 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
923 |
const Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
924 |
|
0 | 925 |
if (w->left == left && w->top == top) { |
926 |
left += 5; |
|
927 |
top += 5; |
|
928 |
goto restart; |
|
929 |
} |
|
930 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
931 |
|
0 | 932 |
pt.x = left; |
933 |
pt.y = top; |
|
934 |
return pt; |
|
935 |
} |
|
936 |
} |
|
937 |
||
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
938 |
/** |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
939 |
* Set the x and y coordinates of a new window. |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
940 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
941 |
* @param *desc The pointer to the WindowDesc to be created |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
942 |
* @param window_number the window number of the new window |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
943 |
* @param data arbitrary data that is send with the WE_CREATE message |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
944 |
* |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
945 |
* @return see Window pointer of the newly created window |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
946 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
947 |
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data) |
0 | 948 |
{ |
949 |
Point pt; |
|
950 |
Window *w; |
|
951 |
||
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
952 |
/* By default position a child window at an offset of 10/10 of its parent. |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
953 |
* With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports) |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
954 |
* and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
955 |
* its parent. So it's exactly under the parent toolbar and no buttons will be covered. |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
956 |
* However if it falls too extremely outside window positions, reposition |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
957 |
* it to an automatic place */ |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
958 |
if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
959 |
(w = FindWindowById(desc->parent_cls, window_number)) != NULL && |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
960 |
w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) { |
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
961 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
962 |
pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
963 |
if (pt.x > _screen.width + 10 - desc->default_width) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
964 |
pt.x = (_screen.width + 10 - desc->default_width) - 20; |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
965 |
} |
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
966 |
pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10); |
0 | 967 |
} else { |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
968 |
switch (desc->left) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
969 |
case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
970 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
971 |
pt.x = (w->left + w->width) - desc->default_width; |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
972 |
} break; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
973 |
case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
974 |
pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
975 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
976 |
case WDP_AUTO: /* Find a good automatic position for the window */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
977 |
pt = GetAutoPlacePosition(desc->default_width, desc->default_height); |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
978 |
goto allocate_window; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
979 |
case WDP_CENTER: /* Centre the window horizontally */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
980 |
pt.x = (_screen.width - desc->default_width) / 2; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
981 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
982 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
983 |
pt.x = desc->left; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
984 |
if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
985 |
} |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
986 |
|
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
987 |
switch (desc->top) { |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
988 |
case WDP_CENTER: /* Centre the window vertically */ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
989 |
pt.y = (_screen.height - desc->default_height) / 2; |
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
990 |
break; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
991 |
/* WDP_AUTO sets the position at once and is controlled by desc->left. |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
992 |
* Both left and top must be set to WDP_AUTO */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
993 |
case WDP_AUTO: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
994 |
NOT_REACHED(); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
995 |
assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO); |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
996 |
/* fallthrough */ |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
997 |
default: |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
998 |
pt.y = desc->top; |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
999 |
if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen |
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1000 |
break; |
0 | 1001 |
} |
1002 |
} |
|
1003 |
||
5072
df5bde83a4bc
(svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents:
5071
diff
changeset
|
1004 |
allocate_window: |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1005 |
w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data); |
0 | 1006 |
w->desc_flags = desc->flags; |
1007 |
return w; |
|
1008 |
} |
|
1009 |
||
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1010 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1011 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1012 |
* @param *desc The pointer to the WindowDesc to be created |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1013 |
* @param data arbitrary data that is send with the WE_CREATE message |
9599 | 1014 |
* @return Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1015 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1016 |
Window *AllocateWindowDesc(const WindowDesc *desc, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1017 |
{ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1018 |
return LocalAllocateWindowDesc(desc, 0, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1019 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1020 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1021 |
/** |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1022 |
* Open a new window. |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1023 |
* @param *desc The pointer to the WindowDesc to be created |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1024 |
* @param window_number the window number of the new window |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1025 |
* @param data arbitrary data that is send with the WE_CREATE message |
9599 | 1026 |
* @return see Window pointer of the newly created window |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1027 |
*/ |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1028 |
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data) |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1029 |
{ |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1030 |
Window *w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1031 |
|
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1032 |
if (BringWindowToFrontById(desc->cls, window_number)) return NULL; |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1033 |
w = LocalAllocateWindowDesc(desc, window_number, data); |
4520
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1034 |
return w; |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1035 |
} |
d5f94a18a68c
(svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents:
4337
diff
changeset
|
1036 |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1037 |
/** Do a search for a window at specific coordinates. For this we start |
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1038 |
* at the topmost window, obviously and work our way down to the bottom |
9599 | 1039 |
* @param x position x to query |
1040 |
* @param y position y to query |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
1041 |
* @return a pointer to the found window if any, NULL otherwise */ |
0 | 1042 |
Window *FindWindowFromPt(int x, int y) |
1043 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1044 |
Window* const *wz; |
0 | 1045 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1046 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1047 |
Window *w = *--wz; |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1048 |
if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) { |
2639 | 1049 |
return w; |
1050 |
} |
|
0 | 1051 |
} |
1052 |
||
1053 |
return NULL; |
|
1054 |
} |
|
1055 |
||
6573 | 1056 |
void InitWindowSystem() |
152
c3964b43943e
(svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents:
136
diff
changeset
|
1057 |
{ |
136
78ac8de2b2b8
(svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents:
126
diff
changeset
|
1058 |
IConsoleClose(); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1059 |
|
0 | 1060 |
memset(&_windows, 0, sizeof(_windows)); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1061 |
_last_z_window = _z_windows; |
5122
a68d16b055fa
(svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents:
5121
diff
changeset
|
1062 |
InitViewports(); |
1397
b04402b901cd
(svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents:
1299
diff
changeset
|
1063 |
_no_scroll = 0; |
0 | 1064 |
} |
1065 |
||
6573 | 1066 |
void UnInitWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1067 |
{ |
5664 | 1068 |
Window **wz; |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1069 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1070 |
restart_search: |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1071 |
/* Delete all windows, reset z-array. |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1072 |
* When we find the window to delete, we need to restart the search |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1073 |
* as deleting this window could cascade in deleting (many) others |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1074 |
* anywhere in the z-array. We call DeleteWindow() so that it can properly |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1075 |
* release own alloc'd memory, which otherwise could result in memleaks */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1076 |
FOR_ALL_WINDOWS(wz) { |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1077 |
DeleteWindow(*wz); |
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1078 |
goto restart_search; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1079 |
} |
5893
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1080 |
|
16a86ac09d80
(svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents:
5860
diff
changeset
|
1081 |
assert(_last_z_window == _z_windows); |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1082 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1083 |
|
6573 | 1084 |
void ResetWindowSystem() |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1085 |
{ |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1086 |
UnInitWindowSystem(); |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1087 |
InitWindowSystem(); |
1744
1677a99b0daf
(svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents:
1737
diff
changeset
|
1088 |
_thd.pos.x = 0; |
1677a99b0daf
(svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents:
1737
diff
changeset
|
1089 |
_thd.pos.y = 0; |
2877
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
1090 |
_thd.new_pos.x = 0; |
c307d8f60e48
(svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents:
2817
diff
changeset
|
1091 |
_thd.new_pos.y = 0; |
1474
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1092 |
} |
d83520edcda6
(svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents:
1397
diff
changeset
|
1093 |
|
6573 | 1094 |
static void DecreaseWindowCounters() |
0 | 1095 |
{ |
1096 |
Window *w; |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1097 |
Window* const *wz; |
0 | 1098 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1099 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1100 |
w = *--wz; |
9574 | 1101 |
/* Unclick scrollbar buttons if they are pressed. */ |
0 | 1102 |
if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) { |
1103 |
w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP); |
|
1104 |
SetWindowDirty(w); |
|
1105 |
} |
|
1106 |
CallWindowEventNP(w, WE_MOUSELOOP); |
|
1107 |
} |
|
1108 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1109 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1110 |
w = *--wz; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1111 |
|
0 | 1112 |
if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) { |
1113 |
CallWindowEventNP(w, WE_TIMEOUT); |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1114 |
if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons(); |
0 | 1115 |
} |
1116 |
} |
|
1117 |
} |
|
1118 |
||
6573 | 1119 |
Window *GetCallbackWnd() |
0 | 1120 |
{ |
1121 |
return FindWindowById(_thd.window_class, _thd.window_number); |
|
1122 |
} |
|
1123 |
||
6573 | 1124 |
static void HandlePlacePresize() |
0 | 1125 |
{ |
1126 |
Window *w; |
|
1127 |
WindowEvent e; |
|
1128 |
||
2639 | 1129 |
if (_special_mouse_mode != WSM_PRESIZE) return; |
0 | 1130 |
|
2639 | 1131 |
w = GetCallbackWnd(); |
1132 |
if (w == NULL) return; |
|
0 | 1133 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1134 |
e.we.place.pt = GetTileBelowCursor(); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1135 |
if (e.we.place.pt.x == -1) { |
0 | 1136 |
_thd.selend.x = -1; |
1137 |
return; |
|
1138 |
} |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1139 |
e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y); |
0 | 1140 |
e.event = WE_PLACE_PRESIZE; |
1141 |
w->wndproc(w, &e); |
|
1142 |
} |
|
1143 |
||
6573 | 1144 |
static bool HandleDragDrop() |
0 | 1145 |
{ |
1146 |
Window *w; |
|
1147 |
WindowEvent e; |
|
1148 |
||
2639 | 1149 |
if (_special_mouse_mode != WSM_DRAGDROP) return true; |
0 | 1150 |
|
2639 | 1151 |
if (_left_button_down) return false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1152 |
|
0 | 1153 |
w = GetCallbackWnd(); |
1154 |
||
2639 | 1155 |
if (w != NULL) { |
9574 | 1156 |
/* send an event in client coordinates. */ |
0 | 1157 |
e.event = WE_DRAGDROP; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1158 |
e.we.dragdrop.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1159 |
e.we.dragdrop.pt.y = _cursor.pos.y - w->top; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1160 |
e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y); |
0 | 1161 |
w->wndproc(w, &e); |
1162 |
} |
|
9732 | 1163 |
|
1164 |
ResetObjectToPlace(); |
|
1165 |
||
0 | 1166 |
return false; |
1167 |
} |
|
1168 |
||
6573 | 1169 |
static bool HandlePopupMenu() |
0 | 1170 |
{ |
1171 |
Window *w; |
|
1172 |
WindowEvent e; |
|
1173 |
||
2639 | 1174 |
if (!_popup_menu_active) return true; |
0 | 1175 |
|
1176 |
w = FindWindowById(WC_TOOLBAR_MENU, 0); |
|
1177 |
if (w == NULL) { |
|
1178 |
_popup_menu_active = false; |
|
1179 |
return false; |
|
1180 |
} |
|
1181 |
||
1182 |
if (_left_button_down) { |
|
1183 |
e.event = WE_POPUPMENU_OVER; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1184 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1185 |
} else { |
1186 |
_popup_menu_active = false; |
|
1187 |
e.event = WE_POPUPMENU_SELECT; |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1188 |
e.we.popupmenu.pt = _cursor.pos; |
0 | 1189 |
} |
1190 |
||
1038
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
1191 |
w->wndproc(w, &e); |
cf60aaf4c4ba
(svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents:
1033
diff
changeset
|
1192 |
|
0 | 1193 |
return false; |
1194 |
} |
|
1195 |
||
6573 | 1196 |
static bool HandleMouseOver() |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1197 |
{ |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1198 |
Window *w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1199 |
WindowEvent e; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1200 |
static Window *last_w = NULL; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1201 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1202 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1203 |
|
9574 | 1204 |
/* We changed window, put a MOUSEOVER event to the last window */ |
2639 | 1205 |
if (last_w != NULL && last_w != w) { |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1206 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1207 |
e.we.mouseover.pt.x = -1; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1208 |
e.we.mouseover.pt.y = -1; |
2639 | 1209 |
if (last_w->wndproc) last_w->wndproc(last_w, &e); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1210 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1211 |
last_w = w; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1212 |
|
2639 | 1213 |
if (w != NULL) { |
9574 | 1214 |
/* send an event in client coordinates. */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1215 |
e.event = WE_MOUSEOVER; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1216 |
e.we.mouseover.pt.x = _cursor.pos.x - w->left; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1217 |
e.we.mouseover.pt.y = _cursor.pos.y - w->top; |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1218 |
if (w->widget != NULL) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1219 |
e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y); |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1220 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1221 |
w->wndproc(w, &e); |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1222 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1223 |
|
9574 | 1224 |
/* Mouseover never stops execution */ |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1225 |
return true; |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1226 |
} |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1227 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1228 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1229 |
* Resize the window. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1230 |
* Update all the widgets of a window based on their resize flags |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1231 |
* Both the areas of the old window and the new sized window are set dirty |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1232 |
* ensuring proper redrawal. |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1233 |
* @param w Window to resize |
9601
b499fdd106d5
(svn r9713) [NoAI] -Sync with trunk (r9631:9712).
rubidium
parents:
9599
diff
changeset
|
1234 |
* @param x delta x-size of changed window (positive if larger, etc.) |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1235 |
* @param y delta y-size of changed window |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1236 |
*/ |
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1237 |
void ResizeWindow(Window *w, int x, int y) |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1238 |
{ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1239 |
Widget *wi; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1240 |
bool resize_height = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1241 |
bool resize_width = false; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1242 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1243 |
if (x == 0 && y == 0) return; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1244 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1245 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1246 |
for (wi = w->widget; wi->type != WWT_LAST; wi++) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1247 |
/* Isolate the resizing flags */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1248 |
byte rsizeflag = GB(wi->display_flags, 0, 4); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1249 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1250 |
if (rsizeflag == RESIZE_NONE) continue; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1251 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1252 |
/* Resize the widget based on its resize-flag */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1253 |
if (rsizeflag & RESIZE_LEFT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1254 |
wi->left += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1255 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1256 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1257 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1258 |
if (rsizeflag & RESIZE_RIGHT) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1259 |
wi->right += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1260 |
resize_width = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1261 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1262 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1263 |
if (rsizeflag & RESIZE_TOP) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1264 |
wi->top += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1265 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1266 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1267 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1268 |
if (rsizeflag & RESIZE_BOTTOM) { |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1269 |
wi->bottom += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1270 |
resize_height = true; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1271 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1272 |
} |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1273 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1274 |
/* We resized at least 1 widget, so let's resize the window totally */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1275 |
if (resize_width) w->width += x; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1276 |
if (resize_height) w->height += y; |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1277 |
|
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1278 |
SetWindowDirty(w); |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1279 |
} |
2596 | 1280 |
|
1281 |
static bool _dragging_window; |
|
1282 |
||
6573 | 1283 |
static bool HandleWindowDragging() |
0 | 1284 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1285 |
Window* const *wz; |
9574 | 1286 |
/* Get out immediately if no window is being dragged at all. */ |
2639 | 1287 |
if (!_dragging_window) return true; |
0 | 1288 |
|
9574 | 1289 |
/* Otherwise find the window... */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1290 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1291 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1292 |
|
350 | 1293 |
if (w->flags4 & WF_DRAGGING) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1294 |
const Widget *t = &w->widget[1]; // the title bar ... ugh |
350 | 1295 |
const Window *v; |
1296 |
int x; |
|
1297 |
int y; |
|
1298 |
int nx; |
|
1299 |
int ny; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1300 |
|
9574 | 1301 |
/* Stop the dragging if the left mouse button was released */ |
0 | 1302 |
if (!_left_button_down) { |
350 | 1303 |
w->flags4 &= ~WF_DRAGGING; |
0 | 1304 |
break; |
1305 |
} |
|
1306 |
||
1307 |
SetWindowDirty(w); |
|
1308 |
||
350 | 1309 |
x = _cursor.pos.x + _drag_delta.x; |
1310 |
y = _cursor.pos.y + _drag_delta.y; |
|
1311 |
nx = x; |
|
1312 |
ny = y; |
|
1313 |
||
1314 |
if (_patches.window_snap_radius != 0) { |
|
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1315 |
Window* const *vz; |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1316 |
|
353 | 1317 |
int hsnap = _patches.window_snap_radius; |
1318 |
int vsnap = _patches.window_snap_radius; |
|
1319 |
int delta; |
|
350 | 1320 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1321 |
FOR_ALL_WINDOWS(vz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1322 |
const Window *v = *vz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1323 |
|
350 | 1324 |
if (v == w) continue; // Don't snap at yourself |
1325 |
||
1326 |
if (y + w->height > v->top && y < v->top + v->height) { |
|
9574 | 1327 |
/* Your left border <-> other right border */ |
350 | 1328 |
delta = abs(v->left + v->width - x); |
1329 |
if (delta <= hsnap) { |
|
1330 |
nx = v->left + v->width; |
|
1331 |
hsnap = delta; |
|
1332 |
} |
|
1333 |
||
9574 | 1334 |
/* Your right border <-> other left border */ |
350 | 1335 |
delta = abs(v->left - x - w->width); |
1336 |
if (delta <= hsnap) { |
|
1337 |
nx = v->left - w->width; |
|
1338 |
hsnap = delta; |
|
1339 |
} |
|
1340 |
} |
|
1341 |
||
353 | 1342 |
if (w->top + w->height >= v->top && w->top <= v->top + v->height) { |
9574 | 1343 |
/* Your left border <-> other left border */ |
353 | 1344 |
delta = abs(v->left - x); |
1345 |
if (delta <= hsnap) { |
|
1346 |
nx = v->left; |
|
1347 |
hsnap = delta; |
|
1348 |
} |
|
1349 |
||
9574 | 1350 |
/* Your right border <-> other right border */ |
353 | 1351 |
delta = abs(v->left + v->width - x - w->width); |
1352 |
if (delta <= hsnap) { |
|
1353 |
nx = v->left + v->width - w->width; |
|
1354 |
hsnap = delta; |
|
1355 |
} |
|
1356 |
} |
|
1357 |
||
350 | 1358 |
if (x + w->width > v->left && x < v->left + v->width) { |
9574 | 1359 |
/* Your top border <-> other bottom border */ |
350 | 1360 |
delta = abs(v->top + v->height - y); |
1361 |
if (delta <= vsnap) { |
|
1362 |
ny = v->top + v->height; |
|
1363 |
vsnap = delta; |
|
1364 |
} |
|
1365 |
||
9574 | 1366 |
/* Your bottom border <-> other top border */ |
350 | 1367 |
delta = abs(v->top - y - w->height); |
1368 |
if (delta <= vsnap) { |
|
1369 |
ny = v->top - w->height; |
|
1370 |
vsnap = delta; |
|
1371 |
} |
|
1372 |
} |
|
353 | 1373 |
|
1374 |
if (w->left + w->width >= v->left && w->left <= v->left + v->width) { |
|
9574 | 1375 |
/* Your top border <-> other top border */ |
353 | 1376 |
delta = abs(v->top - y); |
1377 |
if (delta <= vsnap) { |
|
1378 |
ny = v->top; |
|
1379 |
vsnap = delta; |
|
1380 |
} |
|
1381 |
||
9574 | 1382 |
/* Your bottom border <-> other bottom border */ |
353 | 1383 |
delta = abs(v->top + v->height - y - w->height); |
1384 |
if (delta <= vsnap) { |
|
1385 |
ny = v->top + v->height - w->height; |
|
1386 |
vsnap = delta; |
|
1387 |
} |
|
1388 |
} |
|
0 | 1389 |
} |
1390 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1391 |
|
9574 | 1392 |
/* Make sure the window doesn't leave the screen |
1393 |
* 13 is the height of the title bar */ |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1394 |
nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left); |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1395 |
ny = Clamp(ny, 0, _screen.height - 13); |
350 | 1396 |
|
9574 | 1397 |
/* Make sure the title bar isn't hidden by behind the main tool bar */ |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1398 |
v = FindWindowById(WC_MAIN_TOOLBAR, 0); |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1399 |
if (v != NULL) { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1400 |
int v_bottom = v->top + v->height; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1401 |
int v_right = v->left + v->width; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1402 |
if (ny + t->top >= v->top && ny + t->top < v_bottom) { |
371 | 1403 |
if ((v->left < 13 && nx + t->left < v->left) || |
1404 |
(v_right > _screen.width - 13 && nx + t->right > v_right)) { |
|
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1405 |
ny = v_bottom; |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1406 |
} else { |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1407 |
if (nx + t->left > v->left - 13 && |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1408 |
nx + t->right < v_right + 13) { |
2639 | 1409 |
if (w->top >= v_bottom) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1410 |
ny = v_bottom; |
2639 | 1411 |
} else if (w->left < nx) { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1412 |
nx = v->left - 13 - t->left; |
2639 | 1413 |
} else { |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1414 |
nx = v_right + 13 - t->right; |
2639 | 1415 |
} |
370
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1416 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1417 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1418 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1419 |
} |
687b13abdf0c
(svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents:
353
diff
changeset
|
1420 |
|
350 | 1421 |
if (w->viewport != NULL) { |
1422 |
w->viewport->left += nx - w->left; |
|
1423 |
w->viewport->top += ny - w->top; |
|
1424 |
} |
|
1425 |
w->left = nx; |
|
1426 |
w->top = ny; |
|
1427 |
||
0 | 1428 |
SetWindowDirty(w); |
1429 |
return false; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1430 |
} else if (w->flags4 & WF_SIZING) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1431 |
WindowEvent e; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1432 |
int x, y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1433 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1434 |
/* Stop the sizing if the left mouse button was released */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1435 |
if (!_left_button_down) { |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1436 |
w->flags4 &= ~WF_SIZING; |
1657
eb57fee328fb
(svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents:
1648
diff
changeset
|
1437 |
SetWindowDirty(w); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1438 |
break; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1439 |
} |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1440 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1441 |
x = _cursor.pos.x - _drag_delta.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1442 |
y = _cursor.pos.y - _drag_delta.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1443 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1444 |
/* X and Y has to go by step.. calculate it. |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1445 |
* The cast to int is necessary else x/y are implicitly casted to |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1446 |
* unsigned int, which won't work. */ |
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1447 |
if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1448 |
|
2675
269c38d892f9
(svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents:
2643
diff
changeset
|
1449 |
if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1450 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1451 |
/* Check if we don't go below the minimum set size */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1452 |
if ((int)w->width + x < (int)w->resize.width) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1453 |
x = w->resize.width - w->width; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1454 |
if ((int)w->height + y < (int)w->resize.height) |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1455 |
y = w->resize.height - w->height; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1456 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1457 |
/* Window already on size */ |
2639 | 1458 |
if (x == 0 && y == 0) return false; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1459 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1460 |
/* Now find the new cursor pos.. this is NOT _cursor, because |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1461 |
we move in steps. */ |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1462 |
_drag_delta.x += x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1463 |
_drag_delta.y += y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1464 |
|
5268
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1465 |
/* ResizeWindow sets both pre- and after-size to dirty for redrawal */ |
cbff87066429
(svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents:
5236
diff
changeset
|
1466 |
ResizeWindow(w, x, y); |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1467 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1468 |
e.event = WE_RESIZE; |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1469 |
e.we.sizing.size.x = x + w->width; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1470 |
e.we.sizing.size.y = y + w->height; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1471 |
e.we.sizing.diff.x = x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1472 |
e.we.sizing.diff.y = y; |
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1473 |
w->wndproc(w, &e); |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1474 |
return false; |
0 | 1475 |
} |
1476 |
} |
|
1477 |
||
1478 |
_dragging_window = false; |
|
1479 |
return false; |
|
1480 |
} |
|
1481 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1482 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1483 |
* Start window dragging |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1484 |
* @param w Window to start dragging |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1485 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1486 |
static void StartWindowDrag(Window *w) |
0 | 1487 |
{ |
1488 |
w->flags4 |= WF_DRAGGING; |
|
1489 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1490 |
|
350 | 1491 |
_drag_delta.x = w->left - _cursor.pos.x; |
1492 |
_drag_delta.y = w->top - _cursor.pos.y; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1493 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1494 |
BringWindowToFront(w); |
0 | 1495 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1496 |
} |
|
1497 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1498 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1499 |
* Start resizing a window |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1500 |
* @param w Window to start resizing |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1501 |
*/ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1502 |
static void StartWindowSizing(Window *w) |
0 | 1503 |
{ |
1504 |
w->flags4 |= WF_SIZING; |
|
1505 |
_dragging_window = true; |
|
867
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1506 |
|
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1507 |
_drag_delta.x = _cursor.pos.x; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1508 |
_drag_delta.y = _cursor.pos.y; |
581154a08a78
(svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents:
857
diff
changeset
|
1509 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1510 |
BringWindowToFront(w); |
0 | 1511 |
DeleteWindowById(WC_DROPDOWN_MENU, 0); |
1512 |
} |
|
1513 |
||
1514 |
||
6573 | 1515 |
static bool HandleScrollbarScrolling() |
0 | 1516 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1517 |
Window* const *wz; |
0 | 1518 |
int i; |
1519 |
int pos; |
|
1520 |
Scrollbar *sb; |
|
1521 |
||
9574 | 1522 |
/* Get out quickly if no item is being scrolled */ |
2639 | 1523 |
if (!_scrolling_scrollbar) return true; |
0 | 1524 |
|
9574 | 1525 |
/* Find the scrolling window */ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1526 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1527 |
Window *w = *wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1528 |
|
0 | 1529 |
if (w->flags4 & WF_SCROLL_MIDDLE) { |
9574 | 1530 |
/* Abort if no button is clicked any more. */ |
0 | 1531 |
if (!_left_button_down) { |
1532 |
w->flags4 &= ~WF_SCROLL_MIDDLE; |
|
1533 |
SetWindowDirty(w); |
|
1534 |
break; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1535 |
} |
0 | 1536 |
|
1537 |
if (w->flags4 & WF_HSCROLL) { |
|
1538 |
sb = &w->hscroll; |
|
1539 |
i = _cursor.pos.x - _cursorpos_drag_start.x; |
|
842 | 1540 |
} else if (w->flags4 & WF_SCROLL2){ |
1541 |
sb = &w->vscroll2; |
|
1542 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
0 | 1543 |
} else { |
1544 |
sb = &w->vscroll; |
|
1545 |
i = _cursor.pos.y - _cursorpos_drag_start.y; |
|
1546 |
} |
|
1547 |
||
9574 | 1548 |
/* Find the item we want to move to and make sure it's inside bounds. */ |
0 | 1549 |
pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap)); |
1550 |
if (pos != sb->pos) { |
|
1551 |
sb->pos = pos; |
|
1552 |
SetWindowDirty(w); |
|
1553 |
} |
|
1554 |
return false; |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1555 |
} |
0 | 1556 |
} |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1557 |
|
0 | 1558 |
_scrolling_scrollbar = false; |
1559 |
return false; |
|
1560 |
} |
|
1561 |
||
6573 | 1562 |
static bool HandleViewportScroll() |
0 | 1563 |
{ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1564 |
WindowEvent e; |
0 | 1565 |
Window *w; |
1566 |
||
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1567 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1568 |
|
2639 | 1569 |
if (!_scrolling_viewport) return true; |
0 | 1570 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1571 |
w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y); |
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1572 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1573 |
if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) { |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1574 |
_cursor.fix_at = false; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1575 |
_scrolling_viewport = false; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1576 |
return true; |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1577 |
} |
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1578 |
|
9718
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1579 |
if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) { |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1580 |
/* If the main window is following a vehicle, then first let go of it! */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1581 |
const Vehicle *veh = GetVehicle(WP(w, vp_d).follow_vehicle); |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1582 |
ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */ |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1583 |
return true; |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1584 |
} |
f82a4facea8b
(svn r11309) [NoAI] -Sync: with trunk r11145:11308.
truelight
parents:
9701
diff
changeset
|
1585 |
|
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1586 |
if (_patches.reverse_scroll) { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1587 |
e.we.scroll.delta.x = -_cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1588 |
e.we.scroll.delta.y = -_cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1589 |
} else { |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1590 |
e.we.scroll.delta.x = _cursor.delta.x; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1591 |
e.we.scroll.delta.y = _cursor.delta.y; |
2680
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1592 |
} |
576d9d47df80
(svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents:
2675
diff
changeset
|
1593 |
|
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1594 |
if (scrollwheel_scrolling) { |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1595 |
/* We are using scrollwheels for scrolling */ |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1596 |
e.we.scroll.delta.x = _cursor.h_wheel; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1597 |
e.we.scroll.delta.y = _cursor.v_wheel; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1598 |
_cursor.v_wheel = 0; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1599 |
_cursor.h_wheel = 0; |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1600 |
} |
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1601 |
|
4335
18bc63352a17
(svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents:
4300
diff
changeset
|
1602 |
/* Create a scroll-event and send it to the window */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1603 |
e.event = WE_SCROLL; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1604 |
w->wndproc(w, &e); |
0 | 1605 |
|
2989 | 1606 |
_cursor.delta.x = 0; |
1607 |
_cursor.delta.y = 0; |
|
1608 |
return false; |
|
0 | 1609 |
} |
1610 |
||
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1611 |
/** Check if a window can be made top-most window, and if so do |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1612 |
* it. If a window does not obscure any other windows, it will not |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1613 |
* be brought to the foreground. Also if the only obscuring windows |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1614 |
* are so-called system-windows, the window will not be moved. |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1615 |
* The function will return false when a child window of this window is a |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1616 |
* modal-popup; function returns a false and child window gets a white border |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1617 |
* @param w Window to bring on-top |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1618 |
* @return false if the window has an active modal child, true otherwise */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1619 |
static bool MaybeBringWindowToFront(const Window *w) |
0 | 1620 |
{ |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1621 |
bool bring_to_front = false; |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1622 |
Window* const *wz; |
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
1623 |
Window* const *uz; |
0 | 1624 |
|
2639 | 1625 |
if (w->window_class == WC_MAIN_WINDOW || |
1626 |
IsVitalWindow(w) || |
|
1627 |
w->window_class == WC_TOOLTIPS || |
|
1628 |
w->window_class == WC_DROPDOWN_MENU) { |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1629 |
return true; |
2639 | 1630 |
} |
0 | 1631 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1632 |
wz = FindWindowZPosition(w); |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1633 |
for (uz = wz; ++uz != _last_z_window;) { |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1634 |
Window *u = *uz; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1635 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1636 |
/* A modal child will prevent the activation of the parent window */ |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1637 |
if (u->parent == w && (u->desc_flags & WDF_MODAL)) { |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1638 |
u->flags4 |= WF_WHITE_BORDER_MASK; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1639 |
SetWindowDirty(u); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1640 |
return false; |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1641 |
} |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1642 |
|
2639 | 1643 |
if (u->window_class == WC_MAIN_WINDOW || |
1644 |
IsVitalWindow(u) || |
|
1645 |
u->window_class == WC_TOOLTIPS || |
|
1646 |
u->window_class == WC_DROPDOWN_MENU) { |
|
1647 |
continue; |
|
1648 |
} |
|
0 | 1649 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1650 |
/* Window sizes don't interfere, leave z-order alone */ |
0 | 1651 |
if (w->left + w->width <= u->left || |
1652 |
u->left + u->width <= w->left || |
|
1653 |
w->top + w->height <= u->top || |
|
2639 | 1654 |
u->top + u->height <= w->top) { |
1655 |
continue; |
|
1656 |
} |
|
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1657 |
|
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1658 |
bring_to_front = true; |
0 | 1659 |
} |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1660 |
|
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1661 |
if (bring_to_front) BringWindowToFront(w); |
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1662 |
return true; |
0 | 1663 |
} |
1664 |
||
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1665 |
/** Send a message from one window to another. The receiving window is found by |
9599 | 1666 |
* @param w Window pointer pointing to the other window |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1667 |
* @param msg Specifies the message to be sent |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1668 |
* @param wparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1669 |
* @param lparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1670 |
*/ |
4171 | 1671 |
static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1672 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1673 |
WindowEvent e; |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1674 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1675 |
e.event = WE_MESSAGE; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1676 |
e.we.message.msg = msg; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1677 |
e.we.message.wparam = wparam; |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1678 |
e.we.message.lparam = lparam; |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1679 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1680 |
w->wndproc(w, &e); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1681 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1682 |
|
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1683 |
/** Send a message from one window to another. The receiving window is found by |
9574 | 1684 |
* @param wnd_class see WindowClass class AND |
1685 |
* @param wnd_num see WindowNumber number, mostly 0 |
|
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1686 |
* @param msg Specifies the message to be sent |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1687 |
* @param wparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1688 |
* @param lparam Specifies additional message-specific information |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1689 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1690 |
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam) |
1648
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1691 |
{ |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1692 |
Window *w = FindWindowById(wnd_class, wnd_num); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1693 |
if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam); |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1694 |
} |
747061dca705
(svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents:
1645
diff
changeset
|
1695 |
|
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1696 |
/** Send a message from one window to another. The message will be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1697 |
* to ALL windows of the windowclass specified in the first parameter |
9574 | 1698 |
* @param wnd_class see WindowClass class |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1699 |
* @param msg Specifies the message to be sent |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1700 |
* @param wparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1701 |
* @param lparam Specifies additional message-specific information |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1702 |
*/ |
5838
9c3129cb019b
(svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents:
5835
diff
changeset
|
1703 |
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam) |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1704 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1705 |
Window* const *wz; |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1706 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1707 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1708 |
if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam); |
5043
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1709 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1710 |
} |
d567abc96b5d
(svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents:
4962
diff
changeset
|
1711 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1712 |
/** Handle keyboard input. |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1713 |
* @param key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1714 |
*/ |
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1715 |
void HandleKeypress(uint32 key) |
0 | 1716 |
{ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1717 |
WindowEvent e; |
4549
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1718 |
/* Stores if a window with a textfield for typing is open |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1719 |
* If this is the case, keypress events are only passed to windows with text fields and |
60410aa1aa88
(svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents:
4520
diff
changeset
|
1720 |
* to thein this main toolbar. */ |
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1721 |
bool query_open = false; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1722 |
|
5086
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1723 |
/* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1724 |
* During the generation of the world, there might be |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1725 |
* another thread that is currently building for example |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1726 |
* a road. To not interfere with those tasks, we should |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1727 |
* NOT change the _current_player here. |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1728 |
* |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1729 |
* This is not necessary either, as the only events that |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1730 |
* can be handled are the 'close application' events |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1731 |
*/ |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1732 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
99e0b202b9fb
(svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents:
5077
diff
changeset
|
1733 |
|
9574 | 1734 |
/* Setup event */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1735 |
e.event = WE_KEYPRESS; |
5108
dc67d70b5a45
(svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents:
5090
diff
changeset
|
1736 |
e.we.keypress.key = GB(key, 0, 16); |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
1737 |
e.we.keypress.keycode = GB(key, 16, 16); |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1738 |
e.we.keypress.cont = true; |
0 | 1739 |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1740 |
/* |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1741 |
* The Unicode standard defines an area called the private use area. Code points in this |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1742 |
* area are reserved for private use and thus not portable between systems. For instance, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1743 |
* Apple defines code points for the arrow keys in this area, but these are only printable |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1744 |
* on a system running OS X. We don't want these keys to show up in text fields and such, |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1745 |
* and thus we have to clear the unicode character when we encounter such a key. |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1746 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1747 |
if (e.we.keypress.key >= 0xE000 && e.we.keypress.key <= 0xF8FF) e.we.keypress.key = 0; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1748 |
|
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1749 |
/* |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1750 |
* If both key and keycode is zero, we don't bother to process the event. |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1751 |
*/ |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1752 |
if (e.we.keypress.key == 0 && e.we.keypress.keycode == 0) return; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1753 |
|
9574 | 1754 |
/* check if we have a query string window open before allowing hotkeys */ |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1755 |
if (FindWindowById(WC_QUERY_STRING, 0) != NULL || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1756 |
FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1757 |
FindWindowById(WC_GENERATE_LANDSCAPE, 0) != NULL || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1758 |
FindWindowById(WC_CONSOLE, 0) != NULL || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1759 |
FindWindowById(WC_SAVELOAD, 0) != NULL || |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1760 |
FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) { |
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1761 |
query_open = true; |
2639 | 1762 |
} |
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1763 |
|
9574 | 1764 |
/* Call the event, start with the uppermost window. */ |
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1765 |
for (Window* const *wz = _last_z_window; wz != _z_windows;) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1766 |
Window *w = *--wz; |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1767 |
|
9574 | 1768 |
/* if a query window is open, only call the event for certain window types */ |
2639 | 1769 |
if (query_open && |
1770 |
w->window_class != WC_QUERY_STRING && |
|
1771 |
w->window_class != WC_SEND_NETWORK_MSG && |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1772 |
w->window_class != WC_GENERATE_LANDSCAPE && |
2639 | 1773 |
w->window_class != WC_CONSOLE && |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1774 |
w->window_class != WC_SAVELOAD && |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
1775 |
w->window_class != WC_COMPANY_PASSWORD_WINDOW) { |
651
32b229802ed2
(svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents:
649
diff
changeset
|
1776 |
continue; |
2639 | 1777 |
} |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1778 |
w->wndproc(w, &e); |
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1779 |
if (!e.we.keypress.cont) break; |
0 | 1780 |
} |
1637
5a51ba5fb8b7
(svn r2141) - Fix: Keys now hopefully only activate the right windows. If console/querybox/chatbox is open, all input goes there, if closed to game itself.
Darkvater
parents:
1570
diff
changeset
|
1781 |
|
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1782 |
if (e.we.keypress.cont) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
1783 |
Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
9574 | 1784 |
/* When there is no toolbar w is null, check for that */ |
4634
897461a3e9ca
(svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents:
4549
diff
changeset
|
1785 |
if (w != NULL) w->wndproc(w, &e); |
1642
593a9b750b91
(svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents:
1637
diff
changeset
|
1786 |
} |
0 | 1787 |
} |
1788 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1789 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1790 |
* State of CONTROL key has changed |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1791 |
*/ |
9732 | 1792 |
void HandleCtrlChanged() |
1793 |
{ |
|
1794 |
WindowEvent e; |
|
1795 |
||
1796 |
e.event = WE_CTRL_CHANGED; |
|
1797 |
e.we.ctrl.cont = true; |
|
1798 |
||
1799 |
/* Call the event, start with the uppermost window. */ |
|
1800 |
for (Window* const *wz = _last_z_window; wz != _z_windows;) { |
|
1801 |
Window *w = *--wz; |
|
1802 |
w->wndproc(w, &e); |
|
1803 |
if (!e.we.ctrl.cont) break; |
|
1804 |
} |
|
1805 |
} |
|
1806 |
||
6573 | 1807 |
extern void UpdateTileSelection(); |
1808 |
extern bool VpHandlePlaceSizingDrag(); |
|
0 | 1809 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1810 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1811 |
* Local counter that is incremented each time an mouse input event is detected. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1812 |
* The counter is used to stop auto-scrolling. |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1813 |
* @see HandleAutoscroll() |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1814 |
* @see HandleMouseEvents() |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1815 |
*/ |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1816 |
static int _input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1817 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1818 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1819 |
* If needed and switched on, perform auto scrolling (automatically |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1820 |
* moving window contents when mouse is near edge of the window). |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1821 |
*/ |
6573 | 1822 |
static void HandleAutoscroll() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1823 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1824 |
Window *w; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1825 |
ViewPort *vp; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1826 |
int x = _cursor.pos.x; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1827 |
int y = _cursor.pos.y; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1828 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1829 |
if (_input_events_this_tick != 0) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1830 |
/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1831 |
_input_events_this_tick = 0; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1832 |
/* there were some inputs this tick, don't scroll ??? */ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1833 |
return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1834 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1835 |
|
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1836 |
if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1837 |
w = FindWindowFromPt(x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1838 |
if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1839 |
vp = IsPtInWindowViewport(w, x, y); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1840 |
if (vp != NULL) { |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1841 |
x -= vp->left; |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1842 |
y -= vp->top; |
9574 | 1843 |
/* here allows scrolling in both x and y axis */ |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1844 |
#define scrollspeed 3 |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1845 |
if (x - 15 < 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1846 |
WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1847 |
} else if (15 - (vp->width - x) > 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1848 |
WP(w, vp_d).dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1849 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1850 |
if (y - 15 < 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1851 |
WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1852 |
} else if (15 - (vp->height - y) > 0) { |
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
1853 |
WP(w, vp_d).dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom); |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1854 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1855 |
#undef scrollspeed |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1856 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1857 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1858 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1859 |
|
9629 | 1860 |
enum MouseClick { |
1861 |
MC_NONE = 0, |
|
1862 |
MC_LEFT, |
|
1863 |
MC_RIGHT, |
|
1864 |
MC_DOUBLE_LEFT, |
|
1865 |
||
1866 |
MAX_OFFSET_DOUBLE_CLICK = 5, ///< How much the mouse is allowed to move to call it a double click |
|
1867 |
TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms |
|
1868 |
}; |
|
1869 |
||
1870 |
void MouseLoop(MouseClick click, int mousewheel) |
|
0 | 1871 |
{ |
1872 |
int x,y; |
|
1873 |
Window *w; |
|
1874 |
ViewPort *vp; |
|
6615
96d30d65ed35
(svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents:
6574
diff
changeset
|
1875 |
bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
1876 |
|
0 | 1877 |
DecreaseWindowCounters(); |
1878 |
HandlePlacePresize(); |
|
1879 |
UpdateTileSelection(); |
|
2639 | 1880 |
if (!VpHandlePlaceSizingDrag()) return; |
1881 |
if (!HandleDragDrop()) return; |
|
1882 |
if (!HandlePopupMenu()) return; |
|
1883 |
if (!HandleWindowDragging()) return; |
|
1884 |
if (!HandleScrollbarScrolling()) return; |
|
1885 |
if (!HandleViewportScroll()) return; |
|
1886 |
if (!HandleMouseOver()) return; |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
410
diff
changeset
|
1887 |
|
0 | 1888 |
x = _cursor.pos.x; |
1889 |
y = _cursor.pos.y; |
|
1890 |
||
9629 | 1891 |
if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return; |
0 | 1892 |
|
1893 |
w = FindWindowFromPt(x, y); |
|
2639 | 1894 |
if (w == NULL) return; |
5667
248a3234d2e2
(svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents:
5666
diff
changeset
|
1895 |
if (!MaybeBringWindowToFront(w)) return; |
0 | 1896 |
vp = IsPtInWindowViewport(w, x, y); |
1897 |
||
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1898 |
/* Don't allow any action in a viewport if either in menu of in generating world */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1899 |
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
|
1900 |
|
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1901 |
if (mousewheel != 0) { |
6622
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1902 |
if (_patches.scrollwheel_scrolling == 0) { |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1903 |
/* Scrollwheel is in zoom mode. Make the zoom event. */ |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1904 |
WindowEvent e; |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1905 |
|
6622
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1906 |
/* Send WE_MOUSEWHEEL event to window */ |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1907 |
e.event = WE_MOUSEWHEEL; |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1908 |
e.we.wheel.wheel = mousewheel; |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1909 |
w->wndproc(w, &e); |
2ce7ffa9db00
(svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents:
6616
diff
changeset
|
1910 |
} |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1911 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1912 |
/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */ |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1913 |
if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1914 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1915 |
|
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1916 |
if (vp != NULL) { |
9629 | 1917 |
if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1918 |
switch (click) { |
9629 | 1919 |
case MC_DOUBLE_LEFT: |
1920 |
case MC_LEFT: |
|
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
1921 |
DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite); |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1922 |
if (_thd.place_mode != VHM_NONE && |
9574 | 1923 |
/* query button and place sign button work in pause mode */ |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1924 |
_cursor.sprite != SPR_CURSOR_QUERY && |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1925 |
_cursor.sprite != SPR_CURSOR_SIGN && |
6557
8381016f71f3
(svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents:
6443
diff
changeset
|
1926 |
_pause_game != 0 && |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1927 |
!_cheats.build_in_pause.value) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1928 |
return; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1929 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1930 |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
1931 |
if (_thd.place_mode == VHM_NONE) { |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1932 |
HandleViewportClicked(vp, x, y); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1933 |
} else { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1934 |
PlaceObject(); |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1935 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1936 |
break; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1937 |
|
9629 | 1938 |
case MC_RIGHT: |
4337
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1939 |
if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) { |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1940 |
_scrolling_viewport = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1941 |
_cursor.fix_at = true; |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1942 |
} |
f77887bd2634
(svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents:
4335
diff
changeset
|
1943 |
break; |
9629 | 1944 |
|
1945 |
default: |
|
1946 |
break; |
|
0 | 1947 |
} |
1948 |
} else { |
|
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1949 |
switch (click) { |
9629 | 1950 |
case MC_DOUBLE_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, true); |
1951 |
/* fallthough, and also give a single-click for backwards compatible */ |
|
1952 |
case MC_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, false); break; |
|
6616
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1953 |
default: |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1954 |
if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break; |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1955 |
/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons. |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1956 |
* Simulate a right button click so we can get started. */ |
fb4513362b7f
(svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents:
6615
diff
changeset
|
1957 |
/* fallthough */ |
9629 | 1958 |
case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break; |
2631
13daba67f217
(svn r3173) Use the trinary operator and switch to improve readability
tron
parents:
2630
diff
changeset
|
1959 |
} |
0 | 1960 |
} |
1961 |
} |
|
1962 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1963 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1964 |
* Handle a mouse event from the video driver |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
1965 |
*/ |
6573 | 1966 |
void HandleMouseEvents() |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1967 |
{ |
9629 | 1968 |
static int double_click_time = 0; |
1969 |
static int double_click_x = 0; |
|
1970 |
static int double_click_y = 0; |
|
1971 |
MouseClick click; |
|
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1972 |
int mousewheel; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1973 |
|
4300
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1974 |
/* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1975 |
* During the generation of the world, there might be |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1976 |
* another thread that is currently building for example |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1977 |
* a road. To not interfere with those tasks, we should |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1978 |
* NOT change the _current_player here. |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1979 |
* |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1980 |
* This is not necessary either, as the only events that |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1981 |
* can be handled are the 'close application' events |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1982 |
*/ |
687a17c9c557
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
4171
diff
changeset
|
1983 |
if (!IsGeneratingWorld()) _current_player = _local_player; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1984 |
|
9574 | 1985 |
/* Mouse event? */ |
9629 | 1986 |
click = MC_NONE; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1987 |
if (_left_button_down && !_left_button_clicked) { |
9629 | 1988 |
click = MC_LEFT; |
1989 |
if (double_click_time != 0 && _realtime_tick - double_click_time < TIME_BETWEEN_DOUBLE_CLICK && |
|
1990 |
double_click_x != 0 && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK && |
|
1991 |
double_click_y != 0 && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) { |
|
1992 |
click = MC_DOUBLE_LEFT; |
|
1993 |
} |
|
1994 |
double_click_time = _realtime_tick; |
|
1995 |
double_click_x = _cursor.pos.x; |
|
1996 |
double_click_y = _cursor.pos.y; |
|
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1997 |
_left_button_clicked = true; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
1998 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
1999 |
} else if (_right_button_clicked) { |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2000 |
_right_button_clicked = false; |
9629 | 2001 |
click = MC_RIGHT; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2002 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2003 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2004 |
|
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2005 |
mousewheel = 0; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2006 |
if (_cursor.wheel) { |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2007 |
mousewheel = _cursor.wheel; |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2008 |
_cursor.wheel = 0; |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2009 |
_input_events_this_tick++; |
1570
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2010 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2011 |
|
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2012 |
MouseLoop(click, mousewheel); |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2013 |
} |
c470380facb9
(svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents:
1474
diff
changeset
|
2014 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2015 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2016 |
* Regular call from the global game loop |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2017 |
*/ |
6573 | 2018 |
void InputLoop() |
5090
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2019 |
{ |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2020 |
HandleMouseEvents(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2021 |
HandleAutoscroll(); |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2022 |
} |
8907f67c2c15
(svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents:
5089
diff
changeset
|
2023 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2024 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2025 |
* Update the continuously changing contents of the windows, such as the viewports |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2026 |
*/ |
6573 | 2027 |
void UpdateWindows() |
0 | 2028 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2029 |
Window* const *wz; |
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
2030 |
static int we4_timer = 0; |
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
2031 |
int t = we4_timer + 1; |
0 | 2032 |
|
2639 | 2033 |
if (t >= 100) { |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2034 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2035 |
CallWindowEventNP(*--wz, WE_4); |
0 | 2036 |
} |
2037 |
t = 0; |
|
2038 |
} |
|
5089
9d290a04d79c
(svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents:
5086
diff
changeset
|
2039 |
we4_timer = t; |
0 | 2040 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2041 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2042 |
Window *w = *--wz; |
0 | 2043 |
if (w->flags4 & WF_WHITE_BORDER_MASK) { |
2044 |
w->flags4 -= WF_WHITE_BORDER_ONE; |
|
5120
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
2045 |
|
e12dfc67761f
(svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents:
5108
diff
changeset
|
2046 |
if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w); |
0 | 2047 |
} |
2048 |
} |
|
2049 |
||
2050 |
DrawDirtyBlocks(); |
|
2051 |
||
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2052 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2053 |
if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz); |
0 | 2054 |
} |
9701
d1ac22c62f64
(svn r11036) [NoAI] -Sync: with trunk r10774:11035.
rubidium
parents:
9694
diff
changeset
|
2055 |
DrawChatMessage(); |
9574 | 2056 |
/* Redraw mouse cursor in case it was hidden */ |
0 | 2057 |
DrawMouseCursor(); |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2058 |
} |
0 | 2059 |
|
2060 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2061 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2062 |
* In a window with menu_d custom extension, retrieve the menu item number from a position |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2063 |
* @param w Window holding the menu items |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2064 |
* @param x X coordinate of the position |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2065 |
* @param y Y coordinate of the position |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2066 |
* @return Index number of the menu item, or \c -1 if no valid selection under position |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2067 |
*/ |
2436
177cb6a8339f
(svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents:
2216
diff
changeset
|
2068 |
int GetMenuItemIndex(const Window *w, int x, int y) |
0 | 2069 |
{ |
2070 |
if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) { |
|
2071 |
y /= 10; |
|
2072 |
||
2639 | 2073 |
if (y < WP(w, const menu_d).item_count && |
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2074 |
!HasBit(WP(w, const menu_d).disabled_items, y)) { |
0 | 2075 |
return y; |
2639 | 2076 |
} |
0 | 2077 |
} |
2078 |
return -1; |
|
2079 |
} |
|
2080 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2081 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2082 |
* Mark window data as invalid (in need of re-computing) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2083 |
* @param w Window with invalid data |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2084 |
*/ |
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
2085 |
void InvalidateWindow(WindowClass cls, WindowNumber number) |
0 | 2086 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2087 |
Window* const *wz; |
0 | 2088 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2089 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2090 |
const Window *w = *wz; |
2639 | 2091 |
if (w->window_class == cls && w->window_number == number) SetWindowDirty(w); |
0 | 2092 |
} |
2093 |
} |
|
2094 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2095 |
/* |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2096 |
* Mark a particular widget in a particular window as dirty (in need of repainting) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2097 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2098 |
* @param number Window number in that class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2099 |
* @param widget_index Index number of the widget that needs repainting |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2100 |
*/ |
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
2101 |
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index) |
0 | 2102 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2103 |
Window* const *wz; |
0 | 2104 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2105 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2106 |
const Window *w = *wz; |
2639 | 2107 |
if (w->window_class == cls && w->window_number == number) { |
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2108 |
w->InvalidateWidget(widget_index); |
0 | 2109 |
} |
2110 |
} |
|
2111 |
} |
|
2112 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2113 |
/* |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2114 |
* Mark all windows of a particular class as dirty (in need of repainting) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2115 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2116 |
*/ |
2788
db2896482939
(svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents:
2703
diff
changeset
|
2117 |
void InvalidateWindowClasses(WindowClass cls) |
0 | 2118 |
{ |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2119 |
Window* const *wz; |
2639 | 2120 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2121 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2122 |
if ((*wz)->window_class == cls) SetWindowDirty(*wz); |
0 | 2123 |
} |
2124 |
} |
|
2125 |
||
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2126 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2127 |
* Mark window data as invalid (in need of re-computing) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2128 |
* @param w Window with invalid data |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2129 |
*/ |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2130 |
void InvalidateThisWindowData(Window *w) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2131 |
{ |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2132 |
CallWindowEventNP(w, WE_INVALIDATE_DATA); |
5198
2547d72f2db4
(svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents:
5143
diff
changeset
|
2133 |
SetWindowDirty(w); |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2134 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2135 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2136 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2137 |
* Mark window data the window of a given class and specific window number as invalid (in need of re-computing) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2138 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2139 |
* @param number Window number within the class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2140 |
*/ |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2141 |
void InvalidateWindowData(WindowClass cls, WindowNumber number) |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2142 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2143 |
Window* const *wz; |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2144 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2145 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2146 |
Window *w = *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2147 |
if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w); |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2148 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2149 |
} |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2150 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2151 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2152 |
* Mark window data of all windows of a given class as invalid (in need of re-computing) |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2153 |
* @param cls Window class |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2154 |
*/ |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2155 |
void InvalidateWindowClassesData(WindowClass cls) |
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2156 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2157 |
Window* const *wz; |
4766
a23183d868d1
(svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents:
4757
diff
changeset
|
2158 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2159 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2160 |
if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz); |
4739
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2161 |
} |
bd535b408617
(svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents:
4719
diff
changeset
|
2162 |
} |
0 | 2163 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2164 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2165 |
* Dispatch WE_TICK event over all windows |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2166 |
*/ |
6573 | 2167 |
void CallWindowTickEvent() |
0 | 2168 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2169 |
Window* const *wz; |
2639 | 2170 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2171 |
for (wz = _last_z_window; wz != _z_windows;) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2172 |
CallWindowEventNP(*--wz, WE_TICK); |
0 | 2173 |
} |
2174 |
} |
|
2175 |
||
6573 | 2176 |
void DeleteNonVitalWindows() |
0 | 2177 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2178 |
Window* const *wz; |
2639 | 2179 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2180 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2181 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2182 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2183 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2184 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2185 |
Window *w = *wz; |
0 | 2186 |
if (w->window_class != WC_MAIN_WINDOW && |
2187 |
w->window_class != WC_SELECT_GAME && |
|
2188 |
w->window_class != WC_MAIN_TOOLBAR && |
|
2189 |
w->window_class != WC_STATUS_BAR && |
|
2190 |
w->window_class != WC_TOOLBAR_MENU && |
|
682
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
2191 |
w->window_class != WC_TOOLTIPS && |
7f5de4abac85
(svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents:
679
diff
changeset
|
2192 |
(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned' |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2193 |
|
0 | 2194 |
DeleteWindow(w); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2195 |
goto restart_search; |
0 | 2196 |
} |
2197 |
} |
|
2198 |
} |
|
2199 |
||
9599 | 2200 |
/** It is possible that a stickied window gets to a position where the |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2201 |
* 'close' button is outside the gaming area. You cannot close it then; except |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2202 |
* with this function. It closes all windows calling the standard function, |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2203 |
* then, does a little hacked loop of closing all stickied windows. Note |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2204 |
* that standard windows (status bar, etc.) are not stickied, so these aren't affected */ |
6573 | 2205 |
void DeleteAllNonVitalWindows() |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2206 |
{ |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2207 |
Window* const *wz; |
2639 | 2208 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2209 |
/* Delete every window except for stickied ones, then sticky ones as well */ |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2210 |
DeleteNonVitalWindows(); |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2211 |
|
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2212 |
restart_search: |
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2213 |
/* When we find the window to delete, we need to restart the search |
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2214 |
* as deleting this window could cascade in deleting (many) others |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2215 |
* anywhere in the z-array */ |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2216 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2217 |
if ((*wz)->flags4 & WF_STICKY) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2218 |
DeleteWindow(*wz); |
5121
9fedd27b3ec3
(svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents:
5120
diff
changeset
|
2219 |
goto restart_search; |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2220 |
} |
763
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2221 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2222 |
} |
8ff348acf75e
(svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents:
682
diff
changeset
|
2223 |
|
9599 | 2224 |
/** Delete all always on-top windows to get an empty screen */ |
6573 | 2225 |
void HideVitalWindows() |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2226 |
{ |
6158
ca1471170695
(svn r8533) -Fix: segmentation fault when the toolbar gets removed and you have selected one of the items in a submenu of the toolbar.
rubidium
parents:
5893
diff
changeset
|
2227 |
DeleteWindowById(WC_TOOLBAR_MENU, 0); |
983
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2228 |
DeleteWindowById(WC_MAIN_TOOLBAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2229 |
DeleteWindowById(WC_STATUS_BAR, 0); |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2230 |
} |
1be852dcdd4c
(svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents:
982
diff
changeset
|
2231 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2232 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2233 |
* (Re)position main toolbar window at the screen |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2234 |
* @param w Window structure of the main toolbar window, may also be \c NULL |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2235 |
* @return X coordinate of left edge of the repositioned toolbar window |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2236 |
*/ |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2237 |
int PositionMainToolbar(Window *w) |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2238 |
{ |
5568
75f13d7bfaed
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5272
diff
changeset
|
2239 |
DEBUG(misc, 5, "Repositioning Main Toolbar..."); |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2240 |
|
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2241 |
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
|
2242 |
w = FindWindowById(WC_MAIN_TOOLBAR, 0); |
4077
d3022f976946
(svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents:
4000
diff
changeset
|
2243 |
} |
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2244 |
|
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2245 |
switch (_patches.toolbar_pos) { |
5071
14f432b47034
(svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents:
5043
diff
changeset
|
2246 |
case 1: w->left = (_screen.width - w->width) / 2; break; |
2026 | 2247 |
case 2: w->left = _screen.width - w->width; break; |
2248 |
default: w->left = 0; |
|
68
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2249 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2250 |
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
|
2251 |
return w->left; |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2252 |
} |
4051f3c8efa2
(svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents:
67
diff
changeset
|
2253 |
|
10142
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2254 |
/** |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2255 |
* Relocate all windows to fit the new size of the game application screen |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2256 |
* @param neww New width of the game application screen |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2257 |
* @param newh New height of the game appliction screen |
56ee7da4ad56
(svn r12673) [NoAI] -Sync: with trunk r12596:12672. Note that due to the order rewrite AIOrder.ChangeOrder does currently not work as expected.
rubidium
parents:
9826
diff
changeset
|
2258 |
*/ |
0 | 2259 |
void RelocateAllWindows(int neww, int newh) |
2260 |
{ |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2261 |
Window* const *wz; |
0 | 2262 |
|
5124
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2263 |
FOR_ALL_WINDOWS(wz) { |
d30772d0e9e1
(svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents:
5122
diff
changeset
|
2264 |
Window *w = *wz; |
0 | 2265 |
int left, top; |
158
b1a821f84250
(svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents:
152
diff
changeset
|
2266 |
|
0 | 2267 |
if (w->window_class == WC_MAIN_WINDOW) { |
2268 |
ViewPort *vp = w->viewport; |
|
2269 |
vp->width = w->width = neww; |
|
2270 |
vp->height = w->height = newh; |
|
9624 | 2271 |
vp->virtual_width = ScaleByZoom(neww, vp->zoom); |
2272 |
vp->virtual_height = ScaleByZoom(newh, vp->zoom); |
|
0 | 2273 |
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
|
2274 |
} |
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
|
2275 |
|
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2276 |
/* XXX - this probably needs something more sane. For example specying |
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2277 |
* in a 'backup'-desc that the window should always be centred. */ |
2989 | 2278 |
switch (w->window_class) { |
2279 |
case WC_MAIN_TOOLBAR: |
|
9694
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2280 |
if (neww - w->width != 0) { |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2281 |
ResizeWindow(w, min(neww, 640) - w->width, 0); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2282 |
|
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2283 |
WindowEvent e; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2284 |
e.event = WE_RESIZE; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2285 |
e.we.sizing.size.x = w->width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2286 |
e.we.sizing.size.y = w->height; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2287 |
e.we.sizing.diff.x = neww - w->width; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2288 |
e.we.sizing.diff.y = 0; |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2289 |
w->wndproc(w, &e); |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2290 |
} |
e72987579514
(svn r10775) [NoAI] -Sync: with trunk r10535:r10774.
rubidium
parents:
9641
diff
changeset
|
2291 |
|
2989 | 2292 |
top = w->top; |
2293 |
left = PositionMainToolbar(w); // changes toolbar orientation |
|
2294 |
break; |
|
2295 |
||
2296 |
case WC_SELECT_GAME: |
|
2297 |
case WC_GAME_OPTIONS: |
|
2298 |
case WC_NETWORK_WINDOW: |
|
2299 |
top = (newh - w->height) >> 1; |
|
2300 |
left = (neww - w->width) >> 1; |
|
2301 |
break; |
|
2302 |
||
2303 |
case WC_NEWS_WINDOW: |
|
2304 |
top = newh - w->height; |
|
2305 |
left = (neww - w->width) >> 1; |
|
2306 |
break; |
|
2307 |
||
2308 |
case WC_STATUS_BAR: |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2309 |
ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0); |
2989 | 2310 |
top = newh - w->height; |
2311 |
left = (neww - w->width) >> 1; |
|
2312 |
break; |
|
2313 |
||
2314 |
case WC_SEND_NETWORK_MSG: |
|
9722
ebf0ece7d8f6
(svn r11503) [NoAI] -Sync: with trunk r11308:11502.
rubidium
parents:
9718
diff
changeset
|
2315 |
ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0); |
2989 | 2316 |
top = (newh - 26); // 26 = height of status bar + height of chat bar |
2317 |
left = (neww - w->width) >> 1; |
|
2318 |
break; |
|
2319 |
||
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2320 |
case WC_CONSOLE: |
5143
a78072872bff
(svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents:
5137
diff
changeset
|
2321 |
IConsoleResize(w); |
5137
a1f26c30fecd
(svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents:
5126
diff
changeset
|
2322 |
continue; |
5126
d87bd8d5e159
(svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents:
5124
diff
changeset
|
2323 |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2324 |
default: { |
2989 | 2325 |
left = w->left; |
2326 |
if (left + (w->width >> 1) >= neww) left = neww - w->width; |
|
9723
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2327 |
if (left < 0) left = 0; |
eee46cb39750
(svn r11796) [NoAI] -Sync: with trunk r11502:11795.
rubidium
parents:
9722
diff
changeset
|
2328 |
|
2989 | 2329 |
top = w->top; |
2330 |
if (top + (w->height >> 1) >= newh) top = newh - w->height; |
|
9826
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2331 |
|
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2332 |
const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0); |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2333 |
if (wt != NULL) { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2334 |
if (top < wt->height) top = wt->height; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2335 |
if (top >= newh) top = newh - 1; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2336 |
} else { |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2337 |
if (top < 0) top = 0; |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2338 |
} |
9707ad4c9b60
(svn r12462) [NoAI] -Sync: with trunk r12304:12461.
rubidium
parents:
9732
diff
changeset
|
2339 |
} break; |
0 | 2340 |
} |
2341 |
||
2639 | 2342 |
if (w->viewport != NULL) { |
0 | 2343 |
w->viewport->left += left - w->left; |
2344 |
w->viewport->top += top - w->top; |
|
2345 |
} |
|
2346 |
||
2347 |
w->left = left; |
|
2348 |
w->top = top; |
|
2349 |
} |
|
2350 |
} |