src/widget.cpp
author peter1138
Thu, 17 Jan 2008 18:09:15 +0000
changeset 8335 09a2e049b3a8
parent 8320 5a41b1329cdf
child 8349 e61105cb1f87
permissions -rw-r--r--
(svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
     3
/** @file widget.cpp */
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1657
diff changeset
     6
#include "openttd.h"
8254
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8224
diff changeset
     7
#include "core/math_func.hpp"
1496654ca5e7 (svn r11818) -Codechange: split player.h into smaller pieces.
rubidium
parents: 8224
diff changeset
     8
#include "player_func.h"
8224
c5a64d87cc54 (svn r11787) -Codechange: more header rewrites. This time related to viewport.h.
rubidium
parents: 8131
diff changeset
     9
#include "gfx_func.h"
8106
e6790dd9e750 (svn r11667) -Codechange: split window.h into a header that defines some 'global' window related types, on that defined 'global' window functions and one that defines functions and types only used by *_gui.cpps.
rubidium
parents: 8082
diff changeset
    10
#include "window_gui.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8121
diff changeset
    11
#include "window_func.h"
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents: 8264
diff changeset
    12
#include "widgets/dropdown_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8121
diff changeset
    13
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    14
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8254
diff changeset
    15
#include "table/strings.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    16
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
    17
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
    18
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    19
	Point pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    20
	int height, count, pos, cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    21
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    22
	top += 10;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    23
	bottom -= 9;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
    24
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    25
	height = (bottom - top);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    26
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    27
	pos = sb->pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    28
	count = sb->count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    29
	cap = sb->cap;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    30
2026
567e3bc9af72 (svn r2535) Tabs
tron
parents: 2021
diff changeset
    31
	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
    32
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    33
	if (cap > count) cap = count;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
    34
	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
    35
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    36
	pt.x = top;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    37
	pt.y = bottom - 1;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    38
	return pt;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    39
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    40
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
    41
/** Special handling for the scrollbar widget type.
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    42
 * Handles the special scrolling buttons and other
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    43
 * scrolling.
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
    44
 * @param w Window on which a scroll was performed.
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
    45
 * @param wi Pointer to the scrollbar widget.
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
    46
 * @param x The X coordinate of the mouse click.
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
    47
 * @param y The Y coordinate of the mouse click. */
0
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
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    53
	switch (wi->type) {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    54
		case WWT_SCROLLBAR: {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
    55
			/* vertical scroller */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    56
			w->flags4 &= ~WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    57
			w->flags4 &= ~WF_SCROLL2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    58
			mi = wi->top;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    59
			ma = wi->bottom;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    60
			pos = y;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    61
			sb = &w->vscroll;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    62
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    63
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    64
		case WWT_SCROLL2BAR: {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
    65
			/* 2nd vertical scroller */
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    66
			w->flags4 &= ~WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    67
			w->flags4 |= WF_SCROLL2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    68
			mi = wi->top;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    69
			ma = wi->bottom;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    70
			pos = y;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    71
			sb = &w->vscroll2;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    72
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    73
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    74
		case  WWT_HSCROLLBAR: {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
    75
			/* horizontal scroller */
867
dffd33233237 (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
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    77
			w->flags4 |= WF_HSCROLL;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    78
			mi = wi->left;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    79
			ma = wi->right;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    80
			pos = x;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    81
			sb = &w->hscroll;
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
    82
			break;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
    83
		}
845
4960e265d25b (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) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
    87
		/* Pressing the upper button? */
2597
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    88
		w->flags4 |= WF_SCROLL_UP;
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    89
		if (_scroller_click_timeout == 0) {
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    90
			_scroller_click_timeout = 6;
b806dafa9be6 (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
b806dafa9be6 (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) {
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
    95
		/* Pressing the lower button? */
2597
b806dafa9be6 (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
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    98
		if (_scroller_click_timeout == 0) {
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
    99
			_scroller_click_timeout = 6;
b806dafa9be6 (svn r3134) Forgot to commit one file in r3133
tron
parents: 2548
diff changeset
   100
			if ((byte)(sb->pos + sb->cap) < sb->count)
b806dafa9be6 (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
b806dafa9be6 (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 {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   105
		Point pt = HandleScrollbarHittest(sb, mi, ma);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   106
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   107
		if (pos < pt.x) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   108
			sb->pos = max(sb->pos - sb->cap, 0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   109
		} else if (pos > pt.y) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   110
			sb->pos = min(
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   111
				sb->pos + sb->cap,
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
				max(sb->count - sb->cap, 0)
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   113
			);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   114
		} else {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   115
			_scrollbar_start_pos = pt.x - mi - 9;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   116
			_scrollbar_size = ma - mi - 23;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
			w->flags4 |= WF_SCROLL_MIDDLE;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   118
			_scrolling_scrollbar = true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   119
			_cursorpos_drag_start = _cursor.pos;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   120
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   121
	}
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
	SetWindowDirty(w);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   124
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   125
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   126
/** Returns the index for the widget located at the given position
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   127
 * relative to the window. It includes all widget-corner pixels as well.
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   128
 * @param *w Window to look inside
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
   129
 * @param  x The Window client X coordinate
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
   130
 * @param  y The Window client y coordinate
2021
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   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
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   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
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   135
	uint index;
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   136
	int found_index = -1;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   137
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   138
	/* Go through the widgets and check if we find the widget that the coordinate is
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   139
	 * inside. */
5236
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   140
	for (index = 0; index < w->widget_count; index++) {
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   141
		const Widget *wi = &w->widget[index];
2639
eeaefdabfdfd (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
3a8c59ea3fbe (svn r2530) - Fix: [ 1219829 ] Mouse-wheel crashes OTTD. Widget detection failed to detect the most-right and most-bottom pixels of a widget. If scrollwheel is used on a not-found widget (such as the background of the toolbar), it will now fail correctly (glx)
Darkvater
parents: 1938
diff changeset
   144
		if (x >= wi->left && x <= wi->right && y >= wi->top &&  y <= wi->bottom &&
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7962
diff changeset
   145
				!w->IsWidgetHidden(index)) {
2639
eeaefdabfdfd (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
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   154
void DrawFrameRect(int left, int top, int right, int bottom, int ctab, FrameFlags flags)
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   155
{
4444
8d40844e6755 (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];
8d40844e6755 (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];
8d40844e6755 (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];
8d40844e6755 (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
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   160
4438
c8b86504b83c (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) {
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   162
		GfxFillRect(left, top, right, bottom, PALETTE_TO_TRANSPARENT | (1 << USE_COLORTABLE));
4437
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   163
	} else {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   164
		uint interior;
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   165
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   166
		if (flags & FR_LOWERED) {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   167
			GfxFillRect(left,     top,     left,  bottom,     dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   168
			GfxFillRect(left + 1, top,     right, top,        dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   169
			GfxFillRect(right,    top + 1, right, bottom - 1, light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   170
			GfxFillRect(left + 1, bottom,  right, bottom,     light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   171
			interior = (flags & FR_DARKENED ? medium_dark : medium_light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   172
		} else {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   173
			GfxFillRect(left,     top,    left,      bottom - 1, light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   174
			GfxFillRect(left + 1, top,    right - 1, top,        light);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   175
			GfxFillRect(right,    top,    right,     bottom - 1, dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   176
			GfxFillRect(left,     bottom, right,     bottom,     dark);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   177
			interior = medium_dark;
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   178
		}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   179
		if (!(flags & FR_BORDERONLY)) {
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   180
			GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, interior);
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   181
		}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   182
	}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   183
}
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   184
49e79e135539 (svn r6209) Move DrawFrameRect() out of gfx.[ch], because it uses data (_color_list) which the renderer shouldn't have know about
tron
parents: 4345
diff changeset
   185
2436
7d5df545bd5d (svn r2962) - const correctness for all Get* functions and most Draw* functions that don't change their pointer parameters
Darkvater
parents: 2406
diff changeset
   186
void DrawWindowWidgets(const Window *w)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   187
{
2548
49c8a096033f (svn r3077) static, const, bracing, indentation, 0 -> '\0'/NULL, typos in comments, excess empty lines, minor other changes
tron
parents: 2448
diff changeset
   188
	const DrawPixelInfo* dpi = _cur_dpi;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   189
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   190
	for (uint i = 0; i < w->widget_count; i++) {
5236
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   191
		const Widget *wi = &w->widget[i];
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7962
diff changeset
   192
		bool clicked = w->IsWidgetLowered(i);
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   193
		Rect r;
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   194
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   195
		if (dpi->left > (r.right = wi->right) ||
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   196
				dpi->left + dpi->width <= (r.left = wi->left) ||
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   197
				dpi->top > (r.bottom = wi->bottom) ||
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   198
				dpi->top + dpi->height <= (r.top = wi->top) ||
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7962
diff changeset
   199
				w->IsWidgetHidden(i)) {
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   200
			continue;
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   201
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   203
		switch (wi->type & WWT_MASK) {
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   204
		case WWT_IMGBTN:
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   205
		case WWT_IMGBTN_2: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   206
			SpriteID img = wi->data;
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   207
			assert(img != 0);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   208
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   210
			/* show different image when clicked for WWT_IMGBTN_2 */
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   211
			if ((wi->type & WWT_MASK) == WWT_IMGBTN_2 && clicked) img++;
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   212
			DrawSprite(img, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   213
			break;
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   214
		}
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   215
4938
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   216
		case WWT_PANEL: {
0447845fd1b3 (svn r6925) -Codechange: Be more strict with widget distinctions. WWT_PANEL is only plain panel,
Darkvater
parents: 4749
diff changeset
   217
			assert(wi->data == 0);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   218
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   219
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   220
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   221
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   222
		case WWT_TEXTBTN:
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   223
		case WWT_TEXTBTN_2: {
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   224
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
		/* fall through */
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
4345
1da147230c79 (svn r6046) CodeChange : Rename WWT_5 Widget type to WWT_LABEL : a centered label
belugas
parents: 3762
diff changeset
   228
		case WWT_LABEL: {
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   229
			StringID str = wi->data;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   230
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   231
			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
   232
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   233
			DrawStringCentered(((r.left + r.right + 1) >> 1) + clicked, ((r.top + r.bottom + 1) >> 1) - 5 + clicked, str, TC_FROMSTRING);
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   234
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   235
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   236
6278
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   237
		case WWT_TEXT: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   238
			const StringID str = wi->data;
6278
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   239
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   240
			if (str != STR_NULL) DrawStringTruncated(r.left, r.top, str, wi->color, r.right - r.left);
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   241
			break;
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   242
		}
f4d4b7c1c886 (svn r9088) -Add : a new type of widget, called WWT_TEXT. It is a simple truncated string. It will be usefull on windows where lot of simple text is always drawn on the WE_PAINT event, making the code clearer. For now, left, right (total size of the window), top, color and data are necessary to use it. Maybe more features will be available soon.
belugas
parents: 5824
diff changeset
   243
4939
bef7c24a6027 (svn r6926) -Codechange: Rename WWT_4 to WWT_TEXTBTN_2 and WWT_6 to WWT_INSET (credits to peter1138
Darkvater
parents: 4938
diff changeset
   244
		case WWT_INSET: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   245
			const StringID str = wi->data;
1938
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   246
			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
   247
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   248
			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_FROMSTRING, r.right - r.left - 10);
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   249
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   250
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   252
		case WWT_MATRIX: {
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   253
			int c, d, ctr;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
			int x, amt1, amt2;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   255
			int color;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   256
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   257
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   258
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   259
			c = GB(wi->data, 0, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
			amt1 = (wi->right - wi->left + 1) / c;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
4547
d37c2d172ad4 (svn r6379) -Codechange: cast 'remove babel' on widget's unkA and rename it to 'data'.
Darkvater
parents: 4444
diff changeset
   262
			d = GB(wi->data, 8, 8);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
			amt2 = (wi->bottom - wi->top + 1) / d;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   264
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   265
			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
   266
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   267
			x = r.left;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   268
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   269
				x += amt1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   270
				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
   271
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   272
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
			x = r.top;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   274
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   275
				x += amt2;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   276
				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
   277
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   278
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   279
			color = _colour_gradient[wi->color & 0xF][4];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   281
			x = r.left - 1;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   282
			for (ctr = c; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   283
				x += amt1;
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   284
				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
   285
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2636
diff changeset
   287
			x = r.top - 1;
2801
b9062d829629 (svn r3349) Fix off-by-one error in drawing matrix widget, from r3181.
peter1138
parents: 2757
diff changeset
   288
			for (ctr = d; ctr > 1; ctr--) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   289
				x += amt2;
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   290
				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
   291
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   292
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   293
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   294
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   295
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   296
		/* vertical scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   297
		case WWT_SCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   298
			Point pt;
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   299
			int c1, c2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   300
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   301
			assert(wi->data == 0);
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   302
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   303
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   304
			/* draw up/down buttons */
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   305
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_UP);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   306
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   307
			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   308
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   309
			clicked = (((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_DOWN));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   310
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   311
			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   312
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   313
			c1 = _colour_gradient[wi->color & 0xF][3];
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   314
			c2 = _colour_gradient[wi->color & 0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   315
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   316
			/* draw "shaded" background */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   317
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   318
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   319
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   320
			/* draw shaded lines */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   321
			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   322
			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   323
			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   324
			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
   325
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
			pt = HandleScrollbarHittest(&w->vscroll, r.top, r.bottom);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   327
			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == WF_SCROLL_MIDDLE ? FR_LOWERED : FR_NONE);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   328
			break;
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   329
		}
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   330
		case WWT_SCROLL2BAR: {
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   331
			Point pt;
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   332
			int c1, c2;
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   333
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   334
			assert(wi->data == 0);
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   335
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   336
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   337
			/* draw up/down buttons */
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   338
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_UP | WF_SCROLL2));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   339
			DrawFrameRect(r.left, r.top, r.right, r.top + 9, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   340
			DoDrawString(UPARROW, r.left + 2 + clicked, r.top + clicked, TC_BLACK);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   341
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   342
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_DOWN | WF_SCROLL2));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   343
			DrawFrameRect(r.left, r.bottom - 9, r.right, r.bottom, wi->color,  (clicked) ? FR_LOWERED : FR_NONE);
7824
5a63d41b59ea (svn r11374) -Codechange: Give meaning to the magical number that specifies the color of the text in a DrawString call.
belugas
parents: 6481
diff changeset
   344
			DoDrawString(DOWNARROW, r.left + 2 + clicked, r.bottom - 9 + clicked, TC_BLACK);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   345
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   346
			c1 = _colour_gradient[wi->color & 0xF][3];
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   347
			c2 = _colour_gradient[wi->color & 0xF][7];
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   348
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   349
			/* draw "shaded" background */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   350
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   351
			GfxFillRect(r.left, r.top + 10, r.right, r.bottom - 10, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   352
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   353
			/* draw shaded lines */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   354
			GfxFillRect(r.left + 2, r.top + 10, r.left + 2, r.bottom - 10, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   355
			GfxFillRect(r.left + 3, r.top + 10, r.left + 3, r.bottom - 10, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   356
			GfxFillRect(r.left + 7, r.top + 10, r.left + 7, r.bottom - 10, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   357
			GfxFillRect(r.left + 8, r.top + 10, r.left + 8, r.bottom - 10, c2);
842
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   358
efc3546bc313 (svn r1323) Adding autoreplace feature
bjarni
parents: 682
diff changeset
   359
			pt = HandleScrollbarHittest(&w->vscroll2, r.top, r.bottom);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   360
			DrawFrameRect(r.left, pt.x, r.right, pt.y, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL | WF_SCROLL2)) == (WF_SCROLL_MIDDLE | WF_SCROLL2) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   361
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   362
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   363
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   364
		/* horizontal scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
		case WWT_HSCROLLBAR: {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
			Point pt;
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   367
			int c1, c2;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   368
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   369
			assert(wi->data == 0);
894
8b59c639837d (svn r1380) -Fix: missed widget fixes; thanks Jango and TestMan57
darkvater
parents: 893
diff changeset
   370
			assert(r.bottom - r.top == 11); // XXX - to ensure the same sizes are used everywhere!
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   371
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   372
			clicked = ((w->flags4 & (WF_SCROLL_UP | WF_HSCROLL)) == (WF_SCROLL_UP | WF_HSCROLL));
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   373
			DrawFrameRect(r.left, r.top, r.left + 9, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   374
			DrawSprite(SPR_ARROW_LEFT, PAL_NONE, r.left + 1 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   375
4940
d021a1285a5f (svn r6927) -Codechange: No need to explicitly cast a boolean to a boolean and move draw_default
Darkvater
parents: 4939
diff changeset
   376
			clicked = ((w->flags4 & (WF_SCROLL_DOWN | WF_HSCROLL)) == (WF_SCROLL_DOWN | WF_HSCROLL));
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   377
			DrawFrameRect(r.right - 9, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   378
			DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, r.right - 8 + clicked, r.top + 1 + clicked);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   379
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   380
			c1 = _colour_gradient[wi->color & 0xF][3];
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   381
			c2 = _colour_gradient[wi->color & 0xF][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   382
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   383
			/* draw "shaded" background */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   384
			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   385
			GfxFillRect(r.left + 10, r.top, r.right - 10, r.bottom, c1 | (1 << PALETTE_MODIFIER_GREYOUT));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   386
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   387
			/* draw shaded lines */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   388
			GfxFillRect(r.left + 10, r.top + 2, r.right - 10, r.top + 2, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   389
			GfxFillRect(r.left + 10, r.top + 3, r.right - 10, r.top + 3, c2);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   390
			GfxFillRect(r.left + 10, r.top + 7, r.right - 10, r.top + 7, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   391
			GfxFillRect(r.left + 10, r.top + 8, r.right - 10, r.top + 8, c2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   392
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   393
			/* draw actual scrollbar */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   394
			pt = HandleScrollbarHittest(&w->hscroll, r.left, r.right);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   395
			DrawFrameRect(pt.x, r.top, pt.y, r.bottom, wi->color, (w->flags4 & (WF_SCROLL_MIDDLE | WF_HSCROLL)) == (WF_SCROLL_MIDDLE | WF_HSCROLL) ? FR_LOWERED : FR_NONE);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   396
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   397
			break;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   398
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   399
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   400
		case WWT_FRAME: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   401
			const StringID str = wi->data;
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   402
			int c1, c2;
860
fad6642f6217 (svn r1341) -Fix: fix WWT_FRAME drawing when there is no text there (STR_NULL)
darkvater
parents: 845
diff changeset
   403
			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
   404
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   405
			if (str != STR_NULL) x2 = DrawString(r.left + 6, r.top, str, TC_FROMSTRING);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   406
4444
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   407
			c1 = _colour_gradient[wi->color][3];
8d40844e6755 (svn r6222) Remove struct ColorList, because the names of its attributes are plain confusing
tron
parents: 4438
diff changeset
   408
			c2 = _colour_gradient[wi->color][7];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   409
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   410
			/* Line from upper left corner to start of text */
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   411
			GfxFillRect(r.left, r.top + 4, r.left + 4, r.top + 4, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   412
			GfxFillRect(r.left + 1, r.top + 5, r.left + 4, r.top + 5, c2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   413
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   414
			/* Line from end of text to upper right corner */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   415
			GfxFillRect(x2, r.top + 4, r.right - 1, r.top + 4, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   416
			GfxFillRect(x2, r.top + 5, r.right - 2, r.top + 5, c2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   417
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   418
			/* Line from upper left corner to bottom left corner */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   419
			GfxFillRect(r.left, r.top + 5, r.left, r.bottom - 1, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   420
			GfxFillRect(r.left + 1, r.top + 6, r.left + 1, r.bottom - 2, c2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   421
6432
226650eb2ef3 (svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents: 6278
diff changeset
   422
			/*Line from upper right corner to bottom right corner */
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   423
			GfxFillRect(r.right - 1, r.top + 5, r.right - 1, r.bottom - 2, c1);
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   424
			GfxFillRect(r.right, r.top + 4, r.right, r.bottom - 1, c2);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   425
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   426
			GfxFillRect(r.left + 1, r.bottom - 1, r.right - 1, r.bottom - 1, c1);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   427
			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
   428
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   429
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   430
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   431
682
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   432
		case WWT_STICKYBOX: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   433
			assert(wi->data == 0);
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   434
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
2703
a969970a5245 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   435
a969970a5245 (svn r3247) - Fix: "[ 1335580 ] sticky windows not sticky anymore"
peter1138
parents: 2683
diff changeset
   436
			clicked = !!(w->flags4 & WF_STICKY);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   437
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   438
			DrawSprite((clicked) ? SPR_PIN_UP : SPR_PIN_DOWN, PAL_NONE, r.left + 2 + clicked, r.top + 3 + clicked);
682
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   439
			break;
74c70f645d95 (svn r1121) -Feature: Added sticky windows feature. A small pin allows the user to set the window as undeletable and can only be closed by hand. As an example the viewport window has been stickied (thanks to Neko-San)
darkvater
parents: 674
diff changeset
   440
		}
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   441
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   442
		case WWT_RESIZEBOX: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   443
			assert(wi->data == 0);
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   444
			assert(r.right - r.left == 11); // XXX - to ensure the same sizes are used everywhere!
915
d845fe7cf6f2 (svn r1402) Trim trailing whitespace
tron
parents: 894
diff changeset
   445
1657
af84fedacc6d (svn r2161) - Fix: When resizing a window, the button is also visibly depressed
Darkvater
parents: 1363
diff changeset
   446
			clicked = !!(w->flags4 & WF_SIZING);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   447
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, (clicked) ? FR_LOWERED : FR_NONE);
5668
36b39f4a9032 (svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents: 5587
diff changeset
   448
			DrawSprite(SPR_WINDOW_RESIZE, PAL_NONE, r.left + 3 + clicked, r.top + 3 + clicked);
867
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   449
			break;
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   450
		}
dffd33233237 (svn r1348) -Feature: resizable windows. Read the comment in window.h to find out
truelight
parents: 860
diff changeset
   451
2757
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   452
		case WWT_CLOSEBOX: {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   453
			const StringID str = wi->data;
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   454
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   455
			assert(str == STR_00C5 || str == STR_00C6); // black or silver cross
2757
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   456
			assert(r.right - r.left == 10); // ensure the same sizes are used everywhere
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   457
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   458
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_NONE);
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   459
			DrawString(r.left + 2, r.top + 2, str, TC_FROMSTRING);
2757
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   460
			break;
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   461
		}
d1ccb6600be3 (svn r3302) - Fix: split drawing of text buttons and the closebox, so the closebox symbol can be centred.
peter1138
parents: 2703
diff changeset
   462
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   463
		case WWT_CAPTION: {
893
f4698309dec7 (svn r1379) -Fix: various GUI glitches. Added default sizes to various widgets. Sticky/Resize- and Scrollbar must be 11 pixels wide, Horizontal scrollbar 11 pixels high, caption must be 13 pixels. I hope I didn't forget any widgets, the game will assert for that so report them to me!
darkvater
parents: 884
diff changeset
   464
			assert(r.bottom - r.top == 13); // XXX - to ensure the same sizes are used everywhere!
1938
70baf462aff1 (svn r2444) - CodeChange: Add an enum for demagicifying the values of the 'flags' parameter of DrawFrameRect(). (_Abraxa_)
hackykid
parents: 1891
diff changeset
   465
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_BORDERONLY);
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   466
			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
   467
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   468
			if (w->caption_color != 0xFF) {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   469
				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
   470
			}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   471
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   472
			DrawStringCenteredTruncated(r.left + 2, r.right - 2, r.top + 2, wi->data, 0x84);
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   473
			break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   474
		}
8335
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   475
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   476
		case WWT_DROPDOWN: {
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   477
			assert(r.bottom - r.top == 11); // ensure consistent size
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   478
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   479
			StringID str = wi->data;
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   480
			DrawFrameRect(r.left, r.top, r.right - 12, r.bottom, wi->color, FR_NONE);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   481
			DrawFrameRect(r.right - 11, r.top, r.right, r.bottom, wi->color, clicked ? FR_LOWERED : FR_NONE);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   482
			DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   483
			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 1, str, TC_BLACK, r.right - r.left - 12);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   484
			break;
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   485
		}
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   486
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   487
		case WWT_DROPDOWNIN: {
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   488
			assert(r.bottom - r.top == 11); // ensure consistent size
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   489
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   490
			StringID str = wi->data;
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   491
			DrawFrameRect(r.left, r.top, r.right, r.bottom, wi->color, FR_LOWERED | FR_DARKENED);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   492
			DrawFrameRect(r.right - 11, r.top + 1, r.right - 1, r.bottom - 1, wi->color, clicked ? FR_LOWERED : FR_NONE);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   493
			DrawString(r.right - (clicked ? 8 : 9), r.top + (clicked ? 2 : 1), STR_0225, TC_BLACK);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   494
			if (str != STR_NULL) DrawStringTruncated(r.left + 2, r.top + 2, str, TC_BLACK, r.right - r.left - 12);
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   495
			break;
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8320
diff changeset
   496
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   497
		}
8320
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   498
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   499
		if (w->IsWidgetDisabled(i)) {
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   500
			GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, _colour_gradient[wi->color & 0xF][2] | (1 << PALETTE_MODIFIER_GREYOUT));
5a41b1329cdf (svn r11885) -Cleanup: Remove gotos from widget drawing code. A side affect is that it is now possible for any widget type to be shown disabled.
peter1138
parents: 8284
diff changeset
   501
		}
5236
4c1289d5e45a (svn r7356) -Codechange: replace 'for (i = 0, wi = w->widget; wi->type != WWT_LAST; i++, wi++)' type for loops with 'for (i = 0; i < w->window_count; i++) { wi = &w->widget[i];'-type for loops for better readability.
rubidium
parents: 5196
diff changeset
   502
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 176
diff changeset
   503
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   504
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   505
	if (w->flags4 & WF_WHITE_BORDER_MASK) {
7962
4a815b659fd7 (svn r11518) -Codechange: enforce (by assert) unused parameters of widgets to be zero. Better readability of DrawWindowWidgets(), too
smatz
parents: 7928
diff changeset
   506
		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
   507
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   508
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   509
}
164
0cbdf3c9bde1 (svn r165) -Feature: Option to sort vehicles in vehicle-list window by different criteria. Total independent sort for all types and players. Periodic resort of list every 10 TTD days. Thank you for your graphical inspiration follow and buxo (since none of you provided any code).
darkvater
parents: 0
diff changeset
   510
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   511
static void ResizeWidgets(Window *w, byte a, byte b)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   512
{
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   513
	int16 offset = w->widget[a].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   514
	int16 length = w->widget[b].right - offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   515
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   516
	w->widget[a].right  = (length / 2) + offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   517
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   518
	w->widget[b].left  = w->widget[a].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   519
}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   520
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   521
static void ResizeWidgets(Window *w, byte a, byte b, byte c)
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   522
{
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   523
	int16 offset = w->widget[a].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   524
	int16 length = w->widget[c].right - offset;
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   525
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   526
	w->widget[a].right = length / 3;
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   527
	w->widget[b].right = w->widget[a].right * 2;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   528
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   529
	w->widget[a].right += offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   530
	w->widget[b].right += offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   531
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   532
	/* Now the right side of the buttons are set. We will now set the left sides next to them */
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   533
	w->widget[b].left  = w->widget[a].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   534
	w->widget[c].left  = w->widget[b].right + 1;
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   535
}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   536
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   537
/** Evenly distribute some widgets when resizing horizontally (often a button row)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   538
 *  When only two arguments are given, the widgets are presumed to be on a line and only the ends are given
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6432
diff changeset
   539
 * @param w Window to modify
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   540
 * @param left The leftmost widget to resize
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   541
 * @param right The rightmost widget to resize. Since right side of it is used, remember to set it to RESIZE_RIGHT
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   542
 */
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   543
void ResizeButtons(Window *w, byte left, byte right)
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   544
{
5824
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   545
	int16 num_widgets = right - left + 1;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   546
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   547
	if (num_widgets < 2) NOT_REACHED();
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   548
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   549
	switch (num_widgets) {
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   550
		case 2: ResizeWidgets(w, left, right); break;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   551
		case 3: ResizeWidgets(w, left, left + 1, right); break;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   552
		default: {
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   553
			/* Looks like we got more than 3 widgets to resize
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   554
			 * Now we will find the middle of the space desinated for the widgets
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   555
			 * and place half of the widgets on each side of it and call recursively.
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   556
			 * Eventually we will get down to blocks of 2-3 widgets and we got code to handle those cases */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   557
			int16 offset = w->widget[left].left;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   558
			int16 length = w->widget[right].right - offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   559
			byte widget = ((num_widgets - 1)/ 2) + left; // rightmost widget of the left side
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   560
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   561
			/* Now we need to find the middle of the widgets.
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   562
			 * It will not always be the middle because if we got an uneven number of widgets,
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   563
			 *   we will need it to be 2/5, 3/7 and so on
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   564
			 * To get this, we multiply with num_widgets/num_widgets. Since we calculate in int, we will get:
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   565
			 *
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   566
			 *    num_widgets/2 (rounding down)
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   567
			 *   ---------------
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   568
			 *     num_widgets
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   569
			 *
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   570
			 * as multiplier to length. We just multiply before divide to that we stay in the int area though */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   571
			int16 middle = ((length * num_widgets) / (2 * num_widgets)) + offset;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   572
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   573
			/* Set left and right on the widgets, that's next to our "middle" */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   574
			w->widget[widget].right = middle;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   575
			w->widget[widget + 1].left = w->widget[widget].right + 1;
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   576
			/* Now resize the left and right of the middle */
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   577
			ResizeButtons(w, left, widget);
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   578
			ResizeButtons(w, widget + 1, right);
8398b44ad3bc (svn r8390) -Codechange (r8384): Rewrote ResizeButtons()
bjarni
parents: 5822
diff changeset
   579
		}
5822
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   580
	}
f71317de4ab6 (svn r8384) -Codechange: [GUI] instead of writing a resize button function for each window, a global ResizeButtons() is added
bjarni
parents: 5668
diff changeset
   581
}