MenuWidget_InfoBox.cpp (5810B)
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_InfoBox::Update 35 ======================== 36 */ 37 void idMenuWidget_InfoBox::Initialize( idMenuHandler * data) { 38 idMenuWidget::Initialize( data ); 39 } 40 41 /* 42 ======================== 43 idMenuWidget_InfoBox::Update 44 ======================== 45 */ 46 void idMenuWidget_InfoBox::Update() { 47 48 if ( GetSWFObject() == NULL ) { 49 return; 50 } 51 52 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 53 if ( !BindSprite( root ) || GetSprite() == NULL ) { 54 return; 55 } 56 57 idSWFTextInstance * txtHeading = GetSprite()->GetScriptObject()->GetNestedText( "info", "heading", "txtVal" ); 58 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 59 60 if ( txtHeading != NULL ) { 61 txtHeading->SetText( heading ); 62 } 63 64 if ( txtBody != NULL ) { 65 txtBody->SetText( info ); 66 } 67 68 if ( scrollbar != NULL && txtBody != NULL ) { 69 txtBody->CalcMaxScroll(); 70 scrollbar->Update(); 71 } 72 73 idSWFScriptObject * info = GetSprite()->GetScriptObject()->GetNestedObj( "info" ); 74 if ( info != NULL ) { 75 info->Set( "onRollOver", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OVER, 0 ) ); 76 info->Set( "onRollOut", new ( TAG_SWF ) WrapWidgetSWFEvent( this, WIDGET_EVENT_ROLL_OUT, 0 ) ); 77 } 78 79 } 80 81 /* 82 ======================== 83 idMenuWidget_InfoBox::ObserveEvent 84 ======================== 85 */ 86 void idMenuWidget_InfoBox::ResetInfoScroll() { 87 88 idSWFScriptObject & root = GetSWFObject()->GetRootObject(); 89 if ( !BindSprite( root ) || GetSprite() == NULL ){ 90 return; 91 } 92 93 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 94 if ( txtBody != NULL ) { 95 txtBody->scroll = 0; 96 } 97 98 if ( scrollbar != NULL ) { 99 scrollbar->Update(); 100 } 101 } 102 103 /* 104 ======================== 105 idMenuWidget_InfoBox::Scroll 106 ======================== 107 */ 108 void idMenuWidget_InfoBox::Scroll( int d ) { 109 110 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 111 112 if ( txtBody != NULL && txtBody->scroll + d >= 0 && txtBody->scroll + d <= txtBody->maxscroll ) { 113 txtBody->scroll += d; 114 } 115 116 if ( scrollbar != NULL ) { 117 scrollbar->Update(); 118 } 119 120 } 121 122 /* 123 ======================== 124 idMenuWidget_InfoBox::GetScroll 125 ======================== 126 */ 127 int idMenuWidget_InfoBox::GetScroll() { 128 129 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 130 if ( txtBody != NULL ) { 131 return txtBody->scroll; 132 } 133 134 return 0; 135 } 136 137 /* 138 ======================== 139 idMenuWidget_InfoBox::GetMaxScroll 140 ======================== 141 */ 142 int idMenuWidget_InfoBox::GetMaxScroll() { 143 144 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 145 if ( txtBody != NULL ) { 146 return txtBody->maxscroll; 147 } 148 149 return 0; 150 } 151 152 /* 153 ======================== 154 idMenuWidget_InfoBox::SetScroll 155 ======================== 156 */ 157 void idMenuWidget_InfoBox::SetScroll( int scroll ) { 158 159 idSWFTextInstance * txtBody = GetSprite()->GetScriptObject()->GetNestedText( "info", "txtBody" ); 160 161 if ( txtBody != NULL && scroll <= txtBody->maxscroll ) { 162 txtBody->scroll = scroll; 163 } 164 165 } 166 167 /* 168 ======================== 169 idMenuWidget_InfoBox::SetScrollbar 170 ======================== 171 */ 172 void idMenuWidget_InfoBox::SetScrollbar( idMenuWidget_ScrollBar * bar ) { 173 scrollbar = bar; 174 } 175 176 /* 177 ======================== 178 idMenuWidget_InfoBox::ObserveEvent 179 ======================== 180 */ 181 bool idMenuWidget_InfoBox::HandleAction( idWidgetAction & action, const idWidgetEvent & event, idMenuWidget * widget, bool forceHandled ) { 182 183 const idSWFParmList & parms = action.GetParms(); 184 185 if ( action.GetType() == WIDGET_ACTION_SCROLL_VERTICAL ) { 186 const scrollType_t scrollType = static_cast< scrollType_t >( event.arg ); 187 if ( scrollType == SCROLL_SINGLE ) { 188 Scroll( parms[ 0 ].ToInteger() ); 189 } 190 return true; 191 } 192 193 return idMenuWidget::HandleAction( action, event, widget, forceHandled ); 194 } 195 196 /* 197 ======================== 198 idMenuWidget_InfoBox::ObserveEvent 199 ======================== 200 */ 201 void idMenuWidget_InfoBox::ObserveEvent( const idMenuWidget & widget, const idWidgetEvent & event ) { 202 switch ( event.type ) { 203 case WIDGET_EVENT_FOCUS_ON: { 204 ResetInfoScroll(); 205 break; 206 } 207 } 208 }