diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-27 14:50:37 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-27 14:50:37 +0000 |
commit | 79f3d57b899e797fe9acc116146bf64e0327deb9 (patch) | |
tree | a02e2380024dc329a7872bc33e700f7f01f061dd /src | |
parent | 3abd19af870b83175359c2e1e0af063123d14635 (diff) | |
download | fpGUI-79f3d57b899e797fe9acc116146bf64e0327deb9.tar.xz |
X11 only:
* Fixed a bug in the SetLineStyle which caused
inaccurate line drawing. This eluded me for ages.
* Started the process of removing TfpgRect and replacing
it with the standard Object Pascal TRect.
* Started updating some methods to rather use two sets
of coordinates instead of width and height.
* Added a new test to verify drawing accuracy
* Implemented more line styles under X11
* Fixed up painting issues in widgets (Scrollbar and Memo
are still outstanding)
* Added three new helper functions for use with TRect in
fpgfx.pas (InflateRect, CentrePoint, OffsetRect).
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/fpgfx.pas | 125 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_gdi.pas | 65 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 62 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 122 | ||||
-rw-r--r-- | src/gui/gui_bevel.pas | 6 | ||||
-rw-r--r-- | src/gui/gui_button.pas | 13 | ||||
-rw-r--r-- | src/gui/gui_combobox.pas | 13 | ||||
-rw-r--r-- | src/gui/gui_edit.pas | 9 | ||||
-rw-r--r-- | src/gui/gui_listbox.pas | 38 | ||||
-rw-r--r-- | src/gui/gui_memo.pas | 6 | ||||
-rw-r--r-- | src/gui/gui_scrollbar.pas | 6 |
11 files changed, 262 insertions, 203 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index 8ffcc02e..826a45f3 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -153,7 +153,7 @@ type MenuDisabledFont: TfpgFont; public constructor Create; virtual; - procedure DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); virtual; + procedure DrawButtonFace(ACanvas: TfpgCanvas; x1, y1, x2, y2: TfpgCoord; AFlags: TFButtonFlags); virtual; procedure DrawControlFrame(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord); virtual; procedure DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; direction: integer); virtual; procedure DrawString(ACanvas: TfpgCanvas; x, y: TfpgCoord; AText: string; AEnabled: boolean = True); virtual; @@ -260,6 +260,11 @@ procedure fpgInitTimers; procedure fpgCheckTimers; function fpgClosestTimer(ctime: TDateTime; amaxtime: integer): integer; +// Rectangle routines +function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; +function OffsetRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; +function CenterPoint(const Rect: TRect): TPoint; + implementation @@ -341,6 +346,51 @@ begin Result := -1; end; +function InflateRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; +begin + if Assigned(@Rect) then + begin + with Rect do + begin + dec(Left, dx); + dec(Top, dy); + inc(Right, dx); + inc(Bottom, dy); + end; + Result := True; + end + else + Result := False; +end; + +function OffsetRect(var Rect: TRect; dx: Integer; dy: Integer): Boolean; +begin + if Assigned(@Rect) then + begin + with Rect do + begin + inc(Left, dx); + inc(Top, dy); + inc(Right, dx); + inc(Bottom, dy); + end; + OffsetRect := True; + end + else + OffsetRect := False; +end; + +function CenterPoint(const Rect: TRect): TPoint; +begin + with Rect do + begin + Result.X := (Left+Right) div 2; + Result.Y := (Top+Bottom) div 2; + end; +end; + +{ TfpgTimer } + procedure TfpgTimer.SetEnabled(const AValue: boolean); begin if not FEnabled and AValue then @@ -655,7 +705,7 @@ end; procedure TfpgCanvas.DrawButtonFace(x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); begin - fpgStyle.DrawButtonFace(self, x, y, w, h, AFlags); + fpgStyle.DrawButtonFace(self, x, y, x+w-1, y+h-1, AFlags); end; procedure TfpgCanvas.DrawControlFrame(x, y, w, h: TfpgCoord); @@ -765,11 +815,25 @@ begin MenuDisabledFont := fpgGetFont(fpgGetNamedFontDesc('MenuDisabled')); end; -procedure TfpgStyle.DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); +procedure TfpgStyle.DrawButtonFace(ACanvas: TfpgCanvas; x1, y1, x2, y2: TfpgCoord; AFlags: TFButtonFlags); +var + r: TRect; begin + if btnIsDefault in AFlags then + begin + r := Rect(x1, y1, x2, y2); + ACanvas.SetColor(clBlack); + ACanvas.SetLineStyle(1, lsSolid); + ACanvas.DrawRectangle(r); + InflateRect(r, -1, -1); + Exclude(AFlags, btnIsDefault); + fpgStyle.DrawButtonFace(ACanvas, r.Left, r.Top, r.Right, r.Bottom, AFlags); + Exit; //==> + end; + ACanvas.SetColor(clButtonFace); ACanvas.SetLineStyle(1, lsSolid); - ACanvas.FillRectangle(x, y, w, h); + ACanvas.FillRectangle(x1, y1, x2, y2); // Left and Top (outer) if (btnIsPressed in AFlags) then @@ -781,8 +845,8 @@ begin end else ACanvas.SetColor(clHilite1); - ACanvas.DrawLine(x, y+h-1, x, y); // left - ACanvas.DrawLine(x, y, x+w, y); // top + ACanvas.DrawLine(x1, y2-1, x1, y1); // left + ACanvas.DrawLine(x1, y1, x2-1, y1); // top // Left and Top (inner) //if btnIsPressed in AFlags then @@ -801,14 +865,9 @@ begin ACanvas.SetColor(clShadow2); end else - begin - if (btnIsDefault in AFlags) then - ACanvas.SetColor(clBlack) - else - ACanvas.SetColor(clShadow2); - end; - ACanvas.DrawLine(x+w-1, y, x+w-1, y+h-1); // right - ACanvas.DrawLine(x, y+h-1, x+w, y+h-1); // bottom + ACanvas.SetColor(clShadow2); + ACanvas.DrawLine(x2, y1, x2, y2); // right + ACanvas.DrawLine(x2, y2, x1, y2); // bottom // Right and Bottom (inner) if btnIsPressed in AFlags then @@ -819,33 +878,35 @@ begin ACanvas.SetColor(clHilite1); end else - begin - if (btnIsDefault in AFlags) then - ACanvas.SetColor(clShadow2) - else - ACanvas.SetColor(clShadow1); - end; - ACanvas.DrawLine(x+w-2, y+1, x+w-2, y+h-2); // right - ACanvas.DrawLine(x+1, y+h-2, x+w-1, y+h-2); // bottom + ACanvas.SetColor(clShadow1); + ACanvas.DrawLine(x2-1, y1+1, x2-1, y2-1); // right + ACanvas.DrawLine(x2-1, y2-1, x1+1, y2-1); // bottom end; procedure TfpgStyle.DrawControlFrame(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord); +var + x2: TfpgCoord; + y2: TfpgCoord; begin + // outer bottom right coordinates + x2 := x+w-1; + y2 := y+h-1; + ACanvas.SetColor(clShadow1); - ACanvas.DrawLine(x, y, x + w - 1, y); // top (outer) - ACanvas.DrawLine(x, y + h - 1, x, y); // left (outer) + ACanvas.DrawLine(x, y2, x, y); // left (outer) + ACanvas.DrawLine(x, y, x2-1, y); // top (outer) ACanvas.SetColor(clShadow2); - ACanvas.DrawLine(x + 1, y + 1, x + w - 2, y + 1); // top (inner) - ACanvas.DrawLine(x + 1, y + h - 2, x + 1, y + 1); // left (inner) - - ACanvas.SetColor(clHilite2); - ACanvas.DrawLine(x + 1, y + h - 1, x + w, y + h - 1); // bottom (outer) - ACanvas.DrawLine(x + w - 1, y, x + w - 1, y + h); // right (outer) + ACanvas.DrawLine(x+1, y+1, x2-1, y+1); // top (inner) + ACanvas.DrawLine(x+1, y2-1, x+1, y+1); // left (inner) ACanvas.SetColor(clHilite1); - ACanvas.DrawLine(x + 2, y + h - 2, x + w - 2, y + h - 2); // bottom (inner) - ACanvas.DrawLine(x + w - 2, y + 1, x + w - 2, y + h - 1); // right (inner) + ACanvas.DrawLine(x+2, y2-1, x2-1, y2-1); // bottom (inner) + ACanvas.DrawLine(x2-1, y+1, x2-1, y2-1); // right (inner) + + ACanvas.SetColor(clHilite2); + ACanvas.DrawLine(x+1, y2, x2, y2); // bottom (outer) + ACanvas.DrawLine(x2, y, x2, y2); // right (outer) end; procedure TfpgStyle.DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; direction: integer); diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas index c4eaa161..aad8429e 100644 --- a/src/corelib/gdi/gfx_gdi.pas +++ b/src/corelib/gdi/gfx_gdi.pas @@ -78,7 +78,7 @@ type FWinGC: TfpgGContext; FBackgroundColor: TfpgColor; FCurFontRes: TfpgFontResourceImpl; - FClipRect: TfpgRect; + FClipRect: TRect; FClipRectSet: Boolean; FWindowsColor: longword; FBrush: HBRUSH; @@ -91,16 +91,16 @@ type procedure DoSetColor(cl: TfpgColor); override; procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; procedure DoGetWinRect(var r: TfpgRect); override; - procedure DoFillRectangle(x, y, w, h: TfpgCoord); override; + procedure DoFillRectangle(x1, y1, x2, y2: 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 DoDrawRectangle(x1, y1, x2, y2: 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 DoSetClipRect(const ARect: TRect); override; + function DoGetClipRect: TRect; override; + procedure DoAddClipRect(const ARect: TRect); override; procedure DoClearClipRect; override; procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); override; procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); override; @@ -1111,7 +1111,7 @@ begin Fgc := FWinGC; end; - SetTextAlign(Fgc, TA_TOP); //TA_BASELINE); + SetTextAlign(Fgc, TA_TOP); SetBkMode(Fgc, TRANSPARENT); FBrush := CreateSolidBrush(0); @@ -1120,7 +1120,7 @@ begin FColor := fpgColorToWin(clText1); FLineStyle := lsSolid; - FLineWidth := 0; + FLineWidth := 1; FBackgroundColor := fpgColorToWin(clBoxColor); end; @@ -1190,12 +1190,12 @@ begin BitBlt(FWinGC, x, y, w, h, Fgc, x, y, SRCCOPY); end; -procedure TfpgCanvasImpl.DoAddClipRect(const rect: TfpgRect); +procedure TfpgCanvasImpl.DoAddClipRect(const ARect: TRect); var rg: HRGN; begin - rg := CreateRectRgn(rect.left, rect.top, rect.left + rect.Width, rect.top + rect.Height); - FClipRect := Rect; + rg := CreateRectRgn(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); + FClipRect := ARect; FClipRectSet := True; CombineRgn(FClipRegion, rg, FClipRegion, RGN_AND); SelectClipRgn(Fgc, FClipRegion); @@ -1209,18 +1209,26 @@ begin end; procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: TfpgCoord); +var + pts: array[1..2] of TPoint; begin - Windows.MoveToEx(Fgc, x1, y1, nil); - Windows.LineTo(Fgc, x2, y2); + pts[1].X := x1; + pts[1].Y := y1; + pts[2].X := x2; + pts[2].Y := y2; + Windows.Polygon(Fgc, pts, 2); end; -procedure TfpgCanvasImpl.DoDrawRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasImpl.DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); +var + pts: array[1..5] of TPoint; begin - Windows.MoveToEx(Fgc, x, y, nil); - Windows.LineTo(Fgc, x+w-1, y); - Windows.LineTo(Fgc, x+w-1, y+h-1); - Windows.LineTo(Fgc, x, y+h-1); - Windows.LineTo(Fgc, x, y); + pts[1].X := x1; pts[1].Y := y1; + pts[2].X := x2; pts[2].Y := y1; + pts[3].X := x2; pts[3].Y := y2; + pts[4].X := x1; pts[4].Y := y2; + pts[5].X := x1; pts[5].Y := y1; + Windows.Polyline(Fgc, pts, 5); end; procedure TfpgCanvasImpl.DoDrawString(x, y: TfpgCoord; const txt: string); @@ -1238,15 +1246,12 @@ begin {$endif} end; -procedure TfpgCanvasImpl.DoFillRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasImpl.DoFillRectangle(x1, y1, x2, y2: TfpgCoord); var - wr: Windows.TRect; + r: TRect; begin - wr.Left := x; - wr.Top := y; - wr.Right := x + w; - wr.Bottom := y + h; - Windows.FillRect(Fgc, wr, FBrush); + r := Rect(x1, y1, x2, y2); + Windows.FillRect(Fgc, r, FBrush); end; procedure TfpgCanvasImpl.DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); @@ -1262,7 +1267,7 @@ begin Windows.Polygon(Fgc, pts, 3); end; -function TfpgCanvasImpl.DoGetClipRect: TfpgRect; +function TfpgCanvasImpl.DoGetClipRect: TRect; begin Result := FClipRect; end; @@ -1278,12 +1283,12 @@ begin r.Height := wr.Bottom - wr.Top + 1; end; -procedure TfpgCanvasImpl.DoSetClipRect(const rect: TfpgRect); +procedure TfpgCanvasImpl.DoSetClipRect(const ARect: TRect); begin FClipRectSet := True; - FClipRect := rect; + FClipRect := ARect; DeleteObject(FClipRegion); - FClipRegion := CreateRectRgn(rect.left, rect.top, rect.left + rect.Width, rect.top + rect.Height); + FClipRegion := CreateRectRgn(ARect.Left, ARect.Top, ARect.Right, ARect.Bottom); SelectClipRgn(Fgc, FClipRegion); end; diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 28149f8f..684391f5 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -107,7 +107,7 @@ type PfpgMessageRec = ^TfpgMessageRec; - TfpgLineStyle = (lsSolid, lsDash, lsDot); + TfpgLineStyle = (lsSolid, lsDash, lsDot, lsDashDot, lsDashDotDot); // forward declaration @@ -232,17 +232,17 @@ type 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 DoGetWinRect(out r: TRect); virtual; abstract; + procedure DoFillRectangle(x1, y1, x2, y2: 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 DoDrawRectangle(x1, y1, x2, y2: 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 DoSetClipRect(const ARect: TRect); virtual; abstract; + function DoGetClipRect: TRect; virtual; abstract; + procedure DoAddClipRect(const ARect: TRect); virtual; abstract; procedure DoClearClipRect; virtual; abstract; procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); virtual; abstract; procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); virtual; abstract; @@ -254,8 +254,8 @@ type public constructor Create; virtual; destructor Destroy; override; - procedure DrawRectangle(x, y, w, h: TfpgCoord); overload; - procedure DrawRectangle(r: TfpgRect); overload; + procedure DrawRectangle(x1, y1, x2, y2: TfpgCoord); overload; + procedure DrawRectangle(r: TRect); 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); @@ -263,18 +263,18 @@ type 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 FillRectangle(x1, y1, x2, y2: TfpgCoord); overload; + procedure FillRectangle(r: TRect); 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); - function GetClipRect: TfpgRect; - procedure AddClipRect(const rect: TfpgRect); + procedure SetClipRect(const ARect: TRect); + function GetClipRect: TRect; + procedure AddClipRect(const ARect: TRect); procedure ClearClipRect; procedure Clear(AColor: TfpgColor); - procedure GetWinRect(var r: TfpgRect); + procedure GetWinRect(out r: TRect); procedure SetColor(AColor: TfpgColor); procedure SetTextColor(AColor: TfpgColor); procedure SetLineStyle(AWidth: integer; AStyle: TfpgLineStyle); @@ -726,14 +726,14 @@ begin inherited Destroy; end; -procedure TfpgCanvasBase.DrawRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasBase.DrawRectangle(x1, y1, x2, y2: TfpgCoord); begin - DoDrawRectangle(x, y, w, h); + DoDrawRectangle(x1, y1, x2, y2); end; -procedure TfpgCanvasBase.DrawRectangle(r: TfpgRect); +procedure TfpgCanvasBase.DrawRectangle(r: TRect); begin - DoDrawRectangle(r.Left, r.Top, r.Width, r.Height); + DoDrawRectangle(r.Left, r.Top, r.Right, r.Bottom); end; procedure TfpgCanvasBase.DrawLine(x1, y1, x2, y2: TfpgCoord); @@ -818,14 +818,14 @@ begin end; end; -procedure TfpgCanvasBase.FillRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasBase.FillRectangle(x1, y1, x2, y2: TfpgCoord); begin - DoFillRectangle(x, y, w, h); + DoFillRectangle(x1, y1, x2, y2); end; -procedure TfpgCanvasBase.FillRectangle(r: TfpgRect); +procedure TfpgCanvasBase.FillRectangle(r: TRect); begin - DoFillRectangle(r.Left, r.Top, r.Width, r.Height); + DoFillRectangle(r.Left, r.Top, r.Right, r.Bottom); end; procedure TfpgCanvasBase.FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); @@ -848,19 +848,19 @@ begin DoXORFillRectangle(col, r.Left, r.Top, r.Width, r.Height); end; -procedure TfpgCanvasBase.SetClipRect(const rect: TfpgRect); +procedure TfpgCanvasBase.SetClipRect(const ARect: TRect); begin - DoSetClipRect(rect); + DoSetClipRect(ARect); end; -function TfpgCanvasBase.GetClipRect: TfpgRect; +function TfpgCanvasBase.GetClipRect: TRect; begin Result := DoGetClipRect; end; -procedure TfpgCanvasBase.AddClipRect(const rect: TfpgRect); +procedure TfpgCanvasBase.AddClipRect(const ARect: TRect); begin - DoAddClipRect(rect); + DoAddClipRect(ARect); end; procedure TfpgCanvasBase.ClearClipRect; @@ -871,16 +871,16 @@ end; procedure TfpgCanvasBase.Clear(AColor: TfpgColor); var lCol: TfpgColor; - lWinRect: TfpgRect; + lWinRect: TRect; begin lCol := FColor; DoSetColor(AColor); DoGetWinRect(lWinRect); - DoFillRectangle(0, 0, lWinRect.Width, lWinRect.Height); + DoFillRectangle(0, 0, lWinRect.Right, lWinRect.Bottom); DoSetColor(lCol); end; -procedure TfpgCanvasBase.GetWinRect(var r: TfpgRect); +procedure TfpgCanvasBase.GetWinRect(out r: TRect); begin DoGetWinRect(r); end; diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index 35564db6..ce63fdfd 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -47,7 +47,7 @@ type TXWindowStateFlags = set of TXWindowStateFlag; TfpgWindowImpl = class; - + TfpgFontResourceImpl = class(TfpgFontResourceBase) private @@ -88,7 +88,7 @@ type FDrawHandle: TXID; Fgc: TfpgGContext; FCurFontRes: TfpgFontResourceImpl; - FClipRect: TfpgRect; + FClipRect: TRect; FClipRectSet: boolean; FXftDraw: PXftDraw; FXftDrawBuffer: PXftDraw; @@ -99,17 +99,17 @@ type procedure DoSetTextColor(cl: TfpgColor); override; procedure DoSetColor(cl: TfpgColor); override; procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; - procedure DoGetWinRect(var r: TfpgRect); override; - procedure DoFillRectangle(x, y, w, h: TfpgCoord); override; + procedure DoGetWinRect(out r: TRect); override; + procedure DoFillRectangle(x1, y1, x2, y2: 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 DoDrawRectangle(x1, y1, x2, y2: 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 DoSetClipRect(const ARect: TRect); override; + function DoGetClipRect: TRect; override; + procedure DoAddClipRect(const ARect: TRect); override; procedure DoClearClipRect; override; procedure DoBeginDraw(awin: TfpgWindowBase; buffered: boolean); override; procedure DoPutBufferToScreen(x, y, w, h: TfpgCoord); override; @@ -1305,9 +1305,8 @@ var begin oldColor := Color; SetColor(AValue); - DrawLine(X, Y, X+1, Y+1); + XDrawPoint(xapplication.display, FDrawHandle, Fgc, X, Y); SetColor(oldColor); - {$Note We must still implement DrawPoint} end; procedure TfpgCanvasImpl.DoDrawArc(x, y, w, h: TfpgCoord; a1, a2: Extended); @@ -1340,42 +1339,41 @@ begin end; procedure TfpgCanvasImpl.DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); -//const -// DotDashes: array[0..1] of Char = #1#1; -// DotDashes: array[0..1] of Char = #4#2; - { It was #1#1 which gives 1 pixel dots. Now it gives a 4 pixel line and a - 2 pixel space. } -var - ls: integer; - DotDashes: array[0..6] of Char; - len: integer; +const + cDot: array[0..1] of Char = #1#1; + cDash: array[0..1] of Char = #4#2; + cDashDot: array[0..3] of Char = #4#1#1#1; + cDashDotDot: array[0..5] of Char = #4#1#1#1#1#1; begin - {$Note Extend this and the GDI code some more to support more Line Styles} - // This design can be improved on. It smells! - len := 0; case AStyle of lsDot: begin - ls := LineOnOffDash; - len := 2; - DotDashes[0] := Char(#1); - DotDashes[1] := Char(#1); + XSetLineAttributes(xapplication.display, Fgc, 0, + LineOnOffDash, CapButt, JoinMiter); + XSetDashes(xapplication.display, Fgc, 0, cDot, 2); end; lsDash: begin - ls := LineOnOffDash; - len := 2; - DotDashes[0] := Char(#4); - DotDashes[1] := Char(#2); + XSetLineAttributes(xapplication.display, Fgc, 0, + LineOnOffDash, CapButt, JoinMiter); + XSetDashes(xapplication.display, Fgc, 0, cDash, 2); end; - lsSolid: - ls := LineSolid; - else - ls := LineSolid; - end; - XSetLineAttributes(xapplication.display, Fgc, awidth, ls, CapButt, JoinMiter); - if ls = LineOnOffDash then - XSetDashes(xapplication.display, Fgc, 0, DotDashes, len); + lsDashDot: + begin + XSetLineAttributes(xapplication.display, Fgc, 0, + LineOnOffDash, CapButt, JoinMiter); + XSetDashes(xapplication.display, Fgc, 0, cDashDot, 4); + end; + lsDashDotDot: + begin + XSetLineAttributes(xapplication.display, Fgc, 0, + LineOnOffDash, CapButt, JoinMiter); + XSetDashes(xapplication.display, Fgc, 0, cDashDotDot, 6); + end; + else // which includes lsSolid + XSetLineAttributes(xapplication.display, Fgc, 0, + LineSolid, CapButt, JoinMiter); + end; { case } end; procedure TfpgCanvasImpl.DoDrawString(x, y: TfpgCoord; const txt: string); @@ -1387,28 +1385,32 @@ begin y + FCurFontRes.GetAscent, PChar(txt), Length(txt)); end; -procedure TfpgCanvasImpl.DoGetWinRect(var r: TfpgRect); +procedure TfpgCanvasImpl.DoGetWinRect(out r: TRect); var rw: TfpgWinHandle; x: integer; y: integer; bw: longword; d: longword; + w: Cardinal; + h: Cardinal; begin - r.left := 0; - r.Top := 0; XGetGeometry(xapplication.display, FDrawWindow.FWinHandle, @rw, @x, @y, - @(r.Width), @(r.Height), @bw, @d); + @w, @h, @bw, @d); + r.Left := 0; + r.Top := 0; + r.Right := w; + r.Bottom := h; end; -procedure TfpgCanvasImpl.DoFillRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasImpl.DoFillRectangle(x1, y1, x2, y2: TfpgCoord); begin // Remember this for when we add Canvas.Pen support! { Note: By default XFillRectangle doesn't paint the same size rectangle that XDrawRectangle does - given the same coordinates! In this case we enlarge the Width and Height to paint consistant rectangle sizes, even thought it might repaint the same (only a few) pixels twice. } - XFillRectangle(xapplication.display, FDrawHandle, Fgc, x, y, w{+1}, h{+1}); + XFillRectangle(xapplication.display, FDrawHandle, Fgc, x1, y1, x2-x1, y2-y1); end; procedure TfpgCanvasImpl.DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); @@ -1434,9 +1436,9 @@ begin XFillPolygon(xapplication.display, FDrawHandle, Fgc, @pts, 3, 0, 0); end; -procedure TfpgCanvasImpl.DoDrawRectangle(x, y, w, h: TfpgCoord); +procedure TfpgCanvasImpl.DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); begin - XDrawRectangle(xapplication.display, FDrawHandle, Fgc, x, y, w-1, h-1); + XDrawRectangle(xapplication.display, FDrawHandle, Fgc, x1, y1, x2-x1, y2-y1); end; procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: TfpgCoord); @@ -1444,15 +1446,15 @@ begin XDrawLine(xapplication.display, FDrawHandle, Fgc, x1, y1, x2, y2); end; -procedure TfpgCanvasImpl.DoSetClipRect(const rect: TfpgRect); +procedure TfpgCanvasImpl.DoSetClipRect(const ARect: TRect); var r: TXRectangle; rg: TRegion; begin - r.x := rect.left; - r.y := rect.top; - r.Width := rect.Width; - r.Height := rect.Height; + r.x := ARect.Left; + r.y := ARect.Top; + r.Width := ARect.Right - ARect.Left + 1; + r.Height := ARect.Bottom - ARect.Top + 1; rg := XCreateRegion; @@ -1460,32 +1462,32 @@ begin XSetRegion(xapplication.display, Fgc, FClipRegion); XftDrawSetClip(FXftDraw, FClipRegion); - FClipRect := rect; + FClipRect := ARect; FClipRectSet := True; XDestroyRegion(rg); end; -function TfpgCanvasImpl.DoGetClipRect: TfpgRect; +function TfpgCanvasImpl.DoGetClipRect: TRect; begin Result := FClipRect; end; -procedure TfpgCanvasImpl.DoAddClipRect(const rect: TfpgRect); +procedure TfpgCanvasImpl.DoAddClipRect(const ARect: TRect); var r: TXRectangle; rg: TRegion; begin - r.x := rect.left; - r.y := rect.top; - r.Width := rect.Width; - r.Height := rect.Height; + r.x := ARect.Left; + r.y := ARect.Top; + r.Width := ARect.Right - ARect.Left + 1; + r.Height := ARect.Bottom - ARect.Top + 1; rg := XCreateRegion; XUnionRectWithRegion(@r, rg, rg); XIntersectRegion(FClipRegion, rg, FClipRegion); XSetRegion(xapplication.display, Fgc, FClipRegion); - FClipRect := Rect; + FClipRect := ARect; // Double check this, it might be wrong!! FClipRectSet := True; XftDrawSetClip(FXftDraw, FClipRegion); @@ -1494,7 +1496,7 @@ end; procedure TfpgCanvasImpl.DoClearClipRect; var - r: TfpgRect; + r: TRect; begin DoGetWinRect(r); DoSetClipRect(r); diff --git a/src/gui/gui_bevel.pas b/src/gui/gui_bevel.pas index d531fde0..9b0def1c 100644 --- a/src/gui/gui_bevel.pas +++ b/src/gui/gui_bevel.pas @@ -77,9 +77,9 @@ begin inherited HandlePaint; Canvas.Clear(clWindowBackground); - Canvas.SetLineStyle(2, lsSolid); - Canvas.SetColor(clWindowBackground); - Canvas.DrawRectangle(1, 1, Width - 1, Height - 1); +// Canvas.SetLineStyle(2, lsSolid); +// Canvas.SetColor(clWindowBackground); +// Canvas.DrawRectangle(1, 1, Width - 1, Height - 1); Canvas.SetLineStyle(1, lsSolid); if Style = bsRaised then diff --git a/src/gui/gui_button.pas b/src/gui/gui_button.pas index e5f32428..d3e84b80 100644 --- a/src/gui/gui_button.pas +++ b/src/gui/gui_button.pas @@ -182,7 +182,7 @@ procedure TfpgButton.HandlePaint; var AText: string; x, y, iy, w: integer; - r: TfpgRect; + r: TRect; pofs: integer; lBtnFlags: TFButtonFlags; begin @@ -190,6 +190,8 @@ begin // inherited HandlePaint; Canvas.Clear(clButtonFace); Canvas.ClearClipRect; + + r := Rect(0, 0, Width-1, Height-1); lBtnFlags := []; if FDown then @@ -207,7 +209,8 @@ begin begin Canvas.SetColor(clText1); Canvas.SetLineStyle(1, lsDot); - Canvas.DrawRectangle(3, 3, Width - 6, Height - 6); + InflateRect(r, -3, -3); + Canvas.DrawRectangle(r); end else begin @@ -215,14 +218,10 @@ begin Canvas.SetColor(clText1); end; - r.left := 2; - r.top := 2; - r.Width := Width - 4; - r.Height := Height - 4; Canvas.SetClipRect(r); - Canvas.SetFont(Font); AText := FText; + y := Height div 2 - FFont.Height div 2; if y < 3 then y := 3; diff --git a/src/gui/gui_combobox.pas b/src/gui/gui_combobox.pas index 9bbed12d..35bb39e7 100644 --- a/src/gui/gui_combobox.pas +++ b/src/gui/gui_combobox.pas @@ -255,7 +255,7 @@ end; procedure TfpgCustomComboBox.HandlePaint; var - r: TfpgRect; + r: TRect; begin inherited HandlePaint; Canvas.BeginDraw; @@ -263,22 +263,17 @@ begin Canvas.DrawControlFrame(0, 0, Width, Height); // internal background rectangle (without frame) - r.Left := 2; - r.Top := 2; - r.Width := Width - 4; - r.Height := Height - 4; + r := Rect(2, 2, Width-2, Height-2); Canvas.SetClipRect(r); if Enabled then Canvas.SetColor(FBackgroundColor) else Canvas.SetColor(clWindowBackground); - Canvas.FillRectangle(2, 2, Width - 4, Height - 4); - + Canvas.FillRectangle(r); // fpgStyle.DrawButtonFace(canvas, width - min(height, 20)-3, 2, height-4, height-4, [btnIsEmbedded]); // fpgStyle.DrawDirectionArrow(canvas, width - height + 1, 1, height-2, height-2, 1); - Canvas.SetFont(Font); if Focused then @@ -291,9 +286,7 @@ begin Canvas.SetColor(FBackgroundColor); Canvas.SetTextColor(clText1); end; - Canvas.FillRectangle(r); - Canvas.SetClipRect(r); // Draw select item's text if FocusItem > -1 then diff --git a/src/gui/gui_edit.pas b/src/gui/gui_edit.pas index 15aff0da..02710088 100644 --- a/src/gui/gui_edit.pas +++ b/src/gui/gui_edit.pas @@ -201,7 +201,7 @@ end; procedure TfpgEdit.HandlePaint; var - r: TfpgRect; + r: TRect; tw, tw2, st, len: integer; dtext: string; begin @@ -209,10 +209,7 @@ begin Canvas.ClearClipRect; Canvas.DrawControlFrame(0, 0, Width, Height); - r.Left := 2; - r.Top := 2; - r.Width := Width - 4; - r.Height := Height - 4; + r := Rect(2, 2, Width-2, Height-2); Canvas.SetClipRect(r); if Enabled then @@ -220,7 +217,7 @@ begin else Canvas.SetColor(clWindowBackground); - Canvas.FillRectAngle(2, 2, Width - 4, Height - 4); + Canvas.FillRectAngle(r); dtext := GetDrawText; Canvas.SetTextColor(clText1); Canvas.SetFont(FFont); diff --git a/src/gui/gui_listbox.pas b/src/gui/gui_listbox.pas index 4a766548..9bfc6db5 100644 --- a/src/gui/gui_listbox.pas +++ b/src/gui/gui_listbox.pas @@ -49,7 +49,7 @@ type function ScrollBarWidth: TfpgCoord; function PageLength: integer; procedure ScrollBarMove(Sender: TObject; position : integer); - procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); virtual; + procedure DrawItem(num: integer; rect: TRect; flags: integer); virtual; procedure DoChange; procedure DoSelect; procedure HandleKeyPress(var keycode: word; var shiftstate: TShiftState; var consumed : boolean); override; @@ -81,7 +81,7 @@ type protected FItems: TStrings; FInternalItems: TStrings; - procedure DrawItem(num: integer; rect: TfpgRect; flags: integer); override; + procedure DrawItem(num: integer; rect: TRect; flags: integer); override; property Items: TStrings read FItems; public constructor Create(AOwner: TComponent); override; @@ -451,23 +451,25 @@ end; procedure TfpgBaseListBox.HandlePaint; var n: integer; - r: TfpgRect; + r: TRect; begin Canvas.BeginDraw; inherited HandlePaint; - Canvas.ClearClipRect; + + r := Rect(0, 0, Width-1, Height-1); if popupframe then begin + Canvas.SetLineStyle(1, lsSolid); Canvas.SetColor(clWidgetFrame); - Canvas.DrawRectangle(0, 0, Width, Height); - r.SetRect(1, 1, Width - 2, Height - 2); + Canvas.DrawRectangle(r); + InflateRect(r, -1, -1); end else begin Canvas.DrawControlFrame(0, 0, Width, Height); - r.SetRect(2, 2, Width-4, Height-4); + InflateRect(r, -2, -2); end; Canvas.SetClipRect(r); @@ -475,10 +477,10 @@ begin Canvas.FillRectangle(r); Canvas.SetFont(FFont); - r.SetRect(FMargin, FMargin, Width-ScrollBarWidth-FMargin-2, Height-(2*FMargin)); - canvas.SetClipRect(r); + r := Rect(FMargin, FMargin, (Width-1)-ScrollBarWidth-FMargin, (Height-1)-FMargin); + Canvas.SetClipRect(r); - r.Height := RowHeight; + r.Bottom := RowHeight; for n := FFirstItem to ItemCount do begin @@ -502,18 +504,18 @@ begin end; Canvas.FillRectangle(r); - DrawItem(n,r,0); - r.Top := r.Top + r.Height; + DrawItem(n, r, 0); + r.Top := r.Top + r.Bottom; - if r.Top >= self.Height then - break; + if r.Top >= Height then + Break; end; // clearing after the last row if r.Top <= Height then begin canvas.SetColor(FBackgroundColor); - r.SetBottom(Height - fmargin); + r.Bottom := Height - fmargin; Canvas.FillRectangle(r); end; @@ -568,17 +570,17 @@ begin result := FFont.Height+2; end; -procedure TfpgBaseListBox.DrawItem(num: integer; rect: TfpgRect; flags: integer); +procedure TfpgBaseListBox.DrawItem(num: integer; rect: TRect; flags: integer); var s: string; begin s := 'Item' + IntToStr(num); - Canvas.DrawString(rect.left+2, rect.top+1,s); + Canvas.DrawString(rect.left+2, rect.top+1, s); end; { TfpgTextListBox } -procedure TfpgTextListBox.DrawItem(num: integer; rect: TfpgRect; flags: integer); +procedure TfpgTextListBox.DrawItem(num: integer; rect: TRect; flags: integer); begin Canvas.DrawString(rect.left+2, rect.top+1, FItems.Strings[num-1]); end; diff --git a/src/gui/gui_memo.pas b/src/gui/gui_memo.pas index 8736ec6d..d3ff7864 100644 --- a/src/gui/gui_memo.pas +++ b/src/gui/gui_memo.pas @@ -623,7 +623,7 @@ var tw, tw2, st, len: integer; yp: integer; ls: string; - r: TfpgRect; + r: TRect; selsl, selsp, selel, selep: integer; begin Canvas.BeginDraw; @@ -632,8 +632,8 @@ begin r.Left := 2; r.Top := 2; - r.Width := Width - 4; - r.Height := Height - 4; + r.Right := Width - 4; + r.Bottom := Height - 4; Canvas.SetClipRect(r); if Enabled then diff --git a/src/gui/gui_scrollbar.pas b/src/gui/gui_scrollbar.pas index 325dce0d..a76e9f9a 100644 --- a/src/gui/gui_scrollbar.pas +++ b/src/gui/gui_scrollbar.pas @@ -96,7 +96,7 @@ end; procedure TfpgScrollBar.HandlePaint; begin Canvas.BeginDraw; - + if Orientation = orVertical then begin DrawButton(0, 0, Width, Width, 'sys.sb.up' ,FStartBtnPressed); @@ -165,12 +165,12 @@ begin if Orientation = orVertical then begin - Canvas.FillRectangle(0, Width, Width, Height - Width - Width); + Canvas.FillRectangle(0, Width-1, Width-1, Height - (2*Width)-2); area := Height - (Width shl 1); end else begin - Canvas.FillRectangle(Height, 0, Width - Height - Height, Height); + Canvas.FillRectangle(Height-1, 0, Width - (2*Height)-2, Height-1); area := Width - (Height shl 1); end; |