diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-06 22:46:50 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-06 22:46:50 +0000 |
commit | c3cd981fa5692460b807ca064cedea553fcd837d (patch) | |
tree | ce1568e8956bf3aa20fd2d633b2f9b9de8e0142d /prototypes | |
parent | 342d49d4249e9f2e6bef86cec00fd865cfd890b2 (diff) | |
download | fpGUI-c3cd981fa5692460b807ca064cedea553fcd837d.tar.xz |
Refactored a lot of the Canvas class. Only tested under Linux, but should work under Windows.
Minor performance improvement in the fpgcanvas test project.
Minor changes to the edittest test project.
Diffstat (limited to 'prototypes')
-rw-r--r-- | prototypes/fpgui2/examples/core/helloworld/helloworld.lpi | 1 | ||||
-rw-r--r-- | prototypes/fpgui2/examples/gui/stdimages/stdimglist.lpi | 1 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/fpgfx.pas | 189 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/gdi/gfx_gdi.pas | 78 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/gfxbase.pas | 234 | ||||
-rw-r--r-- | prototypes/fpgui2/source/core/x11/gfx_x11.pas | 69 | ||||
-rw-r--r-- | prototypes/fpgui2/tests/edittest.lpi | 7 | ||||
-rw-r--r-- | prototypes/fpgui2/tests/fpgcanvas.lpr | 48 |
8 files changed, 335 insertions, 292 deletions
diff --git a/prototypes/fpgui2/examples/core/helloworld/helloworld.lpi b/prototypes/fpgui2/examples/core/helloworld/helloworld.lpi index c2762521..9ee223bd 100644 --- a/prototypes/fpgui2/examples/core/helloworld/helloworld.lpi +++ b/prototypes/fpgui2/examples/core/helloworld/helloworld.lpi @@ -9,6 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> diff --git a/prototypes/fpgui2/examples/gui/stdimages/stdimglist.lpi b/prototypes/fpgui2/examples/gui/stdimages/stdimglist.lpi index 8ec0e1a4..28d0f2e9 100644 --- a/prototypes/fpgui2/examples/gui/stdimages/stdimglist.lpi +++ b/prototypes/fpgui2/examples/gui/stdimages/stdimglist.lpi @@ -9,6 +9,7 @@ </Flags> <SessionStorage Value="InProjectDir"/> <MainUnit Value="0"/> + <IconPath Value="./"/> <TargetFileExt Value=""/> </General> <VersionInfo> diff --git a/prototypes/fpgui2/source/core/fpgfx.pas b/prototypes/fpgui2/source/core/fpgfx.pas index 6ca78510..c69edc13 100644 --- a/prototypes/fpgui2/source/core/fpgfx.pas +++ b/prototypes/fpgui2/source/core/fpgfx.pas @@ -66,19 +66,9 @@ type TfpgFont = class(TfpgFontBase) - private - FFontDesc: string; - FFontRes: TfpgFontResource; public constructor Create(afontres: TfpgFontResource; const afontdesc: string); destructor Destroy; override; - function TextWidth(const txt: string): integer; - function Ascent: integer; - function Descent: integer; - function Height: integer; - property FontDesc: string read FFontDesc; - property FontRes: TfpgFontResource read FFontRes; - property Handle: TfpgFontResource read FFontRes; end; @@ -105,15 +95,6 @@ type TfpgImage = class(TfpgImageImpl) - protected - FWidth: integer; - FHeight: integer; - FColorDepth: integer; - FMasked: boolean; - FImageData: pointer; - FImageDataSize: integer; - FMaskData: pointer; - FMaskDataSize: integer; public constructor Create; destructor Destroy; override; @@ -123,14 +104,6 @@ type procedure Invert; procedure UpdateImage; procedure CreateMaskFromSample(x, y: integer); - property ImageData: pointer read FImageData; - property ImageDataSize: integer read FImageDataSize; - property MaskData: pointer read FMaskData; - property MaskDataSize: integer read FMaskDataSize; - property Width: integer read FWidth; - property Height: integer read FHeight; - property ColorDepth: integer read FColorDepth; - property Masked: boolean read FMasked; end; @@ -150,55 +123,26 @@ type TfpgCanvas = class(TfpgCanvasImpl) - private - FColorText: TfpgColor; protected - FBufferedDraw: boolean; FPersistentResources: boolean; - FWindow: TfpgWindow; - FColor: TfpgColor; - FTextColor: TfpgColor; - FFont: TfpgFont; - FLineWidth: integer; - FLineStyle: TfpgLineStyle; - FBeginDrawCount: integer; public constructor Create(awin: TfpgWindow); reintroduce; destructor Destroy; override; - procedure BeginDraw; overload; - procedure BeginDraw(abuffered: boolean); overload; procedure EndDraw(x, y, w, h: TfpgCoord); overload; procedure EndDraw; overload; procedure FreeResources; - procedure SetFont(fnt: TfpgFont); - procedure SetColor(cl: TfpgColor); - procedure SetTextColor(cl: TfpgColor); - procedure SetLineStyle(awidth: integer; astyle: TfpgLineStyle); - procedure DrawString(x, y: TfpgCoord; const txt: string); procedure Clear(col: TfpgColor); procedure GetWinRect(var r: TfpgRect); - procedure FillRectangle(x, y, w, h: TfpgCoord); overload; - procedure FillRectangle(r: TfpgRect); overload; procedure XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); procedure XORFillRect(col: TfpgColor; r: TfpgRect); procedure FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); - procedure DrawRectangle(x, y, w, h: TfpgCoord); - procedure DrawRect(r: TfpgRect); - procedure DrawLine(x1, y1, x2, y2: TfpgCoord); - procedure SetClipRect(const rect: TfpgRect); - function GetClipRect: TfpgRect; - procedure AddClipRect(const rect: TfpgRect); - procedure ClearClipRect; - procedure DrawImage(x, y: TfpgCoord; img: TfpgImage); - procedure DrawImagePart(x, y: TfpgCoord; img: TfpgImage; xi, yi, w, h: integer); + procedure DrawButtonFace(x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); procedure DrawControlFrame(x, y, w, h: TfpgCoord); procedure DrawDirectionArrow(x, y, w, h: TfpgCoord; direction: integer); - property Font: TfpgFont read FFont write SetFont; - property Color: TfpgColor read FColor; - property TextColor: TfpgColor read FColorText; end; + { This is very basic for now, just to remind us of theming support. Later we will rework this to use a Style Manager like the previous fpGUI. Styles must also move out of fpGFX. Also support Bitmap based styles for easier theme @@ -648,26 +592,6 @@ begin inherited; end; -function TfpgFont.TextWidth(const txt: string): integer; -begin - Result := FFontRes.GetTextWidth(txt); -end; - -function TfpgFont.Ascent: integer; -begin - Result := FFontRes.GetAscent; -end; - -function TfpgFont.Descent: integer; -begin - Result := FFontRes.GetDescent; -end; - -function TfpgFont.Height: integer; -begin - Result := FFontRes.GetHeight; -end; - { TfpgFontResource } constructor TfpgFontResource.Create(const afontdesc: string); @@ -709,28 +633,6 @@ begin inherited Destroy; end; -procedure TfpgCanvas.BeginDraw; -begin - BeginDraw(FBufferedDraw); -end; - -procedure TfpgCanvas.BeginDraw(abuffered: boolean); -begin - if FBeginDrawCount < 1 then - begin - DoBeginDraw(FWindow, abuffered); - - SetColor(clText1); - SetTextColor(clText1); - SetFont(fpgApplication.DefaultFont); - - SetLineStyle(0, lsSolid); - - FBeginDrawCount := 0; - end; - Inc(FBeginDrawCount); -end; - procedure TfpgCanvas.EndDraw(x, y, w, h: TfpgCoord); begin if FBeginDrawCount > 0 then @@ -757,36 +659,6 @@ begin FBeginDrawCount := 0; end; -procedure TfpgCanvas.SetFont(fnt: TfpgFont); -begin - FFont := fnt; - DoSetFontRes(fnt.FFontRes); -end; - -procedure TfpgCanvas.SetTextColor(cl: TfpgColor); -begin - FTextColor := cl; - DoSetTextColor(FTextColor); -end; - -procedure TfpgCanvas.SetColor(cl: TfpgColor); -begin - FColor := cl; - DoSetColor(FColor); -end; - -procedure TfpgCanvas.SetLineStyle(awidth: integer; astyle: TfpgLineStyle); -begin - FLineWidth := awidth; - FLineStyle := astyle; - DoSetLineStyle(FLineWidth, FLineStyle); -end; - -procedure TfpgCanvas.DrawString(x, y: TfpgCoord; const txt: string); -begin - DoDrawString(x, y, txt); -end; - procedure TfpgCanvas.Clear(col: TfpgColor); var ACol: TfpgColor; @@ -804,11 +676,6 @@ begin DoGetWinRect(r); end; -procedure TfpgCanvas.FillRectangle(x, y, w, h: TfpgCoord); -begin - DoFillRectangle(x, y, w, h); -end; - procedure TfpgCanvas.XORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); begin DoXORFillRectangle(col, x, y, w, h); @@ -819,63 +686,11 @@ begin DoXORFillRectangle(col, r.Left, r.Top, r.Width, r.Height); end; -procedure TfpgCanvas.FillRectangle(r: TfpgRect); -begin - DoFillRectangle(r.Left, r.Top, r.Width, r.Height); -end; - procedure TfpgCanvas.FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); begin DoFillTriangle(x1, y1, x2, y2, x3, y3); end; -procedure TfpgCanvas.DrawRectangle(x, y, w, h: TfpgCoord); -begin - DoDrawRectangle(x, y, w, h); -end; - -procedure TfpgCanvas.DrawRect(r: TfpgRect); -begin - DoDrawRectangle(r.Left, r.Top, r.Width, r.Height); -end; - -procedure TfpgCanvas.DrawLine(x1, y1, x2, y2: TfpgCoord); -begin - DoDrawLine(x1, y1, x2, y2); -end; - -procedure TfpgCanvas.SetClipRect(const rect: TfpgRect); -begin - DoSetClipRect(rect); -end; - -function TfpgCanvas.GetClipRect: TfpgRect; -begin - Result := DoGetClipRect; -end; - -procedure TfpgCanvas.AddClipRect(const rect: TfpgRect); -begin - DoAddClipRect(rect); -end; - -procedure TfpgCanvas.ClearClipRect; -begin - DoClearClipRect; -end; - -procedure TfpgCanvas.DrawImage(x, y: TfpgCoord; img: TfpgImage); -begin - if img = nil then - exit; - DrawImagePart(x, y, img, 0, 0, img.Width, img.Height); -end; - -procedure TfpgCanvas.DrawImagePart(x, y: TfpgCoord; img: TfpgImage; xi, yi, w, h: integer); -begin - DoDrawImagePart(x, y, img, xi, yi, w, h); -end; - procedure TfpgCanvas.DrawButtonFace(x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); begin fpgStyle.DrawButtonFace(self, x, y, w, h, AFlags); diff --git a/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas b/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas index f84a331a..ed8d3065 100644 --- a/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas +++ b/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas @@ -40,10 +40,10 @@ type constructor Create(const afontdesc: string); destructor Destroy; override; function HandleIsValid: boolean; - function GetAscent: integer; - function GetDescent: integer; - function GetHeight: integer; - function GetTextWidth(const txt: string): integer; + function GetAscent: integer; override; + function GetDescent: integer; override; + function GetHeight: integer; override; + function GetTextWidth(const txt: string): integer; override; end; @@ -72,39 +72,35 @@ type FDrawing: boolean; FBufferBitmap: HBitmap; FDrawWindow: TfpgWindowImpl; - Fgc, FWinGC: TfpgGContext; - FColorText: TfpgColor; - FColor: TfpgColor; + Fgc: TfpgGContext; + FWinGC: TfpgGContext; FBackgroundColor: TfpgColor; FCurFontRes: TfpgFontResourceImpl; FClipRect: TfpgRect; FClipRectSet: Boolean; - FLineStyle: integer; - FLineWidth: integer; FWindowsColor: longword; FBrush: HBRUSH; FPen: HPEN; FClipRegion: HRGN; FIntLineStyle: integer; - FIntLineWidth: integer; protected - procedure DoSetFontRes(fntres: TfpgFontResourceImpl); - procedure DoSetTextColor(cl: TfpgColor); - procedure DoSetColor(cl: TfpgColor); - procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); - procedure DoDrawString(x, y: TfpgCoord; const txt: string); + procedure DoSetFontRes(fntres: TfpgFontResourceBase); override; + procedure DoSetTextColor(cl: TfpgColor); override; + procedure DoSetColor(cl: TfpgColor); override; + procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; procedure DoGetWinRect(var r: TfpgRect); - procedure DoFillRectangle(x, y, w, h: TfpgCoord); + procedure DoFillRectangle(x, y, w, h: TfpgCoord); override; procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); - procedure DoDrawRectangle(x, y, w, h: TfpgCoord); - procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); - procedure DoSetClipRect(const rect: TfpgRect); - function DoGetClipRect: TfpgRect; - procedure DoAddClipRect(const rect: TfpgRect); - procedure DoClearClipRect; - procedure DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageImpl; xi, yi, w, h: integer); - procedure DoBeginDraw(awin: TfpgWindowImpl; buffered: boolean); + 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 rect: TfpgRect); override; + function DoGetClipRect: TfpgRect; override; + procedure DoAddClipRect(const rect: TfpgRect); override; + procedure DoClearClipRect; override; + procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); override; procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); procedure DoEndDraw; public @@ -869,7 +865,7 @@ begin inherited; end; -procedure TfpgCanvasImpl.DoBeginDraw(awin: TfpgWindowImpl; buffered: boolean); +procedure TfpgCanvasImpl.DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); var ARect: TfpgRect; bmsize: Windows.TSIZE; @@ -878,7 +874,7 @@ begin begin // check if the dimensions are ok GetBitmapDimensionEx(FBufferBitmap, bmsize); - FDrawWindow := awin; + FDrawWindow := TfpgWindowImpl(awin); DoGetWinRect(ARect); if (bmsize.cx <> ARect.Width) or (bmsize.cy <> ARect.Height) then DoEndDraw; @@ -886,7 +882,7 @@ begin if not FDrawing then begin - FDrawWindow := awin; + FDrawWindow := TfpgWindowImpl(awin); FWinGC := Windows.GetDC(FDrawWindow.FWinHandle); if buffered then @@ -1059,7 +1055,7 @@ begin FWindowsColor := fpgColorToWin(cl); FBrush := CreateSolidBrush(FWindowsColor); - FPen := CreatePen(FintLineStyle, FintLineWidth, FWindowsColor); + FPen := CreatePen(FintLineStyle, FLineWidth, FWindowsColor); SelectObject(Fgc, FBrush); SelectObject(Fgc, FPen); end; @@ -1069,29 +1065,29 @@ begin { Notes from MSDN: If the value specified by nWidth is greater than 1, the fnPenStyle parameter must be PS_NULL, PS_SOLID, or PS_INSIDEFRAME. } - FintLineWidth := awidth; + FLineWidth := awidth; case AStyle of lsDot: begin FintLineStyle := PS_DOT; - FintLineWidth := 1; + FLineWidth := 1; end; lsDash: begin FintLineStyle := PS_DASH; - FintLineWidth := 1; + FLineWidth := 1; end; lsSolid: FintLineStyle := PS_SOLID; else begin FintLineStyle := PS_DOT; - FintLineWidth := 1; + FLineWidth := 1; end; end; DeleteObject(FPen); - FPen := CreatePen(FintLineStyle, FintLineWidth, FWindowsColor); + FPen := CreatePen(FintLineStyle, FLineWidth, FWindowsColor); SelectObject(Fgc, FPen); end; @@ -1100,15 +1096,15 @@ begin Windows.SetTextColor(Fgc, fpgColorToWin(cl)); end; -procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceImpl); +procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceBase); begin if fntres = nil then - Exit; - FCurFontRes := fntres; + Exit; //==> + FCurFontRes := TfpgFontResourceImpl(fntres); Windows.SelectObject(Fgc, FCurFontRes.Handle); end; -procedure TfpgCanvasImpl.DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageImpl; xi, yi, w, h: integer); +procedure TfpgCanvasImpl.DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi, w, h: integer); const DSTCOPY = $00AA0029; ROP_DSPDxax = $00E20746; @@ -1117,18 +1113,18 @@ var rop: longword; begin if img = nil then - Exit; + Exit; //==> tmpdc := CreateCompatibleDC(wapplication.display); - SelectObject(tmpdc, img.BMPHandle); + SelectObject(tmpdc, TfpgImageImpl(img).BMPHandle); if img.FIsTwoColor then rop := PATCOPY //ROP_DSPDxax else rop := SRCCOPY; - if img.MaskHandle > 0 then - MaskBlt(Fgc, x, y, w, h, tmpdc, xi, yi, img.MaskHandle, xi, yi, MakeRop4(rop, DSTCOPY)) + if TfpgImageImpl(img).MaskHandle > 0 then + MaskBlt(Fgc, x, y, w, h, tmpdc, xi, yi, TfpgImageImpl(img).MaskHandle, xi, yi, MakeRop4(rop, DSTCOPY)) else BitBlt(Fgc, x, y, w, h, tmpdc, xi, yi, rop); diff --git a/prototypes/fpgui2/source/core/gfxbase.pas b/prototypes/fpgui2/source/core/gfxbase.pas index 00e72e84..e901caf8 100644 --- a/prototypes/fpgui2/source/core/gfxbase.pas +++ b/prototypes/fpgui2/source/core/gfxbase.pas @@ -171,18 +171,110 @@ type TfpgImageBase = class(TObject) + protected + FWidth: integer; + FHeight: integer; + FColorDepth: integer; + FMasked: boolean; + FImageData: pointer; + FImageDataSize: integer; + FMaskData: pointer; + FMaskDataSize: integer; + public + property ImageData: pointer read FImageData; + property ImageDataSize: integer read FImageDataSize; + property MaskData: pointer read FMaskData; + property MaskDataSize: integer read FMaskDataSize; + property Width: integer read FWidth; + property Height: integer read FHeight; + property ColorDepth: integer read FColorDepth; + property Masked: boolean read FMasked; end; - TfpgCanvasBase = class(TObject) + TfpgFontResourceBase = class(TObject) + public + function GetAscent: integer; virtual; abstract; + function GetDescent: integer; virtual; abstract; + function GetHeight: integer; virtual; abstract; + function GetTextWidth(const txt: string): integer; virtual; abstract; end; - TfpgFontResourceBase = class(TObject) + { TfpgFontBase } + + TfpgFontBase = class(TObject) + protected + FFontDesc: string; + FFontRes: TfpgFontResourceBase; + public + function TextWidth(const txt: string): integer; + function Ascent: integer; + function Descent: integer; + function Height: integer; + property FontDesc: string read FFontDesc; + property FontRes: TfpgFontResourceBase read FFontRes; + property Handle: TfpgFontResourceBase read FFontRes; end; - TfpgFontBase = class(TObject) + // forward declaration + TfpgWindowBase = class; + + + { TfpgCanvasBase } + + TfpgCanvasBase = class(TObject) + protected + FBufferedDraw: boolean; + FBeginDrawCount: integer; + FWindow: TfpgWindowBase; + FColor: TfpgColor; + FTextColor: TfpgColor; + FLineWidth: integer; + FLineStyle: TfpgLineStyle; + FFont: TfpgFontBase; + procedure DoSetFontRes(fntres: TfpgFontResourceBase); virtual; abstract; + procedure DoSetTextColor(cl: TfpgColor); virtual; abstract; + procedure DoSetColor(cl: TfpgColor); virtual; abstract; + procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); virtual; abstract; + procedure DoGetWinRect(var r: TfpgRect); virtual; abstract; + procedure DoFillRectangle(x, y, w, h: TfpgCoord); virtual; abstract; + procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); virtual; abstract; + procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); virtual; abstract; + procedure DoDrawRectangle(x, y, w, h: TfpgCoord); virtual; abstract; + procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); virtual; abstract; + procedure DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi, w, h: integer); virtual; abstract; + procedure DoDrawString(x, y: TfpgCoord; const txt: string); virtual; abstract; + procedure DoSetClipRect(const rect: TfpgRect); virtual; abstract; + function DoGetClipRect: TfpgRect; virtual; abstract; + procedure DoAddClipRect(const rect: TfpgRect); virtual; abstract; + procedure DoClearClipRect; virtual; abstract; + procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); virtual; abstract; + procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); virtual; abstract; + procedure DoEndDraw; virtual; abstract; + public + procedure DrawRectangle(x, y, w, h: TfpgCoord); overload; + procedure DrawRectangle(r: TfpgRect); overload; + 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 DrawString(x, y: TfpgCoord; const txt: string); + procedure FillRectangle(x, y, w, h: TfpgCoord); overload; + procedure FillRectangle(r: TfpgRect); overload; + procedure SetClipRect(const rect: TfpgRect); + function GetClipRect: TfpgRect; + procedure AddClipRect(const rect: TfpgRect); + procedure ClearClipRect; + procedure SetColor(AColor: TfpgColor); + procedure SetTextColor(AColor: TfpgColor); + procedure SetLineStyle(AWidth: integer; AStyle: TfpgLineStyle); + procedure SetFont(AFont: TfpgFontBase); + procedure BeginDraw; overload; + procedure BeginDraw(ABuffered: boolean); overload; + property Color: TfpgColor read FColor; + property TextColor: TfpgColor read FTextColor; + property Font: TfpgFontBase read FFont write SetFont; end; @@ -225,6 +317,9 @@ type implementation +uses + fpgfx; // needed for fpgApplication + { TfpgRect } procedure TfpgRect.SetRect(aleft, atop, awidth, aheight: TfpgCoord); @@ -267,5 +362,138 @@ begin // does nothing end; +{ TfpgCanvasBase } + +procedure TfpgCanvasBase.DrawRectangle(x, y, w, h: TfpgCoord); +begin + DoDrawRectangle(x, y, w, h); +end; + +procedure TfpgCanvasBase.DrawRectangle(r: TfpgRect); +begin + DoDrawRectangle(r.Left, r.Top, r.Width, r.Height); +end; + +procedure TfpgCanvasBase.DrawLine(x1, y1, x2, y2: TfpgCoord); +begin + DoDrawLine(x1, y1, x2, y2); +end; + +procedure TfpgCanvasBase.DrawImage(x, y: TfpgCoord; img: TfpgImageBase); +begin + if img = nil then + Exit; //==> + DrawImagePart(x, y, img, 0, 0, img.Width, img.Height); +end; + +procedure TfpgCanvasBase.DrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, + yi, w, h: integer); +begin + DoDrawImagePart(x, y, img, xi, yi, w, h); +end; + +procedure TfpgCanvasBase.DrawString(x, y: TfpgCoord; const txt: string); +begin + DoDrawString(x, y, txt); +end; + +procedure TfpgCanvasBase.FillRectangle(x, y, w, h: TfpgCoord); +begin + DoFillRectangle(x, y, w, h); +end; + +procedure TfpgCanvasBase.FillRectangle(r: TfpgRect); +begin + DoFillRectangle(r.Left, r.Top, r.Width, r.Height); +end; + +procedure TfpgCanvasBase.SetClipRect(const rect: TfpgRect); +begin + DoSetClipRect(rect); +end; + +function TfpgCanvasBase.GetClipRect: TfpgRect; +begin + Result := DoGetClipRect; +end; + +procedure TfpgCanvasBase.AddClipRect(const rect: TfpgRect); +begin + DoAddClipRect(rect); +end; + +procedure TfpgCanvasBase.ClearClipRect; +begin + DoClearClipRect; +end; + +procedure TfpgCanvasBase.SetColor(AColor: TfpgColor); +begin + FColor := AColor; + DoSetColor(FColor); +end; + +procedure TfpgCanvasBase.SetTextColor(AColor: TfpgColor); +begin + FTextColor := AColor; + DoSetTextColor(FTextColor); +end; + +procedure TfpgCanvasBase.SetLineStyle(AWidth: integer; AStyle: TfpgLineStyle); +begin + FLineWidth := AWidth; + FLineStyle := AStyle; + DoSetLineStyle(FLineWidth, FLineStyle); +end; + +procedure TfpgCanvasBase.SetFont(AFont: TfpgFontBase); +begin + FFont := AFont; + DoSetFontRes(AFont.FFontRes); +end; + +procedure TfpgCanvasBase.BeginDraw; +begin + BeginDraw(FBufferedDraw); +end; + +procedure TfpgCanvasBase.BeginDraw(ABuffered: boolean); +begin + if FBeginDrawCount < 1 then + begin + DoBeginDraw(FWindow, ABuffered); + + SetColor(clText1); + SetTextColor(clText1); + SetFont(fpgApplication.DefaultFont); + SetLineStyle(0, lsSolid); + + FBeginDrawCount := 0; + end; + Inc(FBeginDrawCount); +end; + +{ TfpgFontBase } + +function TfpgFontBase.TextWidth(const txt: string): integer; +begin + Result := FFontRes.GetTextWidth(txt); +end; + +function TfpgFontBase.Ascent: integer; +begin + Result := FFontRes.GetAscent; +end; + +function TfpgFontBase.Descent: integer; +begin + Result := FFontRes.GetDescent; +end; + +function TfpgFontBase.Height: integer; +begin + Result := FFontRes.GetHeight; +end; + end. diff --git a/prototypes/fpgui2/source/core/x11/gfx_x11.pas b/prototypes/fpgui2/source/core/x11/gfx_x11.pas index 2e1d5d79..0956726a 100644 --- a/prototypes/fpgui2/source/core/x11/gfx_x11.pas +++ b/prototypes/fpgui2/source/core/x11/gfx_x11.pas @@ -51,10 +51,10 @@ type constructor Create(const afontdesc: string); destructor Destroy; override; function HandleIsValid: boolean; - function GetAscent: integer; - function GetDescent: integer; - function GetHeight: integer; - function GetTextWidth(const txt: string): integer; + function GetAscent: integer; override; + function GetDescent: integer; override; + function GetHeight: integer; override; + function GetTextWidth(const txt: string): integer; override; end; @@ -62,7 +62,6 @@ type private FXimg: TXImage; FXimgmask: TXImage; - FMasked: boolean; function XImage: PXImage; function XImageMask: PXImage; protected @@ -81,35 +80,31 @@ type FBufferPixmap: TPixmap; FDrawHandle: TXID; Fgc: TfpgGContext; - FColorText: TfpgColor; - FColor: TfpgColor; FCurFontRes: TfpgFontResourceImpl; FClipRect: TfpgRect; FClipRectSet: boolean; - FLineStyle: integer; - FLineWidth: integer; FXftDraw: PXftDraw; FXftDrawBuffer: PXftDraw; FColorTextXft: TXftColor; FClipRegion: TRegion; protected - procedure DoSetFontRes(fntres: TfpgFontResourceImpl); - procedure DoSetTextColor(cl: TfpgColor); - procedure DoSetColor(cl: TfpgColor); - procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); - procedure DoDrawString(x, y: TfpgCoord; const txt: string); + procedure DoSetFontRes(fntres: TfpgFontResourceBase); override; + procedure DoSetTextColor(cl: TfpgColor); override; + procedure DoSetColor(cl: TfpgColor); override; + procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; procedure DoGetWinRect(var r: TfpgRect); - procedure DoFillRectangle(x, y, w, h: TfpgCoord); + procedure DoFillRectangle(x, y, w, h: TfpgCoord); override; procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); - procedure DoDrawRectangle(x, y, w, h: TfpgCoord); - procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); - procedure DoSetClipRect(const rect: TfpgRect); - function DoGetClipRect: TfpgRect; - procedure DoAddClipRect(const rect: TfpgRect); - procedure DoClearClipRect; - procedure DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageImpl; xi, yi, w, h: integer); - procedure DoBeginDraw(awin: TfpgWindowImpl; buffered: boolean); + 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 rect: TfpgRect); override; + function DoGetClipRect: TfpgRect; override; + procedure DoAddClipRect(const rect: TfpgRect); override; + procedure DoClearClipRect; override; + procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); override; procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); procedure DoEndDraw; public @@ -172,9 +167,7 @@ implementation uses baseunix, fpgfx, - gfx_widget, {$Note This dependency to gfx_widget must be removed.} - xatom, - gfx_UTF8utils; + gfx_widget; {$Note This dependency to gfx_widget must be removed.} var xapplication: TfpgApplication; @@ -993,7 +986,7 @@ begin inherited Destroy; end; -procedure TfpgCanvasImpl.DoBeginDraw(awin: TfpgWindowImpl; buffered: boolean); +procedure TfpgCanvasImpl.DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); var x: integer; y: integer; @@ -1006,7 +999,7 @@ var pmh: longword; GcValues: TXGcValues; begin - XGetGeometry(xapplication.display, awin.FWinHandle, @rw, @x, @y, @w, @h, @bw, @d); + XGetGeometry(xapplication.display, TfpgWindowImpl(awin).FWinHandle, @rw, @x, @y, @w, @h, @bw, @d); if FDrawing and buffered and (FBufferPixmap > 0) then if FBufferPixmap > 0 then @@ -1019,7 +1012,7 @@ begin if not FDrawing then begin - FDrawWindow := awin; + FDrawWindow := TfpgWindowImpl(awin); if buffered then begin @@ -1074,11 +1067,11 @@ begin end; end; -procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceImpl); +procedure TfpgCanvasImpl.DoSetFontRes(fntres: TfpgFontResourceBase); begin if fntres = nil then - Exit; - FCurFontRes := fntres; + Exit; //==> + FCurFontRes := TfpgFontResourceImpl(fntres); end; procedure TfpgCanvasImpl.DoSetTextColor(cl: TfpgColor); @@ -1247,7 +1240,7 @@ begin FClipRectSet := False; end; -procedure TfpgCanvasImpl.DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageImpl; xi, yi, w, h: integer); +procedure TfpgCanvasImpl.DoDrawImagePart(x, y: TfpgCoord; img: TfpgImageBase; xi, yi, w, h: integer); var msk: TPixmap; gc2: Tgc; @@ -1255,9 +1248,9 @@ var GcValues: TXGcValues; begin if img = nil then - Exit; + Exit; //==> - if img.FMasked then + if img.Masked then begin // rendering the mask @@ -1271,19 +1264,19 @@ begin XFillRectangle(xapplication.display, msk, gc2, 0, 0, w, h); XSetForeground(xapplication.display, gc2, 1); - XPutImage(xapplication.display, msk, gc2, img.XImageMask, xi, yi, 0, 0, w, h); + XPutImage(xapplication.display, msk, gc2, TfpgImageImpl(img).XImageMask, xi, yi, 0, 0, w, h); drawgc := XCreateGc(xapplication.display, FDrawHandle, 0, @GcValues); XSetClipMask(xapplication.display, drawgc, msk); XSetClipOrigin(xapplication.display, drawgc, x, y); - XPutImage(xapplication.display, FDrawHandle, drawgc, img.XImage, xi, yi, x, y, w, h); + XPutImage(xapplication.display, FDrawHandle, drawgc, TfpgImage(img).XImage, xi, yi, x, y, w, h); XFreePixmap(xapplication.display, msk); XFreeGc(xapplication.display, drawgc); XFreeGc(xapplication.display, gc2); end else - XPutImage(xapplication.display, FDrawHandle, Fgc, img.XImage, xi, yi, x, y, w, h); + XPutImage(xapplication.display, FDrawHandle, Fgc, TfpgImage(img).XImage, xi, yi, x, y, w, h); end; { TfpgImageImpl } diff --git a/prototypes/fpgui2/tests/edittest.lpi b/prototypes/fpgui2/tests/edittest.lpi index 269ce784..3e9244a7 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"> @@ -46,7 +46,6 @@ </ProjectOptions> <CompilerOptions> <Version Value="5"/> - <PathDelim Value="\"/> <CodeGeneration> <Generate Value="Faster"/> </CodeGeneration> diff --git a/prototypes/fpgui2/tests/fpgcanvas.lpr b/prototypes/fpgui2/tests/fpgcanvas.lpr index f26167d6..7cae700f 100644 --- a/prototypes/fpgui2/tests/fpgcanvas.lpr +++ b/prototypes/fpgui2/tests/fpgcanvas.lpr @@ -6,7 +6,7 @@ uses {$IFDEF UNIX}{$IFDEF UseCThreads} cthreads, {$ENDIF}{$ENDIF} - Classes, + Classes, SysUtils, fpgfx, gfxbase, gui_form, @@ -21,11 +21,17 @@ const clBlack = $000000; type + + { TMainForm } + TMainForm = class(TfpgForm) + private + bmp: TfpgImage; protected procedure HandlePaint; override; public procedure AfterCreate; override; + procedure BeforeDestruction; override; end; { TMainForm } @@ -34,7 +40,6 @@ procedure TMainForm.HandlePaint; var r: TfpgRect; fnt: TfpgFont; - bmp: TfpgImage; y: integer; begin // Enable double buffering. Must be before 'inherited' to prevent form @@ -53,16 +58,16 @@ begin r.Left := 60; r.Width := 50; r.Height := 50; - Canvas.DrawRect(r); + Canvas.DrawRectangle(r); r.Left := 120; Canvas.SetLineStyle(2, lsDash); - Canvas.DrawRect(r); + Canvas.DrawRectangle(r); r.Left := 180; Canvas.SetColor(clGreen); Canvas.SetLineStyle(1, lsDot); - Canvas.DrawRect(r); + Canvas.DrawRectangle(r); r.Left := 240; Canvas.SetColor(clBlue); @@ -107,20 +112,13 @@ begin // Testing Bitmap painting - bmp := LoadImage_BMP('button.bmp'); - try - bmp.CreateMaskFromSample(0,0); - bmp.UpdateImage; - Canvas.DrawString(5, 180, 'Single BMP file:'); - Canvas.DrawString(300, 210, '(mask enabled for all images)'); - Canvas.DrawImage(150, 180, bmp); - Canvas.DrawString(5, 210, 'Parts of BMP file:'); - Canvas.DrawImagePart(150, 210, bmp, 0, 0, 32, 21); - Canvas.DrawImagePart(190, 210, bmp, 32, 0, 32, 21); - Canvas.DrawImagePart(230, 210, bmp, 64, 0, 32, 21); - finally - bmp.Free; - end; + Canvas.DrawString(5, 180, 'Single BMP file:'); + Canvas.DrawString(300, 210, '(mask enabled for all images)'); + Canvas.DrawImage(150, 180, bmp); + Canvas.DrawString(5, 210, 'Parts of BMP file:'); + Canvas.DrawImagePart(150, 210, bmp, 0, 0, 32, 21); + Canvas.DrawImagePart(190, 210, bmp, 32, 0, 32, 21); + Canvas.DrawImagePart(230, 210, bmp, 64, 0, 32, 21); Canvas.EndDraw; @@ -131,6 +129,18 @@ begin inherited AfterCreate; SetPosition(100, 100, 500, 400); WindowTitle := 'fpGFX Canvas Test'; + + bmp := LoadImage_BMP('button.bmp'); + if not Assigned(bmp) then + raise Exception.Create('Failed to load button.bmp'); + bmp.CreateMaskFromSample(0,0); + bmp.UpdateImage; +end; + +procedure TMainForm.BeforeDestruction; +begin + bmp.Free; + inherited BeforeDestruction; end; procedure MainProc; |