diff --git a/components/skia/design/Skia.LCL.Design.lpk b/components/skia/design/Skia.LCL.Design.lpk index 33f1cb1a1..fbfb3cd7d 100644 --- a/components/skia/design/Skia.LCL.Design.lpk +++ b/components/skia/design/Skia.LCL.Design.lpk @@ -21,6 +21,9 @@ + + + diff --git a/components/skia/design/SkiaLCLRegister.pas b/components/skia/design/SkiaLCLRegister.pas index b9c32b09a..986547086 100644 --- a/components/skia/design/SkiaLCLRegister.pas +++ b/components/skia/design/SkiaLCLRegister.pas @@ -8,7 +8,17 @@ unit SkiaLCLRegister; interface uses - LCL.Skia, classes; + LCL.Skia, classes, PropEdits, ObjInspStrConsts, FileUtil, Dialogs; + +type + + { TSkSvgSourcePropertyEditor } + + TSkSvgSourcePropertyEditor = class(TPropertyEditor) + public + function GetAttributes: TPropertyAttributes; override; + procedure Edit; override; + end; procedure Register; @@ -18,7 +28,36 @@ implementation procedure Register; begin - RegisterComponents('Skia', [TSkPaintBox]); + RegisterPropertyEditor(TypeInfo(TSkSvgSource), nil, '', TSkSvgSourcePropertyEditor); + RegisterComponents('Skia', [TSkPaintBox,TSkSvg]); +end; + +{ TSkSvgSourcePropertyEditor } + +function TSkSvgSourcePropertyEditor.GetAttributes: TPropertyAttributes; +begin + Result:=[paDialog,paRevertable]; +end; + +procedure TSkSvgSourcePropertyEditor.Edit; +var + Dlg: TOpenDialog; + ss: TStringStream; +begin + Dlg:=TOpenDialog.Create(nil); + ss:=nil; + try + Dlg.Filter:='Scalable Vector Grahics (*.svg)|*.svg|'+oisAllFiles+' ('+GetAllFilesMask+')|'+GetAllFilesMask; + Dlg.Options:=DefaultOpenDialogOptions+[ofFileMustExist]; + Dlg.Title:=oisSelectAFile; + if not Dlg.Execute then exit; + ss:=TStringStream.Create(''); + ss.LoadFromFile(Dlg.Filename); + SetStrValue(ss.AnsiDataString); + finally + ss.Free; + Dlg.Free; + end; end; end. diff --git a/components/skia/src/LCL.Skia.pas b/components/skia/src/LCL.Skia.pas index ecf472aa1..9fbeac04a 100644 --- a/components/skia/src/LCL.Skia.pas +++ b/components/skia/src/LCL.Skia.pas @@ -39,6 +39,7 @@ type procedure SetOpacity(const AValue: Byte); protected FScaleFactor: Single; + class function GetControlClassDefaultSize: TSize; override; procedure ChangeScale(Multiplier, Divider: Integer); override; procedure Draw(const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single); virtual; procedure DeleteBuffers; virtual; @@ -59,24 +60,17 @@ type { TSkPaintBox } TSkPaintBox = class(TSkCustomControl) - protected - class function GetControlClassDefaultSize: TSize; override; public - constructor Create(AOwner: TComponent); override; property DrawCacheKind; published property Align; property Anchors; property BorderSpacing; - property Color; property Constraints; property DragCursor; property DragMode; property Enabled; - property Font; property Hint; - property ParentColor; - property ParentFont; property ParentShowHint; property PopupMenu; property ShowHint; @@ -149,7 +143,7 @@ type property WrapMode: TSkSvgWrapMode read FWrapMode write SetWrapMode default DefaultWrapMode; end; - { TSkSvg } + { TSkSvg - does not work yet } TSkSvg = class(TSkCustomControl) strict private @@ -163,8 +157,41 @@ type destructor Destroy; override; procedure Draw(const ACanvas: ISkCanvas; const ADest: TRectF; const AOpacity: Single); override; published + property Align; + property Anchors; + property BorderSpacing; + property Constraints; + property DragCursor; + property DragMode; + property Enabled; + property Hint; + property ParentShowHint; + property PopupMenu; + property ShowHint; property Svg: TSkSvgBrush read FSvg write SetSvg; + property Visible; + property OnChangeBounds; + property OnClick; + property OnContextPopup; + property OnDblClick; + property OnDragDrop; + property OnDragOver; property OnDraw; + property OnEndDrag; + property OnMouseDown; + property OnMouseEnter; + property OnMouseLeave; + property OnMouseMove; + property OnMouseUp; + property OnMouseWheel; + property OnMouseWheelDown; + property OnMouseWheelUp; + property OnMouseWheelHorz; + property OnMouseWheelLeft; + property OnMouseWheelRight; + property OnPaint; + property OnResize; + property OnStartDrag; end; TSkControlRenderBackend = (Default, Raster, HardwareAcceleration); @@ -406,6 +433,12 @@ begin Invalidate; end; +class function TSkCustomControl.GetControlClassDefaultSize: TSize; +begin + Result.CX := 50; + Result.CY := 50; +end; + procedure TSkCustomControl.ChangeScale(Multiplier, Divider: Integer); begin if Multiplier <> Divider then @@ -514,6 +547,8 @@ begin FDrawCacheKind := TSkDrawCacheKind.Raster; FOpacity := 255; FScaleFactor := 1; + with GetControlClassDefaultSize do + SetInitialBounds(0, 0, CX, CY); end; destructor TSkCustomControl.Destroy; @@ -524,8 +559,7 @@ end; procedure TSkCustomControl.Redraw; begin - FDrawCached := False; - Repaint; + Invalidate; end; procedure TSkCustomControl.Invalidate; @@ -534,22 +568,6 @@ begin inherited Invalidate; end; -{ TSkPaintBox } - -class function TSkPaintBox.GetControlClassDefaultSize: TSize; -begin - Result.CX := 50; - Result.CY := 50; -end; - -constructor TSkPaintBox.Create(AOwner: TComponent); -begin - inherited Create(AOwner); - ControlStyle := ControlStyle + [csReplicatable]; - with GetControlClassDefaultSize do - SetInitialBounds(0, 0, CX, CY); -end; - { TSkSvgBrush } function TSkSvgBrush.GetDOM: ISkSVGDOM; @@ -602,6 +620,7 @@ begin if FSource <> AValue then begin FSource := AValue; + writeln('TSkSvgBrush.SetSource ',length(FSource)); RecreateDOM; DoChanged; end;