transparency_gui.cpp

00001 /* $Id: transparency_gui.cpp 12319 2008-02-29 13:57:50Z peter1138 $ */
00002 
00003 #include "stdafx.h"
00004 #include "openttd.h"
00005 #include "gui.h"
00006 #include "window_gui.h"
00007 #include "variables.h"
00008 #include "transparency.h"
00009 #include "sound_func.h"
00010 
00011 #include "table/sprites.h"
00012 #include "table/strings.h"
00013 
00014 TransparencyOptionBits _transparency_opt;
00015 TransparencyOptionBits _transparency_lock;
00016 
00017 enum TransparencyToolbarWidgets{
00018   TTW_WIDGET_SIGNS = 3,    
00019   TTW_WIDGET_TREES,        
00020   TTW_WIDGET_HOUSES,       
00021   TTW_WIDGET_INDUSTRIES,   
00022   TTW_WIDGET_BUILDINGS,    
00023   TTW_WIDGET_BRIDGES,      
00024   TTW_WIDGET_STRUCTURES,   
00025   TTW_WIDGET_CATENARY,     
00026   TTW_WIDGET_LOADING,      
00027   TTW_WIDGET_END,          
00028 };
00029 
00030 static void TransparencyToolbWndProc(Window *w, WindowEvent *e)
00031 {
00032   switch (e->event) {
00033     case WE_PAINT:
00034       /* must be sure that the widgets show the transparency variable changes
00035        * also when we use shortcuts */
00036       for (uint i = TTW_WIDGET_SIGNS; i < TTW_WIDGET_END; i++) {
00037         w->SetWidgetLoweredState(i, IsTransparencySet((TransparencyOption)(i - TTW_WIDGET_SIGNS)));
00038       }
00039 
00040       DrawWindowWidgets(w);
00041       for (uint i = TO_SIGNS; i < TO_END; i++) {
00042         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);
00043       }
00044       break;
00045 
00046     case WE_CLICK:
00047       if (e->we.click.widget >= TTW_WIDGET_SIGNS && e->we.click.widget < TTW_WIDGET_END) {
00048         if (_ctrl_pressed) {
00049           /* toggle the bit of the transparencies lock variable */
00050           ToggleTransparencyLock((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
00051           SetWindowDirty(w);
00052         } else {
00053           /* toggle the bit of the transparencies variable and play a sound */
00054           ToggleTransparency((TransparencyOption)(e->we.click.widget - TTW_WIDGET_SIGNS));
00055           SndPlayFx(SND_15_BEEP);
00056           MarkWholeScreenDirty();
00057         }
00058       }
00059       break;
00060   }
00061 }
00062 
00063 static const Widget _transparency_widgets[] = {
00064 { WWT_CLOSEBOX,   RESIZE_NONE,  7,   0,  10,   0,  13, STR_00C5,                 STR_018B_CLOSE_WINDOW},
00065 {  WWT_CAPTION,   RESIZE_NONE,  7,  11, 206,   0,  13, STR_TRANSPARENCY_TOOLB,   STR_018C_WINDOW_TITLE_DRAG_THIS},
00066 {WWT_STICKYBOX,   RESIZE_NONE,  7, 207, 218,   0,  13, STR_NULL,                 STR_STICKY_BUTTON},
00067 
00068 /* transparency widgets:
00069  * transparent signs, trees, houses, industries, player's buildings, bridges, unmovable structures, catenary and loading indicators */
00070 {   WWT_IMGBTN,   RESIZE_NONE,  7,   0,  21,  14,  35, SPR_IMG_SIGN,         STR_TRANSPARENT_SIGNS_DESC},
00071 {   WWT_IMGBTN,   RESIZE_NONE,  7,  22,  43,  14,  35, SPR_IMG_PLANTTREES,   STR_TRANSPARENT_TREES_DESC},
00072 {   WWT_IMGBTN,   RESIZE_NONE,  7,  44,  65,  14,  35, SPR_IMG_TOWN,         STR_TRANSPARENT_HOUSES_DESC},
00073 {   WWT_IMGBTN,   RESIZE_NONE,  7,  66,  87,  14,  35, SPR_IMG_INDUSTRY,     STR_TRANSPARENT_INDUSTRIES_DESC},
00074 {   WWT_IMGBTN,   RESIZE_NONE,  7,  88, 109,  14,  35, SPR_IMG_COMPANY_LIST, STR_TRANSPARENT_BUILDINGS_DESC},
00075 {   WWT_IMGBTN,   RESIZE_NONE,  7, 110, 152,  14,  35, SPR_IMG_BRIDGE,       STR_TRANSPARENT_BRIDGES_DESC},
00076 {   WWT_IMGBTN,   RESIZE_NONE,  7, 153, 174,  14,  35, SPR_IMG_TRANSMITTER,  STR_TRANSPARENT_STRUCTURES_DESC},
00077 {   WWT_IMGBTN,   RESIZE_NONE,  7, 175, 196,  14,  35, SPR_BUILD_X_ELRAIL,   STR_TRANSPARENT_CATENARY_DESC},
00078 {   WWT_IMGBTN,   RESIZE_NONE,  7, 197, 218,  14,  35, SPR_IMG_TRAINLIST,    STR_TRANSPARENT_LOADING_DESC},
00079 
00080 {   WIDGETS_END},
00081 };
00082 
00083 static const WindowDesc _transparency_desc = {
00084   WDP_ALIGN_TBR, 58+36, 219, 36, 219, 36,
00085   WC_TRANSPARENCY_TOOLBAR, WC_NONE,
00086   WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
00087   _transparency_widgets,
00088   TransparencyToolbWndProc
00089 };
00090 
00091 void ShowTransparencyToolbar(void)
00092 {
00093   AllocateWindowDescFront(&_transparency_desc, 0);
00094 }

Generated on Mon Sep 22 20:34:20 2008 for openttd by  doxygen 1.5.6