home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 535 / tcolortx.doc < prev    next >
Text File  |  1992-11-16  |  3KB  |  90 lines

  1. /*------------------------------------------------------------*/
  2. /* filename -       tcolortx.doc                              */
  3. /*                                                            */
  4. /* function(s)                                                */
  5. /*                  TColoredText member functions             */
  6. /*------------------------------------------------------------*/
  7.  
  8. /*----------------------------------------------------------------------
  9. TColoredText is a descendent of TStaticText designed to allow the writing
  10. of colored text when color monitors are used.  With a monochrome or BW
  11. monitor, TColoredText acts the same as TStaticText.
  12.  
  13. TColoredText is used in exactly the same way as TStaticText except that
  14. the constructor has an extra ushort parameter specifying the attribute
  15. desired.  (Do not use a 0 attribute, black on black).
  16.  
  17. The source for TColoredText is listed below except for the draw method.
  18. Since the draw method is 99% the same as that for TStaticText found in
  19. Borland's Run Time Library source, I didn't feel that it was appropriate
  20. for me copy it here.  If you have the RTL you can reconstruct the draw
  21. method since I do show the changes made.
  22. ----------------------------------------------------------------------*/
  23.  
  24. #define Uses_TColoredText
  25. #define Uses_TStaticText
  26. #define Uses_TApplication
  27. #define Uses_TDrawBuffer
  28. #define Uses_opstream
  29. #define Uses_ipstream
  30. #include <tv.h>
  31. #include "tcolortx.h"
  32.  
  33. #if !defined( __CTYPE_H )
  34. #include <ctype.h>
  35. #endif  // __CTYPE_H
  36.  
  37. #if !defined( __STRING_H )
  38. #include <String.h>
  39. #endif  // __STRING_H
  40.  
  41. TColoredText::TColoredText( const TRect& bounds, const char *aText,
  42.                 ushort attribute ) :
  43.     TStaticText( bounds, aText ),
  44.     attr(  attribute )
  45. {
  46. }
  47.  
  48. ushort TColoredText::getTheColor()
  49. {
  50.     if (TProgram::application->appPalette == apColor)
  51.       return attr;
  52.     else return getColor(1);
  53. }
  54.  
  55. void TColoredText::draw()
  56.  
  57. Copy TStaticText.Draw from TSTATICT.CPP.  Change the 6th line from
  58.  
  59.   color = getColor(1);
  60. to
  61.   color = getTheColor();
  62.  
  63.  
  64.  
  65. void TColoredText::write( opstream& os )
  66. {
  67.     TStaticText::write( os );
  68.     os << attr;
  69. }
  70.  
  71. void *TColoredText::read( ipstream& is )
  72. {
  73.     TStaticText::read( is );
  74.     is >> attr;
  75.     return this;
  76. }
  77.  
  78. TStreamable *TColoredText::build()
  79. {
  80.     return new TColoredText( streamableInit );
  81. }
  82.  
  83. TColoredText::TColoredText( StreamableInit ) : TStaticText( streamableInit )
  84. {
  85. }
  86.  
  87. const char * const near TColoredText::name = "TColoredText";
  88.  
  89.  
  90.