-
Notifications
You must be signed in to change notification settings - Fork 6
/
TSegmentClass.pas
277 lines (232 loc) · 7.91 KB
/
TSegmentClass.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
{ MMP: Minimalist Media Player
Copyright (C) 2021-2024 Baz Cuda
https://github.com/BazzaCuda/MinimalistMediaPlayerX
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
}
unit TSegmentClass;
interface
uses
winApi.windows,
system.classes, system.generics.collections,
vcl.controls, vcl.extCtrls, vcl.forms, vcl.graphics, vcl.stdCtrls;
const
NEARLY_BLACK = clBlack + $101010;
DEFAULT_SEGMENT_HEIGHT = 54;
type
TSegment = class(TPanel)
strict private
FDeleted: boolean;
FEndSS: integer;
FOldColor: TColor;
FSegDetails: TLabel;
FSegID: TLabel;
FSelected: boolean;
FStartSS: integer;
FTitle: TLabel;
FTrashCan: TImage;
private
function getDuration: integer;
function getIsFirst: boolean;
function getIsLast: boolean;
function getIx: integer;
function getSegID: string;
function getTitle: string;
procedure setSegID(const Value: string);
procedure setSelected(const Value: boolean);
procedure setTitle(const Value: string);
class var FParent: TWinControl;
class var FSelSeg: TSegment;
class var FSegments: TObjectList<TSegment>;
class destructor freeSegments;
class function getSegments: TObjectList<TSegment>; static;
class function getIncludedCount: integer; static;
protected
procedure doClick(Sender: TObject);
procedure paint; override;
public
constructor create(const aStartSS: integer; const aEndSS: integer; const bDeleted: boolean = FALSE);
function delete: boolean;
procedure setDisplayDetails;
function setAsSelSeg: boolean;
property deleted: boolean read FDeleted write FDeleted;
property duration: integer read getDuration;
property endSS: integer read FEndSS write FEndSS;
property isFirst: boolean read getIsFirst;
property isLast: boolean read getIsLast;
property ix: integer read getIx;
property oldColor: TColor read FOldColor write FOldColor;
property segID: string read getSegID write setSegID;
property selected: boolean read FSelected write setSelected;
property startSS: integer read FStartSS write FStartSS;
property title: string read getTitle write setTitle;
property trashCan: TImage read FTrashCan;
class function clearFocus: boolean; static;
class property includedCount: integer read getIncludedCount;
class property parentForm: TWinControl write FParent;
class property segments: TObjectList<TSegment> read getSegments; // technique copied from system.messaging.TMessageManager
class property selSeg: TSegment read FSelSeg write FSelSeg;
end;
implementation
uses
system.sysUtils,
mmpConsts,
_debugWindow;
function generateRandomEvenDarkerSoftColor: TColor; // from a suggestion by chatGPT
{$J+} const nextColor: integer = 0; {$J-}
var
darkerSoftColors: array of TColor;
begin
// Define an array of even darker soft colors
SetLength(darkerSoftColors, 5);
darkerSoftColors[0] := RGB(80, 80, 80); // Very Dark Gray
darkerSoftColors[1] := RGB(70, 70, 70); // Very Dark Silver
darkerSoftColors[2] := RGB(60, 60, 60); // Very Dark Platinum
darkerSoftColors[3] := RGB(50, 50, 50); // Very Dark Snow
darkerSoftColors[4] := RGB(40, 40, 40); // Very Dark Ivory
// darkerSoftColors[5] := RGB(30, 30, 30); // Extremely Dark Gray
result := darkerSoftColors[nextColor];
inc(nextColor);
case nextColor > 4 of TRUE: nextColor := 0; end;
end;
{ TSegment }
class function TSegment.clearFocus: boolean;
begin
for var vSegment in FSegments do vSegment.selected := FALSE;
FSelSeg := NIL;
end;
class function TSegment.getIncludedCount: integer;
begin
result := 0;
for var vSegment in FSegments do
case vSegment.deleted of FALSE: inc(result); end;
end;
class function TSegment.getSegments: TObjectList<TSegment>;
begin
case FSegments = NIL of TRUE: begin
FSegments := TObjectList<TSegment>.create;
FSegments.ownsObjects := TRUE; end;end;
result := FSegments;
end;
class destructor TSegment.freeSegments;
begin
freeAndNil(FSegments);
end;
constructor TSegment.create(const aStartSS: integer; const aEndSS: integer; const bDeleted: boolean = FALSE);
begin
inherited create(NIL);
parent := FParent;
height := DEFAULT_SEGMENT_HEIGHT;
font.color := DARK_MODE_SILVER;
font.size := 10;
font.style := [fsBold];
alignment := taLeftJustify;
onClick := doClick;
startSS := aStartSS;
endSS := aEndSS;
borderStyle := bsNone;
bevelOuter := bvNone;
color := generateRandomEvenDarkerSoftColor;
oldColor := color;
FSegID := TLabel.create(SELF);
FSegID.parent := SELF;
FSegID.top := 0;
FSegID.left := 4;
FSegID.styleElements := [];
FTitle := TLabel.create(SELF);
FTitle.parent := SELF;
FTitle.top := 18;
FTitle.left := 4;
FTitle.styleElements := [];
FSegDetails := TLabel.create(SELF);
FSegDetails.parent := SELF;
FSegDetails.top := 38;
FSegDetails.left := 4;
FSegDetails.styleElements := [];
FTrashCan := TImage.create(SELF);
FTrashCan.parent := SELF;
FTrashCan.stretch := TRUE;
FTrashCan.center := TRUE;
FTrashCan.height := 31;
FTrashCan.width := 41;
FTrashCan.visible := FALSE;
FTrashCan.onClick := doClick;
case bDeleted of TRUE: SELF.delete; end;
end;
function TSegment.delete: boolean;
begin
result := FALSE;
deleted := TRUE;
case color = NEARLY_BLACK of FALSE: oldColor := color; end; // in case user tries to delete an already-deleted segment
color := NEARLY_BLACK;
result := TRUE;
end;
procedure TSegment.doClick(Sender: TObject);
begin
setAsSelSeg;
end;
function TSegment.getDuration: integer;
begin
result := FEndSS - FStartSS;
end;
function TSegment.getIsFirst: boolean;
begin
result := ix = 0;
end;
function TSegment.getIsLast: boolean;
begin
result := ix = FSegments.count - 1;
end;
function TSegment.getIx: integer;
begin
result := FSegments.indexOf(SELF);
end;
function TSegment.getSegID: string;
begin
result := FSegID.caption;
end;
function TSegment.getTitle: string;
begin
result := FTitle.caption;
end;
procedure TSegment.paint;
begin
var rect := getClientRect;
canvas.brush.color := color;
canvas.fillRect(rect);
case selected of TRUE: Frame3D(canvas, rect, clTeal, clTeal, 1);
FALSE: Frame3D(canvas, rect, color, color, 1); end;
end;
procedure TSegment.setSegID(const Value: string);
begin
FSegID.caption := value;
end;
function TSegment.setAsSelSeg: boolean;
begin
clearFocus;
FSelSeg := SELF;
selected := TRUE;
end;
procedure TSegment.setDisplayDetails;
begin
FSegDetails.caption := format('%ds - %ds', [startSS, endSS]);
end;
procedure TSegment.setSelected(const Value: boolean);
begin
FSelected := Value;
invalidate;
end;
procedure TSegment.setTitle(const Value: string);
begin
FTitle.caption := Value;
end;
end.