function ValueFromAngle(Angle: single): single;
var
RelativeAngle: single;
begin
RelativeAngle := Angle - KNOB_OFFSET_ANGLE;
if RelativeAngle < 0 then
RelativeAngle := RelativeAngle + 2 * pi;
Result := (RelativeAngle) / KNOB_ANGLE_RANGE;
if Result > 1.0 then
if RelativeAngle < 0.5 * KNOB_ANGLE_RANGE + pi then
Result := 1
else
Result := 0
end;
procedure UpdateFramePosition(WinHandle: HWND);
var
Img, imgW, imgH: cardinal;
begin
//with SkinEngine do
//begin
Img := SkinEngine.GetProperty(WinHandle, KNOB_IMAGE);
SkinEngine.GetImageSize(Img, imgW, imgH);
XOffset := FFrame mod tmax;
YOffset := FFrame div tmax;
dXOffset := integer(imgW) div tmax;
dYOffset := 0;
//end;
end;
procedure SetKnobLocation(WinHandle: HWND; x, y: single);
var
rc: TRect;
Img, imgW, imgH: cardinal;
begin
//with SkinEngine do
//begin
GetClientRect(WinHandle, rc);
Img := SkinEngine.GetProperty(WinHandle, KNOB_IMAGE);
SkinEngine.GetImageSize(Img, imgW, imgH);
tMin := SkinEngine.GetProperty(WinHandle, KNOB_MINVAL);
tMax := SkinEngine.GetProperty(WinHandle, KNOB_MAXVAL);
Angle := arctan2(y - rc.Bottom div 2, x - rc.Right div 2);
Value := ValueFromAngle(Angle) * tMax ;
FFrame := round(Value) mod tMax;
UpdateFramePosition(WinHandle);
SkinEngine.SetProperty(WinHandle, KNOB_VALUE, round(Value));
if Value <> SkinEngine.GetProperty(WinHandle, KNOB_WAS_VALUE) then
begin
SkinEngine.FUpdateWindow(WinHandle, False);
SetToolTipText(WinHandle, PWideChar(IntToStr(round(Value))));
end;
SkinEngine.SetProperty(WinHandle, KNOB_WAS_VALUE, round(Value));
//end;
end;
// Berechne die X, Y koordinaten abhängig von der aktuellen tVal
procedure GetKnobLocation(WinHandle: HWND);
var
Img, imgW, imgH: cardinal;
begin
//with SkinEngine do
//begin
Img := SkinEngine.GetProperty(WinHandle, KNOB_IMAGE);
SkinEngine.GetImageSize(Img, imgW, imgH);
tMax := SkinEngine.GetProperty(WinHandle, KNOB_MAXVAL);
Value := SkinEngine.GetProperty(WinHandle, KNOB_VALUE);
if Value <= (tMax - 1) then
begin
FFrame := round(Value) mod tMax;
UpdateFramePosition(WinHandle);
end else
begin
FFrame := round(Value - 1) mod tMax;
UpdateFramePosition(WinHandle);
end;
//end;
end;
// Default Value setzen
procedure SetKnobDefaultValue(WinHandle: HWND; tVal: Integer);
begin
//with SkinEngine do
//begin
tMin := SkinEngine.GetProperty(WinHandle, KNOB_MINVAL);
tMax := SkinEngine.GetProperty(WinHandle, KNOB_MAXVAL);
if tMin > tMax then
SWAP(tMin, tMax);
tVal := MIN(MAX(tMin, tVAL), tMax);
if tVal <> SkinEngine.GetProperty(WinHandle, KNOB_VALUE) then
begin
SkinEngine.SetProperty(WinHandle, KNOB_VALUE, tVal);
SkinEngine.SetProperty(WinHandle, KNOB_WAS_VALUE, tVal);
SkinEngine.FUpdateWindow(WinHandle, False);
end;
//end;
end;