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

View File

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