~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/transparency_gui.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: transparency_gui.cpp 12319 2008-02-29 13:57:50Z peter1138 $ */
 
1
/* $Id: transparency_gui.cpp 15723 2009-03-15 15:12:06Z rubidium $ */
 
2
 
 
3
/** @file transparency_gui.cpp The transparency GUI. */
2
4
 
3
5
#include "stdafx.h"
4
6
#include "openttd.h"
5
 
#include "gui.h"
6
7
#include "window_gui.h"
7
 
#include "variables.h"
8
8
#include "transparency.h"
9
9
#include "sound_func.h"
10
10
 
13
13
 
14
14
TransparencyOptionBits _transparency_opt;
15
15
TransparencyOptionBits _transparency_lock;
16
 
 
17
 
enum TransparencyToolbarWidgets{
18
 
        TTW_WIDGET_SIGNS = 3,    ///< Make signs background transparent
19
 
        TTW_WIDGET_TREES,        ///< Make trees transparent
20
 
        TTW_WIDGET_HOUSES,       ///< Make houses transparent
21
 
        TTW_WIDGET_INDUSTRIES,   ///< Make Industries transparent
22
 
        TTW_WIDGET_BUILDINGS,    ///< Make player buildings and structures transparent
23
 
        TTW_WIDGET_BRIDGES,      ///< Make bridges transparent
24
 
        TTW_WIDGET_STRUCTURES,   ///< Make unmovable structures transparent
25
 
        TTW_WIDGET_CATENARY,     ///< Make catenary transparent
26
 
        TTW_WIDGET_LOADING,      ///< Make loading indicators transparent
27
 
        TTW_WIDGET_END,          ///< End of toggle buttons
 
16
TransparencyOptionBits _invisibility_opt;
 
17
 
 
18
class TransparenciesWindow : public Window
 
19
{
 
20
        enum TransparencyToolbarWidgets{
 
21
                TTW_WIDGET_SIGNS = 3,    ///< Make signs background transparent
 
22
                TTW_WIDGET_TREES,        ///< Make trees transparent
 
23
                TTW_WIDGET_HOUSES,       ///< Make houses transparent
 
24
                TTW_WIDGET_INDUSTRIES,   ///< Make Industries transparent
 
25
                TTW_WIDGET_BUILDINGS,    ///< Make company buildings and structures transparent
 
26
                TTW_WIDGET_BRIDGES,      ///< Make bridges transparent
 
27
                TTW_WIDGET_STRUCTURES,   ///< Make unmovable structures transparent
 
28
                TTW_WIDGET_CATENARY,     ///< Make catenary transparent
 
29
                TTW_WIDGET_LOADING,      ///< Make loading indicators transparent
 
30
                TTW_WIDGET_END,          ///< End of toggle buttons
 
31
 
 
32
                /* Panel with buttons for invisibility */
 
33
                TTW_BUTTONS = 12,        ///< Panel with 'invisibility' buttons
 
34
        };
 
35
 
 
36
public:
 
37
        TransparenciesWindow(const WindowDesc *desc, int window_number) : Window(desc, window_number)
 
38
        {
 
39
                this->FindWindowPlacementAndResize(desc);
 
40
        }
 
41
 
 
42
        virtual void OnPaint()
 
43
        {
 
44
                /* must be sure that the widgets show the transparency variable changes
 
45
                 * also when we use shortcuts */
 
46
                for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
 
47
                        this->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
 
48
                }
 
49
 
 
50
                this->DrawWidgets();
 
51
                for (uint i = TO_SIGNS; i < TO_END; i++) {
 
52
                        if (HasBit(_transparency_lock, i)) DrawSprite(SPR_LOCK, PAL_NONE, this->widget[TTW_WIDGET_SIGNS + i].left + 1, this->widget[TTW_WIDGET_SIGNS + i].top + 1);
 
53
                }
 
54
 
 
55
                /* Do not draw button for invisible loading indicators */
 
56
                for (uint i = TTW_WIDGET_SIGNS; i <= TTW_WIDGET_CATENARY; i++) {
 
57
                        const Widget *wi = &this->widget[i];
 
58
                        DrawFrameRect(wi->left + 1, 38, wi->right - 1, 46, COLOUR_PALE_GREEN, HasBit(_invisibility_opt, i - TTW_WIDGET_SIGNS) ? FR_LOWERED : FR_NONE);
 
59
                }
 
60
        }
 
61
 
 
62
        virtual void OnClick(Point pt, int widget)
 
63
        {
 
64
                if (widget >= TTW_WIDGET_SIGNS && widget < TTW_WIDGET_END) {
 
65
                        if (_ctrl_pressed) {
 
66
                                /* toggle the bit of the transparencies lock variable */
 
67
                                ToggleTransparencyLock((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
 
68
                                this->SetDirty();
 
69
                        } else {
 
70
                                /* toggle the bit of the transparencies variable and play a sound */
 
71
                                ToggleTransparency((TransparencyOption)(widget - TTW_WIDGET_SIGNS));
 
72
                                SndPlayFx(SND_15_BEEP);
 
73
                                MarkWholeScreenDirty();
 
74
                        }
 
75
                } else if (widget == TTW_BUTTONS) {
 
76
                        uint x = pt.x / 22;
 
77
 
 
78
                        if (x > TTW_WIDGET_BRIDGES - TTW_WIDGET_SIGNS) x--;
 
79
                        if (x > TTW_WIDGET_CATENARY - TTW_WIDGET_SIGNS) return;
 
80
 
 
81
                        ToggleInvisibility((TransparencyOption)x);
 
82
                        SndPlayFx(SND_15_BEEP);
 
83
 
 
84
                        /* Redraw whole screen only if transparency is set */
 
85
                        if (IsTransparencySet((TransparencyOption)x)) {
 
86
                                MarkWholeScreenDirty();
 
87
                        } else {
 
88
                                this->InvalidateWidget(TTW_BUTTONS);
 
89
                        }
 
90
                }
 
91
        }
28
92
};
29
93
 
30
 
static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
31
 
{
32
 
        switch (e->event) {
33
 
                case WE_PAINT:
34
 
                        /* must be sure that the widgets show the transparency variable changes
35
 
                         * also when we use shortcuts */
36
 
                        for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
37
 
                                w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
38
 
                        }
39
 
 
40
 
                        DrawWindowWidgets(w);
41
 
                        for (uint i = TO_SIGNS; i < TO_END; i++) {
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);
43
 
                        }
44
 
                        break;
45
 
 
46
 
                case WE_CLICK:
47
 
                        if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) {
48
 
                                if (_ctrl_pressed) {
49
 
                                        /* toggle the bit of the transparencies lock variable */
50
 
                                        ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
51
 
                                        SetWindowDirty(w);
52
 
                                } else {
53
 
                                        /* toggle the bit of the transparencies variable and play a sound */
54
 
                                        ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
55
 
                                        SndPlayFx(SND_15_BEEP);
56
 
                                        MarkWholeScreenDirty();
57
 
                                }
58
 
                        }
59
 
                        break;
60
 
        }
61
 
}
62
 
 
63
94
static const Widget _transparency_widgets[] = {
64
 
{ WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
65
 
{  WWT_CAPTION,   RESIZE_NONE,  7,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
66
 
{WWT_STICKYBOX,   RESIZE_NONE,  7, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
 
95
{ WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
 
96
{  WWT_CAPTION,   RESIZE_NONE,  COLOUR_DARK_GREEN,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
 
97
{WWT_STICKYBOX,   RESIZE_NONE,  COLOUR_DARK_GREEN, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
67
98
 
68
99
/* transparency widgets:
69
 
 * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */
70
 
{   WWT_IMGBTN,   RESIZE_NONE,  7,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
71
 
{   WWT_IMGBTN,   RESIZE_NONE,  7,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
72
 
{   WWT_IMGBTN,   RESIZE_NONE,  7,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
73
 
{   WWT_IMGBTN,   RESIZE_NONE,  7,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
74
 
{   WWT_IMGBTN,   RESIZE_NONE,  7,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
75
 
{   WWT_IMGBTN,   RESIZE_NONE,  7, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
76
 
{   WWT_IMGBTN,   RESIZE_NONE,  7, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
77
 
{   WWT_IMGBTN,   RESIZE_NONE,  7, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
78
 
{   WWT_IMGBTN,   RESIZE_NONE,  7, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
 
100
 * transparent signs, trees, houses, industries, company's buildings, bridges, unmovable structures, catenary and loading indicators */
 
101
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
 
102
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
 
103
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
 
104
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
 
105
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
 
106
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
 
107
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
 
108
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
 
109
{   WWT_IMGBTN,   RESIZE_NONE,  COLOUR_DARK_GREEN, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
 
110
 
 
111
{    WWT_PANEL,   RESIZE_NONE,  COLOUR_DARK_GREEN,   0, 218,  36,  48, 0x0,                  STR_TRANSPARENT_INVISIBLE_DESC},
79
112
 
80
113
{   WIDGETS_END},
81
114
};
82
115
 
83
 
static const WindowDesc _transparency_desc = {
84
 
        WDP_ALIGN_TBR, 58+36, 219, 36, 219, 36,
 
116
static const WindowDesc _transparency_desc(
 
117
        WDP_ALIGN_TBR, 94, 219, 49, 219, 49,
85
118
        WC_TRANSPARENCY_TOOLBAR, WC_NONE,
86
119
        WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
87
 
        _transparency_widgets,
88
 
        TransparencyToolbWndProc
89
 
};
 
120
        _transparency_widgets
 
121
);
90
122
 
91
123
void ShowTransparencyToolbar(void)
92
124
{
93
 
        AllocateWindowDescFront(&_transparency_desc, 0);
 
125
        AllocateWindowDescFront<TransparenciesWindow>(&_transparency_desc, 0);
94
126
}