Start.cpp 4.2 KB

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