KeyboardRef.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #define KEYBOARDREF_CPP
  2. /*************************************************************************************************\
  3. KeyboardRef.cpp : Implementation of the KeyboardRef component.
  4. //===========================================================================//
  5. // Copyright (C) Microsoft Corporation. All rights reserved. //
  6. //===========================================================================//
  7. \*************************************************************************************************/
  8. #include "KeyboardRef.h"
  9. #include "mclib.h"
  10. #include "..\resource.h"
  11. #include "missiongui.h"
  12. #include "utilities.h"
  13. #define CTRL 0x10000000
  14. #define SHIFT 0x01000000
  15. #define ALT 0x00100000
  16. #define WAYPT 0x20000000
  17. KeyboardRef::KeyboardRef( )
  18. : listItemTemplate( IDS_KEYBOARD_REF_FONT ),
  19. listItemTemplate2( IDS_KEYBOARD_REF_FONT )
  20. {
  21. }
  22. KeyboardRef::~KeyboardRef()
  23. {
  24. listBox.destroy();
  25. }
  26. //-------------------------------------------------------------------------------------------------
  27. int KeyboardRef::init()
  28. {
  29. // clear out old stuff first
  30. clear();
  31. FullPathFileName path;
  32. switch( Environment.screenWidth )
  33. {
  34. case 640:
  35. path.init( artPath, "mcui_keyref_640", ".fit" );
  36. break;
  37. case 800:
  38. path.init( artPath, "mcui_keyref_800", ".fit" );
  39. break;
  40. case 1024:
  41. path.init( artPath, "mcui_keyref_1024", ".fit" );
  42. break;
  43. case 1280:
  44. path.init( artPath, "mcui_keyref_1280", ".fit" );
  45. break;
  46. case 1600:
  47. path.init( artPath, "mcui_keyref_1600", ".fit" );
  48. break;
  49. default:
  50. gosASSERT( !"Invalid resolution" );
  51. return -1;
  52. }
  53. FitIniFile file;
  54. file.open( path );
  55. LogisticsScreen::init( file, "Static", "Text", "Rect", "Button" );
  56. listBox.init( rects[2].left(), rects[2].top(), rects[2].width(), rects[2].height() );
  57. file.close();
  58. path.init( artPath, "mcui_keyref_entry", ".fit" );
  59. file.open( path );
  60. listItemTemplate.init( file, "Text0" );
  61. listItemTemplate2.init( file, "Text1" );
  62. buttons[0].setMessageOnRelease( );
  63. return true;
  64. }
  65. void KeyboardRef::update()
  66. {
  67. listBox.update();
  68. LogisticsScreen::update();
  69. }
  70. void KeyboardRef::render()
  71. {
  72. GUI_RECT rect = { 0, 0, Environment.screenWidth, Environment.screenHeight };
  73. drawRect( rect, 0xff000000 );
  74. listBox.render();
  75. LogisticsScreen::render();
  76. }
  77. void KeyboardRef::reseed( MissionInterfaceManager::Command* commands )
  78. {
  79. listBox.removeAllItems( true );
  80. char shift[32];
  81. char control[32];
  82. char alt[32];
  83. char descText[128];
  84. char keysString[128];
  85. cLoadString( IDS_SHIFT, shift, 31 );
  86. cLoadString( IDS_CONTROL, control, 31 );
  87. cLoadString( IDS_ALT, alt, 31 );
  88. // first count the number of hotTexts
  89. long count = 0;
  90. for ( int i = 0; i < MAX_COMMAND; i++ )
  91. {
  92. if ( commands[i].hotKeyDescriptionText != -1 )
  93. {
  94. count++;
  95. }
  96. }
  97. long curCount = 0;
  98. for ( i = 0; i < MAX_COMMAND; i++ )
  99. {
  100. if ( commands[i].hotKeyDescriptionText != -1 )
  101. {
  102. cLoadString( commands[i].hotKeyDescriptionText, descText, 127 );
  103. long key = commands[i].key;
  104. char* pKey = gos_DescribeKey( (key & 0x000fffff) << 8 );
  105. strcpy( keysString, pKey );
  106. if ( ((key & SHIFT)) )
  107. {
  108. strcat( keysString, " + " );
  109. strcat( keysString, shift );
  110. }
  111. if ( ((key & CTRL)) )
  112. {
  113. strcat( keysString, " + " );
  114. strcat( keysString, control );
  115. }
  116. if ( ((key & ALT)) )
  117. {
  118. strcat( keysString, " + " );
  119. strcat( keysString, alt );
  120. }
  121. aTextListItem* item = new aTextListItem( IDS_KEYBOARD_REF_FONT );
  122. *item = listItemTemplate;
  123. item->setText( keysString );
  124. item->setAlignment( 1 );
  125. listBox.AddItem( item );
  126. long yVal = item->y();
  127. item = new aTextListItem( IDS_KEYBOARD_REF_FONT );
  128. *item = listItemTemplate2;
  129. long xVal = listItemTemplate2.left();
  130. item->setText( descText );
  131. item->setAlignment( 0 );
  132. listBox.AddItem( item );
  133. item->moveTo( xVal + listBox.left(), yVal );
  134. }
  135. }
  136. }
  137. int KeyboardRef::handleMessage( unsigned long who, unsigned long )
  138. {
  139. return MissionInterfaceManager::instance()->toggleHotKeys();
  140. }
  141. //*************************************************************************************************
  142. // end of file ( KeyboardRef.cpp )