Browse Source

pull request #175: restore some positions

Juliette ELSASS 1 year ago
parent
commit
c16a3236cb
1 changed files with 67 additions and 76 deletions
  1. 67 76
      bgraknob.pas

+ 67 - 76
bgraknob.pas

@@ -127,8 +127,7 @@ type
     property PositionMargin: single read FPositionMargin write SetPositionMargin;
     property PositionMargin: single read FPositionMargin write SetPositionMargin;
     property PositionType: TBGRAKnobPositionType
     property PositionType: TBGRAKnobPositionType
       read FPositionType write SetPositionType;
       read FPositionType write SetPositionType;
-    property UsePhongLighting: boolean read FUsePhongLighting
-      write SetUsePhongLighting;
+    property UsePhongLighting: boolean read FUsePhongLighting write SetUsePhongLighting;
     property MinValue: single read FMinValue write SetMinValue nodefault;
     property MinValue: single read FMinValue write SetMinValue nodefault;
     property MaxValue: single read FMaxValue write SetMaxValue nodefault;
     property MaxValue: single read FMaxValue write SetMaxValue nodefault;
     property StartFromBottom: boolean read FStartFromBottom
     property StartFromBottom: boolean read FStartFromBottom
@@ -155,9 +154,7 @@ type
     property OnMouseLeave;
     property OnMouseLeave;
   end;
   end;
 
 
-  {$IFDEF FPC}
-        procedure Register;
-  {$ENDIF}
+{$IFDEF FPC}procedure Register;{$ENDIF}
 
 
 const
 const
   WHEELSPEEDFACTOR = 20.0;  // used to calculate mouse wheel speed
   WHEELSPEEDFACTOR = 20.0;  // used to calculate mouse wheel speed
@@ -168,16 +165,16 @@ implementation
 
 
 uses Math;
 uses Math;
 
 
-  {$IFDEF FPC}
+{$IFDEF FPC}
 procedure Register;
 procedure Register;
 begin
 begin
   RegisterComponents('BGRA Controls', [TBGRAKnob]);
   RegisterComponents('BGRA Controls', [TBGRAKnob]);
 end;
 end;
-  {$ENDIF}
+{$ENDIF}
 
 
-  { TBGRAKnob }
+{ TBGRAKnob }
 
 
-  // Override the base class which has a rectangular dimension, odd for a knob
+// Override the base class which has a rectangular dimension, odd for a knob
 class function TBGRAKnob.GetControlClassDefaultSize: TSize;
 class function TBGRAKnob.GetControlClassDefaultSize: TSize;
 begin
 begin
   Result.CX := 50;
   Result.CX := 50;
@@ -228,13 +225,7 @@ begin
         v.y := v.y / (ty / 2 + 1);
         v.y := v.y / (ty / 2 + 1);
 
 
         //compute squared distance with scalar product
         //compute squared distance with scalar product
-        d2 := v
-          {$if FPC_FULLVERSION < 030301}
-          *
-          {$ELSE}
- **
-          {$ENDIF}
-          v;
+        d2 := v {$if FPC_FULLVERSION < 030301}*{$ELSE}**{$ENDIF} v;
 
 
         //interpolate as quadratic curve and apply power function
         //interpolate as quadratic curve and apply power function
         if d2 > 1 then
         if d2 > 1 then
@@ -268,6 +259,23 @@ begin
   Result := round(FPhong.LightSourceIntensity);
   Result := round(FPhong.LightSourceIntensity);
 end;
 end;
 
 
+function TBGRAKnob.GetValue: single;
+begin
+  // Maintains the correct value range based on knobtype, result in terms of FMinValue and MaxValue
+
+  Result := RemapRange(AngularPosToDeg(FAngularPos), FStartAngle,
+    FEndAngle, FMinValue, FMaxValue); // user range
+
+  // Check to Reverse the scale and fix value
+
+  if FReverseScale then
+    Result := FMaxValue + FMinValue - Result;
+
+  if FKnobType = ktSector then
+    Result := CalcSectorFromValue(Result);
+
+end;
+
 function TBGRAKnob.AngularPosToDeg(RadPos: single): single;
 function TBGRAKnob.AngularPosToDeg(RadPos: single): single;
 begin
 begin
   // helper to convert AnglePos in radians to degrees, wraps as needed
   // helper to convert AnglePos in radians to degrees, wraps as needed
@@ -350,66 +358,6 @@ begin
     FAngularPos := DegPosToAngular(LValue); // Back to Radians
     FAngularPos := DegPosToAngular(LValue); // Back to Radians
 end;
 end;
 
 
-function TBGRAKnob.GetValue: single;
-begin
-  // Maintains the correct value range based on knobtype, result in terms of FMinValue and MaxValue
-
-  Result := RemapRange(AngularPosToDeg(FAngularPos), FStartAngle,
-    FEndAngle, FMinValue, FMaxValue); // user range
-
-  // Check to Reverse the scale and fix value
-
-  if FReverseScale then
-    Result := FMaxValue + FMinValue - Result;
-
-  if FKnobType = ktSector then
-    Result := CalcSectorFromValue(Result);
-
-end;
-
-procedure TBGRAKnob.SetValue(AValue: single);
-var
-  NewAngularPos: single;
-begin
-  // AValue in the range of FStartAngle and FEndAngles after the mapping
-
-  if FKnobType = ktSector then
-  begin
-    // Range check for ktSector mode
-
-    if (AValue < 0) then
-      AValue := 0;
-
-    if (AValue > 255) then
-      AValue := 255;
-
-    AValue := CalcValueFromSector(Round(AValue));    // Round to sector
-  end;
-
-  AValue := RemapRange(AValue, FMinValue, FMaxValue, FStartAngle, FEndAngle);
-
-  // Reverse the scale if needed
-
-  if FReverseScale then
-    AValue := FEndAngle + FStartAngle - AValue;
-
-  ValueCorrection(AValue);
-
-  NewAngularPos := 3 * Pi / 2 - AValue * Pi / 180;
-
-  if NewAngularPos > Pi then
-    NewAngularPos := NewAngularPos - (2 * Pi);
-
-  if NewAngularPos < -Pi then
-    NewAngularPos := NewAngularPos + (2 * Pi);
-
-  if NewAngularPos <> FAngularPos then
-  begin
-    FAngularPos := NewAngularPos;
-    Invalidate;
-  end;
-end;
-
 function TBGRAKnob.RemapRange(OldValue: single;
 function TBGRAKnob.RemapRange(OldValue: single;
   OldMin, OldMax, NewMin, NewMax: single): single;
   OldMin, OldMax, NewMin, NewMax: single): single;
 begin
 begin
@@ -532,6 +480,49 @@ begin
   Invalidate;
   Invalidate;
 end;
 end;
 
 
+procedure TBGRAKnob.SetValue(AValue: single);
+var
+  NewAngularPos: single;
+begin
+  // AValue in the range of FStartAngle and FEndAngles after the mapping
+
+  if FKnobType = ktSector then
+  begin
+    // Range check for ktSector mode
+
+    if (AValue < 0) then
+      AValue := 0;
+
+    if (AValue > 255) then
+      AValue := 255;
+
+    AValue := CalcValueFromSector(Round(AValue));    // Round to sector
+  end;
+
+  AValue := RemapRange(AValue, FMinValue, FMaxValue, FStartAngle, FEndAngle);
+
+  // Reverse the scale if needed
+
+  if FReverseScale then
+    AValue := FEndAngle + FStartAngle - AValue;
+
+  ValueCorrection(AValue);
+
+  NewAngularPos := 3 * Pi / 2 - AValue * Pi / 180;
+
+  if NewAngularPos > Pi then
+    NewAngularPos := NewAngularPos - (2 * Pi);
+
+  if NewAngularPos < -Pi then
+    NewAngularPos := NewAngularPos + (2 * Pi);
+
+  if NewAngularPos <> FAngularPos then
+  begin
+    FAngularPos := NewAngularPos;
+    Invalidate;
+  end;
+end;
+
 procedure TBGRAKnob.SetEndAngle(AValue: single);
 procedure TBGRAKnob.SetEndAngle(AValue: single);
 var
 var
   oldValue: single;
   oldValue: single;