MenuWidget_MenuBar.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. 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.
  17. 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.
  18. ===========================================================================
  19. */
  20. #pragma hdrstop
  21. #include "../../idLib/precompiled.h"
  22. #include "../Game_local.h"
  23. /*
  24. ========================
  25. idMenuWidget_MenuBar::Initialize
  26. ========================
  27. */
  28. void idMenuWidget_MenuBar::Initialize( idMenuHandler * data ) {
  29. idMenuWidget::Initialize( data );
  30. }
  31. /*
  32. ========================
  33. idMenuWidget_MenuBar::Update
  34. ========================
  35. */
  36. void idMenuWidget_MenuBar::Update() {
  37. if ( GetSWFObject() == NULL ) {
  38. return;
  39. }
  40. idSWFScriptObject & root = GetSWFObject()->GetRootObject();
  41. if ( !BindSprite( root ) ) {
  42. return;
  43. }
  44. totalWidth = 0.0f;
  45. buttonPos = 0.0f;
  46. for ( int index = 0; index < GetNumVisibleOptions(); ++index ) {
  47. if ( index >= children.Num() ) {
  48. break;
  49. }
  50. if ( index != 0 ) {
  51. totalWidth += rightSpacer;
  52. }
  53. idMenuWidget & child = GetChildByIndex( index );
  54. child.SetSpritePath( GetSpritePath(), va( "btn%d", index ) );
  55. if ( child.BindSprite( root ) ) {
  56. PrepareListElement( child, index );
  57. child.Update();
  58. }
  59. }
  60. // 640 is half the size of our flash files width
  61. float xPos = 640.0f - ( totalWidth / 2.0f );
  62. GetSprite()->SetXPos( xPos );
  63. idSWFSpriteInstance * backing = GetSprite()->GetScriptObject()->GetNestedSprite( "backing" );
  64. if ( backing != NULL ) {
  65. if ( menuData != NULL && menuData->GetPlatform() != 2 ) {
  66. backing->SetVisible( false );
  67. } else {
  68. backing->SetVisible( true );
  69. backing->SetXPos( totalWidth / 2.0f );
  70. }
  71. }
  72. }
  73. /*
  74. ========================
  75. idMenuWidget_MenuBar::SetListHeadings
  76. ========================
  77. */
  78. void idMenuWidget_MenuBar::SetListHeadings( idList< idStr > & list ) {
  79. headings.Clear();
  80. for ( int index = 0; index < list.Num(); ++index ) {
  81. headings.Append( list[ index ] );
  82. }
  83. }
  84. /*
  85. ========================
  86. idMenuWidget_MenuBar::GetTotalNumberOfOptions
  87. ========================
  88. */
  89. int idMenuWidget_MenuBar::GetTotalNumberOfOptions() const {
  90. return GetChildren().Num();
  91. }
  92. /*
  93. ========================
  94. idMenuWidget_MenuBar::PrepareListElement
  95. ========================
  96. */
  97. bool idMenuWidget_MenuBar::PrepareListElement( idMenuWidget & widget, const int navIndex ) {
  98. if ( navIndex >= GetNumVisibleOptions() ) {
  99. return false;
  100. }
  101. idMenuWidget_MenuButton * const button = dynamic_cast< idMenuWidget_MenuButton * >( &widget );
  102. if ( button == NULL || button->GetSprite() == NULL ) {
  103. return false;
  104. }
  105. if ( navIndex >= headings.Num() ) {
  106. button->SetLabel( "" );
  107. } else {
  108. button->SetLabel( headings[navIndex] );
  109. idSWFTextInstance * ti = button->GetSprite()->GetScriptObject()->GetNestedText( "txtVal" );
  110. if ( ti != NULL ) {
  111. ti->SetStrokeInfo( true, 0.7f, 1.25f );
  112. ti->SetText( headings[ navIndex ] );
  113. button->SetPosition( buttonPos );
  114. totalWidth += ti->GetTextLength();
  115. buttonPos += rightSpacer + ti->GetTextLength();
  116. }
  117. }
  118. return true;
  119. }