LCL: Support for TImage.AntialiasingMode (stretching). Implement Win32 and GTK2. Issue #22205, patch from Chronos

git-svn-id: trunk@39894 -
This commit is contained in:
juha 2013-01-19 17:42:38 +00:00
parent 809f049924
commit 7548ba8e96
8 changed files with 40 additions and 2 deletions

View File

@ -464,6 +464,7 @@ type
TCustomImage = class(TGraphicControl)
private
FAntialiasingMode: TAntialiasingMode;
FOnPictureChanged: TNotifyEvent;
FPicture: TPicture;
FCenter: Boolean;
@ -472,6 +473,7 @@ type
FStretch: Boolean;
FUseAncestorCanvas: boolean;
function GetCanvas: TCanvas;
procedure SetAntialiasingMode(AValue: TAntialiasingMode);
procedure SetPicture(const AValue: TPicture);
procedure SetCenter(const AValue : Boolean);
procedure SetProportional(const AValue: Boolean);
@ -491,6 +493,7 @@ type
property Canvas: TCanvas read GetCanvas;
function DestRect: TRect; virtual;
public
property AntialiasingMode: TAntialiasingMode read FAntialiasingMode write SetAntialiasingMode default amDontCare;
property Align;
property AutoSize;
property Center: Boolean read FCenter write SetCenter default False;
@ -512,6 +515,7 @@ type
TImage = class(TCustomImage)
published
property AntialiasingMode;
property Align;
property Anchors;
property AutoSize;

View File

@ -65,6 +65,13 @@ begin
Result := inherited Canvas;
end;
procedure TCustomImage.SetAntialiasingMode(AValue: TAntialiasingMode);
begin
if FAntialiasingMode = AValue then Exit;
FAntialiasingMode := AValue;
PictureChanged(Self);
end;
procedure TCustomImage.SetPicture(const AValue: TPicture);
begin
if FPicture=AValue then exit;
@ -206,6 +213,7 @@ begin
C := inherited Canvas;
R := DestRect;
C.AntialiasingMode := FAntialiasingMode;
C.StretchDraw(R, Picture.Graphic);
FUseAncestorCanvas := True;

View File

@ -345,6 +345,7 @@ type
DCTextMetric: TDevContextTextMetric; // only valid if dcfTextMetricsValid set
PaintRectangle: TRect;// set during paint, BeginPaint/EndPaint
SavedContext: TGtkDeviceContext; // linked list of saved DCs
Antialiasing: Boolean;
constructor Create; virtual;
procedure CreateGDIObject(AGDIType: TGDIType);

View File

@ -251,6 +251,7 @@ type
procedure AddDummyNoteBookPage(NoteBookWidget: PGtkNoteBook);
{$ENDIF}
procedure DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean); override;
function DCGetPixel(CanvasHandle: HDC; X, Y: integer): TGraphicsColor; override;
procedure DCSetPixel(CanvasHandle: HDC; X, Y: integer; AColor: TGraphicsColor); override;
procedure DCRedraw(CanvasHandle: HDC); override;

View File

@ -3720,7 +3720,10 @@ var
else
if ShrinkWidth or ShrinkHeight
then ScaleMethod := GDK_INTERP_BILINEAR//GDK_INTERP_HYPER
else ScaleMethod := GDK_INTERP_BILINEAR;
else begin
if DstDevContext.Antialiasing then ScaleMethod := GDK_INTERP_BILINEAR
else ScaleMethod := GDK_INTERP_NEAREST;
end;
// Scale the src part to a temporary pixmap with the size of the
// destination rectangle
@ -5224,6 +5227,21 @@ begin
end;
procedure TGtk2WidgetSet.DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean
);
var
DC: TGtk2DeviceContext;
begin
if IsValidDC(CanvasHandle) then
begin
//if CanvasHandle = 1 then
//DC := Gtk2DefaultContext
//else
DC := TGtk2DeviceContext(CanvasHandle);
DC.Antialiasing := AEnabled;
end;
end;
{------------------------------------------------------------------------------
Function: NewDC

View File

@ -161,6 +161,7 @@ type
{ Destructor of the class }
destructor Destroy; override;
procedure DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean); override;
function LCLPlatform: TLCLPlatform; override;
function GetLCLCapability(ACapability: TLCLCapability): PtrUInt; override;

View File

@ -105,6 +105,12 @@ begin
inherited Destroy;
end;
procedure TWin32WidgetSet.DCSetAntialiasing(CanvasHandle: HDC; AEnabled: Boolean);
begin
if AEnabled then SetStretchBltMode(CanvasHandle, HALFTONE)
else SetStretchBltMode(CanvasHandle, COLORONCOLOR);
end;
{------------------------------------------------------------------------------
Method: TWin32WidgetSet.AppInit
Params: None

View File

@ -3567,7 +3567,6 @@ begin
Blend.AlphaFormat := AC_SRC_ALPHA;
end;
Windows.SetStretchBltMode(DestDC, STRETCH_HALFTONE);
Windows.SetBrushOrgEx(DestDC, 0, 0, nil);
if Mask = 0 then
begin