src/window.cpp
author richk
Tue, 17 Jun 2008 13:22:13 +0000
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
permissions -rw-r--r--
(svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
     3
/** @file window.cpp Windowing system, widgets and events */
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
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     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"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
     9
#include "player_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    10
#include "gfx_func.h"
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    11
#include "console_func.h"
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
    12
#include "console_gui.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    13
#include "viewport_func.h"
2159
3b634157c3b2 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    14
#include "variables.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    15
#include "genworld.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    16
#include "blitter/factory.hpp"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    17
#include "window_gui.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    18
#include "zoom_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    19
#include "core/alloc_func.hpp"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    20
#include "map_func.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    21
#include "vehicle_base.h"
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    22
#include "settings_type.h"
10242
52b4a9006029 (svn r12774) [NewGRF_ports] -Sync: with trunk r12742:12772.
richk
parents: 10211
diff changeset
    23
#include "cheat_func.h"
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    24
#include "window_func.h"
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    25
#include "tilehighlight_func.h"
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    26
2517
b90693227193 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2436
diff changeset
    27
#include "table/sprites.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
    29
static Point _drag_delta; ///< delta between mouse cursor and upper left corner of dragged window
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
    30
static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    31
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    32
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    33
 * List of windows opened at the screen.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    34
 * Uppermost window is at  _z_windows[_last_z_window - 1],
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    35
 * bottom window is at _z_windows[0]
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
    36
 */
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
    37
Window *_z_windows[MAX_NUMBER_OF_WINDOWS];
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
    38
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
    39
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
    40
byte _no_scroll;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    41
Point _cursorpos_drag_start;
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    42
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    43
int _scrollbar_start_pos;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    44
int _scrollbar_size;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    45
byte _scroller_click_timeout;
4755
4a3564952554 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
    46
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    47
bool _scrolling_scrollbar;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    48
bool _scrolling_viewport;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    49
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    50
byte _special_mouse_mode;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    51
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
    52
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    53
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    54
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    55
	va_list wdg_list;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    56
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    57
	va_start(wdg_list, widgets);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    58
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    59
	while (widgets != WIDGET_LIST_END) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    60
		SetWidgetDisabledState(widgets, disab_stat);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    61
		widgets = va_arg(wdg_list, int);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    62
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    63
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    64
	va_end(wdg_list);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    65
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    66
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    67
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    68
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    69
	va_list wdg_list;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    70
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    71
	va_start(wdg_list, widgets);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    72
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    73
	while (widgets != WIDGET_LIST_END) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    74
		SetWidgetHiddenState(widgets, hidden_stat);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    75
		widgets = va_arg(wdg_list, int);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    76
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    77
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    78
	va_end(wdg_list);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    79
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    80
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    81
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    82
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    83
	va_list wdg_list;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    84
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    85
	va_start(wdg_list, widgets);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    86
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    87
	while (widgets != WIDGET_LIST_END) {
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    88
		SetWidgetLoweredState(widgets, lowered_stat);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    89
		widgets = va_arg(wdg_list, int);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    90
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    91
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    92
	va_end(wdg_list);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    93
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    94
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    95
void Window::RaiseButtons()
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
    96
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
    97
	for (uint i = 0; i < this->widget_count; i++) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    98
		if (this->IsWidgetLowered(i)) {
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
    99
			this->RaiseWidget(i);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   100
			this->InvalidateWidget(i);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   101
		}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   102
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   103
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   104
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   105
void Window::InvalidateWidget(byte widget_index) const
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   106
{
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   107
	const Widget *wi = &this->widget[widget_index];
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   108
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   109
	/* Don't redraw the window if the widget is invisible or of no-type */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   110
	if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   111
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   112
	SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   113
}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   114
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   115
void Window::HandleButtonClick(byte widget)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
{
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   117
	this->LowerWidget(widget);
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   118
	this->flags4 |= 5 << WF_TIMEOUT_SHL;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
   119
	this->InvalidateWidget(widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   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
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   124
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   125
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   126
 * Dispatch left mouse-button (possibly double) click in window.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   127
 * @param w Window to dispatch event in
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   128
 * @param x X coordinate of the click
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   129
 * @param y Y coordinate of the click
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   130
 * @param double_click Was it a double click?
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   131
 */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
   132
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   133
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   134
	int widget = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   135
	if (w->desc_flags & WDF_DEF_WIDGET) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   136
		widget = GetWidgetFromPos(w, x, y);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   137
		if (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
   138
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
   139
		/* don't allow any interaction if the button has been disabled */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   140
		if (w->IsWidgetDisabled(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
   141
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   142
		const Widget *wi = &w->widget[widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   144
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   145
			/* special widget handling for buttons*/
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   146
			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
   147
				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
   148
				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
   149
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   150
					w->HandleButtonClick(widget);
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   151
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
			}
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   153
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   154
			ScrollbarClickHandler(w, wi, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   157
		if (w->desc_flags & WDF_STD_BTN) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   158
			if (widget == 0) { /* 'X' */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   159
				delete 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
   160
				return;
1109
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   161
			}
1bab892228cd (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   162
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   163
			if (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
   164
				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
   165
				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
   166
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   168
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
   169
		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
   170
			StartWindowSizing(w);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   171
			w->InvalidateWidget(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
   172
			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
   173
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   174
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   175
		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
   176
			w->flags4 ^= WF_STICKY;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   177
			w->InvalidateWidget(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;
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
   179
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   180
	}
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
   181
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   182
	Point pt = { x, y };
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   183
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   184
	if (double_click) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   185
		w->OnDoubleClick(pt, widget);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   186
	} else {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   187
		w->OnClick(pt, widget);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   188
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   190
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   191
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   192
 * Dispatch right mouse-button click in window.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   193
 * @param w Window to dispatch event in
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   194
 * @param x X coordinate of the click
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   195
 * @param y Y coordinate of the click
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   196
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   197
static void DispatchRightClickEvent(Window *w, int x, int y)
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
   198
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   199
	int widget = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
	/* default tooltips handler? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	if (w->desc_flags & WDF_STD_TOOLTIPS) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   203
		widget = GetWidgetFromPos(w, x, y);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   204
		if (widget < 0) return; // exit if clicked outside of widgets
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   206
		if (w->widget[widget].tooltips != 0) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   207
			GuiShowTooltips(w->widget[widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   212
	Point pt = { x, y };
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   213
	w->OnRightClick(pt, widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   216
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   217
 * Dispatch the mousewheel-action to the window.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   218
 * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   219
 * @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
   220
 * @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
   221
 * @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
   222
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   223
static void DispatchMouseWheelEvent(Window *w, int widget, int wheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
{
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
   225
	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
   226
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   227
	const Widget *wi1 = &w->widget[widget];
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   228
	const Widget *wi2 = &w->widget[widget + 1];
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
   229
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
   230
	/* 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
   231
	 * 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
   232
	 * 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
   233
	 * not happening until someone rewrites the whole widget-code */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   234
	Scrollbar *sb;
1019
6363b8a4273e (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   235
	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
   236
			(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
   237
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
		if (sb->count > sb->cap) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   239
			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
   240
			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
   241
				sb->pos = pos;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   242
				w->SetDirty();
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
   243
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   248
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   249
 * Generate repaint events for the visible part of window *wz within the rectangle.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   250
 *
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   251
 * The function goes recursively upwards in the window stack, and splits the rectangle
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   252
 * into multiple pieces at the window edges, so obscured parts are not redrawn.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   253
 *
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   254
 * @param wz Pointer into window stack, pointing at the window that needs to be repainted
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   255
 * @param left Left edge of the rectangle that should be repainted
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   256
 * @param top Top edge of the rectangle that should be repainted
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   257
 * @param right Right edge of the rectangle that should be repainted
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   258
 * @param bottom Bottom edge of the rectangle that should be repainted
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   259
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   260
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
{
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
   262
	Window* const *vz = wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   264
	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
   265
		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
   266
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
		if (right > v->left &&
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
   268
				bottom > v->top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				left < v->left + v->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
				top < v->top + v->height) {
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   271
			/* v and rectangle intersect with eeach other */
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   272
			int x;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   273
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   274
			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
   275
				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
   276
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   280
			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
   281
				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
   282
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   286
			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
   287
				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
   288
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   292
			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
   293
				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
   294
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   296
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   302
	/* Setup blitter, and dispatch a repaint event to window *wz */
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   303
	DrawPixelInfo *dp = _cur_dpi;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   304
	dp->width = right - left;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   305
	dp->height = bottom - top;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   306
	dp->left = left - (*wz)->left;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   307
	dp->top = top - (*wz)->top;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   308
	dp->pitch = _screen.pitch;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   309
	dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   310
	dp->zoom = ZOOM_LVL_NORMAL;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   311
	(*wz)->OnPaint();
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   312
}
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   313
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   314
/**
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   315
 * From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   316
 * These windows should be re-painted.
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   317
 * @param left Left edge of the rectangle that should be repainted
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   318
 * @param top Top edge of the rectangle that should be repainted
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   319
 * @param right Right edge of the rectangle that should be repainted
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   320
 * @param bottom Bottom edge of the rectangle that should be repainted
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   321
 */
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   322
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   323
{
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   324
	Window* const *wz;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   325
	DrawPixelInfo bk;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   326
	_cur_dpi = &bk;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   327
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   328
	FOR_ALL_WINDOWS(wz) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   329
		const Window *w = *wz;
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   330
		if (right > w->left &&
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   331
				bottom > w->top &&
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   332
				left < w->left + w->width &&
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   333
				top < w->top + w->height) {
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   334
			/* Window w intersects with the rectangle => needs repaint */
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   335
			DrawOverlappedWindow(wz, left, top, right, bottom);
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   336
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   338
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   340
/**
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   341
 * Mark entire window as dirty (in need of re-paint)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   342
 * @param w Window to redraw
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   343
 * @ingroup dirty
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   344
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   345
void Window::SetDirty() const
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   346
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   347
	SetDirtyBlocks(this->left, this->top, this->left + this->width, this->top + this->height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   350
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   351
 * Mark entire window as dirty (in need of re-paint)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   352
 * @param w Window to redraw
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   353
 * @ingroup dirty
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   354
 */
4171
3fadda3afe70 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   355
void SetWindowDirty(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   357
	if (w != NULL) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
5666
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   360
/** Find the Window whose parent pointer points to this window
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   361
 * @param w parent Window to find child of
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   362
 * @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
   363
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
   364
{
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   365
	Window* const *wz;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   366
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   367
	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
   368
		Window *v = *wz;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   369
		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
   370
	}
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   371
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   372
	return NULL;
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   373
}
1af12f02bf17 (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5664
diff changeset
   374
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   375
/** Find the z-value of a window. A window must already be open
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   376
 * or the behaviour is undefined but function should never fail
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   377
 * @param w window to query Z Position
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   378
 * @return Pointer into the window-list at the position of \a w
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   379
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   380
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
   381
{
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   382
	Window **wz;
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   383
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   384
	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
   385
		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
   386
	}
5680
b0bae92a1620 (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5667
diff changeset
   387
5838
9c3129cb019b (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5835
diff changeset
   388
	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
   389
		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
   390
	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
   391
}
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   392
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   393
/**
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   394
 * Remove window and all its child windows from the window stack.
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   395
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   396
Window::~Window()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
{
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   398
	if (_thd.place_mode != VHM_NONE &&
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   399
			_thd.window_class == this->window_class &&
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   400
			_thd.window_number == this->window_number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   402
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   404
	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   405
	if (_mouseover_last_w == this) _mouseover_last_w = NULL;
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   406
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   407
	/* Find the window in the z-array, and effectively remove it
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   408
	 * by moving all windows after it one to the left. This must be
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   409
	 * done before removing the child so we cannot cause recursion
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   410
	 * between the deletion of the parent and the child. */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   411
	Window **wz = FindWindowZPosition(this);
5680
b0bae92a1620 (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5667
diff changeset
   412
	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
   413
	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
   414
	_last_z_window--;
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   415
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   416
	/* Delete all children a window might have in a head-recursive manner */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   417
	Window *child = FindChildWindow(this);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   418
	while (child != NULL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   419
		delete child;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   420
		child = FindChildWindow(this);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   421
	}
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   422
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   423
	if (this->viewport != NULL) DeleteWindowViewport(this);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   424
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   425
	this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   426
	free(this->widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   428
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   429
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   430
 * Find a window by its class and window number
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   431
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   432
 * @param number Number of the window within the window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   433
 * @return Pointer to the found window, or \c NULL if not available
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   434
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   435
Window *FindWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   436
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   437
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   438
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   439
	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
   440
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   441
		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
   442
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   443
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   445
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   446
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   447
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   448
 * Delete a window by its class and window number (if it is open).
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   449
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   450
 * @param number Number of the window within the window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   451
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   452
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   454
	delete FindWindowById(cls, number);
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   455
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   457
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   458
 * Delete all windows of a given class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   459
 * @param cls Window class of windows to delete
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   460
 */
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
   461
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
   462
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   463
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   464
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
   465
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
   466
	/* 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
   467
	 * 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
   468
	 * 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
   469
	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
   470
		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
   471
		if (w->window_class == cls) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   472
			delete 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
   473
			goto restart_search;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   474
		}
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
   475
	}
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
   476
}
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
   477
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   478
/** 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
   479
 * 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
   480
 * 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
   481
 * @param id PlayerID player identifier */
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   482
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
   483
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   484
	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
   485
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
   486
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
   487
	/* 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
   488
	 * 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
   489
	 * 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
   490
	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
   491
		Window *w = *wz;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   492
		if (w->caption_color == id) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   493
			delete 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
   494
			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
   495
		}
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
   496
	}
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
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   498
	/* 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
   499
	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
   500
}
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
   501
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   502
/** 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
   503
 * 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
   504
 * 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
   505
 * @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
   506
 * @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
   507
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
   508
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   509
	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
   510
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   511
	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
   512
		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
   513
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   514
		if (w->caption_color != old_player) continue;
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   515
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   516
		switch (w->window_class) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   517
			case WC_PLAYER_COLOR:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   518
			case WC_FINANCES:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   519
			case WC_STATION_LIST:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   520
			case WC_TRAINS_LIST:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   521
			case WC_ROADVEH_LIST:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   522
			case WC_SHIPS_LIST:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   523
			case WC_AIRCRAFT_LIST:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   524
			case WC_BUY_COMPANY:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   525
			case WC_COMPANY:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   526
				continue;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   527
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   528
			default:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   529
				w->caption_color = new_player;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   530
				break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   531
		}
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
   532
	}
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
}
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
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   535
static void BringWindowToFront(const Window *w);
2817
58dcead3f545 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   536
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   537
/** Find a window and make it the top-window on the screen. The window
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   538
 * gets a white border for a brief period of time to visualize its "activation"
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   539
 * @param cls WindowClass of the window to activate
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   540
 * @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
   541
 * @return a pointer to the window thus activated */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   542
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   543
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   544
	Window *w = FindWindowById(cls, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   545
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   546
	if (w != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   547
		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
   548
		BringWindowToFront(w);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   549
		w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   550
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   551
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   552
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   553
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   554
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   555
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
   556
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   557
	switch (w->window_class) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   558
		case WC_MAIN_TOOLBAR:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   559
		case WC_STATUS_BAR:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   560
		case WC_NEWS_WINDOW:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   561
		case WC_SEND_NETWORK_MSG:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   562
			return true;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   563
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   564
		default:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   565
			return false;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   566
	}
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   567
}
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   568
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   569
/** 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
   570
 * 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
   571
 * - 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
   572
 * - 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
   573
 * 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
   574
 * @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
   575
 * @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
   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
static void BringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   578
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   579
	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
   580
	Window **vz = _last_z_window;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   582
	/* Bring the window just below the vital windows */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
	do {
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   584
		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
   585
	} while (IsVitalWindow(*vz));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   586
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   587
	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
   588
	assert(wz < vz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   590
	Window *tempz = *wz;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   591
	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
   592
	*vz = tempz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   593
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   594
	w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   595
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   596
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   597
/** 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
   598
 * 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
   599
 * - 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
   600
 * - 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
   601
 * - 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
   602
 * @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
   603
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   604
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
   605
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   606
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   607
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   608
	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
   609
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   610
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   611
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   612
		}
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
   613
	}
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
	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
   615
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   616
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   617
/** 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
   618
 * 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
   619
 * 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
   620
 * 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
   621
 * @see FindDeletableWindow()
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   622
 * @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
   623
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
   624
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
   625
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   626
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   627
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   628
	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
   629
		Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   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
	}
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
   632
	NOT_REACHED();
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
   633
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   634
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   635
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   636
 * Assign widgets to a new window by initialising its widget pointers, and by
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   637
 * copying the widget array \a widget to \c w->widget to allow for resizable
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   638
 * windows.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   639
 * @param w Window on which to attach the widget array
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   640
 * @param widget pointer of widget array to fill the window with
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   641
 *
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   642
 * @post \c w->widget points to allocated memory and contains the copied widget array except for the terminating widget,
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   643
 *       \c w->widget_count contains number of widgets in the allocated memory.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   644
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   645
static void AssignWidgetToWindow(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
   646
{
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   647
	if (widget != NULL) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   648
		uint index = 1;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   649
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   650
		for (const Widget *wi = widget; wi->type != WWT_LAST; wi++) index++;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   651
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   652
		w->widget = MallocT<Widget>(index);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   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
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   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
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   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
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   661
/**
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   662
 * Initializes a new Window.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   663
 * This function is called the constructors.
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   664
 * 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
   665
 * Only addition here is window_number, which is the window_number being assigned to the new window
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   666
 * @param x offset in pixels from the left of the screen
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   667
 * @param y offset in pixels from the top of the screen
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   668
 * @param min_width minimum width in pixels of the window
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   669
 * @param min_height minimum height in pixels of the window
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   670
 * @param cls see WindowClass class of the window, used for identification and grouping
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   671
 * @param *widget see Widget pointer to the window layout and various elements
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   672
 * @param window_number number being assigned to the new window
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   673
 * @return Window pointer of the newly created window
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   674
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   675
void Window::Initialize(int x, int y, int min_width, int min_height,
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   676
				WindowClass cls, const Widget *widget, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   677
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   678
	/* We have run out of windows, close one and use that as the place for our new one */
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
   679
	if (_last_z_window == endof(_z_windows)) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   680
		Window *w = FindDeletableWindow();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   681
		if (w == NULL) w = ForceFindDeletableWindow();
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   682
		delete w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   683
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   684
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   685
	/* Set up window properties */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   686
	this->window_class = cls;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   687
	this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   688
	this->caption_color = 0xFF;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   689
	this->left = x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   690
	this->top = y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   691
	this->width = min_width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   692
	this->height = min_height;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   693
	AssignWidgetToWindow(this, widget);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   694
	this->resize.width = min_width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   695
	this->resize.height = min_height;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   696
	this->resize.step_width = 1;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   697
	this->resize.step_height = 1;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   698
	this->window_number = window_number;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   699
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   700
	/* Hacky way of specifying always-on-top windows. These windows are
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   701
		* always above other windows because they are moved below them.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   702
		* status-bar is above news-window because it has been created earlier.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   703
		* Also, as the chat-window is excluded from this, it will always be
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   704
		* the last window, thus always on top.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   705
		* XXX - Yes, ugly, probably needs something like w->always_on_top flag
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   706
		* to implement correctly, but even then you need some kind of distinction
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   707
		* between on-top of chat/news and status windows, because these conflict */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   708
	Window **wz = _last_z_window;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   709
	if (wz != _z_windows && this->window_class != WC_SEND_NETWORK_MSG && this->window_class != WC_HIGHSCORE && this->window_class != WC_ENDSCREEN) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   710
		if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   711
		if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   712
		if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   713
		if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   714
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   715
		assert(wz >= _z_windows);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   716
		if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   717
	}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   718
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   719
	*wz = this;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   720
	_last_z_window++;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   721
}
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   722
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   723
/**
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   724
 * Resize window towards the default size.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   725
 * Prior to construction, a position for the new window (for its default size)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   726
 * has been found with LocalGetWindowPlacement(). Initially, the window is
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   727
 * constructed with minimal size. Resizing the window to its default size is
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   728
 * done here.
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   729
 * @param def_width default width in pixels of the window
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   730
 * @param def_height default height in pixels of the window
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   731
 * @see Window::Window(), Window::Initialize()
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   732
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   733
void Window::FindWindowPlacementAndResize(int def_width, int def_height)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   734
{
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   735
	/* Try to make windows smaller when our window is too small.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   736
	 * w->(width|height) is normally the same as min_(width|height),
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   737
	 * but this way the GUIs can be made a little more dynamic;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   738
	 * one can use the same spec for multiple windows and those
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   739
	 * can then determine the real minimum size of the window. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   740
	if (this->width != def_width || this->height != def_height) {
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   741
		/* Think about the overlapping toolbars when determining the minimum window size */
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   742
		int free_height = _screen.height;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   743
		const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   744
		if (wt != NULL) free_height -= wt->height;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   745
		wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   746
		if (wt != NULL) free_height -= wt->height;
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   747
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   748
		int enlarge_x = max(min(def_width  - this->width,  _screen.width - this->width),  0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   749
		int enlarge_y = max(min(def_height - this->height, free_height   - this->height), 0);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   750
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   751
		/* X and Y has to go by step.. calculate it.
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   752
		 * The cast to int is necessary else x/y are implicitly casted to
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   753
		 * unsigned int, which won't work. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   754
		if (this->resize.step_width  > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   755
		if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   756
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   757
		ResizeWindow(this, enlarge_x, enlarge_y);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   758
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   759
		Point size;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   760
		Point diff;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   761
		size.x = this->width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   762
		size.y = this->height;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   763
		diff.x = enlarge_x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   764
		diff.y = enlarge_y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   765
		this->OnResize(size, diff);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   766
	}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   767
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   768
	int nx = this->left;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   769
	int ny = this->top;
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6743
diff changeset
   770
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   771
	if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   772
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   773
	const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   774
	ny = max(ny, (wt == NULL || this == wt || this->top == 0) ? 0 : wt->height);
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6743
diff changeset
   775
	nx = max(nx, 0);
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6743
diff changeset
   776
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   777
	if (this->viewport != NULL) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   778
		this->viewport->left += nx - this->left;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   779
		this->viewport->top  += ny - this->top;
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6743
diff changeset
   780
	}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   781
	this->left = nx;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   782
	this->top = ny;
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   783
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   784
	this->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   785
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   786
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   787
void Window::FindWindowPlacementAndResize(const WindowDesc *desc)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   788
{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   789
	this->FindWindowPlacementAndResize(desc->default_width, desc->default_height);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   790
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   791
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   792
/**
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   793
 * 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
   794
 * 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
   795
 * 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
   796
 * 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
   797
 * @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
   798
 * @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
   799
 * @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
   800
 * @param height height in pixels of the window
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   801
 * @param cls see WindowClass class of the window, used for identification and grouping
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   802
 * @param *widget see Widget pointer to the window layout and various elements
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   803
 * @return Window pointer of the newly created window
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
   804
 */
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   805
Window::Window(int x, int y, int width, int height, WindowClass cls, const Widget *widget)
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   806
{
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
   807
	this->Initialize(x, y, width, height, cls, widget, 0);
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   808
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   809
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   810
/**
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   811
 * Decide whether a given rectangle is a good place to open a completely visible new window.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   812
 * The new window should be within screen borders, and not overlap with another already
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   813
 * existing window (except for the main window in the background).
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   814
 * @param left    Left edge of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   815
 * @param top     Top edge of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   816
 * @param width   Width of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   817
 * @param height  Height of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   818
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   819
 * @return Boolean indication that the rectangle is a good place for the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   820
 */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   821
static bool IsGoodAutoPlace1(int left, int top, int width, int height, Point &pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   822
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   823
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   825
	int right  = width + left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   826
	int bottom = height + top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   828
	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   829
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   830
	/* 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
   831
	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
   832
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   833
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   835
		if (right > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   836
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   837
				bottom > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   838
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   839
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   840
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   841
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   843
	pos.x = left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   844
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   847
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   848
/**
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   849
 * Decide whether a given rectangle is a good place to open a mostly visible new window.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   850
 * The new window should be mostly within screen borders, and not overlap with another already
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   851
 * existing window (except for the main window in the background).
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   852
 * @param left    Left edge of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   853
 * @param top     Top edge of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   854
 * @param width   Width of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   855
 * @param height  Height of the rectangle
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   856
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   857
 * @return Boolean indication that the rectangle is a good place for the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   858
 */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   859
static bool IsGoodAutoPlace2(int left, int top, int width, int height, Point &pos)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   860
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   861
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   862
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   863
	/* Left part of the rectangle may be at most 1/4 off-screen,
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   864
	 * right part of the rectangle may be at most 1/2 off-screen
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   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;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   867
	/* Bottom part of the rectangle may be at most 1/4 off-screen */
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   868
	if (top < 22 || top > _screen.height - (height>>2)) return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   870
	/* 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
   871
	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
   872
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   873
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   874
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   875
		if (left + width > w->left &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   876
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   877
				top + height > w->top &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   878
				w->top + w->height > top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   879
			return false;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   880
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   881
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   882
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   883
	pos.x = left;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   884
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   885
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   886
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   888
/**
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   889
 * Find a good place for opening a new window of a given width and height.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   890
 * @param width  Width of the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   891
 * @param height Height of the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   892
 * @return Top-left coordinate of the new window
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   893
 */
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   894
static Point GetAutoPlacePosition(int width, int height)
90220990fd7c (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   895
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   896
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   897
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   898
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   899
	/* First attempt, try top-left of the screen */
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   900
	if (IsGoodAutoPlace1(0, 24, width, height, pt)) return pt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   901
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   902
	/* Second attempt, try around all existing windows with a distance of 2 pixels.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   903
	 * The new window must be entirely on-screen, and not overlap with an existing window.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   904
	 * Eight starting points are tried, two at each corner.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   905
	 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   906
	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
   907
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   908
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   909
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   910
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   911
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   912
		if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   913
		if (IsGoodAutoPlace1(w->left, w->top - height - 2,    width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   914
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   915
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top + w->height - height, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   916
		if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   917
		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
   918
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   919
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   920
	/* Third attempt, try around all existing windows with a distance of 2 pixels.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   921
	 * The new window may be partly off-screen, and must not overlap with an existing window.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   922
	 * Only four starting points are tried.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   923
	 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   924
	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
   925
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   926
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   928
		if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   929
		if (IsGoodAutoPlace2(w->left - width - 2,    w->top, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   930
		if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt;
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   931
		if (IsGoodAutoPlace2(w->left, w->top - height - 2,    width, height, pt)) return pt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   932
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   933
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   934
	/* Fourth and final attempt, put window at diagonal starting from (0, 24), try multiples
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   935
	 * of (+5, +5)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
   936
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   937
	{
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   938
		int left = 0, top = 24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   939
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
   940
restart:
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   941
		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
   942
			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
   943
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   944
			if (w->left == left && w->top == top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   945
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   946
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   947
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   948
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   949
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   950
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   952
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   953
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   954
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   955
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   956
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   957
/**
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   958
 * Compute the position of the top-left corner of a new window that is opened.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   959
 *
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   960
 * By default position a child window at an offset of 10/10 of its parent.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   961
 * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports)
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   962
 * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   963
 * its parent. So it's exactly under the parent toolbar and no buttons will be covered.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   964
 * However if it falls too extremely outside window positions, reposition
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   965
 * it to an automatic place.
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   966
 *
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   967
 * @param *desc         The pointer to the WindowDesc to be created
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   968
 * @param window_number the window number of the new window
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   969
 *
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   970
 * @return Coordinate of the top-left corner of the new window
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   971
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   972
static Point LocalGetWindowPlacement(const WindowDesc *desc, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   973
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   974
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
5071
14f432b47034 (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   977
	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
   978
			(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
   979
			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
   980
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   981
		pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   982
		if (pt.x > _screen.width + 10 - desc->default_width) {
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   983
			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
   984
		}
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
   985
		pt.y = w->top + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 36 : 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
	} else {
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   987
		switch (desc->left) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   988
			case WDP_ALIGN_TBR: // Align the right side with the top toolbar
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   989
				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
   990
				pt.x = (w->left + w->width) - desc->default_width;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   991
				break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   992
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   993
			case WDP_ALIGN_TBL: // Align the left side with the top toolbar
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   994
				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
   995
				break;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   996
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   997
			case WDP_AUTO: // Find a good automatic position for the window
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   998
				return GetAutoPlacePosition(desc->default_width, desc->default_height);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
   999
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1000
			case WDP_CENTER: // Centre the window horizontally
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  1001
				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
  1002
				break;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1003
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1004
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1005
				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
  1006
				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
  1007
		}
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1008
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1009
		switch (desc->top) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1010
			case WDP_CENTER: // Centre the window vertically
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  1011
				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
  1012
				break;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1013
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1014
			/* 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
  1015
			 * 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
  1016
			case WDP_AUTO:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1017
				NOT_REACHED();
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1018
				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
  1019
				/* fallthrough */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1020
5072
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1021
			default:
df5bde83a4bc (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1022
				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
  1023
				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
  1024
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1025
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1026
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1027
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1028
	return pt;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1030
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1031
/**
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1032
 * Set the positions of a new window from a WindowDesc and open it.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1033
 *
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1034
 * @param *desc         The pointer to the WindowDesc to be created
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1035
 * @param window_number the window number of the new window
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1036
 *
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1037
 * @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
  1038
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1039
Window::Window(const WindowDesc *desc, WindowNumber window_number)
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1040
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1041
	Point pt = LocalGetWindowPlacement(desc, window_number);
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1042
	this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->cls, desc->widgets, window_number);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1043
	this->desc_flags = desc->flags;
4520
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1044
}
d5f94a18a68c (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1045
5120
e12dfc67761f (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1046
/** 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
  1047
 * at the topmost window, obviously and work our way down to the bottom
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1048
 * @param x position x to query
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1049
 * @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
  1050
 * @return a pointer to the found window if any, NULL otherwise */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1051
Window *FindWindowFromPt(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
{
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1053
	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
  1054
		Window *w = *--wz;
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1055
		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1056
			return w;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1057
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1063
/**
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1064
 * (re)initialize the windowing system
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1065
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1066
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
  1067
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
  1068
	IConsoleClose();
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1069
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1070
	_last_z_window = _z_windows;
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1071
	_mouseover_last_w = NULL;
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
  1072
	_no_scroll = 0;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1073
	_scrolling_viewport = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1074
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1076
/**
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1077
 * Close down the windowing system
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1078
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1079
void UnInitWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1080
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1081
	while (_last_z_window != _z_windows) delete _z_windows[0];
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
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1084
/**
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1085
 * Reset the windowing system, by means of shutting it down followed by re-initialization
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1086
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1087
void ResetWindowSystem()
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1088
{
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1089
	UnInitWindowSystem();
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1090
	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
  1091
	_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
  1092
	_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
  1093
	_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
  1094
	_thd.new_pos.y = 0;
1474
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1095
}
d83520edcda6 (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1096
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1097
static void DecreaseWindowCounters()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  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
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1101
	for (wz = _last_z_window; wz != _z_windows;) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1102
		Window *w = *--wz;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1103
		/* Unclick scrollbar buttons if they are pressed. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1106
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
		}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1108
		w->OnMouseLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1111
	for (wz = _last_z_window; wz != _z_windows;) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1112
		Window *w = *--wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1113
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1114
		if (w->flags4 & WF_TIMEOUT_MASK && !(--w->flags4 & WF_TIMEOUT_MASK)) {
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1115
			w->OnTimeout();
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1116
			if (w->desc_flags & WDF_UNCLICK_BUTTONS) w->RaiseButtons();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1118
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1121
Window *GetCallbackWnd()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1122
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1123
	return FindWindowById(_thd.window_class, _thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1126
static void HandlePlacePresize()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1128
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1129
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1130
	Window *w = GetCallbackWnd();
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1131
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1132
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1133
	Point pt = GetTileBelowCursor();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1134
	if (pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1135
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1136
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1138
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1139
	w->OnPlacePresize(pt, TileVirtXY(pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1142
static bool HandleDragDrop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
{
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1144
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1145
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1146
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1147
	Window *w = GetCallbackWnd();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1148
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1149
	if (w != NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1150
		/* send an event in client coordinates. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1151
		Point pt;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1152
		pt.x = _cursor.pos.x - w->left;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1153
		pt.y = _cursor.pos.y - w->top;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1154
		w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1155
	}
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1156
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1157
	ResetObjectToPlace();
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1158
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1161
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1162
static bool HandleMouseOver()
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1163
{
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1164
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1165
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1166
	/* We changed window, put a MOUSEOVER event to the last window */
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1167
	if (_mouseover_last_w != NULL && _mouseover_last_w != w) {
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1168
		/* Reset mouse-over coordinates of previous window */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1169
		Point pt = { -1, -1 };
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1170
		_mouseover_last_w->OnMouseOver(pt, 0);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1171
	}
10210
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1172
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1173
	/* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
a2131f7a315d (svn r12742) [NewGRF_ports] -Sync: with trunk r12673:12705.
richk
parents: 10184
diff changeset
  1174
	_mouseover_last_w = w;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1175
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1176
	if (w != NULL) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1177
		/* send an event in client coordinates. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1178
		Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1179
		int widget = 0;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1180
		if (w->widget != NULL) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1181
			widget = GetWidgetFromPos(w, pt.x, pt.y);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1182
		}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1183
		w->OnMouseOver(pt, widget);
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1184
	}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1185
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1186
	/* Mouseover never stops execution */
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1187
	return true;
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1188
}
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1189
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1190
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1191
 * Resize the window.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1192
 * 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
  1193
 * 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
  1194
 * ensuring proper redrawal.
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1195
 * @param w Window to resize
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1196
 * @param x delta x-size of changed window (positive if larger, etc.)
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1197
 * @param y delta y-size of changed window
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1198
 */
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1199
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
  1200
{
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1201
	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
  1202
	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
  1203
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1204
	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
  1205
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1206
	w->SetDirty();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1207
	for (Widget *wi = w->widget; wi->type != WWT_LAST; wi++) {
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1208
		/* 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
  1209
		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
  1210
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1211
		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
  1212
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1213
		/* 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
  1214
		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
  1215
			wi->left += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1216
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1217
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1218
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1219
		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
  1220
			wi->right += x;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1221
			resize_width = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1222
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1223
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1224
		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
  1225
			wi->top += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1226
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1227
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1228
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1229
		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
  1230
			wi->bottom += y;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1231
			resize_height = true;
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1232
		}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1233
	}
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1234
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1235
	/* 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
  1236
	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
  1237
	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
  1238
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1239
	w->SetDirty();
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1240
}
2596
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1241
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1242
static bool _dragging_window;
d228e8ce6fcf (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1243
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1244
static bool HandleWindowDragging()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1245
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1246
	Window* const *wz;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1247
	/* Get out immediately if no window is being dragged at all. */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1248
	if (!_dragging_window) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1249
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1250
	/* 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
  1251
	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
  1252
		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
  1253
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1254
		if (w->flags4 & WF_DRAGGING) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1255
			const Widget *t = &w->widget[1]; // the title bar ... ugh
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1256
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1257
			/* Stop the dragging if the left mouse button was released */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
			if (!_left_button_down) {
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1259
				w->flags4 &= ~WF_DRAGGING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1260
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1262
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1263
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1264
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1265
			int x = _cursor.pos.x + _drag_delta.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1266
			int y = _cursor.pos.y + _drag_delta.y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1267
			int nx = x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1268
			int ny = y;
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1269
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1270
			if (_settings_client.gui.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
  1271
				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
  1272
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1273
				int hsnap = _settings_client.gui.window_snap_radius;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1274
				int vsnap = _settings_client.gui.window_snap_radius;
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1275
				int delta;
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1276
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1277
				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
  1278
					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
  1279
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1280
					if (v == w) continue; // Don't snap at yourself
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1281
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1282
					if (y + w->height > v->top && y < v->top + v->height) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1283
						/* Your left border <-> other right border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1284
						delta = abs(v->left + v->width - x);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1285
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1286
							nx = v->left + v->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1287
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1288
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1289
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1290
						/* Your right border <-> other left border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1291
						delta = abs(v->left - x - w->width);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1292
						if (delta <= hsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1293
							nx = v->left - w->width;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1294
							hsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1295
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1296
					}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1297
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1298
					if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1299
						/* Your left border <-> other left border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1300
						delta = abs(v->left - x);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1301
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1302
							nx = v->left;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1303
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1304
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1305
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1306
						/* Your right border <-> other right border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1307
						delta = abs(v->left + v->width - x - w->width);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1308
						if (delta <= hsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1309
							nx = v->left + v->width - w->width;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1310
							hsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1311
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1312
					}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1313
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1314
					if (x + w->width > v->left && x < v->left + v->width) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1315
						/* Your top border <-> other bottom border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1316
						delta = abs(v->top + v->height - y);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1317
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1318
							ny = v->top + v->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1319
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1320
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1321
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1322
						/* Your bottom border <-> other top border */
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1323
						delta = abs(v->top - y - w->height);
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1324
						if (delta <= vsnap) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1325
							ny = v->top - w->height;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1326
							vsnap = delta;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1327
						}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1328
					}
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1329
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1330
					if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1331
						/* Your top border <-> other top border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1332
						delta = abs(v->top - y);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1333
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1334
							ny = v->top;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1335
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1336
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1337
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1338
						/* Your bottom border <-> other bottom border */
353
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1339
						delta = abs(v->top + v->height - y - w->height);
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1340
						if (delta <= vsnap) {
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1341
							ny = v->top + v->height - w->height;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1342
							vsnap = delta;
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1343
						}
a4f288d6d7ab (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1344
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1345
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1346
			}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1347
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1348
			/* Make sure the window doesn't leave the screen
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1349
			 * 13 is the height of the title bar */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1350
			nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1351
			ny = Clamp(ny, 0, _screen.height - 13);
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1352
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1353
			/* Make sure the title bar isn't hidden by behind the main tool bar */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1354
			Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1355
			if (v != NULL) {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1356
				int v_bottom = v->top + v->height;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1357
				int v_right = v->left + v->width;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1358
				if (ny + t->top >= v->top && ny + t->top < v_bottom) {
371
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1359
					if ((v->left < 13 && nx + t->left < v->left) ||
bcbc6fb59c26 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1360
							(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
  1361
						ny = v_bottom;
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1362
					} else {
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1363
						if (nx + t->left > v->left - 13 &&
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1364
								nx + t->right < v_right + 13) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1365
							if (w->top >= v_bottom) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1366
								ny = v_bottom;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1367
							} else if (w->left < nx) {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1368
								nx = v->left - 13 - t->left;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1369
							} else {
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1370
								nx = v_right + 13 - t->right;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1371
							}
370
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1372
						}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1373
					}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1374
				}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1375
			}
687b13abdf0c (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1376
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1377
			if (w->viewport != NULL) {
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1378
				w->viewport->left += nx - w->left;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1379
				w->viewport->top  += ny - w->top;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1380
			}
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1381
			w->left = nx;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1382
			w->top  = ny;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1383
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1384
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1385
			return false;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1386
		} 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
  1387
			int x, y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1388
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1389
			/* 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
  1390
			if (!_left_button_down) {
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1391
				w->flags4 &= ~WF_SIZING;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1392
				w->SetDirty();
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1393
				break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1394
			}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1395
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1396
			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
  1397
			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
  1398
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1399
			/* 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
  1400
			 * 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
  1401
			 * unsigned int, which won't work. */
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1402
			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
  1403
2675
269c38d892f9 (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1404
			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
  1405
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1406
			/* 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
  1407
			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
  1408
				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
  1409
			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
  1410
				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
  1411
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1412
			/* Window already on size */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1413
			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
  1414
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1415
			/* 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
  1416
			    we move in steps. */
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1417
			_drag_delta.x += x;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1418
			_drag_delta.y += y;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1419
5268
cbff87066429 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1420
			/* 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
  1421
			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
  1422
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1423
			Point size;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1424
			Point diff;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1425
			size.x = x + w->width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1426
			size.y = y + w->height;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1427
			diff.x = x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1428
			diff.y = y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1429
			w->OnResize(size, diff);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1430
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1431
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1432
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1434
	_dragging_window = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1438
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1439
 * Start window dragging
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1440
 * @param w Window to start dragging
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1441
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1442
static void StartWindowDrag(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1444
	w->flags4 |= WF_DRAGGING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1445
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1446
350
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1447
	_drag_delta.x = w->left - _cursor.pos.x;
67a59a1226b5 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1448
	_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
  1449
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1450
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1452
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1454
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1455
 * Start resizing a window
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1456
 * @param w Window to start resizing
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1457
 */
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1458
static void StartWindowSizing(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1459
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	w->flags4 |= WF_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
	_dragging_window = true;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1462
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1463
	_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
  1464
	_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
  1465
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1466
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1468
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1471
static bool HandleScrollbarScrolling()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1472
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1473
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1475
	/* Get out quickly if no item is being scrolled */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1476
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1478
	/* 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
  1479
	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
  1480
		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
  1481
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1482
		if (w->flags4 & WF_SCROLL_MIDDLE) {
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1483
			/* Abort if no button is clicked any more. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1484
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
				w->flags4 &= ~WF_SCROLL_MIDDLE;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1486
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1488
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1489
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1490
			int i;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1491
			Scrollbar *sb;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1492
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1496
			} else if (w->flags4 & WF_SCROLL2){
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1497
				sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1498
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1499
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1500
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1504
			/* Find the item we want to move to and make sure it's inside bounds. */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1505
			int pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1506
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1507
				sb->pos = pos;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1508
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1511
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1513
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1515
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1517
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1518
static bool HandleViewportScroll()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1520
	bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1521
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1522
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1523
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1524
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
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
  1525
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1526
	if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
		_cursor.fix_at = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
		_scrolling_viewport = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
		return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1530
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1531
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1532
	if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) {
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1533
		/* If the main window is following a vehicle, then first let go of it! */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1534
		const Vehicle *veh = GetVehicle(w->viewport->follow_vehicle);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1535
		ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1536
		return true;
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1537
	}
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1538
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1539
	Point delta;
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1540
	if (_settings_client.gui.reverse_scroll) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1541
		delta.x = -_cursor.delta.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1542
		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
  1543
	} else {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1544
		delta.x = _cursor.delta.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1545
		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
  1546
	}
576d9d47df80 (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1547
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1548
	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
  1549
		/* We are using scrollwheels for scrolling */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1550
		delta.x = _cursor.h_wheel;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1551
		delta.y = _cursor.v_wheel;
6615
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1552
		_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
  1553
		_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
  1554
	}
96d30d65ed35 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6574
diff changeset
  1555
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
  1556
	/* Create a scroll-event and send it to the window */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1557
	w->OnScroll(delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1559
	_cursor.delta.x = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1560
	_cursor.delta.y = 0;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1561
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1562
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1564
/** 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
  1565
 * 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
  1566
 * 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
  1567
 * 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
  1568
 * 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
  1569
 * 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
  1570
 * @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
  1571
 * @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
  1572
static bool MaybeBringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1573
{
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1574
	bool bring_to_front = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1575
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1576
	if (w->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1577
			IsVitalWindow(w) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1578
			w->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1579
			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
  1580
		return true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1581
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1582
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1583
	Window * const *wz = FindWindowZPosition(w);
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1584
	for (Window * const *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
  1585
		Window *u = *uz;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1586
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1587
		/* 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
  1588
		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
  1589
			u->flags4 |= WF_WHITE_BORDER_MASK;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1590
			u->SetDirty();
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1591
			return false;
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1592
		}
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1593
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1594
		if (u->window_class == WC_MAIN_WINDOW ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1595
				IsVitalWindow(u) ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1596
				u->window_class == WC_TOOLTIPS ||
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1597
				u->window_class == WC_DROPDOWN_MENU) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1598
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1599
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1601
		/* Window sizes don't interfere, leave z-order alone */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1602
		if (w->left + w->width <= u->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1603
				u->left + u->width <= w->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
				w->top  + w->height <= u->top ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1605
				u->top + u->height <= w->top) {
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1606
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1607
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1608
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1609
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1610
	}
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1611
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1612
	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
  1613
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1614
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1616
/** Handle keyboard input.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1617
 * @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1618
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1619
void HandleKeypress(uint32 raw_key)
1648
747061dca705 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1620
{
4549
60410aa1aa88 (svn r6381) -Cleanup: make the '/* */' comments that span multiple lines more uniform.
rubidium
parents: 4520
diff changeset
  1621
	/* 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
  1622
	 * 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
  1623
	 * 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
  1624
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1625
5086
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1626
	/*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1627
	* 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
  1628
	* 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
  1629
	* 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
  1630
	* 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
  1631
	*
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1632
	* 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
  1633
	* 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
  1634
	*/
99e0b202b9fb (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1635
	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
  1636
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1637
	/* Setup event */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1638
	uint16 key     = GB(raw_key,  0, 16);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1639
	uint16 keycode = GB(raw_key, 16, 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1640
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1641
	/*
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1642
	 * The Unicode standard defines an area called the private use area. Code points in this
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1643
	 * area are reserved for private use and thus not portable between systems. For instance,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1644
	 * Apple defines code points for the arrow keys in this area, but these are only printable
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1645
	 * on a system running OS X. We don't want these keys to show up in text fields and such,
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1646
	 * and thus we have to clear the unicode character when we encounter such a key.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1647
	 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1648
	if (key >= 0xE000 && key <= 0xF8FF) key = 0;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1649
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1650
	/*
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1651
	 * If both key and keycode is zero, we don't bother to process the event.
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1652
	 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1653
	if (key == 0 && keycode == 0) return;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  1654
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1655
	/* check if we have a query string window open before allowing hotkeys */
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1656
	if (FindWindowById(WC_QUERY_STRING,            0) != NULL ||
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1657
			FindWindowById(WC_SEND_NETWORK_MSG,        0) != NULL ||
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1658
			FindWindowById(WC_GENERATE_LANDSCAPE,      0) != NULL ||
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1659
			FindWindowById(WC_CONSOLE,                 0) != NULL ||
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1660
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1661
			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
  1662
		query_open = true;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1663
	}
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
  1664
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1665
	/* Call the event, start with the uppermost window. */
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1666
	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
  1667
		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
  1668
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1669
		/* if a query window is open, only call the event for certain window types */
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1670
		if (query_open &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1671
				w->window_class != WC_QUERY_STRING &&
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1672
				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
  1673
				w->window_class != WC_GENERATE_LANDSCAPE &&
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1674
				w->window_class != WC_CONSOLE &&
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1675
				w->window_class != WC_SAVELOAD &&
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1676
				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
  1677
			continue;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1678
		}
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1679
		if (w->OnKeyPress(key, keycode) == Window::ES_HANDLED) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1680
	}
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
  1681
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1682
	Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1683
	/* When there is no toolbar w is null, check for that */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1684
	if (w != NULL) w->OnKeyPress(key, keycode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1685
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1686
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1687
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1688
 * State of CONTROL key has changed
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1689
 */
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1690
void HandleCtrlChanged()
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1691
{
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1692
	/* Call the event, start with the uppermost window. */
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1693
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1694
		Window *w = *--wz;
10731
67db0d431d5e (svn r13281) [NewGRF_ports] -Sync: with trunk r13145:13280. Includes support for Noise Level on Prop 24 in .grf files.
richk
parents: 10724
diff changeset
  1695
		if (w->OnCTRLStateChange() == Window::ES_HANDLED) return;
6878
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1696
	}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1697
}
7d1ff2f621c7 (svn r12351) [NewGRF_ports] -Sync: with trunk r12051:12350.
richk
parents: 6872
diff changeset
  1698
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1699
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1700
 * Local counter that is incremented each time an mouse input event is detected.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1701
 * The counter is used to stop auto-scrolling.
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1702
 * @see HandleAutoscroll()
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1703
 * @see HandleMouseEvents()
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1704
 */
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1705
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
  1706
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1707
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1708
 * If needed and switched on, perform auto scrolling (automatically
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1709
 * moving window contents when mouse is near edge of the window).
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1710
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1711
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
  1712
{
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1713
	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
  1714
		/* 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
  1715
		_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
  1716
		/* 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
  1717
		return;
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1718
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1719
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1720
	if (_settings_client.gui.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1721
		int x = _cursor.pos.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1722
		int y = _cursor.pos.y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1723
		Window *w = FindWindowFromPt(x, y);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1724
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1725
		ViewPort *vp = IsPtInWindowViewport(w, x, y);
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1726
		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
  1727
			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
  1728
			y -= vp->top;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1729
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1730
			/* 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
  1731
#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
  1732
			if (x - 15 < 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1733
				w->viewport->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
  1734
			} else if (15 - (vp->width - x) > 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1735
				w->viewport->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
  1736
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1737
			if (y - 15 < 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1738
				w->viewport->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
  1739
			} else if (15 - (vp->height - y) > 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1740
				w->viewport->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
  1741
			}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1742
#undef scrollspeed
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1743
		}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1744
	}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1745
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1746
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1747
enum MouseClick {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1748
	MC_NONE = 0,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1749
	MC_LEFT,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1750
	MC_RIGHT,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1751
	MC_DOUBLE_LEFT,
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1752
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1753
	MAX_OFFSET_DOUBLE_CLICK = 5,     ///< How much the mouse is allowed to move to call it a double click
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1754
	TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1755
};
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1756
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1757
extern void UpdateTileSelection();
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1758
extern bool VpHandlePlaceSizingDrag();
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1759
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1760
static void ScrollMainViewport(int x, int y)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1761
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1762
	if (_game_mode != GM_MENU) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1763
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1764
		assert(w);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1765
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1766
		w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1767
		w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1768
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1769
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1770
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1771
/**
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1772
 * Describes all the different arrow key combinations the game allows
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1773
 * when it is in scrolling mode.
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1774
 * The real arrow keys are bitwise numbered as
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1775
 * 1 = left
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1776
 * 2 = up
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1777
 * 4 = right
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1778
 * 8 = down
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1779
 */
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1780
static const int8 scrollamt[16][2] = {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1781
	{ 0,  0}, ///<  no key specified
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1782
	{-2,  0}, ///<  1 : left
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1783
	{ 0, -2}, ///<  2 : up
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1784
	{-2, -1}, ///<  3 : left  + up
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1785
	{ 2,  0}, ///<  4 : right
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1786
	{ 0,  0}, ///<  5 : left  + right = nothing
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1787
	{ 2, -1}, ///<  6 : right + up
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1788
	{ 0, -2}, ///<  7 : right + left  + up = up
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1789
	{ 0  ,2}, ///<  8 : down
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1790
	{-2  ,1}, ///<  9 : down  + left
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1791
	{ 0,  0}, ///< 10 : down  + up    = nothing
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1792
	{-2,  0}, ///< 11 : left  + up    +  down = left
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1793
	{ 2,  1}, ///< 12 : down  + right
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1794
	{ 0,  2}, ///< 13 : left  + right +  down = down
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1795
	{ 2,  0}, ///< 14 : right + up    +  down = right
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1796
	{ 0,  0}, ///< 15 : left  + up    +  right + down  = nothing
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1797
};
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1798
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1799
static void HandleKeyScrolling()
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1800
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1801
	if (_dirkeys && !_no_scroll) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1802
		int factor = _shift_pressed ? 50 : 10;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1803
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1804
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1805
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1806
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1807
void MouseLoop(MouseClick click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1808
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1809
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
	UpdateTileSelection();
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1812
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1813
	if (!VpHandlePlaceSizingDrag())  return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1814
	if (!HandleDragDrop())           return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1815
	if (!HandleWindowDragging())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1816
	if (!HandleScrollbarScrolling()) return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1817
	if (!HandleViewportScroll())     return;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1818
	if (!HandleMouseOver())          return;
543
e3b43338096b (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1819
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1820
	bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1821
	if (click == MC_NONE && mousewheel == 0 && !scrollwheel_scrolling) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1822
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1823
	int x = _cursor.pos.x;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1824
	int y = _cursor.pos.y;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1825
	Window *w = FindWindowFromPt(x, y);
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1826
	if (w == NULL) return;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1827
5667
248a3234d2e2 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5666
diff changeset
  1828
	if (!MaybeBringWindowToFront(w)) return;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1829
	ViewPort *vp = IsPtInWindowViewport(w, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1830
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
  1831
	/* 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
  1832
	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
  1833
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
  1834
	if (mousewheel != 0) {
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  1835
		if (_settings_client.gui.scrollwheel_scrolling == 0) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1836
			/* Send mousewheel event to window */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1837
			w->OnMouseWheel(mousewheel);
6622
2ce7ffa9db00 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6616
diff changeset
  1838
		}
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
  1839
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1840
		/* 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
  1841
		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
  1842
	}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1843
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1844
	if (vp != NULL) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1845
		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
  1846
		switch (click) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1847
			case MC_DOUBLE_LEFT:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1848
			case MC_LEFT:
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1849
				DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1850
				if (_thd.place_mode != VHM_NONE &&
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1851
						/* 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
  1852
						_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
  1853
						_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
  1854
						_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
  1855
						!_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
  1856
					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
  1857
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1858
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  1859
				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
  1860
					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
  1861
				} 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
  1862
					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
  1863
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1864
				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
  1865
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1866
			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
  1867
				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
  1868
					_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
  1869
					_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
  1870
				}
f77887bd2634 (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1871
				break;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1872
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1873
			default:
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1874
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1875
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1876
	} else {
2631
13daba67f217 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1877
		switch (click) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1878
			case MC_DOUBLE_LEFT:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1879
				DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1880
				if (_mouseover_last_w == NULL) break; // The window got removed.
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1881
				/* fallthough, and also give a single-click for backwards compatibility */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1882
			case MC_LEFT:
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1883
				DispatchLeftClickEvent(w, x - w->left, y - w->top, false);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1884
				break;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1885
6616
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1886
			default:
fb4513362b7f (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6615
diff changeset
  1887
				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
  1888
				/* 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
  1889
				* 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
  1890
				/* fallthough */
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1891
			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
  1892
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1893
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1895
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1896
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1897
 * Handle a mouse event from the video driver
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1898
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1899
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
  1900
{
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1901
	static int double_click_time = 0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1902
	static int double_click_x = 0;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1903
	static int double_click_y = 0;
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
  1904
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1905
	/*
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1906
	 * 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
  1907
	 * 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
  1908
	 * 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
  1909
	 * NOT change the _current_player here.
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1910
	 *
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1911
	 * 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
  1912
	 * 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
  1913
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1914
	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
  1915
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1916
	/* Mouse event? */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1917
	MouseClick 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
  1918
	if (_left_button_down && !_left_button_clicked) {
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1919
		click = MC_LEFT;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1920
		if (double_click_time != 0 && _realtime_tick - double_click_time   < TIME_BETWEEN_DOUBLE_CLICK &&
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1921
			  double_click_x != 0    && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK  &&
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1922
			  double_click_y != 0    && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) {
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1923
			click = MC_DOUBLE_LEFT;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1924
		}
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1925
		double_click_time = _realtime_tick;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1926
		double_click_x = _cursor.pos.x;
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1927
		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
  1928
		_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
  1929
		_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
  1930
	} 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
  1931
		_right_button_clicked = false;
6720
35756db7e577 (svn r10560) [NewGRF_ports] -Sync: with trunk r10027-10559
richk
parents: 6719
diff changeset
  1932
		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
  1933
		_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
  1934
	}
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
  1935
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1936
	int mousewheel = 0;
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
  1937
	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
  1938
		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
  1939
		_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
  1940
		_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
  1941
	}
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
  1942
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
  1943
	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
  1944
}
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
  1945
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1946
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1947
 * Regular call from the global game loop
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1948
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1949
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
  1950
{
10994
cd9968b6f96b (svn r13548) [NewGRF_ports] -Sync: with trunk r13412:13544.
richk
parents: 10991
diff changeset
  1951
	HandleKeyScrolling();
5090
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1952
	HandleMouseEvents();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1953
	HandleAutoscroll();
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1954
}
8907f67c2c15 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1955
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1956
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1957
 * Update the continuously changing contents of the windows, such as the viewports
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1958
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  1959
void UpdateWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1960
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1961
	Window* const *wz;
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1962
	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
  1963
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1964
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1965
	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
  1966
		for (wz = _last_z_window; wz != _z_windows;) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1967
			(*--wz)->OnHundredthTick();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1968
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1969
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1970
	}
5089
9d290a04d79c (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1971
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1972
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1973
	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
  1974
		Window *w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1975
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1976
			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
  1977
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  1978
			if (!(w->flags4 & WF_WHITE_BORDER_MASK)) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1979
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1980
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1981
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1982
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1984
	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
  1985
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1986
	}
6868
7eb395287b3d (svn r11037) [NewGRF_ports] -Sync: with trunk r10844:11035.
rubidium
parents: 6743
diff changeset
  1987
	DrawChatMessage();
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  1988
	/* Redraw mouse cursor in case it was hidden */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1989
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1990
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1992
/**
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1993
 * Mark window as dirty (in need of repainting)
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1994
 * @param cls Window class
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  1995
 * @param number Window number in that class
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  1996
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1997
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1998
{
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
  1999
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2000
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2001
	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
  2002
		const Window *w = *wz;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2003
		if (w->window_class == cls && w->window_number == number) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2007
/**
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2008
 * Mark a particular widget in a particular window as dirty (in need of repainting)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2009
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2010
 * @param number Window number in that class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2011
 * @param widget_index Index number of the widget that needs repainting
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2012
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2013
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
{
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
  2015
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2017
	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
  2018
		const Window *w = *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2019
		if (w->window_class == cls && w->window_number == number) {
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2020
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2021
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2022
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2023
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2024
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2025
/**
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2026
 * Mark all windows of a particular class as dirty (in need of repainting)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2027
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2028
 */
2788
db2896482939 (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2029
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2030
{
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
  2031
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2032
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2033
	FOR_ALL_WINDOWS(wz) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2034
		if ((*wz)->window_class == cls) (*wz)->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2035
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2036
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2037
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2038
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2039
 * Mark window data as invalid (in need of re-computing)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2040
 * @param w Window with invalid data
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2041
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2042
void InvalidateThisWindowData(Window *w, int data)
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
  2043
{
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2044
	w->OnInvalidateData(data);
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2045
	w->SetDirty();
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
  2046
}
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
  2047
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2048
/**
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2049
 * Mark window data of the window of a given class and specific window number as invalid (in need of re-computing)
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2050
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2051
 * @param number Window number within the class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2052
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2053
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data)
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2054
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2055
	Window* const *wz;
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2056
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2057
	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
  2058
		Window *w = *wz;
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2059
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w, data);
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
  2060
	}
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
  2061
}
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
  2062
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2063
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2064
 * Mark window data of all windows of a given class as invalid (in need of re-computing)
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2065
 * @param cls Window class
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2066
 */
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2067
void InvalidateWindowClassesData(WindowClass cls, int data)
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
  2068
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2069
	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
  2070
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2071
	FOR_ALL_WINDOWS(wz) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2072
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz, data);
4739
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2073
	}
bd535b408617 (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2074
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2076
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2077
 * Dispatch WE_TICK event over all windows
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2078
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2079
void CallWindowTickEvent()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
{
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2081
	if (_scroller_click_timeout > 3) {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2082
		_scroller_click_timeout -= 3;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2083
	} else {
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2084
		_scroller_click_timeout = 0;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2085
	}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2086
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2087
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2088
		(*--wz)->OnTick();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2089
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2090
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2091
10274
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2092
/**
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2093
 * Try to delete a non-vital window.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2094
 * Non-vital windows are windows other than the game selection, main toolbar,
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2095
 * status bar, toolbar menu, and tooltip windows. Stickied windows are also
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2096
 * considered vital.
b3c58f3df92b (svn r12806) [NewGRF_ports] -Sync: with trunk r12773:12805.
richk
parents: 10242
diff changeset
  2097
 */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2098
void DeleteNonVitalWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2099
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2100
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2101
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
  2102
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
  2103
	/* 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
  2104
	 * 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
  2105
	 * 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
  2106
	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
  2107
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2108
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2109
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2110
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2111
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2112
				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
  2113
				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
  2114
				(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
  2115
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2116
			delete 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
  2117
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2118
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2119
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2120
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2121
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  2122
/** 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
  2123
 * '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
  2124
 * 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
  2125
 * 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
  2126
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2127
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
  2128
{
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2129
	Window* const *wz;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2130
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
  2131
	/* 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
  2132
	DeleteNonVitalWindows();
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2133
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
  2134
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
  2135
	/* 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
  2136
	 * 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
  2137
	 * 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
  2138
	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
  2139
		if ((*wz)->flags4 & WF_STICKY) {
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2140
			delete *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
  2141
			goto restart_search;
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2142
		}
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
  2143
	}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2144
}
8ff348acf75e (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2145
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  2146
/** Delete all always on-top windows to get an empty screen */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6557
diff changeset
  2147
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
  2148
{
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
  2149
	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
  2150
	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
  2151
	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
  2152
}
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
  2153
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2154
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2155
 * (Re)position main toolbar window at the screen
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2156
 * @param w Window structure of the main toolbar window, may also be \c NULL
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2157
 * @return X coordinate of left edge of the repositioned toolbar window
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2158
 */
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2159
int PositionMainToolbar(Window *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2160
{
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2161
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2162
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2163
	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
  2164
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
4077
d3022f976946 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2165
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2166
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2167
	switch (_settings_client.gui.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
  2168
		case 1:  w->left = (_screen.width - w->width) / 2; break;
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2169
		case 2:  w->left = _screen.width - w->width; break;
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2170
		default: w->left = 0;
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2171
	}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2172
	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
  2173
	return w->left;
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2174
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2175
10991
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2176
void SetVScrollCount(Window *w, int num)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2177
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2178
	w->vscroll.count = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2179
	num -= w->vscroll.cap;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2180
	if (num < 0) num = 0;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2181
	if (num < w->vscroll.pos) w->vscroll.pos = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2182
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2183
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2184
void SetVScroll2Count(Window *w, int num)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2185
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2186
	w->vscroll2.count = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2187
	num -= w->vscroll2.cap;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2188
	if (num < 0) num = 0;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2189
	if (num < w->vscroll2.pos) w->vscroll2.pos = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2190
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2191
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2192
void SetHScrollCount(Window *w, int num)
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2193
{
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2194
	w->hscroll.count = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2195
	num -= w->hscroll.cap;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2196
	if (num < 0) num = 0;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2197
	if (num < w->hscroll.pos) w->hscroll.pos = num;
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2198
}
d8811e327d12 (svn r13545) [NewGRF_ports] -Sync: with trunk r13281:13411.
richk
parents: 10731
diff changeset
  2199
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2200
/**
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2201
 * Relocate all windows to fit the new size of the game application screen
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2202
 * @param neww New width of the game application screen
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2203
 * @param newh New height of the game appliction screen
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2204
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2205
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2208
5124
d30772d0e9e1 (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2209
	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
  2210
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2211
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2212
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2213
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2214
			ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2215
			vp->width = w->width = neww;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2216
			vp->height = w->height = newh;
6719
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  2217
			vp->virtual_width = ScaleByZoom(neww, vp->zoom);
4cc327ad39d5 (svn r10027) [NewGRF_ports] -Sync: with trunk r9506-10026
richk
parents: 6622
diff changeset
  2218
			vp->virtual_height = ScaleByZoom(newh, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2219
			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
  2220
		}
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
  2221
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2222
		/* 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
  2223
		 * in a 'backup'-desc that the window should always be centred. */
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2224
		switch (w->window_class) {
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2225
			case WC_MAIN_TOOLBAR:
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  2226
				if (neww - w->width != 0) {
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  2227
					ResizeWindow(w, min(neww, 640) - w->width, 0);
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  2228
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2229
					Point size;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2230
					Point delta;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2231
					size.x = w->width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2232
					size.y = w->height;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2233
					delta.x = neww - w->width;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2234
					delta.y = 0;
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2235
					w->OnResize(size, delta);
6743
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  2236
				}
cabfaa4a0295 (svn r10766) [NewGRF_ports] -Sync: with trunk r10651-10765
richk
parents: 6732
diff changeset
  2237
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2238
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2239
				left = PositionMainToolbar(w); // changes toolbar orientation
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2240
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2241
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2242
			case WC_SELECT_GAME:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2243
			case WC_GAME_OPTIONS:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2244
			case WC_NETWORK_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2245
				top = (newh - w->height) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2246
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2247
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2248
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2249
			case WC_NEWS_WINDOW:
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2250
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2251
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2252
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2253
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2254
			case WC_STATUS_BAR:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  2255
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2256
				top = newh - w->height;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2257
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2258
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2259
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2260
			case WC_SEND_NETWORK_MSG:
6871
5a9dc001e1ad (svn r11566) [NewGRF_ports] -Sync: with trunk r11218:r11565.
rubidium
parents: 6868
diff changeset
  2261
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2262
				top = (newh - 26); // 26 = height of status bar + height of chat bar
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2263
				left = (neww - w->width) >> 1;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2264
				break;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2265
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2266
			case WC_CONSOLE:
5143
a78072872bff (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2267
				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
  2268
				continue;
5126
d87bd8d5e159 (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2269
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2270
			default: {
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2271
				left = w->left;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2272
				if (left + (w->width >> 1) >= neww) left = neww - w->width;
6872
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2273
				if (left < 0) left = 0;
1c4a4a609f85 (svn r11950) [NewGRF_ports] -Sync with trunk r11566:11949.
rubidium
parents: 6871
diff changeset
  2274
2989
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2275
				top = w->top;
99c95a3ebcaa (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2276
				if (top + (w->height >> 1) >= newh) top = newh - w->height;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2277
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2278
				const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2279
				if (wt != NULL) {
10211
c1391c8ed5c6 (svn r12743) [NewGRF_ports] -Sync: with trunk r12705:12741.
richk
parents: 10210
diff changeset
  2280
					if (top < wt->height && wt->left < (w->left + w->width) && (wt->left + wt->width) > w->left) top = wt->height;
10184
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2281
					if (top >= newh) top = newh - 1;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2282
				} else {
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2283
					if (top < 0) top = 0;
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2284
				}
fcf5fb2548eb (svn r12715) [NewGRF_ports] -Sync: with trunk r12351:12644.
richk
parents: 6878
diff changeset
  2285
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2286
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2287
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2288
		if (w->viewport != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2289
			w->viewport->left += left - w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2290
			w->viewport->top += top - w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2291
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2292
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2293
		w->left = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2294
		w->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2295
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2296
}
10724
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2297
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2298
/** Destructor of the base class PickerWindowBase
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2299
 * Main utility is to stop the base Window destructor from triggering
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2300
 * a free while the child will already be free, in this case by the ResetObjectToPlace().
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2301
 */
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2302
PickerWindowBase::~PickerWindowBase()
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2303
{
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2304
	this->window_class = WC_INVALID; // stop the ancestor from freeing the already (to be) child
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2305
	ResetObjectToPlace();
68a692eacf22 (svn r13274) [NewGRF_ports] -Sync: with trunk r12806:13144.
richk
parents: 10274
diff changeset
  2306
}