qt: reimplement GradientFill rectangle gradients using Gradient class instead of multiple brush drawing

git-svn-id: trunk@30969 -
This commit is contained in:
paul 2011-05-30 07:56:17 +00:00
parent 8a3c07043c
commit 5e7c2ab4d6
2 changed files with 24 additions and 45 deletions

View File

@ -575,8 +575,8 @@ begin
Result := WidgetSet.GetWindowOrgEx(dc, P); Result := WidgetSet.GetWindowOrgEx(dc, P);
end; end;
function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices : Longint; function GradientFill(DC: HDC; Vertices: PTriVertex; NumVertices: Longint;
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): Boolean; Meshes: Pointer; NumMeshes: Longint; Mode: Longint): Boolean;
begin begin
Result := WidgetSet.GradientFill(DC, Vertices, NumVertices, Meshes, NumMeshes, Mode); Result := WidgetSet.GradientFill(DC, Vertices, NumVertices, Meshes, NumMeshes, Mode);
end; end;

View File

@ -3863,12 +3863,12 @@ function TQtWidgetSet.GradientFill(DC: HDC; Vertices: PTriVertex;
NumVertices : Longint; NumVertices : Longint;
Meshes: Pointer; NumMeshes : Longint; Mode : Longint): boolean; Meshes: Pointer; NumMeshes : Longint; Mode : Longint): boolean;
function DoFillTriangle : Boolean; function DoFillTriangle: Boolean;
begin begin
Result := (Mode and GRADIENT_FILL_TRIANGLE) = GRADIENT_FILL_TRIANGLE; Result := (Mode and GRADIENT_FILL_TRIANGLE) = GRADIENT_FILL_TRIANGLE;
end; end;
function DoFillVRect : Boolean; function DoFillVRect: Boolean;
begin begin
Result := (Mode and GRADIENT_FILL_RECT_V) = GRADIENT_FILL_RECT_V; Result := (Mode and GRADIENT_FILL_RECT_V) = GRADIENT_FILL_RECT_V;
end; end;
@ -3925,14 +3925,14 @@ function TQtWidgetSet.GradientFill(DC: HDC; Vertices: PTriVertex;
Result := False; Result := False;
end; end;
function FillRectMesh(Mesh : tagGradientRect) : boolean; function FillRectMesh(Mesh: tagGradientRect) : boolean;
var var
TL,BR : tagTRIVERTEX; TL,BR: tagTRIVERTEX;
StartColor, EndColor : TColorRef; StartColor, EndColor, SwapColor: TQColor;
I, Swap : Longint; Swap: Longint;
SwapColors : Boolean; SwapColors: Boolean;
UseBrush : hBrush; Grad: QGradientH;
Steps, MaxSteps: Int64; Brush: QBrushH;
begin begin
with Mesh do with Mesh do
begin begin
@ -3955,45 +3955,24 @@ function TQtWidgetSet.GradientFill(DC: HDC; Vertices: PTriVertex;
BR.Y := TL.Y; BR.Y := TL.Y;
TL.Y := Swap; TL.Y := Swap;
end; end;
StartColor := RGB(TL.Red shr 8, TL.Green shr 8, TL.Blue shr 8); ColorRefToTQColor(RGB(TL.Red shr 8, TL.Green shr 8, TL.Blue shr 8), StartColor);
EndColor := RGB(BR.Red shr 8, BR.Green shr 8, BR.Blue shr 8); ColorRefToTQColor(RGB(BR.Red shr 8, BR.Green shr 8, BR.Blue shr 8), EndColor);
if SwapColors then if SwapColors then
begin begin
Swap := StartColor; SwapColor := StartColor;
StartColor := EndColor; StartColor := EndColor;
EndColor := Swap; EndColor := SwapColor;
end; end;
UseBrush := 0;
MaxSteps := GetDeviceCaps(DC, BITSPIXEL);
if MaxSteps >= 32 then
MaxSteps := $FFFFFFFF
else
if MaxSteps >= 4 then
MaxSteps := 1 shl MaxSteps
else
MaxSteps := 256;
if DoFillVRect then if DoFillVRect then
begin Grad := QLinearGradient_create(TL.X, TL.Y, TL.X, BR.Y)
Steps := Min(BR.Y - TL.Y, MaxSteps);
for I := 0 to Steps - 1 do
begin
GetGradientBrush(StartColor, EndColor, I, Steps, UseBrush);
LCLIntf.FillRect(DC, Rect(TL.X, TL.Y + I, BR.X, TL.Y + I + 1),
UseBrush);
end;
end
else else
begin Grad := QLinearGradient_create(TL.X, TL.Y, BR.X, TL.Y);
Steps := Min(BR.X - TL.X, MaxSteps); QGradient_setColorAt(Grad, 0, @StartColor);
for i := 0 to Steps - 1 do QGradient_setColorAt(Grad, 1, @EndColor);
begin Brush := QBrush_create(Grad);
GetGradientBrush(StartColor, EndColor, I, Steps, UseBrush); TQtDeviceContext(DC).fillRect(TL.X, TL.Y, BR.X - TL.X, BR.Y - TL.Y, Brush);
LCLIntf.FillRect(DC, Rect(TL.X + I, TL.Y, TL.X + I + 1, BR.Y), QGradient_destroy(Grad);
UseBrush); QBrush_destroy(Brush);
end;
end;
If UseBrush <> 0 then
LCLIntf.DeleteObject(UseBrush);
end; end;
end; end;
@ -4028,7 +4007,7 @@ begin
begin begin
if DoFillTriangle then if DoFillTriangle then
begin begin
If Not FillTriMesh(PGradientTriangle(Meshes)[I]) then if not FillTriMesh(PGradientTriangle(Meshes)[I]) then
exit; exit;
end end
else else