diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-07 15:24:30 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-08-07 15:24:30 +0000 |
commit | bb4616fa1af67de6012a714fe7158b61fa1b0c1a (patch) | |
tree | 24ab2f46e3bd8afe2af610ffd080eb416b0888ce /src/corelib | |
parent | 27b4260ca539231514aa053706c060eff1568695 (diff) | |
download | fpGUI-bb4616fa1af67de6012a714fe7158b61fa1b0c1a.tar.xz |
* Changed the parameters of DrawRectangle, FillRectangle to rather use Width and Height.
* DrawLine and DrawRectangle now use the same coordinate system as Windows does.
* I need to fixed corrupted painting in widgets due to this.
Diffstat (limited to 'src/corelib')
-rw-r--r-- | src/corelib/fpgfx.pas | 73 | ||||
-rw-r--r-- | src/corelib/gdi/gfx_gdi.pas | 41 | ||||
-rw-r--r-- | src/corelib/gfxbase.pas | 24 | ||||
-rw-r--r-- | src/corelib/x11/gfx_x11.pas | 31 |
4 files changed, 84 insertions, 85 deletions
diff --git a/src/corelib/fpgfx.pas b/src/corelib/fpgfx.pas index 5d75ffad..a9dddf07 100644 --- a/src/corelib/fpgfx.pas +++ b/src/corelib/fpgfx.pas @@ -153,10 +153,10 @@ type MenuDisabledFont: TfpgFont; public constructor Create; 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; + procedure DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: integer; AFlags: TFButtonFlags); virtual; + procedure DrawControlFrame(ACanvas: TfpgCanvas; x, y, w, h: integer); virtual; + procedure DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: integer; direction: integer); virtual; + procedure DrawString(ACanvas: TfpgCanvas; x, y: integer; AText: string; AEnabled: boolean = True); virtual; end; @@ -713,7 +713,7 @@ end; procedure TfpgCanvas.DrawButtonFace(x, y, w, h: TfpgCoord; AFlags: TFButtonFlags); begin - fpgStyle.DrawButtonFace(self, x, y, x+w-1, y+h-1, AFlags); + fpgStyle.DrawButtonFace(self, x, y, w, h, AFlags); end; procedure TfpgCanvas.DrawControlFrame(x, y, w, h: TfpgCoord); @@ -824,25 +824,25 @@ begin MenuDisabledFont := fpgGetFont(fpgGetNamedFontDesc('MenuDisabled')); end; -procedure TfpgStyle.DrawButtonFace(ACanvas: TfpgCanvas; x1, y1, x2, y2: TfpgCoord; AFlags: TFButtonFlags); +procedure TfpgStyle.DrawButtonFace(ACanvas: TfpgCanvas; x, y, w, h: integer; AFlags: TFButtonFlags); var r: TRect; begin if btnIsDefault in AFlags then begin - r := Rect(x1, y1, x2, y2); + r := Rect(x, y, x+w+1, y+h+1); 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); + fpgStyle.DrawButtonFace(ACanvas, r.Left, r.Top, r.Right-r.Left-1, r.Bottom-r.Top-1, AFlags); Exit; //==> end; ACanvas.SetColor(clButtonFace); ACanvas.SetLineStyle(1, lsSolid); - ACanvas.FillRectangle(x1, y1, x2, y2); + ACanvas.FillRectangle(x, y, w, h); // Left and Top (outer) if (btnIsPressed in AFlags) then @@ -854,8 +854,8 @@ begin end else ACanvas.SetColor(clHilite1); - ACanvas.DrawLine(x1, y2-1, x1, y1); // left - ACanvas.DrawLine(x1, y1, x2-1, y1); // top + ACanvas.DrawLine(x, y+h-1, x, y); // left + ACanvas.DrawLine(x, y, x+w, y); // top // Left and Top (inner) //if btnIsPressed in AFlags then @@ -875,8 +875,8 @@ begin end else ACanvas.SetColor(clShadow2); - ACanvas.DrawLine(x2, y1, x2, y2); // right - ACanvas.DrawLine(x2, y2, x1, y2); // bottom + ACanvas.DrawLine(x+w, y, x+w, y+h); // right + ACanvas.DrawLine(x+w, y+h, x-1, y+h); // bottom // Right and Bottom (inner) if btnIsPressed in AFlags then @@ -888,44 +888,37 @@ begin end else 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 + ACanvas.DrawLine(x+w-1, y+1, x+w-1, y+h-1); // right + ACanvas.DrawLine(x+w-1, y+h-1, x, y+h-1); // bottom end; -procedure TfpgStyle.DrawControlFrame(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord); -var - x2: TfpgCoord; - y2: TfpgCoord; +procedure TfpgStyle.DrawControlFrame(ACanvas: TfpgCanvas; x, y, w, h: integer); begin - // outer bottom right coordinates - x2 := x+w-1; - y2 := y+h-1; - ACanvas.SetColor(clShadow1); - ACanvas.DrawLine(x, y2, x, y); // left (outer) - ACanvas.DrawLine(x, y, x2-1, y); // top (outer) + ACanvas.DrawLine(x, y+h, x, y); // left (outer) + ACanvas.DrawLine(x, y, x+w, y); // top (outer) + + ACanvas.SetColor(clHilite2); + ACanvas.DrawLine(x+w, y, x+w, y+h); // right (outer) + ACanvas.DrawLine(x+w, y+h, x, y+h); // bottom (outer) ACanvas.SetColor(clShadow2); - 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.DrawLine(x+1, y+h-1, x+1, y+1); // left (inner) + ACanvas.DrawLine(x+1, y+1, x+w-1, y+1); // top (inner) ACanvas.SetColor(clHilite1); - 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) + ACanvas.DrawLine(x+w-1, y+1, x+w-1, y+h-1); // right (inner) + ACanvas.DrawLine(x+w-1, y+h-1, x+1, y+h-1); // bottom (inner) end; -procedure TfpgStyle.DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: TfpgCoord; direction: integer); +procedure TfpgStyle.DrawDirectionArrow(ACanvas: TfpgCanvas; x, y, w, h: integer; direction: integer); var - peekx: TfpgCoord; - peeky: TfpgCoord; - basex: TfpgCoord; - basey: TfpgCoord; - side: TfpgCoord; - margin: TfpgCoord; + peekx: integer; + peeky: integer; + basex: integer; + basey: integer; + side: integer; + margin: integer; begin ACanvas.SetColor(clText1); side := (w div 4) + 1; diff --git a/src/corelib/gdi/gfx_gdi.pas b/src/corelib/gdi/gfx_gdi.pas index 1ed1284b..d0fc1e95 100644 --- a/src/corelib/gdi/gfx_gdi.pas +++ b/src/corelib/gdi/gfx_gdi.pas @@ -91,11 +91,11 @@ type procedure DoSetColor(cl: TfpgColor); override; procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; procedure DoGetWinRect(out r: TRect); override; - procedure DoFillRectangle(x1, y1, x2, y2: TfpgCoord); override; + procedure DoFillRectangle(x, y, w, h: integer); override; procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); override; procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); override; - procedure DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); override; - procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); override; + procedure DoDrawRectangle(x, y, w, h: integer); override; + procedure DoDrawLine(x1, y1, x2, y2: integer); 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: TRect); override; @@ -1227,27 +1227,26 @@ begin FClipRectSet := False; end; -procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: TfpgCoord); -var - pts: array[1..2] of TPoint; +procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: integer); begin - pts[1].X := x1; - pts[1].Y := y1; - pts[2].X := x2; - pts[2].Y := y2; - Windows.Polygon(Fgc, pts, 2); + Windows.MoveToEx(Fgc, x1, y1, nil); + Windows.LineTo(Fgc, x2, y2); end; -procedure TfpgCanvasImpl.DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasImpl.DoDrawRectangle(x, y, w, h: integer); var - pts: array[1..5] of TPoint; + r: TRect; begin - 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); + if (w = 1) and (h = 1) then + SetPixel(x, y, FColor) + else + begin + r := Rect(x, y, x+w-1, y+h-1); + DoDrawLine(r.Left, r.Top, r.Right, r.Top); + DoDrawLine(r.Right, r.Top, r.Right, r.Bottom); + DoDrawLine(r.Right, r.Bottom, r.Left, r.Bottom); + DoDrawLine(r.Left, r.Bottom, r.Left, r.Top); + end; end; procedure TfpgCanvasImpl.DoDrawString(x, y: TfpgCoord; const txt: string); @@ -1265,11 +1264,11 @@ begin {$endif} end; -procedure TfpgCanvasImpl.DoFillRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasImpl.DoFillRectangle(x, y, w, h: integer); var r: TRect; begin - r := Rect(x1, y1, x2+1, y2+1); + r := Rect(x, y, x+w, y+h); Windows.FillRect(Fgc, r, FBrush); end; diff --git a/src/corelib/gfxbase.pas b/src/corelib/gfxbase.pas index 6c0ace9b..b3f4d672 100644 --- a/src/corelib/gfxbase.pas +++ b/src/corelib/gfxbase.pas @@ -236,11 +236,11 @@ type procedure DoSetColor(cl: TfpgColor); virtual; abstract; procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); virtual; abstract; procedure DoGetWinRect(out r: TRect); virtual; abstract; - procedure DoFillRectangle(x1, y1, x2, y2: TfpgCoord); virtual; abstract; + procedure DoFillRectangle(x, y, w, h: integer); 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(x1, y1, x2, y2: TfpgCoord); virtual; abstract; - procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); virtual; abstract; + procedure DoDrawRectangle(x, y, w, h: integer); virtual; abstract; + procedure DoDrawLine(x1, y1, x2, y2: integer); 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 ARect: TRect); virtual; abstract; @@ -257,7 +257,7 @@ type public constructor Create; virtual; destructor Destroy; override; - procedure DrawRectangle(x1, y1, x2, y2: TfpgCoord); overload; + procedure DrawRectangle(x, y, w, h: integer); overload; procedure DrawRectangle(r: TRect); overload; procedure DrawLine(x1, y1, x2, y2: TfpgCoord); procedure DrawImage(x, y: TfpgCoord; img: TfpgImageBase); @@ -266,7 +266,7 @@ 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(x1, y1, x2, y2: TfpgCoord); overload; + procedure FillRectangle(x, y, w, h: integer); 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); @@ -730,14 +730,15 @@ begin inherited Destroy; end; -procedure TfpgCanvasBase.DrawRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasBase.DrawRectangle(x, y, w, h: integer); begin - DoDrawRectangle(x1, y1, x2, y2); + DoDrawRectangle(x, y, w, h); end; procedure TfpgCanvasBase.DrawRectangle(r: TRect); begin - DoDrawRectangle(r.Left, r.Top, r.Right, r.Bottom); + SortRect(r); + DoDrawRectangle(r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top); end; procedure TfpgCanvasBase.DrawLine(x1, y1, x2, y2: TfpgCoord); @@ -822,14 +823,15 @@ begin end; end; -procedure TfpgCanvasBase.FillRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasBase.FillRectangle(x, y, w, h: integer); begin - DoFillRectangle(x1, y1, x2, y2); + DoFillRectangle(x, y, w, h); end; procedure TfpgCanvasBase.FillRectangle(r: TRect); begin - DoFillRectangle(r.Left, r.Top, r.Right, r.Bottom); + SortRect(r); + DoFillRectangle(r.Left, r.Top, r.Right-r.Left, r.Bottom-r.Top); end; procedure TfpgCanvasBase.FillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); diff --git a/src/corelib/x11/gfx_x11.pas b/src/corelib/x11/gfx_x11.pas index fce95e78..f41ce904 100644 --- a/src/corelib/x11/gfx_x11.pas +++ b/src/corelib/x11/gfx_x11.pas @@ -100,11 +100,11 @@ type procedure DoSetColor(cl: TfpgColor); override; procedure DoSetLineStyle(awidth: integer; astyle: TfpgLineStyle); override; procedure DoGetWinRect(out r: TRect); override; - procedure DoFillRectangle(x1, y1, x2, y2: TfpgCoord); override; + procedure DoFillRectangle(x, y, w, h: integer); override; procedure DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); override; procedure DoFillTriangle(x1, y1, x2, y2, x3, y3: TfpgCoord); override; - procedure DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); override; - procedure DoDrawLine(x1, y1, x2, y2: TfpgCoord); override; + procedure DoDrawRectangle(x, y, w, h: integer); override; + procedure DoDrawLine(x1, y1, x2, y2: integer); 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: TRect); override; @@ -1264,6 +1264,8 @@ begin end; Fgc := XCreateGc(xapplication.display, FDrawHandle, 0, @GcValues); + // CapNotLast is so we get the same behavior as Windows. See documentation for more details. + XSetLineAttributes(xapplication.display, Fgc, 0, LineSolid, CapNotLast, JoinMiter); FXftDraw := XftDrawCreate(xapplication.display, FDrawHandle, XDefaultVisual(xapplication.display, xapplication.DefaultScreen), @@ -1380,30 +1382,30 @@ begin lsDot: begin XSetLineAttributes(xapplication.display, Fgc, 0, - LineOnOffDash, CapButt, JoinMiter); + LineOnOffDash, CapNotLast, JoinMiter); XSetDashes(xapplication.display, Fgc, 0, cDot, 2); end; lsDash: begin XSetLineAttributes(xapplication.display, Fgc, 0, - LineOnOffDash, CapButt, JoinMiter); + LineOnOffDash, CapNotLast, JoinMiter); XSetDashes(xapplication.display, Fgc, 0, cDash, 2); end; lsDashDot: begin XSetLineAttributes(xapplication.display, Fgc, 0, - LineOnOffDash, CapButt, JoinMiter); + LineOnOffDash, CapNotLast, JoinMiter); XSetDashes(xapplication.display, Fgc, 0, cDashDot, 4); end; lsDashDotDot: begin XSetLineAttributes(xapplication.display, Fgc, 0, - LineOnOffDash, CapButt, JoinMiter); + LineOnOffDash, CapNotLast, JoinMiter); XSetDashes(xapplication.display, Fgc, 0, cDashDotDot, 6); end; else // which includes lsSolid XSetLineAttributes(xapplication.display, Fgc, 0, - LineSolid, CapButt, JoinMiter); + LineSolid, CapNotLast, JoinMiter); end; { case } end; @@ -1434,9 +1436,9 @@ begin r.Bottom := h; end; -procedure TfpgCanvasImpl.DoFillRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasImpl.DoFillRectangle(x, y, w, h: integer); begin - XFillRectangle(xapplication.display, FDrawHandle, Fgc, x1, y1, x2-x1+1, y2-y1+1); + XFillRectangle(xapplication.display, FDrawHandle, Fgc, x, y, w, h); end; procedure TfpgCanvasImpl.DoXORFillRectangle(col: TfpgColor; x, y, w, h: TfpgCoord); @@ -1462,13 +1464,16 @@ begin XFillPolygon(xapplication.display, FDrawHandle, Fgc, @pts, 3, 0, 0); end; -procedure TfpgCanvasImpl.DoDrawRectangle(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasImpl.DoDrawRectangle(x, y, w, h: integer); begin - XDrawRectangle(xapplication.display, FDrawHandle, Fgc, x1, y1, x2-x1, y2-y1); +// writeln(Format('DoDrawRectangle x=%d y=%d w=%d h=%d', [x, y, w, h])); + // Same behavior as Windows. See documentation for reason. + XDrawRectangle(xapplication.display, FDrawHandle, Fgc, x, y, w-1, h-1); end; -procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: TfpgCoord); +procedure TfpgCanvasImpl.DoDrawLine(x1, y1, x2, y2: integer); begin + // Same behavior as Windows. See documentation for reason. XDrawLine(xapplication.display, FDrawHandle, Fgc, x1, y1, x2, y2); end; |