TPSCircleGaugeT2 component

This is a circle gauge based on my CircleGauge. This in turn was based on RingGauge By Tom Lee. Toms code was still shown as a beta version. His component was different in that his component used a needle (line) to show the progress of the component. His component drew three separate areas on the ring. These areas did not move.

I have dropped the needle and now only have two areas on the ring of which one moves thus showing the progress of the gauge.

I have changed some of his code and added a couple of new properties. The component is FREEWARE. I have supplied the code to try and help others in their quest for programming in a perfect environment. When you do add code try to add comments that help other to understand what you have done. If you don't understand what I have done have no hesitation in emailing me at address shown below with your questions.

If you change my code or add to it please send me a copy at the following address: peter.cook@qr.com.au.


Properties
Methods
Events
Variables

Copyright © 2000 by ... PatSoft


Properties

property BackgroundColor : TColor

This is the background color of the component. You would normally set this component color at design time. It is possible to set it to any color you desire, except black. If you set it to black the floodfills will not work and you not be able to see the fonts.

Possible Values - Any color in the color palette.

Default Value - clSilver.


property Caption : String

This the property that holds a string that will be shown on the circle gauge. This is the text that is displayed in the centre towards the top of the gauge with a rectangle draw around it. If you leave this field blank the rectangle that is normally drawn around the text will not appear. If you want the rectangle to appear but with nothing in it, type in a space in the property field. This works because the rectangle is drawn when the property field is not a zero length string. By pressing the space bar while in the field the field is no longer a zero length string.

Possible Value - Any string.

Default Value - Name of component


property CaptionFontSize : Integer

This is the size of the caption font.

Possible Value - Any number.

Default Value - 10


property ErrorChecking : Boolean

This turns the error message system on or off. When it is set to true the component checks that certain numbers are within the allowed limits and show a message if their not. If it is set to false the messages are not shown. When the property is set to false the limit checking is still done but the message is not show on the screen. I used the errorchecking when i was first designing and testing the components. This give me a visual display of when i reached to limits I had set. I would suggest to leave it as true while you are testing and then set it to false when ready to use you program.

See the SetProgressValue routine to see how I have used the ErrorChecking value.

Possible Value - True or False

Default Value - True.


property HasOutline : Boolean

This field will tell the component weither to draw an outline or not. If the property is changed to false the outline is still drawn but the color of the outline is the same as the component background and so it looks like it has disappeared.

Possible Values - True or False.

Default Value - True.


property Height : Integer

This is the height of the component. The height should always equal the width.

Possible Values - greater than 0

Default Value - 300.


property IndicatorColor : TColor

This is the property to set the color of the indictor arc around the inside of the ring. The color can be any color you like.

Possible Values - Any color in the palette

Default Value - clBlack.


property IndicatorFontSize : Integer

This is the size of the font for the used at either end of the indicator to show the minimum and maximum values.

Possible Value - Any number.

Default Value - 10


property MaxValue : Longint

This is the property to hold the maximum value to be shown on the ring.. It can be any number you like but make sure it is greater that the minimum value. It can be negative value.

Possible Values - Any Number. It must be greater than the minimum value.

Default is 100.


property MinValue : Longint

This is the property to hold the minimum value to be shown on the bar. It can be any number you like but make sure it is less than the maximum value. It can be a negative number.

Possible Values - Any Number. It must be less than the maximum value.

Default is 0.


property ProgressValue : Longint

This property holds the current value of the progress meter.

Possible Values - In the range between MinValue and MaxValue.

Default is 0.


property RingForegroundColor : TColor

This is the color of the section of the ring that will seem to be the moving section. It get longer as the progress value increases and shorter as the progress value decreases.

Possible Values - Any color the palette.

Default Value - clBlue.


property RingWidth : Byte

This is the size of the ring that is filled with the ring background and foreground colors. This value is used to work out the radius of the InnerRadius.

Possible Values - Any integer number that is equal to or greater than 5

Default Value - 15.


property SectorDegree : Integer

This is the amount of degrees between the two open ends of the ring. The end s of the ring will move as the number is increased or decreased.

Possible Values - Any integer number greater than or equal to 10 and less than or equal to 270.

Default Value - 60.


property Width : Integer

This the width of the component. The width should always equal the height.

Possible Values - greater than 0

Default Value - 300.



Methods

function AdjustProgressValue(ProgressValue : Integer) : Integer

This function adjust the progress value that is passed to it. The return value if greater than zero is at least 100th of the max value. The return value is used when drawing the moving section of the ring. DON'T play with this part of the code unless you know exactly what you are doing as the result can be disastrous.

Parameters Taken - ProgressValue as an Integer

Return Value - Integer


procedure CaptionTextChanged(var Message: TMessage)

This procedure is used to trigger a repaint of the component when you change the caption text. This is don by monitoring the incoming windows messages and when a CM_TEXTCHANGED message is received. The component is put into an invalid state and thus is repainted.

Parameters taken - Message of Type TMessage

Returns - NIL.


constructor Create(AOwner: TComponent); override

Creates the component. See code for further info.

Parameters taken - AOwner of Type TComponent

Returns - NIL.


function DegToRad(InputDegrees: Double) : Double

This converts a degrees amount to rads. This is used in the drawing routines of the arcs. Again DON'T play with it as it has a disastrous effect.

Parameters taken - InputDegrees as a Double

Returns - Double.


destructor Destroy; override


procedure DrawArcs( GaugeLeft, GaugeTop, GaugeRight, GaugeBottom, OuterRadius, InnerRadius, HalfTheSectorDegree, D1, D2, TheProgressValue : Integer)

This procedure is used to draw the arcs, cross lines, the arc shadow and the indicator on the inside of the ring.

Parameters Taken - GaugeLeft, GaugeTop, GaugeRight, GaugeBottom, OuterRadius, InnerRadius, HalfTheSectorDegree, D1, D2, TheProgressValue -- all as Integer

Further Information -

GaugeLeft is set in the Paint procedure and is always 5.

GaugeTop is set in the Paint procedure and is always 10.

GaugeRight is set in the DrawCanvas procedure. It is the GaugeLeft + the GaugeWidth.

GaugeBottom is set in the DrawCanvas procedure. It is the GaugeTop + the GaugeHeight.

OuterRadius is set in the Paint procedure.

InnerRadius is set in the Paint procedure. It is the OuterRadius less the RingWidth.

HalfTheSectorDegree is set in the DrawGauge routine. It is SectorDegree divided by 2.

D1 is set in the DrawGauge routine. It is used as a small factor when working out the X and Y coordinates.

D2 is set in the DrawGauge routine. It is used as a small factor when working out the X and Y coordinates.

TheProgressValue is the value that determines how far around the arc is drawn


procedure DrawBackground

This procedure draw the basic shape of the component. If the HasOutline property to set to true an outline is drawn in black. If the HasOutline is set to false the outline is draw in the same color as the component and thus gives the illusion that there is no outline around the component.


procedure DrawCaptionText

This procedure draws the Caption text in the middle of the component just above the progress readout


procedure DrawGauge( GaugeLeft, GaugeTop, GaugeRight, GaugeBottom, OuterRadius, InnerRadius, TheSectorDegree, TheProgressValue: Integer)

This procedure is the main procedure for drawing of the circlegauge itself. From with in this procedure the DrawArcs procedure is called. This procedure does the floodfills of the arcs, I had alot of fun trying to get it right. If you play with it make sure you can undo any changes you make if things go wrong.

Parameters Taken - GaugeLeft, GaugeTop, GaugeRight, GaugeBottom, OuterRadius, InnerRadius, TheSectorDegree, TheProgressValue -- all as Integer

Further Information -

GaugeLeft is set in the Paint procedure and is always 5.

GaugeTop is set in the Paint procedure and is always 10.

GaugeRight is set in the DrawCanvas procedure. It is the GaugeLeft + the GaugeWidth.

GaugeBottom is set in the DrawCanvas procedure. It is the GaugeTop + the GaugeHeight.

OuterRadius is set in the Paint procedure.

InnerRadius is set in the Paint procedure. It is the OuterRadius less the RingWidth.

TheSectorDegree is the value stored in the SectorDegree property.

TheProgressValue is the vlaue stored in the ProgressValue property.


procedure DrawValueText

Draws the current Progress value as text in the middle of gauge. It uses a TextOut to write the value as a string on the component. The rectangle around the text will adjust as the length of the string increase or decreases.


procedure FlipBuffers

This procedure flips the contents of the backbuffer to the screen.


function GetArcPointX(Degrees : Double; GaugeLeft, GaugeRight, OuterOrInnerRadius: Integer) : Integer

Returns an X point on an arc by using the degrees.

function GetArcPointY(Degrees : Double; GaugeTop, GaugeBottom, OuterOrInnerRadius : Integer) : Integer

Returns an Y point on an arc by using the degrees.

function GetR(x1, x2 : Integer) : integer

This is one of the original pieces of code. I have not hacked it as it worked well


function GetRx(x1,x2 : Integer) : Integer

This is one of the original pieces of code. I have not hacked it as it worked well


function GetRy(y1, y2 : Integer) : integer

This is one of the original pieces of code. I have not hacked it as it worked well


procedure Loaded; override


procedure Paint; override

This is the paint routine for the component. It contains all the drawing routines.


procedure WMSize(var Message: TWMSize)

This routine causes the component to be redrawn when the caption text is changed.



Events

event OnClick

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.


event OnDblClick

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.


event OnDragDrop(DragObject: TObject; X, Y: Integer)

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.


event OnMouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer)

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.


event OnMouseMove(Shift: TShiftState; X, Y: Integer)

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.


event OnMouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer)

This is a standard event. It is inherited for the components parent component TGraphicComponent. I have not used any special handling of these events.



Variables

variable BackBuffer : TBitmap

This procedure swaps the temporary canvas (Bitmap) that the component has been painted on for the component canvas.

Parameters taken - NIL

Returns - NIL.


variable DrawFactor : Integer

Used to adjust the minimum amount of the ring that is floodfilled. Initial value is 0.


variable DrawStyle : Integer


variable GaugeBottom : Integer

Initial value is 0.


variable GaugeHeight : Integer

Initial value is 0.

variable GaugeLeft : Integer

Initial value is 0.

variable GaugeRight : Integer

Initial value is 0.


variable GaugeTop : Integer

Initial value is 0.


variable GaugeWidth : Integer

Initial value is 0.


variable InnerRadius : Integer

This is the OuterRaidus Less the BarWidth.

variable OuterRadius : Integer

The OuterRadius is set to the correct amount if the paint procedure.