Browse Source

+ added properties TEnhancedVideoCell.ForegroundColor and .BackgroundColor,
which can store up to 256 colors

Nikolay Nikolov 3 years ago
parent
commit
25a681295a
2 changed files with 36 additions and 3 deletions
  1. 28 3
      packages/rtl-console/src/inc/video.inc
  2. 8 0
      packages/rtl-console/src/inc/videoh.inc

+ 28 - 3
packages/rtl-console/src/inc/video.inc

@@ -23,17 +23,40 @@ const
 
 
 operator = (const a,b : TEnhancedVideoCell) res: Boolean;
 operator = (const a,b : TEnhancedVideoCell) res: Boolean;
 begin
 begin
-  res:=(a.Attribute=b.Attribute) and (a.ExtendedGraphemeCluster = b.ExtendedGraphemeCluster);
+  res:=(a.FForegroundColor=b.FForegroundColor) and
+       (a.FBackgroundColor=b.FBackgroundColor) and
+       (a.ExtendedGraphemeCluster = b.ExtendedGraphemeCluster);
 end;
 end;
 
 
 function TEnhancedVideoCell.GetAttribute: Byte;
 function TEnhancedVideoCell.GetAttribute: Byte;
 begin
 begin
-  GetAttribute := Byte(FAttributes);
+  GetAttribute := (FForegroundColor and $0F) or Byte(FBackgroundColor shl 4);
 end;
 end;
 
 
 procedure TEnhancedVideoCell.SetAttribute(Attr: Byte);
 procedure TEnhancedVideoCell.SetAttribute(Attr: Byte);
 begin
 begin
-  FAttributes := (FAttributes and $FF00) or Attr;
+  FForegroundColor := Attr and $0F;
+  FBackgroundColor := Attr shr 4;
+end;
+
+function TEnhancedVideoCell.GetForegroundColor: Byte;
+begin
+  GetForegroundColor := FForegroundColor;
+end;
+
+procedure TEnhancedVideoCell.SetForegroundColor(AForegroundColor: Byte);
+begin
+  FForegroundColor := AForegroundColor;
+end;
+
+function TEnhancedVideoCell.GetBackgroundColor: Byte;
+begin
+  GetBackgroundColor := FBackgroundColor;
+end;
+
+procedure TEnhancedVideoCell.SetBackgroundColor(ABackgroundColor: Byte);
+begin
+  FBackgroundColor := ABackgroundColor;
 end;
 end;
 
 
 function TEnhancedVideoCell.GetExtendedGraphemeCluster: UnicodeString;
 function TEnhancedVideoCell.GetExtendedGraphemeCluster: UnicodeString;
@@ -69,6 +92,8 @@ end;
 class operator TEnhancedVideoCell.Initialize(var evc: TEnhancedVideoCell);
 class operator TEnhancedVideoCell.Initialize(var evc: TEnhancedVideoCell);
 begin
 begin
   evc.FAttributes := 0;
   evc.FAttributes := 0;
+  evc.ForegroundColor := 0;
+  evc.BackgroundColor := 0;
 end;
 end;
 
 
 class operator TEnhancedVideoCell.Finalize(var evc: TEnhancedVideoCell);
 class operator TEnhancedVideoCell.Finalize(var evc: TEnhancedVideoCell);

+ 8 - 0
packages/rtl-console/src/inc/videoh.inc

@@ -38,12 +38,20 @@ type
     procedure SetExtendedGraphemeCluster(const AExtendedGraphemeCluster: UnicodeString);
     procedure SetExtendedGraphemeCluster(const AExtendedGraphemeCluster: UnicodeString);
     function GetAttribute: Byte;
     function GetAttribute: Byte;
     procedure SetAttribute(Attr: Byte);
     procedure SetAttribute(Attr: Byte);
+    function GetForegroundColor: Byte;
+    procedure SetForegroundColor(AForegroundColor: Byte);
+    function GetBackgroundColor: Byte;
+    procedure SetBackgroundColor(ABackgroundColor: Byte);
   public
   public
     property ExtendedGraphemeCluster: UnicodeString read GetExtendedGraphemeCluster write SetExtendedGraphemeCluster;
     property ExtendedGraphemeCluster: UnicodeString read GetExtendedGraphemeCluster write SetExtendedGraphemeCluster;
     property Attribute: Byte read GetAttribute write SetAttribute;
     property Attribute: Byte read GetAttribute write SetAttribute;
+    property ForegroundColor: Byte read GetForegroundColor write SetForegroundColor;
+    property BackgroundColor: Byte read GetBackgroundColor write SetBackgroundColor;
 
 
   private
   private
     FAttributes: Word;
     FAttributes: Word;
+    FForegroundColor : Byte;
+    FBackgroundColor : Byte;
     case integer of
     case integer of
       0: (EGC_SingleChar: WideChar);
       0: (EGC_SingleChar: WideChar);
       1: (EGC_WideStr: Pointer);
       1: (EGC_WideStr: Pointer);