-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTaskBoard.View.Card.pas
168 lines (149 loc) · 4.79 KB
/
TaskBoard.View.Card.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
unit TaskBoard.View.Card;
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.Memo.Types, FMX.Controls.Presentation, FMX.ScrollBox, FMX.Memo,
FMX.Objects, FMX.Effects, FMX.Layouts, FMX.Ani;
type
TFrameCard = class(TFrame)
RectangleContent: TRectangle;
MemoText: TMemo;
LayoutAction: TLayout;
Button1: TButton;
LayoutEdit: TLayout;
ColorAnimationOver: TColorAnimation;
FloatAnimationActions: TFloatAnimation;
Rectangle1: TRectangle;
procedure FrameDragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
procedure FrameDragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
procedure FrameDragEnd(Sender: TObject);
procedure FrameDragLeave(Sender: TObject);
procedure FrameDragEnter(Sender: TObject; const Data: TDragObject; const Point: TPointF);
procedure FrameResize(Sender: TObject);
procedure MemoTextViewportPositionChange(Sender: TObject; const OldViewportPosition, NewViewportPosition: TPointF; const ContentSizeChanged: Boolean);
private
FLastSize: Single;
protected
procedure BeginAutoDrag; override;
procedure SetParent(const Value: TFmxObject); override;
public
constructor Create(AOwner: TComponent); override;
procedure ChangedParent;
end;
implementation
uses
System.Math;
{$R *.fmx}
procedure TFrameCard.ChangedParent;
begin
MemoText.PrepareForPaint;
FrameResize(nil);
end;
constructor TFrameCard.Create(AOwner: TComponent);
begin
inherited;
FLastSize := 0;
end;
procedure TFrameCard.BeginAutoDrag;
const
DraggingOpacity = 1;
var
B, S: TBitmap;
R: TRectF;
begin
if Root <> nil then
begin
S := MakeScreenshot;
S.Rotate(5);
try
B := nil;
try
if (S.Width > 512) or (S.Height > 512) then
begin
R := TRectF.Create(0, 0, S.Width, S.Height);
R.Fit(TRectF.Create(0, 0, 512, 512));
B := TBitmap.Create(Round(R.Width), Round(R.Height));
B.Clear(0);
if B.Canvas.BeginScene then
try
B.Canvas.DrawBitmap(S, TRectF.Create(0, 0, S.Width, S.Height), TRectF.Create(0, 0, B.Width, B.Height),
DraggingOpacity, False);
finally
B.Canvas.EndScene;
end;
end
else
begin
B := TBitmap.Create(S.Width, S.Height);
B.Clear(0);
if B.Canvas.BeginScene then
try
B.Canvas.DrawBitmap(S, TRectF.Create(0, 0, B.Width, B.Height), TRectF.Create(0, 0, B.Width, B.Height),
DraggingOpacity, False);
finally
B.Canvas.EndScene;
end;
end;
Root.BeginInternalDrag(Self, B);
finally
B.Free;
end;
finally
S.Free;
end;
end;
end;
procedure TFrameCard.FrameDragDrop(Sender: TObject; const Data: TDragObject; const Point: TPointF);
begin
if (not Assigned(ParentControl)) or (not Assigned(ParentControl.ParentControl)) then
Exit;
ParentControl.ParentControl.OnDragDrop(Sender, Data, Point);
end;
procedure TFrameCard.FrameDragEnd(Sender: TObject);
begin
Visible := True;
ParentControl.ParentControl.OnDragEnd(Sender);
end;
procedure TFrameCard.FrameDragEnter(Sender: TObject; const Data: TDragObject; const Point: TPointF);
begin
if Data.Source = Self then
Visible := False;
end;
procedure TFrameCard.FrameDragLeave(Sender: TObject);
begin
if (not Assigned(ParentControl)) or (not Assigned(ParentControl.ParentControl)) then
Exit;
ParentControl.ParentControl.OnDragLeave(Sender);
end;
procedure TFrameCard.FrameDragOver(Sender: TObject; const Data: TDragObject; const Point: TPointF; var Operation: TDragOperation);
begin
if (not Assigned(ParentControl)) or (not Assigned(ParentControl.ParentControl)) then
Exit;
ParentControl.ParentControl.OnDragOver(Sender, Data, Point, Operation);
end;
procedure TFrameCard.FrameResize(Sender: TObject);
begin
MemoText.Height := Round(MemoText.ContentBounds.Height + 2);
var H: Single := 0;
for var Control in RectangleContent.Controls do
if Control.IsVisible and (Control.Align in [TAlignLayout.Top, TAlignLayout.MostTop]) then
H := Max(H, Control.Position.Y + Control.Height + Control.Margins.Bottom);
H := Round(H + RectangleContent.Padding.Top + RectangleContent.Padding.Bottom);
if Height <> H then
Height := H;
end;
procedure TFrameCard.MemoTextViewportPositionChange(Sender: TObject; const OldViewportPosition, NewViewportPosition: TPointF; const ContentSizeChanged: Boolean);
begin
TThread.ForceQueue(nil,
procedure
begin
FrameResize(nil);
end);
end;
procedure TFrameCard.SetParent(const Value: TFmxObject);
begin
inherited;
FrameResize(nil);
end;
end.