Start.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #include <main.h>
  2. #include <Fenster.h>
  3. #include <Bildschirm.h>
  4. #include <RenderThread.h>
  5. #include <TextFeld.h>
  6. #include <iostream>
  7. #include <Schrift.h>
  8. #include <DateiSystem.h>
  9. #include "TestThread.h"
  10. #include <Network.h>
  11. // Output
  12. template <class charT, class traits = std::char_traits<charT> >
  13. class CDG_CoutRerouteStr : public std::basic_streambuf<charT, traits>
  14. {
  15. private:
  16. Framework::TextFeld * tf;
  17. public:
  18. CDG_CoutRerouteStr( Framework::TextFeld *tf )
  19. {
  20. this->tf = tf;
  21. };
  22. protected:
  23. std::streamsize xsputn( const charT * pChar, std::streamsize n )
  24. {
  25. Framework::Text tmp( pChar );
  26. tf->lockZeichnung();
  27. if( tmp.getText()[ 0 ] == 1 && tf->zText()->getText()[ tf->zText()->getLength() - 2 ] == 1 )
  28. {
  29. int anz = tf->zText()->anzahlVon( 1 );
  30. tf->zText()->ersetzen( tf->zText()->positionVon( 1, anz - 2 ), tf->zText()->getLength(), tmp );
  31. }
  32. else
  33. tf->zText()->append( pChar );
  34. tf->setRender();
  35. tf->updateVScroll();
  36. if( tf->zText()->anzahlVon( '\n' ) > 1000 )
  37. tf->zText()->remove( 0, tf->zText()->positionVon( '\n' ) + 1 );
  38. tf->unlockZeichnung();
  39. return strlen( pChar );
  40. }
  41. typedef typename traits::int_type int_type;
  42. int_type overflow( int_type ch ) override
  43. {
  44. tf->zText()->append( (char)ch );
  45. return 1;
  46. }
  47. };
  48. template <class charT, class traits = std::char_traits<charT> >
  49. class CDG_CerrRerouteStr : public std::basic_streambuf<charT, traits>
  50. {
  51. private:
  52. Framework::TextFeld * tf;
  53. public:
  54. CDG_CerrRerouteStr( Framework::TextFeld *tf )
  55. {
  56. this->tf = tf;
  57. };
  58. protected:
  59. std::streamsize xsputn( const charT * pChar, std::streamsize n )
  60. {
  61. tf->lockZeichnung();
  62. tf->zText()->append( "\r0xFFFF0000" );
  63. tf->zText()->append( pChar );
  64. tf->zText()->append( "\r0xFFFFFFFF" );
  65. tf->setRender();
  66. tf->updateVScroll();
  67. tf->updateHScroll();
  68. if( tf->zText()->anzahlVon( '\n' ) > 1000 )
  69. tf->zText()->remove( 0, tf->zText()->positionVon( '\n' ) + 1 );
  70. tf->unlockZeichnung();
  71. return strlen( pChar );
  72. }
  73. typedef typename traits::int_type int_type;
  74. int_type overflow( int_type ch ) override
  75. {
  76. tf->zText()->append( "\r0xFFFF0000" );
  77. tf->zText()->append( (char)ch );
  78. tf->zText()->append( "\r0xFFFFFFFF" );
  79. return 1;
  80. }
  81. };
  82. int Framework::Start( Framework::Startparam p )
  83. {
  84. Network::Start( 100 );
  85. WNDCLASS wc = Framework::F_Normal( p.hinst );
  86. wc.lpszClassName = "Server System Checker";
  87. WFenster frame;
  88. frame.erstellen( WS_OVERLAPPEDWINDOW, wc );
  89. Punkt pos( 100, 100 );
  90. frame.setPosition( pos );
  91. frame.setSize( 600, 400 );
  92. frame.setMausAktion( _ret1ME );
  93. frame.setTastaturAktion( []( void *param, void *obj, TastaturEreignis te ) -> bool
  94. {
  95. if( te.id == TE_Release )
  96. std::cin.putback( te.taste );
  97. return 1;
  98. } );
  99. frame.setVSchließAktion( []( void*, void*f )
  100. {
  101. StopNachrichtenSchleife( ( (WFenster*)f )->getFensterHandle() );
  102. } );
  103. frame.setAnzeigeModus( 1 );
  104. frame.setNSchließAktion( []( void *param, void *object )
  105. {
  106. StopNachrichtenSchleife( ( (WFenster*)object )->getFensterHandle() );
  107. } );
  108. Bildschirm3D screen( frame.getThis() );
  109. frame.setBildschirm( screen.getThis() );
  110. screen.update();
  111. RenderTh thread;
  112. thread.setBildschirm( screen.getThis() );
  113. thread.beginn();
  114. LTDSDatei d;
  115. d.setPfad( new Text( "console.ltds" ) );
  116. d.leseDaten();
  117. Schrift *schrift = d.ladeSchrift();
  118. TextFeld console;
  119. console.setStyle( TextFeld::Style::Scroll | TextFeld::Style::Mehrfarbig | TextFeld::Style::Mehrzeilig | TextFeld::Style::Sichtbar );
  120. console.setSize( screen.getBackBufferSize() );
  121. console.setSchriftFarbe( 0xFFFFFFFF );
  122. console.setSchriftZ( schrift );
  123. console.setMausEreignis( _ret1ME );
  124. console.setText( "" );
  125. screen.addMember( &console );
  126. // output umleiten...
  127. CDG_CoutRerouteStr<char> str( &console );
  128. std::streambuf* old_buffer = std::cout.rdbuf();
  129. std::cout.rdbuf( &str );
  130. CDG_CerrRerouteStr<char> err( &console );
  131. std::streambuf* old_errbuffer = std::cerr.rdbuf();
  132. std::cerr.rdbuf( &err );
  133. TestThread tests;
  134. StartNachrichtenSchleife();
  135. tests.abbrechen();
  136. tests.warteAufThread( 10000 );
  137. tests.ende();
  138. std::cout.rdbuf( old_buffer );
  139. std::cerr.rdbuf( old_errbuffer );
  140. thread.beenden();
  141. frame.setBildschirm( 0 );
  142. frame.zerstören();
  143. Network::Exit();
  144. return 0;
  145. }