Changeset 542 for Common


Ignore:
Timestamp:
Feb 3, 2020, 12:26:46 AM (5 years ago)
Author:
chronos
Message:
  • Added: Support to draw to RoundRect in TMetaCanvas.
Location:
Common
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • Common/Common.lpk

    r540 r542  
    4040    <License Value="GNU/GPL"/>
    4141    <Version Minor="7"/>
    42     <Files Count="24">
     42    <Files Count="26">
    4343      <Item1>
    4444        <Filename Value="StopWatch.pas"/>
     
    147147        <UnitName Value="UGeometric"/>
    148148      </Item24>
     149      <Item25>
     150        <Filename Value="UTranslator.pas"/>
     151        <HasRegisterProc Value="True"/>
     152        <UnitName Value="UTranslator"/>
     153      </Item25>
     154      <Item26>
     155        <Filename Value="ULanguages.pas"/>
     156        <UnitName Value="ULanguages"/>
     157      </Item26>
    149158    </Files>
    150159    <i18n>
  • Common/UMetaCanvas.pas

    r540 r542  
    3939    Brush: TBrush;
    4040    BoundingRect: TRect;
     41    Rounded: TPoint;
    4142    procedure Paint(Canvas: TCanvas); override;
    4243    procedure Zoom(Factor: Double); override;
     
    133134  public
    134135    Objects: TObjectList;
     136    procedure FillRect(const ARect: TRect); overload; override;
     137    procedure FillRect(X1,Y1,X2,Y2: Integer); overload;
     138    procedure RoundRect(X1, Y1, X2, Y2: Integer; RX,RY: Integer); overload; override;
     139    procedure RoundRect(const Rect: TRect; RX,RY: Integer); overload;
    135140    procedure TextOut(X,Y: Integer; const Text: String); override;
    136141    procedure Polygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); override;
     
    152157
    153158uses
    154   UGeometric;
     159  UGeometric, LCLIntf;
    155160
    156161{ TCanvasPie }
     
    340345  Canvas.Pen.Assign(Pen);
    341346  Canvas.Brush.Assign(Brush);
    342   Canvas.Rectangle(BoundingRect);
     347
     348  if Rounded <> Point(0, 0) then Canvas.RoundRect(BoundingRect, Rounded.X, Rounded.Y)
     349    else Canvas.Rectangle(BoundingRect);
    343350end;
    344351
     
    354361procedure TCanvasRectangle.Move(Delta: TPoint);
    355362begin
    356   ShiftRect(BoundingRect, Delta);
     363  BoundingRect := ShiftRect(BoundingRect, Delta);
    357364end;
    358365
     
    361368  Pen := TPen.Create;
    362369  Brush := TBrush.Create;
     370  Rounded := Point(0, 0);
    363371end;
    364372
     
    547555
    548556function TMetaCanvas.TextExtent(const Text: string): TSize;
    549 begin
    550   Result := Size(0, 0);
     557var
     558  Canvas: TCanvas;
     559begin
     560  Canvas := TCanvas.Create;
     561  Canvas.Handle := CreateCompatibleDC(0);
     562  Canvas.Font.Assign(Font);
     563  Result := Canvas.TextExtent(Text);
     564  DeleteDC(Canvas.Handle);
     565  Canvas.Free;
    551566end;
    552567
     
    560575  DoLine(FPenPos.X, FPenPos.Y, X, Y);
    561576  DoMoveTo(X, Y);
     577end;
     578
     579procedure TMetaCanvas.FillRect(const ARect: TRect);
     580begin
     581  DoRectangleFill(ARect);
     582end;
     583
     584procedure TMetaCanvas.FillRect(X1, Y1, X2, Y2: Integer);
     585begin
     586  FillRect(Rect(X1, Y1, X2, Y2));
     587end;
     588
     589procedure TMetaCanvas.RoundRect(X1, Y1, X2, Y2: Integer; RX, RY: Integer);
     590begin
     591  RoundRect(Rect(X1, Y1, X2, Y2), RX, RY);
     592end;
     593
     594procedure TMetaCanvas.RoundRect(const Rect: TRect; RX, RY: Integer);
     595var
     596  NewObj: TCanvasRectangle;
     597begin
     598  NewObj := TCanvasRectangle.Create;
     599  NewObj.Brush.Assign(Brush);
     600  NewObj.Pen.Assign(Pen);
     601  NewObj.BoundingRect := Rect;
     602  NewObj.Rounded := Point(RX, RY);
     603  Objects.Add(NewObj);
    562604end;
    563605
Note: See TracChangeset for help on using the changeset viewer.