Class TRulerPainter

DescriptionHierarchyFieldsMethodsProperties

Unit

Declaration

type TRulerPainter = class(TObject)

Description

TRulerPainter is a class used to draw the ruler on a TCanvas. It does the actual drawing of the ruler in TRbwRuler but it can also be used to draw a ruler on any TCanvas.

Hierarchy

Overview

Fields

Private FPrecision: integer;
Private FMinorTickLength: integer;
Private FValues: TRulerValues;
Private FMajorTickLength: integer;
Private FDigits: integer;
Private FStart: TStart;
Private FLinePosition: integer;
Private FTextPosition: TTextPosition;
Private FTextOffset: integer;
Private FPositions: TRulerPositions;
Private FDesiredSpacing: integer;
Private FRulerPosition: TRulerPosition;
Private FOnInvalidate: TNotifyEvent;
Private FOwner: TComponent;
Private FAvailableArea: TRect;

Methods

Private procedure SetDesiredSpacing(const Value: integer);
Private procedure SetDigits(Value: integer);
Private procedure SetLinePosition(const Value: integer);
Private procedure SetMajorTickLength(const Value: integer);
Private procedure SetMinorTickLength(const Value: integer);
Private procedure SetPositions(const Value: TRulerPositions);
Private procedure SetPrecision(Value: integer);
Private procedure SetRulerPosition(const Value: TRulerPosition);
Private procedure SetStart(const Value: TStart);
Private procedure SetTextOffset(const Value: integer);
Private procedure SetTextPosition(const Value: TTextPosition);
Private procedure SetValues(const Value: TRulerValues);
Private procedure Invalidate;
Private function GetComponentState: TComponentState;
Private procedure DrawMainLine(ACanvas: TCanvas; out OutputRect: TRect);
Private procedure GetTickSpacingAndFactor( out Spacing: integer; out Factor: double);
Private function GetLineDrawingPosition: integer;
Private function GetOrientation: TOrientation;
Private function GetCurrentPosition(const CurPositionR: double): integer;
Private procedure DrawLabel(ACanvas: TCanvas; const CurPositionR, Increment: double; const CurPositionI: integer; var FirstLabel: boolean; var LastLabelLT, LastLabelRB: integer; out LabelDrawn: boolean; out LabelRect: TRect);
Private procedure DrawTick(ACanvas: TCanvas; const CurPositionI: integer; const IsMajorTick: boolean; out OutputRect: TRect);
Private procedure DrawMinorTicks(ACanvas: TCanvas; const LowCoord, Increment: double; const Index, Spacing: integer; DrawIntermediates: boolean; out OutputRect: TRect; Out TicksDrawn: boolean);
Private function GetTextDrawingPosition: TStart;
Private function RoundNumber(Value, Increment: double): string;
Private function Multiplier: double;
Private function GetDrawingMajorTickLength: integer;
Private function GetDrawingMinorTickLength: integer;
Private function GetHeight: integer;
Private function GetWidth: integer;
Private procedure GenerateRect(out OutputRect: TRect; X1, Y1, X2, Y2: Integer);
Public procedure SetDefaults;
Public procedure Assign(Source: TRulerPainter);
Public constructor Create(Owner: TComponent);
Public destructor Destroy; override;
Public class procedure PaintRotated(ACanvas: TCanvas; const X, Y, Angle: double; const Text: string; out LabelRect: TRect); virtual;
Public procedure DrawRuler(ACanvas: TCanvas; InputRect: TRect; var OutputRect: TRect);

Properties

Private property Height: integer read GetHeight;
Private property Width: integer read GetWidth;
Protected property RulerOrientation: TOrientation read GetOrientation;
Public property ComponentState: TComponentState read GetComponentState;
Public property RulerDesiredSpacing: integer read FDesiredSpacing write SetDesiredSpacing;
Public property RulerDigits: integer read FDigits write SetDigits;
Public property RulerEnds: TRulerPositions read FPositions write SetPositions;
Public property RulerLinePosition: integer read FLinePosition write SetLinePosition;
Public property RulerMajorTickLength: integer read FMajorTickLength write SetMajorTickLength;
Public property RulerMinorTickLength: integer read FMinorTickLength write SetMinorTickLength;
Public property RulerPosition: TRulerPosition read FRulerPosition write SetRulerPosition;
Public property RulerPrecision: integer read FPrecision write SetPrecision;
Public property RulerStart: TStart read FStart write SetStart;
Public property RulerTextOffset: integer read FTextOffset write SetTextOffset;
Public property RulerTextPosition: TTextPosition read FTextPosition write SetTextPosition;
Public property RulerValues: TRulerValues read FValues write SetValues;
Public property OnInvalidate: TNotifyEvent read FOnInvalidate write FOnInvalidate;

Description

Fields

Private FPrecision: integer;
 
Private FMinorTickLength: integer;
 
Private FValues: TRulerValues;
 
Private FMajorTickLength: integer;
 
Private FDigits: integer;
 
Private FStart: TStart;
 
Private FLinePosition: integer;
 
Private FTextPosition: TTextPosition;
 
Private FTextOffset: integer;
 
Private FPositions: TRulerPositions;
 
Private FDesiredSpacing: integer;
 
Private FRulerPosition: TRulerPosition;
 
Private FOnInvalidate: TNotifyEvent;
 
Private FOwner: TComponent;
 
Private FAvailableArea: TRect;
 

Methods

Private procedure SetDesiredSpacing(const Value: integer);
 
Private procedure SetDigits(Value: integer);
 
Private procedure SetLinePosition(const Value: integer);
 
Private procedure SetMajorTickLength(const Value: integer);
 
Private procedure SetMinorTickLength(const Value: integer);
 
Private procedure SetPositions(const Value: TRulerPositions);
 
Private procedure SetPrecision(Value: integer);
 
Private procedure SetRulerPosition(const Value: TRulerPosition);
 
Private procedure SetStart(const Value: TStart);
 
Private procedure SetTextOffset(const Value: integer);
 
Private procedure SetTextPosition(const Value: TTextPosition);
 
Private procedure SetValues(const Value: TRulerValues);
 
Private procedure Invalidate;
 
Private function GetComponentState: TComponentState;
 
Private procedure DrawMainLine(ACanvas: TCanvas; out OutputRect: TRect);

DrawMainLine draws the main line of the ruler.

Private procedure GetTickSpacingAndFactor( out Spacing: integer; out Factor: double);

GetTickSpacingAndFactor get the spacing between tick marks and Factor.

Private function GetLineDrawingPosition: integer;

GetLineDrawingPosition gets the X or Y coordinate where the main line of the ruler should be drawn.

Private function GetOrientation: TOrientation;
 
Private function GetCurrentPosition(const CurPositionR: double): integer;

Get the pixel equivalent of the current number.

Private procedure DrawLabel(ACanvas: TCanvas; const CurPositionR, Increment: double; const CurPositionI: integer; var FirstLabel: boolean; var LastLabelLT, LastLabelRB: integer; out LabelDrawn: boolean; out LabelRect: TRect);

DrawLabel draws the numbers on the ruler.

Private procedure DrawTick(ACanvas: TCanvas; const CurPositionI: integer; const IsMajorTick: boolean; out OutputRect: TRect);

DrawTick draws a tick line

Private procedure DrawMinorTicks(ACanvas: TCanvas; const LowCoord, Increment: double; const Index, Spacing: integer; DrawIntermediates: boolean; out OutputRect: TRect; Out TicksDrawn: boolean);

DrawMinorTicks draws minor tick lines on the ruler

Private function GetTextDrawingPosition: TStart;

GetTextDrawingPosition determines where the labels are drawn with respect to the main line of the ruler.

Private function RoundNumber(Value, Increment: double): string;

RoundNumber converts Value to a string using RulerPrecision and RulerDigits. However, if Value is within Increment/RoundFactor of 0, RoundNumber returns '0'.

Private function Multiplier: double;

Multiplier is the ratio between the length that the ruler represents and its length in pixels.

Private function GetDrawingMajorTickLength: integer;

GetDrawingMajorTickLength gets the length (which may be negative) of the major ticks during drawing.

Private function GetDrawingMinorTickLength: integer;

GetDrawingMinorTickLength gets the length (which may be negative) of the minor ticks during drawing.

Private function GetHeight: integer;
 
Private function GetWidth: integer;
 
Private procedure GenerateRect(out OutputRect: TRect; X1, Y1, X2, Y2: Integer);
 
Public procedure SetDefaults;
 
Public procedure Assign(Source: TRulerPainter);
 
Public constructor Create(Owner: TComponent);

Create creates and instance of TRulerPainter

Public destructor Destroy; override;

Destroy destroys the current instance of TRulerPainter. Do not call Destroy directly. Call Free instead.

Public class procedure PaintRotated(ACanvas: TCanvas; const X, Y, Angle: double; const Text: string; out LabelRect: TRect); virtual;

PaintRotated draws Text at the position X,Y at the angle specified by Angle. X and Y are in pixels (despite being real numbers). Angle is measured in degrees in a clockwise direction. The font must be a TrueType Font for PaintRotated to work properly.

Public procedure DrawRuler(ACanvas: TCanvas; InputRect: TRect; var OutputRect: TRect);
 

Properties

Private property Height: integer read GetHeight;
 
Private property Width: integer read GetWidth;
 
Protected property RulerOrientation: TOrientation read GetOrientation;

RulerOrientation controls whether the ruler is drawn in a horizontal or vertical orientation. RulerOrientation is determined by RulerPosition.

Public property ComponentState: TComponentState read GetComponentState;
 
Public property RulerDesiredSpacing: integer read FDesiredSpacing write SetDesiredSpacing;

RulerDesiredSpacing is the desired spacing between major ticks in pixels. The actual spacing will, in most cases, be slightly different from RulerDesiredSpacing.

Public property RulerDigits: integer read FDigits write SetDigits;

RulerDigits specifies how many digits will appear in the exponent portion of numbers on the ruler.

Public property RulerEnds: TRulerPositions read FPositions write SetPositions;

RulerEnds specifies the positions, in pixels, of the starting and ending ends of the main line of the ruler.

Public property RulerLinePosition: integer read FLinePosition write SetLinePosition;

RulerLinePosition specifies the distance of the main line of the ruler from the left, top, right, or bottom edge in pixels. Which one is determined by RulerPosition.

Public property RulerMajorTickLength: integer read FMajorTickLength write SetMajorTickLength;

RulerMajorTickLength is the length of the major ticks in pixels.

Public property RulerMinorTickLength: integer read FMinorTickLength write SetMinorTickLength;

RulerMinorTickLength is the length of the minor ticks in pixels.

Public property RulerPosition: TRulerPosition read FRulerPosition write SetRulerPosition;

RulerPosition specifies the orientation of the main line on the ruler. RulerPosition controls RulerOrientation.

Public property RulerPrecision: integer read FPrecision write SetPrecision;

RulerPrecision specifies how many digits appear in the number in the ruler.

Public property RulerStart: TStart read FStart write SetStart;

RulerStart specifies the end of the ruler that has the lower value of the ruler.

Public property RulerTextOffset: integer read FTextOffset write SetTextOffset;

RulerTextOffset specifies the distance from the main line of the ruler to the labels on the ruler.

Public property RulerTextPosition: TTextPosition read FTextPosition write SetTextPosition;

RulerTextPosition specifies whether the labels are inside or outside the ruler.

Public property RulerValues: TRulerValues read FValues write SetValues;

RulerValues specifies the values of the lower and upper end of the ruler line. Thus the ruler represents a length equal to TRulerValues.Upper minus TRulerValues.Lower

Public property OnInvalidate: TNotifyEvent read FOnInvalidate write FOnInvalidate;
 

Generated by PasDoc 0.12.1 on 2013-05-13 15:42:00