diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-10-05 21:47:13 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2008-10-05 21:47:13 +0000 |
commit | 8571f99a9f8e21d8e96999da505f9139621943b1 (patch) | |
tree | ef609a9c392b0d27eee20989fe9d30114acff0d3 /src/corelib | |
parent | ff87ebe7afdf27042b7963ca04246963adbdcaab (diff) | |
download | fpGUI-8571f99a9f8e21d8e96999da505f9139621943b1.tar.xz |
* Added a new Canvas.DrawPolygon() method
* Added a new unit fpg_extgraphics.pas with extensive shape drawing methods
* Added a new conversion method called fpgRectToRect()
* Replaced the implementation of TfpgStyle.DrawDirectionArrow to use the
new fpg_extgraphics.PaintTriangle() method instead.
* Adjusted ComboBox painting of internal button to accomodate the new
fpg_extgraphics unit.
* Added Jean-Marc's new fpg_spinedit unit.
* Made some further improvements and minor fixes to the SpinEdit
and SpinEditFloat components.
* renamed the fpdoc file fpgfx.xml to fpg_main.xml as per the new unit names.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/fpg_base.pas | 46 | ||||
-rw-r--r-- | src/corelib/fpg_main.pas | 33 | ||||
-rw-r--r-- | src/corelib/gdi/fpg_gdi.pas | 10 | ||||
-rw-r--r-- | src/corelib/gdi/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/corelib/gdi/fpgui_toolkit.pas | 15 | ||||
-rw-r--r-- | src/corelib/x11/fpg_x11.pas | 29 | ||||
-rw-r--r-- | src/corelib/x11/fpgui_toolkit.lpk | 6 | ||||
-rw-r--r-- | src/corelib/x11/fpgui_toolkit.pas | 2 |
8 files changed, 129 insertions, 18 deletions
diff --git a/src/corelib/fpg_base.pas b/src/corelib/fpg_base.pas index 1785d15d..042a55b9 100644 --- a/src/corelib/fpg_base.pas +++ b/src/corelib/fpg_base.pas @@ -32,6 +32,8 @@ type TfpgString = type string; TfpgChar = type string[4]; TfpgModalResult = Low(integer)..High(integer); + + PPoint = ^TPoint; TRGBTriple = record Red: word; @@ -305,6 +307,7 @@ type procedure SetPixel(X, Y: integer; const AValue: TfpgColor); virtual; abstract; procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); virtual; abstract; procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); virtual; abstract; + procedure DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); virtual; abstract; public constructor Create; virtual; destructor Destroy; override; @@ -316,6 +319,9 @@ type procedure DrawImage(x, y: TfpgCoord; img: TfpgImageBase); procedure DrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi, w, h: integer); procedure DrawArc(x, y, w, h: TfpgCoord; a1, a2: double); + procedure DrawPolygon(const Points: array of TPoint; Winding: Boolean; StartIndex: Integer = 0; NumPts: Integer = -1); + procedure DrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); virtual; + procedure DrawPolygon(const Points: array of TPoint); procedure StretchDraw (x, y, w, h: TfpgCoord; ASource: TfpgImageBase); procedure CopyRect(ADest_x, ADest_y: TfpgCoord; ASrcCanvas: TfpgCanvasBase; var ASrcRect: TfpgRect); procedure DrawString(x, y: TfpgCoord; const txt: string); @@ -1299,6 +1305,46 @@ begin DoDrawArc(x, y, w, h, a1, a2); end; +{ Use Polygon to draw a closed, many-sided shape on the canvas, using the value + of Canvas.Color. The shape is always filled. + The Points parameter is an array of points that give the vertices of the + polygon. + Winding determines how the polygon is filled. When Winding is True, Polygon + fills the shape using the Winding fill algorithm. When Winding is False, + Polygon uses the even-odd (alternative) fill algorithm. + StartIndex gives the index of the first point in the array to use. All points + before this are ignored. + NumPts indicates the number of points to use, starting at StartIndex. + If NumPts is -1 (the default), Polygon uses all points from StartIndex to the + end of the array. + The first point is always connected to the last point. + To draw a polygon on the canvas, without filling it, use the Polyline method, + specifying the first point a second time at the end. } +procedure TfpgCanvasBase.DrawPolygon(const Points: array of TPoint; + Winding: Boolean; StartIndex: Integer; NumPts: Integer); +var + NPoints: integer; +begin + if NumPts<0 then + NPoints:=High(Points)-StartIndex+1 + else + NPoints:=NumPts; + if NPoints<=0 then exit; + DrawPolygon(@Points[StartIndex],NPoints,Winding); +end; + +procedure TfpgCanvasBase.DrawPolygon(Points: PPoint; NumPts: Integer; + Winding: boolean); +begin + if NumPts<=0 then exit; + DoDrawPolygon(Points,NumPts,Winding); +end; + +procedure TfpgCanvasBase.DrawPolygon(const Points: array of TPoint); +begin + DrawPolygon(Points, True, Low(Points), High(Points) - Low(Points) + 1); +end; + procedure TfpgCanvasBase.StretchDraw(x, y, w, h: TfpgCoord; ASource: TfpgImageBase); var FreeInterpolation: boolean; diff --git a/src/corelib/fpg_main.pas b/src/corelib/fpg_main.pas index d248fbc4..753856f6 100644 --- a/src/corelib/fpg_main.pas +++ b/src/corelib/fpg_main.pas @@ -364,6 +364,7 @@ function OffsetRect(var Rect: TfpgRect; dx: Integer; dy: Integer): Boolean; function CenterPoint(const Rect: TRect): TPoint; function CenterPoint(const Rect: TfpgRect): TPoint; function fpgRect(ALeft, ATop, AWidth, AHeight: integer): TfpgRect; +function fpgRectToRect(const ARect: TfpgRect): TRect; // Debug rountines procedure PrintRect(const Rect: TRect); @@ -387,7 +388,8 @@ uses fpg_stringutils, fpg_widget, fpg_dialogs, - fpg_hint; + fpg_hint, + fpg_extgraphics; var fpgTimers: TList; @@ -556,6 +558,14 @@ begin Result.SetRect(ALeft, ATop, AWidth, AHeight); end; +function fpgRectToRect(const ARect: TfpgRect): TRect; +begin + Result.Left := ARect.Left; + Result.Top := ARect.Top; + Result.Right := ARect.Right; + Result.Bottom := ARect.Bottom; +end; + procedure PrintRect(const Rect: TRect); begin writeln('Rect left=', Rect.Left, ' top=', Rect.Top, ' right=', Rect.Right, @@ -1622,13 +1632,19 @@ end; procedure TfpgStyle.DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; direction: TArrowDirection); var +{ peekx: integer; peeky: integer; basex: integer; basey: integer; side: integer; margin: integer; +} + rad: Extended; + r: TRect; + r2: TfpgRect; begin +{ side := (w div 4) + 1; margin := side + 1; @@ -1662,6 +1678,21 @@ begin end; ACanvas.FillTriangle(peekx, peeky, basex, peeky - side, basex, peeky + side); end; +} + + r2.SetRect(x, y, w, h); + r := fpgRectToRect(r2); + + if direction = adRight then + rad := DegToRad(0) + else if direction = adUp then + rad := DegToRad(90) + else if direction = adLeft then + rad := DegToRad(180) + else + rad := DegToRad(270); + + PaintTriangle(ACanvas, r, rad); end; procedure TfpgStyle.DrawString(ACanvas: TfpgCanvas; x, y: TfpgCoord; diff --git a/src/corelib/gdi/fpg_gdi.pas b/src/corelib/gdi/fpg_gdi.pas index b28e0e3d..49f2fb05 100644 --- a/src/corelib/gdi/fpg_gdi.pas +++ b/src/corelib/gdi/fpg_gdi.pas @@ -87,6 +87,8 @@ type end; + { TfpgCanvasImpl } + TfpgCanvasImpl = class(TfpgCanvasBase) private FDrawing: boolean; @@ -131,6 +133,7 @@ type procedure SetPixel(X, Y: integer; const AValue: TfpgColor); override; procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; + procedure DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); override; property DCHandle: TfpgDCHandle read Fgc; public constructor Create; override; @@ -1679,6 +1682,13 @@ begin {$ENDIF} end; +procedure TfpgCanvasImpl.DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean); +//var +// pts: array of TPoint; +begin + Windows.Polygon(Fgc, Points, NumPts); +end; + procedure TfpgCanvasImpl.DoPutBufferToScreen(x, y, w, h: TfpgCoord); begin if FBufferBitmap > 0 then diff --git a/src/corelib/gdi/fpgui_toolkit.lpk b/src/corelib/gdi/fpgui_toolkit.lpk index 0c62a067..fdc70220 100644 --- a/src/corelib/gdi/fpgui_toolkit.lpk +++ b/src/corelib/gdi/fpgui_toolkit.lpk @@ -27,7 +27,7 @@ <License Value="Modified LGPL "/>
<Version Minor="6" Release="3"/>
- <Files Count="70">
+ <Files Count="71">
<Item1>
<Filename Value="..\stdimages.inc"/>
<Type Value="Include"/>
@@ -308,6 +308,10 @@ <Filename Value="..\..\gui\fpg_spinedit.pas"/>
<UnitName Value="fpg_spinedit"/>
</Item70>
+ <Item71>
+ <Filename Value="..\fpg_extgraphics.pas"/>
+ <UnitName Value="fpg_extgraphics"/>
+ </Item71>
</Files>
<LazDoc Paths="..\..\..\docs\xml\corelib\;..\..\..\docs\xml\corelib\x11\;..\..\..\docs\xml\corelib\gdi\;..\..\..\docs\xml\gui\"/>
<RequiredPkgs Count="1">
diff --git a/src/corelib/gdi/fpgui_toolkit.pas b/src/corelib/gdi/fpgui_toolkit.pas index bbfa850e..52698712 100644 --- a/src/corelib/gdi/fpgui_toolkit.pas +++ b/src/corelib/gdi/fpgui_toolkit.pas @@ -10,13 +10,14 @@ uses fpg_base, fpg_main, fpg_cmdlineparams, fpg_command_intf, fpg_constants, fpg_extinterpolation, fpg_imagelist, fpg_imgfmt_bmp, fpg_pofiles, fpg_popupwindow, fpg_stdimages, fpg_stringhashlist, fpg_translations, - fpg_stringutils, fpg_utils, fpg_widget, fpg_wuline, fpg_animation, - fpg_basegrid, fpg_button, fpg_checkbox, fpg_combobox, fpg_customgrid, - fpg_dialogs, fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid, - fpg_hyperlink, fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, - fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, - fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, - fpgui_db, fpg_gdi, fpg_impl, fpg_splitter, fpg_hint, fpg_spinedit; + fpg_stringutils, fpg_utils, fpg_widget, fpg_wuline, fpg_animation, + fpg_basegrid, fpg_button, fpg_checkbox, fpg_combobox, fpg_customgrid, + fpg_dialogs, fpg_editcombo, fpg_edit, fpg_form, fpg_gauge, fpg_grid, + fpg_hyperlink, fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, + fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, + fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, + fpgui_db, fpg_gdi, fpg_impl, fpg_splitter, fpg_hint, fpg_spinedit, + fpg_extgraphics; implementation diff --git a/src/corelib/x11/fpg_x11.pas b/src/corelib/x11/fpg_x11.pas index 4c7fa049..010fda63 100644 --- a/src/corelib/x11/fpg_x11.pas +++ b/src/corelib/x11/fpg_x11.pas @@ -195,6 +195,7 @@ type procedure SetPixel(X, Y: integer; const AValue: TfpgColor); override; procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; + procedure DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean=False); override; property DCHandle: TfpgDCHandle read FDrawHandle; public constructor Create; override; @@ -1918,6 +1919,23 @@ begin Trunc(64 * a1), Trunc(64 * a2)); end; +procedure TfpgCanvasImpl.DoDrawPolygon(Points: fpg_base.PPoint; NumPts: Integer; Winding: boolean); +var + PointArray: PXPoint; + i: integer; +begin + { convert TPoint to TXPoint } + GetMem(PointArray, SizeOf(TXPoint)*(NumPts+1)); // +1 for return line + for i := 0 to NumPts-1 do + begin + PointArray[i].x := Points[i].x; + PointArray[i].y := Points[i].y; + end; + XFillPolygon(xapplication.display, FDrawHandle, Fgc, PointArray, NumPts, CoordModeOrigin, X.Complex); + if PointArray <> nil then + FreeMem(PointArray); +end; + procedure TfpgCanvasImpl.BufferFreeTimer(Sender: TObject); begin {$IFDEF DEBUG} @@ -2039,14 +2057,11 @@ procedure TfpgCanvasImpl.DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); var pts: array[1..3] of TXPoint; begin - pts[1].x := x1; - pts[1].y := y1; - pts[2].x := x2; - pts[2].y := y2; - pts[3].x := x3; - pts[3].y := y3; + pts[1].x := x1; pts[1].y := y1; + pts[2].x := x2; pts[2].y := y2; + pts[3].x := x3; pts[3].y := y3; - XFillPolygon(xapplication.display, FDrawHandle, Fgc, @pts, 3, 0, 0); + XFillPolygon(xapplication.display, FDrawHandle, Fgc, @pts, 3, CoordModeOrigin, X.Complex); end; procedure TfpgCanvasImpl.DoDrawRectangle(x, y, w, h: TfpgCoord); diff --git a/src/corelib/x11/fpgui_toolkit.lpk b/src/corelib/x11/fpgui_toolkit.lpk index 7329a3bb..55614af2 100644 --- a/src/corelib/x11/fpgui_toolkit.lpk +++ b/src/corelib/x11/fpgui_toolkit.lpk @@ -29,7 +29,7 @@ <License Value="Modified LGPL "/> <Version Minor="6" Release="3"/> - <Files Count="72"> + <Files Count="73"> <Item1> <Filename Value="../stdimages.inc"/> <Type Value="Include"/> @@ -318,6 +318,10 @@ <Filename Value="../../gui/fpg_spinedit.pas"/> <UnitName Value="fpg_spinedit"/> </Item72> + <Item73> + <Filename Value="../fpg_extgraphics.pas"/> + <UnitName Value="fpg_extgraphics"/> + </Item73> </Files> <LazDoc Paths="../../../docs/xml/corelib/;../../../docs/xml/corelib/x11/;../../../docs/xml/corelib/gdi/;../../../docs/xml/gui/"/> <RequiredPkgs Count="1"> diff --git a/src/corelib/x11/fpgui_toolkit.pas b/src/corelib/x11/fpgui_toolkit.pas index 953d2aa1..b7c3da23 100644 --- a/src/corelib/x11/fpgui_toolkit.pas +++ b/src/corelib/x11/fpgui_toolkit.pas @@ -17,7 +17,7 @@ uses fpg_iniutils, fpg_label, fpg_listbox, fpg_listview, fpg_memo, fpg_menu, fpg_mru, fpg_panel, fpg_popupcalendar, fpg_progressbar, fpg_radiobutton, fpg_scrollbar, fpg_style, fpg_tab, fpg_trackbar, fpg_tree, fpgui_db, - fpg_splitter, fpg_hint, fpg_spinedit; + fpg_splitter, fpg_hint, fpg_spinedit, fpg_extgraphics; implementation |