src/widget.cpp
author maedhros
Mon, 16 Apr 2007 10:59:35 +0000
changeset 6472 f1e70dc23fac
parent 6432 226650eb2ef3
child 6481 85ad87daf4b0
permissions -rw-r--r--
(svn r9648) -Codechange: Use HASBIT directly rather than shifting and then using it on the first bit.
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
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: 6278
diff changeset
     3
/** @file widget.cpp */
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: 6278
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1657
diff changeset
     6
#include "openttd.h"
2163
b17b313113a0 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2154
diff changeset
     7
#include "functions.h"
2154
f86c59e73a16 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2064
diff changeset
     8
#include "player.h"
1363
775a7ee52369 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1177
diff changeset
     9
#include "table/sprites.h"
507
04b5403aaf6b (svn r815) Include strings.h only in the files which need it.
tron
parents: 193
diff changeset
    10
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    13
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    14
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
    15
static Point HandleScrollbarHittest(const Scrollbar *sb, int top, int bottom)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	int height, count, pos, cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
	top += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	bottom -= 9;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    22
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	height = (bottom - top);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	pos = sb->pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
	count = sb->count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	cap = sb->cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
    29
	if (count != 0) top += height * pos / count;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    30
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    31
	if (cap > count) cap = count;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
    32
	if (count != 0) bottom -= (count - pos - cap) * height / count;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	pt.x = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
	pt.y = bottom - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
/*****************************************************
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
 * Special handling for the scrollbar widget type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
 * Handles the special scrolling buttons and other
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
 * scrolling.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
 * Parameters:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
 *   w   - Window.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
 *   wi  - Pointer to the scrollbar widget.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
 *   x   - The X coordinate of the mouse click.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
 *   y   - The Y coordinate of the mouse click.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    49
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
void ScrollbarClickHandler(Window *w, const Widget *wi, int x, int y)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
	int mi, ma, pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    53
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    55
	switch (wi->type) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    56
		case WWT_SCROLLBAR: {
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: 6278
diff changeset
    57
			/* vertical scroller */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    58
			w->flags4 &= ~WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    59
			w->flags4 &= ~WF_SCROLL2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    60
			mi = wi->top;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    61
			ma = wi->bottom;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    62
			pos = y;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    63
			sb = &w->vscroll;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    64
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    65
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    66
		case WWT_SCROLL2BAR: {
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: 6278
diff changeset
    67
			/* 2nd vertical scroller */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    68
			w->flags4 &= ~WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    69
			w->flags4 |= WF_SCROLL2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    70
			mi = wi->top;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    71
			ma = wi->bottom;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    72
			pos = y;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    73
			sb = &w->vscroll2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    74
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    75
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    76
		case  WWT_HSCROLLBAR: {
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: 6278
diff changeset
    77
			/* horizontal scroller */
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
    78
			w->flags4 &= ~WF_SCROLL2;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    79
			w->flags4 |= WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    80
			mi = wi->left;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    81
			ma = wi->right;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    82
			pos = x;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    83
			sb = &w->hscroll;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
    84
			break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    85
		}
845
4960e265d25b (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 842
diff changeset
    86
		default: return; //this should never happen
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    88
	if (pos <= mi+9) {
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: 6278
diff changeset
    89
		/* Pressing the upper button? */
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    90
		w->flags4 |= WF_SCROLL_UP;
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    91
		if (_scroller_click_timeout == 0) {
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    92
			_scroller_click_timeout = 6;
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    93
			if (sb->pos != 0) sb->pos--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
		}
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    95
		_left_button_clicked = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    96
	} else if (pos >= ma-10) {
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: 6278
diff changeset
    97
		/* Pressing the lower button? */
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    98
		w->flags4 |= WF_SCROLL_DOWN;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    99
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   100
		if (_scroller_click_timeout == 0) {
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   101
			_scroller_click_timeout = 6;
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   102
			if ((byte)(sb->pos + sb->cap) < sb->count)
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   103
				sb->pos++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
		}
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   105
		_left_button_clicked = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
	} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		Point pt = HandleScrollbarHittest(sb, mi, ma);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		if (pos < pt.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
			sb->pos = max(sb->pos - sb->cap, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
		} else if (pos > pt.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
			sb->pos = min(
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   113
				sb->pos + sb->cap,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
				max(sb->count - sb->cap, 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
			_scrollbar_start_pos = pt.x - mi - 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			_scrollbar_size = ma - mi - 23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
			w->flags4 |= WF_SCROLL_MIDDLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
			_scrolling_scrollbar = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
			_cursorpos_drag_start = _cursor.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   122
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   123
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
	SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   127
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: 1938
diff changeset
   128
/** Returns the index for the widget located at the given position
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: 1938
diff changeset
   129
 * relative to the window. It includes all widget-corner pixels as well.
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: 1938
diff changeset
   130
 * @param *w Window to look inside
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: 6278
diff changeset
   131
 * @param  x
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: 6278
diff changeset
   132
 * @param  y Window client coordinates
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: 1938
diff changeset
   133
 * @return A widget index, or -1 if no widget was found.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   134
 */
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   135
int GetWidgetFromPos(const Window *w, int x, int y)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   136
{
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: 5196
diff changeset
   137
	uint index;
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: 5196
diff changeset
   138
	int found_index = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
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: 6278
diff changeset
   140
	/* Go through the widgets and check if we find the widget that the coordinate is
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: 6278
diff changeset
   141
	 * inside. */
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: 5196
diff changeset
   142
	for (index = 0; index < w->widget_count; index++) {
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: 5196
diff changeset
   143
		const Widget *wi = &w->widget[index];
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   144
		if (wi->type == WWT_EMPTY || wi->type == WWT_FRAME) continue;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   145
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: 1938
diff changeset
   146
		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
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: 5196
diff changeset
   147
				!IsWindowWidgetHidden(w, index)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   148
			found_index = index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   149
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   150
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   151
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	return found_index;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   154
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   155
4437
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   156
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags)
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   157
{
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   158
	uint dark         = _colour_gradient[ctab][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   159
	uint medium_dark  = _colour_gradient[ctab][5];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   160
	uint medium_light = _colour_gradient[ctab][6];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   161
	uint light        = _colour_gradient[ctab][7];
4437
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   162
4438
c8b86504b83c (svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents: 4437
diff changeset
   163
	if (flags & FR_TRANSPARENT) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   164
		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE));
4437
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   165
	} else {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   166
		uint interior;
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   167
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   168
		if (flags & FR_LOWERED) {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   169
			GfxFillRect(left,     top,     left,  bottom,     dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   170
			GfxFillRect(left + 1, top,     right, top,        dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   171
			GfxFillRect(right,    top + 1, right, bottom - 1, light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   172
			GfxFillRect(left + 1, bottom,  right, bottom,     light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   173
			interior = (flags & FR_DARKENED ? medium_dark : medium_light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   174
		} else {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   175
			GfxFillRect(left,     top,    left,      bottom - 1, light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   176
			GfxFillRect(left + 1, top,    right - 1, top,        light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   177
			GfxFillRect(right,    top,    right,     bottom - 1, dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   178
			GfxFillRect(left,     bottom, right,     bottom,     dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   179
			interior = medium_dark;
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   180
		}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   181
		if (!(flags & FR_BORDERONLY)) {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   182
			GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   183
		}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   184
	}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   185
}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   186
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   187
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   188
void DrawWindowWidgets(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
{
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2448
diff changeset
   190
	const DrawPixelInfo* dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
	Rect r;
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: 5196
diff changeset
   192
	uint i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   193
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: 5196
diff changeset
   194
	for (i = 0; i < w->widget_count; i++) {
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: 5196
diff changeset
   195
		const Widget *wi = &w->widget[i];
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: 5196
diff changeset
   196
		bool clicked = IsWindowWidgetLowered(w, i);
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   197
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
		if (dpi->left > (r.right=/*w->left + */wi->right) ||
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   199
				dpi->left + dpi->width <= (r.left=wi->left/* + w->left*/) ||
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   200
				dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
				dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
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: 5196
diff changeset
   202
				IsWindowWidgetHidden(w, i)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   203
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   204
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   206
		switch (wi->type & WWT_MASK) {
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   207
		case WWT_IMGBTN:
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   208
		case WWT_IMGBTN_2: {
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   209
			int img = wi->data;
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   210
			assert(img != 0);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   211
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   212
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   213
			/* show different image when clicked for WWT_IMGBTN_2 */
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   214
			if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   215
			DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   216
			goto draw_default;
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   217
		}
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   218
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   219
		case WWT_PANEL: {
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   220
			assert(wi->data == 0);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   221
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
			goto draw_default;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   224
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   225
		case WWT_TEXTBTN:
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   226
		case WWT_TEXTBTN_2: {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   227
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   229
		/* fall through */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
4345
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 3762
diff changeset
   231
		case WWT_LABEL: {
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   232
			StringID str = wi->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   233
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   234
			if ((wi->type & WWT_MASK) == WWT_TEXTBTN_2 && clicked) str++;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   235
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   236
			DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, 0);
2064
e6a2b42d0b15 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2026
diff changeset
   237
			goto draw_default;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   239
6278
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   240
		case WWT_TEXT: {
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   241
			StringID str = wi->data;
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   242
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   243
			if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left);
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   244
			break;
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   245
		}
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   246
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   247
		case WWT_INSET: {
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   248
			StringID str = wi->data;
1938
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   249
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   251
			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, 0, r.right - r.left - 10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
			goto draw_default;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   253
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
		case WWT_MATRIX: {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   256
			int c, d, ctr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			int x, amt1, amt2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
			int color;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   259
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   260
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   261
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   262
			c = GB(wi->data, 0, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
			amt1 = (wi->right - wi->left + 1) / c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   265
			d = GB(wi->data, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
			amt2 = (wi->bottom - wi->top + 1) / d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   268
			color = _colour_gradient[wi->color & 0xF][6];
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   269
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
			x = r.left;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   271
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
				x += amt1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   273
				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
0
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
			x = r.top;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   277
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
				x += amt2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   279
				GfxFillRect(r.left + 1, x, r.right - 1, x, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   281
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   282
			color = _colour_gradient[wi->color&0xF][4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   284
			x = r.left - 1;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   285
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
				x += amt1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   287
				GfxFillRect(x, r.top + 1, x, r.bottom - 1, color);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   288
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   290
			x = r.top - 1;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   291
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
				x += amt2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
				GfxFillRect(r.left+1, x, r.right-1, x, color);
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
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   296
			goto draw_default;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
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: 6278
diff changeset
   299
		/* vertical scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
		case WWT_SCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   301
			Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   302
			int c1,c2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   304
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   305
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: 6278
diff changeset
   306
			/* draw up/down buttons */
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   307
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   308
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
2406
8c873205483a (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   309
			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   311
			clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   312
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
2406
8c873205483a (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   313
			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   315
			c1 = _colour_gradient[wi->color&0xF][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   316
			c2 = _colour_gradient[wi->color&0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   317
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: 6278
diff changeset
   318
			/* draw "shaded" background */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   320
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   321
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: 6278
diff changeset
   322
			/* draw shaded lines */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   323
			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   324
			GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   325
			GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   327
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   329
			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   330
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   331
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   332
		case WWT_SCROLL2BAR: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   333
			Point pt;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   334
			int c1,c2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   335
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   336
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   337
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: 6278
diff changeset
   338
			/* draw up/down buttons */
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   339
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   340
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
2406
8c873205483a (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   341
			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   342
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   343
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   344
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
2406
8c873205483a (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   345
			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   346
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   347
			c1 = _colour_gradient[wi->color&0xF][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   348
			c2 = _colour_gradient[wi->color&0xF][7];
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   349
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: 6278
diff changeset
   350
			/* draw "shaded" background */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   351
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   352
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   353
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: 6278
diff changeset
   354
			/* draw shaded lines */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   355
			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   356
			GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   357
			GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   358
			GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   359
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   360
			pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   361
			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
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: 6278
diff changeset
   365
		/* horizontal scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
		case WWT_HSCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   367
			Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
			int c1,c2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   369
894
8b59c639837d (svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents: 893
diff changeset
   370
			assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   371
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   372
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   373
			DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   374
			DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   376
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   377
			DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   378
			DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   380
			c1 = _colour_gradient[wi->color&0xF][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   381
			c2 = _colour_gradient[wi->color&0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
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: 6278
diff changeset
   383
			/* draw "shaded" background */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   385
			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
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: 6278
diff changeset
   387
			/* draw shaded lines */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			GfxFillRect(r.left+10, r.top+2, r.right-10, r.top+2, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
			GfxFillRect(r.left+10, r.top+3, r.right-10, r.top+3, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
			GfxFillRect(r.left+10, r.top+7, r.right-10, r.top+7, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
			GfxFillRect(r.left+10, r.top+8, r.right-10, r.top+8, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
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: 6278
diff changeset
   393
			/* draw actual scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   395
			DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		case WWT_FRAME: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
			int c1,c2;
860
fad6642f6217 (svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents: 845
diff changeset
   402
			int x2 = r.left; // by default the left side is the left side of the widget
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   403
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   404
			if (wi->data != 0) x2 = DrawString(r.left + 6, r.top, wi->data, 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   406
			c1 = _colour_gradient[wi->color][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   407
			c2 = _colour_gradient[wi->color][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
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: 6278
diff changeset
   409
			/*Line from upper left corner to start of text */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   410
			GfxFillRect(r.left, r.top+4, r.left+4,r.top+4, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   411
			GfxFillRect(r.left+1, r.top+5, r.left+4,r.top+5, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
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: 6278
diff changeset
   413
			/* Line from end of text to upper right corner */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   414
			GfxFillRect(x2, r.top+4, r.right-1,r.top+4,c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   415
			GfxFillRect(x2, r.top+5, r.right-2,r.top+5,c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
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: 6278
diff changeset
   417
			/* Line from upper left corner to bottom left corner */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   418
			GfxFillRect(r.left, r.top+5, r.left, r.bottom-1, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   419
			GfxFillRect(r.left+1, r.top+6, r.left+1, r.bottom-2, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
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: 6278
diff changeset
   421
			/*Line from upper right corner to bottom right corner */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   422
			GfxFillRect(r.right-1, r.top+5, r.right-1, r.bottom-2, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   423
			GfxFillRect(r.right, r.top+4, r.right, r.bottom-1, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   424
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
			GfxFillRect(r.left+1, r.bottom-1, r.right-1, r.bottom-1, c1);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   426
			GfxFillRect(r.left, r.bottom, r.right, r.bottom, c2);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
2064
e6a2b42d0b15 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2026
diff changeset
   428
			goto draw_default;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   429
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
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: 674
diff changeset
   431
		case WWT_STICKYBOX: {
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   432
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
2703
a969970a5245 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   433
a969970a5245 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   434
			clicked = !!(w->flags4 & WF_STICKY);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   435
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   436
			DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked);
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: 674
diff changeset
   437
			break;
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: 674
diff changeset
   438
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   439
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   440
		case WWT_RESIZEBOX: {
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   441
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 894
diff changeset
   442
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   443
			clicked = !!(w->flags4 & WF_SIZING);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   444
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   445
			DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   446
			break;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   447
		}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   448
2757
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   449
		case WWT_CLOSEBOX: {
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   450
			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   451
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   452
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
2757
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   453
			DrawString(r.left + 2, r.top + 2, STR_00C5, 0);
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   454
			break;
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   455
		}
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   456
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   457
		case WWT_CAPTION: {
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   458
			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
1938
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   459
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   460
			DrawFrameRect(r.left+1, r.top+1, r.right-1, r.bottom-1, wi->color, (w->caption_color == 0xFF) ? FR_LOWERED | FR_DARKENED : FR_LOWERED | FR_DARKENED | FR_BORDERONLY);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   461
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
			if (w->caption_color != 0xFF) {
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   463
				GfxFillRect(r.left+2, r.top+2, r.right-2, r.bottom-2, _colour_gradient[_player_colors[w->caption_color]][4]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   464
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   465
5017
3df5ce293696 (svn r7058) -Codechange: Truncate text in window captions
peter1138
parents: 4940
diff changeset
   466
			DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top+2, wi->data, 0x84);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
draw_default:;
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: 5196
diff changeset
   468
			if (IsWindowWidgetDisabled(w, i)) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   469
				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT));
0
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
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   472
		}
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: 5196
diff changeset
   473
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   474
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   475
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   476
	if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   477
		//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
1938
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   478
		DrawFrameRect(0, 0, w->width-1, w->height-1, 0xF, FR_BORDERONLY);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   479
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   480
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   481
}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   482
883
9bfde7bab1f9 (svn r1368) -Fix: Disabled dropdown menu options are gray again (instead of blue)
truelight
parents: 876
diff changeset
   483
static const Widget _dropdown_menu_widgets[] = {
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   484
{      WWT_PANEL,   RESIZE_NONE,     0,     0, 0,     0, 0, 0x0, STR_NULL},
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   485
{  WWT_SCROLLBAR,   RESIZE_NONE,     0,     0, 0,     0, 0, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
176
84990c4b9212 (svn r177) -Fix: padded out Widget code to solve warnings on C99 compiler (Tron)
darkvater
parents: 164
diff changeset
   486
{   WIDGETS_END},
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   487
};
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   488
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   489
static int GetDropdownItem(const Window *w)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   490
{
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   491
	byte item, counter;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   492
	int y;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   493
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   494
	if (GetWidgetFromPos(w, _cursor.pos.x - w->left, _cursor.pos.y - w->top) < 0)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   495
		return -1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   496
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   497
	y = _cursor.pos.y - w->top - 2 + w->vscroll.pos * 10;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   498
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   499
	if (y < 0)
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   500
		return - 1;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   501
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   502
	item = y / 10;
2683
ca9645a21734 (svn r3225) - Fix for "[ 1359165 ] Autoreplace problem with r3171 and later" -- Move the disabled/hidden bits to custom data in window struct.
peter1138
parents: 2642
diff changeset
   503
	if (item >= WP(w,dropdown_d).num_items || (HASBIT(WP(w,dropdown_d).disabled_state, item) && !HASBIT(WP(w,dropdown_d).hidden_state, item)) || WP(w,dropdown_d).items[item] == 0)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   504
		return - 1;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   505
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: 6278
diff changeset
   506
	/* Skip hidden items -- +1 for each hidden item before the clicked item. */
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   507
	for (counter = 0; item >= counter; ++counter)
2683
ca9645a21734 (svn r3225) - Fix for "[ 1359165 ] Autoreplace problem with r3171 and later" -- Move the disabled/hidden bits to custom data in window struct.
peter1138
parents: 2642
diff changeset
   508
		if (HASBIT(WP(w,dropdown_d).hidden_state, counter)) item++;
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   509
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   510
	return item;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   511
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   512
1095
b59632d9df1b (svn r1596) Add some more statics
tron
parents: 915
diff changeset
   513
static void DropdownMenuWndProc(Window *w, WindowEvent *e)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   514
{
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   515
	int item;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   516
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2801
diff changeset
   517
	switch (e->event) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   518
		case WE_PAINT: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   519
			int x,y,i,sel;
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   520
			int width, height;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   521
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   522
			DrawWindowWidgets(w);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   523
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   524
			x = 1;
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   525
			y = 2 - w->vscroll.pos * 10;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   526
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   527
			sel    = WP(w,dropdown_d).selected_index;
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   528
			width  = w->widget[0].right - 3;
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   529
			height = w->widget[0].bottom - 3;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   530
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   531
			for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) {
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   532
				if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   533
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   534
				if (y >= 0 && y <= height) {
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   535
					if (WP(w,dropdown_d).items[i] != STR_NULL) {
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   536
						if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   537
						DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   538
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   539
						if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   540
							GfxFillRect(x, y, x + width, y + 9,
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   541
								(1 << PALETTE_MODIFIER_GREYOUT) | _colour_gradient[_dropdown_menu_widgets[0].color][5]
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   542
							);
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   543
						}
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   544
					} else {
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   545
						int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   546
						int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   547
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   548
						GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   549
						GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   550
					}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   551
				}
1177
9a250d8f0794 (svn r1679) Fix: dropdown menus now returns the index of the string that was clicked even if a previous item is hidden
bjarni
parents: 1095
diff changeset
   552
				y += 10;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   553
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   554
		} break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   555
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   556
		case WE_CLICK: {
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   557
			if (e->we.click.widget != 0) break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   558
			item = GetDropdownItem(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   559
			if (item >= 0) {
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   560
				WP(w,dropdown_d).click_delay = 4;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   561
				WP(w,dropdown_d).selected_index = item;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   562
				SetWindowDirty(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   563
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   564
		} break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   565
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   566
		case WE_MOUSELOOP: {
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   567
			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   568
			if (w2 == NULL) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   569
				DeleteWindow(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   570
				return;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   571
			}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   572
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   573
			if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   574
				WindowEvent e;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   575
				e.event = WE_DROPDOWN_SELECT;
4634
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4573
diff changeset
   576
				e.we.dropdown.button = WP(w,dropdown_d).parent_button;
07699ac2bf37 (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4573
diff changeset
   577
				e.we.dropdown.index  = WP(w,dropdown_d).selected_index;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   578
				w2->wndproc(w2, &e);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   579
				DeleteWindow(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   580
				return;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   581
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   582
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   583
			if (WP(w,dropdown_d).drag_mode) {
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   584
				item = GetDropdownItem(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   585
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   586
				if (!_left_button_clicked) {
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   587
					WP(w,dropdown_d).drag_mode = false;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   588
					if (item < 0) return;
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   589
					WP(w,dropdown_d).click_delay = 2;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   590
				} else {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   591
					if (item < 0) return;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   592
				}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   593
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   594
				WP(w,dropdown_d).selected_index = item;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   595
				SetWindowDirty(w);
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   596
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   597
		} break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   598
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   599
		case WE_DESTROY: {
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   600
			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   601
			if (w2 != NULL) {
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   602
				RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   603
				InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   604
			}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   605
		} break;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   606
	}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   607
}
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   608
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   609
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask)
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   610
{
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   611
	int i;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   612
	const Widget *wi;
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   613
	Window *w2;
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   614
	const Window *w3;
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   615
	bool is_dropdown_menu_shown = IsWindowWidgetLowered(w, button);
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   616
	int top, height;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   617
	int screen_top, screen_bottom;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   618
	bool scroll = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   619
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   620
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   621
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   622
	if (is_dropdown_menu_shown) return;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   623
4719
fc6e14219f72 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   624
	LowerWindowWidget(w, button);
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   625
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   626
	InvalidateWidget(w, button);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   627
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   628
	for (i = 0; strings[i] != INVALID_STRING_ID; i++) {}
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   629
	if (i == 0) return;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   630
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   631
	wi = &w->widget[button];
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   632
2448
1a07657c9f9a (svn r2974) -Fix: Drag and drop selection on drop down boxes didn't select correct item when some items were hidden.
peter1138
parents: 2436
diff changeset
   633
	if (hidden_mask != 0) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   634
		uint j;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   635
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   636
		for (j = 0; strings[j] != INVALID_STRING_ID; j++) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   637
			if (HASBIT(hidden_mask, j)) i--;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   638
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   639
	}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   640
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   641
	/* The preferred position is just below the dropdown calling widget */
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   642
	top = w->top + wi->bottom + 2;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   643
	height = i * 10 + 4;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   644
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   645
	w3 = FindWindowById(WC_STATUS_BAR, 0);
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   646
	screen_bottom = w3 == NULL ? _screen.height : w3->top;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   647
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   648
	/* Check if the dropdown will fully fit below the widget */
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   649
	if (top + height >= screen_bottom) {
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   650
		w3 = FindWindowById(WC_MAIN_TOOLBAR, 0);
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   651
		screen_top = w3 == NULL ? 0 : w3->top + w3->height;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   652
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   653
		/* If not, check if it will fit above the widget */
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   654
		if (w->top + wi->top - height - 1 > screen_top) {
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   655
			top = w->top + wi->top - height - 1;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   656
		} else {
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   657
			/* ... and lastly if it won't, enable the scroll bar and fit the
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   658
			 * list in below the widget */
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   659
			int rows = (screen_bottom - 4 - top) / 10;
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   660
			height = rows * 10 + 4;
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   661
			scroll = true;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   662
		}
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   663
	}
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   664
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   665
	w2 = AllocateWindow(
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   666
		w->left + wi[-1].left + 1,
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   667
		top,
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   668
		wi->right - wi[-1].left + 1,
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   669
		height,
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   670
		DropdownMenuWndProc,
4573
92032cec7021 (svn r6423) -Codechange: Replace two magic numbers by appropriate enum/define value
belugas
parents: 4547
diff changeset
   671
		WC_DROPDOWN_MENU,
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   672
		_dropdown_menu_widgets);
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   673
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   674
	w2->widget[0].color = wi->color;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   675
	w2->widget[0].right = wi->right - wi[-1].left;
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   676
	w2->widget[0].bottom = height - 1;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   677
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   678
	SetWindowWidgetHiddenState(w2, 1, !scroll);
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   679
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   680
	if (scroll) {
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   681
		/* We're scrolling, so enable the scroll bar and shrink the list by
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   682
		 * the scrollbar's width */
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   683
		w2->widget[1].color  = wi->color;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   684
		w2->widget[1].right  = w2->widget[0].right;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   685
		w2->widget[1].left   = w2->widget[1].right - 11;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   686
		w2->widget[1].bottom = height - 1;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   687
		w2->widget[0].right -= 12;
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   688
5196
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   689
		w2->vscroll.cap   = (height - 4) / 10;
8a686679598b (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   690
		w2->vscroll.count = i;
5041
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   691
	}
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   692
674e5e1b4ad4 (svn r7086) -Featurette: Add additional positioning for long dropdown lists: first, try to fit the dropdown below the calling widget, as before; second, try to fit it wholly above the calling widget; and lastly, fit the list below the widget and add a scrollbar.
peter1138
parents: 5017
diff changeset
   693
	w2->desc_flags = WDF_DEF_WIDGET;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   694
	w2->flags4 &= ~WF_WHITE_BORDER_MASK;
2629
78f87f273407 (svn r3171) - Codechange: remove static _dropdown_disabled/_dropdown_hidden variables, as a window already contains this information.
peter1138
parents: 2597
diff changeset
   695
2683
ca9645a21734 (svn r3225) - Fix for "[ 1359165 ] Autoreplace problem with r3171 and later" -- Move the disabled/hidden bits to custom data in window struct.
peter1138
parents: 2642
diff changeset
   696
	WP(w2,dropdown_d).disabled_state = disabled_mask;
ca9645a21734 (svn r3225) - Fix for "[ 1359165 ] Autoreplace problem with r3171 and later" -- Move the disabled/hidden bits to custom data in window struct.
peter1138
parents: 2642
diff changeset
   697
	WP(w2,dropdown_d).hidden_state = hidden_mask;
2636
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   698
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   699
	WP(w2,dropdown_d).parent_wnd_class = w->window_class;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   700
	WP(w2,dropdown_d).parent_wnd_num = w->window_number;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   701
	WP(w2,dropdown_d).parent_button = button;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   702
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   703
	WP(w2,dropdown_d).num_items = i;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   704
	WP(w2,dropdown_d).selected_index = selected;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   705
	WP(w2,dropdown_d).items = strings;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   706
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   707
	WP(w2,dropdown_d).click_delay = 0;
bdff7da76aa2 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   708
	WP(w2,dropdown_d).drag_mode = true;
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   709
}
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   710
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   711
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   712
static void ResizeWidgets(Window *w, byte a, byte b)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   713
{
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   714
	int16 offset = w->widget[a].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   715
	int16 length = w->widget[b].right - offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   716
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   717
	w->widget[a].right  = (length / 2) + offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   718
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   719
	w->widget[b].left  = w->widget[a].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   720
}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   721
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   722
static void ResizeWidgets(Window *w, byte a, byte b, byte c)
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   723
{
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   724
	int16 offset = w->widget[a].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   725
	int16 length = w->widget[c].right - offset;
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   726
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   727
	w->widget[a].right = length / 3;
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   728
	w->widget[b].right = w->widget[a].right * 2;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   729
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   730
	w->widget[a].right += offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   731
	w->widget[b].right += offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   732
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   733
	/* Now the right side of the buttons are set. We will now set the left sides next to them */
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   734
	w->widget[b].left  = w->widget[a].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   735
	w->widget[c].left  = w->widget[b].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   736
}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   737
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   738
/** Evenly distribute some widgets when resizing horizontally (often a button row)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   739
 *  When only two arguments are given, the widgets are presumed to be on a line and only the ends are given
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   740
 * @param w widow to modify
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   741
 * @param left The leftmost widget to resize
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   742
 * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   743
 */
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   744
void ResizeButtons(Window *w, byte left, byte right)
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   745
{
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   746
	int16 num_widgets = right - left + 1;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   747
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   748
	if (num_widgets < 2) NOT_REACHED();
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   749
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   750
	switch (num_widgets) {
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   751
		case 2: ResizeWidgets(w, left, right); break;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   752
		case 3: ResizeWidgets(w, left, left + 1, right); break;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   753
		default: {
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   754
			/* Looks like we got more than 3 widgets to resize
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   755
			 * Now we will find the middle of the space desinated for the widgets
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   756
			 * and place half of the widgets on each side of it and call recursively.
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   757
			 * Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   758
			int16 offset = w->widget[left].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   759
			int16 length = w->widget[right].right - offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   760
			byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   761
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   762
			/* Now we need to find the middle of the widgets.
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   763
			 * It will not always be the middle because if we got an uneven number of widgets,
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   764
			 *   we will need it to be 2/5, 3/7 and so on
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   765
			 * To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get:
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   766
			 *
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   767
			 *    num_widgets/2 (rounding down)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   768
			 *   ---------------
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   769
			 *     num_widgets
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   770
			 *
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   771
			 * as multiplier to length. We just multiply before divide to that we stay in the int area though */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   772
			int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   773
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   774
			/* Set left and right on the widgets, that's next to our "middle" */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   775
			w->widget[widget].right = middle;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   776
			w->widget[widget + 1].left = w->widget[widget].right + 1;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   777
			/* Now resize the left and right of the middle */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   778
			ResizeButtons(w, left, widget);
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   779
			ResizeButtons(w, widget + 1, right);
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   780
		}
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   781
	}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   782
}