/
unitframesoundvolume.pas
74 lines (58 loc) · 1.88 KB
/
unitframesoundvolume.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
unit UnitFrameSoundVolume;
// Copyright 2022-2024 Zoran Vučenović
// SPDX-License-Identifier: Apache-2.0
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, ComCtrls, Types, Math;
type
TFrameSoundVolume = class(TFrame)
TrackBar1: TTrackBar;
procedure TrackBar1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
private
function GetLevel: Integer;
function GetVerticalOrientation: Boolean;
procedure SetLevel(AValue: Integer);
procedure SetOnTrackBarPositionChg(AValue: TNotifyEvent);
procedure SetVerticalOrientation(AValue: Boolean);
public
property OnTrackBarPositionChg: TNotifyEvent write SetOnTrackBarPositionChg;
property Level: Integer read GetLevel write SetLevel;
property VerticalOrientation: Boolean read GetVerticalOrientation write SetVerticalOrientation;
end;
implementation
{$R *.lfm}
{ TFrameSoundVolume }
procedure TFrameSoundVolume.TrackBar1MouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
begin
TrackBar1.Position := TrackBar1.Position + 2 * Sign(WheelDelta);
Handled := True;
end;
function TFrameSoundVolume.GetLevel: Integer;
begin
Result := (TrackBar1.Position and 31) * 4;
Result := Result + (Result shr 5);
end;
function TFrameSoundVolume.GetVerticalOrientation: Boolean;
begin
Result := TrackBar1.Orientation = trVertical;
end;
procedure TFrameSoundVolume.SetLevel(AValue: Integer);
begin
TrackBar1.Position := AValue div 4;
end;
procedure TFrameSoundVolume.SetOnTrackBarPositionChg(AValue: TNotifyEvent);
begin
TrackBar1.OnChange := AValue;
end;
procedure TFrameSoundVolume.SetVerticalOrientation(AValue: Boolean);
begin
if AValue then
TrackBar1.Orientation := trVertical
else
TrackBar1.Orientation := trHorizontal;
TrackBar1.Reversed := AValue;
end;
end.