src/transparency_gui.cpp
author belugas
Wed, 27 Feb 2008 04:26:25 +0000
changeset 8645 fd2d92d9761b
parent 8528 6e61e651790e
child 8657 e089730989d5
permissions -rw-r--r--
(svn r12288) -Fix(r12287): forgot to include two sprite renames out of consistency.
And obviously forgot to compile before committing, as the array rename would have been evident.
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     1
/* $Id$ */
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     2
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     3
#include "stdafx.h"
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     4
#include "openttd.h"
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     5
#include "gui.h"
8107
bb7deea89175 (svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents: 8106
diff changeset
     6
#include "window_gui.h"
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
     7
#include "variables.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7341
diff changeset
     8
#include "transparency.h"
8157
1505def01945 (svn r11719) -Codechange: split sound.h in a header with types and one with functions.
rubidium
parents: 8131
diff changeset
     9
#include "sound_func.h"
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7341
diff changeset
    10
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    11
#include "table/sprites.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    12
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8224
diff changeset
    13
7849
0a1c0af2c96c (svn r11399) -Feature(ette): transparency settings can now be saved and thus remembered.
belugas
parents: 7341
diff changeset
    14
TransparencyOptionBits _transparency_opt;
8527
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    15
TransparencyOptionBits _transparency_lock;
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    16
6496
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    17
enum TransparencyToolbarWidgets{
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    18
	TTW_WIDGET_SIGNS = 3,    ///< Make signs background transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    19
	TTW_WIDGET_TREES,        ///< Make trees transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    20
	TTW_WIDGET_HOUSES,       ///< Make houses transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    21
	TTW_WIDGET_INDUSTRIES,   ///< Make Industries transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    22
	TTW_WIDGET_BUILDINGS,    ///< Make player buildings and structures transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    23
	TTW_WIDGET_BRIDGES,      ///< Make bridges transparent
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    24
	TTW_WIDGET_STRUCTURES,   ///< Make unmovable structures transparent
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    25
	TTW_WIDGET_CATENARY,     ///< Make catenary transparent
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6600
diff changeset
    26
	TTW_WIDGET_LOADING,      ///< Make loading indicators transperent
6598
f2be0a6ba79a (svn r9812) -Fix (r9679): Obiwan prevented proper display of last transparency button.
peter1138
parents: 6496
diff changeset
    27
	TTW_WIDGET_END,          ///< End of toggle buttons
6496
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    28
};
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    29
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    30
static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    31
{
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    32
	switch (e->event) {
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    33
		case WE_PAINT:
6496
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    34
			/* must be sure that the widgets show the transparency variable changes
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    35
			 * also when we use shortcuts */
6598
f2be0a6ba79a (svn r9812) -Fix (r9679): Obiwan prevented proper display of last transparency button.
peter1138
parents: 6496
diff changeset
    36
			for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
7997
df87ccd00a96 (svn r11555) -Codechange: use the new members introduced in r11551.
rubidium
parents: 7849
diff changeset
    37
				w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    38
			}
8448
f716c812f401 (svn r12018) -Fix(FS#1721,r9563): Restore initial intent on the invisible tree while transparent building patch setting
belugas
parents: 8264
diff changeset
    39
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    40
			DrawWindowWidgets(w);
8527
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    41
			for (uint i = TO_SIGNS; i < TO_END; i++) {
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    42
				if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, w->widget[TTW_WIDGET_SIGNS + i].left + 1, w->widget[TTW_WIDGET_SIGNS + i].top + 1);
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    43
			}
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    44
			break;
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    45
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    46
		case WE_CLICK:
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    47
			if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) {
8527
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    48
				if (_ctrl_pressed) {
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    49
					/* toggle the bit of the transparencies lock variable */
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    50
					ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    51
					SetWindowDirty(w);
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    52
				} else {
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    53
					/* toggle the bit of the transparencies variable and play a sound */
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    54
					ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    55
					SndPlayFx(SND_15_BEEP);
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    56
					MarkWholeScreenDirty();
a32b9ac056af (svn r12102) -Feature: Allow locking individual transparency settings so they will not be changed by pressing 'x'. (Roujin)
maedhros
parents: 8452
diff changeset
    57
				}
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    58
			}
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    59
			break;
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    60
	}
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    61
}
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    62
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    63
static const Widget _transparency_widgets[] = {
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    64
{ WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    65
{  WWT_CAPTION,   RESIZE_NONE,  7,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    66
{WWT_STICKYBOX,   RESIZE_NONE,  7, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    67
6496
40748e256bbe (svn r9679) -Codechange: use enums to identify transparency widgets and add a bit of documentation (patch by Wolf01)
belugas
parents: 6427
diff changeset
    68
/* transparency widgets:
6998
39e783d3816c (svn r10254) -Feature: loading indicator, which shows in % how full a vehicle is while loading/unloading (TheJosh)
truelight
parents: 6600
diff changeset
    69
 * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures and loading indicators */
6600
1482680e3303 (svn r9814) -Fix (r1): Remove the duplicate sign sprite from openttd.grf since it's in the original data files.
maedhros
parents: 6598
diff changeset
    70
{   WWT_IMGBTN,   RESIZE_NONE,  7,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    71
{   WWT_IMGBTN,   RESIZE_NONE,  7,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    72
{   WWT_IMGBTN,   RESIZE_NONE,  7,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    73
{   WWT_IMGBTN,   RESIZE_NONE,  7,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    74
{   WWT_IMGBTN,   RESIZE_NONE,  7,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    75
{   WWT_IMGBTN,   RESIZE_NONE,  7, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    76
{   WWT_IMGBTN,   RESIZE_NONE,  7, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    77
{   WWT_IMGBTN,   RESIZE_NONE,  7, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    78
{   WWT_IMGBTN,   RESIZE_NONE,  7, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    79
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    80
{   WIDGETS_END},
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    81
};
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    82
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    83
static const WindowDesc _transparency_desc = {
8528
6e61e651790e (svn r12103) -Feature(tte): separate catenary transparency settings from building transparency settings
smatz
parents: 8527
diff changeset
    84
	WDP_ALIGN_TBR, 58+36, 219, 36, 219, 36,
6427
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    85
	WC_TRANSPARENCY_TOOLBAR, WC_NONE,
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    86
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    87
	_transparency_widgets,
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    88
	TransparencyToolbWndProc
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    89
};
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    90
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    91
void ShowTransparencyToolbar(void)
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    92
{
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    93
	AllocateWindowDescFront(&_transparency_desc, 0);
7dc1012757d8 (svn r9563) -Feature: Add more finer control to transparency options, including a new toolbar, accessible from the map menu or Ctrl X. Patch by Wolf01.
peter1138
parents:
diff changeset
    94
}