summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-25 09:29:31 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-25 09:29:31 +0000
commit1a5fd690766d2dd1805a9b9d0b76d5caa9ffe528 (patch)
tree83ad623610c5e4b90aef852a994e5d48643e7f15
parent083bdeb224ff6a54a0b494f3a08b067d1d478981 (diff)
downloadfpGUI-1a5fd690766d2dd1805a9b9d0b76d5caa9ffe528.tar.xz
* Implemented two new canvas functions. DrawArc() and FillArc()
-rw-r--r--examples/corelib/canvastest/fpgcanvas.lpi2
-rw-r--r--examples/corelib/canvastest/fpgcanvas.lpr20
-rw-r--r--src/corelib/gdi/gfx_gdi.pas46
-rw-r--r--src/corelib/gfxbase.pas14
-rw-r--r--src/corelib/x11/gfx_x11.pas14
5 files changed, 87 insertions, 9 deletions
diff --git a/examples/corelib/canvastest/fpgcanvas.lpi b/examples/corelib/canvastest/fpgcanvas.lpi
index 6ba29e31..71f908fb 100644
--- a/examples/corelib/canvastest/fpgcanvas.lpi
+++ b/examples/corelib/canvastest/fpgcanvas.lpi
@@ -29,7 +29,7 @@
</RunParams>
<RequiredPackages Count="1">
<Item1>
- <PackageName Value="fpgfx_package"/>
+ <PackageName Value="fpgui_package"/>
<MinVersion Minor="5" Valid="True"/>
</Item1>
</RequiredPackages>
diff --git a/examples/corelib/canvastest/fpgcanvas.lpr b/examples/corelib/canvastest/fpgcanvas.lpr
index 4e3b0944..0f9919ff 100644
--- a/examples/corelib/canvastest/fpgcanvas.lpr
+++ b/examples/corelib/canvastest/fpgcanvas.lpr
@@ -10,7 +10,7 @@ uses
fpgfx,
gfxbase,
gui_form,
- gfx_imgfmt_bmp;
+ gfx_imgfmt_bmp, fpgui_package;
type
@@ -144,12 +144,6 @@ begin
Canvas.DrawLine(183, 303, 247, 303);
-// Stretch(bmp, dst, ResampleFilters[6].Filter, ResampleFilters[6].Width);
-//// Canvas.DrawImage(150, 240, bmp);
-// Canvas.DrawImage(160, 250, dst);
-
-
-
// Testing Canvas.Pixels[]
// two pixels should have changed color in the top left of the form
Canvas.Pixels[7,5] := clBlue; // This tests consistant bit order handling (RGB)
@@ -158,6 +152,18 @@ begin
Canvas.Pixels[9,5] := c;
c := Canvas.Pixels[150 + (32*4) + 3, 199]; // should be lightblue like color
Canvas.Pixels[10,5] := c;
+
+
+ // Arc drawing tests
+ Canvas.SetColor(clBlack);
+ Canvas.DrawRectangle(5, 235, 50, 50);
+ Canvas.SetColor(clRed);
+ Canvas.DrawArc(5, 235, 50, 50, 0, 360); // should overlap rectangle pixels
+ Canvas.SetColor(clBlack);
+ Canvas.DrawRectangle(5, 290, 50, 50);
+ Canvas.SetColor(clRed);
+ Canvas.FillArc(5, 290, 50, 50, 0, 360); // should overlap rectangle pixels
+
Canvas.EndDraw;
end;
diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas
index 6aa7f910..8912957c 100644
--- a/src/corelib/gdi/gfx_gdi.pas
+++ b/src/corelib/gdi/gfx_gdi.pas
@@ -107,6 +107,8 @@ type
procedure DoEndDraw; override;
function GetPixel(X, Y: integer): TfpgColor; override;
procedure SetPixel(X, Y: integer; const AValue: TfpgColor); override;
+ procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double); override;
+ procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double); override;
public
constructor Create; override;
destructor Destroy; override;
@@ -1063,6 +1065,48 @@ begin
Windows.SetPixel(Fgc, X, Y, fpgColorToWin(AValue));
end;
+procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double);
+var
+ xr: double;
+ yr: double;
+begin
+ xr := w / 2;
+ yr := h / 2;
+ Arc(Fgc, x, y, x+w, y+h,
+ Trunc(0.5 + x + xr + cos(a1)*xr),
+ Trunc(0.5 + y + yr - sin(a1)*yr),
+ Trunc(0.5 + x + xr + cos(a1+a2)*xr),
+ Trunc(0.5 + y + yr - sin(a1+a2)*yr)
+ );
+(*
+var
+ SX, SY, EX, EY : Longint;
+begin
+ {$Warning DoDrawArc needs testing. }
+ Angles2Coords(ARect.Left, ARect.Top, ARect.Right - ARect.Left,
+ ARect.Bottom - ARect.Top, StartAngle, EndAngle, SX, SY, EX, EY);
+ {$ifndef wince}
+ Windows.Arc(Handle, ARect.Left, ARect.Top, ARect.Right,
+ ARect.Bottom, SX, SY, EX, EY)
+ {$endif}
+*)
+end;
+
+procedure TfpgCanvasImpl.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double);
+var
+ xr: double;
+ yr: double;
+begin
+ xr := w / 2;
+ yr := h / 2;
+ Pie(Fgc, x, y, x+w, y+h,
+ Trunc(0.5 + x + xr + cos(a1)*xr),
+ Trunc(0.5 + y + yr - sin(a1)*yr),
+ Trunc(0.5 + x + xr + cos(a1+a2)*xr),
+ Trunc(0.5 + y + yr - sin(a1+a2)*yr)
+ );
+end;
+
procedure TfpgCanvasImpl.DoPutBufferToScreen(x, y, w, h: TfpgCoord);
begin
if FBufferBitmap > 0 then
@@ -1250,7 +1294,7 @@ begin
SelectObject(tmpdc, TfpgImageImpl(img).BMPHandle);
if TfpgImageImpl(img).FIsTwoColor then
- rop := PATCOPY //ROP_DSPDxax
+ rop := PATCOPY
else
rop := SRCCOPY;
diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas
index 2b677e57..d66d1604 100644
--- a/src/corelib/gfxbase.pas
+++ b/src/corelib/gfxbase.pas
@@ -249,6 +249,8 @@ type
procedure DoEndDraw; virtual; abstract;
function GetPixel(X, Y: integer): TfpgColor; virtual; abstract;
procedure SetPixel(X, Y: integer; const AValue: TfpgColor); virtual; abstract;
+ procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double); virtual; abstract;
+ procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double); virtual; abstract;
public
constructor Create; virtual;
destructor Destroy; override;
@@ -257,12 +259,14 @@ type
procedure DrawLine(x1, y1, x2, y2: TfpgCoord);
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 StretchDraw (x, y, w, h: TfpgCoord; ASource: TfpgImageBase);
procedure CopyRect(x, y: TfpgCoord; ACanvas: TfpgCanvasBase; var SourceRect: TRect);
procedure DrawString(x, y: TfpgCoord; const txt: string);
procedure FillRectangle(x, y, w, h: TfpgCoord); overload;
procedure FillRectangle(r: TfpgRect); overload;
procedure FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord);
+ procedure FillArc(x, y, w, h: TfpgCoord; a1, a2: double);
procedure XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); overload;
procedure XORFillRectangle(col: TfpgColor; r: TfpgRect); overload;
procedure SetClipRect(const rect: TfpgRect);
@@ -748,6 +752,11 @@ begin
DoDrawImagePart(x, y, img, xi, yi, w, h);
end;
+procedure TfpgCanvasBase.DrawArc(x, y, w, h: TfpgCoord; a1, a2: double);
+begin
+ DoDrawArc(x, y, w, h, a1, a2);
+end;
+
procedure TfpgCanvasBase.StretchDraw(x, y, w, h: TfpgCoord; ASource: TfpgImageBase);
var
i: TfpgCustomInterpolation;
@@ -822,6 +831,11 @@ begin
DoFillTriangle(x1, y1, x2, y2, x3, y3);
end;
+procedure TfpgCanvasBase.FillArc(x, y, w, h: TfpgCoord; a1, a2: double);
+begin
+ DoFillArc(x, y, w, h, a1, a2);
+end;
+
procedure TfpgCanvasBase.XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord);
begin
DoXORFillRectangle(col, x, y, w, h);
diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas
index d5a09843..279c5eba 100644
--- a/src/corelib/x11/gfx_x11.pas
+++ b/src/corelib/x11/gfx_x11.pas
@@ -116,6 +116,8 @@ type
procedure DoEndDraw; override;
function GetPixel(X, Y: integer): TfpgColor; override;
procedure SetPixel(X, Y: integer; const AValue: TfpgColor); override;
+ procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double); override;
+ procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double); override;
public
constructor Create; override;
destructor Destroy; override;
@@ -1309,6 +1311,18 @@ begin
{$Note We must still implement DrawPoint}
end;
+procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double);
+begin
+ XDrawArc(xapplication.display, FDrawHandle, Fgc, x, y, w-1, h-1,
+ Trunc(64 * a1), Trunc(64 * a2));
+end;
+
+procedure TfpgCanvasImpl.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double);
+begin
+ XFillArc(xapplication.display, FDrawHandle, Fgc, x, y, w, h,
+ Trunc(64 * a1), Trunc(64 * a2));
+end;
+
procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceBase);
begin
if fntres = nil then