MenuWidget_NavButton.cpp (5776B)
1 /* 2 =========================================================================== 3 4 Doom 3 BFG Edition GPL Source Code 5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 6 7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). 8 9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation, either version 3 of the License, or 12 (at your option) any later version. 13 14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>. 21 22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below. 23 24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA. 25 26 =========================================================================== 27 */ 28 #pragma hdrstop 29 #include "../../idLib/precompiled.h" 30 #include "../Game_local.h" 31 32 /* 33 ======================== 34 idMenuWidget_NavButton::Update 35 ======================== 36 */ 37 void idMenuWidget_NavButton::Update() { 38 39 if ( GetSprite() == NULL ) { 40 return; 41 } 42 43 if ( btnLabel.IsEmpty() ) { 44 GetSprite()->SetVisible( false ); 45 return; 46 } 47 48 GetSprite()->SetVisible( true ); 49 50 idSWFScriptObject * const spriteObject = GetSprite()->GetScriptObject(); 51 idSWFTextInstance * const text = spriteObject->GetNestedText( "txtVal" ); 52 if ( text != NULL ) { 53 text->SetText( btnLabel.c_str() ); 54 text->SetStrokeInfo( true, 0.7f, 1.25f ); 55 } 56 57 GetSprite()->SetXPos( xPos ); 58 59 if ( navState == NAV_WIDGET_SELECTED ) { 60 idSWFSpriteInstance * backing = GetSprite()->GetScriptObject()->GetNestedSprite( "backing" ); 61 if ( backing != NULL && text != NULL ) { 62 backing->SetXPos( text->GetTextLength() + 53.0f ); 63 } 64 } 65 66 // 67 // events 68 // 69 70 idSWFScriptObject * textObj = spriteObject->GetNestedObj( "txtVal" ); 71 72 if ( textObj != NULL ) { 73 74 textObj->Set( "onPress", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_PRESS, 0 ) ); 75 textObj->Set( "onRelease", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_RELEASE, 0 ) ); 76 77 idSWFScriptObject * hitBox = spriteObject->GetObject( "hitBox" ); 78 if ( hitBox == NULL ) { 79 hitBox = textObj; 80 } 81 82 hitBox->Set( "onRollOver", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OVER, 0 ) ); 83 hitBox->Set( "onRollOut", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OUT, 0 ) ); 84 } 85 } 86 87 /* 88 ======================== 89 idMenuWidget_NavButton::ExecuteEvent 90 ======================== 91 */ 92 bool idMenuWidget_NavButton::ExecuteEvent( const idWidgetEvent & event ) { 93 94 bool handled = false; 95 96 //// do nothing at all if it's disabled 97 if ( GetState() != WIDGET_STATE_DISABLED ) { 98 switch ( event.type ) { 99 case WIDGET_EVENT_PRESS: { 100 //AnimateToState( ANIM_STATE_DOWN ); 101 handled = true; 102 break; 103 } 104 case WIDGET_EVENT_ROLL_OVER: { 105 if ( GetMenuData() ) { 106 GetMenuData()->PlaySound( GUI_SOUND_ROLL_OVER ); 107 } 108 handled = true; 109 break; 110 } 111 } 112 } 113 114 idMenuWidget::ExecuteEvent( event ); 115 116 return handled; 117 } 118 119 //********************************************************************************************************* 120 // idMenuWidget_MenuButton 121 122 123 /* 124 ======================== 125 idMenuWidget_NavButton::Update 126 ======================== 127 */ 128 void idMenuWidget_MenuButton::Update() { 129 130 if ( GetSprite() == NULL ) { 131 return; 132 } 133 134 if ( btnLabel.IsEmpty() ) { 135 GetSprite()->SetVisible( false ); 136 return; 137 } 138 139 GetSprite()->SetVisible( true ); 140 141 idSWFScriptObject * const spriteObject = GetSprite()->GetScriptObject(); 142 idSWFTextInstance * const text = spriteObject->GetNestedText( "txtVal" ); 143 if ( text != NULL ) { 144 text->SetText( btnLabel.c_str() ); 145 text->SetStrokeInfo( true, 0.7f, 1.25f ); 146 147 idSWFSpriteInstance * selBar = spriteObject->GetNestedSprite( "sel", "bar" ); 148 idSWFSpriteInstance * hoverBar =spriteObject->GetNestedSprite( "hover", "bar" ); 149 150 if ( selBar != NULL ) { 151 selBar->SetXPos( text->GetTextLength() / 2.0f ); 152 selBar->SetScale( 100.0f * ( text->GetTextLength() / 300.0f ), 100.0f ); 153 } 154 155 if ( hoverBar != NULL ) { 156 hoverBar->SetXPos( text->GetTextLength() / 2.0f ); 157 hoverBar->SetScale( 100.0f * ( text->GetTextLength() / 352.0f ), 100.0f ); 158 } 159 160 idSWFSpriteInstance * hitBox =spriteObject->GetNestedSprite( "hitBox" ); 161 if ( hitBox != NULL ) { 162 hitBox->SetScale( 100.0f * ( text->GetTextLength() / 235 ), 100.0f ); 163 } 164 } 165 166 GetSprite()->SetXPos( xPos ); 167 168 idSWFScriptObject * textObj = spriteObject->GetNestedObj( "txtVal" ); 169 170 if ( textObj != NULL ) { 171 172 textObj->Set( "onPress", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_PRESS, 0 ) ); 173 textObj->Set( "onRelease", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_RELEASE, 0 ) ); 174 175 idSWFScriptObject * hitBox = spriteObject->GetObject( "hitBox" ); 176 if ( hitBox == NULL ) { 177 hitBox = textObj; 178 } 179 180 hitBox->Set( "onRollOver", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OVER, 0 ) ); 181 hitBox->Set( "onRollOut", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OUT, 0 ) ); 182 } 183 }