widget.c
author celestar
Sun, 31 Dec 2006 18:03:21 +0000
branchcustombridgeheads
changeset 5615 d6197e6c420e
parent 5236 e959e132a78e
permissions -rw-r--r--
(svn r7705) [cbh] - Fix: Trains leave the bridge according to the trackbits that a present on the bridge head.
WARNING: zero-length bridges do not work yet
2186
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
461a2aff3486 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     3
#include "stdafx.h"
1891
92a3b0aa0946 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1657
diff changeset
     4
#include "openttd.h"
2163
637ec3c361f5 (svn r2673) Include functions.h directly, not globally via openttd.h
tron
parents: 2154
diff changeset
     5
#include "functions.h"
2154
63a6b880b4c0 (svn r2664) Remove depedency on player.h from variables.h
tron
parents: 2064
diff changeset
     6
#include "player.h"
1363
01d3de5d8039 (svn r1867) Include tables/sprites.h only in files which need it
tron
parents: 1177
diff changeset
     7
#include "table/sprites.h"
507
8aa8100b0b22 (svn r815) Include strings.h only in the files which need it.
tron
parents: 193
diff changeset
     8
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     9
#include "window.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "gfx.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    11
#include "viewport.h"
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    12
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
    13
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
    14
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    15
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
	int height, count, pos, cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    17
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    18
	top += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
	bottom -= 9;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    20
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
	height = (bottom - top);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	pos = sb->pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    24
	count = sb->count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	cap = sb->cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
2026
02dfa0aa2c2f (svn r2535) Tabs
tron
parents: 2021
diff changeset
    27
	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
    28
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	if (cap > count) cap = count;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
    30
	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
    31
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    32
	pt.x = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	pt.y = bottom - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    34
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    35
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
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
 * Special handling for the scrollbar widget type.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
 * Handles the special scrolling buttons and other
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
 * scrolling.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    41
 * Parameters:
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
 *   w   - Window.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
 *   wi  - Pointer to the scrollbar widget.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
 *   x   - The X coordinate of the mouse click.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    45
 *   y   - The Y coordinate of the mouse click.
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    46
 */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    47
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    48
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
    49
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    50
	int mi, ma, pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    51
	Scrollbar *sb;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    52
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    53
	switch (wi->type) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    54
		case WWT_SCROLLBAR: {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    55
			// vertical scroller
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    56
			w->flags4 &= ~WF_HSCROLL;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    57
			w->flags4 &= ~WF_SCROLL2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    58
			mi = wi->top;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    59
			ma = wi->bottom;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    60
			pos = y;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    61
			sb = &w->vscroll;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    62
			break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    63
		}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    64
		case WWT_SCROLL2BAR: {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    65
			// 2nd vertical scroller
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    66
			w->flags4 &= ~WF_HSCROLL;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    67
			w->flags4 |= WF_SCROLL2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    68
			mi = wi->top;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    69
			ma = wi->bottom;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    70
			pos = y;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    71
			sb = &w->vscroll2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    72
			break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    73
		}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    74
		case  WWT_HSCROLLBAR: {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    75
			// horizontal scroller
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
    76
			w->flags4 &= ~WF_SCROLL2;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    77
			w->flags4 |= WF_HSCROLL;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    78
			mi = wi->left;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    79
			ma = wi->right;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    80
			pos = x;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    81
			sb = &w->hscroll;
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
    82
			break;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    83
		}
845
0c66e26fecb2 (svn r1326) fixed compiler warnings in vehicle_gui.c and widget.c
bjarni
parents: 842
diff changeset
    84
		default: return; //this should never happen
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    85
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    86
	if (pos <= mi+9) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    87
		// Pressing the upper button?
2597
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    88
		w->flags4 |= WF_SCROLL_UP;
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    89
		if (_scroller_click_timeout == 0) {
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    90
			_scroller_click_timeout = 6;
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    91
			if (sb->pos != 0) sb->pos--;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
		}
2597
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    93
		_left_button_clicked = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    94
	} else if (pos >= ma-10) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    95
		// Pressing the lower button?
2597
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    96
		w->flags4 |= WF_SCROLL_DOWN;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    97
2597
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    98
		if (_scroller_click_timeout == 0) {
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    99
			_scroller_click_timeout = 6;
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   100
			if ((byte)(sb->pos + sb->cap) < sb->count)
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   101
				sb->pos++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   102
		}
2597
68ffedae1eb5 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   103
		_left_button_clicked = false;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   104
	} else {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   105
		//
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
		Point pt = HandleScrollbarHittest(sb, mi, ma);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
		if (pos < pt.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
			sb->pos = max(sb->pos - sb->cap, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
		} else if (pos > pt.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   111
			sb->pos = min(
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   112
				sb->pos + sb->cap,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
				max(sb->count - sb->cap, 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
			_scrollbar_start_pos = pt.x - mi - 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
			_scrollbar_size = ma - mi - 23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			w->flags4 |= WF_SCROLL_MIDDLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
			_scrolling_scrollbar = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
			_cursorpos_drag_start = _cursor.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
		}
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
	SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   126
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   127
/** Returns the index for the widget located at the given position
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   128
 * relative to the window. It includes all widget-corner pixels as well.
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   129
 * @param *w Window to look inside
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   130
 * @param  x,y Window client coordinates
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   131
 * @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
   132
 */
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   133
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
   134
{
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   135
	uint index;
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   136
	int found_index = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   138
	// Go through the widgets and check if we find the widget that the coordinate is
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   139
	// inside.
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   140
	for (index = 0; index < w->widget_count; index++) {
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   141
		const Widget *wi = &w->widget[index];
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   142
		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
   143
2021
3be628c59488 (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   144
		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   145
				!IsWindowWidgetHidden(w, index)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   146
			found_index = index;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   147
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   148
	}
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
	return found_index;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
4437
d06bb548e48d (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
   154
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags)
d06bb548e48d (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
   155
{
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   156
	uint dark         = _colour_gradient[ctab][3];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   157
	uint medium_dark  = _colour_gradient[ctab][5];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   158
	uint medium_light = _colour_gradient[ctab][6];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   159
	uint light        = _colour_gradient[ctab][7];
4437
d06bb548e48d (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
   160
4438
bfa7b06c0afe (svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents: 4437
diff changeset
   161
	if (flags & FR_TRANSPARENT) {
bfa7b06c0afe (svn r6210) Remove FR_NOBORDER, because it is exclusivly used in conjunction with FR_TRANSPARENT
tron
parents: 4437
diff changeset
   162
		GfxFillRect(left, top, right, bottom, 0x322 | USE_COLORTABLE);
4437
d06bb548e48d (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
   163
	} else {
d06bb548e48d (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
   164
		uint interior;
d06bb548e48d (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
d06bb548e48d (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
		if (flags & FR_LOWERED) {
d06bb548e48d (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
			GfxFillRect(left,     top,     left,  bottom,     dark);
d06bb548e48d (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
			GfxFillRect(left + 1, top,     right, top,        dark);
d06bb548e48d (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(right,    top + 1, right, bottom - 1, light);
d06bb548e48d (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, bottom,  right, bottom,     light);
d06bb548e48d (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
			interior = (flags & FR_DARKENED ? medium_dark : medium_light);
d06bb548e48d (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
		} else {
d06bb548e48d (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
			GfxFillRect(left,     top,    left,      bottom - 1, light);
d06bb548e48d (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
			GfxFillRect(left + 1, top,    right - 1, top,        light);
d06bb548e48d (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(right,    top,    right,     bottom - 1, dark);
d06bb548e48d (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,     bottom, right,     bottom,     dark);
d06bb548e48d (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
			interior = medium_dark;
d06bb548e48d (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
		}
d06bb548e48d (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
		if (!(flags & FR_BORDERONLY)) {
d06bb548e48d (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
			GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior);
d06bb548e48d (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
		}
d06bb548e48d (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
	}
d06bb548e48d (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
}
d06bb548e48d (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
d06bb548e48d (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
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   186
void DrawWindowWidgets(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
{
2548
97ada3bd2702 (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2448
diff changeset
   188
	const DrawPixelInfo* dpi = _cur_dpi;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   189
	Rect r;
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   190
	uint i;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   191
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   192
	for (i = 0; i < w->widget_count; i++) {
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   193
		const Widget *wi = &w->widget[i];
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   194
		bool clicked = IsWindowWidgetLowered(w, i);
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   195
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   196
		if (dpi->left > (r.right=/*w->left + */wi->right) ||
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   197
				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
   198
				dpi->top > (r.bottom=/*w->top +*/ wi->bottom) ||
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   199
				dpi->top + dpi->height <= (r.top = /*w->top +*/ wi->top) ||
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   200
				IsWindowWidgetHidden(w, i)) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   201
			continue;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   202
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   204
		switch (wi->type & WWT_MASK) {
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   205
		case WWT_IMGBTN:
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   206
		case WWT_IMGBTN_2: {
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   207
			int img = wi->data;
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   208
			assert(img != 0);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   209
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   210
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   211
			/* show different image when clicked for WWT_IMGBTN_2 */
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   212
			if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   213
			DrawSprite(img, r.left + 1 + clicked, r.top + 1 + clicked);
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   214
			goto draw_default;
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   215
		}
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   216
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   217
		case WWT_PANEL: {
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   218
			assert(wi->data == 0);
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   219
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
			goto draw_default;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   223
		case WWT_TEXTBTN:
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   224
		case WWT_TEXTBTN_2: {
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   225
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
		/* fall through */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
4345
dd12549ad473 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 3762
diff changeset
   229
		case WWT_LABEL: {
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   230
			StringID str = wi->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   232
			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
   233
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   234
			DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, 0);
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2026
diff changeset
   235
			goto draw_default;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
4939
ede0f6777b3c (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   238
		case WWT_INSET: {
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   239
			StringID str = wi->data;
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   240
			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
   241
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   242
			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
   243
			goto draw_default;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   246
		case WWT_MATRIX: {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   247
			int c, d, ctr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   248
			int x, amt1, amt2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   249
			int color;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   250
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   251
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   252
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   253
			c = GB(wi->data, 0, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			amt1 = (wi->right - wi->left + 1) / c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   256
			d = GB(wi->data, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
			amt2 = (wi->bottom - wi->top + 1) / d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   259
			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
   260
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
			x = r.left;
2801
c70673b84010 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   262
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
				x += amt1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   264
				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
   265
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   266
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
			x = r.top;
2801
c70673b84010 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   268
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				x += amt2;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   270
				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
   271
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   273
			color = _colour_gradient[wi->color&0xF][4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   274
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   275
			x = r.left - 1;
2801
c70673b84010 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   276
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
				x += amt1;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   278
				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
   279
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   281
			x = r.top - 1;
2801
c70673b84010 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   282
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
				x += amt2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   284
				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
   285
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   287
			goto draw_default;
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
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   290
		// vertical scrollbar
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   291
		case WWT_SCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
			Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   293
			int c1,c2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
893
d9e69e5060ba (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
   295
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
d9e69e5060ba (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
   296
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
			// draw up/down buttons
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   298
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   299
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : 0);
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   300
			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
   301
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   302
			clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   303
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   304
			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
   305
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   306
			c1 = _colour_gradient[wi->color&0xF][3];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   307
			c2 = _colour_gradient[wi->color&0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   309
			// draw "shaded" background
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
2218
abd47ef7d902 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
   311
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
			// draw shaded lines
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   314
			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
   315
			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
   316
			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
   317
			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
   318
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   320
			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 : 0);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   321
			break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   322
		}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   323
		case WWT_SCROLL2BAR: {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   324
			Point pt;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   325
			int c1,c2;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   326
893
d9e69e5060ba (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
   327
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
d9e69e5060ba (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
   328
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   329
			// draw up/down buttons
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   330
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   331
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : 0);
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   332
			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, 0x10);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   333
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   334
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   335
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : 0);
2406
be5cfb8cd20d (svn r2932) Give the strings consisting of an up/a down arrow symbolic names
tron
parents: 2218
diff changeset
   336
			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, 0x10);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   337
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   338
			c1 = _colour_gradient[wi->color&0xF][3];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   339
			c2 = _colour_gradient[wi->color&0xF][7];
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   340
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   341
			// draw "shaded" background
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   342
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c2);
2218
abd47ef7d902 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
   343
			GfxFillRect(r.left, r.top+10, r.right, r.bottom-10, c1 | PALETTE_MODIFIER_GREYOUT);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   344
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   345
			// draw shaded lines
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   346
			GfxFillRect(r.left+2, r.top+10, r.left+2, r.bottom-10, c1);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   347
			GfxFillRect(r.left+3, r.top+10, r.left+3, r.bottom-10, c2);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   348
			GfxFillRect(r.left+7, r.top+10, r.left+7, r.bottom-10, c1);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   349
			GfxFillRect(r.left+8, r.top+10, r.left+8, r.bottom-10, c2);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   350
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   351
			pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   352
			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 : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   353
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   354
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   355
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   356
		// horizontal scrollbar
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
		case WWT_HSCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   358
			Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   359
			int c1,c2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   360
894
ab8a5f7ea3db (svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents: 893
diff changeset
   361
			assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
893
d9e69e5060ba (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
   362
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   363
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   364
			DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   365
			DrawSprite(SPR_ARROW_LEFT, r.left + 1 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
4940
2ff872152453 (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   367
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   368
			DrawFrameRect(r.right-9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   369
			DrawSprite(SPR_ARROW_RIGHT, r.right - 8 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   370
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   371
			c1 = _colour_gradient[wi->color&0xF][3];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   372
			c2 = _colour_gradient[wi->color&0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   373
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   374
			// draw "shaded" background
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c2);
2218
abd47ef7d902 (svn r2736) -Codechange: De-mystified GfxDrawFillRect a bit, and used enums from table/sprites.h. You can now change the number of bits used for sprites and switches in the SpriteSetup enum and the rest should work automagically. Can be used to increase the number of active sprites to 2^19 in case there are no colortables (recolor sprites) in any newgrf. We should possibly move the the colortables to an own list, but how to detect them in a newgrf.
celestar
parents: 2186
diff changeset
   376
			GfxFillRect(r.left+10, r.top, r.right-10, r.bottom, c1 | PALETTE_MODIFIER_GREYOUT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   377
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   378
			// draw shaded lines
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
			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
   380
			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
   381
			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
   382
			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
   383
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   384
			// draw actual scrollbar
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   385
			pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   386
			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 : 0);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   387
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   388
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   389
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   390
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   391
		case WWT_FRAME: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
			int c1,c2;
860
d756b3e0e171 (svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents: 845
diff changeset
   393
			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
   394
4547
9786a24c4102 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   395
			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
   396
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   397
			c1 = _colour_gradient[wi->color][3];
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   398
			c2 = _colour_gradient[wi->color][7];
0
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
			//Line from upper left corner to start of text
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   401
			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
   402
			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
   403
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   404
			// Line from end of text to upper right corner
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   405
			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
   406
			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
   407
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   408
			// Line from upper left corner to bottom left corner
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
			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
   410
			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
   411
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   412
			//Line from upper right corner to bottom right corner
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
			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
   414
			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
   415
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   416
			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
   417
			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
   418
2064
c889fcc76398 (svn r2573) Codechange: Removed WDF_RESTORE_DPARAM, it's not needed with the new string system.
ludde
parents: 2026
diff changeset
   419
			goto draw_default;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   420
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
682
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   422
		case WWT_STICKYBOX: {
893
d9e69e5060ba (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
   423
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
2703
edd58a233988 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   424
edd58a233988 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   425
			clicked = !!(w->flags4 & WF_STICKY);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   426
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   427
			DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, r.left + 2 + clicked, r.top + 3 + clicked);
682
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   428
			break;
7f5de4abac85 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   429
		}
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   430
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   431
		case WWT_RESIZEBOX: {
893
d9e69e5060ba (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!
915
013cb2d74800 (svn r1402) Trim trailing whitespace
tron
parents: 894
diff changeset
   433
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   434
			clicked = !!(w->flags4 & WF_SIZING);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   435
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : 0);
1657
eb57fee328fb (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   436
			DrawSprite(SPR_WINDOW_RESIZE, r.left + 3 + clicked, r.top + 3 + clicked);
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   437
			break;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   438
		}
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   439
2757
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   440
		case WWT_CLOSEBOX: {
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   441
			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   442
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   443
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, 0);
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   444
			DrawString(r.left + 2, r.top + 2, STR_00C5, 0);
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   445
			break;
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   446
		}
854d1b1d61b2 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   447
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   448
		case WWT_CAPTION: {
893
d9e69e5060ba (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
   449
			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   450
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   451
			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
   452
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   453
			if (w->caption_color != 0xFF) {
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   454
				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
   455
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   456
5017
e085e1fca90b (svn r7058) -Codechange: Truncate text in window captions
peter1138
parents: 4940
diff changeset
   457
			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
   458
draw_default:;
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   459
			if (IsWindowWidgetDisabled(w, i)) {
4444
9c9c7f962482 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   460
				GfxFillRect(r.left+1, r.top+1, r.right-1, r.bottom-1, _colour_gradient[wi->color&0xF][2] | PALETTE_MODIFIER_GREYOUT);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   461
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   462
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
		}
5236
e959e132a78e (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   464
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   465
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   466
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   467
	if (w->flags4 & WF_WHITE_BORDER_MASK) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
		//DrawFrameRect(w->left, w->top, w->left + w->width-1, w->top+w->height-1, 0xF, 0x10);
1938
21bd6ef5f85e (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   469
		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
   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
}
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
   473
883
0c54c6fc1790 (svn r1368) -Fix: Disabled dropdown menu options are gray again (instead of blue)
truelight
parents: 876
diff changeset
   474
static const Widget _dropdown_menu_widgets[] = {
4938
074f734a91ca (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   475
{      WWT_PANEL,   RESIZE_NONE,     0,     0, 0,     0, 0, 0x0, STR_NULL},
5041
6e292440425f (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
   476
{  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
   477
{   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
   478
};
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
   479
2436
177cb6a8339f (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   480
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
   481
{
2448
0a34e90cb31f (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
   482
	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
   483
	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
   484
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
   485
	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
   486
		return -1;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   487
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   488
	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
   489
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
	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
   491
		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
   492
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
	item = y / 10;
2683
6f67fcf73873 (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
   494
	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
   495
		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
   496
2448
0a34e90cb31f (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
   497
	// Skip hidden items -- +1 for each hidden item before the clicked item.
0a34e90cb31f (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
   498
	for (counter = 0; item >= counter; ++counter)
2683
6f67fcf73873 (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
   499
		if (HASBIT(WP(w,dropdown_d).hidden_state, counter)) item++;
2448
0a34e90cb31f (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
   500
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
   501
	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
   502
}
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
   503
1095
90220990fd7c (svn r1596) Add some more statics
tron
parents: 915
diff changeset
   504
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
   505
{
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
   506
	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
   507
2952
6a26eeda9679 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2801
diff changeset
   508
	switch (e->event) {
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   509
		case WE_PAINT: {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   510
			int x,y,i,sel;
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   511
			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
   512
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   513
			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
   514
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   515
			x = 1;
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   516
			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
   517
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   518
			sel    = WP(w,dropdown_d).selected_index;
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   519
			width  = w->widget[0].right - 3;
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   520
			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
   521
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   522
			for (i = 0; WP(w,dropdown_d).items[i] != INVALID_STRING_ID; i++, sel--) {
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   523
				if (HASBIT(WP(w,dropdown_d).hidden_state, i)) continue;
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   524
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   525
				if (y >= 0 && y <= height) {
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   526
					if (WP(w,dropdown_d).items[i] != STR_NULL) {
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   527
						if (sel == 0) GfxFillRect(x + 1, y, x + width, y + 9, 0);
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   528
						DrawStringTruncated(x + 2, y, WP(w,dropdown_d).items[i], sel == 0 ? 12 : 16, x + width);
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   529
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   530
						if (HASBIT(WP(w,dropdown_d).disabled_state, i)) {
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   531
							GfxFillRect(x, y, x + width, y + 9,
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   532
								PALETTE_MODIFIER_GREYOUT | _colour_gradient[_dropdown_menu_widgets[0].color][5]
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   533
							);
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   534
						}
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   535
					} else {
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   536
						int c1 = _colour_gradient[_dropdown_menu_widgets[0].color][3];
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   537
						int c2 = _colour_gradient[_dropdown_menu_widgets[0].color][7];
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   538
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   539
						GfxFillRect(x + 1, y + 3, x + w->width - 5, y + 3, c1);
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   540
						GfxFillRect(x + 1, y + 4, x + w->width - 5, y + 4, c2);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   541
					}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   542
				}
1177
6adbf59f59a3 (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
   543
				y += 10;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   544
			}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   545
		} break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   546
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   547
		case WE_CLICK: {
5041
6e292440425f (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
   548
			if (e->we.click.widget != 0) break;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   549
			item = GetDropdownItem(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   550
			if (item >= 0) {
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   551
				WP(w,dropdown_d).click_delay = 4;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   552
				WP(w,dropdown_d).selected_index = item;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   553
				SetWindowDirty(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   554
			}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   555
		} break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   556
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   557
		case WE_MOUSELOOP: {
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   558
			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   559
			if (w2 == NULL) {
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   560
				DeleteWindow(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   561
				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
   562
			}
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
   563
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   564
			if (WP(w,dropdown_d).click_delay != 0 && --WP(w,dropdown_d).click_delay == 0) {
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   565
				WindowEvent e;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   566
				e.event = WE_DROPDOWN_SELECT;
4634
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4573
diff changeset
   567
				e.we.dropdown.button = WP(w,dropdown_d).parent_button;
897461a3e9ca (svn r6499) -Codechange: Finally, got "byte event" outside of the union WindowEvent, which is now a struct
belugas
parents: 4573
diff changeset
   568
				e.we.dropdown.index  = WP(w,dropdown_d).selected_index;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   569
				w2->wndproc(w2, &e);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   570
				DeleteWindow(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   571
				return;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   572
			}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   573
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   574
			if (WP(w,dropdown_d).drag_mode) {
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   575
				item = GetDropdownItem(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   576
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   577
				if (!_left_button_clicked) {
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   578
					WP(w,dropdown_d).drag_mode = false;
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   579
					if (item < 0) return;
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   580
					WP(w,dropdown_d).click_delay = 2;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   581
				} else {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   582
					if (item < 0) return;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   583
				}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   584
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   585
				WP(w,dropdown_d).selected_index = item;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   586
				SetWindowDirty(w);
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   587
			}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   588
		} break;
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   589
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   590
		case WE_DESTROY: {
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   591
			Window *w2 = FindWindowById(WP(w,dropdown_d).parent_wnd_class, WP(w,dropdown_d).parent_wnd_num);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   592
			if (w2 != NULL) {
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   593
				RaiseWindowWidget(w2, WP(w,dropdown_d).parent_button);
2636
e2bfdc3e82b6 (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
				InvalidateWidget(w2, WP(w,dropdown_d).parent_button);
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   595
			}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   596
		} 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
   597
	}
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
   598
}
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
   599
2448
0a34e90cb31f (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
   600
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
   601
{
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   602
	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
   603
	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
   604
	Window *w2;
5041
6e292440425f (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
   605
	const Window *w3;
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   606
	bool is_dropdown_menu_shown = IsWindowWidgetLowered(w, button);
5041
6e292440425f (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
   607
	int top, height;
6e292440425f (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
   608
	int screen_top, screen_bottom;
6e292440425f (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
   609
	bool scroll = false;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   610
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
   611
	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
   612
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   613
	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
   614
4719
413b21513ef7 (svn r6631) -Codechange: Use accessors for click_state.
belugas
parents: 4634
diff changeset
   615
	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
   616
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
   617
	InvalidateWidget(w, button);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   618
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   619
	for (i = 0; strings[i] != INVALID_STRING_ID; i++) {}
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   620
	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
   621
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
   622
	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
   623
2448
0a34e90cb31f (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
   624
	if (hidden_mask != 0) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   625
		uint j;
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   626
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   627
		for (j = 0; strings[j] != INVALID_STRING_ID; j++) {
2639
8a7342eb3a78 (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   628
			if (HASBIT(hidden_mask, j)) i--;
842
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   629
		}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   630
	}
ebfd36603ab9 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   631
5041
6e292440425f (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
   632
	/* The preferred position is just below the dropdown calling widget */
6e292440425f (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
   633
	top = w->top + wi->bottom + 2;
6e292440425f (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
   634
	height = i * 10 + 4;
6e292440425f (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
   635
6e292440425f (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
   636
	w3 = FindWindowById(WC_STATUS_BAR, 0);
6e292440425f (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
   637
	screen_bottom = w3 == NULL ? _screen.height : w3->top;
6e292440425f (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
   638
6e292440425f (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
   639
	/* Check if the dropdown will fully fit below the widget */
6e292440425f (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
   640
	if (top + height >= screen_bottom) {
6e292440425f (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
		w3 = FindWindowById(WC_MAIN_TOOLBAR, 0);
6e292440425f (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
		screen_top = w3 == NULL ? 0 : w3->top + w3->height;
6e292440425f (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
6e292440425f (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
		/* If not, check if it will fit above the widget */
6e292440425f (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
		if (w->top + wi->top - height - 1 > screen_top) {
6e292440425f (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
			top = w->top + wi->top - height - 1;
6e292440425f (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
		} else {
6e292440425f (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
			/* ... and lastly if it won't, enable the scroll bar and fit the
6e292440425f (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
			 * list in below the widget */
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   650
			int rows = (screen_bottom - 4 - top) / 10;
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   651
			height = rows * 10 + 4;
5041
6e292440425f (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
			scroll = true;
6e292440425f (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
		}
6e292440425f (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
	}
6e292440425f (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
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
   656
	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
   657
		w->left + wi[-1].left + 1,
5041
6e292440425f (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
		top,
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   659
		wi->right - wi[-1].left + 1,
5041
6e292440425f (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
   660
		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
   661
		DropdownMenuWndProc,
4573
65b6fe8b65b4 (svn r6423) -Codechange: Replace two magic numbers by appropriate enum/define value
belugas
parents: 4547
diff changeset
   662
		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
   663
		_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
   664
867
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   665
	w2->widget[0].color = wi->color;
581154a08a78 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   666
	w2->widget[0].right = wi->right - wi[-1].left;
5041
6e292440425f (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
	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
   668
5041
6e292440425f (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
	SetWindowWidgetHiddenState(w2, 1, !scroll);
6e292440425f (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
   670
6e292440425f (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
   671
	if (scroll) {
6e292440425f (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
   672
		/* We're scrolling, so enable the scroll bar and shrink the list by
6e292440425f (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
   673
		 * the scrollbar's width */
6e292440425f (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
   674
		w2->widget[1].color  = wi->color;
6e292440425f (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
   675
		w2->widget[1].right  = w2->widget[0].right;
6e292440425f (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[1].left   = w2->widget[1].right - 11;
6e292440425f (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
   677
		w2->widget[1].bottom = height - 1;
6e292440425f (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
		w2->widget[0].right -= 12;
6e292440425f (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
5196
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   680
		w2->vscroll.cap   = (height - 4) / 10;
c419a5b39f8f (svn r7310) -Codechange: Change scrolling dropdown box to use 1 scroll unit = 1 line
peter1138
parents: 5125
diff changeset
   681
		w2->vscroll.count = i;
5041
6e292440425f (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
	}
6e292440425f (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
6e292440425f (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->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
   685
	w2->flags4 &= ~WF_WHITE_BORDER_MASK;
2629
842a290af2fb (svn r3171) - Codechange: remove static _dropdown_disabled/_dropdown_hidden variables, as a window already contains this information.
peter1138
parents: 2597
diff changeset
   686
2683
6f67fcf73873 (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
   687
	WP(w2,dropdown_d).disabled_state = disabled_mask;
6f67fcf73873 (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
   688
	WP(w2,dropdown_d).hidden_state = hidden_mask;
2636
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   689
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   690
	WP(w2,dropdown_d).parent_wnd_class = w->window_class;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   691
	WP(w2,dropdown_d).parent_wnd_num = w->window_number;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   692
	WP(w2,dropdown_d).parent_button = button;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   693
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   694
	WP(w2,dropdown_d).num_items = i;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   695
	WP(w2,dropdown_d).selected_index = selected;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   696
	WP(w2,dropdown_d).items = strings;
e2bfdc3e82b6 (svn r3178) - Codechange: move static _dropdown_* vars into the window custom data, giving var1 and var2 more meaningful names.
peter1138
parents: 2629
diff changeset
   697
e2bfdc3e82b6 (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
	WP(w2,dropdown_d).click_delay = 0;
e2bfdc3e82b6 (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).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
   700
}