-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
ChatGPT.FrameImage.pas
105 lines (90 loc) · 2.67 KB
/
ChatGPT.FrameImage.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
unit ChatGPT.FrameImage;
interface
uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
FMX.Objects, FMX.Effects, FMX.Filter.Effects, FMX.Menus,
FMX.Controls.Presentation;
type
TFrameImage = class(TFrame)
RectangleImage: TRectangle;
AniIndicator: TAniIndicator;
PopupMenuCopy: TPopupMenu;
MenuItemCopy: TMenuItem;
LabelError: TLabel;
procedure RectangleImageClick(Sender: TObject);
procedure MenuItemCopyClick(Sender: TObject);
procedure RectangleImagePaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
procedure LabelErrorResize(Sender: TObject);
private
FImage: string;
FIsLoaded: Boolean;
procedure SetImage(const Value: string);
public
property Image: string read FImage write SetImage;
constructor Create(AOwner: TComponent); override;
end;
implementation
uses
ChatGPT.FrameImagePreview, FMX.Platform, ChatGPT.FrameUIMessage, HGM.FMX.Image;
{$R *.fmx}
{ TFrameImage }
constructor TFrameImage.Create(AOwner: TComponent);
begin
inherited;
FIsLoaded := False;
Name := '';
RectangleImage.HitTest := False;
end;
procedure TFrameImage.LabelErrorResize(Sender: TObject);
begin
if LabelError.Width < 100 then
LabelError.Font.Size := 12
else
LabelError.Font.Size := 14;
end;
procedure TFrameImage.MenuItemCopyClick(Sender: TObject);
begin
var ClipBoard: IFMXClipboardService;
if TPlatformServices.Current.SupportsPlatformService(IFMXClipboardService, ClipBoard) then
begin
ClipBoard.SetClipboard(RectangleImage.Fill.Bitmap.Bitmap);
ShowUIMessage('Image coppied');
end
else
ShowUIMessage('ClipBoard error');
end;
procedure TFrameImage.RectangleImageClick(Sender: TObject);
begin
RectangleImage.Visible := False;
TFramePreview.ShowPreview(RectangleImage.Fill.Bitmap.Bitmap, RectangleImage,
procedure
begin
RectangleImage.Visible := True;
end);
end;
procedure TFrameImage.RectangleImagePaint(Sender: TObject; Canvas: TCanvas; const ARect: TRectF);
begin
if not FIsLoaded then
begin
FIsLoaded := True;
RectangleImage.Fill.Bitmap.Bitmap.LoadFromUrlAsync(RectangleImage, FImage, True,
procedure(Success: Boolean)
begin
AniIndicator.Visible := False;
if Success then
begin
RectangleImage.Fill.Kind := TBrushKind.Bitmap;
RectangleImage.Fill.Bitmap.WrapMode := TWrapMode.TileStretch;
RectangleImage.HitTest := True;
end
else
LabelError.Visible := True;
end);
end;
end;
procedure TFrameImage.SetImage(const Value: string);
begin
FImage := Value;
end;
end.