-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathuntERDPlayerButton.pas
More file actions
821 lines (721 loc) · 24.1 KB
/
Copy pathuntERDPlayerButton.pas
File metadata and controls
821 lines (721 loc) · 24.1 KB
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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
{
untERDPlayerButton v1.0.0 - a button for use with a audio player
for Delphi 2010 - 10.4 by Ernst Reidinga
https://erdesigns.eu
This unit is part of the ERDesigns Audio Toolkit Components Pack.
(c) Copyright 2020 Ernst Reidinga <ernst@erdesigns.eu>
Bugfixes / Updates:
- Initial Release 1.0.0
If you use this unit, please give credits to the original author;
Ernst Reidinga.
}
unit untERDPlayerButton;
interface
uses
System.SysUtils, System.Classes, Winapi.Windows, Vcl.Controls, Vcl.Graphics,
Winapi.Messages, System.Types, Vcl.ExtCtrls, GDIPlus;
type
TERDPlayerButtonState = (bsNormal, bsHot, bsPressed, bsChecked);
TERDPlayerButtonIndicatorShape = (bisStop, bisPlay, bisPause, bisNext,
bisPrevious, bisEject, bisRecord, bisVolume, bisMute);
TERDPlayerButtonIndicator = class(TPersistent)
private
{ Private declarations }
FShape : TERDPlayerButtonIndicatorShape;
FOnColor : TColor;
FOffColor : TColor;
FWidth : Integer;
FHeight : Integer;
FOnChange : TNotifyEvent;
procedure SetShape(const S: TERDPlayerButtonIndicatorShape);
procedure SetOnColor(const C: TColor);
procedure SetOffColor(const C: TColor);
procedure SetWidth(const I: Integer);
procedure SetHeight(const I: Integer);
public
{ Public declarations }
constructor Create; virtual;
procedure Assign(Source: TPersistent); override;
published
{ Published declarations }
property Shape: TERDPlayerButtonIndicatorShape read FShape write SetShape default bisStop;
property OnColor: TColor read FOnColor write SetOnColor default $00EAA900;
property OffColor: TColor read FOffColor write SetOffColor default $00E5E5D5;
property Width: Integer read FWidth write SetWidth default 16;
property Height: Integer read FHeight write SetHeight default 16;
property OnChange: TNotifyEvent read FOnChange write FOnChange;
end;
TERDPlayerButton = class(TCustomControl)
private
{ Private declarations }
FIndicator : TERDPlayerButtonIndicator;
FOnClick : TNotifyEvent;
{ Buffer - Avoid flickering }
FBuffer : TBitmap;
FButtonBuffer : TBitmap;
FUpdateRect : TRect;
FRedraw : Boolean;
{ Button State }
FLastButton : Boolean;
FButtonState : TERDPlayerButtonState;
FActive : Boolean;
FBlinking : Boolean;
FIsPressed : Boolean;
{ Do we want a focus rect ? }
FDrawFocusRect : Boolean;
{ Blinking Timer }
FBlinkingTimer : TTimer;
procedure SetIndicator(const I: TERDPlayerButtonIndicator);
procedure SetActive(const B: Boolean);
procedure SetLastButton(const B: Boolean);
function GetBlinkingActive : Boolean;
procedure SetBlinkingActive(const B: Boolean);
function GetBlinkInterval : Integer;
procedure SetBlinkInterval(const I: Integer);
function GetChecked : Boolean;
procedure SetChecked(const B: Boolean);
procedure WMPaint(var Msg: TWMPaint); message WM_PAINT;
procedure WMEraseBkGnd(var Msg: TWMEraseBkGnd); message WM_ERASEBKGND;
protected
{ Protected declarations }
procedure SettingsChanged(Sender: TObject);
procedure OnBlinkingTimer(Sender: TObject);
procedure Paint; override;
procedure Resize; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure WndProc(var Message: TMessage); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyUp(var Key: Word; Shift: TShiftState); override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
property Redraw: Boolean read FRedraw write FRedraw;
property UpdateRect: TRect read FUpdateRect write FUpdateRect;
property ButtonState: TERDPlayerButtonState read FButtonState;
published
{ Published declarations }
property Indicator: TERDPlayerButtonIndicator read FIndicator write SetIndicator;
property Active: Boolean read FActive write SetActive default False;
property Checked: Boolean read GetChecked write SetChecked default False;
property Blinking: Boolean read GetBlinkingActive write SetBlinkingActive;
property BlinkInterval: Integer read GetBlinkInterval write SetBlinkInterval default 1000;
property LastButton: Boolean read FLastButton write SetLastButton default False;
property DrawFocusRect: Boolean read FDrawFocusRect write FDrawFocusRect default True;
property OnClick: TNotifyEvent read FOnClick write FOnClick;
property Align;
property Anchors;
property Color default $00444444;
property Constraints;
property Enabled;
property ParentColor;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property TabOrder;
property TabStop;
property Touch;
property Visible;
property OnEnter;
property OnExit;
property OnGesture;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnResize;
end;
implementation
uses System.Math, untERDMidiCommon;
(******************************************************************************)
(*
(* ERD Player Button Indicator (TERDPlayerButtonIndicator)
(*
(******************************************************************************)
constructor TERDPlayerButtonIndicator.Create;
begin
inherited Create;
FShape := bisStop;
FOnColor := $00EAA900;
FOffColor := $00E5E5D5;
FWidth := 16;
FHeight := 16;
end;
procedure TERDPlayerButtonIndicator.Assign(Source: TPersistent);
begin
if Source is TERDPlayerButtonIndicator then
begin
FShape := TERDPlayerButtonIndicator(Source).Shape;
FOnColor := TERDPlayerButtonIndicator(Source).OnColor;
FOffColor := TERDPlayerButtonIndicator(Source).OffColor;
FWidth := TERDPlayerButtonIndicator(Source).Width;
FHeight := TERDPlayerButtonIndicator(Source).Height;
end else
inherited;
end;
procedure TERDPlayerButtonIndicator.SetShape(const S: TERDPlayerButtonIndicatorShape);
begin
if Shape <> S then
begin
FShape := S;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TERDPlayerButtonIndicator.SetOnColor(const C: TColor);
begin
if OnColor <> C then
begin
FOnColor := C;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TERDPlayerButtonIndicator.SetOffColor(const C: TColor);
begin
if OffColor <> C then
begin
FOffColor := C;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TERDPlayerButtonIndicator.SetWidth(const I: Integer);
begin
if Width <> I then
begin
FWidth := I;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
procedure TERDPlayerButtonIndicator.SetHeight(const I: Integer);
begin
if Height <> I then
begin
FHeight := I;
if Assigned(FOnChange) then FOnChange(Self);
end;
end;
(******************************************************************************)
(*
(* ERD Player Button (TERDPlayerButton)
(*
(******************************************************************************)
constructor TERDPlayerButton.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{ If the ControlStyle property includes csOpaque, the control paints itself
directly. We don want the control to accept controls, this is a player display
which will hold components. Offcourse we like to get click, double click
and mouse events. }
ControlStyle := ControlStyle + [csOpaque, {csAcceptsControls,}
csCaptureMouse, csClickEvents, csDoubleClicks];
{ We do want to be able to get focus }
TabStop := True;
{ Create Buffers }
FBuffer := TBitmap.Create;
FBuffer.PixelFormat := pf32bit;
FBuffer.Canvas.Brush.Style := bsClear;
FButtonBuffer := TBitmap.Create;
FButtonBuffer.PixelFormat := pf32bit;
{ Settings }
FIndicator := TERDPlayerButtonIndicator.Create;
FIndicator.OnChange := SettingsChanged;
{ Blinking Timer }
FBlinkingTimer := TTimer.Create(Self);
FBlinkingTimer.Interval := 1000;
FBlinkingTimer.Enabled := False;
FBlinkingTimer.OnTimer := OnBlinkingTimer;
{ Width / Height }
Width := 81;
Height := 57;
{ Defaults }
Color := $00444444;
FButtonState := bsNormal;
FDrawFocusRect := True;
{ Initial Draw }
SettingsChanged(Self);
end;
destructor TERDPlayerButton.Destroy;
begin
{ Free Buffer }
FBuffer.Free;
FButtonBuffer.Free;
{ Free Blinking Timer }
FBlinkingTimer.Free;
{ Free Settings }
FIndicator.Free;
inherited Destroy;
end;
procedure TERDPlayerButton.SetIndicator(const I: TERDPlayerButtonIndicator);
begin
if Indicator <> I then
begin
FIndicator.Assign(I);
SettingsChanged(Self);
end;
end;
procedure TERDPlayerButton.SetActive(const B: Boolean);
begin
if Active <> B then
begin
FActive := B;
SettingsChanged(Self);
end;
end;
procedure TERDPlayerButton.SetLastButton(const B: Boolean);
begin
if LastButton <> B then
begin
FLastButton := B;
SettingsChanged(Self);
end;
end;
function TERDPlayerButton.GetBlinkingActive : Boolean;
begin
Result := FBlinkingTimer.Enabled;
end;
procedure TERDPlayerButton.SetBlinkingActive(const B: Boolean);
begin
if B <> FBlinkingTimer.Enabled then
begin
FBlinkingTimer.Enabled := B;
if not B then FBlinking := False;
Invalidate;
end;
end;
function TERDPlayerButton.GetBlinkInterval : Integer;
begin
Result := FBlinkingTimer.Interval;
end;
procedure TERDPlayerButton.SetBlinkInterval(const I: Integer);
begin
if FBlinkingTimer.Interval <> I then
FBlinkingTimer.Interval := I
end;
function TERDPlayerButton.GetChecked : Boolean;
begin
Result := ButtonState = bsChecked;
end;
procedure TERDPlayerButton.SetChecked(const B: Boolean);
begin
case B of
True : FButtonState := bsChecked;
False : FButtonState := bsNormal;
end;
SettingsChanged(Self);
end;
procedure TERDPlayerButton.WMPaint(var Msg: TWMPaint);
begin
GetUpdateRect(Handle, FUpdateRect, False);
inherited;
end;
procedure TERDPlayerButton.WMEraseBkGnd(var Msg: TWMEraseBkgnd);
begin
{ Draw Buffer to the Control }
BitBlt(Msg.DC, 0, 0, ClientWidth, ClientHeight, FBuffer.Canvas.Handle, 0, 0, SRCCOPY);
Msg.Result := -1;
end;
procedure TERDPlayerButton.SettingsChanged(Sender: TObject);
begin
Redraw := True;
Invalidate;
end;
procedure TERDPlayerButton.OnBlinkingTimer(Sender: TObject);
begin
FBlinking := not FBlinking;
Invalidate;
end;
procedure TERDPlayerButton.Paint;
var
WorkRect : TRect;
procedure DrawBorder;
begin
with FButtonBuffer.Canvas do
begin
Brush.Style := bsSolid;
Brush.Color := Darken(Color, 50);
FillRect(WorkRect);
end;
end;
function StopPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddRectangle(TGPRect.Create(Rect));
Path.CloseFigure;
Result := Path;
end;
function PlayPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddPolygon([
TGPPoint.Create(Rect.Left, Rect.Top),
TGPPoint.Create(Rect.Left, Rect.Bottom),
TGPPoint.Create(Rect.Right, Rect.Top + Rect.Height div 2)
]);
Path.CloseFigure;
Result := Path;
end;
function PausePath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddRectangle(TGPRect.Create(Rect.Left, Rect.Top, (Rect.Width div 5) * 2, Rect.Height));
Path.AddRectangle(TGPRect.Create(Rect.Right - ((Rect.Width div 5) * 2), Rect.Top, (Rect.Width div 5) * 2, Rect.Height));
Path.CloseFigure;
Result := Path;
end;
function NextPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddPolygon([
TGPPoint.Create(Rect.Left, Rect.Top),
TGPPoint.Create(Rect.Left, Rect.Bottom),
TGPPoint.Create(Rect.Right - (Rect.Width div 4), Rect.Top + Rect.Height div 2)
]);
Path.AddRectangle(TGPRect.Create(Rect.Right - (Rect.Width div 4), Rect.Top, (Rect.Width div 4), Rect.Height));
Path.CloseFigure;
Result := Path;
end;
function PreviousPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddRectangle(TGPRect.Create(Rect.Left, Rect.Top, (Rect.Width div 4), Rect.Height));
Path.AddPolygon([
TGPPoint.Create(Rect.Left + (Rect.Width div 4), Rect.Top + Rect.Height div 2),
TGPPoint.Create(Rect.Right, Rect.Top),
TGPPoint.Create(Rect.Right, Rect.Bottom)
]);
Path.CloseFigure;
Result := Path;
end;
function EjectPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddPolygon([
TGPPoint.Create(Rect.Left + (Rect.Width div 2), Rect.Top),
TGPPoint.Create(Rect.Left, Rect.Top + ((Rect.Height div 5) * 3)),
TGPPoint.Create(Rect.Right, Rect.Top + ((Rect.Height div 5) * 3))
]);
Path.AddRectangle(TGPRect.Create(Rect.Left, Rect.Bottom - (Rect.Height div 5), Rect.Width, (Rect.Height div 5)));
Path.CloseFigure;
Result := Path;
end;
function RecordPath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddEllipse(TGPRect.Create(Rect));
Path.CloseFigure;
Result := Path;
end;
function VolumePath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
begin
Path := TGPGraphicsPath.Create;
Path.AddPolygon([
TGPPoint.Create(Rect.Left, Rect.Top + (Rect.Height div 4)),
TGPPoint.Create(Rect.Left + (Rect.Width div 4), Rect.Top + (Rect.Height div 4)),
TGPPoint.Create(Rect.Left + (Rect.Width div 2), Rect.Top),
TGPPoint.Create(Rect.Left + (Rect.Width div 2), Rect.Bottom),
TGPPoint.Create(Rect.Left + (Rect.Width div 4), Rect.Top + ((Rect.Height div 4) * 3)),
TGPPoint.Create(Rect.Left, Rect.Top + ((Rect.Height div 4) * 3))
]);
Path.AddArc(TGPRect.Create(
Rect.Left + (Rect.Width div 2),
Rect.Top,
(Rect.Width div 2),
Rect.Height), -90, 180);
Path.CloseFigure;
Result := Path;
end;
function MutePath(Rect: TRect) : IGPGraphicsPath;
var
Path : IGPGraphicsPath;
R : TRect;
begin
Path := TGPGraphicsPath.Create;
R := Rect;
InflateRect(R, -(Rect.Width div 8), 0);
Path.AddPolygon([
TGPPoint.Create(R.Left, R.Top + ((R.Height div 6) * 2)),
TGPPoint.Create(R.Left + (R.Width div 2), R.Top + ((R.Height div 6) * 2)),
TGPPoint.Create(R.Right, R.Top),
TGPPoint.Create(R.Right, R.Bottom),
TGPPoint.Create(R.Left + (R.Width div 2), R.Bottom - ((R.Height div 6) * 2)),
TGPPoint.Create(R.Left, R.Bottom - ((R.Height div 6) * 2))
]);
Path.CloseFigure;
Result := Path;
end;
procedure DrawButtonFace(var FGraphics : IGPGraphics; const ButtonState: TERDPlayerButtonState);
var
FaceBrush : IGPLinearGradientBrush;
IndicatorBrush : IGPLinearGradientBrush;
IndicatorRect : TRect;
XC, YC : Integer;
begin
{ Draw Button Face }
if LastButton then WorkRect.Right := WorkRect.Right -1;
InflateRect(WorkRect, -1, -1);
if not Enabled then
begin
FaceBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Brighten(Color, 10)),
TGPColor.CreateFromColorRef(Darken(Color, 5)),
90);
end else
case ButtonState of
{ Normal }
bsNormal : FaceBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Color),
TGPColor.CreateFromColorRef(Darken(Color, 30)),
90);
{ Hot }
bsHot : FaceBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Brighten(Color, 5)),
TGPColor.CreateFromColorRef(Darken(Color, 20)),
90);
{ Pressed }
bsPressed : FaceBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Darken(Color, 5)),
TGPColor.CreateFromColorRef(Color),
90);
{ Checked }
bsChecked : FaceBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(WorkRect),
TGPColor.CreateFromColorRef(Darken(Color, 5)),
TGPColor.CreateFromColorRef(Brighten(Color, 5)),
90);
end;
FGraphics.FillRectangle(FaceBrush, TGPRect.Create(WorkRect));
with FButtonBuffer.Canvas do
begin
IndicatorRect := ClientRect;
InflateRect(IndicatorRect, -1, -1);
Brush.Style := bsClear;
Pen.Width := 1;
Pen.Color := Brighten(Color, 10);
Rectangle(IndicatorRect);
end;
{ Draw Indicator }
XC := WorkRect.Left + Floor(WorkRect.Width / 2);
YC := WorkRect.Top + Floor(WorkRect.Height / 2);
IndicatorRect := Rect(
XC - Floor(Indicator.Width / 2),
YC - Floor(Indicator.Height / 2),
XC + Floor(Indicator.Width / 2),
YC + Floor(Indicator.Height / 2)
);
if not Enabled then
begin
IndicatorBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(IndicatorRect),
TGPColor.CreateFromColorRef(Darken(Indicator.OffColor, 30)),
TGPColor.CreateFromColorRef(Darken(Indicator.OffColor, 50)),
90);
end else
case Active of
{ Active }
True: IndicatorBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(IndicatorRect),
TGPColor.CreateFromColorRef(Brighten(Indicator.OnColor, 20)),
TGPColor.CreateFromColorRef(Darken(Indicator.OnColor, 20)),
90);
{ Not Active }
False: IndicatorBrush := TGPLinearGradientBrush.Create(
TGPRect.Create(IndicatorRect),
TGPColor.CreateFromColorRef(Indicator.OffColor),
TGPColor.CreateFromColorRef(Indicator.OffColor),
90);
end;
case Indicator.Shape of
bisStop : FGraphics.FillPath(IndicatorBrush, StopPath(IndicatorRect));
bisPlay : FGraphics.FillPath(IndicatorBrush, PlayPath(IndicatorRect));
bisPause : FGraphics.FillPath(IndicatorBrush, PausePath(IndicatorRect));
bisNext : FGraphics.FillPath(IndicatorBrush, NextPath(IndicatorRect));
bisPrevious : FGraphics.FillPath(IndicatorBrush, PreviousPath(IndicatorRect));
bisEject : FGraphics.FillPath(IndicatorBrush, EjectPath(IndicatorRect));
bisRecord : FGraphics.FillPath(IndicatorBrush, RecordPath(IndicatorRect));
bisVolume : FGraphics.FillPath(IndicatorBrush, VolumePath(IndicatorRect));
bisMute : FGraphics.FillPath(IndicatorBrush, MutePath(IndicatorRect));
end;
end;
var
FGraphics : IGPGraphics;
var
X, Y, W, H : Integer;
begin
if Redraw then
begin
Redraw := False;
{ Create toggle clientrect }
WorkRect := ClientRect;
{ Set Buffer size }
FButtonBuffer.SetSize(ClientWidth, ClientHeight);
FBuffer.SetSize(ClientWidth, ClientHeight);
{ Create GDI+ Graphic }
FGraphics := TGPGraphics.Create(FButtonBuffer.Canvas.Handle);
FGraphics.SmoothingMode := SmoothingModeAntiAlias;
FGraphics.InterpolationMode := InterpolationModeHighQualityBicubic;
{ Background }
DrawBorder;
DrawButtonFace(FGraphics, ButtonState);
end;
{ Draw the Button to the Buffer }
BitBlt(FBuffer.Canvas.Handle, 0, 0, ClientWidth, ClientHeight, FButtonBuffer.Canvas.Handle, 0, 0, SRCCOPY);
{ Draw a square in the button if blinking is on }
if FBlinking then
with FBuffer.Canvas do
begin
WorkRect := Rect(ClientRect.Left +1, ClientRect.Top +1, ClientRect.Right, ClientRect.Bottom);
InflateRect(WorkRect, -4, -4);
Pen.Color := Indicator.OnColor;
Pen.Width := 3;
Rectangle(WorkRect);
end;
{ Need a focus rect ? }
if DrawFocusRect and Focused then
with FBuffer.Canvas do
begin
WorkRect := ClientRect;
InflateRect(WorkRect, -3, -3);
DrawFocusRect(WorkRect);
end;
{ Now draw the Buffer to the components surface }
X := UpdateRect.Left;
Y := UpdateRect.Top;
W := UpdateRect.Right - UpdateRect.Left;
H := UpdateRect.Bottom - UpdateRect.Top;
if (W <> 0) and (H <> 0) then
{ Only update part - invalidated }
BitBlt(Canvas.Handle, X, Y, W, H, FBuffer.Canvas.Handle, X, Y, SRCCOPY)
else
{ Repaint the whole buffer to the surface }
BitBlt(Canvas.Handle, 0, 0, ClientWidth, ClientHeight, FBuffer.Canvas.Handle, X, Y, SRCCOPY);
inherited;
end;
procedure TERDPlayerButton.Resize;
begin
SettingsChanged(Self);
inherited;
end;
procedure TERDPlayerButton.CreateParams(var Params: TCreateParams);
begin
inherited CreateParams(Params);
with Params do
Style := Style and not (CS_HREDRAW or CS_VREDRAW);
end;
procedure TERDPlayerButton.WndProc(var Message: TMessage);
begin
inherited;
case Message.Msg of
// Capture Keystrokes
WM_GETDLGCODE:
Message.Result := Message.Result or DLGC_WANTARROWS or DLGC_WANTALLKEYS;
{ Enabled/Disabled - Redraw }
CM_ENABLEDCHANGED:
begin
if (not Enabled) and (ButtonState <> bsNormal) then FButtonState := bsNormal;
SettingsChanged(Self);
end;
{ Focus is lost }
WM_KILLFOCUS:
begin
Invalidate;
end;
{ Focus is set }
WM_SETFOCUS:
begin
Invalidate;
end;
{ The color changed }
CM_COLORCHANGED:
begin
SettingsChanged(Self);
end;
CM_MOUSEENTER:
if not (csDesigning in ComponentState) then
if (not FIsPressed) and (not Checked) and (ButtonState <> bsHot) then
begin
FButtonState := bsHot;
SettingsChanged(Self);
end;
CM_MOUSELEAVE:
if not (csDesigning in ComponentState) then
if (not FIsPressed) and (not Checked) and (ButtonState <> bsNormal) then
begin
FButtonState := bsNormal;
SettingsChanged(Self);
end;
end;
end;
procedure TERDPlayerButton.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if CanFocus and (not Focused) then SetFocus;
if (not Checked) and (not FIsPressed) then
begin
if Assigned(FOnClick) then FOnClick(Self);
FIsPressed := True;
FButtonState := bsPressed;
SettingsChanged(Self);
end;
inherited;
end;
procedure TERDPlayerButton.MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (FIsPressed) then FIsPressed := False;
if (not FIsPressed) and (not Checked) and (not PtInRect(ClientRect, Point(X, Y))) then
begin
FButtonState := bsNormal;
SettingsChanged(Self);
end;
if (not FIsPressed) and (not Checked) and PtInRect(ClientRect, Point(X, Y)) and (ButtonState <> bsHot) then
begin
FButtonState := bsHot;
SettingsChanged(Self);
end;
inherited;
end;
procedure TERDPlayerButton.KeyDown(var Key: Word; Shift: TShiftState);
begin
if (not Checked) and (not FIsPressed) then
if (Key = VK_RETURN) or (Key = VK_SPACE) then
begin
if Assigned(FOnClick) then FOnClick(Self);
FIsPressed := True;
FButtonState := bsPressed;
SettingsChanged(Self);
end;
inherited;
end;
procedure TERDPlayerButton.KeyUp(var Key: Word; Shift: TShiftState);
begin
if (FIsPressed) then FIsPressed := False;
if (Key = VK_RETURN) or (Key = VK_SPACE) then
begin
if Assigned(FOnClick) then FOnClick(Self);
FButtonState := bsNormal;
SettingsChanged(Self);
end;
inherited;
end;
end.