home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 12 / CD_ASCQ_12_0294.iso / maj / 535 / colortxt.int next >
Text File  |  1992-08-06  |  2KB  |  79 lines

  1. Unit ColorTxt;
  2.  
  3. {
  4. TColoredText is a descendent of TStaticText designed to allow the writing
  5. of colored text when color monitors are used.  With a monochrome or BW
  6. monitor, TColoredText acts the same as TStaticText.
  7.  
  8. TColoredText is used in exactly the same way as TStaticText except that
  9. the constructor has an extra Byte parameter specifying the attribute
  10. desired.  (Do not use a 0 attribute, black on black).
  11.  
  12. The source for TColoredText is listed below except for the Draw method.
  13. Since the Draw method is 99% the same as that for TStaticText found in
  14. Borland's Run Time Library source, I didn't feel that it was appropriate
  15. for me copy it here.  If you have the RTL you can reconstruct the draw
  16. method since I do show the changes made.
  17. }
  18.  
  19. Interface
  20. uses Objects, Drivers, Views, Dialogs, App;
  21.  
  22. type
  23.   PColoredText = ^TColoredText;
  24.   TColoredText = object(TStaticText)
  25.     Attr : Byte;
  26.     constructor Init(var Bounds: TRect; AText: String; Attribute : Byte);
  27.     constructor Load(var S: TStream);
  28.     function GetTheColor : byte; virtual;
  29.     procedure Draw; virtual;
  30.     procedure Store(var S: TStream);
  31.   end;
  32.  
  33. const
  34.   RColoredText: TStreamRec = (
  35.      ObjType: 611;
  36.      VmtLink: Ofs(TypeOf(TColoredText)^);
  37.      Load:    @TColoredText.Load;
  38.      Store:   @TColoredText.Store
  39.   );
  40.  
  41. Implementation
  42.  
  43. constructor TColoredText.Init(var Bounds: TRect; AText: String;
  44.                                   Attribute : Byte);
  45. begin
  46. TStaticText.Init(Bounds, AText);
  47. Attr := Attribute;
  48. end;
  49.  
  50. constructor TColoredText.Load(var S: TStream);
  51. begin
  52. TStaticText.Load(S);
  53. S.Read(Attr, Sizeof(Attr));
  54. end;
  55.  
  56. procedure TColoredText.Store(var S: TStream);
  57. begin
  58. TStaticText.Store(S);
  59. S.Write(Attr, Sizeof(Attr));
  60. end;
  61.  
  62. function TColoredText.GetTheColor : byte;
  63. begin
  64. if AppPalette = apColor then
  65.   GetTheColor := Attr
  66. else
  67.   GetTheColor := GetColor(1);
  68. end;
  69.  
  70. procedure TColoredText.Draw;
  71.  
  72. Copy TStaticText.Draw from DIALOGS.PAS.  Change the first line from
  73.   Color := GetColor(1);
  74. to
  75.   Color := GetTheColor;
  76.  
  77.  
  78. end.
  79.