소스 검색

Added Triangle style pointer, updated test application and versions.

sganz 11 달 전
부모
커밋
b315b82a52
4개의 변경된 파일160개의 추가작업 그리고 64개의 파일을 삭제
  1. 107 59
      supergauge.pas
  2. 1 1
      supergaugecommon.pas
  3. 44 1
      test/test_supergauge/sgtest.lfm
  4. 8 3
      test/test_supergauge/sgtest.pas

+ 107 - 59
supergauge.pas

@@ -30,7 +30,7 @@ uses
 const
   INTERNAL_GAUGE_MIN_VALUE = 0;   // internal lowest value
   INTERNAL_GAUGE_MAX_VALUE = 270; // internal highest value
-  VERSIONSTR = '1.00';            // SG version, Should ALWAYS show as a delta when merging!
+  VERSIONSTR = '1.01';            // SG version, Should ALWAYS show as a delta when merging!
 
 type
 
@@ -1456,7 +1456,8 @@ var
   PointerLength: single;
   startAngle, endAngle: single;
   bandRadius: single;
-
+  vecLen: single;
+  A, B, U, V: TPointF;
 begin
   // Note : Min and max values are the GAUGE Settings, not the Scales,
   //        the scale display is independant of the value of the gauge to
@@ -1488,77 +1489,124 @@ begin
 
   // draw the arc style of pointer
 
-  if PointerSettings.Style = psArc then
+  if (PointerSettings.Style = psLine) or  (PointerSettings.Style = psLineExt) then
     begin
-      // drawn arc pointer, ensure not negative or crash, zero no need to draw
-
-      if FValue <= 0.0 then
-        Exit;
-
-       BandRadius := PointerLength - PointerSettings.Thickness div 2;    // adjust for band thickness so end of pointer is top
-
-       // Start = 225 degree is 0 on gague scale (Not the angle), and -45 degree is 100 on scale
-       // 270, down (gauge angle 0)180 flat, increase moves towards 0 decrease towards 100
-       // 0 is flat line, right most end. Increase goes backwards towards 0, -45 is 100 percent on scale
-
-       startAngle := 225 * PI / 180;  // start at 0 on the gauge
-       endAngle := startAngle - FValue * PI / 180;
-
-       FGaugeBitMap.LineCap := pecFlat; // caps should be flat, rounded does not align to scales well
-       FGaugeBitMap.Arc(
-                        Origin.CenterPoint.x, Origin.CenterPoint.y,
-                        BandRadius + 0.5, BandRadius + 0.5, // push down a bit
-                        startAngle, endAngle,
-                        PointerSettings.Color,
-                        PointerSettings.Thickness,
-                        false,
-                        BGRA(0,0,0,0) // last param is alpha, so no interior color, inner routings ONLY draw the arc, no fill
-                   );
+      // if we are need to draw the extension behind the cap, we can
+      // recalc the ending point to just do one line draw instead of
+      // 2 discrete lines from the center. That is easier, but slower
+      // If extension len is 0, skip as will show a partial pixel
+
+      FGaugeBitMap.LineCap := pecRound; // caps should be round for line type pointers
+
+      if (PointerSettings.Style = psLineExt) and (PointerSettings.ExtensionLength > 0) then
+        begin
+          // The extension is always pixels visable from the center or edge of the
+          // cap, fix as needed. Makes nice for the user.
+
+          if PointerCapSettings.CapStyle = csNone then
+            extLen := PointerSettings.ExtensionLength
+          else
+            extLen := PointerSettings.ExtensionLength + PointerCapSettings.Radius;
+
+          // compute end point of pointer if an extension
+
+          commonSubEx := (-225 + FValue) * Pi / 180;
+          x1 := Origin.CenterPoint.x - Round(extLen * cos(commonSubEx));
+          y1 := Origin.CenterPoint.y - Round(extLen * sin(commonSubEx));
+
+        end
+          else
+            begin
+              // no extension or extension length is 0, just draw to center
+
+              x1 := Origin.CenterPoint.x;
+              y1 := Origin.CenterPoint.y;
+            end;
+
+      // computer start point of pointer
+
+      commonSubEx := (-45 + FValue) * Pi / 180;
+      x := Origin.CenterPoint.x - Round(PointerLength * cos(commonSubEx));
+      y := Origin.CenterPoint.y - Round(PointerLength * sin(commonSubEx));
+
+      // finally draw it
+
+      FGaugeBitMap.DrawLineAntialias(x, y, x1, y1, PointerSettings.Color, PointerSettings.Thickness)
     end
       else
-      begin
-        // if we are need to draw the extension behind the cap, we can
-        // recalc the ending point to just do one line draw instead of
-        // 2 discrete lines from the center. That is easier, but slower
-        // If extension len is 0, skip as will show a partial pixel
+        if PointerSettings.Style = psTriangle then
+          begin
+              // Draw a Triangle style pointer
 
-        FGaugeBitMap.LineCap := pecRound; // caps should be round for line type pointers
+              // Draw from center point out
 
-        if (PointerSettings.Style = psLineExt) and (PointerSettings.ExtensionLength > 0) then
-          begin
-            // The extension is always pixels visable from the center or edge of the
-            // cap, fix as needed. Makes nice for the user.
+              commonSubEx := (-45 + FValue) * Pi / 180;
+              x := Origin.CenterPoint.x;
+              y := Origin.CenterPoint.y;
+              A := PointF(x, y);
 
-            if PointerCapSettings.CapStyle = csNone then
-              extLen := PointerSettings.ExtensionLength
-            else
-              extLen := PointerSettings.ExtensionLength + PointerCapSettings.Radius;
+              // Calculate draw to point top
 
-            // compute end point of pointer if an extension
+              x1 := Origin.CenterPoint.x - Round(PointerSettings.Length * cos(commonSubEx));
+              y1 := Origin.CenterPoint.y - Round(PointerSettings.Length * sin(commonSubEx));
+              B := PointF(x1, y1);
 
-            commonSubEx := (-225 + FValue) * Pi / 180;
-            x1 := Origin.CenterPoint.x - Round(extLen * cos(commonSubEx));
-            y1 := Origin.CenterPoint.y - Round(extLen * sin(commonSubEx));
+              // set line cap just in case
 
-          end
-            else
-              begin
-                // no extension or extension length is 0, just draw to center
+              FMarkerBitmap.LineCap := pecRound; // Ensure Round Cap
 
-                x1 := Origin.CenterPoint.x;
-                y1 := Origin.CenterPoint.y;
-              end;
+              // This is the vector that runs from outer to inner
 
-        // computer start point of pointer
+              U := B - A;
 
-        commonSubEx := (-45 + FValue) * Pi / 180;
-        x := Origin.CenterPoint.x - Round(PointerLength * cos(commonSubEx));
-        y := Origin.CenterPoint.y - Round(PointerLength * sin(commonSubEx));
+              // build the perpendicular vector
+              // (clockwise in screen coordinates while the opposite would be counter clockwise)
 
-        // finally draw it
+              V := PointF(-U.y, U.x);
 
-        FGaugeBitMap.DrawLineAntialias(x, y, x1, y1, PointerSettings.Color, PointerSettings.Thickness)
-      end;
+              // scale it to set the new segment length
+
+              vecLen := VectLen(V);
+
+              // catch odd case of zero len vector, do nothing
+
+              if vecLen = 0.0 then
+                Exit;
+
+              V := V * (PointerSettings.Thickness / vecLen);
+
+              // draw a full triangle pointer
+
+              FGaugeBitMap.FillPolyAntialias([B, A + V, A - V], PointerSettings.Color);
+          end
+            else
+              if PointerSettings.Style = psArc then
+                begin
+                  // drawn arc pointer, ensure not negative or crash, zero no need to draw
+
+                  if FValue <= 0.0 then
+                    Exit;
+
+                   BandRadius := PointerLength - PointerSettings.Thickness div 2;    // adjust for band thickness so end of pointer is top
+
+                   // Start = 225 degree is 0 on gague scale (Not the angle), and -45 degree is 100 on scale
+                   // 270, down (gauge angle 0)180 flat, increase moves towards 0 decrease towards 100
+                   // 0 is flat line, right most end. Increase goes backwards towards 0, -45 is 100 percent on scale
+
+                   startAngle := 225 * PI / 180;  // start at 0 on the gauge
+                   endAngle := startAngle - FValue * PI / 180;
+
+                   FGaugeBitMap.LineCap := pecFlat; // caps should be flat, rounded does not align to scales well
+                   FGaugeBitMap.Arc(
+                                    Origin.CenterPoint.x, Origin.CenterPoint.y,
+                                    BandRadius + 0.5, BandRadius + 0.5, // push down a bit
+                                    startAngle, endAngle,
+                                    PointerSettings.Color,
+                                    PointerSettings.Thickness,
+                                    false,
+                                    BGRA(0,0,0,0) // last param is alpha, so no interior color, inner routings ONLY draw the arc, no fill
+                               );
+                end;
 end;
 
 procedure TSGCustomSuperGauge.DrawPointerCap;

+ 1 - 1
supergaugecommon.pas

@@ -29,7 +29,7 @@ uses
 
 type
   TSGFillStyle = (fsNone, fsGradient{, fsTexture}); // Add more if needed here
-  TSGPointerStyle = (psLine, psLineExt, psArc {, nsTriangle, nsTriangleExt}); // Todo : Add others at some point
+  TSGPointerStyle = (psLine, psLineExt, psArc , psTriangle {, psTriangleLine, psTriangleLineExt}); // Todo : Add others at some point
   TSGLEDStyle = (lsNone, lsFlat, lsShaded);
   TSGLEDShape = (lshRound, lshSquare, lshTriangle, lshDownTriangle);
   TSGPointerCapPosition = (cpUnder, cpOver);

+ 44 - 1
test/test_supergauge/sgtest.lfm

@@ -1199,6 +1199,7 @@ object SGTestFrm: TSGTestFrm
           'psLine'
           'psLineExt'
           'psArc'
+          'psTriangle'
         )
         ParentShowHint = False
         ShowHint = True
@@ -1212,6 +1213,23 @@ object SGTestFrm: TSGTestFrm
         Width = 37
         Caption = 'Style'
       end
+      object PointerMemo: TMemo
+        Left = 9
+        Height = 254
+        Top = 248
+        Width = 463
+        Lines.Strings = (
+          'Several types of pointers are available.'
+          ''
+          'The Extension line is the ''Tail'' of the pointer and only'
+          'used for psLineExt type. Extention length has no effect'
+          'on other pointer types'
+          ''
+          'Don''t forget to use the PointerCap settings to draw the'
+          'pointer cap over or under the pointer, or not at all.'
+        )
+        TabOrder = 5
+      end
     end
     object CapTab: TTabSheet
       Caption = 'Cap'
@@ -1378,6 +1396,29 @@ object SGTestFrm: TSGTestFrm
         NullValue = 0
         Value = 0
       end
+      object CapMemo: TMemo
+        Left = 24
+        Height = 400
+        Top = 328
+        Width = 545
+        Lines.Strings = (
+          'Various settings for the pointer cap. '
+          ''
+          'For some pointers the cap looks better drawn over the '
+          'pointer, and some the other way around.'
+          ''
+          'For thicker pointers and the triangle shaped pointer, '
+          'setting the Edge Color to match the Fill Color can make'
+          'it look nicer.'
+          ''
+          'The Curve Exponent is for the Phong Shader, and can'
+          'give some nice results. This only applies to the Phong '
+          'shader, values less that 1.0 give good results.'
+          ''
+          'Again, play and experiment!'
+        )
+        TabOrder = 7
+      end
     end
     object TextTab: TTabSheet
       Caption = 'Text'
@@ -4240,8 +4281,10 @@ object SGTestFrm: TSGTestFrm
       Left = 232
       Height = 25
       Top = 32
-      Width = 84
+      Width = 92
       Caption = 'KnobValue'
+      Font.Style = [fsBold]
+      ParentFont = False
     end
     object Label6: TLabel
       Left = 168

+ 8 - 3
test/test_supergauge/sgtest.pas

@@ -25,7 +25,7 @@ uses
   BGRAShape, BGRAImageList, SuperGaugeCommon, SuperGauge,about;
 
 const
-  VERSIONSTR = '1.00';            // SG TEST version, Should ALWAYS show as a delta when merging!
+  VERSIONSTR = '1.01';            // SG TEST version, Should ALWAYS show as a delta when merging!
 
 type
   { TSGTestFrm }
@@ -33,6 +33,8 @@ type
   TSGTestFrm = class(TForm)
     BGRAKnob: TBGRAKnob;
     DisableAllMarkersBtn: TBitBtn;
+    CapMemo: TMemo;
+    PointerMemo: TMemo;
     SuperGauge: TSuperGauge;
     EnableAllMarkersBtn: TBitBtn;
     MainMenu1: TMainMenu;
@@ -1054,7 +1056,6 @@ begin
   ScaleMainTickThicknessSpe.Value := SuperGauge.ScaleSettings.ThicknessMainTick;
   ScaleSubTickThicknessSpe.Value := SuperGauge.ScaleSettings.ThicknessSubTick;
   ScaleTickArcStyleCb.ItemIndex := ord(SuperGauge.ScaleSettings.TickArcStyle);
-
 end;
 
 procedure TSGTestFrm.UpdateFaceStats;
@@ -2241,7 +2242,7 @@ end;
 procedure TSGTestFrm.PointerStyleCbChange(Sender: TObject);
 begin
   // Set the Pointer Style
-  // psLine = 0, psLineExt = 1, psArc = 2
+  // psLine = 0, psLineExt = 1, psArc = 2, 3 = psTriangle
 
   case PointerStyleCb.ItemIndex of
     0 : {psLine}
@@ -2256,6 +2257,10 @@ begin
         begin
           SuperGauge.PointerSettings.Style := psArc;
         end;
+    3: {psTriangle}
+        begin
+          SuperGauge.PointerSettings.Style := psTriangle;
+        end;
 
   else
     // Unknown type, warn somewhere...