diff options
author | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2006-12-07 15:11:50 +0000 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@users.sourceforge.net> | 2006-12-07 15:11:50 +0000 |
commit | c548c149f444cd946e35839ce7d681efd3221d16 (patch) | |
tree | 68e9771c7d6386031a79cf3841beebd799c1f66e | |
parent | dbbb9e0d3ea19cef11f6442a11c80b065ec6db4d (diff) | |
download | fpGUI-c548c149f444cd946e35839ce7d681efd3221d16.tar.xz |
* Implement a FillTriangle method for TFCustomCanvas.
* Implement a DrawArrowDirection function for TDefaultStyle
-rw-r--r-- | gfx/gdi/gfx_gdi.pas | 12 | ||||
-rw-r--r-- | gfx/gfxbase.pas | 7 | ||||
-rw-r--r-- | gfx/x11/gfx_x11.pas | 12 | ||||
-rw-r--r-- | gui/style.inc | 49 |
4 files changed, 79 insertions, 1 deletions
diff --git a/gfx/gdi/gfx_gdi.pas b/gfx/gdi/gfx_gdi.pas index 7f60733b..151e90a9 100644 --- a/gfx/gdi/gfx_gdi.pas +++ b/gfx/gdi/gfx_gdi.pas @@ -95,6 +95,7 @@ type procedure DoDrawLine(const AFrom, ATo: TPoint); override; procedure DoDrawPoint(const APoint: TPoint); override; procedure DoFillRect(const ARect: TRect); override; + procedure DoFillTriangle(const P1, P2, P3: TPoint); override; procedure DoTextOut(const APosition: TPoint; const AText: String); override; procedure DoCopyRect(ASource: TFCustomCanvas; const ASourceRect: TRect; const ADestPos: TPoint); override; procedure DoMaskedCopyRect(ASource, AMask: TFCustomCanvas; const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint); override; @@ -607,6 +608,17 @@ begin Windows.FillRect(Handle, r, FBrush); end; +procedure TGDICanvas.DoFillTriangle(const P1, P2, P3: TPoint); +var + pts : array[1..3] of windows.TPoint; +begin + pts[1].X := P1.X; pts[1].Y := P1.Y; + pts[2].X := P2.X; pts[2].Y := P2.Y; + pts[3].X := P3.X; pts[3].Y := P3.Y; + + Windows.Polygon(Handle, pts, 3); +end; + function TGDICanvas.FontCellHeight: Integer; begin diff --git a/gfx/gfxbase.pas b/gfx/gfxbase.pas index 8c11c59a..31d8876f 100644 --- a/gfx/gfxbase.pas +++ b/gfx/gfxbase.pas @@ -313,6 +313,7 @@ type procedure DoDrawRect(const ARect: TRect); virtual; procedure DoDrawPoint(const APoint: TPoint); virtual; abstract; procedure DoFillRect(const ARect: TRect); virtual; abstract; + procedure DoFillTriangle(const P1, P2, P3: TPoint); virtual; abstract; procedure DoTextOut(const APosition: TPoint; const AText: String); virtual; abstract; procedure DoCopyRect(ASource: TFCustomCanvas; const ASourceRect: TRect; const ADestPos: TPoint); virtual; abstract; procedure DoMaskedCopyRect(ASource, AMask: TFCustomCanvas; const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint); virtual; abstract; @@ -349,6 +350,7 @@ type procedure DrawRect(const ARect: TRect); procedure DrawPoint(const APoint: TPoint); procedure FillRect(const ARect: TRect); + procedure FillTriangle(const P1, P2, P3: TPoint); // Fonts function FontCellHeight: Integer; virtual; abstract; @@ -809,6 +811,11 @@ begin DoFillRect(r); end; +procedure TFCustomCanvas.FillTriangle(const P1, P2, P3: TPoint); +begin + DoFillTriangle(P1, P2, P3); +end; + function TFCustomCanvas.TextExtent(const AText: String): TSize; begin Result.cx := TextWidth(AText); diff --git a/gfx/x11/gfx_x11.pas b/gfx/x11/gfx_x11.pas index 2755c92a..938ac75a 100644 --- a/gfx/x11/gfx_x11.pas +++ b/gfx/x11/gfx_x11.pas @@ -106,6 +106,7 @@ type procedure DoDrawRect(const ARect: TRect); override; procedure DoDrawPoint(const APoint: TPoint); override; procedure DoFillRect(const ARect: TRect); override; + procedure DoFillTriangle(const P1, P2, P3: TPoint); override; procedure DoTextOut(const APosition: TPoint; const AText: String); override; procedure DoCopyRect(ASource: TFCustomCanvas; const ASourceRect: TRect; const ADestPos: TPoint); override; procedure DoMaskedCopyRect(ASource, AMask: TFCustomCanvas; const ASourceRect: TRect; const AMaskPos, ADestPos: TPoint); override; @@ -571,6 +572,17 @@ begin Right - Left, Bottom - Top); end; +procedure TX11Canvas.DoFillTriangle(const P1, P2, P3: TPoint); +var + pts : array[1..3] of TXPoint; +begin + pts[1].X := P1.X; pts[1].Y := P1.Y; + pts[2].X := P2.X; pts[2].Y := P2.Y; + pts[3].X := P3.X; pts[3].Y := P3.Y; + + XFillPolygon(GFApplication.Handle, Handle, GC, @pts, 3, 0, 0); +end; + function TX11Canvas.FontCellHeight: Integer; begin diff --git a/gui/style.inc b/gui/style.inc index 6954b78b..58c18bd5 100644 --- a/gui/style.inc +++ b/gui/style.inc @@ -94,6 +94,7 @@ ImageCanvas: TFCustomCanvas; MaskCanvas: TFCustomCanvas; // ArrowBitmaps: array[TArrowDirection] of TGfxImage; + procedure DrawDirectionArrows(ACanvas: TFCanvas; const ARect: TRect; ADirection: integer); public constructor Create; override; destructor Destroy; override; @@ -230,6 +231,50 @@ const {$I defimpl/defstyle.inc} {$ENDIF} +{ ADirection values: 1 - down, 2 - up, 3 - right, 4 - left } +procedure TDefaultStyle.DrawDirectionArrows(ACanvas: TFCanvas; + const ARect: TRect; ADirection: integer); +var + peekx, peeky: Cardinal; + basex, basey: Cardinal; + side, margin: Cardinal; +begin + ACanvas.SetColor(GetGUIColor(clWindowText)); + + side := (ARect.Right div 4) + 1; + margin := side + 1; + + if ADirection < 2 then // vertical + begin + peekx := ARect.Left+(ARect.Right div 2); + if ADirection = 1 then // down + begin + peeky := ARect.Top + ARect.Bottom - margin; + basey := peeky-side; + end + else + begin // up + peeky := ARect.Top+margin; + basey := peeky+side; + end; + ACanvas.FillTriangle(Point(peekx, peeky), Point(peekx+side, basey), Point(peekx-side, basey)); + end + else // horizontal + begin + peeky := ARect.Top + (ARect.Bottom div 2); + if ADirection = 3 then // right + begin + peekx := ARect.Left + ARect.Right - margin; + basex := peekx - side; + end + else // left + begin + peekx := ARect.Left + margin; + basex := peekx + side; + end; + ACanvas.FillTriangle(Point(peekx, peeky), Point(basex, peeky-side), Point(basex, peeky+side)); + end; +end; constructor TDefaultStyle.Create; const @@ -335,7 +380,7 @@ begin Image.SetPixelsFromData(@ArrowBitmapData, 32); ImageCanvas.DrawImage(Image, Point(0, 25)); Image.Free; - + Palette.Release; end; @@ -737,6 +782,8 @@ begin ImageCanvas, Rect(Index * 8, 25, (Index + 1) * 8, 33), TopLeft + Point((Right - Left - 8) div 2, (Bottom - Top - 8) div 2)); + +// DrawDirectionArrows(Canvas, ARect, Ord(Direction)); end; |