From 93bc9de92d38b365d3bbe0e9c8344517f9fa6bda Mon Sep 17 00:00:00 2001 From: Graeme Geldenhuys Date: Thu, 8 Dec 2011 14:11:13 +0200 Subject: [PATCH] Implements a new Gauge component with customized painting. 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. --- fptest_fpgui.lpk | 6 +- fptest_fpgui.pas | 2 +- src/fpGUI/customgauge.pas | 119 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/fpGUI/customgauge.pas diff --git a/fptest_fpgui.lpk b/fptest_fpgui.lpk index dac7e7c..d042f09 100644 --- a/fptest_fpgui.lpk +++ b/fptest_fpgui.lpk @@ -15,7 +15,7 @@ - + @@ -24,6 +24,10 @@ + + + + diff --git a/fptest_fpgui.pas b/fptest_fpgui.pas index 8c922f0..de528ab 100644 --- a/fptest_fpgui.pas +++ b/fptest_fpgui.pas @@ -7,7 +7,7 @@ interface uses - GUITestRunner, formimages; + GUITestRunner, formimages, CustomGauge; implementation diff --git a/src/fpGUI/customgauge.pas b/src/fpGUI/customgauge.pas new file mode 100644 index 0000000..06f3e82 --- /dev/null +++ b/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. +