Skip to content

Commit

Permalink
Implements a new Gauge component with customized painting.
Browse files Browse the repository at this point in the history
This fits better with how we want to display the Score of our test run.
Instead of only changing the background color of the gauge (like it use
to do), it now paints the progress bar in the score color.
  • Loading branch information
Graeme Geldenhuys committed Dec 8, 2011
1 parent 45d2f78 commit 93bc9de
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 2 deletions.
6 changes: 5 additions & 1 deletion fptest_fpgui.lpk
Expand Up @@ -15,7 +15,7 @@
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Files Count="2">
<Files Count="3">
<Item1>
<Filename Value="src/fpGUI/GUITestRunner.pas"/>
<UnitName Value="GUITestRunner"/>
Expand All @@ -24,6 +24,10 @@
<Filename Value="src/fpGUI/formimages.pas"/>
<UnitName Value="formimages"/>
</Item2>
<Item3>
<Filename Value="src/fpGUI/customgauge.pas"/>
<UnitName Value="customgauge"/>
</Item3>
</Files>
<RequiredPkgs Count="2">
<Item1>
Expand Down
2 changes: 1 addition & 1 deletion fptest_fpgui.pas
Expand Up @@ -7,7 +7,7 @@
interface

uses
GUITestRunner, formimages;
GUITestRunner, formimages, CustomGauge;

implementation

Expand Down
119 changes: 119 additions & 0 deletions src/fpGUI/customgauge.pas
@@ -0,0 +1,119 @@
{
This unit defines a custom Gauge descendant which improves the visibility
of the background. The background is what tells the end user the state
of the test run.
Copyright (c) 2011 by Graeme Geldenhuys
All rights reserved.
}
unit CustomGauge;

{$mode objfpc}{$H+}

interface

uses
fpg_base, fpg_main, fpg_gauge;

type
TGUIRunnerGauge = class(TfpgBaseGauge)
protected
procedure BarDraw; override;
procedure BackgroundDraw; override;
published
property Align;
property Anchors;
property BorderStyle;
property Color;
property Enabled;
property FirstColor;
property Hint;
property Kind;
property MaxValue;
property MinValue;
property ParentShowHint;
property Progress;
property SecondColor;
property ShowHint;
property ShowText;
property Visible;
property OnShowHint;
end;


implementation

{ TGUIRunnerGauge }

procedure TGUIRunnerGauge.BarDraw;
var
BarLength: Longint;
SavedRect: TfpgRect;
begin
SavedRect := FClientRect; // save client rect for text !!
with FClientRect do
begin
case FKind of
gkHorizontalBar:
begin
{ now paint as normal }
BarLength := Longint(Trunc( (Width * Percentage) / 100.0 ) );
if BarLength > 0 then
begin
if BarLength > Width then
BarLength := Width;
Width := BarLength;
// left top
Canvas.SetColor(fpgLighter(Color, 45));
Canvas.DrawLine(Left, Bottom, Left, Top); // left
Canvas.DrawLine(Left, Top, Right, Top); // top
// right bottom
Canvas.SetColor(fpgDarker(Color, 45));
Canvas.DrawLine(Right, Top, Right, Bottom); // right
Canvas.DrawLine(Right, Bottom, Left, Bottom); // bottom
// inside gradient fill
InflateRect(FClientRect, -1, -1);
Canvas.GradientFill(FClientRect, Color, fpgLighter(Color, 45), gdVertical);
end; { if }
FClientRect := SavedRect;
end;
gkVerticalBar:
begin
inherited BarDraw;
end;
end; { case }
end; { FClientRect }
end;

procedure TGUIRunnerGauge.BackgroundDraw;
begin
FClientRect.SetRect(0, 0, Width, Height);
with FClientRect do
begin
{ Kind specific Bacground }
case FKind of
{ Currently Text doesn't require additional Bacground }
{ And so horizontal and vertical bar - Unless style requires it}
gkHorizontalBar:
begin
{Client area is Widget area, to start with}
Canvas.ClearClipRect;
Canvas.Clear(TfpgColor($c4c4c4));
{ This must be adjusted according the selected style }
Canvas.SetColor(TfpgColor($999999));
Canvas.SetLineStyle(1, lsSolid);
Canvas.DrawRectangle(FClientRect);
{ This must be completed and adjusted with border style }
InflateRect(FClientRect, -1, -1);
Canvas.SetLineStyle(1, lsSolid); // just in case background changed that
end;
else
begin
inherited BackgroundDraw;
end;
end;
end; { with }
end;

end.

0 comments on commit 93bc9de

Please sign in to comment.