Einstellungen.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include "Einstellungen.h"
  2. #include <MausEreignis.h>
  3. #include <GraphicsApi.h>
  4. #include <InitDatei.h>
  5. #include "../../Global/Variablen.h"
  6. #include "../../Global/Initialisierung.h"
  7. // Inhalt der Einstellungen Klasse aus Einstellungen.h
  8. // Konstruktor
  9. Einstellungen::Einstellungen( Schrift *zSchrift, Fenster *zF )
  10. {
  11. f = initFenster( zF->getBreite() / 2 - 250, zF->getHeight() / 2 - 250, 500, 500, zSchrift,
  12. Fenster::Style::normal | Fenster::Style::BodyHAlpha | Fenster::Style::BodyHintergrund |
  13. Fenster::Style::TitelHintergrund | Fenster::Style::TitelHAlpha, "Einstellungen" );
  14. f->removeStyle( Fenster::Style::Sichtbar );
  15. f->setKBgFarbe( 0xe0000000 );
  16. f->setTBgFarbe( 0xe0000000 );
  17. f->setSBgFarbe( 0xF0000000 );
  18. f->setClosingMeParam( this );
  19. f->setClosingMe( einstellungenSchließenME );
  20. TextFeld *gat = initTextFeld( 5, 5, 300, 20, zSchrift, TextFeld::Style::Text, "Grafik Engine (Neustart erforderlich)" );
  21. f->addMember( gat );
  22. AuswahlBox *graphicAPI = initAuswahlBox( 5, 25, 100, 20, zSchrift, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, { "Aktuellste", "DirectX 9" } );
  23. if( DirectX11::isAvailable() )
  24. graphicAPI->addEintrag( "DirectX 11" );
  25. if( DirectX12::isAvailable() )
  26. graphicAPI->addEintrag( "DirectX 12" );
  27. graphicAPI->setAuswahl( 0 );
  28. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX9" ) )
  29. graphicAPI->setAuswahl( 1 );
  30. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX11" ) )
  31. graphicAPI->setAuswahl( 2 );
  32. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX12" ) )
  33. graphicAPI->setAuswahl( 3 );
  34. graphicAPI->setEventAktion( [ this ]( void *p, AuswahlBox * b, int unused, int auswahl )
  35. {
  36. switch( auswahl )
  37. {
  38. case 1:
  39. userOptions->setWert( "GraphicAPI", "DX9" );
  40. break;
  41. case 2:
  42. userOptions->setWert( "GraphicAPI", "DX11" );
  43. break;
  44. case 3:
  45. userOptions->setWert( "GraphicAPI", "DX12" );
  46. break;
  47. default:
  48. userOptions->setWert( "GraphicAPI", "BEST" );
  49. break;
  50. }
  51. } );
  52. TextFeld *mft = initTextFeld( 5, 50, 200, 20, zSchrift, TextFeld::Style::Text, "Maximale FPS" );
  53. f->addMember( mft );
  54. maxFPS = initTextFeld( 5, 70, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "MaxFPS" ) ? userOptions->zWert( "MaxFPS" )->getText() : "30" );
  55. maxFPS->setTastaturEreignis( _nurNummernTE );
  56. f->addMember( maxFPS->getThis() );
  57. ok = initKnopf( 390, 450, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Ok" );
  58. ok->setMausEreignisParameter( this );
  59. ok->setMausEreignis( einstellungenOkME );
  60. f->addMember( ok->getThis() );
  61. // add AuswahlBoxen
  62. f->addMember( graphicAPI );
  63. zF->addMember( f->getThis() );
  64. ref = 1;
  65. }
  66. // Destruktor
  67. Einstellungen::~Einstellungen()
  68. {
  69. maxFPS->release();
  70. f->release();
  71. ok->release();
  72. }
  73. // nicht constant
  74. void Einstellungen::setSichtbar()
  75. {
  76. f->setStyle( Fenster::Style::Sichtbar, f->hatStyleNicht( Fenster::Style::Sichtbar ) );
  77. }
  78. bool Einstellungen::closeME( MausEreignis &me )
  79. {
  80. if( me.id == ME_RLinks )
  81. f->removeStyle( Fenster::Style::Sichtbar );
  82. return 1;
  83. }
  84. bool Einstellungen::okME( MausEreignis &me )
  85. {
  86. if( me.id == ME_RLinks )
  87. {
  88. f->removeStyle( Fenster::Style::Sichtbar );
  89. int fps = *maxFPS->zText();
  90. if( fps > 0 )
  91. {
  92. hauptScreen->lock();
  93. if( !userOptions->wertExistiert( "MaxFPS" ) )
  94. userOptions->addWert( "MaxFPS", maxFPS->zText()->getText() );
  95. else
  96. userOptions->setWert( "MaxFPS", maxFPS->zText()->getText() );
  97. hauptScreen->unlock();
  98. }
  99. userOptions->speichern();
  100. }
  101. return 1;
  102. }
  103. // Reference Counting
  104. Einstellungen *Einstellungen::getThis()
  105. {
  106. ref++;
  107. return this;
  108. }
  109. Einstellungen *Einstellungen::release()
  110. {
  111. ref--;
  112. if( !ref )
  113. delete this;
  114. return 0;
  115. }
  116. // Ereignisse
  117. bool einstellungenSchließenME( void *p, void *obj, MausEreignis me )
  118. {
  119. if( !p )
  120. return 1;
  121. return ( (Einstellungen*)p )->closeME( me );
  122. }
  123. bool einstellungenOkME( void *p, void *obj, MausEreignis me )
  124. {
  125. if( !p )
  126. return 1;
  127. return ( (Einstellungen*)p )->okME( me );
  128. }