소스 검색

* Add interfaces, invert control

Michaël Van Canneyt 1 년 전
부모
커밋
ad375faa1a
3개의 변경된 파일75개의 추가작업 그리고 18개의 파일을 삭제
  1. 19 0
      src/base/fresnel.controls.pas
  2. 46 1
      src/base/fresnel.dom.pas
  3. 10 17
      src/base/fresnel.renderer.pas

+ 19 - 0
src/base/fresnel.controls.pas

@@ -74,6 +74,7 @@ type
     procedure ComputeMinCaption; virtual;
     procedure SetCaption(const AValue: String); virtual;
     procedure SetName(const NewName: TComponentName); override;
+    procedure DoRender(aRenderer: IFresnelRenderer); override;
   public
     function GetMinWidthIntrinsicContentBox: TFresnelLength; override;
     function GetPreferredContentBox_MaxWidth(MaxWidth: TFresnelLength): TFresnelPoint;
@@ -447,6 +448,24 @@ begin
   if ChangeCaption then Caption := NewName;
 end;
 
+procedure TCustomLabel.DoRender(aRenderer: IFresnelRenderer);
+
+var
+  aColor,aCaption : string;
+  aColorFP : TFPColor;
+
+begin
+  aCaption:=RenderedCaption;
+  if aCaption='' then
+    exit;
+  aColor:=GetRenderedCSString(fcaColor,true);
+  if not CSSToFPColor(aColor,aColorFP) then
+    aColorFP:=colTransparent;
+  if aColorFP.Alpha=alphaTransparent then
+    exit;
+  aRenderer.TextOut(RenderedContentBox.Left,RenderedContentBox.Top,Font,aColorFP,aCaption);
+end;
+
 function TCustomLabel.GetMinWidthIntrinsicContentBox: TFresnelLength;
 var
   p: TFresnelPoint;

+ 46 - 1
src/base/fresnel.dom.pas

@@ -21,6 +21,7 @@ unit Fresnel.DOM;
 
 {$mode ObjFPC}{$H+}
 {$WARN 6060 off} // Case statement does not handle all possible cases
+{$Interfaces CORBA}
 {$ModeSwitch AdvancedRecords}
 
 interface
@@ -262,6 +263,19 @@ type
   end;
   IFLFont = IFresnelFont;
 
+  IFresnelRenderer = Interface ['{06738575-BE7F-4EA5-A4D0-3E26A5441BFD}']
+    procedure FillRect(const aColor: TFPColor; const aRect: TFresnelRect);
+    procedure Line(const aColor: TFPColor; const x1, y1, x2, y2: TFresnelLength);
+    procedure TextOut(const aLeft, aTop: TFresnelLength; const aFont: IFresnelFont; const aColor: TFPColor; const aText: string);
+    procedure DrawImage(const aLeft, aTop, aWidth, aHeight: TFresnelLength; const aImage: TFPCustomImage);
+  end;
+
+  IFresnelRenderable = Interface ['{1364DA87-CA22-48A4-B1B2-A8A2C3047FD8}']
+    Procedure BeforeRender;
+    Procedure AfterRender;
+    Procedure Render(aRenderer : IFresnelRenderer);
+  end;
+
   { TFresnelFontDesc - font descriptor }
 
   TFresnelFontDesc = record
@@ -285,7 +299,7 @@ type
 
   { TFresnelElement }
 
-  TFresnelElement = class(TFresnelComponent, ICSSNode, IFPObserver)
+  TFresnelElement = class(TFresnelComponent, ICSSNode, IFPObserver, IFresnelRenderable)
   private
     function GetCSSPseudoClass(Pseudo: TFresnelCSSPseudoClass): boolean;
     function GetNodeCount: integer;
@@ -297,6 +311,8 @@ type
     procedure SetCSSRenderedAttribute(Attr: TFresnelCSSAttribute; const AValue: string
       );
   private
+    FAfterRender: TNotifyEvent;
+    FBeforeRender: TNotifyEvent;
     FDOMIndex: integer;
     FFont: IFresnelFont;
     FLayoutNode: TFresnelLayoutNode;
@@ -395,6 +411,11 @@ type
   protected
     procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
     procedure SetParentComponent(Value: TComponent); override;
+    procedure DoRender(aRenderer :  IFresnelRenderer); virtual;
+    { IFResnelRenderable }
+    Procedure BeforeRender;
+    Procedure AfterRender;
+    Procedure Render(aRenderer : IFresnelRenderer);
   public
     constructor Create(AOwner: TComponent); override;
     destructor Destroy; override;
@@ -488,6 +509,8 @@ type
     Property OnFocus : TFresnelFocusEventHandler Index evtFocus Read GetFocusEventHandler Write SetFocusEventHandler;
     Property OnEnter : TFresnelFocusEventHandler Index evtFocusIn Read GetFocusEventHandler Write SetFocusEventHandler;
     Property OnLeave : TFresnelFocusEventHandler Index evtFocusOut Read GetFocusEventHandler Write SetFocusEventHandler;
+    Property BeforeRendering : TNotifyEvent Read FBeforeRender Write FBeforeRender;
+    Property AfterRendered : TNotifyEvent Read FAfterRender Write FAfterRender;
   end;
   TFLElement = TFresnelElement;
   TFresnelElementClass = class of TFresnelElement;
@@ -2907,6 +2930,28 @@ begin
     raise EFresnel.CreateFmt('TFresnelElement.SetParentComponent Self=%s NewParentComponent=%s',[Self.ToString,Value.ToString]);
 end;
 
+procedure TFresnelElement.DoRender(aRenderer: IFresnelRenderer);
+begin
+  //
+end;
+
+procedure TFresnelElement.BeforeRender;
+begin
+  If Assigned(FBeforeRender) then
+    FBeforeRender(Self);
+end;
+
+procedure TFresnelElement.AfterRender;
+begin
+  If Assigned(FAfterRender) then
+    FAfterRender(Self);
+end;
+
+procedure TFresnelElement.Render(aRenderer: IFresnelRenderer);
+begin
+  DoRender(aRenderer);
+end;
+
 procedure TFresnelElement.GetChildren(Proc: TGetChildProc; Root: TComponent);
 var
   i: Integer;

+ 10 - 17
src/base/fresnel.renderer.pas

@@ -13,7 +13,7 @@ type
 
   { TFresnelRenderer }
 
-  TFresnelRenderer = class(TComponent)
+  TFresnelRenderer = class(TComponent,IFresnelRenderer)
   private
     FSubPixel: boolean;
   protected
@@ -29,6 +29,7 @@ type
     procedure FillRect(const aColor: TFPColor; const aRect: TFresnelRect); virtual; abstract;
     procedure Line(const aColor: TFPColor; const x1, y1, x2, y2: TFresnelLength); virtual; abstract;
     procedure TextOut(const aLeft, aTop: TFresnelLength; const aFont: IFresnelFont; const aColor: TFPColor; const aText: string); virtual; abstract;
+    procedure DrawImage(const aLeft, aTop, aWidth, aHeight: TFresnelLength; const aImage: TFPCustomImage); virtual; abstract;
     procedure MathRoundRect(var r: TFresnelRect);
     procedure DrawElBorder(El: TFresnelElement; Params: TBorderAndBackground); virtual;
     procedure DrawElement(El: TFresnelElement); virtual;
@@ -107,11 +108,14 @@ var
     aPaddingLeft, aPaddingRight, aPaddingTop, aPaddingBottom: TFresnelLength;
   aBorderBox, aContentBox: TFresnelRect;
   BorderParams: TBorderAndBackground;
+  aRenderable : IFresnelRenderable;
+
 begin
   //DebugLn(['TFresnelRenderer.DrawElement ',El.GetPath,' Origin=',dbgs(Origin)]);
   LNode:=TSimpleFresnelLayoutNode(El.LayoutNode);
   if LNode.SkipRendering then exit;
-
+  aRenderable:=El as IFresnelRenderable;
+  aRenderable.BeforeRender;
   El.Rendered:=true;
   aLeft:=El.GetRenderedCSSLength(fcaLeft,false);
   aTop:=El.GetRenderedCSSLength(fcaTop,false);
@@ -166,23 +170,12 @@ begin
   finally
     BorderParams.Free;
   end;
-
-  if El is TCustomLabel then
-  begin
-    aCaption:=TCustomLabel(El).RenderedCaption;
-    if aCaption<>'' then
-    begin
-      aColor:=El.GetRenderedCSString(fcaColor,true);
-      if not CSSToFPColor(aColor,aColorFP) then
-        aColorFP:=colTransparent;
-      if aColorFP.Alpha<>alphaTransparent then
-      begin
-        TextOut(aContentBox.Left,aContentBox.Top,El.Font,aColorFP,aCaption);
-      end;
-    end;
-  end;
+  // Give element a chance to draw itself.
+  aRenderable.Render(Self as IFresnelRenderer);
 
   DrawChildren(El);
+
+  aRenderable.BeforeRender;
 end;
 
 procedure TFresnelRenderer.DrawChildren(El: TFresnelElement);