src/window.cpp
author rubidium
Tue, 25 Dec 2007 11:26:07 +0000
changeset 8131 160939e24ed3
parent 8130 d2eb7d04f6e1
child 8139 4e91c448c409
permissions -rw-r--r--
(svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
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
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
     3
/** @file window.cpp windowing system, widgets and events */
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"
679
04ca2cd69420 (svn r1117) Move map arrays and some related macros into their own files map.c and map.h
tron
parents: 651
diff changeset
     9
#include "map.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2026
diff changeset
    10
#include "player.h"
152
c3964b43943e (svn r153) -Feature: [1009710] Extra Viewport. In the minimap dropdown menu, open a new viewport to have a quick look at your favorite map-positions. Independent zoom and quick jump to/from viewport (Dribbel)
darkvater
parents: 136
diff changeset
    11
#include "viewport.h"
126
152df0cc4ac2 (svn r127) New feature: ingame console. (sign_de)
dominik
parents: 116
diff changeset
    12
#include "console.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2154
diff changeset
    13
#include "variables.h"
2517
6e3832ddd0f6 (svn r3046) Replace some numbers with sprite names and fix a typo in the sprite list
tron
parents: 2436
diff changeset
    14
#include "table/sprites.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"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
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
    21
/* delta between mouse cursor and upper left corner of dragged window */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    22
static Point _drag_delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
    23
8068
41569ce2d1d9 (svn r11629) -Fix [FS#1527]: many viewports could crash the scenario editor.
rubidium
parents: 8036
diff changeset
    24
static Window _windows[MAX_NUMBER_OF_WINDOWS];
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    25
Window *_z_windows[lengthof(_windows)];
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
    26
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
    27
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
    28
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
    29
{
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
    30
	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
    31
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
    32
	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
    33
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
    34
	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
    35
		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
    36
		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
    37
	}
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
    38
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
    39
	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
    40
}
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
    41
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
    42
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
    43
{
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
    44
	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
    45
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
    46
	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
    47
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
    48
	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
    49
		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
    50
		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
    51
	}
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
    52
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
    53
	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
    54
}
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
    55
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
    56
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
    57
{
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
    58
	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
    59
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
    60
	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
    61
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
	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
    63
		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
    64
		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
    65
	}
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
	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
    68
}
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
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
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
    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
	uint i;
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
	for (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
    75
		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
    76
			this->RaiseWidget(i);
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
    77
			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
    78
		}
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
    79
	}
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
    80
}
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
    81
8026
a188ea8201ce (svn r11586) -Fix: make another widget 'accessor' function const when it should be const.
glx
parents: 8023
diff changeset
    82
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
    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
	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
    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
	/* 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
    87
	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
    88
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
	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
    90
}
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
8035
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
    92
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
    93
{
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
    94
	this->LowerWidget(widget);
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
    95
	this->flags4 |= 5 << WF_TIMEOUT_SHL;
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
    96
	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
    97
}
8c76ea0d84ab (svn r11595) -Codechange: add a new member to Window struct, based on its function counterpart HandleButtonClick.
belugas
parents: 8033
diff changeset
    98
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
    99
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
   100
static void StartWindowSizing(Window *w);
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   101
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
   102
static void DispatchLeftClickEvent(Window *w, int x, int y, bool double_click)
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
   103
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
	const Widget *wi;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   107
	e.we.click.pt.x = x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   108
	e.we.click.pt.y = y;
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
   109
	e.event = double_click ? WE_DOUBLE_CLICK : WE_CLICK;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
	if (w->desc_flags & WDF_DEF_WIDGET) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   112
		e.we.click.widget = GetWidgetFromPos(w, x, y);
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
   113
		if (e.we.click.widget < 0) return; // exit if clicked outside of widgets
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   114
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
   115
		/* don't allow any interaction if the button has been disabled */
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7993
diff changeset
   116
		if (w->IsWidgetDisabled(e.we.click.widget)) return;
222
b88456001397 (svn r223) -Fix: Const correctness and miscellaneous fixes. Thank you Tron for your diligent fixing of warnings (and some possibly bugs) (Tron)
darkvater
parents: 211
diff changeset
   117
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
   118
		wi = &w->widget[e.we.click.widget];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   120
		if (wi->type & WWB_MASK) {
211
2954c4b30525 (svn r212) -Fix: Network-gui fixes (sign_de)
darkvater
parents: 193
diff changeset
   121
			/* special widget handling for buttons*/
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   122
			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
   123
				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
   124
				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
   125
				case WWT_TEXTBTN | WWB_PUSHBUTTON: /* WWT_PUSHTXTBTN */
8036
279f4cbf9ec7 (svn r11596) -Codechange: Use the Window member HandleButtonClick and remove its now useless counterpart function
belugas
parents: 8035
diff changeset
   126
					w->HandleButtonClick(e.we.click.widget);
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4766
diff changeset
   127
					break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   128
			}
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
   129
		} else if (wi->type == WWT_SCROLLBAR || wi->type == WWT_SCROLL2BAR || wi->type == WWT_HSCROLLBAR) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   130
			ScrollbarClickHandler(w, wi, e.we.click.pt.x, e.we.click.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   131
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   132
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   133
		if (w->desc_flags & WDF_STD_BTN) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   134
			if (e.we.click.widget == 0) { /* 'X' */
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   135
				DeleteWindow(w);
984
2ff5fb62658a (svn r1481) -Fix: [ 1099891 ] Added a return in DispatchLeftClickEvent which prevents reading of free'd memory (tamlin)
celestar
parents: 983
diff changeset
   136
				return;
1109
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   137
			}
ecb98f43ba2c (svn r1610) Remove trailing whitespace (last time ever, i hope)
tron
parents: 1101
diff changeset
   138
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   139
			if (e.we.click.widget == 1) { /* 'Title bar' */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   140
				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
   141
				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
   142
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   143
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   144
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
   145
		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
   146
			StartWindowSizing(w);
8028
e578ea22f371 (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8026
diff changeset
   147
			w->InvalidateWidget(e.we.click.widget);
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   148
			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
   149
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   150
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   151
		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
   152
			w->flags4 ^= WF_STICKY;
8028
e578ea22f371 (svn r11588) -Codechange: use the new member introduced in r11551
glx
parents: 8026
diff changeset
   153
			w->InvalidateWidget(e.we.click.widget);
1112
d8503ef77898 (svn r1613) -Fix: WE_CLICK event is not called on default actions. If special action is needed, use the other events like WE_RESIZE or WE_DESTROY, etc.
darkvater
parents: 1109
diff changeset
   154
			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
   155
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   156
	}
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
   157
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
   158
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   159
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   161
static void DispatchRightClickEvent(Window *w, int x, int y)
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
   162
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   164
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   165
	/* default tooltips handler? */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   166
	if (w->desc_flags & WDF_STD_TOOLTIPS) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   167
		e.we.click.widget = GetWidgetFromPos(w, x, y);
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   168
		if (e.we.click.widget < 0)
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
   169
			return; // exit if clicked outside of widgets
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   170
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   171
		if (w->widget[e.we.click.widget].tooltips != 0) {
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   172
			GuiShowTooltips(w->widget[e.we.click.widget].tooltips);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   173
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   174
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   175
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   176
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   177
	e.event = WE_RCLICK;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   178
	e.we.click.pt.x = x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
   179
	e.we.click.pt.y = y;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   180
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   181
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   182
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   183
/** Dispatch the mousewheel-action to the window which will scroll any
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   184
 * compatible scrollbars if the mouse is pointed over the bar or its contents
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   185
 * @param *w Window
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   186
 * @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
   187
 * @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
   188
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   189
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
   190
{
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
   191
	const Widget *wi1, *wi2;
982
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   192
	Scrollbar *sb;
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   193
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
   194
	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
   195
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
   196
	wi1 = &w->widget[widget];
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   197
	wi2 = &w->widget[widget + 1];
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1980
diff changeset
   198
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
   199
	/* 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
   200
	 * 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
   201
	 * 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
   202
	 * not happening until someone rewrites the whole widget-code */
1019
6bae6c11e865 (svn r1520) Trim 134 (!) lines with trailing whitespace ):
tron
parents: 999
diff changeset
   203
	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
   204
			(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
   205
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
   206
		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
   207
			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
   208
			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
   209
				sb->pos = pos;
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   210
				SetWindowDirty(w);
d3ce4d6a65f8 (svn r1478) -Fix: [1099195] mouse-wheel in train replace window. Scrollbar1 and Scrollbar2 now work independently. You can only scroll on list and scrollbar itself; scrollbar must be next widget of the list.
darkvater
parents: 959
diff changeset
   211
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   213
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   214
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   216
static void DrawOverlappedWindow(Window* const *wz, int left, int top, int right, int bottom);
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   217
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   218
void DrawOverlappedWindowForAll(int left, int top, int right, int bottom)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   220
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
	DrawPixelInfo bk;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	_cur_dpi = &bk;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   224
	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
   225
		const Window *w = *wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   226
		if (right > w->left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
				bottom > w->top &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
				left < w->left + w->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
				top < w->top + w->height) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   230
			DrawOverlappedWindow(wz, left, top, right, bottom);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   231
		}
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
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   235
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
   236
{
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
   237
	Window* const *vz = wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	int x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   240
	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
   241
		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
   242
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
		if (right > v->left &&
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
   244
				bottom > v->top &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
				left < v->left + v->width &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
				top < v->top + v->height) {
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   247
			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
   248
				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
   249
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   253
			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
   254
				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
   255
				DrawOverlappedWindow(wz, x, top, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   256
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   259
			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
   260
				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
   261
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6481
diff changeset
   265
			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
   266
				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
   267
				DrawOverlappedWindow(wz, left, x, right, bottom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
				return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
			return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
	{
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   276
		DrawPixelInfo *dp = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
		dp->width = right - left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
		dp->height = bottom - top;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   279
		dp->left = left - (*wz)->left;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   280
		dp->top = top - (*wz)->top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
		dp->pitch = _screen.pitch;
6937
40c760fcf1f6 (svn r10190) -Codechange: merged renderer and blitter to one single class API: blitter
truelight
parents: 6878
diff changeset
   282
		dp->dst_ptr = BlitterFactoryBase::GetCurrentBlitter()->MoveTo(_screen.dst_ptr, left, top);
6624
880e29b1f25e (svn r9844) -Codechange: replace zoomlevel with an enum
truelight
parents: 6532
diff changeset
   283
		dp->zoom = ZOOM_LVL_NORMAL;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   284
		CallWindowEventNP(*wz, WE_PAINT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   287
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
void CallWindowEventNP(Window *w, int event)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
	WindowEvent e;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
   291
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
	e.event = event;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   296
void SetWindowDirty(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
{
2549
5587f9a38563 (svn r3078) Some more stuff, which piled up:
tron
parents: 2517
diff changeset
   298
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   299
	SetDirtyBlocks(w->left, w->top, w->left + w->width, w->top + w->height);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   302
/** 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
   303
 * @param w parent Window to find child of
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   304
 * @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
   305
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
   306
{
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   307
	Window* const *wz;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   308
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   309
	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
   310
		Window *v = *wz;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   311
		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
   312
	}
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   313
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   314
	return NULL;
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   315
}
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   316
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   317
/** 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
   318
 * or the behaviour is undefined but function should never fail
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   319
 * @param w window to query Z Position
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   320
 * @return the window that matches it */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   321
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
   322
{
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   323
	Window **wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   324
5429
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   325
	for (wz = _z_windows; wz != _last_z_window; wz++) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   326
		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
   327
	}
5429
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   328
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   329
	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
   330
		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
   331
	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
   332
}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   333
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   334
void DeleteWindow(Window *w)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   335
{
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   336
	Window *v;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   337
	Window **wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   338
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   339
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   340
	/* Delete any children a window might have in a head-recursive manner */
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   341
	v = FindChildWindow(w);
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   342
	if (v != NULL) DeleteWindow(v);
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   343
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   344
	if (_thd.place_mode != VHM_NONE &&
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   345
			_thd.window_class == w->window_class &&
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
   346
			_thd.window_number == w->window_number) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   347
		ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   348
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   349
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
	CallWindowEventNP(w, WE_DESTROY);
5122
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5121
diff changeset
   351
	if (w->viewport != NULL) DeleteWindowViewport(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
	SetWindowDirty(w);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   354
	free(w->widget);
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   355
	w->widget = NULL;
5232
d099cc0d7961 (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   356
	w->widget_count = 0;
5415
60e096e4818d (svn r7618) -Feature: Add support for a parent<>child relationship in Window terms. A child
Darkvater
parents: 5413
diff changeset
   357
	w->parent = NULL;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   358
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   359
	/* Find the window in the z-array, and effectively remove it
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   360
	 * by moving all windows after it one to the left */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   361
	wz = FindWindowZPosition(w);
5429
a664da42d64e (svn r7635) -Fix (r7618, r7621): Guard against recursive deletion. It is possible that when a
Darkvater
parents: 5416
diff changeset
   362
	if (wz == NULL) return;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   363
	memmove(wz, wz + 1, (byte*)_last_z_window - (byte*)wz);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   364
	_last_z_window--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
Window *FindWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   369
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   371
	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
   372
		Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   373
		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
   374
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   376
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
void DeleteWindowById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   380
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   381
	DeleteWindow(FindWindowById(cls, number));
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   382
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   383
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
   384
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
   385
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   386
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   387
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
   388
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
   389
	/* 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
   390
	 * 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
   391
	 * 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
   392
	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
   393
		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
   394
		if (w->window_class == cls) {
647f65adeb9e (svn r1497) -Fix: [1101179] Crash if generating land while industry window is open. This also happened for towns and the land information window
darkvater
parents: 984
diff changeset
   395
			DeleteWindow(w);
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   396
			goto restart_search;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   397
		}
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
   398
	}
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
   399
}
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
   400
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   401
/** Delete all windows of a player. We identify windows of a player
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   402
 * by looking at the caption colour. If it is equal to the player ID
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   403
 * then we say the window belongs to the player and should be deleted
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   404
 * @param id PlayerID player identifier */
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   405
void DeletePlayerWindows(PlayerID id)
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   406
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   407
	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
   408
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
   409
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
   410
	/* 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
   411
	 * 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
   412
	 * 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
   413
	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
   414
		Window *w = *wz;
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   415
		if (w->caption_color == id) {
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   416
			DeleteWindow(w);
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
   417
			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
   418
		}
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
   419
	}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   420
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   421
	/* Also delete the player specific windows, that don't have a player-colour */
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   422
	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
   423
}
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   424
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   425
/** Change the owner of all the windows one player can take over from another
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   426
 * player in the case of a company merger. Do not change ownership of windows
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   427
 * that need to be deleted once takeover is complete
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   428
 * @param old_player PlayerID of original owner of the window
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   429
 * @param new_player PlayerID of the new owner of the window */
5077
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   430
void ChangeWindowOwner(PlayerID old_player, PlayerID new_player)
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   431
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   432
	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
   433
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   434
	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
   435
		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
   436
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
   437
		if (w->caption_color != old_player)      continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   438
		if (w->window_class == WC_PLAYER_COLOR)  continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   439
		if (w->window_class == WC_FINANCES)      continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   440
		if (w->window_class == WC_STATION_LIST)  continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   441
		if (w->window_class == WC_TRAINS_LIST)   continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   442
		if (w->window_class == WC_ROADVEH_LIST)  continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   443
		if (w->window_class == WC_SHIPS_LIST)    continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   444
		if (w->window_class == WC_AIRCRAFT_LIST) continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   445
		if (w->window_class == WC_BUY_COMPANY)   continue;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   446
		if (w->window_class == WC_COMPANY)       continue;
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   447
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
   448
		w->caption_color = new_player;
5a601eb01735 (svn r7138) -Fix: [vehicle list windows] fixed a rare crash where having some (not all) vehicle list windows open for a player, that goes bankrupt would crash the game
bjarni
parents: 5072
diff changeset
   449
	}
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
   450
}
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
   451
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   452
static void BringWindowToFront(const Window *w);
2817
cdf488223c23 (svn r3365) Staticise 36 functions
tron
parents: 2816
diff changeset
   453
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   454
/** 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
   455
 * 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
   456
 * @param cls WindowClass of the window to activate
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   457
 * @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
   458
 * @return a pointer to the window thus activated */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   459
Window *BringWindowToFrontById(WindowClass cls, WindowNumber number)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   460
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
	Window *w = FindWindowById(cls, number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
	if (w != NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
		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
   465
		BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
		SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   469
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   470
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   472
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
   473
{
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   474
	WindowClass wc = w->window_class;
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   475
	return (wc == WC_MAIN_TOOLBAR || wc == WC_STATUS_BAR || wc == WC_NEWS_WINDOW || wc == WC_SEND_NETWORK_MSG);
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   476
}
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   477
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   478
/** 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
   479
 * 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
   480
 * - 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
   481
 * - 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
   482
 * 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
   483
 * @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
   484
 * @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
   485
 */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   486
static void BringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   487
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   488
	Window *tempz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   489
	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
   490
	Window **vz = _last_z_window;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   491
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   492
	/* Bring the window just below the vital windows */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   493
	do {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   494
		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
   495
	} while (IsVitalWindow(*vz));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   496
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   497
	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
   498
	assert(wz < vz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   499
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   500
	tempz = *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   501
	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
   502
	*vz = tempz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   503
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   504
	SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   506
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   507
/** 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
   508
 * 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
   509
 * - 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
   510
 * - 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
   511
 * - 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
   512
 * @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
   513
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   514
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
   515
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   516
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   517
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   518
	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
   519
		Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   520
		if (w->window_class != WC_MAIN_WINDOW && !IsVitalWindow(w) && !(w->flags4 & WF_STICKY)) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   521
			return w;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   522
		}
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
   523
	}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   524
	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
   525
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   526
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   527
/** 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
   528
 * 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
   529
 * 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
   530
 * 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
   531
 * @see FindDeletableWindow()
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   532
 * @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
   533
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   534
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
   535
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   536
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   537
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   538
	for (wz = _z_windows;; wz++) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   539
		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
   540
		assert(wz < _last_z_window);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   541
		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
   542
	}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   543
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
   544
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   545
bool IsWindowOfPrototype(const Window *w, const Widget *widget)
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   546
{
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   547
	return (w->original_widget == widget);
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   548
}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   549
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   550
/** Copies 'widget' to 'w->widget' to allow for resizable windows
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   551
 * @param w Window on which to attach the widget array
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   552
 * @param widget pointer of widget array to fill the window with */
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   553
void AssignWidgetToWindow(Window *w, const Widget *widget)
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   554
{
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   555
	w->original_widget = widget;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   556
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   557
	if (widget != NULL) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   558
		uint index = 1;
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
   559
		const Widget *wi;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   560
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   561
		for (wi = widget; wi->type != WWT_LAST; wi++) index++;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   562
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   563
		w->widget = ReallocT(w->widget, index);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   564
		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
   565
		w->widget_count = index - 1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   566
	} else {
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   567
		w->widget = NULL;
5232
d099cc0d7961 (svn r7352) -Codechange: add widget_count parameter to the window.
rubidium
parents: 5198
diff changeset
   568
		w->widget_count = 0;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   569
	}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   570
}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   571
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   572
static Window *FindFreeWindow()
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   573
{
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   574
	Window *w;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   575
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   576
	for (w = _windows; w < endof(_windows); w++) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   577
		Window* const *wz;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   578
		bool window_in_use = false;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   579
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   580
		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
   581
			if (*wz == w) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   582
				window_in_use = true;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   583
				break;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   584
			}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   585
		}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   586
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   587
		if (!window_in_use) return w;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   588
	}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   589
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   590
	assert(_last_z_window == endof(_z_windows));
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   591
	return NULL;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   592
}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   593
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   594
/** Open a new window.
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   595
 * This function is called from AllocateWindow() or AllocateWindowDesc()
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   596
 * 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
   597
 * See AllocateWindow() for description of arguments.
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   598
 * 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
   599
 * @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
   600
 * @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
   601
 * @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
   602
 * @param min_height minimum height 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
   603
 * @param def_width default 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
   604
 * @param def_height default height in pixels of the window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   605
 * @param *proc see WindowProc function to call when any messages/updates happen to the window
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   606
 * @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
   607
 * @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
   608
 * @param window_number number being assigned to the new window
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   609
 * @param data the data to be given during the WE_CREATE message
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   610
 * @return Window pointer of the newly created window */
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   611
static Window *LocalAllocateWindow(
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
   612
							int x, int y, int min_width, int min_height, int def_width, int def_height,
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   613
							WindowProc *proc, WindowClass cls, const Widget *widget, int window_number, void *data)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
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
	Window *w = FindFreeWindow();
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
	/* We have run out of windows, close one and use that as the place for our new one */
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   618
	if (w == NULL) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   619
		w = FindDeletableWindow();
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   620
		if (w == NULL) w = ForceFindDeletableWindow();
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   621
		DeleteWindow(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   622
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   623
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
   624
	/* Set up window properties */
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   625
	memset(w, 0, sizeof(*w));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   626
	w->window_class = cls;
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
   627
	w->flags4 = WF_WHITE_BORDER_MASK; // just opened windows have a white border
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   628
	w->caption_color = 0xFF;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   629
	w->left = x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   630
	w->top = y;
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
   631
	w->width = min_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
   632
	w->height = min_height;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   633
	w->wndproc = proc;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   634
	AssignWidgetToWindow(w, widget);
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
   635
	w->resize.width = min_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
   636
	w->resize.height = min_height;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   637
	w->resize.step_width = 1;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
   638
	w->resize.step_height = 1;
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   639
	w->window_number = window_number;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   640
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   641
	{
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   642
		Window **wz = _last_z_window;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   643
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   644
		/* Hacky way of specifying always-on-top windows. These windows are
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   645
		 * always above other windows because they are moved below them.
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   646
		 * status-bar is above news-window because it has been created earlier.
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   647
		 * Also, as the chat-window is excluded from this, it will always be
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   648
		 * the last window, thus always on top.
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   649
		 * XXX - Yes, ugly, probably needs something like w->always_on_top flag
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   650
		 * to implement correctly, but even then you need some kind of distinction
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   651
		 * between on-top of chat/news and status windows, because these conflict */
7068
b7340338ea66 (svn r10333) -Fix [FS#943]: News messages were shown on top of the endgame screen and high score chart.
rubidium
parents: 7018
diff changeset
   652
		if (wz != _z_windows && w->window_class != WC_SEND_NETWORK_MSG && w->window_class != WC_HIGHSCORE && w->window_class != WC_ENDSCREEN) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   653
			if (FindWindowById(WC_MAIN_TOOLBAR, 0)     != NULL) wz--;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   654
			if (FindWindowById(WC_STATUS_BAR, 0)       != NULL) wz--;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   655
			if (FindWindowById(WC_NEWS_WINDOW, 0)      != NULL) wz--;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   656
			if (FindWindowById(WC_SEND_NETWORK_MSG, 0) != NULL) wz--;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   657
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   658
			assert(wz >= _z_windows);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   659
			if (wz != _last_z_window) memmove(wz + 1, wz, (byte*)_last_z_window - (byte*)wz);
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   660
		}
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   661
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   662
		*wz = w;
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   663
		_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
   664
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   665
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   666
	WindowEvent e;
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   667
	e.event = WE_CREATE;
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   668
	e.we.create.data = data;
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   669
	w->wndproc(w, &e);
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
   670
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
   671
	/* 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
   672
	 * 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
   673
	 * 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
   674
	 * 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
   675
	 * can then determine the real minimum size of the window. */
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
   676
	if (w->width != def_width || w->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
   677
		/* 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
   678
		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
   679
		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
   680
		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
   681
		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
   682
		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
   683
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
   684
		int enlarge_x = max(min(def_width  - w->width,  _screen.width - w->width),  0);
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
   685
		int enlarge_y = max(min(def_height - w->height, free_height   - w->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
   686
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   687
		/* 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
   688
		 * 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
   689
		 * unsigned int, which won't work. */
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   690
		if (w->resize.step_width  > 1) enlarge_x -= enlarge_x % (int)w->resize.step_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
   691
		if (w->resize.step_height > 1) enlarge_y -= enlarge_y % (int)w->resize.step_height;
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   692
02515d0d4ced (svn r10704) -Codechange: provide an infrastructure to have resizable windows that are smaller than the default window size.
rubidium
parents: 7301
diff changeset
   693
		ResizeWindow(w, 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
   694
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
   695
		WindowEvent e;
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
   696
		e.event = WE_RESIZE;
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
   697
		e.we.sizing.size.x = w->width;
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
   698
		e.we.sizing.size.y = w->height;
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
   699
		e.we.sizing.diff.x = enlarge_x;
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
   700
		e.we.sizing.diff.y = enlarge_y;
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
   701
		w->wndproc(w, &e);
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
   702
	}
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
   703
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
   704
	int nx = w->left;
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
   705
	int ny = w->top;
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
   706
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
   707
	if (nx + w->width > _screen.width) nx -= (nx + w->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
   708
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
   709
	const Window *wt = FindWindowById(WC_MAIN_TOOLBAR, 0);
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
   710
	ny = max(ny, (wt == NULL || w == wt || y == 0) ? 0 : wt->height);
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
   711
	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
   712
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
   713
	if (w->viewport != NULL) {
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
   714
		w->viewport->left += nx - w->left;
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
   715
		w->viewport->top  += ny - w->top;
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
   716
	}
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
   717
	w->left = nx;
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
   718
	w->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
   719
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   720
	SetWindowDirty(w);
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
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   723
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   724
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   725
/**
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   726
 * 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
   727
 * 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
   728
 * 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
   729
 * 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
   730
 * @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
   731
 * @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
   732
 * @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
   733
 * @param height height in pixels of the window
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   734
 * @param *proc see WindowProc function to call when any messages/updates happen to the window
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   735
 * @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
   736
 * @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
   737
 * @return Window pointer of the newly created window */
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   738
Window *AllocateWindow(
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   739
							int x, int y, int width, int height,
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   740
							WindowProc *proc, WindowClass cls, const Widget *widget, void *data)
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   741
{
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   742
	return LocalAllocateWindow(x, y, width, height, width, height, proc, cls, widget, 0, data);
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   743
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   744
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   745
struct SizeRect {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   746
	int left,top,width,height;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   747
};
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   748
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   749
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   750
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
   751
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   752
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   753
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   754
	int right  = width + left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   755
	int bottom = height + top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   756
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   757
	if (left < 0 || top < 22 || right > _screen.width || bottom > _screen.height)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   758
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   759
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
   760
	/* 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
   761
	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
   762
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   763
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   764
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   765
		if (right > w->left &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   766
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   767
				bottom > w->top &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   768
				w->top + w->height > top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   769
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   770
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   771
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   772
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   773
	pos.x = left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   774
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   775
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   776
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   777
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   778
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
   779
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   780
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   781
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   782
	if (left < -(width>>2) || left > _screen.width - (width>>1)) return false;
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   783
	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
   784
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
   785
	/* 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
   786
	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
   787
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   788
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   789
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   790
		if (left + width > w->left &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   791
				w->left + w->width > left &&
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   792
				top + height > w->top &&
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   793
				w->top + w->height > top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   794
			return false;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   795
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   796
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   797
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   798
	pos.x = left;
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   799
	pos.y = top;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   800
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   801
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   802
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   803
static Point GetAutoPlacePosition(int width, int height)
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 1093
diff changeset
   804
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   805
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   806
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   807
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   808
	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
   809
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   810
	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
   811
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   812
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   813
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   814
		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
   815
		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
   816
		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
   817
		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
   818
		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
   819
		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
   820
		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
   821
		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
   822
	}
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   823
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   824
	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
   825
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   826
		if (w->window_class == WC_MAIN_WINDOW) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   827
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   828
		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
   829
		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
   830
		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
   831
		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
   832
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   833
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   834
	{
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   835
		int left = 0, top = 24;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   836
6532
034c5077ab16 (svn r9720) -Codechange: Remove global var and gotos from window autoplacement
peter1138
parents: 6492
diff changeset
   837
restart:
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   838
		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
   839
			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
   840
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   841
			if (w->left == left && w->top == top) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   842
				left += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   843
				top += 5;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   844
				goto restart;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   845
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   846
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
   847
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   848
		pt.x = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   849
		pt.y = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   850
		return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   851
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   852
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   853
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
   854
/**
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
   855
 * Set the x and y coordinates of a 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
   856
 *
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
   857
 * @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
   858
 * @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
   859
 * @param data          arbitrary data that is send with the WE_CREATE message
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
   860
 *
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
   861
 * @return see Window pointer of the newly created 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
   862
 */
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   863
static Window *LocalAllocateWindowDesc(const WindowDesc *desc, int window_number, void *data)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   864
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   865
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   866
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   867
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   868
	/* By default position a child window at an offset of 10/10 of its parent.
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
   869
	 * With the exception of WC_BUILD_TOOLBAR (build railway/roads/ship docks/airports)
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
   870
	 * and WC_SCEN_LAND_GEN (landscaping). Whose child window has an offset of 0/36 of
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
   871
	 * its parent. So it's exactly under the parent toolbar and no buttons will be covered.
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   872
	 * However if it falls too extremely outside window positions, reposition
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   873
	 * it to an automatic place */
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
   874
	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
   875
			(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
   876
			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
   877
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
   878
		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
   879
		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
   880
			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
   881
		}
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
   882
		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
   883
	} else {
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   884
		switch (desc->left) {
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   885
			case WDP_ALIGN_TBR: { /* Align the right side with the top toolbar */
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   886
				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
   887
				pt.x = (w->left + w->width) - desc->default_width;
6492
286a52449b54 (svn r9673) -Cleanup: remove spaces before tabs and replace non-indenting tabs with spaces.
rubidium
parents: 6491
diff changeset
   888
			} break;
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   889
			case WDP_ALIGN_TBL: /* Align the left side with the top toolbar */
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   890
				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
   891
				break;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   892
			case WDP_AUTO: /* Find a good automatic position for the window */
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
   893
				pt = GetAutoPlacePosition(desc->default_width, desc->default_height);
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   894
				goto allocate_window;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   895
			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
   896
				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
   897
				break;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   898
			default:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   899
				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
   900
				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
   901
		}
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   902
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   903
		switch (desc->top) {
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   904
			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
   905
				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
   906
				break;
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   907
			/* 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
   908
			 * 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
   909
			case WDP_AUTO:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   910
				NOT_REACHED();
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   911
				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
   912
				/* fallthrough */
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   913
			default:
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   914
				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
   915
				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
   916
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   917
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   918
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   919
5072
69195f96a23a (svn r7130) -Codechange: Handle the positioning of windows through the desc->left/top settings with
Darkvater
parents: 5071
diff changeset
   920
allocate_window:
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   921
	w = LocalAllocateWindow(pt.x, pt.y, desc->minimum_width, desc->minimum_height, desc->default_width, desc->default_height, desc->proc, desc->cls, desc->widgets, window_number, data);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   922
	w->desc_flags = desc->flags;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   923
	return w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   924
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   925
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   926
/**
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   927
 * Open a new window.
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   928
 * @param *desc The pointer to the WindowDesc to be created
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   929
 * @param data arbitrary data that is send with the WE_CREATE message
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   930
 * @return Window pointer of the newly created window
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   931
 */
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   932
Window *AllocateWindowDesc(const WindowDesc *desc, void *data)
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   933
{
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   934
	return LocalAllocateWindowDesc(desc, 0, data);
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   935
}
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   936
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   937
/**
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   938
 * Open a new window.
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   939
 * @param *desc The pointer to the WindowDesc to be created
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   940
 * @param window_number the window number of the new window
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   941
 * @param data arbitrary data that is send with the WE_CREATE message
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   942
 * @return see Window pointer of the newly created window
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   943
 */
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   944
Window *AllocateWindowDescFront(const WindowDesc *desc, int window_number, void *data)
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   945
{
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   946
	Window *w;
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   947
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   948
	if (BringWindowToFrontById(desc->cls, window_number)) return NULL;
7367
cafca0510781 (svn r10730) -Codechange: allow (some) arbitrary data to be send to the WE_CREATE event.
rubidium
parents: 7364
diff changeset
   949
	w = LocalAllocateWindowDesc(desc, window_number, data);
4520
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   950
	return w;
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   951
}
98f1b167d0ca (svn r6345) -Codechange: AllocateWindowDescFront() now ensures that window_number is set before calling the WE_CREATE event
bjarni
parents: 4337
diff changeset
   952
5120
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
   953
/** 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
   954
 * 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
   955
 * @param x position x to query
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
   956
 * @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
   957
 * @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
   958
Window *FindWindowFromPt(int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   959
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   960
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   961
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   962
	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
   963
		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
   964
		if (IsInsideBS(x, w->left, w->width) && IsInsideBS(y, w->top, w->height)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   965
			return w;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
   966
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   967
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   968
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   969
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   970
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   971
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   972
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
   973
{
136
78ac8de2b2b8 (svn r137) Fix: console sometime didn't open (sign_de)
dominik
parents: 126
diff changeset
   974
	IConsoleClose();
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   975
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   976
	memset(&_windows, 0, sizeof(_windows));
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   977
	_last_z_window = _z_windows;
5122
3aa375cb5e8e (svn r7202) -Codechange: Move _viewports and _active_viewports local to viewport.c and have them
Darkvater
parents: 5121
diff changeset
   978
	InitViewports();
1397
fa8539dcab46 (svn r1901) - Fix: unwanted behaviour of the savegame dialog, as well as a bug with a sloppy termination of a string. When any editbox is open, scrolling is disabled. If any new types of editboxes come up, please use SET/CLRBIT of _no_scroll with its unique identifier (ttd.h)
Darkvater
parents: 1299
diff changeset
   979
	_no_scroll = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   980
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   981
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
   982
void UnInitWindowSystem()
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   983
{
5413
21f75917d589 (svn r7616) -Cleanup:
Darkvater
parents: 5380
diff changeset
   984
	Window **wz;
5642
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   985
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   986
restart_search:
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   987
	/* Delete all windows, reset z-array.
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   988
	 *When we find the window to delete, we need to restart the search
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   989
	 * as deleting this window could cascade in deleting (many) others
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   990
	 * anywhere in the z-array. We call DeleteWindow() so that it can properly
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   991
	 * release own alloc'd memory, which otherwise could result in memleaks */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
   992
	FOR_ALL_WINDOWS(wz) {
5642
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   993
		DeleteWindow(*wz);
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   994
		goto restart_search;
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   995
	}
5642
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   996
5d4dec6baa29 (svn r8101) -Fix (runknown): Plug potential memleaks when calling UnInitWindowSystem. The function directly deleted all windows instead of calling their respective deallocators which could then in turn any used memory.
Darkvater
parents: 5609
diff changeset
   997
	assert(_last_z_window == _z_windows);
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   998
}
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
   999
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1000
void ResetWindowSystem()
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1001
{
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1002
	UnInitWindowSystem();
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1003
	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
  1004
	_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
  1005
	_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
  1006
	_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
  1007
	_thd.new_pos.y = 0;
1474
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1008
}
a26a21fa10ef (svn r1978) - Fix: Plug some memleaks; thanks Valgrind
Darkvater
parents: 1397
diff changeset
  1009
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1010
static void DecreaseWindowCounters()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1011
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1012
	Window *w;
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1013
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1014
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1015
	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
  1016
		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
  1017
		/* Unclick scrollbar buttons if they are pressed. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1018
		if (w->flags4 & (WF_SCROLL_DOWN | WF_SCROLL_UP)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1019
			w->flags4 &= ~(WF_SCROLL_DOWN | WF_SCROLL_UP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1020
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1021
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1022
		CallWindowEventNP(w, WE_MOUSELOOP);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1023
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1024
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1025
	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
  1026
		w = *--wz;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1027
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1028
		if (w->flags4&WF_TIMEOUT_MASK && !(--w->flags4&WF_TIMEOUT_MASK)) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1029
			CallWindowEventNP(w, WE_TIMEOUT);
8032
f35fba9bacb0 (svn r11592) -Codechange: Use the Window member RaiseButtons and remove the now useless RaiseWindowButtons function
belugas
parents: 8031
diff changeset
  1030
			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
  1031
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1034
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1035
Window *GetCallbackWnd()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
	return FindWindowById(_thd.window_class, _thd.window_number);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1039
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1040
static void HandlePlacePresize()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1041
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1042
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1043
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1044
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1045
	if (_special_mouse_mode != WSM_PRESIZE) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1046
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1047
	w = GetCallbackWnd();
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1048
	if (w == NULL) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1050
	e.we.place.pt = GetTileBelowCursor();
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1051
	if (e.we.place.pt.x == -1) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1052
		_thd.selend.x = -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
		return;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1054
	}
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1055
	e.we.place.tile = TileVirtXY(e.we.place.pt.x, e.we.place.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
	e.event = WE_PLACE_PRESIZE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
	w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1058
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1060
static bool HandleDragDrop()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1065
	if (_special_mouse_mode != WSM_DRAGDROP) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1067
	if (_left_button_down) return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1068
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	w = GetCallbackWnd();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1071
	ResetObjectToPlace();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1073
	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
  1074
		/* send an event in client coordinates. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
		e.event = WE_DRAGDROP;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1076
		e.we.dragdrop.pt.x = _cursor.pos.x - w->left;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1077
		e.we.dragdrop.pt.y = _cursor.pos.y - w->top;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1078
		e.we.dragdrop.widget = GetWidgetFromPos(w, e.we.dragdrop.pt.x, e.we.dragdrop.pt.y);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
		w->wndproc(w, &e);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1084
static bool HandlePopupMenu()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
	WindowEvent e;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1089
	if (!_popup_menu_active) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	w = FindWindowById(WC_TOOLBAR_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	if (w == NULL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	if (_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
		e.event = WE_POPUPMENU_OVER;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1099
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
		_popup_menu_active = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
		e.event = WE_POPUPMENU_SELECT;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1103
		e.we.popupmenu.pt = _cursor.pos;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1104
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1105
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
  1106
	w->wndproc(w, &e);
fb62bb1c424f (svn r1539) -Fix: [1103271] free'd memory used. Moved w->wndproc(w, &e) to end of function. Thanks for finding this tamlin.
darkvater
parents: 1033
diff changeset
  1107
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1111
static bool HandleMouseOver()
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1112
{
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1113
	Window *w;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1114
	WindowEvent e;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1115
	static Window *last_w = NULL;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1116
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1117
	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1118
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
  1119
	/* We changed window, put a MOUSEOVER event to the last window */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1120
	if (last_w != NULL && last_w != w) {
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1121
		e.event = WE_MOUSEOVER;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1122
		e.we.mouseover.pt.x = -1;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1123
		e.we.mouseover.pt.y = -1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1124
		if (last_w->wndproc) last_w->wndproc(last_w, &e);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1125
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1126
	last_w = w;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1127
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1128
	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
  1129
		/* send an event in client coordinates. */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1130
		e.event = WE_MOUSEOVER;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1131
		e.we.mouseover.pt.x = _cursor.pos.x - w->left;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1132
		e.we.mouseover.pt.y = _cursor.pos.y - w->top;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1133
		if (w->widget != NULL) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1134
			e.we.mouseover.widget = GetWidgetFromPos(w, e.we.mouseover.pt.x, e.we.mouseover.pt.y);
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1135
		}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1136
		w->wndproc(w, &e);
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1137
	}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1138
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
  1139
	/* Mouseover never stops execution */
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1140
	return true;
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1141
}
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1142
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1143
/** Update all the widgets of a window based on their resize flags
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1144
 * 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
  1145
 * ensuring proper redrawal.
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1146
 * @param w Window to resize
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6443
diff changeset
  1147
 * @param x delta x-size of changed window (positive if larger, etc.)
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1148
 * @param y delta y-size of changed window */
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1149
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
  1150
{
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1151
	Widget *wi;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1152
	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
  1153
	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
  1154
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1155
	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
  1156
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1157
	SetWindowDirty(w);
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1158
	for (wi = w->widget; wi->type != WWT_LAST; wi++) {
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1159
		/* 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
  1160
		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
  1161
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1162
		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
  1163
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1164
		/* 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
  1165
		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
  1166
			wi->left += x;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1167
			resize_width = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1168
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1169
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1170
		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
  1171
			wi->right += x;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1172
			resize_width = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1173
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1174
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1175
		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
  1176
			wi->top += y;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1177
			resize_height = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1178
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1179
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1180
		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
  1181
			wi->bottom += y;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1182
			resize_height = true;
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1183
		}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1184
	}
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1185
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1186
	/* 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
  1187
	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
  1188
	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
  1189
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1190
	SetWindowDirty(w);
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1191
}
2596
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1192
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1193
static bool _dragging_window;
07cecb439908 (svn r3133) - static, const
tron
parents: 2549
diff changeset
  1194
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1195
static bool HandleWindowDragging()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1196
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1197
	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
  1198
	/* Get out immediately if no window is being dragged at all. */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1199
	if (!_dragging_window) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1200
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
  1201
	/* 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
  1202
	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
  1203
		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
  1204
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1205
		if (w->flags4 & WF_DRAGGING) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1206
			const Widget *t = &w->widget[1]; // the title bar ... ugh
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1207
			const Window *v;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1208
			int x;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1209
			int y;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1210
			int nx;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1211
			int ny;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1212
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
  1213
			/* 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
  1214
			if (!_left_button_down) {
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1215
				w->flags4 &= ~WF_DRAGGING;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
				break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1221
			x = _cursor.pos.x + _drag_delta.x;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1222
			y = _cursor.pos.y + _drag_delta.y;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1223
			nx = x;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1224
			ny = y;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1225
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1226
			if (_patches.window_snap_radius != 0) {
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1227
				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
  1228
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1229
				int hsnap = _patches.window_snap_radius;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1230
				int vsnap = _patches.window_snap_radius;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1231
				int delta;
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1232
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1233
				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
  1234
					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
  1235
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1236
					if (v == w) continue; // Don't snap at yourself
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1237
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1238
					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
  1239
						/* Your left border <-> other right border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1240
						delta = abs(v->left + v->width - x);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1241
						if (delta <= hsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1242
							nx = v->left + v->width;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1243
							hsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1244
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1245
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
  1246
						/* Your right border <-> other left border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1247
						delta = abs(v->left - x - w->width);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1248
						if (delta <= hsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1249
							nx = v->left - w->width;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1250
							hsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1251
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1252
					}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1253
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1254
					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
  1255
						/* Your left border <-> other left border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1256
						delta = abs(v->left - x);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1257
						if (delta <= hsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1258
							nx = v->left;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1259
							hsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1260
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1261
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
  1262
						/* Your right border <-> other right border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1263
						delta = abs(v->left + v->width - x - w->width);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1264
						if (delta <= hsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1265
							nx = v->left + v->width - w->width;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1266
							hsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1267
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1268
					}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1269
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1270
					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
  1271
						/* Your top border <-> other bottom border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1272
						delta = abs(v->top + v->height - y);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1273
						if (delta <= vsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1274
							ny = v->top + v->height;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1275
							vsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1276
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1277
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
  1278
						/* Your bottom border <-> other top border */
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1279
						delta = abs(v->top - y - w->height);
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1280
						if (delta <= vsnap) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1281
							ny = v->top - w->height;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1282
							vsnap = delta;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1283
						}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1284
					}
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1285
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1286
					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
  1287
						/* Your top border <-> other top border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1288
						delta = abs(v->top - y);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1289
						if (delta <= vsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1290
							ny = v->top;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1291
							vsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1292
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1293
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
  1294
						/* Your bottom border <-> other bottom border */
353
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1295
						delta = abs(v->top + v->height - y - w->height);
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1296
						if (delta <= vsnap) {
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1297
							ny = v->top + v->height - w->height;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1298
							vsnap = delta;
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1299
						}
6d5f81e332c8 (svn r541) Make windows even snappier! ^^
tron
parents: 350
diff changeset
  1300
					}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1301
				}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1302
			}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1303
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
  1304
			/* 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
  1305
			 * 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
  1306
			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
  1307
			ny = Clamp(ny, 0, _screen.height - 13);
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1308
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
  1309
			/* Make sure the title bar isn't hidden by behind the main tool bar */
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1310
			v = FindWindowById(WC_MAIN_TOOLBAR, 0);
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1311
			if (v != NULL) {
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1312
				int v_bottom = v->top + v->height;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1313
				int v_right = v->left + v->width;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1314
				if (ny + t->top >= v->top && ny + t->top < v_bottom) {
371
be6daee0afa3 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1315
					if ((v->left < 13 && nx + t->left < v->left) ||
be6daee0afa3 (svn r559) Minor simplification
tron
parents: 370
diff changeset
  1316
							(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
  1317
						ny = v_bottom;
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1318
					} else {
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1319
						if (nx + t->left > v->left - 13 &&
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1320
								nx + t->right < v_right + 13) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1321
							if (w->top >= v_bottom) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1322
								ny = v_bottom;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1323
							} else if (w->left < nx) {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1324
								nx = v->left - 13 - t->left;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1325
							} else {
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1326
								nx = v_right + 13 - t->right;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1327
							}
370
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1328
						}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1329
					}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1330
				}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1331
			}
dc2452392ce4 (svn r558) -Fix: [ 1065247 ] Windows can be placed behind toolbar
tron
parents: 353
diff changeset
  1332
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1333
			if (w->viewport != NULL) {
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1334
				w->viewport->left += nx - w->left;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1335
				w->viewport->top  += ny - w->top;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1336
			}
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1337
			w->left = nx;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1338
			w->top  = ny;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1339
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1340
			SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1341
			return false;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1342
		} 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
  1343
			WindowEvent e;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1344
			int x, y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1345
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1346
			/* 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
  1347
			if (!_left_button_down) {
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1348
				w->flags4 &= ~WF_SIZING;
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1648
diff changeset
  1349
				SetWindowDirty(w);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1350
				break;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1351
			}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1352
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1353
			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
  1354
			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
  1355
2675
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1356
			/* 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
  1357
			 * 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
  1358
			 * unsigned int, which won't work. */
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1359
			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
  1360
2675
010fe459fc1d (svn r3217) Fix issue with resizing stepped windows introduced in revision 3181.
peter1138
parents: 2643
diff changeset
  1361
			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
  1362
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1363
			/* 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
  1364
			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
  1365
				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
  1366
			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
  1367
				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
  1368
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1369
			/* Window already on size */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1370
			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
  1371
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1372
			/* 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
  1373
			    we move in steps. */
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1374
			_drag_delta.x += x;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1375
			_drag_delta.y += y;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1376
5268
e2625c661000 (svn r7409) -Codechange: Make the ResizeWindow function also available outside of window.c. This makes
Darkvater
parents: 5236
diff changeset
  1377
			/* 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
  1378
			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
  1379
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1380
			e.event = WE_RESIZE;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1381
			e.we.sizing.size.x = x + w->width;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1382
			e.we.sizing.size.y = y + w->height;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1383
			e.we.sizing.diff.x = x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1384
			e.we.sizing.diff.y = y;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1385
			w->wndproc(w, &e);
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1386
			return false;
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
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1389
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1390
	_dragging_window = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1391
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1392
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1393
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1394
static void StartWindowDrag(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1395
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1396
	w->flags4 |= WF_DRAGGING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1397
	_dragging_window = true;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1398
350
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1399
	_drag_delta.x = w->left - _cursor.pos.x;
36f4ee00d0b6 (svn r538) -Feature: Windows snap at each other
tron
parents: 222
diff changeset
  1400
	_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
  1401
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1402
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1403
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1404
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1405
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1406
static void StartWindowSizing(Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1407
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1408
	w->flags4 |= WF_SIZING;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1409
	_dragging_window = true;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1410
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 857
diff changeset
  1411
	_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
  1412
	_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
  1413
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1414
	BringWindowToFront(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1415
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1417
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1418
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1419
static bool HandleScrollbarScrolling()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1420
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1421
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1422
	int i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1423
	int pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1424
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1425
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
  1426
	/* Get out quickly if no item is being scrolled */
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1427
	if (!_scrolling_scrollbar) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1428
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
  1429
	/* 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
  1430
	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
  1431
		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
  1432
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1433
		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
  1434
			/* Abort if no button is clicked any more. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
			if (!_left_button_down) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1436
				w->flags4 &= ~WF_SCROLL_MIDDLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1437
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1438
				break;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1439
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1440
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1441
			if (w->flags4 & WF_HSCROLL) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1442
				sb = &w->hscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1443
				i = _cursor.pos.x - _cursorpos_drag_start.x;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1444
			} else if (w->flags4 & WF_SCROLL2){
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1445
				sb = &w->vscroll2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 763
diff changeset
  1446
				i = _cursor.pos.y - _cursorpos_drag_start.y;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1447
			} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1448
				sb = &w->vscroll;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1449
				i = _cursor.pos.y - _cursorpos_drag_start.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1450
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1451
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
  1452
			/* Find the item we want to move to and make sure it's inside bounds. */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1453
			pos = min(max(0, i + _scrollbar_start_pos) * sb->count / _scrollbar_size, max(0, sb->count - sb->cap));
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1454
			if (pos != sb->pos) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1455
				sb->pos = pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1456
				SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
			return false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1459
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1461
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1462
	_scrolling_scrollbar = false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
	return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1464
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1465
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1466
static bool HandleViewportScroll()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1467
{
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
  1468
	WindowEvent e;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1470
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1471
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _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
  1472
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1473
	if (!_scrolling_viewport) return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1474
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
  1475
	w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
02934874f33d (svn r6036) -Codechange: do not handle SCROLL in a central function, but let windows handle them theirself. Added WE_SCROLL for this.
truelight
parents: 4300
diff changeset
  1476
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
  1477
	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
  1478
		_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
  1479
		_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
  1480
		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
  1481
	}
e82c1fca64ee (svn r11405) -Fix: in rare cases OpenTTD could segfault when resizing and scroll the main window (Rafal Rzepecki)
truelight
parents: 7759
diff changeset
  1482
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
  1483
	if (WP(w, vp_d).follow_vehicle != INVALID_VEHICLE && w == FindWindowById(WC_MAIN_WINDOW, 0)) {
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
  1484
		/* If the main window is following a vehicle, then first let go of it! */
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
  1485
		const Vehicle *veh = GetVehicle(WP(w, vp_d).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
  1486
		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
  1487
		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
  1488
	}
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
  1489
2680
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1490
	if (_patches.reverse_scroll) {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1491
		e.we.scroll.delta.x = -_cursor.delta.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1492
		e.we.scroll.delta.y = -_cursor.delta.y;
2680
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1493
	} else {
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1494
		e.we.scroll.delta.x = _cursor.delta.x;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1495
		e.we.scroll.delta.y = _cursor.delta.y;
2680
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1496
	}
7fd99282368c (svn r3222) -Feature: Right-Click-Scrolling optionally moves in the opposite direction (Requested by manx)
tron
parents: 2675
diff changeset
  1497
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1498
	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
  1499
		/* We are using scrollwheels for scrolling */
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1500
		e.we.scroll.delta.x = _cursor.h_wheel;
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1501
		e.we.scroll.delta.y = _cursor.v_wheel;
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1502
		_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
  1503
		_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
  1504
	}
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1505
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
  1506
	/* Create a scroll-event and send it to the window */
4337
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1507
	e.event = WE_SCROLL;
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1508
	w->wndproc(w, &e);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1509
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1510
	_cursor.delta.x = 0;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1511
	_cursor.delta.y = 0;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  1512
	return false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1513
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1514
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1515
/** 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
  1516
 * 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
  1517
 * 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
  1518
 * 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
  1519
 * 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
  1520
 * 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
  1521
 * @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
  1522
 * @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
  1523
static bool MaybeBringWindowToFront(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1524
{
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1525
	bool bring_to_front = false;
5137
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1526
	Window* const *wz;
54425dc8b5b3 (svn r7219) -Fix: Several warnings by gcc introduced in r7206 which MSVC found not of a problem. Thanks Tron
Darkvater
parents: 5126
diff changeset
  1527
	Window* const *uz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1528
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1529
	if (w->window_class == WC_MAIN_WINDOW ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1530
			IsVitalWindow(w) ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1531
			w->window_class == WC_TOOLTIPS ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1532
			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
  1533
		return true;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1534
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1535
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1536
	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
  1537
	for (uz = wz; ++uz != _last_z_window;) {
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1538
		Window *u = *uz;
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1539
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1540
		/* 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
  1541
		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
  1542
			u->flags4 |= WF_WHITE_BORDER_MASK;
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1543
			SetWindowDirty(u);
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1544
			return false;
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1545
		}
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1546
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1547
		if (u->window_class == WC_MAIN_WINDOW ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1548
				IsVitalWindow(u) ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1549
				u->window_class == WC_TOOLTIPS ||
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1550
				u->window_class == WC_DROPDOWN_MENU) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1551
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1552
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1553
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1554
		/* 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
  1555
		if (w->left + w->width <= u->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1556
				u->left + u->width <= w->left ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1557
				w->top  + w->height <= u->top ||
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1558
				u->top + u->height <= w->top) {
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1559
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1560
		}
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1561
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1562
		bring_to_front = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1563
	}
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1564
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1565
	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
  1566
	return true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1567
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1568
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1569
/** Send a message from one window to another. The receiving window is found by
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  1570
 * @param w Window pointer pointing to the other window
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1571
 * @param msg Specifies the message to be sent
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1572
 * @param wparam Specifies additional message-specific information
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1573
 * @param lparam Specifies additional message-specific information
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1574
 */
4171
5c6e60c392c3 (svn r5609) CodeChange : Apply coding style
belugas
parents: 4077
diff changeset
  1575
static void SendWindowMessageW(Window *w, uint msg, uint wparam, uint lparam)
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1576
{
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1577
	WindowEvent e;
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1578
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1579
	e.event             = WE_MESSAGE;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1580
	e.we.message.msg    = msg;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1581
	e.we.message.wparam = wparam;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1582
	e.we.message.lparam = lparam;
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1583
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1584
	w->wndproc(w, &e);
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1585
}
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1586
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1587
/** Send a message from one window to another. The receiving window is found by
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
  1588
 * @param wnd_class see WindowClass class AND
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
  1589
 * @param wnd_num see WindowNumber number, mostly 0
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1590
 * @param msg Specifies the message to be sent
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1591
 * @param wparam Specifies additional message-specific information
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1592
 * @param lparam Specifies additional message-specific information
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1593
 */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1594
void SendWindowMessage(WindowClass wnd_class, WindowNumber wnd_num, int msg, int wparam, int lparam)
1648
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1595
{
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1596
	Window *w = FindWindowById(wnd_class, wnd_num);
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1597
	if (w != NULL) SendWindowMessageW(w, msg, wparam, lparam);
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1598
}
41c3d5de9994 (svn r2152) - Fix: Chatbar in MP games is now on-top of the news window.
darkvater
parents: 1645
diff changeset
  1599
5043
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1600
/** Send a message from one window to another. The message will be sent
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1601
 * to ALL windows of the windowclass specified in the first parameter
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
  1602
 * @param wnd_class see WindowClass class
5043
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1603
 * @param msg Specifies the message to be sent
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1604
 * @param wparam Specifies additional message-specific information
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1605
 * @param lparam Specifies additional message-specific information
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1606
 */
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
  1607
void SendWindowMessageClass(WindowClass wnd_class, int msg, int wparam, int lparam)
5043
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1608
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1609
	Window* const *wz;
5043
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1610
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1611
	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
  1612
		if ((*wz)->window_class == wnd_class) SendWindowMessageW(*wz, msg, wparam, lparam);
5043
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1613
	}
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1614
}
948d79587b11 (svn r7092) -Codechange: Add function to send a window message to a whole class of windows,
Darkvater
parents: 4962
diff changeset
  1615
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1616
/** Handle keyboard input.
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1617
 * @param key Lower 8 bits contain the ASCII character, the higher
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1618
 * 16 bits the keycode */
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1619
void HandleKeypress(uint32 key)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1620
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1621
	Window* const *wz;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1622
	WindowEvent e;
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1623
	/* 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
  1624
	 * 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
  1625
	 * to thein this main toolbar. */
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1626
	bool query_open = false;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1627
5086
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1628
	/*
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1629
	* 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
  1630
	* 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
  1631
	* a road. To not interfere with those tasks, we should
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1632
	* NOT change the _current_player here.
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1633
	*
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1634
	* 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
  1635
	* 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
  1636
	*/
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1637
	if (!IsGeneratingWorld()) _current_player = _local_player;
386ba9fe0621 (svn r7153) -Fix [FS#279]: Some keyboard events possibly lost under high CPU load, handle
Darkvater
parents: 5077
diff changeset
  1638
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
  1639
	/* Setup event */
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1640
	e.event = WE_KEYPRESS;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5090
diff changeset
  1641
	e.we.keypress.key     = GB(key,  0, 16);
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1642
	e.we.keypress.keycode = GB(key, 16, 16);
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1643
	e.we.keypress.cont = true;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1644
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1645
	/* 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
  1646
	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
  1647
			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
  1648
			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
  1649
			FindWindowById(WC_CONSOLE,                 0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1650
			FindWindowById(WC_SAVELOAD,                0) != NULL ||
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1651
			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
  1652
		query_open = true;
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1653
	}
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1654
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
  1655
	/* Call the event, start with the uppermost window. */
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1656
	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
  1657
		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
  1658
8019
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1659
		/* 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
  1660
		if (query_open &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1661
				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
  1662
				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
  1663
				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
  1664
				w->window_class != WC_CONSOLE &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1665
				w->window_class != WC_SAVELOAD &&
fc0e94dee165 (svn r11579) -Revert(r11578): some cases of key propagation are not handled correctly.
belugas
parents: 8018
diff changeset
  1666
				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
  1667
			continue;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1668
		}
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1669
		w->wndproc(w, &e);
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1670
		if (!e.we.keypress.cont) break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1671
	}
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
  1672
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1673
	if (e.we.keypress.cont) {
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1674
		Window *w = FindWindowById(WC_MAIN_TOOLBAR, 0);
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
  1675
		/* When there is no toolbar w is null, check for that */
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4549
diff changeset
  1676
		if (w != NULL) w->wndproc(w, &e);
1642
1678f11897cc (svn r2146) - Fix: [ 1175973 ] Crash if any key is pressed in startup (pkirchhofer)
matthijs
parents: 1637
diff changeset
  1677
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1678
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1679
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1680
extern void UpdateTileSelection();
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1681
extern bool VpHandlePlaceSizingDrag();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1682
5090
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1683
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
  1684
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1685
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
  1686
{
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1687
	Window *w;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1688
	ViewPort *vp;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1689
	int x = _cursor.pos.x;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1690
	int y = _cursor.pos.y;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1691
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1692
	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
  1693
		/* 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
  1694
		_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
  1695
		/* 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
  1696
		return;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1697
	}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1698
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1699
	if (_patches.autoscroll && _game_mode != GM_MENU && !IsGeneratingWorld()) {
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1700
		w = FindWindowFromPt(x, y);
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1701
		if (w == NULL || w->flags4 & WF_DISABLE_VP_SCROLL) return;
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1702
		vp = IsPtInWindowViewport(w, x, y);
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1703
		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
  1704
			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
  1705
			y -= vp->top;
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
  1706
			/* 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
  1707
#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
  1708
			if (x - 15 < 0) {
7301
f0c5513d706d (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7190
diff changeset
  1709
				WP(w, vp_d).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
  1710
			} else if (15 - (vp->width - x) > 0) {
7301
f0c5513d706d (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7190
diff changeset
  1711
				WP(w, vp_d).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
  1712
			}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1713
			if (y - 15 < 0) {
7301
f0c5513d706d (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7190
diff changeset
  1714
				WP(w, vp_d).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
  1715
			} else if (15 - (vp->height - y) > 0) {
7301
f0c5513d706d (svn r10649) -Fix (r9962): autoscroll (pointer near screen edge) didn't work
peter1138
parents: 7190
diff changeset
  1716
				WP(w, vp_d).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
  1717
			}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1718
#undef scrollspeed
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1719
		}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1720
	}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1721
}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1722
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1723
enum MouseClick {
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1724
	MC_NONE = 0,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1725
	MC_LEFT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1726
	MC_RIGHT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1727
	MC_DOUBLE_LEFT,
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1728
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
  1729
	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
  1730
	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
  1731
};
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1732
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1733
void MouseLoop(MouseClick click, int mousewheel)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1734
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1735
	int x,y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1736
	Window *w;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1737
	ViewPort *vp;
6289
9f468eccc674 (svn r9111) -Feature: [OSX] mighty mice and touchpads can now scroll the map (in all directions)
bjarni
parents: 6248
diff changeset
  1738
	bool scrollwheel_scrolling = _patches.scrollwheel_scrolling == 1 && (_cursor.v_wheel != 0 || _cursor.h_wheel != 0);
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1739
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1740
	DecreaseWindowCounters();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1741
	HandlePlacePresize();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1742
	UpdateTileSelection();
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1743
	if (!VpHandlePlaceSizingDrag())  return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1744
	if (!HandleDragDrop())           return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1745
	if (!HandlePopupMenu())          return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1746
	if (!HandleWindowDragging())     return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1747
	if (!HandleScrollbarScrolling()) return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1748
	if (!HandleViewportScroll())     return;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1749
	if (!HandleMouseOver())          return;
543
946badd71033 (svn r942) -Merged branch/network back into the trunk
truelight
parents: 410
diff changeset
  1750
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1751
	x = _cursor.pos.x;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1752
	y = _cursor.pos.y;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1753
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1754
	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
  1755
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1756
	w = FindWindowFromPt(x, y);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1757
	if (w == NULL) return;
5416
b9a3326da943 (svn r7619) -Feature (Internal): Add support for modal children. It's a window-child that
Darkvater
parents: 5415
diff changeset
  1758
	if (!MaybeBringWindowToFront(w)) return;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1759
	vp = IsPtInWindowViewport(w, x, y);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1760
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
  1761
	/* 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
  1762
	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
  1763
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
  1764
	if (mousewheel != 0) {
6296
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1765
		if (_patches.scrollwheel_scrolling == 0) {
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1766
			/* Scrollwheel is in zoom mode. Make the zoom event. */
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1767
			WindowEvent e;
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
  1768
6296
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1769
			/* Send WE_MOUSEWHEEL event to window */
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1770
			e.event = WE_MOUSEWHEEL;
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1771
			e.we.wheel.wheel = mousewheel;
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1772
			w->wndproc(w, &e);
a6bed59002c6 (svn r9126) -Feature: "Function of scrollwheel" can now be set to off as well
bjarni
parents: 6290
diff changeset
  1773
		}
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
  1774
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1775
		/* 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
  1776
		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
  1777
	}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1778
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1779
	if (vp != NULL) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1780
		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
  1781
		switch (click) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1782
			case MC_DOUBLE_LEFT:
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1783
			case MC_LEFT:
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  1784
				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
  1785
				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
  1786
						/* 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
  1787
						_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
  1788
						_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
  1789
						_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
  1790
						!_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
  1791
					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
  1792
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1793
7918
970e7c5005e5 (svn r11471) -Codechange: one more variable retyped to enum ViewportHighlightMode
smatz
parents: 7855
diff changeset
  1794
				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
  1795
					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
  1796
				} 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
  1797
					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
  1798
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1799
				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
  1800
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1801
			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
  1802
				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
  1803
					_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
  1804
					_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
  1805
				}
e705eef174bf (svn r6038) -Codechange: move mousewheel code to event WE_MOUSEWHEEL instead of a general function that handles that
truelight
parents: 4335
diff changeset
  1806
				break;
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1807
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1808
			default:
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1809
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1810
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1811
	} else {
2631
2ed0eb408229 (svn r3173) Use the trinary operator and switch to improve readability
tron
parents: 2630
diff changeset
  1812
		switch (click) {
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1813
			case MC_DOUBLE_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, true);
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1814
				/* fallthough, and also give a single-click for backwards compatible */
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1815
			case MC_LEFT: DispatchLeftClickEvent(w, x - w->left, y - w->top, false); break;
6290
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1816
			default:
a3ca06710eeb (svn r9112) -Feature r9111: scrollwheel scrolling can now also scroll the smallmap
bjarni
parents: 6289
diff changeset
  1817
				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
  1818
				/* 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
  1819
				* 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
  1820
				/* fallthough */
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1821
			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
  1822
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1823
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1824
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1825
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1826
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
  1827
{
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1828
	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
  1829
	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
  1830
	static int double_click_y = 0;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1831
	MouseClick click;
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
  1832
	int mousewheel;
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1833
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1834
	/*
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1835
	 * 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
  1836
	 * 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
  1837
	 * a road. To not interfere with those tasks, we should
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1838
	 * NOT change the _current_player here.
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1839
	 *
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1840
	 * 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
  1841
	 * 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
  1842
	 */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4171
diff changeset
  1843
	if (!IsGeneratingWorld()) _current_player = _local_player;
1570
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1844
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
  1845
	/* Mouse event? */
7009
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1846
	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
  1847
	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
  1848
		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
  1849
		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
  1850
			  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
  1851
			  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
  1852
			click = MC_DOUBLE_LEFT;
9992ccf17e58 (svn r10265) -Feature: allow double-clicking on certain places: build-vehicle and town-action
truelight
parents: 6937
diff changeset
  1853
		}
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
  1854
		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
  1855
		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
  1856
		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
  1857
		_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
  1858
		_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
  1859
	} 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
  1860
		_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
  1861
		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
  1862
		_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
  1863
	}
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
  1864
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
  1865
	mousewheel = 0;
c9b6cf44ce53 (svn r2074) MouseLoop -> InputLoop(), factor out a real mouse-specific MouseLoop from the new InitLoop() (more in the spirit of HandleKeypress()).
pasky
parents: 1474
diff changeset
  1866
	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
  1867
		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
  1868
		_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
  1869
		_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
  1870
	}
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
  1871
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
  1872
	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
  1873
}
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
  1874
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1875
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
  1876
{
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1877
	HandleMouseEvents();
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1878
	HandleAutoscroll();
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1879
}
67446a4104f7 (svn r7157) -Fix [FS#221, SF1168820]: Some mouse events possibly lost under high CPU load, handle
Darkvater
parents: 5089
diff changeset
  1880
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1881
void UpdateWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1882
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1883
	Window* const *wz;
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1884
	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
  1885
	int t = we4_timer + 1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1886
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1887
	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
  1888
		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
  1889
			CallWindowEventNP(*--wz, WE_4);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1890
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1891
		t = 0;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1892
	}
5089
67c761427921 (svn r7156) -Codechange: Remove obsolete variable, localize global variable, use GB and change logic
Darkvater
parents: 5086
diff changeset
  1893
	we4_timer = t;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1894
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1895
	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
  1896
		Window *w = *--wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1897
		if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1898
			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
  1899
1ff65e874ce3 (svn r7200) -Codechange: remove unneeded redraw (console.c), coding style, use FindWindowById
Darkvater
parents: 5108
diff changeset
  1900
			if (!(w->flags4 & WF_WHITE_BORDER_MASK)) SetWindowDirty(w);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1901
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1902
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1903
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1904
	DrawDirtyBlocks();
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1905
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1906
	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
  1907
		if ((*wz)->viewport != NULL) UpdateViewportPosition(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1908
	}
7454
e55eea8c05c7 (svn r10932) -Codechange: replace "text" with "chat" for the chat related function and variables.
rubidium
parents: 7367
diff changeset
  1909
	DrawChatMessage();
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
  1910
	/* Redraw mouse cursor in case it was hidden */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1911
	DrawMouseCursor();
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  1912
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1913
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1914
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2216
diff changeset
  1915
int GetMenuItemIndex(const Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1916
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1917
	if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1918
		y /= 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1919
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1920
		if (y < WP(w, const menu_d).item_count &&
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7922
diff changeset
  1921
				!HasBit(WP(w, const menu_d).disabled_items, y)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1922
			return y;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1923
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1924
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1925
	return -1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1926
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1927
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1928
void InvalidateWindow(WindowClass cls, WindowNumber number)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1929
{
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
  1930
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1931
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1932
	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
  1933
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1934
		if (w->window_class == cls && w->window_number == number) SetWindowDirty(w);
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
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1938
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
  1939
{
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
  1940
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1941
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1942
	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
  1943
		const Window *w = *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1944
		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
  1945
			w->InvalidateWidget(widget_index);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1946
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1947
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1948
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1949
2788
0187c588107e (svn r3336) byte -> WindowClass, uint16 -> WindowNumber
tron
parents: 2703
diff changeset
  1950
void InvalidateWindowClasses(WindowClass cls)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1951
{
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
  1952
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1953
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1954
	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
  1955
		if ((*wz)->window_class == cls) SetWindowDirty(*wz);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1956
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1957
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1958
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
  1959
void InvalidateThisWindowData(Window *w)
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1960
{
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
  1961
	CallWindowEventNP(w, WE_INVALIDATE_DATA);
5198
7046e5b0b5bc (svn r7313) -Codechange: Calling invalidate data on a window will surely warrant a redraw, so call
Darkvater
parents: 5143
diff changeset
  1962
	SetWindowDirty(w);
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1963
}
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
  1964
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1965
void InvalidateWindowData(WindowClass cls, WindowNumber number)
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1966
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1967
	Window* const *wz;
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1968
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1969
	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
  1970
		Window *w = *wz;
4766
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1971
		if (w->window_class == cls && w->window_number == number) InvalidateThisWindowData(w);
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1972
	}
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
  1973
}
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
  1974
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
  1975
void InvalidateWindowClassesData(WindowClass cls)
aa276d0ec2eb (svn r6680) -Codechange r6679: [train build window] only generate the list when the window data is invalidated or the window is generated, not on each redraw
bjarni
parents: 4757
diff changeset
  1976
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1977
	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
  1978
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1979
	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
  1980
		if ((*wz)->window_class == cls) InvalidateThisWindowData(*wz);
4739
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1981
	}
e626ef1b522e (svn r6651) -Coding feature: added the windowevent WE_INVALIDATE_DATA
bjarni
parents: 4719
diff changeset
  1982
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1983
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1984
void CallWindowTickEvent()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1985
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1986
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1987
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1988
	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
  1989
		CallWindowEventNP(*--wz, WE_TICK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1990
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1991
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1992
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  1993
void DeleteNonVitalWindows()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1994
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  1995
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  1996
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
  1997
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
  1998
	/* 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
  1999
	 * 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
  2000
	 * 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
  2001
	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
  2002
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2003
		if (w->window_class != WC_MAIN_WINDOW &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2004
				w->window_class != WC_SELECT_GAME &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2005
				w->window_class != WC_MAIN_TOOLBAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2006
				w->window_class != WC_STATUS_BAR &&
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2007
				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
  2008
				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
  2009
				(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
  2010
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2011
			DeleteWindow(w);
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2012
			goto restart_search;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2013
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2014
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2015
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2016
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  2017
/** 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
  2018
 * '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
  2019
 * 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
  2020
 * 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
  2021
 * 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
  2022
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
  2023
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2024
	Window* const *wz;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2025
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
  2026
	/* 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
  2027
	DeleteNonVitalWindows();
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2028
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
  2029
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
  2030
	/* 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
  2031
	 * 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
  2032
	 * 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
  2033
	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
  2034
		if ((*wz)->flags4 & WF_STICKY) {
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2035
			DeleteWindow(*wz);
5121
e45de1152730 (svn r7201) -Codechange: Use goto's to loop _windows when there is a change you need to start over
Darkvater
parents: 5120
diff changeset
  2036
			goto restart_search;
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2037
		}
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
  2038
	}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2039
}
ced9fcae239d (svn r1225) -Feature: SHIFT+DEL now deletes all non-vital windows (only status bar and main bar remain)
darkvater
parents: 682
diff changeset
  2040
6443
63fbe9f76801 (svn r9580) -Documentation: Correction of doxygen function declarations
belugas
parents: 6432
diff changeset
  2041
/** Delete all always on-top windows to get an empty screen */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6231
diff changeset
  2042
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
  2043
{
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
  2044
	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
  2045
	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
  2046
	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
  2047
}
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
  2048
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2049
int PositionMainToolbar(Window *w)
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2050
{
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5272
diff changeset
  2051
	DEBUG(misc, 5, "Repositioning Main Toolbar...");
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2052
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2053
	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
  2054
		w = FindWindowById(WC_MAIN_TOOLBAR, 0);
4077
d4d440dd8925 (svn r5391) Miscellaneous, mostly bracing and whitespace, nothing spectacular
tron
parents: 4000
diff changeset
  2055
	}
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2056
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2057
	switch (_patches.toolbar_pos) {
5071
e28106dfcb6f (svn r7129) -Codechange: Get rid of a global variable that only sets a window's number.
Darkvater
parents: 5043
diff changeset
  2058
		case 1:  w->left = (_screen.width - w->width) / 2; break;
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2059
		case 2:  w->left = _screen.width - w->width; break;
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
  2060
		default: w->left = 0;
68
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2061
	}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2062
	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
  2063
	return w->left;
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2064
}
4051f3c8efa2 (svn r69) -Feature: align toolbar left/center/right patch (TrueLight)
darkvater
parents: 67
diff changeset
  2065
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2066
void RelocateAllWindows(int neww, int newh)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2067
{
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2068
	Window* const *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2069
5124
2ca62776430e (svn r7205) -Fix [FS#350, SF#1560913]: Window allocation and deletion messed with the actual window
Darkvater
parents: 5122
diff changeset
  2070
	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
  2071
		Window *w = *wz;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2072
		int left, top;
158
b1a821f84250 (svn r159) -Fix: w->custom[] was too small for 64bit pointers
truelight
parents: 152
diff changeset
  2073
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2074
		if (w->window_class == WC_MAIN_WINDOW) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2075
			ViewPort *vp = w->viewport;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2076
			vp->width = w->width = neww;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2077
			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
  2078
			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
  2079
			vp->virtual_height = ScaleByZoom(newh, vp->zoom);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2080
			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
  2081
		}
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
  2082
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2083
		/* 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
  2084
		 * in a 'backup'-desc that the window should always be centred. */
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2085
		switch (w->window_class) {
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2086
			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
  2087
				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
  2088
					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
  2089
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2090
					WindowEvent e;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2091
					e.event = WE_RESIZE;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2092
					e.we.sizing.size.x = w->width;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2093
					e.we.sizing.size.y = w->height;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2094
					e.we.sizing.diff.x = neww - w->width;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2095
					e.we.sizing.diff.y = 0;
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2096
					w->wndproc(w, &e);
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2097
				}
959896e9b55b (svn r10725) -Codechange: move some window related code out of gfx.cpp to windows.cpp
rubidium
parents: 7354
diff changeset
  2098
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2099
				top = w->top;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2100
				left = PositionMainToolbar(w); // changes toolbar orientation
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2101
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2102
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2103
			case WC_SELECT_GAME:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2104
			case WC_GAME_OPTIONS:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2105
			case WC_NETWORK_WINDOW:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2106
				top = (newh - w->height) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2107
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2108
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2109
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2110
			case WC_NEWS_WINDOW:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2111
				top = newh - w->height;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2112
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2113
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2114
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2115
			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
  2116
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2117
				top = newh - w->height;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2118
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2119
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2120
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2121
			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
  2122
				ResizeWindow(w, Clamp(neww, 320, 640) - w->width, 0);
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2123
				top = (newh - 26); // 26 = height of status bar + height of chat bar
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2124
				left = (neww - w->width) >> 1;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2125
				break;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2126
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2127
			case WC_CONSOLE:
5143
43f7b9457827 (svn r7233) -Codechange: get rid of three console.c globals
Darkvater
parents: 5137
diff changeset
  2128
				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
  2129
				continue;
5126
9084bb06e52e (svn r7207) -Codechange: Pass the (unchanged) windowpointer to the console window and do it only once.
Darkvater
parents: 5124
diff changeset
  2130
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2131
			default:
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2132
				left = w->left;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2133
				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
  2134
				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
  2135
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2136
				top = w->top;
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2137
				if (top + (w->height >> 1) >= newh) top = newh - w->height;
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
  2138
				if (top < 0) top = 0;
2989
916f9443345f (svn r3564) Several smaller changes:
tron
parents: 2952
diff changeset
  2139
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2140
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2141
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2631
diff changeset
  2142
		if (w->viewport != NULL) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2143
			w->viewport->left += left - w->left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2144
			w->viewport->top += top - w->top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2145
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2146
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2147
		w->left = left;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2148
		w->top = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2149
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  2150
}