summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2012-03-16 00:14:08 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2012-03-16 00:14:08 +0200
commit1fd7872734ea7ddd6063edbbe66e97aba401e9de (patch)
tree1923d16b8b50eed35a4be9c65a8683defbc96e11
parentec4c45a26a2243520cd3724b71afa8f4c6e77093 (diff)
downloadfpGUI-1fd7872734ea7ddd6063edbbe66e97aba401e9de.tar.xz
agg: Define and implement most of the abstract TfpgCanvasBase methods.
-rw-r--r--src/corelib/render/software/Agg2D.pas79
-rw-r--r--src/corelib/render/software/agg_platform_gdi.inc32
-rw-r--r--src/corelib/render/software/agg_platform_x11.inc259
3 files changed, 367 insertions, 3 deletions
diff --git a/src/corelib/render/software/Agg2D.pas b/src/corelib/render/software/Agg2D.pas
index 13aa7176..6a587b7e 100644
--- a/src/corelib/render/software/Agg2D.pas
+++ b/src/corelib/render/software/Agg2D.pas
@@ -70,11 +70,22 @@ uses
{$ENDIF }
Math ,
- {$IFDEF WINDOWS}
- Windows ,
- {$ENDIF}
Classes,
SysUtils,
+
+ // This allows for platform specific uses clauses
+ {$define uses_interface}
+ {$undef agg_platform_interface}
+ {$undef uses_implementation}
+ {$undef agg_platform_implementation}
+ {$IFDEF WINDOWS}
+ {$I agg_platform_gdi.inc}
+ {$ENDIF}
+ {$IFDEF UNIX}
+ {$I agg_platform_x11.inc}
+ {$ENDIF}
+
+ fpg_base,
fpg_main;
{ GLOBAL VARIABLES & CONSTANTS }
@@ -326,6 +337,45 @@ type
m_ifSpline16 : image_filter_spline16;
m_ifSpline36 : image_filter_spline36;
m_ifBlackman144 : image_filter_blackman144;
+ protected
+
+ {$undef uses_interface}
+ {$define agg_platform_interface}
+ {$undef uses_implementation}
+ {$undef agg_platform_implementation}
+ {$IFDEF WINDOWS}
+ {$I agg_platform_gdi.inc}
+ {$ENDIF}
+ {$IFDEF UNIX}
+ {$I agg_platform_x11.inc}
+ {$ENDIF}
+
+ // ------ TfpgCanvasBase implementation requirements ---------
+ procedure DoSetFontRes(fntres: TfpgFontResourceBase); override;
+ procedure DoSetTextColor(cl: TfpgColor); override;
+ procedure DoSetColor(cl: TfpgColor); override;
+ procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override;
+ procedure DoGetWinRect(out r: TfpgRect); override;
+ procedure DoFillRectangle(x, y, w, h: TfpgCoord); override;
+ procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); override;
+ procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); override;
+ procedure DoDrawRectangle(x, y, w, h: TfpgCoord); override;
+ procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); override;
+ procedure DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi, w, h: integer); override;
+ procedure DoDrawString(x, y: TfpgCoord; const txt: string); override;
+ procedure DoSetClipRect(const ARect: TfpgRect); override;
+ function DoGetClipRect: TfpgRect; override;
+ procedure DoAddClipRect(const ARect: TfpgRect); override;
+ procedure DoClearClipRect; override;
+ procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); override;
+ procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); override;
+ 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: Extended); override;
+ procedure DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended); override;
+ procedure DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean = False); override;
+ // -------- TfpgCanvasBase end ---------------
public
constructor Create(awin: TfpgWindowBase); override;
@@ -581,6 +631,17 @@ type
IMPLEMENTATION
uses
+ // This allows for platform specific uses clauses
+ {$undef uses_interface}
+ {$undef agg_platform_interface}
+ {$define uses_implementation}
+ {$undef agg_platform_implementation}
+ {$IFDEF WINDOWS}
+ {$I agg_platform_gdi.inc}
+ {$ENDIF}
+ {$IFDEF UNIX}
+ {$I agg_platform_x11.inc}
+ {$ENDIF}
fpg_stringutils;
{ LOCAL VARIABLES & CONSTANTS }
@@ -1086,6 +1147,18 @@ begin
end;
+{$undef uses_interface}
+{$undef agg_platform_interface}
+{$undef uses_implementation}
+{$define agg_platform_implementation}
+{$IFDEF WINDOWS}
+ {$I agg_platform_gdi.inc}
+{$ENDIF}
+{$IFDEF UNIX}
+ {$I agg_platform_x11.inc}
+{$ENDIF}
+
+
{ CREATE }
constructor TAgg2D.Create(awin: TfpgWindowBase);
begin
diff --git a/src/corelib/render/software/agg_platform_gdi.inc b/src/corelib/render/software/agg_platform_gdi.inc
new file mode 100644
index 00000000..d6052d6e
--- /dev/null
+++ b/src/corelib/render/software/agg_platform_gdi.inc
@@ -0,0 +1,32 @@
+{%mainunit Agg2D.pas}
+
+{$ifdef uses_interface}
+ Windows,
+{$endif}
+
+
+{$ifdef agg_platform_interface}
+ protected
+// m_ximg_window : PXImage;
+{$endif}
+
+
+{$ifdef uses_implementation}
+ // nothing
+{$endif}
+
+
+{$ifdef agg_platform_implementation}
+
+procedure TAgg2D.DoBeginDraw(awin: TfpgWindowBase; buffered: boolean);
+begin
+
+end;
+
+procedure TAgg2D.DoEndDraw;
+begin
+
+end;
+
+{$endif}
+
diff --git a/src/corelib/render/software/agg_platform_x11.inc b/src/corelib/render/software/agg_platform_x11.inc
new file mode 100644
index 00000000..94846f8b
--- /dev/null
+++ b/src/corelib/render/software/agg_platform_x11.inc
@@ -0,0 +1,259 @@
+{%mainunit Agg2D.pas}
+
+{$ifdef uses_interface}
+ X,
+ Xlib,
+ Xutil,
+ Xatom,
+{$endif}
+
+
+{$ifdef agg_platform_interface}
+ protected
+// m_ximg_window : PXImage;
+// m_buf_window: pointer;
+// m_buf_alloc: unsigned;
+// m_bpp: unsigned;
+// m_byte_order: int;
+// m_gc: TGC;
+ FImg: TfpgImage;
+{$endif}
+
+
+{$ifdef uses_implementation}
+ fpg_x11,
+{$endif}
+
+
+{$ifdef agg_platform_implementation}
+
+type
+ // to get access to protected methods
+ TX11AppHack = class(TfpgApplication);
+ TX11ImageHack = class(TfpgImage);
+
+procedure TAgg2D.DoSetFontRes(fntres: TfpgFontResourceBase);
+begin
+ Font('/usr/share/fonts/truetype/ttf-liberation/LiberationSans-Regular.ttf', 13);
+end;
+
+procedure TAgg2D.DoSetTextColor(cl: TfpgColor);
+var
+ t: TRGBTriple;
+ c: TfpgColor;
+begin
+ c := fpgColorToRGB(cl);
+ t := fpgColorToRGBTriple(c);
+
+ FillColor(t.Red, t.Green, t.Blue{, t.Alpha});
+end;
+
+procedure TAgg2D.DoSetColor(cl: TfpgColor);
+var
+ t: TRGBTriple;
+ c: TfpgColor;
+begin
+ c := fpgColorToRGB(cl);
+ t := fpgColorToRGBTriple(c);
+
+ LineColor(t.Red, t.Green, t.Blue{, t.Alpha});
+end;
+
+procedure TAgg2D.DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle);
+begin
+// LineWidth(awidth);
+ case astyle of
+ lsSolid:
+ begin
+ m_convDash.remove_all_dashes;
+ m_convDash.add_dash(1, 0);
+ end;
+ lsDash:
+ begin
+ m_convDash.remove_all_dashes;
+ m_convDash.add_dash(3, 3);
+ end;
+ lsDot:
+ begin
+ m_convDash.remove_all_dashes;
+ m_convDash.add_dash(1, 1.5);
+ end;
+ lsDashDot:
+ begin
+ m_convDash.remove_all_dashes;
+ m_convDash.add_dash(3, 1);
+ end;
+ lsDashDotDot:
+ begin
+ m_convDash.add_dash(3, 1);
+ m_convDash.add_dash(1, 1);
+ end;
+ end;
+end;
+
+procedure TAgg2D.DoGetWinRect(out r: TfpgRect);
+begin
+ r.Left := 0;
+ r.Top := 0;
+ r.Width := FWindow.Width;
+ r.Height := FWindow.Height;
+end;
+
+procedure TAgg2D.DoFillRectangle(x, y, w, h: TfpgCoord);
+begin
+ FillColor(LineColor);
+ NoLine;
+// LineWidth(FLineWidth);
+ if (w = 1) or (h = 1) then
+ begin
+ // we have a line
+ LineCap(AGG_CapButt);
+ if w = 1 then
+ Line(x, y, x, y+h, True)
+ else
+ Line(x, y, x+w, y, True);
+ end
+ else
+ Rectangle(x, y, x+w-1, y+h-1, True);
+end;
+
+procedure TAgg2D.DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord);
+begin
+
+end;
+
+procedure TAgg2D.DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord);
+begin
+
+end;
+
+procedure TAgg2D.DoDrawRectangle(x, y, w, h: TfpgCoord);
+begin
+// LineWidth(FLineWidth);
+ DoSetColor(FColor);
+ NoFill;
+ if (w = 1) or (h = 1) then
+ begin
+ // we have a line
+ LineCap(AGG_CapButt);
+ if w = 1 then
+ Line(x, y, x, y+h, True)
+ else
+ Line(x, y, x+w, y, True);
+ end
+ else
+ Rectangle(x, y, x+w-1, y+h-1, True);
+end;
+
+procedure TAgg2D.DoDrawLine(x1, y1, x2, y2: TfpgCoord);
+begin
+ Line(x1, y1, x2, y2, True);
+end;
+
+procedure TAgg2D.DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi,
+ w, h: integer);
+begin
+ ImageFilter(AGG_NoFilter);
+ TransformImage(
+ TfpgImage(img) ,
+ xi ,yi ,
+ xi+w-1 ,
+ yi+h-1 ,
+ x ,y ,
+ x+w-1 ,
+ y+h-1 );
+end;
+
+procedure TAgg2D.DoDrawString(x, y: TfpgCoord; const txt: string);
+begin
+ DoSetTextColor(FTextColor);
+ NoLine;
+ TextHints(True);
+ Text(x, y+FontHeight, txt);
+end;
+
+procedure TAgg2D.DoSetClipRect(const ARect: TfpgRect);
+begin
+
+end;
+
+function TAgg2D.DoGetClipRect: TfpgRect;
+begin
+
+end;
+
+procedure TAgg2D.DoAddClipRect(const ARect: TfpgRect);
+begin
+
+end;
+
+procedure TAgg2D.DoClearClipRect;
+begin
+
+end;
+
+procedure TAgg2D.DoBeginDraw(awin: TfpgWindowBase; buffered: boolean);
+begin
+ if not Assigned(FImg) then
+ begin
+ FImg := TfpgImage.Create;
+ FImg.AllocateImage(32, FWindow.Width, FWindow.Height);
+ Attach(FImg);
+ end;
+end;
+
+procedure TAgg2D.DoPutBufferToScreen(x, y, w, h: TfpgCoord);
+var
+ drawgc: Tgc;
+ GcValues: TXGcValues;
+begin
+ if TfpgX11Window(FWindow).WinHandle <= 0 then
+ begin
+ writeln(' no winhandle available');
+ exit;
+ end;
+
+ FImg.UpdateImage;
+ drawgc := XCreateGc(fpgApplication.Display, TfpgX11Window(FWindow).WinHandle, 0, @GcValues);
+
+ // finally dump the image to screen!
+ XPutImage(fpgApplication.Display, TfpgX11Window(FWindow).WinHandle,
+ drawgc, TX11ImageHack(FImg).XImage, 0, 0, 0, 0,
+ FWindow.Width, FWindow.Height);
+
+ XFreeGc(fpgApplication.Display, drawgc);
+end;
+
+procedure TAgg2D.DoEndDraw;
+begin
+ // nothing to do here
+end;
+
+function TAgg2D.GetPixel(X, Y: integer): TfpgColor;
+begin
+ Result := FImg.Colors[y, y];
+end;
+
+procedure TAgg2D.SetPixel(X, Y: integer; const AValue: TfpgColor);
+begin
+ FImg.Colors[x, y] := AValue;
+end;
+
+procedure TAgg2D.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended);
+begin
+
+end;
+
+procedure TAgg2D.DoFillArc(x, y, w, h: TfpgCoord; a1, a2: Extended);
+begin
+
+end;
+
+procedure TAgg2D.DoDrawPolygon(Points: PPoint; NumPts: Integer; Winding: boolean
+ );
+begin
+
+end;
+
+{$endif}
+