diff options
-rw-r--r-- | examples/corelib/canvastest/fpgcanvas.lpi | 7 | ||||
-rw-r--r-- | examples/corelib/canvastest/fpgcanvas.lpr | 6 | ||||
-rw-r--r-- | examples/gui/timertest/timertest.lpi | 8 | ||||
-rw-r--r-- | prototypes/fpgui2/tests/edittest.lpi | 7 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_gdi.pas | 158 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 4 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 8 |
7 files changed, 140 insertions, 58 deletions
diff --git a/examples/corelib/canvastest/fpgcanvas.lpi b/examples/corelib/canvastest/fpgcanvas.lpi index 71f908fb..7f1c6c21 100644 --- a/examples/corelib/canvastest/fpgcanvas.lpi +++ b/examples/corelib/canvastest/fpgcanvas.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="/"/> + <PathDelim Value="\"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value="./"/> + <IconPath Value=".\"/> <TargetFileExt Value=""/> <Title Value="fpcanvas"/> </General> @@ -24,7 +24,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -43,6 +43,7 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> + <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/examples/corelib/canvastest/fpgcanvas.lpr b/examples/corelib/canvastest/fpgcanvas.lpr index 0f9919ff..b77c9a80 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, fpgui_package; + gfx_imgfmt_bmp, math; type @@ -158,11 +158,11 @@ begin 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.DrawArc(5, 235, 50, 50, 0, 270); // 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.FillArc(5, 290, 50, 50, 0, 270); // should overlap rectangle pixels Canvas.EndDraw; diff --git a/examples/gui/timertest/timertest.lpi b/examples/gui/timertest/timertest.lpi index 32287328..a3a2caea 100644 --- a/examples/gui/timertest/timertest.lpi +++ b/examples/gui/timertest/timertest.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="/"/> + <PathDelim Value="\"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value="./"/> + <IconPath Value=".\"/> <TargetFileExt Value=""/> </General> <VersionInfo> @@ -17,13 +17,14 @@ </VersionInfo> <PublishOptions> <Version Value="2"/> + <DestinationDirectory Value="$(TestDir)\publishedproject\"/> <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/> <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/> </PublishOptions> <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -42,6 +43,7 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> + <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/prototypes/fpgui2/tests/edittest.lpi b/prototypes/fpgui2/tests/edittest.lpi index 1ecb384f..b609d403 100644 --- a/prototypes/fpgui2/tests/edittest.lpi +++ b/prototypes/fpgui2/tests/edittest.lpi @@ -1,7 +1,7 @@ <?xml version="1.0"?> <CONFIG> <ProjectOptions> - <PathDelim Value="/"/> + <PathDelim Value="\"/> <Version Value="5"/> <General> <Flags> @@ -9,7 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> - <IconPath Value="./"/> + <IconPath Value=".\"/> <TargetFileExt Value=""/> </General> <VersionInfo> @@ -23,7 +23,7 @@ <RunParams> <local> <FormatVersion Value="1"/> - <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/> + <LaunchingApplication PathPlusParams="\usr\X11R6\bin\xterm -T 'Lazarus Run Output' -e $(LazarusDir)\tools\runwait.sh $(TargetCmdLine)"/> </local> </RunParams> <RequiredPackages Count="1"> @@ -42,6 +42,7 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> + <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas index 8912957c..5e53cf56 100644 --- a/src/corelib/gdi/gfx_gdi.pas +++ b/src/corelib/gdi/gfx_gdi.pas @@ -7,9 +7,9 @@ unit gfx_gdi; interface uses + Windows, Classes, SysUtils, - Windows, gfxbase; { Constants missing on windows unit } @@ -107,8 +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; + procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; + procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; public constructor Create; override; destructor Destroy; override; @@ -179,7 +179,8 @@ uses fpgfx, gfx_widget, gui_form, // remove this!!!!! - gfx_UTF8Utils; + gfx_UTF8Utils, + math; var wapplication: TfpgApplication; @@ -211,6 +212,105 @@ begin Result := nil; end; +{ Use CenterPoint to get the Center-Point of any rectangle. It is primarily + for use with, and in, other routines such as Quadrant, and RadialPoint. } +function CenterPoint(Rect: TRect): TPoint; +var + Tmp: Longint; +begin + with Rect do + begin + if Right < Left then + begin + Tmp := Right; + Right := Left; + Left := Tmp; + end; + + if Bottom < Top then + begin + Tmp := Bottom; + Bottom := Top; + Top := Tmp; + end; + + Result.X := Left + (Right - Left) div 2; + Result.Y := Top + (Bottom - Top) div 2; + end; +end; + +{ Use LineEndPoint to get the End-Point of a line of any given Length at + any given angle with any given Start-Point. It is primarily for use in + other routines such as RadialPoint. The angle is in 1/16th of a degree. + For example, a full circle equals 5760 (16*360). Zero degrees is at the + 3'o clock position. } +function LineEndPoint(StartPoint: TPoint; Angle, Length: Extended): TPoint; +begin + if Angle > 360*16 then + Angle := Frac(Angle / 360*16) * 360*16; + + if Angle < 0 then + Angle := 360*16 - abs(Angle); + + Result.Y := StartPoint.Y - Round(Length*Sin(DegToRad(Angle/16))); + Result.X := StartPoint.X + Round(Length*Cos(DegToRad(Angle/16))); +end; + +{ Use EllipseRadialLength to get the Radial-Length of non-rotated ellipse at + any given Eccentric( aka Radial ) Angle. It is primarily for use in other + routines such as RadialPoint. The Eccentric angle is in 1/16th of a degree. + For example, a full circle equals 5760 (16*360). Zero degrees is at the + 3'o clock position. } +function EllipseRadialLength(Rect: TRect; EccentricAngle: Extended): Longint; +var + a, b, R: Extended; +begin + a := (Rect.Right - Rect.Left) div 2; + b := (Rect.Bottom - Rect.Top) div 2; + R := Sqr(a)*Sqr(b); + R := Sqrt(R / ((Sqr(b)*Sqr(Cos(DegToRad(EccentricAngle/16)))) + + (Sqr(a)*Sqr(Sin(DegToRad(EccentricAngle/16)))))); + Result := integer(Trunc(R)); +end; + +{ Use RadialPoint to get the Radial-Point at any given Eccentric( aka Radial ) + angle on any non-rotated ellipse. It is primarily for use in Angles2Coords. + The EccentricAngle is in 1/16th of a degree. For example, a full circle + equals 5760 (16*360). Zero degrees is at the 3'o clock position. } +function RadialPoint(EccentricAngle: Extended; Rect: TRect): TPoint; +var + R: Longint; +Begin + R := EllipseRadialLength(Rect, EccentricAngle); + Result := LineEndPoint(CenterPoint(Rect), EccentricAngle, R); +end; + +{ Use Angles2Coords to convert an Eccentric(aka Radial) Angle and an + Angle-Length, such as are used in X-Windows and GTK, into the coords, + for Start and End Radial-Points, such as are used in the Windows API Arc + Pie and Chord routines. The angles are 1/16th of a degree. For example, a + full circle equals 5760 (16*360). Positive values of Angle and AngleLength + mean counter-clockwise while negative values mean clockwise direction. + Zero degrees is at the 3'o clock position. } +procedure Angles2Coords(X, Y, Width, Height: Integer; Angle1, Angle2: Extended; + var SX, SY, EX, EY: Integer); +var + aRect: TRect; + SP, EP: TPoint; +begin + aRect := Classes.Rect(X, Y, X+Width, Y+Height); + SP := RadialPoint(Angle1, aRect); + if Angle2 + Angle1 > 360*16 then + Angle2 := (Angle2 + Angle1) - 360*16 + else + Angle2 := Angle2 + Angle1; + EP := RadialPoint(Angle2, aRect); + SX := SP.X; + SY := SP.Y; + EX := EP.X; + EY := EP.Y; +end; + (* procedure SendMouseMessage(wg : TWidget; msg : UINT; button : integer; wParam : WPARAM; lParam : LPARAM); var @@ -1065,46 +1165,24 @@ 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) - ); -(* +procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); 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} -*) + SX, SY, EX, EY: Longint; +begin + Angles2Coords(x, y, w, h, a1*16, a2*16, SX, SY, EX, EY); + {$IFNDEF wince} + Windows.Arc(Fgc, x, y, x+w, y+h, SX, SY, EX, EY); + {$ENDIF} end; -procedure TfpgCanvasImpl.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: double); +procedure TfpgCanvasImpl.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); 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) - ); + SX, SY, EX, EY: Longint; +begin + Angles2Coords(x, y, w, h, a1*16, a2*16, SX, SY, EX, EY); + {$IFNDEF wince} + Windows.Pie(Fgc, x, y, x+w, y+h, SX, SY, EX, EY); + {$ENDIF} end; procedure TfpgCanvasImpl.DoPutBufferToScreen(x, y, w, h: TfpgCoord); diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index d66d1604..5add81ad 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -249,8 +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; + procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); virtual; abstract; + procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); virtual; abstract; public constructor Create; virtual; destructor Destroy; override; diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 279c5eba..a010c298 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -116,8 +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; + procedure DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; + procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override; public constructor Create; override; destructor Destroy; override; @@ -1311,13 +1311,13 @@ begin {$Note We must still implement DrawPoint} end; -procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: double); +procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); 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); +procedure TfpgCanvasImpl.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); begin XFillArc(xapplication.display, FDrawHandle, Fgc, x, y, w, h, Trunc(64 * a1), Trunc(64 * a2)); |