View Issue Details

IDProjectCategoryView StatusLast Update
0005326JEDI VCL03 Donationspublic2012-02-29 16:53
ReportergwarkAssigned ToAHUser 
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Product Version3.39 
Target VersionFixed in Version3.45 
Summary0005326: Inverted gradient progressbar feature
DescriptionI'd like to contribute a new "inverted" property to the JvGradientProgressBar.
See the attached file.
I hope one can review and maby commit it to the trunk. Thanks.
TagsNo tags attached.

Activities

2010-09-08 16:59

 

JvProgressBar.pas (20,590 bytes)

2010-09-10 22:24

 

Inverted_JvGradientProgressBar.patch (5,636 bytes)
Index: jvcl/run/JvProgressBar.pas
===================================================================
--- jvcl/run/JvProgressBar.pas	(revision 12842)
+++ jvcl/run/JvProgressBar.pas	(working copy)
@@ -14,7 +14,8 @@
 Portions created by S�bastien Buysse are Copyright (C) 2001 S�bastien Buysse.
 All Rights Reserved.
 
-Contributor(s): Michael Beck [mbeck att bigfoot dott com].
+Contributor(s): Michael Beck [mbeck att bigfoot dott com]
+								Michiel Koot [makoot att gmx dott net] (inverted property)
 
 You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
 located at http://jvcl.delphi-jedi.org
@@ -43,6 +44,7 @@
   private
     FBlockSize: Integer;
     FSmooth: Boolean;
+    FInverted: Boolean;
     FPosition: Integer;
     FMin: Integer;
     FMax: Integer;
@@ -55,6 +57,7 @@
     procedure SetOrientation(Value: TProgressBarOrientation);
     procedure SetPosition(Value: Integer);
     procedure SetSmooth(const Value: Boolean);
+    procedure SetInverted(const Value: Boolean);
     procedure SetBlockSize(const Value: Integer);
     procedure SetBarColor(const Value: TColor);
     procedure SetSteps(const Value: Integer);
@@ -84,6 +87,7 @@
     property Orientation: TProgressBarOrientation read FOrientation write SetOrientation default pbHorizontal;
     property Position: Integer read FPosition write SetPosition default 0;
     property Smooth: Boolean read FSmooth write SetSmooth default False;
+    property Inverted: Boolean read FInverted write SetInverted default False; // Michiel Koot: enabling inverted drawing behaviour.
     property OnChange: TNotifyEvent read FOnChange write FOnChange;
   published
     property Width default 150;
@@ -161,6 +165,7 @@
     property Orientation;
     property Position;
     property Smooth;
+    property Inverted; // MK
 
     property Align;
     property Anchors;
@@ -331,6 +336,15 @@
   end;
 end;
 
+procedure TJvBaseProgressBar.SetInverted(const Value: Boolean);
+begin
+  if FInverted <> Value then
+  begin
+    FInverted := Value;
+    Invalidate;
+  end;
+end;
+
 procedure TJvBaseProgressBar.DrawBar(ACanvas: TCanvas; BarSize: Integer);
 var
   R: TRect;
@@ -599,14 +613,20 @@
   InflateRect(R, -1, -1);
   if Orientation = pbHorizontal then
   begin
-    R.Right := BarSize;
+    if FInverted = false then
+			R.Right := BarSize
+		else
+			R.Left := R.Right - BarSize;				
     if R.Right > ClientWidth - 2 then
       R.Right := ClientWidth - 2;
     GradientFillRect(ACanvas, R, BarColorFrom, BarColorTo, fdLeftToRight, 255);
   end
   else
   begin
-    R.Top := R.Bottom - BarSize;
+    if FInverted = false then
+      R.Top := R.Bottom - BarSize
+    else
+  		R.Bottom := R.Top + BarSize;
     if R.Top < 2 then
       R.Top := 2;
     GradientFillRect(ACanvas, R, BarColorFrom, BarColorTo, fdBottomToTop, 255);
@@ -622,33 +642,71 @@
     if Orientation = pbHorizontal then
     begin
       R := ClientRect;
-      InflateRect(R, -2, -2);
-      R.Right := R.Left + Round(LBlockSize);
-      while R.Left <= BarSize do
-      begin
-        ACanvas.MoveTo(R.Left, R.Top);
-        ACanvas.LineTo(R.Left, R.Bottom);
-        Inc(I);
-        R := ClientRect;
-        InflateRect(R, -2, -2);
-        R.Right := R.Left + Round(LBlockSize);
-        OffsetRect(R, Round(I * LBlockSize), 0);
-      end;
+      if FInverted = false then
+			begin
+				InflateRect(R, -2, -2);
+				R.Right := R.Left + Round(LBlockSize);
+				while R.Left <= BarSize do
+				begin
+					ACanvas.MoveTo(R.Left, R.Top);
+					ACanvas.LineTo(R.Left, R.Bottom);
+					Inc(I);
+					R := ClientRect;
+					InflateRect(R, -2, -2);
+					R.Right := R.Left + Round(LBlockSize);
+					OffsetRect(R, Round(I * LBlockSize), 0);
+				end;
+			end
+			else
+			// Inverted horizontal
+			begin
+        InflateRect(R, 2, 2);
+        R.Left := R.Right - Round(LBlockSize);
+        while (BarSize <> 0) and (R.Left >= (GetMaxBarSize - BarSize)) do
+        begin
+          ACanvas.MoveTo(R.Right, R.Top);
+          ACanvas.LineTo(R.Right, R.Bottom);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, 2, 2);
+          R.Left := R.Right - Round(LBlockSize);
+          OffsetRect(R, -Round(I * LBlockSize), 0);
+        end;
+      end;	
     end
     else
     begin
       R := ClientRect;
-      InflateRect(R, -2, -2);
-      R.Top := R.Bottom - Round(LBlockSize);
-      while R.Bottom >= GetMaxBarSize - BarSize do
+      if FInverted = false then
       begin
-        ACanvas.MoveTo(R.Left, R.Bottom);
-        ACanvas.LineTo(R.Right, R.Bottom);
-        Inc(I);
-        R := ClientRect;
         InflateRect(R, -2, -2);
         R.Top := R.Bottom - Round(LBlockSize);
-        OffsetRect(R, 0, -Round(I * LBlockSize));
+        while R.Bottom >= GetMaxBarSize - BarSize do
+        begin
+          ACanvas.MoveTo(R.Left, R.Bottom);
+          ACanvas.LineTo(R.Right, R.Bottom);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, -2, -2);
+          R.Top := R.Bottom - Round(LBlockSize);
+          OffsetRect(R, 0, -Round(I * LBlockSize));
+        end;
+      end
+      else
+			// Inverted vertical
+      begin
+        InflateRect(R, 2, 2);
+        R.Bottom := R.Top + Round(LBlockSize);
+        while (BarSize <> 0) and (R.Top <= BarSize) do
+        begin
+          ACanvas.MoveTo(R.Left, R.Top);
+          ACanvas.LineTo(R.Right, R.Top);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, 2, 2);
+          R.Bottom := R.Top + Round(LBlockSize);
+          OffsetRect(R, 0, Round(I * LBlockSize));
+        end;
       end;
     end;
   end;

2010-09-10 22:25

 

gwark

2010-09-10 22:27

reporter   ~0017662

I've added a patch, patched against https://jcl.svn.sourceforge.net:443/svnroot/jvcl/trunk revision 12842 (current latest).
And preview jpg.

2010-09-10 22:49

 

JvGradientProgressBar_v2.patch (6,420 bytes)
Index: jvcl/run/JvProgressBar.pas
===================================================================
--- jvcl/run/JvProgressBar.pas	(revision 12842)
+++ jvcl/run/JvProgressBar.pas	(working copy)
@@ -14,7 +14,8 @@
 Portions created by S�bastien Buysse are Copyright (C) 2001 S�bastien Buysse.
 All Rights Reserved.
 
-Contributor(s): Michael Beck [mbeck att bigfoot dott com].
+Contributor(s): Michael Beck [mbeck att bigfoot dott com]
+								Michiel Koot [makoot att gmx dott net] (inverted property)
 
 You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
 located at http://jvcl.delphi-jedi.org
@@ -42,7 +43,7 @@
   TJvBaseProgressBar = class(TGraphicControl)
   private
     FBlockSize: Integer;
-    FSmooth: Boolean;
+    FSmooth: Boolean;    
     FPosition: Integer;
     FMin: Integer;
     FMax: Integer;
@@ -54,7 +55,7 @@
     procedure SetMin(Value: Integer);
     procedure SetOrientation(Value: TProgressBarOrientation);
     procedure SetPosition(Value: Integer);
-    procedure SetSmooth(const Value: Boolean);
+    procedure SetSmooth(const Value: Boolean);    
     procedure SetBlockSize(const Value: Integer);
     procedure SetBarColor(const Value: TColor);
     procedure SetSteps(const Value: Integer);
@@ -83,7 +84,7 @@
     property Min: Integer read FMin write SetMin default 0;
     property Orientation: TProgressBarOrientation read FOrientation write SetOrientation default pbHorizontal;
     property Position: Integer read FPosition write SetPosition default 0;
-    property Smooth: Boolean read FSmooth write SetSmooth default False;
+    property Smooth: Boolean read FSmooth write SetSmooth default False;    
     property OnChange: TNotifyEvent read FOnChange write FOnChange;
   published
     property Width default 150;
@@ -138,11 +139,14 @@
   private
     FBarColorFrom: TColor;
     FBarColorTo: TColor;
+	FInverted: Boolean;
     procedure SetBarColorFrom(Value: TColor);
     procedure SetBarColorTo(const Value: TColor);
+	procedure SetInverted(const Value: Boolean);
   public
     property BarColorFrom: TColor read FBarColorFrom write SetBarColorFrom;
     property BarColorTo: TColor read FBarColorTo write SetBarColorTo;
+	property Inverted: Boolean read FInverted write SetInverted default False; // Michiel Koot: enabling inverted drawing behaviour.
   end;
 
   TJvCustomGradientProgressBar = class(TJvBaseGradientProgressBar)
@@ -161,6 +165,7 @@
     property Orientation;
     property Position;
     property Smooth;
+    property Inverted; // MK
 
     property Align;
     property Anchors;
@@ -576,6 +581,15 @@
   end;
 end;
 
+procedure TJvBaseGradientProgressBar.SetInverted(const Value: Boolean);
+begin
+  if FInverted <> Value then
+  begin
+    FInverted := Value;
+    Invalidate;
+  end;
+end;
+
 //=== { TJvGradientProgressBar } =============================================
 
 constructor TJvCustomGradientProgressBar.Create(AOwner: TComponent);
@@ -599,14 +613,20 @@
   InflateRect(R, -1, -1);
   if Orientation = pbHorizontal then
   begin
-    R.Right := BarSize;
+    if FInverted = false then
+			R.Right := BarSize
+		else
+			R.Left := R.Right - BarSize;				
     if R.Right > ClientWidth - 2 then
       R.Right := ClientWidth - 2;
     GradientFillRect(ACanvas, R, BarColorFrom, BarColorTo, fdLeftToRight, 255);
   end
   else
   begin
-    R.Top := R.Bottom - BarSize;
+    if FInverted = false then
+      R.Top := R.Bottom - BarSize
+    else
+  		R.Bottom := R.Top + BarSize;
     if R.Top < 2 then
       R.Top := 2;
     GradientFillRect(ACanvas, R, BarColorFrom, BarColorTo, fdBottomToTop, 255);
@@ -622,33 +642,71 @@
     if Orientation = pbHorizontal then
     begin
       R := ClientRect;
-      InflateRect(R, -2, -2);
-      R.Right := R.Left + Round(LBlockSize);
-      while R.Left <= BarSize do
-      begin
-        ACanvas.MoveTo(R.Left, R.Top);
-        ACanvas.LineTo(R.Left, R.Bottom);
-        Inc(I);
-        R := ClientRect;
-        InflateRect(R, -2, -2);
-        R.Right := R.Left + Round(LBlockSize);
-        OffsetRect(R, Round(I * LBlockSize), 0);
-      end;
+      if FInverted = false then
+			begin
+				InflateRect(R, -2, -2);
+				R.Right := R.Left + Round(LBlockSize);
+				while R.Left <= BarSize do
+				begin
+					ACanvas.MoveTo(R.Left, R.Top);
+					ACanvas.LineTo(R.Left, R.Bottom);
+					Inc(I);
+					R := ClientRect;
+					InflateRect(R, -2, -2);
+					R.Right := R.Left + Round(LBlockSize);
+					OffsetRect(R, Round(I * LBlockSize), 0);
+				end;
+			end
+			else
+			// Inverted horizontal
+			begin
+        InflateRect(R, 2, 2);
+        R.Left := R.Right - Round(LBlockSize);
+        while (BarSize <> 0) and (R.Left >= (GetMaxBarSize - BarSize)) do
+        begin
+          ACanvas.MoveTo(R.Right, R.Top);
+          ACanvas.LineTo(R.Right, R.Bottom);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, 2, 2);
+          R.Left := R.Right - Round(LBlockSize);
+          OffsetRect(R, -Round(I * LBlockSize), 0);
+        end;
+      end;	
     end
     else
     begin
       R := ClientRect;
-      InflateRect(R, -2, -2);
-      R.Top := R.Bottom - Round(LBlockSize);
-      while R.Bottom >= GetMaxBarSize - BarSize do
+      if FInverted = false then
       begin
-        ACanvas.MoveTo(R.Left, R.Bottom);
-        ACanvas.LineTo(R.Right, R.Bottom);
-        Inc(I);
-        R := ClientRect;
         InflateRect(R, -2, -2);
         R.Top := R.Bottom - Round(LBlockSize);
-        OffsetRect(R, 0, -Round(I * LBlockSize));
+        while R.Bottom >= GetMaxBarSize - BarSize do
+        begin
+          ACanvas.MoveTo(R.Left, R.Bottom);
+          ACanvas.LineTo(R.Right, R.Bottom);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, -2, -2);
+          R.Top := R.Bottom - Round(LBlockSize);
+          OffsetRect(R, 0, -Round(I * LBlockSize));
+        end;
+      end
+      else
+			// Inverted vertical
+      begin
+        InflateRect(R, 2, 2);
+        R.Bottom := R.Top + Round(LBlockSize);
+        while (BarSize <> 0) and (R.Top <= BarSize) do
+        begin
+          ACanvas.MoveTo(R.Left, R.Top);
+          ACanvas.LineTo(R.Right, R.Top);
+          Inc(I);
+          R := ClientRect;
+          InflateRect(R, 2, 2);
+          R.Bottom := R.Top + Round(LBlockSize);
+          OffsetRect(R, 0, Round(I * LBlockSize));
+        end;
       end;
     end;
   end;

gwark

2010-09-10 22:51

reporter   ~0017664

I yet noticed a small conflict-bug with the base class. Fixed it in a new patchfile JvGradientProgressBar_v2.patch. Please use this one instead of the other file.

obones

2010-10-08 16:34

administrator   ~0017835

Thanks, this will be looked at

AHUser

2010-11-27 12:33

developer   ~0018175

Added to TJvGradientProgressBar in svn revision 12902.

Issue History

Date Modified Username Field Change
2010-09-08 16:59 gwark New Issue
2010-09-08 16:59 gwark File Added: JvProgressBar.pas
2010-09-10 22:24 gwark File Added: Inverted_JvGradientProgressBar.patch
2010-09-10 22:25 gwark File Added: Inverted_JvGradientProgressBar.jpg
2010-09-10 22:27 gwark Note Added: 0017662
2010-09-10 22:49 gwark File Added: JvGradientProgressBar_v2.patch
2010-09-10 22:51 gwark Note Added: 0017664
2010-10-08 16:34 obones Note Added: 0017835
2010-10-08 16:34 obones Status new => acknowledged
2010-11-27 12:33 AHUser Note Added: 0018175
2010-11-27 12:33 AHUser Status acknowledged => resolved
2010-11-27 12:33 AHUser Fixed in Version => Daily / SVN
2010-11-27 12:33 AHUser Resolution open => fixed
2010-11-27 12:33 AHUser Assigned To => AHUser
2012-02-29 16:53 obones Fixed in Version Daily / SVN => 3.45