home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / streams / stream / funkview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-30  |  2.6 KB  |  112 lines

  1. //========================================================================
  2. //  The following example routines have been provided by the Technical
  3. //  Support staff at Borland International.  They are provided as a
  4. //  courtesy and not as part of a Borland product, and as such, are
  5. //  provided without the assurance of technical support or any specific
  6. //  guarantees.
  7. //========================================================================
  8. //
  9. // funkview.cpp:  The member function definition for TMyApp.
  10. //
  11.  
  12. #define Uses_TView
  13. #define Uses_TWindow
  14. #define Uses_TPalette
  15. #define Uses_TDrawBuffer
  16. #define Uses_TStreamable
  17. #define Uses_TStreamableClass
  18. #include <tv.h>
  19. __link( RView );
  20. __link( RWindow );
  21.  
  22. #include <stdlib.h>         // For random number generator
  23.  
  24. #include "funkview.h"       // Class definition
  25.  
  26.  
  27. //
  28. //  FunkyView constructor
  29. //
  30.  
  31. FunkyView::FunkyView( TRect& r, char *word ) :
  32.     TView( r )
  33. {
  34.     text = newStr( word );
  35. }
  36.  
  37. void FunkyView::draw()
  38. {
  39.     TDrawBuffer buf;
  40.     char color = random(16);    // This has bizarre implications if a
  41.                                 // monochrome monitor or mode BW80 is used.
  42.  
  43.     buf.moveChar(0, ' ', 112, size.x);
  44.     writeLine(0, 0, size.x, 5, buf);
  45.     buf.moveStr(0, text, color + 112);
  46.     writeLine(0, 2, size.x, 1, buf);
  47. }
  48.  
  49.  
  50. const char * const FunkyView::name = "FunkyView";
  51.  
  52. void FunkyView::write( opstream& os )
  53. {
  54.     TView::write( os );
  55.     os.writeString(text);
  56. }
  57.  
  58. void *FunkyView::read( ipstream& is )
  59. {
  60.     text = new char [32];
  61.     TView::read( is );
  62.     is.readString(text, 32);
  63.  
  64.     return this;
  65. }
  66.  
  67. TStreamable *FunkyView::build()
  68. {
  69.     return new FunkyView( streamableInit );
  70. }
  71.  
  72. TStreamableClass RFunkyView( FunkyView::name,
  73.                              FunkyView::build,
  74.                              __DELTA( FunkyView )
  75.                            );
  76.  
  77. //
  78. // FunkyWindow
  79. //
  80.  
  81. FunkyWindow::FunkyWindow( TRect& bounds, char *words ) :
  82.     TWindow( bounds, 0, wnNoNumber ),
  83.     TWindowInit( FunkyWindow::initFrame )
  84. {
  85.     bounds = getExtent();
  86.     bounds.grow(-1, -1);
  87.  
  88.     flags = wfMove | wfClose;
  89.  
  90.     insert( new FunkyView(bounds, words) );
  91. }
  92.  
  93.  
  94. // stream support
  95. //
  96. // Use inherited read/write functions since there are no data members
  97. // in this object.
  98. //
  99.  
  100. const char * const FunkyWindow::name = "FunkyWindow";
  101.  
  102. TStreamable *FunkyWindow::build()
  103. {
  104.     return new FunkyWindow( streamableInit );
  105. }
  106.  
  107. TStreamableClass RFunkyWindow( FunkyWindow::name,
  108.                                FunkyWindow::build,
  109.                                __DELTA( FunkyWindow )
  110.                              );
  111.  
  112.