spktoolbar: Fix painting issues in Ubuntu (patch by haword for issue #0024081)

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3661 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-10-15 22:46:07 +00:00
parent ab758dbfc5
commit 7d32a9d9c4
2 changed files with 176 additions and 167 deletions

View File

@ -1445,8 +1445,8 @@ end;
class procedure TGUITools.DrawAARoundCorner(ABitmap: TBitmap; Point: T2DIntVector;
Radius: integer; CornerPos: TCornerPos; Color: TColor);
var CornerRect : T2DIntRect;
var
CornerRect: T2DIntRect;
Center: T2DIntVector;
Line: PByte;
Ptr: PByte;
@ -1455,59 +1455,66 @@ var CornerRect : T2DIntRect;
RadiusDist: double;
OrgCornerRect: T2DIntRect;
BitmapRect: T2DIntRect;
DestImg: TLazIntfImage;
cr, cg, cb: Byte;
begin
if ABitmap.PixelFormat <> pf24bit then
raise exception.create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!');
raise Exception.Create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!');
// Sprawdzamy poprawnoϾ
if Radius < 1 then
exit;
if (ABitmap.width=0) or (ABitmap.height=0) then
if (ABitmap.Width=0) or (ABitmap.Height=0) then
exit;
{$IFDEF EnhancedRecordSupport}
// �?ród³owy rect...
OrgCornerRect:=T2DIntRect.create(Point.x,
OrgCornerRect := T2DIntRect.Create(Point.x,
Point.y,
Point.x + radius - 1,
Point.y + radius - 1);
// ...przycinamy do rozmiarów bitmapy
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
BitmapRect := T2DIntRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1);
{$ELSE}
// �?ród³owy rect...
OrgCornerRect.create(Point.x,
OrgCornerRect.Create(Point.x,
Point.y,
Point.x + radius - 1,
Point.y + radius - 1);
// ...przycinamy do rozmiarów bitmapy
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1);
{$ENDIF}
if not(BitmapRect.intersectsWith(OrgCornerRect, CornerRect)) then
if not BitmapRect.intersectsWith(OrgCornerRect, CornerRect) then
exit;
// Jeœli nie ma czego rysowaæ, wychodzimy
if (CornerRect.left>CornerRect.right) or (CornerRect.top>CornerRect.bottom) then
if (CornerRect.Left > CornerRect.Right) or (CornerRect.Top > CornerRect.Bottom) then
exit;
// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika
{$IFDEF EnhancedRecordSupport}
case CornerPos of
cpLeftTop: Center:=T2DIntVector.create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop: Center:=T2DIntVector.create(Point.x, Point.y + Radius - 1);
cpLeftBottom: Center:=T2DIntVector.Create(Point.x + radius - 1, Point.y);
cpRightBottom: Center:=T2DIntVector.Create(Point.x, Point.y);
cpLeftTop:
Center := T2DIntVector.Create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop:
Center := T2DIntVector.Create(Point.x, Point.y + Radius - 1);
cpLeftBottom:
Center := T2DIntVector.Create(Point.x + radius - 1, Point.y);
cpRightBottom:
Center := T2DIntVector.Create(Point.x, Point.y);
end;
{$ELSE}
case CornerPos of
cpLeftTop: Center.create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop: Center.create(Point.x, Point.y + Radius - 1);
cpLeftBottom: Center.Create(Point.x + radius - 1, Point.y);
cpRightBottom: Center.Create(Point.x, Point.y);
cpLeftTop:
Center.Create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop:
Center.Create(Point.x, Point.y + Radius - 1);
cpLeftBottom:
Center.Create(Point.x + radius - 1, Point.y);
cpRightBottom:
Center.Create(Point.x, Point.y);
end;
{$ENDIF}
@ -1515,12 +1522,11 @@ Color:=ColorToRGB(Color);
colorR := GetRValue(Color);
colorG := GetGValue(Color);
ColorB:=GetBValue(Color);
DestImg := ABitmap.CreateIntfImage;
for y := CornerRect.top to CornerRect.bottom do
colorB := GetBValue(Color);
for y := CornerRect.Top to CornerRect.Bottom do
begin
Line:=DestImg.GetDataLineStart(y);
for x := CornerRect.left to CornerRect.right do
for x := CornerRect.Left to CornerRect.Right do
begin
{$IFDEF EnhancedRecordSupport}
RadiusDist := 1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y)));
@ -1529,22 +1535,21 @@ for y := CornerRect.top to CornerRect.bottom do
{$ENDIF}
if RadiusDist > 0 then
begin
Ptr:=pointer(PtrInt(Line) + 3*x);
Ptr^:=round(Ptr^ + (ColorB - Ptr^) * RadiusDist); inc(Ptr);
Ptr^:=round(Ptr^ + (ColorG - Ptr^) * RadiusDist); inc(Ptr);
Ptr^:=round(Ptr^ + (ColorR - Ptr^) * RadiusDist);
RedGreenBlue(ColorToRGB(ABitmap.Canvas.Pixels[x,y]), cr, cg, cb);
cb := round(cb + (ColorB - cb) * RadiusDist);
cg := round(cg + (ColorG - cg) * RadiusDist);
cr := round(cr + (ColorR - cr) * RadiusDist);
ABitmap.Canvas.Pixels[x,y] := RGBToColor(cr,cg,cb);
end;
end;
end;
ABitmap.LoadFromIntfImage(DestImg);
DestImg.Destroy;
end;
class procedure TGUITools.DrawAARoundCorner(ABitmap: TBitmap;
Point: T2DIntVector; Radius: integer; CornerPos: TCornerPos; Color: TColor;
ClipRect: T2DIntRect);
var CornerRect : T2DIntRect;
var
CornerRect: T2DIntRect;
Center: T2DIntVector;
Line: PByte;
Ptr: PByte;
@ -1554,8 +1559,7 @@ var CornerRect : T2DIntRect;
OrgCornerRect: T2DIntRect;
UnClippedCornerRect : T2DIntRect;
BitmapRect: T2DIntRect;
DestImg: TLazIntfImage;
cr,cb,cg: byte;
begin
if ABitmap.PixelFormat<>pf24bit then
raise exception.create('TSpkGUITools.DrawAARoundCorner: Bitmapa musi byæ w trybie 24-bitowym!');
@ -1563,7 +1567,7 @@ if ABitmap.PixelFormat<>pf24bit then
// Sprawdzamy poprawnoϾ
if Radius < 1 then
exit;
if (ABitmap.width=0) or (ABitmap.height=0) then
if (ABitmap.Width=0) or (ABitmap.Height=0) then
exit;
{$IFDEF EnhancedRecordSupport}
@ -1574,43 +1578,51 @@ OrgCornerRect:=T2DIntRect.create(Point.x,
Point.y + radius - 1);
// ...przycinamy do rozmiarów bitmapy
BitmapRect:=T2DIntRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
BitmapRect := T2DIntRect.create(0, 0, ABitmap.Width-1, ABitmap.Height-1);
{$ELSE}
// �?ród³owy rect...
OrgCornerRect.create(Point.x,
OrgCornerRect.Create(Point.x,
Point.y,
Point.x + radius - 1,
Point.y + radius - 1);
// ...przycinamy do rozmiarów bitmapy
BitmapRect.create(0, 0, ABitmap.width-1, ABitmap.height-1);
BitmapRect.Create(0, 0, ABitmap.Width-1, ABitmap.Height-1);
{$ENDIF}
if not(BitmapRect.intersectsWith(OrgCornerRect, UnClippedCornerRect)) then
if not BitmapRect.IntersectsWith(OrgCornerRect, UnClippedCornerRect) then
exit;
// ClipRect
if not(UnClippedCornerRect.IntersectsWith(ClipRect, CornerRect)) then
if not UnClippedCornerRect.IntersectsWith(ClipRect, CornerRect) then
exit;
// Jeœli nie ma czego rysowaæ, wychodzimy
if (CornerRect.left>CornerRect.right) or (CornerRect.top>CornerRect.bottom) then
if (CornerRect.Left > CornerRect.Right) or (CornerRect.Top > CornerRect.Bottom) then
exit;
// Szukamy œrodka ³uku - zale¿nie od rodzaju naro¿nika
{$IFDEF EnhancedRecordSupport}
case CornerPos of
cpLeftTop: Center:=T2DIntVector.create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop: Center:=T2DIntVector.create(Point.x, Point.y + Radius - 1);
cpLeftBottom: Center:=T2DIntVector.Create(Point.x + radius - 1, Point.y);
cpRightBottom: Center:=T2DIntVector.Create(Point.x, Point.y);
cpLeftTop:
Center := T2DIntVector.Create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop:
Center := T2DIntVector.Create(Point.x, Point.y + Radius - 1);
cpLeftBottom:
Center := T2DIntVector.Create(Point.x + radius - 1, Point.y);
cpRightBottom:
Center := T2DIntVector.Create(Point.x, Point.y);
end;
{$ELSE}
case CornerPos of
cpLeftTop: Center.create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop: Center.create(Point.x, Point.y + Radius - 1);
cpLeftBottom: Center.Create(Point.x + radius - 1, Point.y);
cpRightBottom: Center.Create(Point.x, Point.y);
cpLeftTop:
Center.Create(Point.x + radius - 1, Point.y + Radius - 1);
cpRightTop:
Center.Create(Point.x, Point.y + Radius - 1);
cpLeftBottom:
Center.Create(Point.x + radius - 1, Point.y);
cpRightBottom:
Center.Create(Point.x, Point.y);
end;
{$ENDIF}
@ -1618,13 +1630,11 @@ Color:=ColorToRGB(Color);
colorR := GetRValue(Color);
colorG := GetGValue(Color);
ColorB:=GetBValue(Color);
colorB := GetBValue(Color);
DestImg := ABitmap.CreateIntfImage;
for y := CornerRect.top to CornerRect.bottom do
for y := CornerRect.Top to CornerRect.Bottom do
begin
Line:=DestImg.GetDataLineStart(y);
for x := CornerRect.left to CornerRect.right do
for x := CornerRect.Left to CornerRect.Right do
begin
{$IFDEF EnhancedRecordSupport}
RadiusDist := 1 - abs((Radius - 1) - Center.DistanceTo(T2DIntVector.create(x, y)));
@ -1633,15 +1643,14 @@ for y := CornerRect.top to CornerRect.bottom do
{$ENDIF}
if RadiusDist > 0 then
begin
Ptr:=pointer(PtrInt(Line) + 3*x);
Ptr^:=round(Ptr^ + (ColorB - Ptr^) * RadiusDist); inc(Ptr);
Ptr^:=round(Ptr^ + (ColorG - Ptr^) * RadiusDist); inc(Ptr);
Ptr^:=round(Ptr^ + (ColorR - Ptr^) * RadiusDist);
RedGreenBlue(ColorToRGB(ABitmap.Canvas.Pixels[x,y]), cr, cg, cb);
cb := round(cb + (ColorB - cb) * RadiusDist);
cg := round(cg + (ColorG - cg) * RadiusDist);
cr := round(cr + (ColorR - cr) * RadiusDist);
ABitmap.Canvas.Pixels[x,y] := RGBToColor(cr,cg,cb);
end;
end;
end;
ABitmap.LoadFromIntfImage(DestImg);
DestImg.Destroy;
end;
class procedure TGUITools.DrawAARoundCorner(ACanvas: TCanvas;

View File

@ -28,7 +28,7 @@ const // ****************
LARGEBUTTON_CAPTION_TOP_RAIL = 45;
LARGEBUTTON_CAPTION_BOTTOM_RAIL = 58;
SMALLBUTTON_GLYPH_WIDTH = 16;
SMALLBUTTON_GLYPH_WIDTH = 20; //16;
SMALLBUTTON_BORDER_WIDTH = 2;
SMALLBUTTON_HALF_BORDER_WIDTH = 1;
SMALLBUTTON_PADDING = 2;