src/window.cpp
author smatz
Sat, 13 Dec 2008 16:16:44 +0000
changeset 10417 a1a609566853
parent 10238 5076964d81a1
child 10426 4a77f7049b5e
permissions -rw-r--r--
(svn r14670) -Codechange: use better readable (I hope) and branchless (for some archs/compilers) code for cargo value computation
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9083
diff changeset
     3
/** @file window.cpp Windowing system, widgets and events */
6117
6507b2a7e71d (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: 5907
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
4755
9ebcb0db6c06 (svn r6669) -Add: vararg functions to set hidden/disabled/lowered state of multiple widgets in one call
glx
parents: 4749
diff changeset
     6
#include <stdarg.h>
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1867
diff changeset
     7
#include "openttd.h"
1299
39c06aba09aa (svn r1803) Move debugging stuff into files of it's own
tron
parents: 1112
diff changeset
     8
#include "debug.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
     9
#include "company_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8177
diff changeset
    10
#include "gfx_func.h"
9336
6baad5b3033d (svn r13228) -Codechange: split console.h.
rubidium
parents: 9317
diff changeset
    11
#include "console_func.h"
6baad5b3033d (svn r13228) -Codechange: split console.h.
rubidium
parents: 9317
diff changeset
    12
#include "console_gui.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8177
diff changeset
    13
#include "viewport_func.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    14
#include "variables.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
    15
#include "genworld.h"
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
    16
#include "blitter/factory.hpp"
8106
e6790dd9e750 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8068
diff changeset
    17
#include "window_gui.h"
8123
ce31d2843a95 (svn r11684) -Codechange: split gfx.h in a type and functional header.
rubidium
parents: 8121
diff changeset
    18
#include "zoom_func.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 8123
diff changeset
    19
#include "core/alloc_func.hpp"
8139
4e91c448c409 (svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents: 8131
diff changeset
    20
#include "map_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8139
diff changeset
    21
#include "vehicle_base.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8268
diff changeset
    22
#include "settings_type.h"
8965
29a591456a2f (svn r12757) -Codechange: move all cheat related stuff from all over the place to a single location.
rubidium
parents: 8957
diff changeset
    23
#include "cheat_func.h"
9117
87f472043e9e (svn r12977) -Codechange: remove quite some redundant (duplicate) function declarations.
rubidium
parents: 9116
diff changeset
    24
#include "window_func.h"
9127
14f21c5954ee (svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents: 9124
diff changeset
    25
#include "tilehighlight_func.h"
9898
75347c78b276 (svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents: 9508
diff changeset
    26
#include "network/network.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    28
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    29
8924
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
    30
static Point _drag_delta; ///< delta between mouse cursor and upper left corner of dragged window
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
    31
static Window *_mouseover_last_w = NULL; ///< Window of the last MOUSEOVER event
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    32
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
    33
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
    34
 * List of windows opened at the screen.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
    35
 * Uppermost window is at  _z_windows[_last_z_window - 1],
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
    36
 * bottom window is at _z_windows[0]
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
    37
 */
8925
e0d37ce1eba8 (svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium
parents: 8924
diff changeset
    38
Window *_z_windows[MAX_NUMBER_OF_WINDOWS];
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
    39
Window **_last_z_window; ///< always points to the next free space in the z-array
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    40
9411
f54d5b3b3bf8 (svn r13322) -Codechange: _no_scroll belongs more with the window code.
rubidium
parents: 9410
diff changeset
    41
byte _no_scroll;
8268
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    42
Point _cursorpos_drag_start;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    43
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    44
int _scrollbar_start_pos;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    45
int _scrollbar_size;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    46
byte _scroller_click_timeout;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    47
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    48
bool _scrolling_scrollbar;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    49
bool _scrolling_viewport;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    50
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    51
byte _special_mouse_mode;
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    52
5027ad5e70a0 (svn r11832) -Codechange: get rid of (quite) some VARDEFs.
rubidium
parents: 8264
diff changeset
    53
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    54
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    55
 * Sets the enabled/disabled status of a list of widgets.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    56
 * By default, widgets are enabled.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    57
 * On certain conditions, they have to be disabled.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    58
 * @param disab_stat status to use ie: disabled = true, enabled = false
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    59
 * @param widgets list of widgets ended by WIDGET_LIST_END
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    60
 */
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    61
void CDECL Window::SetWidgetsDisabledState(bool disab_stat, int widgets, ...)
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    62
{
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    63
	va_list wdg_list;
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    64
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    65
	va_start(wdg_list, widgets);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    66
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    67
	while (widgets != WIDGET_LIST_END) {
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    68
		SetWidgetDisabledState(widgets, disab_stat);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    69
		widgets = va_arg(wdg_list, int);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    70
	}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    71
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    72
	va_end(wdg_list);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    73
}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    74
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    75
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    76
 * Sets the hidden/shown status of a list of widgets.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    77
 * By default, widgets are visible.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    78
 * On certain conditions, they have to be hidden.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    79
 * @param hidden_stat status to use ie. hidden = true, visible = false
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    80
 * @param widgets list of widgets ended by WIDGET_LIST_END
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    81
 */
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    82
void CDECL Window::SetWidgetsHiddenState(bool hidden_stat, int widgets, ...)
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    83
{
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    84
	va_list wdg_list;
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    85
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    86
	va_start(wdg_list, widgets);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    87
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    88
	while (widgets != WIDGET_LIST_END) {
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    89
		SetWidgetHiddenState(widgets, hidden_stat);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    90
		widgets = va_arg(wdg_list, int);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    91
	}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    92
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    93
	va_end(wdg_list);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    94
}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
    95
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    96
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    97
 * Sets the lowered/raised status of a list of widgets.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    98
 * @param lowered_stat status to use ie: lowered = true, raised = false
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
    99
 * @param widgets list of widgets ended by WIDGET_LIST_END
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   100
 */
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   101
void CDECL Window::SetWidgetsLoweredState(bool lowered_stat, int widgets, ...)
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   102
{
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   103
	va_list wdg_list;
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   104
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   105
	va_start(wdg_list, widgets);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   106
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   107
	while (widgets != WIDGET_LIST_END) {
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   108
		SetWidgetLoweredState(widgets, lowered_stat);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   109
		widgets = va_arg(wdg_list, int);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   110
	}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   111
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   112
	va_end(wdg_list);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   113
}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   114
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   115
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   116
 * Raise all buttons of the window
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   117
 */
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   118
void Window::RaiseButtons()
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   119
{
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   120
	for (uint i = 0; i < this->widget_count; i++) {
8032
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
   121
		if (this->IsWidgetLowered(i)) {
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
   122
			this->RaiseWidget(i);
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
   123
			this->InvalidateWidget(i);
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   124
		}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   125
	}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   126
}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   127
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   128
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   129
 * Invalidate a widget, i.e. mark it as being changed and in need of redraw.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   130
 * @param widget_index the widget to redraw.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   131
 */
8026
a188ea8201ce (svn r11586) -Fix: make another widget 'accessor' function const when it should be const.
glx
parents: 8023
diff changeset
   132
void Window::InvalidateWidget(byte widget_index) const
7993
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   133
{
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   134
	const Widget *wi = &this->widget[widget_index];
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   135
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   136
	/* Don't redraw the window if the widget is invisible or of no-type */
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   137
	if (wi->type == WWT_EMPTY || IsWidgetHidden(widget_index)) return;
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   138
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   139
	SetDirtyBlocks(this->left + wi->left, this->top + wi->top, this->left + wi->right + 1, this->top + wi->bottom + 1);
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   140
}
8776e72bf3da (svn r11551) -Codechange: Introduction of widget control members on struct Window. These "new" members have the exact same functionalities as their pure functions "genitors"
belugas
parents: 7954
diff changeset
   141
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   142
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   143
 * Do all things to make a button look clicked and mark it to be
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   144
 * unclicked in a few ticks.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   145
 * @param widget the widget to "click"
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   146
 */
8035
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   147
void Window::HandleButtonClick(byte widget)
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   148
{
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   149
	this->LowerWidget(widget);
10180
a99cf854c6d0 (svn r14390) -Codechange: replace magic constants with symbolic constants.
rubidium
parents: 9898
diff changeset
   150
	this->flags4 |= WF_TIMEOUT_BEGIN;
8035
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   151
	this->InvalidateWidget(widget);
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   152
}
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
   153
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   154
static void StartWindowDrag(Window *w);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   155
static void StartWindowSizing(Window *w);
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   156
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   157
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   158
 * Dispatch left mouse-button (possibly double) click in window.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   159
 * @param w Window to dispatch event in
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   160
 * @param x X coordinate of the click
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   161
 * @param y Y coordinate of the click
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   162
 * @param double_click Was it a double click?
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   163
 */
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
   164
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click)
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
   165
{
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   166
	int widget = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   167
	if (w->desc_flags & WDF_DEF_WIDGET) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   168
		widget = GetWidgetFromPos(w, x, y);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   169
		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
   170
5236
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5235
diff changeset
   171
		/* don't allow any interaction if the button has been disabled */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   172
		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
   173
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   174
		const Widget *wi = &w->widget[widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   176
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   177
			/* special widget handling for buttons*/
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   178
			switch (wi->type) {
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   179
				case WWT_PANEL   | WWB_PUSHBUTTON: /* WWT_PUSHBTN */
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   180
				case WWT_IMGBTN  | WWB_PUSHBUTTON: /* WWT_PUSHIMGBTN */
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   181
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   182
					w->HandleButtonClick(widget);
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   183
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   184
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   185
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   186
			ScrollbarClickHandler(w, wi, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
		if (w->desc_flags & WDF_STD_BTN) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   190
			if (widget == 0) { /* 'X' */
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   191
				delete w;
984
2ff5fb62658a (svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents: 983
diff changeset
   192
				return;
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   193
			}
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   194
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   195
			if (widget == 1) { /* 'Title bar' */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   196
				StartWindowDrag(w);
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   197
				return;
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   198
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   200
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   201
		if (w->desc_flags & WDF_RESIZABLE && wi->type == WWT_RESIZEBOX) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   202
			StartWindowSizing(w);
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   203
			w->InvalidateWidget(widget);
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   204
			return;
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   205
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   206
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   207
		if (w->desc_flags & WDF_STICKY_BUTTON && wi->type == WWT_STICKYBOX) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   208
			w->flags4 ^= WF_STICKY;
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   209
			w->InvalidateWidget(widget);
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   210
			return;
682
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
   211
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
	}
1038
fb62bb1c424f (svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents: 1033
diff changeset
   213
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   214
	Point pt = { x, y };
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   215
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   216
	if (double_click) {
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   217
		w->OnDoubleClick(pt, widget);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   218
	} else {
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   219
		w->OnClick(pt, widget);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   220
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   223
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   224
 * Dispatch right mouse-button click in window.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   225
 * @param w Window to dispatch event in
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   226
 * @param x X coordinate of the click
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   227
 * @param y Y coordinate of the click
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   228
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   229
static void DispatchRightClickEvent(Window *w, int x, int y)
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
   230
{
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   231
	int widget = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   232
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
	/* default tooltips handler? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	if (w->desc_flags & WDF_STD_TOOLTIPS) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   235
		widget = GetWidgetFromPos(w, x, y);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   236
		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
   237
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   238
		if (w->widget[widget].tooltips != 0) {
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   239
			GuiShowTooltips(w->widget[widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   244
	Point pt = { x, y };
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   245
	w->OnRightClick(pt, widget);
0
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
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   248
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   249
 * Dispatch the mousewheel-action to the window.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   250
 * The window will scroll any compatible scrollbars if the mouse is pointed over the bar or its contents
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   251
 * @param w Window
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   252
 * @param widget the widget where the scrollwheel was used
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   253
 * @param wheel scroll up or down
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   254
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   255
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
   256
{
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   257
	if (widget < 0) return;
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   258
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   259
	const Widget *wi1 = &w->widget[widget];
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   260
	const Widget *wi2 = &w->widget[widget + 1];
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   261
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   262
	/* The listbox can only scroll if scrolling was done on the scrollbar itself,
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   263
	 * or on the listbox (and the next item is (must be) the scrollbar)
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   264
	 * XXX - should be rewritten as a widget-dependent scroller but that's
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   265
	 * not happening until someone rewrites the whole widget-code */
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   266
	Scrollbar *sb;
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   267
	if ((sb = &w->vscroll,  wi1->type == WWT_SCROLLBAR)  || (sb = &w->vscroll2, wi1->type == WWT_SCROLL2BAR)  ||
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   268
			(sb = &w->vscroll2, wi2->type == WWT_SCROLL2BAR) || (sb = &w->vscroll, wi2->type == WWT_SCROLLBAR) ) {
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   269
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   270
		if (sb->count > sb->cap) {
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7918
diff changeset
   271
			int pos = Clamp(sb->pos + wheel, 0, sb->count - sb->cap);
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   272
			if (pos != sb->pos) {
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   273
				sb->pos = pos;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
   274
				w->SetDirty();
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   275
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
	}
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
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   280
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   281
 * Generate repaint events for the visible part of window *wz within the rectangle.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   282
 *
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   283
 * The function goes recursively upwards in the window stack, and splits the rectangle
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   284
 * into multiple pieces at the window edges, so obscured parts are not redrawn.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   285
 *
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   286
 * @param wz Pointer into window stack, pointing at the window that needs to be repainted
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   287
 * @param left Left edge of the rectangle that should be repainted
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   288
 * @param top Top edge of the rectangle that should be repainted
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   289
 * @param right Right edge of the rectangle that should be repainted
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   290
 * @param bottom Bottom edge of the rectangle that should be repainted
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   291
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   292
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
   293
{
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
   294
	Window* const *vz = wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   296
	while (++vz != _last_z_window) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   297
		const Window *v = *vz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   298
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
		if (right > v->left &&
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
   300
				bottom > v->top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
				left < v->left + v->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
				top < v->top + v->height) {
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   303
			/* v and rectangle intersect with eeach other */
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   304
			int x;
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   305
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   306
			if (left < (x = v->left)) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   307
				DrawOverlappedWindow(wz, left, top, x, bottom);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   308
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   312
			if (right > (x = v->left + v->width)) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   313
				DrawOverlappedWindow(wz, left, top, x, bottom);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   314
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   316
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   318
			if (top < (x = v->top)) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   319
				DrawOverlappedWindow(wz, left, top, right, x);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   320
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   322
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   324
			if (bottom > (x = v->top + v->height)) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   325
				DrawOverlappedWindow(wz, left, top, right, x);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   326
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   327
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   331
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
   334
	/* Setup blitter, and dispatch a repaint event to window *wz */
8922
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   335
	DrawPixelInfo *dp = _cur_dpi;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   336
	dp->width = right - left;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   337
	dp->height = bottom - top;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   338
	dp->left = left - (*wz)->left;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   339
	dp->top = top - (*wz)->top;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   340
	dp->pitch = _screen.pitch;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   341
	dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   342
	dp->zoom = ZOOM_LVL_NORMAL;
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   343
	(*wz)->OnPaint();
8922
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   344
}
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   345
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   346
/**
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   347
 * From a rectangle that needs redrawing, find the windows that intersect with the rectangle.
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   348
 * These windows should be re-painted.
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   349
 * @param left Left edge of the rectangle that should be repainted
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   350
 * @param top Top edge of the rectangle that should be repainted
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   351
 * @param right Right edge of the rectangle that should be repainted
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   352
 * @param bottom Bottom edge of the rectangle that should be repainted
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   353
 */
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   354
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   355
{
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   356
	Window* const *wz;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   357
	DrawPixelInfo bk;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   358
	_cur_dpi = &bk;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   359
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   360
	FOR_ALL_WINDOWS(wz) {
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   361
		const Window *w = *wz;
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   362
		if (right > w->left &&
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   363
				bottom > w->top &&
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   364
				left < w->left + w->width &&
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   365
				top < w->top + w->height) {
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
   366
			/* Window w intersects with the rectangle => needs repaint */
8922
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   367
			DrawOverlappedWindow(wz, left, top, right, bottom);
2a945724618d (svn r12692) -Codechange: swap to functions to remove a function declaration.
rubidium
parents: 8857
diff changeset
   368
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   371
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   372
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   373
 * Mark entire window as dirty (in need of re-paint)
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   374
 * @ingroup dirty
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   375
 */
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   376
void Window::SetDirty() const
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   377
{
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   378
	SetDirtyBlocks(this->left, this->top, this->left + this->width, this->top + this->height);
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   379
}
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   380
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   381
/**
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   382
 * Mark entire window as dirty (in need of re-paint)
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   383
 * @param w Window to redraw
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   384
 * @ingroup dirty
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   385
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   386
void SetWindowDirty(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
{
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   388
	if (w != NULL) w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   391
/** Find the Window whose parent pointer points to this window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   392
 * @param w parent Window to find child of
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   393
 * @return a Window pointer that is the child of w, or NULL otherwise */
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   394
static Window *FindChildWindow(const Window *w)
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   395
{
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   396
	Window* const *wz;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   397
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   398
	FOR_ALL_WINDOWS(wz) {
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   399
		Window *v = *wz;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   400
		if (v->parent == w) return v;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   401
	}
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   402
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   403
	return NULL;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   404
}
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   405
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   406
/** Find the z-value of a window. A window must already be open
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   407
 * or the behaviour is undefined but function should never fail
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   408
 * @param w window to query Z Position
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   409
 * @return Pointer into the window-list at the position of \a w
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   410
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   411
Window **FindWindowZPosition(const Window *w)
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   412
{
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   413
	Window **wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   414
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   415
	FOR_ALL_WINDOWS(wz) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   416
		if (*wz == w) return wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   417
	}
5429
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   418
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   419
	DEBUG(misc, 3, "Window (cls %d, number %d) is not open, probably removed by recursive calls",
5429
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   420
		w->window_class, w->window_number);
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   421
	return NULL;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   422
}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   423
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   424
/**
10184
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   425
 * Delete all children a window might have in a head-recursive manner
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   426
 */
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   427
void Window::DeleteChildWindows() const
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   428
{
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   429
	Window *child = FindChildWindow(this);
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   430
	while (child != NULL) {
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   431
		delete child;
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   432
		child = FindChildWindow(this);
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   433
	}
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   434
}
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   435
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   436
/**
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
   437
 * Remove window and all its child windows from the window stack.
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   438
 */
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   439
Window::~Window()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   440
{
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   441
	if (_thd.place_mode != VHM_NONE &&
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   442
			_thd.window_class == this->window_class &&
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   443
			_thd.window_number == this->window_number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   444
		ResetObjectToPlace();
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
9083
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   447
	/* Prevent Mouseover() from resetting mouse-over coordinates on a non-existing window */
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   448
	if (_mouseover_last_w == this) _mouseover_last_w = NULL;
9083
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   449
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   450
	/* Find the window in the z-array, and effectively remove it
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   451
	 * by moving all windows after it one to the left. This must be
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   452
	 * done before removing the child so we cannot cause recursion
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   453
	 * between the deletion of the parent and the child. */
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   454
	Window **wz = FindWindowZPosition(this);
9083
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   455
	if (wz == NULL) return;
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   456
	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   457
	_last_z_window--;
e18c37b3a45e (svn r12942) -Fix [FS#1979]: closing some windows caused recursion in the Window deletion causing the reading invalid/freed data which could cause crashes.
rubidium
parents: 9082
diff changeset
   458
10184
bf4e3ff4cf16 (svn r14395) -Fix [FS#2285]: crashes and GUI desyncs when order is deleted/modified while the timetable window is open
smatz
parents: 10180
diff changeset
   459
	this->DeleteChildWindows();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   461
	if (this->viewport != NULL) DeleteWindowViewport(this);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   462
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   463
	this->SetDirty();
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   464
	free(this->widget);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   467
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   468
 * Find a window by its class and window number
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   469
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   470
 * @param number Number of the window within the window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   471
 * @return Pointer to the found window, or \c NULL if not available
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   472
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   473
Window *FindWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   475
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   477
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   478
		Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   479
		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
   480
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   482
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   483
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   484
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   485
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   486
 * Delete a window by its class and window number (if it is open).
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   487
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   488
 * @param number Number of the window within the window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   489
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   490
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
{
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   492
	delete FindWindowById(cls, number);
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   493
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   494
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   495
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   496
 * Delete all windows of a given class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   497
 * @param cls Window class of windows to delete
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   498
 */
999
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   499
void DeleteWindowByClass(WindowClass cls)
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   500
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   501
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   502
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   503
restart_search:
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   504
	/* When we find the window to delete, we need to restart the search
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   505
	 * as deleting this window could cascade in deleting (many) others
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   506
	 * anywhere in the z-array */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   507
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   508
		Window *w = *wz;
999
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   509
		if (w->window_class == cls) {
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   510
			delete w;
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   511
			goto restart_search;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   512
		}
999
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   513
	}
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   514
}
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   515
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   516
/** Delete all windows of a company. We identify windows of a company
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   517
 * by looking at the caption colour. If it is equal to the company ID
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   518
 * then we say the window belongs to the company and should be deleted
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   519
 * @param id company identifier */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   520
void DeleteCompanyWindows(CompanyID id)
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   521
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   522
	Window* const *wz;
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   523
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   524
restart_search:
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   525
	/* When we find the window to delete, we need to restart the search
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   526
	 * as deleting this window could cascade in deleting (many) others
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   527
	 * anywhere in the z-array */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   528
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   529
		Window *w = *wz;
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   530
		if (w->caption_color == id) {
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   531
			delete w;
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   532
			goto restart_search;
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   533
		}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   534
	}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   535
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   536
	/* Also delete the company specific windows, that don't have a company-colour */
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   537
	DeleteWindowById(WC_BUY_COMPANY, id);
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   538
}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   539
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   540
/** Change the owner of all the windows one company can take over from another
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   541
 * company in the case of a company merger. Do not change ownership of windows
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   542
 * that need to be deleted once takeover is complete
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   543
 * @param old_owner original owner of the window
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   544
 * @param new_owner the new owner of the window */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   545
void ChangeWindowOwner(Owner old_owner, Owner new_owner)
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   546
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   547
	Window* const *wz;
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   548
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   549
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   550
		Window *w = *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   551
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   552
		if (w->caption_color != old_owner) continue;
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   553
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   554
		switch (w->window_class) {
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   555
			case WC_COMPANY_COLOR:
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   556
			case WC_FINANCES:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   557
			case WC_STATION_LIST:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   558
			case WC_TRAINS_LIST:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   559
			case WC_ROADVEH_LIST:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   560
			case WC_SHIPS_LIST:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   561
			case WC_AIRCRAFT_LIST:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   562
			case WC_BUY_COMPANY:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   563
			case WC_COMPANY:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   564
				continue;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   565
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   566
			default:
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
   567
				w->caption_color = new_owner;
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   568
				break;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   569
		}
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   570
	}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   571
}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   572
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   573
static void BringWindowToFront(const Window *w);
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   574
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   575
/** Find a window and make it the top-window on the screen. The window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   576
 * gets a white border for a brief period of time to visualize its "activation"
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   577
 * @param cls WindowClass of the window to activate
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   578
 * @param number WindowNumber of the window to activate
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   579
 * @return a pointer to the window thus activated */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   580
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   582
	Window *w = FindWindowById(cls, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   583
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   584
	if (w != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
		w->flags4 |= WF_WHITE_BORDER_MASK;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   586
		BringWindowToFront(w);
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
   587
		w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   588
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   589
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   590
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   591
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   592
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   593
static inline bool IsVitalWindow(const Window *w)
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   594
{
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   595
	switch (w->window_class) {
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   596
		case WC_MAIN_TOOLBAR:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   597
		case WC_STATUS_BAR:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   598
		case WC_NEWS_WINDOW:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   599
		case WC_SEND_NETWORK_MSG:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   600
			return true;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   601
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   602
		default:
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   603
			return false;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   604
	}
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   605
}
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   606
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   607
/** On clicking on a window, make it the frontmost window of all. However
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   608
 * there are certain windows that always need to be on-top; these include
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   609
 * - Toolbar, Statusbar (always on)
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   610
 * - New window, Chatbar (only if open)
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   611
 * The window is marked dirty for a repaint if the window is actually moved
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   612
 * @param w window that is put into the foreground
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   613
 * @return pointer to the window, the same as the input pointer
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   614
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   615
static void BringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   616
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   617
	Window **wz = FindWindowZPosition(w);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   618
	Window **vz = _last_z_window;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   619
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   620
	/* Bring the window just below the vital windows */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   621
	do {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   622
		if (--vz < _z_windows) return;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   623
	} while (IsVitalWindow(*vz));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   624
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   625
	if (wz == vz) return; // window is already in the right position
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   626
	assert(wz < vz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   627
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   628
	Window *tempz = *wz;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   629
	memmove(wz, wz + 1, (byte*)vz - (byte*)wz);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   630
	*vz = tempz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   631
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
   632
	w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   634
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   635
/** We have run out of windows, so find a suitable candidate for replacement.
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   636
 * Keep all important windows intact. These are
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   637
 * - Main window (gamefield), Toolbar, Statusbar (always on)
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   638
 * - News window, Chatbar (when on)
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   639
 * - Any sticked windows since we wanted to keep these
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   640
 * @return w pointer to the window that is going to be deleted
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   641
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   642
static Window *FindDeletableWindow()
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   643
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   644
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   645
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   646
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   647
		Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   648
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   649
			return w;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   650
		}
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   651
	}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   652
	return NULL;
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   653
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   654
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   655
/** A window must be freed, and all are marked as important windows. Ease the
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   656
 * restriction a bit by allowing to delete sticky windows. Keep important/vital
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   657
 * windows intact (Main window, Toolbar, Statusbar, News Window, Chatbar)
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   658
 * Start finding an appropiate candidate from the lowest z-values (bottom)
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   659
 * @see FindDeletableWindow()
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   660
 * @return w Pointer to the window that is being deleted
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   661
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   662
static Window *ForceFindDeletableWindow()
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   663
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   664
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   665
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
   666
	FOR_ALL_WINDOWS(wz) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   667
		Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   668
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w)) return w;
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   669
	}
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
   670
	NOT_REACHED();
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   671
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   672
9167
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   673
/**
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   674
 * Assign widgets to a new window by initialising its widget pointers, and by
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   675
 * copying the widget array \a widget to \c w->widget to allow for resizable
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   676
 * windows.
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   677
 * @param w Window on which to attach the widget array
9167
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   678
 * @param widget pointer of widget array to fill the window with
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   679
 *
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   680
 * @post \c w->widget points to allocated memory and contains the copied widget array except for the terminating widget,
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   681
 *       \c w->widget_count contains number of widgets in the allocated memory.
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   682
 */
9168
888730a77af3 (svn r13031) -Codechange: make AssignWidgetToWindow a static function instead of a global one as it should only be used from window.cpp.
rubidium
parents: 9167
diff changeset
   683
static void AssignWidgetToWindow(Window *w, const Widget *widget)
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   684
{
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   685
	if (widget != NULL) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   686
		uint index = 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   687
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   688
		for (const Widget *wi = widget; wi->type != WWT_LAST; wi++) index++;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   689
9167
f99163cc2832 (svn r13030) -Codechange: do use MallocT instead of ReallocT when 100% sure that the pointer you are allocating to is NULL. Patch by Alberth.
rubidium
parents: 9166
diff changeset
   690
		w->widget = MallocT<Widget>(index);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   691
		memcpy(w->widget, widget, sizeof(*w->widget) * index);
5232
d099cc0d7961 (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   692
		w->widget_count = index - 1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   693
	} else {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   694
		w->widget = NULL;
5232
d099cc0d7961 (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   695
		w->widget_count = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   696
	}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   697
}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   698
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   699
/**
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   700
 * Initializes a new Window.
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   701
 * This function is called the constructors.
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   702
 * See descriptions for those functions for usage
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   703
 * Only addition here is window_number, which is the window_number being assigned to the new window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   704
 * @param x offset in pixels from the left of the screen
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   705
 * @param y offset in pixels from the top of the screen
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   706
 * @param min_width minimum width in pixels of the window
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   707
 * @param min_height minimum height in pixels of the window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   708
 * @param cls see WindowClass class of the window, used for identification and grouping
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   709
 * @param *widget see Widget pointer to the window layout and various elements
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   710
 * @param window_number number being assigned to the new window
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9184
diff changeset
   711
 * @return Window pointer of the newly created window
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9184
diff changeset
   712
 */
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   713
void Window::Initialize(int x, int y, int min_width, int min_height,
9317
f14eb8815829 (svn r13185) -Codechange: remove everything related to the WindowProc callbacks.
rubidium
parents: 9301
diff changeset
   714
				WindowClass cls, const Widget *widget, int window_number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   715
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   716
	/* We have run out of windows, close one and use that as the place for our new one */
8925
e0d37ce1eba8 (svn r12695) -Codechange: only allocate window structs when needed. Based on a patch by Alberth.
rubidium
parents: 8924
diff changeset
   717
	if (_last_z_window == endof(_z_windows)) {
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   718
		Window *w = FindDeletableWindow();
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   719
		if (w == NULL) w = ForceFindDeletableWindow();
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
   720
		delete w;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   721
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   722
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
   723
	/* Set up window properties */
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   724
	this->window_class = cls;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   725
	this->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   726
	this->caption_color = 0xFF;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   727
	this->left = x;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   728
	this->top = y;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   729
	this->width = min_width;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   730
	this->height = min_height;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   731
	AssignWidgetToWindow(this, widget);
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   732
	this->resize.width = min_width;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   733
	this->resize.height = min_height;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   734
	this->resize.step_width = 1;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   735
	this->resize.step_height = 1;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   736
	this->window_number = window_number;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   737
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   738
	/* Hacky way of specifying always-on-top windows. These windows are
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   739
		* always above other windows because they are moved below them.
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   740
		* status-bar is above news-window because it has been created earlier.
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   741
		* Also, as the chat-window is excluded from this, it will always be
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   742
		* the last window, thus always on top.
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   743
		* XXX - Yes, ugly, probably needs something like w->always_on_top flag
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   744
		* to implement correctly, but even then you need some kind of distinction
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   745
		* between on-top of chat/news and status windows, because these conflict */
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   746
	Window **wz = _last_z_window;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   747
	if (wz != _z_windows && this->window_class != WC_SEND_NETWORK_MSG && this->window_class != WC_HIGHSCORE && this->window_class != WC_ENDSCREEN) {
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   748
		if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   749
		if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   750
		if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   751
		if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   752
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   753
		assert(wz >= _z_windows);
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   754
		if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   755
	}
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   756
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   757
	*wz = this;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   758
	_last_z_window++;
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   759
}
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   760
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   761
/**
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   762
 * Resize window towards the default size.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   763
 * Prior to construction, a position for the new window (for its default size)
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   764
 * has been found with LocalGetWindowPlacement(). Initially, the window is
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   765
 * constructed with minimal size. Resizing the window to its default size is
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   766
 * done here.
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   767
 * @param def_width default width in pixels of the window
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   768
 * @param def_height default height in pixels of the window
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   769
 * @see Window::Window(), Window::Initialize()
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   770
 */
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   771
void Window::FindWindowPlacementAndResize(int def_width, int def_height)
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   772
{
7353
5d8ba9486e96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7344
diff changeset
   773
	/* Try to make windows smaller when our window is too small.
5d8ba9486e96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7344
diff changeset
   774
	 * w->(width|height) is normally the same as min_(width|height),
5d8ba9486e96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7344
diff changeset
   775
	 * but this way the GUIs can be made a little more dynamic;
5d8ba9486e96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7344
diff changeset
   776
	 * one can use the same spec for multiple windows and those
5d8ba9486e96 (svn r10716) -Codechange: not all windows' minimum size is actually their minimum size, so take the size of the window after WE_CREATE has been called as bare minimum size.
rubidium
parents: 7344
diff changeset
   777
	 * can then determine the real minimum size of the window. */
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   778
	if (this->width != def_width || this->height != def_height) {
7344
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   779
		/* Think about the overlapping toolbars when determining the minimum window size */
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   780
		int free_height = _screen.height;
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   781
		const Window *wt = FindWindowById(WC_STATUS_BAR, 0);
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   782
		if (wt != NULL) free_height -= wt->height;
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   783
		wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   784
		if (wt != NULL) free_height -= wt->height;
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   785
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   786
		int enlarge_x = max(min(def_width  - this->width,  _screen.width - this->width),  0);
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   787
		int enlarge_y = max(min(def_height - this->height, free_height   - this->height), 0);
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   788
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   789
		/* X and Y has to go by step.. calculate it.
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   790
		 * The cast to int is necessary else x/y are implicitly casted to
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   791
		 * unsigned int, which won't work. */
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   792
		if (this->resize.step_width  > 1) enlarge_x -= enlarge_x % (int)this->resize.step_width;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   793
		if (this->resize.step_height > 1) enlarge_y -= enlarge_y % (int)this->resize.step_height;
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   794
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   795
		ResizeWindow(this, enlarge_x, enlarge_y);
7342
c42f92fe1a60 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7341
diff changeset
   796
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   797
		Point size;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   798
		Point diff;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   799
		size.x = this->width;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   800
		size.y = this->height;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   801
		diff.x = enlarge_x;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   802
		diff.y = enlarge_y;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
   803
		this->OnResize(size, diff);
7344
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   804
	}
7342
c42f92fe1a60 (svn r10705) -Fix (r10704): some windows were not correctly initialized as they resized the window themselves and that should be interfered by making sure the window is resized in the right "step" size.
rubidium
parents: 7341
diff changeset
   805
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   806
	int nx = this->left;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   807
	int ny = this->top;
7464
be4757750389 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7454
diff changeset
   808
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   809
	if (nx + this->width > _screen.width) nx -= (nx + this->width - _screen.width);
7364
b9333195343a (svn r10727) -Codechange: when a window would fall outside of the screen (on the right) when opening it, move it to the left so it stays inside the screen.
rubidium
parents: 7363
diff changeset
   810
7344
1d44a3182218 (svn r10707) -Codechange: account for the main toolbar and status bar when determining the maximum height for a window.
rubidium
parents: 7342
diff changeset
   811
	const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   812
	ny = max(ny, (wt == NULL || this == wt || this->top == 0) ? 0 : wt->height);
7464
be4757750389 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7454
diff changeset
   813
	nx = max(nx, 0);
be4757750389 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7454
diff changeset
   814
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   815
	if (this->viewport != NULL) {
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   816
		this->viewport->left += nx - this->left;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   817
		this->viewport->top  += ny - this->top;
7464
be4757750389 (svn r10967) -Fix: in case of moving the window on create (because it doesn't fit in the screen), make sure to move the viewport too if we are an extra viewport (spotted by Maedhros)
truelight
parents: 7454
diff changeset
   818
	}
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   819
	this->left = nx;
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   820
	this->top = ny;
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   821
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
   822
	this->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   823
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   824
10238
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   825
/**
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   826
 * Resize window towards the default size given in the window description.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   827
 * @param desc the description to get the default size from.
5076964d81a1 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium
parents: 10208
diff changeset
   828
 */
9178
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   829
void Window::FindWindowPlacementAndResize(const WindowDesc *desc)
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   830
{
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   831
	this->FindWindowPlacementAndResize(desc->default_width, desc->default_height);
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   832
}
3235f895bf12 (svn r13041) -Fix: calling a virtual function on a not fully constructed object is bound to cause errors.
rubidium
parents: 9168
diff changeset
   833
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   834
/**
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   835
 * Open a new window. If there is no space for a new window, close an open
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   836
 * window. Try to avoid stickied windows, but if there is no else, close one of
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   837
 * those as well. Then make sure all created windows are below some always-on-top
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   838
 * ones. Finally set all variables and call the WE_CREATE event
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   839
 * @param x offset in pixels from the left of the screen
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   840
 * @param y offset in pixels from the top of the screen
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   841
 * @param width width in pixels of the window
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   842
 * @param height height in pixels of the window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   843
 * @param cls see WindowClass class of the window, used for identification and grouping
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   844
 * @param *widget see Widget pointer to the window layout and various elements
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   845
 * @return Window pointer of the newly created window
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
   846
 */
9301
3b20dfb6c4e8 (svn r13169) -Codechange: remove a (now) unneeded parameter of one of the Window constructors.
rubidium
parents: 9293
diff changeset
   847
Window::Window(int x, int y, int width, int height, WindowClass cls, const Widget *widget)
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   848
{
9317
f14eb8815829 (svn r13185) -Codechange: remove everything related to the WindowProc callbacks.
rubidium
parents: 9301
diff changeset
   849
	this->Initialize(x, y, width, height, cls, widget, 0);
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   850
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   852
/**
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   853
 * Decide whether a given rectangle is a good place to open a completely visible new window.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   854
 * The new window should be within screen borders, and not overlap with another already
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   855
 * existing window (except for the main window in the background).
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   856
 * @param left    Left edge of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   857
 * @param top     Top edge of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   858
 * @param width   Width of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   859
 * @param height  Height of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   860
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   861
 * @return Boolean indication that the rectangle is a good place for the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   862
 */
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   863
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
   864
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   865
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   867
	int right  = width + left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   868
	int bottom = height + top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   869
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
   870
	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
   871
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
   872
	/* Make sure it is not obscured by any window. */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   873
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   874
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   875
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   876
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   877
		if (right > w->left &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   878
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   879
				bottom > w->top &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   880
				w->top + w->height > top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   881
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   882
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   883
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   884
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   885
	pos.x = left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   886
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   887
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   888
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   889
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   890
/**
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   891
 * Decide whether a given rectangle is a good place to open a mostly visible new window.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   892
 * The new window should be mostly within screen borders, and not overlap with another already
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   893
 * existing window (except for the main window in the background).
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   894
 * @param left    Left edge of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   895
 * @param top     Top edge of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   896
 * @param width   Width of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   897
 * @param height  Height of the rectangle
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   898
 * @param pos     If rectangle is good, use this parameter to return the top-left corner of the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   899
 * @return Boolean indication that the rectangle is a good place for the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   900
 */
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   901
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
   902
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   903
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   904
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   905
	/* Left part of the rectangle may be at most 1/4 off-screen,
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   906
	 * right part of the rectangle may be at most 1/2 off-screen
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   907
	 */
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   908
	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   909
	/* Bottom part of the rectangle may be at most 1/4 off-screen */
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   910
	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
   911
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
   912
	/* Make sure it is not obscured by any window. */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   913
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   914
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   915
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   916
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   917
		if (left + width > w->left &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   918
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
				top + height > w->top &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   920
				w->top + w->height > top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   921
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   922
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   923
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   925
	pos.x = left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   926
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   927
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   928
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   929
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   930
/**
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   931
 * Find a good place for opening a new window of a given width and height.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   932
 * @param width  Width of the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   933
 * @param height Height of the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   934
 * @return Top-left coordinate of the new window
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   935
 */
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   936
static Point GetAutoPlacePosition(int width, int height)
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   937
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   938
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   939
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   940
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   941
	/* First attempt, try top-left of the screen */
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   942
	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
   943
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   944
	/* Second attempt, try around all existing windows with a distance of 2 pixels.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   945
	 * The new window must be entirely on-screen, and not overlap with an existing window.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   946
	 * Eight starting points are tried, two at each corner.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   947
	 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   948
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   949
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   950
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   951
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   952
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   953
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   954
		if (IsGoodAutoPlace1(w->left, w->top + w->height + 2, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   955
		if (IsGoodAutoPlace1(w->left, w->top - height - 2,    width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   956
		if (IsGoodAutoPlace1(w->left + w->width + 2, w->top + w->height - height, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   957
		if (IsGoodAutoPlace1(w->left - width - 2,    w->top + w->height - height, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   958
		if (IsGoodAutoPlace1(w->left + w->width - width, w->top + w->height + 2, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   959
		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
   960
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   961
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   962
	/* Third attempt, try around all existing windows with a distance of 2 pixels.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   963
	 * The new window may be partly off-screen, and must not overlap with an existing window.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   964
	 * Only four starting points are tried.
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   965
	 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   966
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   967
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   968
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   970
		if (IsGoodAutoPlace2(w->left + w->width + 2, w->top, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   971
		if (IsGoodAutoPlace2(w->left - width - 2,    w->top, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   972
		if (IsGoodAutoPlace2(w->left, w->top + w->height + 2, width, height, pt)) return pt;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   973
		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
   974
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   975
9424
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   976
	/* Fourth and final attempt, put window at diagonal starting from (0, 24), try multiples
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   977
	 * of (+5, +5)
0e77ca5edffb (svn r13338) -Doc: add documentation about the window placement. Patch by Alberth.
rubidium
parents: 9413
diff changeset
   978
	 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   979
	{
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   980
		int left = 0, top = 24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   981
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   982
restart:
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   983
		FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   984
			const Window *w = *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   985
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   986
			if (w->left == left && w->top == top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   987
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   988
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   989
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   990
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   991
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   992
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   993
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   994
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   995
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   996
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   997
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   998
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
   999
/**
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1000
 * Compute the position of the top-left corner of a new window that is opened.
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1001
 *
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1002
 * By default position a child window at an offset of 10/10 of its parent.
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1003
 * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports)
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1004
 * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1005
 * its parent. So it's exactly under the parent toolbar and no buttons will be covered.
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1006
 * However if it falls too extremely outside window positions, reposition
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1007
 * it to an automatic place.
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1008
 *
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1009
 * @param *desc         The pointer to the WindowDesc to be created
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1010
 * @param window_number the window number of the new window
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1011
 *
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1012
 * @return Coordinate of the top-left corner of the new window
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1013
 */
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1014
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
  1015
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1016
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1017
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  1019
	if (desc->parent_cls != 0 /* WC_MAIN_WINDOW */ &&
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  1020
			(w = FindWindowById(desc->parent_cls, window_number)) != NULL &&
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  1021
			w->left < _screen.width - 20 && w->left > -60 && w->top < _screen.height - 20) {
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  1022
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1023
		pt.x = w->left + ((desc->parent_cls == WC_BUILD_TOOLBAR || desc->parent_cls == WC_SCEN_LAND_GEN) ? 0 : 10);
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
  1024
		if (pt.x > _screen.width + 10 - desc->default_width) {
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
  1025
			pt.x = (_screen.width + 10 - desc->default_width) - 20;
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  1026
		}
7721
8aaea36c01df (svn r11256) -Codechange: Make opening a new toolbar not overlapping its parent one, by locating it under the parent, and aligned with the left side of it.
belugas
parents: 7464
diff changeset
  1027
		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
  1028
	} else {
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1029
		switch (desc->left) {
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1030
			case WDP_ALIGN_TBR: // Align the right side with the top toolbar
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1031
				w = FindWindowById(WC_MAIN_TOOLBAR, 0);
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
  1032
				pt.x = (w->left + w->width) - desc->default_width;
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1033
				break;
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1034
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1035
			case WDP_ALIGN_TBL: // Align the left side with the top toolbar
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1036
				pt.x = FindWindowById(WC_MAIN_TOOLBAR, 0)->left;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1037
				break;
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1038
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1039
			case WDP_AUTO: // Find a good automatic position for the window
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1040
				return GetAutoPlacePosition(desc->default_width, desc->default_height);
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1041
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1042
			case WDP_CENTER: // Centre the window horizontally
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
  1043
				pt.x = (_screen.width - desc->default_width) / 2;
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1044
				break;
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1045
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1046
			default:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1047
				pt.x = desc->left;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1048
				if (pt.x < 0) pt.x += _screen.width; // negative is from right of the screen
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1049
		}
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1050
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1051
		switch (desc->top) {
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1052
			case WDP_CENTER: // Centre the window vertically
7341
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
  1053
				pt.y = (_screen.height - desc->default_height) / 2;
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1054
				break;
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1055
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1056
			/* WDP_AUTO sets the position at once and is controlled by desc->left.
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1057
			 * Both left and top must be set to WDP_AUTO */
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1058
			case WDP_AUTO:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1059
				NOT_REACHED();
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1060
				assert(desc->left == WDP_AUTO && desc->top != WDP_AUTO);
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1061
				/* fallthrough */
9079
1b3d1fb740d8 (svn r12938) -Codechange: coding style fixes. Patch by Alberth.
rubidium
parents: 9078
diff changeset
  1062
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1063
			default:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1064
				pt.y = desc->top;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1065
				if (pt.y < 0) pt.y += _screen.height; // negative is from bottom of the screen
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
  1066
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1070
	return pt;
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1071
}
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1072
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1073
/**
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1074
 * Set the positions of a new window from a WindowDesc and open it.
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1075
 *
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1076
 * @param *desc         The pointer to the WindowDesc to be created
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1077
 * @param window_number the window number of the new window
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1078
 *
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1079
 * @return Window pointer of the newly created window
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1080
 */
9203
082fbf0500c4 (svn r13069) -Codechange: it is no longer needed to pass a void *data pointer with the WE_CREATE message because nothing uses it anymore.
rubidium
parents: 9184
diff changeset
  1081
Window::Window(const WindowDesc *desc, WindowNumber window_number)
9078
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1082
{
09266c44bd2f (svn r12937) -Codechange: split allocating and finding the spot to place a window. Patch by Alberth.
rubidium
parents: 8995
diff changeset
  1083
	Point pt = LocalGetWindowPlacement(desc, window_number);
9317
f14eb8815829 (svn r13185) -Codechange: remove everything related to the WindowProc callbacks.
rubidium
parents: 9301
diff changeset
  1084
	this->Initialize(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->cls, desc->widgets, window_number);
9142
858a058aa730 (svn r13004) -Codechange: replace AllocateWindow and AllocateWindowDesc with a Window constructor.
rubidium
parents: 9138
diff changeset
  1085
	this->desc_flags = desc->flags;
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1086
}
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
  1087
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1088
/** Do a search for a window at specific coordinates. For this we start
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1089
 * at the topmost window, obviously and work our way down to the bottom
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  1090
 * @param x position x to query
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  1091
 * @param y position y to query
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1092
 * @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
  1093
Window *FindWindowFromPt(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
{
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1095
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1096
		Window *w = *--wz;
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
  1097
		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1098
			return w;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1099
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1103
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
8923
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1105
/**
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1106
 * (re)initialize the windowing system
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1107
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1108
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
  1109
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
  1110
	IConsoleClose();
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1111
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1112
	_last_z_window = _z_windows;
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1113
	_mouseover_last_w = NULL;
1397
fa8539dcab46 (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1299
diff changeset
  1114
	_no_scroll = 0;
9410
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1115
	_scrolling_viewport = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
8923
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1118
/**
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1119
 * Close down the windowing system
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1120
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1121
void UnInitWindowSystem()
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1122
{
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1123
	while (_last_z_window != _z_windows) delete _z_windows[0];
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1124
}
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1125
8923
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1126
/**
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1127
 * Reset the windowing system, by means of shutting it down followed by re-initialization
145035178dcb (svn r12693) -Documentation: add some documentation to some window related stuff. Based on a patch by Albert.
rubidium
parents: 8922
diff changeset
  1128
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1129
void ResetWindowSystem()
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1130
{
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1131
	UnInitWindowSystem();
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1132
	InitWindowSystem();
1744
c999671a5740 (svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents: 1737
diff changeset
  1133
	_thd.pos.x = 0;
c999671a5740 (svn r2248) - Fix (regression): fix crashing of game when joining a dedicated server (only reset _thd.pos, not the whole structure; as done in revision 2241 to fix another crash)
Darkvater
parents: 1737
diff changeset
  1134
	_thd.pos.y = 0;
2877
3058c128f10e (svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents: 2817
diff changeset
  1135
	_thd.new_pos.x = 0;
3058c128f10e (svn r3425) - Fix: Followup to r3421. Correctly reset the TileHighLightData structure to prevent crashes in all the other cases where it is not guarded against sufficiently
Darkvater
parents: 2817
diff changeset
  1136
	_thd.new_pos.y = 0;
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1137
}
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1138
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1139
static void DecreaseWindowCounters()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1140
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1141
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1143
	for (wz = _last_z_window; wz != _z_windows;) {
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1144
		Window *w = *--wz;
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1145
		/* Unclick scrollbar buttons if they are pressed. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1147
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1148
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1149
		}
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1150
		w->OnMouseLoop();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1152
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1153
	for (wz = _last_z_window; wz != _z_windows;) {
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1154
		Window *w = *--wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1155
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1156
		if (w->flags4 & WF_TIMEOUT_MASK && !(--w->flags4 & WF_TIMEOUT_MASK)) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1157
			w->OnTimeout();
8032
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
  1158
			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
  1159
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1162
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1163
Window *GetCallbackWnd()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1164
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1165
	return FindWindowById(_thd.window_class, _thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1166
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1168
static void HandlePlacePresize()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1169
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1170
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1172
	Window *w = GetCallbackWnd();
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1173
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1174
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1175
	Point pt = GetTileBelowCursor();
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1176
	if (pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1177
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1178
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
	}
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1180
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1181
	w->OnPlacePresize(pt, TileVirtXY(pt.x, pt.y));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1183
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1184
static bool HandleDragDrop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
{
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1186
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1187
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1188
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1189
	Window *w = GetCallbackWnd();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1190
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1191
	if (w != NULL) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1192
		/* send an event in client coordinates. */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1193
		Point pt;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1194
		pt.x = _cursor.pos.x - w->left;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1195
		pt.y = _cursor.pos.y - w->top;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1196
		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
  1197
	}
8585
61ac905ff5f7 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8270
diff changeset
  1198
61ac905ff5f7 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8270
diff changeset
  1199
	ResetObjectToPlace();
61ac905ff5f7 (svn r12166) -Fix [FS#337]: when drag&drop mode was cancelled by keyboard input, depot/group window wasn't updated (original patch by GrimRC)
smatz
parents: 8270
diff changeset
  1200
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1203
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1204
static bool HandleMouseOver()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1205
{
8924
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1206
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1207
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1208
	/* We changed window, put a MOUSEOVER event to the last window */
8924
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1209
	if (_mouseover_last_w != NULL && _mouseover_last_w != w) {
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1210
		/* Reset mouse-over coordinates of previous window */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1211
		Point pt = { -1, -1 };
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1212
		_mouseover_last_w->OnMouseOver(pt, 0);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1213
	}
8924
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1214
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1215
	/* _mouseover_last_w will get reset when the window is deleted, see DeleteWindow() */
7063881d180a (svn r12694) -Fix: do not call the mouse over callback on already deleted windows.
rubidium
parents: 8923
diff changeset
  1216
	_mouseover_last_w = w;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1217
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1218
	if (w != NULL) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1219
		/* send an event in client coordinates. */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1220
		Point pt = { _cursor.pos.x - w->left, _cursor.pos.y - w->top };
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1221
		int widget = 0;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1222
		if (w->widget != NULL) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1223
			widget = GetWidgetFromPos(w, pt.x, pt.y);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1224
		}
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1225
		w->OnMouseOver(pt, widget);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1226
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1227
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1228
	/* Mouseover never stops execution */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1229
	return true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1230
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1231
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1232
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1233
 * Resize the window.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1234
 * Update all the widgets of a window based on their resize flags
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1235
 * Both the areas of the old window and the new sized window are set dirty
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1236
 * ensuring proper redrawal.
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1237
 * @param w Window to resize
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6443
diff changeset
  1238
 * @param x delta x-size of changed window (positive if larger, etc.)
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1239
 * @param y delta y-size of changed window
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1240
 */
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1241
void ResizeWindow(Window *w, int x, int y)
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1242
{
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1243
	bool resize_height = false;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1244
	bool resize_width = false;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1245
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1246
	if (x == 0 && y == 0) return;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1247
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1248
	w->SetDirty();
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1249
	for (Widget *wi = w->widget; wi->type != WWT_LAST; wi++) {
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1250
		/* Isolate the resizing flags */
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1251
		byte rsizeflag = GB(wi->display_flags, 0, 4);
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1252
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1253
		if (rsizeflag == RESIZE_NONE) continue;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1254
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1255
		/* Resize the widget based on its resize-flag */
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1256
		if (rsizeflag & RESIZE_LEFT) {
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1257
			wi->left += x;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1258
			resize_width = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1259
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1260
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1261
		if (rsizeflag & RESIZE_RIGHT) {
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1262
			wi->right += x;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1263
			resize_width = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1264
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1265
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1266
		if (rsizeflag & RESIZE_TOP) {
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1267
			wi->top += y;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1268
			resize_height = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1269
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1270
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1271
		if (rsizeflag & RESIZE_BOTTOM) {
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1272
			wi->bottom += y;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1273
			resize_height = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1274
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1275
	}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1276
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1277
	/* We resized at least 1 widget, so let's resize the window totally */
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1278
	if (resize_width)  w->width  += x;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1279
	if (resize_height) w->height += y;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1280
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1281
	w->SetDirty();
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1282
}
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1283
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1284
static bool _dragging_window;
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1285
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1286
static bool HandleWindowDragging()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1288
	Window* const *wz;
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1289
	/* Get out immediately if no window is being dragged at all. */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1290
	if (!_dragging_window) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1291
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1292
	/* Otherwise find the window... */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1293
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1294
		Window *w = *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1295
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1296
		if (w->flags4 & WF_DRAGGING) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1297
			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
  1298
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1299
			/* 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
  1300
			if (!_left_button_down) {
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1301
				w->flags4 &= ~WF_DRAGGING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1303
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1304
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1305
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1306
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1307
			int x = _cursor.pos.x + _drag_delta.x;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1308
			int y = _cursor.pos.y + _drag_delta.y;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1309
			int nx = x;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1310
			int ny = y;
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1311
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1312
			if (_settings_client.gui.window_snap_radius != 0) {
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1313
				Window* const *vz;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1314
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1315
				int hsnap = _settings_client.gui.window_snap_radius;
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1316
				int vsnap = _settings_client.gui.window_snap_radius;
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1317
				int delta;
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1318
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1319
				FOR_ALL_WINDOWS(vz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1320
					const Window *v = *vz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1321
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1322
					if (v == w) continue; // Don't snap at yourself
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1323
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1324
					if (y + w->height > v->top && y < v->top + v->height) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1325
						/* Your left border <-> other right border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1326
						delta = abs(v->left + v->width - x);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1327
						if (delta <= hsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1328
							nx = v->left + v->width;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1329
							hsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1330
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1331
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1332
						/* Your right border <-> other left border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1333
						delta = abs(v->left - x - w->width);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1334
						if (delta <= hsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1335
							nx = v->left - w->width;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1336
							hsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1337
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1338
					}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1339
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1340
					if (w->top + w->height >= v->top && w->top <= v->top + v->height) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1341
						/* Your left border <-> other left border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1342
						delta = abs(v->left - x);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1343
						if (delta <= hsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1344
							nx = v->left;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1345
							hsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1346
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1347
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1348
						/* Your right border <-> other right border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1349
						delta = abs(v->left + v->width - x - w->width);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1350
						if (delta <= hsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1351
							nx = v->left + v->width - w->width;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1352
							hsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1353
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1354
					}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1355
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1356
					if (x + w->width > v->left && x < v->left + v->width) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1357
						/* Your top border <-> other bottom border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1358
						delta = abs(v->top + v->height - y);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1359
						if (delta <= vsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1360
							ny = v->top + v->height;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1361
							vsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1362
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1363
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1364
						/* Your bottom border <-> other top border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1365
						delta = abs(v->top - y - w->height);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1366
						if (delta <= vsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1367
							ny = v->top - w->height;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1368
							vsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1369
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1370
					}
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1371
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1372
					if (w->left + w->width >= v->left && w->left <= v->left + v->width) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1373
						/* Your top border <-> other top border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1374
						delta = abs(v->top - y);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1375
						if (delta <= vsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1376
							ny = v->top;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1377
							vsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1378
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1379
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1380
						/* Your bottom border <-> other bottom border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1381
						delta = abs(v->top + v->height - y - w->height);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1382
						if (delta <= vsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1383
							ny = v->top + v->height - w->height;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1384
							vsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1385
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1386
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1387
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1388
			}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1389
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1390
			/* Make sure the window doesn't leave the screen
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1391
			 * 13 is the height of the title bar */
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7918
diff changeset
  1392
			nx = Clamp(nx, 13 - t->right, _screen.width - 13 - t->left);
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7918
diff changeset
  1393
			ny = Clamp(ny, 0, _screen.height - 13);
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1394
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1395
			/* Make sure the title bar isn't hidden by behind the main tool bar */
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1396
			Window *v = FindWindowById(WC_MAIN_TOOLBAR, 0);
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1397
			if (v != NULL) {
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1398
				int v_bottom = v->top + v->height;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1399
				int v_right = v->left + v->width;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1400
				if (ny + t->top >= v->top && ny + t->top < v_bottom) {
371
be6daee0afa3 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1401
					if ((v->left < 13 && nx + t->left < v->left) ||
be6daee0afa3 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1402
							(v_right > _screen.width - 13 && nx + t->right > v_right)) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1403
						ny = v_bottom;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1404
					} else {
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1405
						if (nx + t->left > v->left - 13 &&
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1406
								nx + t->right < v_right + 13) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1407
							if (w->top >= v_bottom) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1408
								ny = v_bottom;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1409
							} else if (w->left < nx) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1410
								nx = v->left - 13 - t->left;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1411
							} else {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1412
								nx = v_right + 13 - t->right;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1413
							}
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1414
						}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1415
					}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1416
				}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1417
			}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1418
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1419
			if (w->viewport != NULL) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1420
				w->viewport->left += nx - w->left;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1421
				w->viewport->top  += ny - w->top;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1422
			}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1423
			w->left = nx;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1424
			w->top  = ny;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1425
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1426
			w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1427
			return false;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1428
		} else if (w->flags4 & WF_SIZING) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1429
			int x, y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1430
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1431
			/* Stop the sizing if the left mouse button was released */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1432
			if (!_left_button_down) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1433
				w->flags4 &= ~WF_SIZING;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1434
				w->SetDirty();
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1435
				break;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1436
			}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1437
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1438
			x = _cursor.pos.x - _drag_delta.x;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1439
			y = _cursor.pos.y - _drag_delta.y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1440
2675
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1441
			/* X and Y has to go by step.. calculate it.
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1442
			 * The cast to int is necessary else x/y are implicitly casted to
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1443
			 * unsigned int, which won't work. */
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1444
			if (w->resize.step_width > 1) x -= x % (int)w->resize.step_width;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1445
2675
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1446
			if (w->resize.step_height > 1) y -= y % (int)w->resize.step_height;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1447
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1448
			/* Check if we don't go below the minimum set size */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1449
			if ((int)w->width + x < (int)w->resize.width)
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1450
				x = w->resize.width - w->width;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1451
			if ((int)w->height + y < (int)w->resize.height)
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1452
				y = w->resize.height - w->height;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1453
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1454
			/* Window already on size */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1455
			if (x == 0 && y == 0) return false;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1456
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1457
			/* Now find the new cursor pos.. this is NOT _cursor, because
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1458
			    we move in steps. */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1459
			_drag_delta.x += x;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1460
			_drag_delta.y += y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1461
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1462
			/* ResizeWindow sets both pre- and after-size to dirty for redrawal */
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1463
			ResizeWindow(w, x, y);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1464
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1465
			Point size;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1466
			Point diff;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1467
			size.x = x + w->width;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1468
			size.y = y + w->height;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1469
			diff.x = x;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1470
			diff.y = y;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1471
			w->OnResize(size, diff);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1472
			return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1473
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1476
	_dragging_window = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1477
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1478
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1479
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1480
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1481
 * Start window dragging
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1482
 * @param w Window to start dragging
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1483
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1484
static void StartWindowDrag(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1485
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1486
	w->flags4 |= WF_DRAGGING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1487
	_dragging_window = true;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1488
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1489
	_drag_delta.x = w->left - _cursor.pos.x;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1490
	_drag_delta.y = w->top  - _cursor.pos.y;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1491
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1492
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1493
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1494
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1495
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1496
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1497
 * Start resizing a window
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1498
 * @param w Window to start resizing
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1499
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1500
static void StartWindowSizing(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1501
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1502
	w->flags4 |= WF_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1503
	_dragging_window = true;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1504
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1505
	_drag_delta.x = _cursor.pos.x;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1506
	_drag_delta.y = _cursor.pos.y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1507
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1508
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1510
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1511
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1512
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1513
static bool HandleScrollbarScrolling()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1515
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1516
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1517
	/* Get out quickly if no item is being scrolled */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1518
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1519
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1520
	/* Find the scrolling window */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1521
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1522
		Window *w = *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1523
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
		if (w->flags4 & WF_SCROLL_MIDDLE) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1525
			/* Abort if no button is clicked any more. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1526
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1527
				w->flags4 &= ~WF_SCROLL_MIDDLE;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1528
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1529
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1530
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1531
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1532
			int i;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1533
			Scrollbar *sb;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1534
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1536
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1537
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1538
			} else if (w->flags4 & WF_SCROLL2){
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1539
				sb = &w->vscroll2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1540
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1541
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1542
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1543
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1544
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1545
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1546
			/* Find the item we want to move to and make sure it's inside bounds. */
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1547
			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
  1548
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1549
				sb->pos = pos;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1550
				w->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1551
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1552
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1553
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1554
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1555
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1558
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1559
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1560
static bool HandleViewportScroll()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1561
{
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1562
	bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1563
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1564
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1565
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1566
	Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1567
7855
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1568
	if (!(_right_button_down || scrollwheel_scrolling) || w == NULL) {
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1569
		_cursor.fix_at = false;
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1570
		_scrolling_viewport = false;
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1571
		return true;
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1572
	}
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1573
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1574
	if (w == FindWindowById(WC_MAIN_WINDOW, 0) && w->viewport->follow_vehicle != INVALID_VEHICLE) {
7759
eb8f1b5b2883 (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 7721
diff changeset
  1575
		/* If the main window is following a vehicle, then first let go of it! */
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1576
		const Vehicle *veh = GetVehicle(w->viewport->follow_vehicle);
7759
eb8f1b5b2883 (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 7721
diff changeset
  1577
		ScrollMainWindowTo(veh->x_pos, veh->y_pos, true); /* This also resets follow_vehicle */
eb8f1b5b2883 (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 7721
diff changeset
  1578
		return true;
eb8f1b5b2883 (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 7721
diff changeset
  1579
	}
eb8f1b5b2883 (svn r11304) -Feature: Control-Clicking the Center Main View button on the vehicle window allows the main viewport to follow the chosen vehicle.(stevenh)
belugas
parents: 7721
diff changeset
  1580
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1581
	Point delta;
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1582
	if (_settings_client.gui.reverse_scroll) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1583
		delta.x = -_cursor.delta.x;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1584
		delta.y = -_cursor.delta.y;
2680
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1585
	} else {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1586
		delta.x = _cursor.delta.x;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1587
		delta.y = _cursor.delta.y;
2680
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1588
	}
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1589
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1590
	if (scrollwheel_scrolling) {
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1591
		/* We are using scrollwheels for scrolling */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1592
		delta.x = _cursor.h_wheel;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1593
		delta.y = _cursor.v_wheel;
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1594
		_cursor.v_wheel = 0;
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1595
		_cursor.h_wheel = 0;
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1596
	}
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1597
4335
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1598
	/* Create a scroll-event and send it to the window */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1599
	w->OnScroll(delta);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1600
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1601
	_cursor.delta.x = 0;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1602
	_cursor.delta.y = 0;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1603
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1604
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1605
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1606
/** Check if a window can be made top-most window, and if so do
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1607
 * it. If a window does not obscure any other windows, it will not
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1608
 * be brought to the foreground. Also if the only obscuring windows
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1609
 * are so-called system-windows, the window will not be moved.
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1610
 * The function will return false when a child window of this window is a
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1611
 * modal-popup; function returns a false and child window gets a white border
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1612
 * @param w Window to bring on-top
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1613
 * @return false if the window has an active modal child, true otherwise */
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1614
static bool MaybeBringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1615
{
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1616
	bool bring_to_front = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1617
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1618
	if (w->window_class == WC_MAIN_WINDOW ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1619
			IsVitalWindow(w) ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1620
			w->window_class == WC_TOOLTIPS ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1621
			w->window_class == WC_DROPDOWN_MENU) {
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1622
		return true;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1623
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1624
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1625
	Window * const *wz = FindWindowZPosition(w);
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1626
	for (Window * const *uz = wz; ++uz != _last_z_window;) {
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1627
		Window *u = *uz;
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1628
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1629
		/* A modal child will prevent the activation of the parent window */
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1630
		if (u->parent == w && (u->desc_flags & WDF_MODAL)) {
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1631
			u->flags4 |= WF_WHITE_BORDER_MASK;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  1632
			u->SetDirty();
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1633
			return false;
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1634
		}
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1635
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1636
		if (u->window_class == WC_MAIN_WINDOW ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1637
				IsVitalWindow(u) ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1638
				u->window_class == WC_TOOLTIPS ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1639
				u->window_class == WC_DROPDOWN_MENU) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1640
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1641
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1642
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1643
		/* 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
  1644
		if (w->left + w->width <= u->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1645
				u->left + u->width <= w->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1646
				w->top  + w->height <= u->top ||
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1647
				u->top + u->height <= w->top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1648
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1649
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1650
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1651
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1652
	}
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1653
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1654
	if (bring_to_front) BringWindowToFront(w);
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1655
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1656
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1657
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1658
/** Handle keyboard input.
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1659
 * @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1660
 */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1661
void HandleKeypress(uint32 raw_key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1662
{
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1663
	/* Stores if a window with a textfield for typing is open
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1664
	 * If this is the case, keypress events are only passed to windows with text fields and
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1665
	 * to thein this main toolbar. */
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1666
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1667
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1668
	/*
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1669
	* During the generation of the world, there might be
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1670
	* another thread that is currently building for example
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1671
	* a road. To not interfere with those tasks, we should
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
  1672
	* NOT change the _current_company here.
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1673
	*
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1674
	* This is not necessary either, as the only events that
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1675
	* can be handled are the 'close application' events
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1676
	*/
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
  1677
	if (!IsGeneratingWorld()) _current_company = _local_company;
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1678
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1679
	/* Setup event */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1680
	uint16 key     = GB(raw_key,  0, 16);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1681
	uint16 keycode = GB(raw_key, 16, 16);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
8177
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1683
	/*
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1684
	 * The Unicode standard defines an area called the private use area. Code points in this
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1685
	 * area are reserved for private use and thus not portable between systems. For instance,
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1686
	 * Apple defines code points for the arrow keys in this area, but these are only printable
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1687
	 * on a system running OS X. We don't want these keys to show up in text fields and such,
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1688
	 * and thus we have to clear the unicode character when we encounter such a key.
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1689
	 */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1690
	if (key >= 0xE000 && key <= 0xF8FF) key = 0;
8177
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1691
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1692
	/*
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1693
	 * If both key and keycode is zero, we don't bother to process the event.
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1694
	 */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1695
	if (key == 0 && keycode == 0) return;
8177
d3b340b0bdfe (svn r11740) -Fix [FS#1610]: Modify and possibly discard key events for code points in the unicode private use area.
egladil
parents: 8144
diff changeset
  1696
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1697
	/* check if we have a query string window open before allowing hotkeys */
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1698
	if (FindWindowById(WC_QUERY_STRING,            0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1699
			FindWindowById(WC_SEND_NETWORK_MSG,        0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1700
			FindWindowById(WC_GENERATE_LANDSCAPE,      0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1701
			FindWindowById(WC_CONSOLE,                 0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1702
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1703
			FindWindowById(WC_COMPANY_PASSWORD_WINDOW, 0) != NULL) {
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1704
		query_open = true;
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1705
	}
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1706
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1707
	/* Call the event, start with the uppermost window. */
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1708
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1709
		Window *w = *--wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1710
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1711
		/* if a query window is open, only call the event for certain window types */
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1712
		if (query_open &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1713
				w->window_class != WC_QUERY_STRING &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1714
				w->window_class != WC_SEND_NETWORK_MSG &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1715
				w->window_class != WC_GENERATE_LANDSCAPE &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1716
				w->window_class != WC_CONSOLE &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1717
				w->window_class != WC_SAVELOAD &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1718
				w->window_class != WC_COMPANY_PASSWORD_WINDOW) {
651
48b94e823465 (svn r1084) Generalized hotkey catching when textfield windows are open. Now only hotkeys attached to the main toolbar are working if you have a textfield open.
dominik
parents: 649
diff changeset
  1719
			continue;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1720
		}
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9275
diff changeset
  1721
		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
  1722
	}
1637
ee2049729147 (svn r2141) - Fix: Keys now hopefully only activate the right windows. If console/querybox/chatbox is open, all input goes there, if closed to game itself.
Darkvater
parents: 1570
diff changeset
  1723
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1724
	Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1725
	/* When there is no toolbar w is null, check for that */
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1726
	if (w != NULL) w->OnKeyPress(key, keycode);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1727
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1728
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1729
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1730
 * State of CONTROL key has changed
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1731
 */
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1732
void HandleCtrlChanged()
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1733
{
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1734
	/* Call the event, start with the uppermost window. */
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1735
	for (Window* const *wz = _last_z_window; wz != _z_windows;) {
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1736
		Window *w = *--wz;
9285
235e5e2d7f55 (svn r13151) -Codechange: use an enum instead of bool as return type of OnKeyPress/OnCTRLStateChange to make it obvious what the return values mean.
rubidium
parents: 9275
diff changeset
  1737
		if (w->OnCTRLStateChange() == Window::ES_HANDLED) return;
8586
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1738
	}
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1739
}
cb0e7e00f1d2 (svn r12167) -Feature(tte): change colour of autorail and autoroad selection when Ctrl is pressed
smatz
parents: 8585
diff changeset
  1740
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1741
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1742
 * Local counter that is incremented each time an mouse input event is detected.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1743
 * The counter is used to stop auto-scrolling.
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1744
 * @see HandleAutoscroll()
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1745
 * @see HandleMouseEvents()
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1746
 */
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1747
static int _input_events_this_tick = 0;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1748
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1749
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1750
 * If needed and switched on, perform auto scrolling (automatically
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1751
 * moving window contents when mouse is near edge of the window).
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1752
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1753
static void HandleAutoscroll()
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1754
{
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1755
	if (_input_events_this_tick != 0) {
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1756
		/* HandleAutoscroll is called only once per GameLoop() - so we can clear the counter here */
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1757
		_input_events_this_tick = 0;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1758
		/* there were some inputs this tick, don't scroll ??? */
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1759
		return;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1760
	}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1761
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1762
	if (_settings_client.gui.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1763
		int x = _cursor.pos.x;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1764
		int y = _cursor.pos.y;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1765
		Window *w = FindWindowFromPt(x, y);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1766
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1767
		ViewPort *vp = IsPtInWindowViewport(w, x, y);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1768
		if (vp != NULL) {
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1769
			x -= vp->left;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1770
			y -= vp->top;
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1771
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1772
			/* here allows scrolling in both x and y axis */
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1773
#define scrollspeed 3
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1774
			if (x - 15 < 0) {
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1775
				w->viewport->dest_scrollpos_x += ScaleByZoom((x - 15) * scrollspeed, vp->zoom);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1776
			} else if (15 - (vp->width - x) > 0) {
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1777
				w->viewport->dest_scrollpos_x += ScaleByZoom((15 - (vp->width - x)) * scrollspeed, vp->zoom);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1778
			}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1779
			if (y - 15 < 0) {
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1780
				w->viewport->dest_scrollpos_y += ScaleByZoom((y - 15) * scrollspeed, vp->zoom);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1781
			} else if (15 - (vp->height - y) > 0) {
9184
6c18790d3929 (svn r13047) -Codechange: remove vp_d
glx
parents: 9178
diff changeset
  1782
				w->viewport->dest_scrollpos_y += ScaleByZoom((15 - (vp->height - y)) * scrollspeed, vp->zoom);
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1783
			}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1784
#undef scrollspeed
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1785
		}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1786
	}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1787
}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1788
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1789
enum MouseClick {
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1790
	MC_NONE = 0,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1791
	MC_LEFT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1792
	MC_RIGHT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1793
	MC_DOUBLE_LEFT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1794
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7009
diff changeset
  1795
	MAX_OFFSET_DOUBLE_CLICK = 5,     ///< How much the mouse is allowed to move to call it a double click
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7009
diff changeset
  1796
	TIME_BETWEEN_DOUBLE_CLICK = 500, ///< Time between 2 left clicks before it becoming a double click, in ms
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1797
};
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1798
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1799
extern void UpdateTileSelection();
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1800
extern bool VpHandlePlaceSizingDrag();
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  1801
9410
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1802
static void ScrollMainViewport(int x, int y)
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1803
{
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1804
	if (_game_mode != GM_MENU) {
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1805
		Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1806
		assert(w);
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1807
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1808
		w->viewport->dest_scrollpos_x += ScaleByZoom(x, w->viewport->zoom);
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1809
		w->viewport->dest_scrollpos_y += ScaleByZoom(y, w->viewport->zoom);
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1810
	}
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1811
}
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1812
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1813
/**
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1814
 * Describes all the different arrow key combinations the game allows
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1815
 * when it is in scrolling mode.
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1816
 * The real arrow keys are bitwise numbered as
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1817
 * 1 = left
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1818
 * 2 = up
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1819
 * 4 = right
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1820
 * 8 = down
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1821
 */
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1822
static const int8 scrollamt[16][2] = {
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1823
	{ 0,  0}, ///<  no key specified
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1824
	{-2,  0}, ///<  1 : left
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1825
	{ 0, -2}, ///<  2 : up
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1826
	{-2, -1}, ///<  3 : left  + up
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1827
	{ 2,  0}, ///<  4 : right
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1828
	{ 0,  0}, ///<  5 : left  + right = nothing
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1829
	{ 2, -1}, ///<  6 : right + up
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1830
	{ 0, -2}, ///<  7 : right + left  + up = up
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1831
	{ 0  ,2}, ///<  8 : down
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1832
	{-2  ,1}, ///<  9 : down  + left
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1833
	{ 0,  0}, ///< 10 : down  + up    = nothing
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1834
	{-2,  0}, ///< 11 : left  + up    +  down = left
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1835
	{ 2,  1}, ///< 12 : down  + right
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1836
	{ 0,  2}, ///< 13 : left  + right +  down = down
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1837
	{ 2,  0}, ///< 14 : right + up    +  down = right
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1838
	{ 0,  0}, ///< 15 : left  + up    +  right + down  = nothing
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1839
};
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1840
9431
ce662bc7151b (svn r13346) -Fix (r13322): scrolling the main viewport with keyboard when having a build tool selected failed.
rubidium
parents: 9424
diff changeset
  1841
static void HandleKeyScrolling()
9410
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1842
{
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1843
	if (_dirkeys && !_no_scroll) {
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1844
		int factor = _shift_pressed ? 50 : 10;
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1845
		ScrollMainViewport(scrollamt[_dirkeys][0] * factor, scrollamt[_dirkeys][1] * factor);
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1846
	}
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1847
}
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  1848
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1849
void MouseLoop(MouseClick click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1850
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1851
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1852
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1853
	UpdateTileSelection();
9431
ce662bc7151b (svn r13346) -Fix (r13322): scrolling the main viewport with keyboard when having a build tool selected failed.
rubidium
parents: 9424
diff changeset
  1854
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1855
	if (!VpHandlePlaceSizingDrag())  return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1856
	if (!HandleDragDrop())           return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1857
	if (!HandleWindowDragging())     return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1858
	if (!HandleScrollbarScrolling()) return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1859
	if (!HandleViewportScroll())     return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1860
	if (!HandleMouseOver())          return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1861
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1862
	bool scrollwheel_scrolling = _settings_client.gui.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1863
	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
  1864
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1865
	int x = _cursor.pos.x;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1866
	int y = _cursor.pos.y;
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1867
	Window *w = FindWindowFromPt(x, y);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1868
	if (w == NULL) return;
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1869
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1870
	if (!MaybeBringWindowToFront(w)) return;
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1871
	ViewPort *vp = IsPtInWindowViewport(w, x, y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1872
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1873
	/* Don't allow any action in a viewport if either in menu of in generating world */
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1874
	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
  1875
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1876
	if (mousewheel != 0) {
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  1877
		if (_settings_client.gui.scrollwheel_scrolling == 0) {
9264
9380b4a14c92 (svn r13130) -Codechange: remove some of the (old) WindowEvent wrapper functions/enums/variables as they are not used anymore.
rubidium
parents: 9233
diff changeset
  1878
			/* Send mousewheel event to window */
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  1879
			w->OnMouseWheel(mousewheel);
6296
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1880
		}
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1881
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1882
		/* Dispatch a MouseWheelEvent for widgets if it is not a viewport */
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1883
		if (vp == NULL) DispatchMouseWheelEvent(w, GetWidgetFromPos(w, x - w->left, y - w->top), mousewheel);
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1884
	}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1885
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1886
	if (vp != NULL) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1887
		if (scrollwheel_scrolling) click = MC_RIGHT; // we are using the scrollwheel in a viewport, so we emulate right mouse button
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1888
		switch (click) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1889
			case MC_DOUBLE_LEFT:
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1890
			case MC_LEFT:
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1891
				DEBUG(misc, 2, "Cursor: 0x%X (%d)", _cursor.sprite, _cursor.sprite);
7918
970e7c5005e5 (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents: 7855
diff changeset
  1892
				if (_thd.place_mode != VHM_NONE &&
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1893
						/* query button and place sign button work in pause mode */
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1894
						_cursor.sprite != SPR_CURSOR_QUERY &&
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1895
						_cursor.sprite != SPR_CURSOR_SIGN &&
6231
ff7454d35935 (svn r9034) -Codechange: renamed _pause to _pause_game, as some targets already have
truelight
parents: 6117
diff changeset
  1896
						_pause_game != 0 &&
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1897
						!_cheats.build_in_pause.value) {
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1898
					return;
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1899
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1900
7918
970e7c5005e5 (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents: 7855
diff changeset
  1901
				if (_thd.place_mode == VHM_NONE) {
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1902
					HandleViewportClicked(vp, x, y);
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1903
				} else {
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1904
					PlaceObject();
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1905
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1906
				break;
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1907
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1908
			case MC_RIGHT:
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1909
				if (!(w->flags4 & WF_DISABLE_VP_SCROLL)) {
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1910
					_scrolling_viewport = true;
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1911
					_cursor.fix_at = true;
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1912
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1913
				break;
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1914
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1915
			default:
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1916
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
	} else {
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1919
		switch (click) {
9138
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1920
			case MC_DOUBLE_LEFT:
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1921
				DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1922
				if (_mouseover_last_w == NULL) break; // The window got removed.
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1923
				/* fallthough, and also give a single-click for backwards compatibility */
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1924
			case MC_LEFT:
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1925
				DispatchLeftClickEvent(w, x - w->left, y - w->top, false);
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1926
				break;
b9fe83746a62 (svn r12999) -Fix [FS#1995]: when a Window got deleted on a double click event, we should not send a click event to the now non-existant Window as that causes segfaults.
rubidium
parents: 9127
diff changeset
  1927
6290
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1928
			default:
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1929
				if (!scrollwheel_scrolling || w == NULL || w->window_class != WC_SMALLMAP) break;
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1930
				/* We try to use the scrollwheel to scroll since we didn't touch any of the buttons.
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1931
				* Simulate a right button click so we can get started. */
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1932
				/* fallthough */
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1933
			case MC_RIGHT: DispatchRightClickEvent(w, x - w->left, y - w->top); break;
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1934
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1935
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1936
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1937
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1938
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1939
 * Handle a mouse event from the video driver
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1940
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1941
void HandleMouseEvents()
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1942
{
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1943
	static int double_click_time = 0;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1944
	static int double_click_x = 0;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1945
	static int double_click_y = 0;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1946
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1947
	/*
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1948
	 * During the generation of the world, there might be
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1949
	 * another thread that is currently building for example
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1950
	 * a road. To not interfere with those tasks, we should
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
  1951
	 * NOT change the _current_company here.
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1952
	 *
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1953
	 * This is not necessary either, as the only events that
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1954
	 * can be handled are the 'close application' events
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1955
	 */
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10184
diff changeset
  1956
	if (!IsGeneratingWorld()) _current_company = _local_company;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1957
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  1958
	/* Mouse event? */
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1959
	MouseClick click = MC_NONE;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1960
	if (_left_button_down && !_left_button_clicked) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1961
		click = MC_LEFT;
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7009
diff changeset
  1962
		if (double_click_time != 0 && _realtime_tick - double_click_time   < TIME_BETWEEN_DOUBLE_CLICK &&
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1963
			  double_click_x != 0    && abs(_cursor.pos.x - double_click_x) < MAX_OFFSET_DOUBLE_CLICK  &&
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1964
			  double_click_y != 0    && abs(_cursor.pos.y - double_click_y) < MAX_OFFSET_DOUBLE_CLICK) {
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1965
			click = MC_DOUBLE_LEFT;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1966
		}
7018
71e174292e42 (svn r10276) -Codechange: made a counter based on milliseconds and independent of the game-state to base double-click and TGP Generation Process on
truelight
parents: 7009
diff changeset
  1967
		double_click_time = _realtime_tick;
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1968
		double_click_x = _cursor.pos.x;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1969
		double_click_y = _cursor.pos.y;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1970
		_left_button_clicked = true;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1971
		_input_events_this_tick++;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1972
	} else if (_right_button_clicked) {
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1973
		_right_button_clicked = false;
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1974
		click = MC_RIGHT;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1975
		_input_events_this_tick++;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1976
	}
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1977
9124
e50e61b8bb42 (svn r12984) -Codechange: some coding style in window.cpp.
rubidium
parents: 9117
diff changeset
  1978
	int mousewheel = 0;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1979
	if (_cursor.wheel) {
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1980
		mousewheel = _cursor.wheel;
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1981
		_cursor.wheel = 0;
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1982
		_input_events_this_tick++;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1983
	}
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1984
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1985
	MouseLoop(click, mousewheel);
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1986
}
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1987
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1988
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1989
 * Regular call from the global game loop
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1990
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1991
void InputLoop()
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1992
{
9508
e5ab9738298a (svn r13495) -Fix: scrolling the main map with the keys speed was influenced by movement of the mouse.
rubidium
parents: 9431
diff changeset
  1993
	HandleKeyScrolling();
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1994
	HandleMouseEvents();
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1995
	HandleAutoscroll();
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1996
}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1997
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1998
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  1999
 * Update the continuously changing contents of the windows, such as the viewports
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2000
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2001
void UpdateWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2002
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2003
	Window* const *wz;
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2004
	static int we4_timer = 0;
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2005
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2007
	if (t >= 100) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2008
		for (wz = _last_z_window; wz != _z_windows;) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2009
			(*--wz)->OnHundredthTick();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2010
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2012
	}
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  2013
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2015
	for (wz = _last_z_window; wz != _z_windows;) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2016
		Window *w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2017
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2018
			w->flags4 -= WF_WHITE_BORDER_ONE;
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  2019
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  2020
			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
  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
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2025
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2026
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2027
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2028
	}
9898
75347c78b276 (svn r14047) -Codechange: move chatmessage handling to the network directory as that's the only case chat messages are used. Furthermore remove any trace of chatmessages when compiling without network support.
rubidium
parents: 9508
diff changeset
  2029
	NetworkDrawChatMessage();
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6296
diff changeset
  2030
	/* Redraw mouse cursor in case it was hidden */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2031
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2032
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2033
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2034
/**
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2035
 * Mark window as dirty (in need of repainting)
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2036
 * @param cls Window class
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2037
 * @param number Window number in that class
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2038
 */
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2039
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2040
{
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  2041
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2042
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2043
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2044
		const Window *w = *wz;
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  2045
		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
  2046
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2047
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2048
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2049
/**
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2050
 * Mark a particular widget in a particular window as dirty (in need of repainting)
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2051
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2052
 * @param number Window number in that class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2053
 * @param widget_index Index number of the widget that needs repainting
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2054
 */
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2055
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
  2056
{
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  2057
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2058
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2059
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2060
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2061
		if (w->window_class == cls && w->window_number == number) {
8028
e578ea22f371 (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8026
diff changeset
  2062
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2063
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2064
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2065
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2067
/**
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2068
 * Mark all windows of a particular class as dirty (in need of repainting)
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2069
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2070
 */
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  2071
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
{
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  2073
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2074
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2075
	FOR_ALL_WINDOWS(wz) {
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  2076
		if ((*wz)->window_class == cls) (*wz)->SetDirty();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2078
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2079
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2080
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2081
 * Mark window data as invalid (in need of re-computing)
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2082
 * @param w Window with invalid data
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2083
 */
9165
6f26cc347e7a (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 9162
diff changeset
  2084
void InvalidateThisWindowData(Window *w, int data)
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2085
{
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2086
	w->OnInvalidateData(data);
9116
f2491d3c321b (svn r12976) -Codechange: use w->SetDirty() instead of SetWindowDirty(w) when it's certain that w != NULL.
rubidium
parents: 9115
diff changeset
  2087
	w->SetDirty();
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2088
}
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2089
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2090
/**
8992
0b2fb43cc875 (svn r12787) -Documentation: add/fix documentation of some functions. Patch by Alberth.
rubidium
parents: 8965
diff changeset
  2091
 * Mark window data of the window of a given class and specific window number as invalid (in need of re-computing)
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2092
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2093
 * @param number Window number within the class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2094
 */
9165
6f26cc347e7a (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 9162
diff changeset
  2095
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data)
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2096
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2097
	Window* const *wz;
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2098
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2099
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2100
		Window *w = *wz;
9165
6f26cc347e7a (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 9162
diff changeset
  2101
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w, data);
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2102
	}
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2103
}
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2104
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2105
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2106
 * Mark window data of all windows of a given class as invalid (in need of re-computing)
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2107
 * @param cls Window class
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2108
 */
9165
6f26cc347e7a (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 9162
diff changeset
  2109
void InvalidateWindowClassesData(WindowClass cls, int data)
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2110
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2111
	Window* const *wz;
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  2112
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2113
	FOR_ALL_WINDOWS(wz) {
9165
6f26cc347e7a (svn r13028) -Codechange: WE_MESSAGE and WE_INVALIDATE_DATA were doing the same thing.
rubidium
parents: 9162
diff changeset
  2114
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz, data);
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2115
	}
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  2116
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2117
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2118
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2119
 * Dispatch WE_TICK event over all windows
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2120
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2121
void CallWindowTickEvent()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2122
{
9410
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2123
	if (_scroller_click_timeout > 3) {
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2124
		_scroller_click_timeout -= 3;
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2125
	} else {
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2126
		_scroller_click_timeout = 0;
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2127
	}
b8cbfacc9057 (svn r13321) -Codechange: move some GUI/viewport related functions out op openttd.cpp to viewport.cpp/window.cpp.
rubidium
parents: 9407
diff changeset
  2128
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2129
	for (Window * const *wz = _last_z_window; wz != _z_windows;) {
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2130
		(*--wz)->OnTick();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2131
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2132
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2133
8995
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2134
/**
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2135
 * Try to delete a non-vital window.
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2136
 * Non-vital windows are windows other than the game selection, main toolbar,
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2137
 * status bar, toolbar menu, and tooltip windows. Stickied windows are also
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2138
 * considered vital.
f6b859375e10 (svn r12790) -Codechange: code style fixes. Patch by Alberth.
rubidium
parents: 8992
diff changeset
  2139
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2140
void DeleteNonVitalWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2142
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2143
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2144
restart_search:
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2145
	/* When we find the window to delete, we need to restart the search
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2146
	 * as deleting this window could cascade in deleting (many) others
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2147
	 * anywhere in the z-array */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2148
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2149
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2151
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2152
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2153
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2154
				w->window_class != WC_TOOLBAR_MENU &&
682
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
  2155
				w->window_class != WC_TOOLTIPS &&
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 679
diff changeset
  2156
				(w->flags4 & WF_STICKY) == 0) { // do not delete windows which are 'pinned'
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2157
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
  2158
			delete w;
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2159
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2160
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2161
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2163
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  2164
/** It is possible that a stickied window gets to a position where the
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2165
 * 'close' button is outside the gaming area. You cannot close it then; except
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2166
 * with this function. It closes all windows calling the standard function,
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2167
 * then, does a little hacked loop of closing all stickied windows. Note
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2168
 * that standard windows (status bar, etc.) are not stickied, so these aren't affected */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2169
void DeleteAllNonVitalWindows()
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2170
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2171
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2172
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2173
	/* Delete every window except for stickied ones, then sticky ones as well */
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2174
	DeleteNonVitalWindows();
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2175
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2176
restart_search:
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2177
	/* When we find the window to delete, we need to restart the search
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2178
	 * as deleting this window could cascade in deleting (many) others
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2179
	 * anywhere in the z-array */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2180
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2181
		if ((*wz)->flags4 & WF_STICKY) {
9115
47ae980bace3 (svn r12975) -Codechange: replace DeleteWindow(w) with delete w.
rubidium
parents: 9111
diff changeset
  2182
			delete *wz;
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2183
			goto restart_search;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2184
		}
763
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2185
	}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2186
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2187
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  2188
/** Delete all always on-top windows to get an empty screen */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2189
void HideVitalWindows()
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2190
{
5907
31c78a89f10c (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: 5642
diff changeset
  2191
	DeleteWindowById(WC_TOOLBAR_MENU, 0);
983
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2192
	DeleteWindowById(WC_MAIN_TOOLBAR, 0);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2193
	DeleteWindowById(WC_STATUS_BAR, 0);
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2194
}
4765bf636f6b (svn r1479) -Added highscore chart (accessible from the difficulty window) with top5 companies for a given difficulty (select the difficulty in the menu)
darkvater
parents: 982
diff changeset
  2195
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2196
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2197
 * (Re)position main toolbar window at the screen
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2198
 * @param w Window structure of the main toolbar window, may also be \c NULL
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2199
 * @return X coordinate of left edge of the repositioned toolbar window
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2200
 */
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2201
int PositionMainToolbar(Window *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2202
{
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2203
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2204
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2205
	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
  2206
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2207
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2208
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9411
diff changeset
  2209
	switch (_settings_client.gui.toolbar_pos) {
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  2210
		case 1:  w->left = (_screen.width - w->width) / 2; break;
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2211
		case 2:  w->left = _screen.width - w->width; break;
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2212
		default: w->left = 0;
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2213
	}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2214
	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
  2215
	return w->left;
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2216
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2217
9407
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2218
void SetVScrollCount(Window *w, int num)
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2219
{
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2220
	w->vscroll.count = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2221
	num -= w->vscroll.cap;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2222
	if (num < 0) num = 0;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2223
	if (num < w->vscroll.pos) w->vscroll.pos = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2224
}
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2225
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2226
void SetVScroll2Count(Window *w, int num)
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2227
{
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2228
	w->vscroll2.count = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2229
	num -= w->vscroll2.cap;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2230
	if (num < 0) num = 0;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2231
	if (num < w->vscroll2.pos) w->vscroll2.pos = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2232
}
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2233
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2234
void SetHScrollCount(Window *w, int num)
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2235
{
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2236
	w->hscroll.count = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2237
	num -= w->hscroll.cap;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2238
	if (num < 0) num = 0;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2239
	if (num < w->hscroll.pos) w->hscroll.pos = num;
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2240
}
079a6bf07bae (svn r13318) -Codechange: move some functions from gui.h/misc_gui.cpp to window_gui.h/window.cpp because they belong there.
rubidium
parents: 9354
diff changeset
  2241
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2242
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2243
 * Relocate all windows to fit the new size of the game application screen
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2244
 * @param neww New width of the game application screen
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2245
 * @param newh New height of the game appliction screen
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8698
diff changeset
  2246
 */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2247
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2248
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2249
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2250
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2251
	FOR_ALL_WINDOWS(wz) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2252
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2253
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2254
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2255
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2256
			ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2257
			vp->width = w->width = neww;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2258
			vp->height = w->height = newh;
6626
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  2259
			vp->virtual_width = ScaleByZoom(neww, vp->zoom);
207875b9069a (svn r9846) -Codechange: introduced ZOOM_LVL_MIN and ZOOM_LVL_MAX for the obvious reasons
truelight
parents: 6624
diff changeset
  2260
			vp->virtual_height = ScaleByZoom(newh, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2261
			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
  2262
		}
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
  2263
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2264
		/* XXX - this probably needs something more sane. For example specying
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2265
		 * in a 'backup'-desc that the window should always be centred. */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2266
		switch (w->window_class) {
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2267
			case WC_MAIN_TOOLBAR:
7362
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2268
				if (neww - w->width != 0) {
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2269
					ResizeWindow(w, min(neww, 640) - w->width, 0);
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2270
9166
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2271
					Point size;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2272
					Point delta;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2273
					size.x = w->width;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2274
					size.y = w->height;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2275
					delta.x = neww - w->width;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2276
					delta.y = 0;
dce886fc5eeb (svn r13029) -Codechange: more work in the road to getting the WP macros and byte[WINDOW_CUSTOM_SIZE] removed. This step changes the event handling to work directly on the Window class instead of via a function pointer and big switches while keeping backward compatability while we're rewriting the Windows to the new scheme.
rubidium
parents: 9165
diff changeset
  2277
					w->OnResize(size, delta);
7362
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2278
				}
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2279
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2280
				top = w->top;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2281
				left = PositionMainToolbar(w); // changes toolbar orientation
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2282
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2283
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2284
			case WC_SELECT_GAME:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2285
			case WC_GAME_OPTIONS:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2286
			case WC_NETWORK_WINDOW:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2287
				top = (newh - w->height) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2288
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2289
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2290
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2291
			case WC_NEWS_WINDOW:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2292
				top = newh - w->height;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2293
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2294
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2295
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2296
			case WC_STATUS_BAR:
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7918
diff changeset
  2297
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2298
				top = newh - w->height;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2299
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2300
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2301
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2302
			case WC_SEND_NETWORK_MSG:
7922
a7e266f966d9 (svn r11475) -Codechange: rename clamp and clampu to Clamp and ClampU to fit with the coding style
skidd13
parents: 7918
diff changeset
  2303
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2304
				top = (newh - 26); // 26 = height of status bar + height of chat bar
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2305
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2306
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2307
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2308
			case WC_CONSOLE:
5143
43f7b9457827 (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2309
				IConsoleResize(w);
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  2310
				continue;
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2311
8698
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2312
			default: {
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2313
				left = w->left;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2314
				if (left + (w->width >> 1) >= neww) left = neww - w->width;
8023
0753dcefda8f (svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents: 8019
diff changeset
  2315
				if (left < 0) left = 0;
0753dcefda8f (svn r11583) -Fix [FS#1484]: windows could get completely missing when one resized the window to something very small.
rubidium
parents: 8019
diff changeset
  2316
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2317
				top = w->top;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2318
				if (top + (w->height >> 1) >= newh) top = newh - w->height;
8698
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2319
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2320
				const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2321
				if (wt != NULL) {
8940
afe7bc9fcc6e (svn r12714) -Fix [FS#1904]: do not move windows below the toolbar on resizes unless they would go behind the toolbar.
rubidium
parents: 8925
diff changeset
  2322
					if (top < wt->height && wt->left < (w->left + w->width) && (wt->left + wt->width) > w->left) top = wt->height;
8698
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2323
					if (top >= newh) top = newh - 1;
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2324
				} else {
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2325
					if (top < 0) top = 0;
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2326
				}
67bf6670f66e (svn r12371) -Fix [FS#1823]: do not let window hide behind the main toolbar after resizing the screen
smatz
parents: 8586
diff changeset
  2327
			} break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2328
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2329
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2330
		if (w->viewport != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2331
			w->viewport->left += left - w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2332
			w->viewport->top += top - w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2333
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2334
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2335
		w->left = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2336
		w->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2337
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2338
}
9267
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2339
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2340
/** Destructor of the base class PickerWindowBase
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2341
 * Main utility is to stop the base Window destructor from triggering
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2342
 * a free while the child will already be free, in this case by the ResetObjectToPlace().
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2343
 */
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2344
PickerWindowBase::~PickerWindowBase()
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2345
{
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2346
	this->window_class = WC_INVALID; // stop the ancestor from freeing the already (to be) child
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2347
	ResetObjectToPlace();
22095cc802dd (svn r13133) -Codechange: Add a base class (descending from Window) for all new windows that are going to require a ResetObjectToPlace to be performed on closing.
belugas
parents: 9264
diff changeset
  2348
}