diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-06 15:09:11 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-06 15:09:11 +0000 |
commit | f11fffeb438a1d3457629d183fe96657d12c9546 (patch) | |
tree | fb3d451acc3201c7bced7075beb83493928929bb /src/corelib | |
parent | 00a0e93ffe1635157c834e58d3b9c18c841bc062 (diff) | |
download | fpGUI-f11fffeb438a1d3457629d183fe96657d12c9546.tar.xz |
* Implemented Canvas.FillGradient().
* Made some improvements to the TfpgBaseGrid painting. Still have lots
outstanding though.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/fpgfx.pas | 7 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 42 |
2 files changed, 49 insertions, 0 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index cce070ca..5d75ffad 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -267,6 +267,8 @@ function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; function OffsetRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; function CenterPoint(const Rect: TRect): TPoint; +// Debug rountines +procedure PrintRect(var Rect: TRect); implementation @@ -391,6 +393,11 @@ begin end; end; +procedure PrintRect(var Rect: TRect); +begin + writeln('Rect x1=', Rect.Left, ' y1=', Rect.Top, ' x2=', Rect.Right, ' y2=', Rect.Bottom); +end; + { TfpgTimer } procedure TfpgTimer.SetEnabled(const AValue: boolean); diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 2929c803..6c0ace9b 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -27,6 +27,9 @@ type TMouseCursor = (mcDefault, mcArrow, mcCross, mcIBeam, mcSizeEW, mcSizeNS, mcSizeNWSE, mcSizeNESW, mcMove, mcHourGlass); + TGradientDirection = (gdVertical, // Fill vertical + gdHorizontal); // Fill Horizontal + const MOUSE_LEFT = 1; MOUSE_RIGHT = 2; @@ -267,6 +270,7 @@ type procedure FillRectangle(r: TRect); overload; procedure FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); procedure FillArc(x, y, w, h: TfpgCoord; a1, a2: double); + procedure GradientFill(ARect: TRect; AStart, AStop: TfpgColor; ADirection: TGradientDirection); procedure XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); overload; procedure XORFillRectangle(col: TfpgColor; r: TfpgRect); overload; procedure SetClipRect(const ARect: TRect); @@ -838,6 +842,44 @@ begin DoFillArc(x, y, w, h, a1, a2); end; +procedure TfpgCanvasBase.GradientFill(ARect: TRect; AStart, AStop: TfpgColor; + ADirection: TGradientDirection); +var + RGBStart: TRGBTriple; + RGBStop: TRGBTriple; + RDiff, GDiff, BDiff: Integer; + count: Integer; + i: Integer; + newcolor: TRGBTriple; +begin + RGBStart := fpgColorToRGBTriple(fpgColorToRGB(AStart)); + RGBStop := fpgColorToRGBTriple(fpgColorToRGB(AStop)); + + if ADirection = gdVertical then + count := ARect.Bottom - ARect.Top + else + count := ARect.Right - ARect.Left; + + RDiff := RGBStop.Red - RGBStart.Red; + GDiff := RGBStop.Green - RGBStart.Green; + BDiff := RGBStop.Blue - RGBStart.Blue; + +// Changing; + for i := 0 to count do + begin + newcolor.Red := RGBStart.Red + (i * RDiff) div count; + newcolor.Green := RGBStart.Green + (i * GDiff) div count; + newcolor.Blue := RGBStart.Blue + (i * BDiff) div count; + SetColor(RGBTripleTofpgColor(newcolor)); + + if ADirection = gdHorizontal then + DrawLine(ARect.Left+i, ARect.Top, ARect.Left+i, ARect.Bottom) + else + DrawLine(ARect.Left, ARect.Top+i, ARect.Right, ARect.Top+i); + end; +// Changed; +end; + procedure TfpgCanvasBase.XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); begin DoXORFillRectangle(col, x, y, w, h); |