Delphi 随着Alpha的降低,玻璃背景上的绘图文本变得模糊
我正在对TIceTabSet(Chrome标签)组件进行一些更新。其中一个变化是增加透明度。除了课文之外,一切都很好。随着背景的alpha通道变低,文本变得越来越模糊。这是一个截图 下面是绘制选项卡的代码。其中大部分是原始的TIceTabSet代码。我只是添加了一些更改以使选项卡透明。对于示例屏幕截图,代码也做了一些修改。底部的DrawText命令是将文本绘制到画布的位置Delphi 随着Alpha的降低,玻璃背景上的绘图文本变得模糊,delphi,google-chrome,windows-7,transparency,gdi+,Delphi,Google Chrome,Windows 7,Transparency,Gdi+,我正在对TIceTabSet(Chrome标签)组件进行一些更新。其中一个变化是增加透明度。除了课文之外,一切都很好。随着背景的alpha通道变低,文本变得越来越模糊。这是一个截图 下面是绘制选项卡的代码。其中大部分是原始的TIceTabSet代码。我只是添加了一些更改以使选项卡透明。对于示例屏幕截图,代码也做了一些修改。底部的DrawText命令是将文本绘制到画布的位置 procedure TIceTabSet.InnerDraw(Canvas: TCanvas; TabRect: TRec
procedure TIceTabSet.InnerDraw(Canvas: TCanvas; TabRect: TRect; Item: TIceTab);
var
graphics : TGPGraphics;
Pen: TGPPen;
Brush: TGPSolidBrush;
path, linePath: TGPGraphicsPath;
linGrBrush: TGPLinearGradientBrush;
font: TGPFont;
solidBrush: TGPSolidBrush;
rectF: TGPRectF;
stringFormat: TGPStringFormat;
DC: HDC;
marginRight: integer;
iconY, iconX: integer;
textStart: Extended;
startColor, EndColor, textColor, borderColor: cardinal;
borderWidth: Integer;
TabProperties: TIceTabProperties;
Alpha: Byte;
begin
DC := Canvas.Handle;
TabProperties := GetTabProperties(Item);
Alpha := Item.Index * 50;
startColor := MakeGDIPColor(TabProperties.TabStyle.StartColor, Alpha);// TabProperties.TabStyle.Alpha);
endColor := MakeGDIPColor(TabProperties.TabStyle.StopColor, Alpha); //TabProperties.TabStyle.Alpha);
textColor := MakeGDIPColor(TabProperties.Font.Color, 255); //TabProperties.TabStyle.Alpha);
borderColor := MakeGDIPColor(TabProperties.BorderColor, TabProperties.TabStyle.Alpha);
borderWidth := TabProperties.BorderWidth;
graphics := TGPGraphics.Create(DC);
Brush := TGPSolidBrush.Create(borderColor);
Pen:= TGPPen.Create(borderColor);
Font := GetGDIPFont(Canvas, FTabActive.Font); //TabProperties.Font);
try
graphics.SetSmoothingMode(SmoothingModeHighQuality);
pen.SetWidth(borderWidth);
path := TGPGraphicsPath.Create();
try
path.AddBezier(TabRect.Left, TabRect.Bottom, TabRect.Left + FTabShape.LeftEdgeWidth / 2, TabRect.Bottom, TabRect.Left + FTabShape.LeftEdgeWidth / 2, TabRect.Top, TabRect.Left + FTabShape.LeftEdgeWidth, TabRect.Top);
path.AddLine(TabRect.Left + FTabShape.LeftEdgeWidth, TabRect.Top, TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top);
path.AddBezier(TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top, TabRect.Right - FTabShape.RightEdgeWidth / 2, TabRect.Top, TabRect.Right - FTabShape.RightEdgeWidth / 2, TabRect.Bottom, TabRect.Right, TabRect.Bottom);
linePath := TGPGraphicsPath.Create;
try
linePath.AddPath(path, false);
path.AddLine(TabRect.Right, TabRect.Bottom, TabRect.Left, TabRect.Bottom);
linGrBrush := TGPLinearGradientBrush.Create(
MakePoint(0, TabRect.Top),
MakePoint(0, TabRect.Bottom),
startColor,
endColor);
try
graphics.DrawPath(pen, linePath);
graphics.FillPath(linGrBrush, path);
finally
linGrBrush.Free;
end;
finally
linePath.Free;
end;
finally
path.Free;
end;
marginRight := 0;
if TabDisplaysCloseButton(Item) then
begin
if (HighLightTabClose = Item) and
(FTabCloseButton.ShowCircle) then
begin
pen.SetWidth(1);
pen.SetColor(MakeGDIPColor(FTabCloseButton.CrossColorHotTrack, 255));
brush.SetColor(MakeGDIPColor(FTabCloseButton.CircleColorHotTrack, 255));
graphics.FillEllipse(brush, TabRect.Right - FTabShape.RightEdgeWidth - 7 - 2,
TabRect.Top + ((TabRect.Bottom - TabRect.Top - 7) div 2) - 3,
(TabRect.Right - FTabShape.RightEdgeWidth) - (TabRect.Right - FTabShape.RightEdgeWidth - 7) + 6,
(TabRect.Top + ((TabRect.Bottom - TabRect.Top + 7) div 2)) - (TabRect.Top + ((TabRect.Bottom - TabRect.Top - 7) div 2)) + 6);
graphics.DrawLine(pen, TabRect.Right - FTabShape.RightEdgeWidth - 5, TabRect.Top + ((TabRect.Bottom - TabRect.Top - 5) div 2),
TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top + ((TabRect.Bottom - TabRect.Top + 5) div 2));
graphics.DrawLine(pen, TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top + ((TabRect.Bottom - TabRect.Top - 5) div 2),
TabRect.Right - FTabShape.RightEdgeWidth - 5, TabRect.Top + ((TabRect.Bottom - TabRect.Top + 5) div 2));
end
else
begin
pen.SetWidth(2);
if HighlightTabClose = Item then
pen.SetColor(MakeGDIPColor(FTabCloseButton.CrossColorHotTrack, 255))
else
pen.SetColor(MakeGDIPColor(FTabCloseButton.CrossColorNormal, 255));
graphics.DrawLine(pen, TabRect.Right - FTabShape.RightEdgeWidth - 7, TabRect.Top + ((TabRect.Bottom - TabRect.Top - 7) div 2),
TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top + ((TabRect.Bottom - TabRect.Top + 7) div 2));
graphics.DrawLine(pen, TabRect.Right - FTabShape.RightEdgeWidth, TabRect.Top + ((TabRect.Bottom - TabRect.Top - 7) div 2),
TabRect.Right - FTabShape.RightEdgeWidth - 7, TabRect.Top + ((TabRect.Bottom - TabRect.Top + 7) div 2));
end;
marginRight := 10;
end;
solidBrush:= TGPSolidBrush.Create(MakeGDIPColor(textColor, 255));
stringFormat:= TGPStringFormat.Create;
stringFormat.SetAlignment(StringAlignmentNear);
stringFormat.SetLineAlignment(StringAlignmentCenter);
stringFormat.SetTrimming(StringTrimmingEllipsisCharacter);
stringFormat.SetFormatFlags(StringFormatFlagsNoWrap);
SelectClipRgn(Canvas.Handle, 0);
textStart := TabRect.Left + FTabShape.LeftEdgeWidth;
iconX := 0;
iconY := 0;
if Assigned(Images) and (Item.ImageIndex <> -1) then
begin
iconY := TabRect.Top + ((TabRect.Bottom - TabRect.Top - Images.Height) div 2);
iconX := Round(textStart);
textStart := textStart + Images.Width + 4;
end;
rectF := MakeRect(textStart, TabRect.Top, TabRect.Right - textStart - FTabShape.RightEdgeWidth - marginRight,
TabRect.Bottom - TabRect.Top);
// ****** Text is drawn here *******
if rectF.Width > 10 then
graphics.DrawString(format('Alpha: %d', [Alpha]), -1, font, rectF, stringFormat, solidBrush);
// *********************************
finally
font.Free;
solidBrush.Free;
Pen.Free;
graphics.Free;
end;
if Assigned(Images) and
(Item.ImageIndex <> -1) then
Images.Draw(Canvas, iconX, iconY, Item.ImageIndex, true);
end;
procedure-TIceTabSet.InnerDraw(Canvas:TCanvas;TabRect:TRect;Item:TIceTab);
变量
图形:TGPGraphics;
钢笔:TGPPen;
刷子:TGPSolidBrush;
路径、线路径:TGPGraphicsPath;
灵草:TGPLinearGradientBrush;
字体:TGPFont;
solidBrush:TGPSolidBrush;
rectF:TGPRectF;
stringFormat:TGPStringFormat;
DC:HDC;
marginRight:整数;
iconY,iconX:整数;
textStart:扩展;
startColor、EndColor、textColor、borderColor:cardinal;
边框宽度:整数;
TabProperties:TIceTabProperties;
Alpha:字节;
开始
DC:=Canvas.Handle;
TabProperties:=GetTabProperties(项);
α:=项目索引*50;
startColor:=MakeGDIPColor(TabProperties.TabStyle.startColor,Alpha);//TabProperties.TabStyle.Alpha);
endColor:=MakeGDIPColor(TabProperties.TabStyle.StopColor,Alpha)//TabProperties.TabStyle.Alpha);
textColor:=MakeGDIPColor(TabProperties.Font.Color,255)//TabProperties.TabStyle.Alpha);
borderColor:=MakeGDIPColor(TabProperties.borderColor,TabProperties.TabStyle.Alpha);
borderWidth:=TabProperties.borderWidth;
图形:=TGPGraphics.Create(DC);
笔刷:=TGPSolidBrush.Create(borderColor);
画笔:=TGPPen.Create(borderColor);
Font:=GetGDIPFont(Canvas,FTabActive.Font)//TabProperties.Font);
尝试
图形。设置平滑模式(平滑模式高质量);
笔设置宽度(边框宽度);
路径:=TGPGraphicsPath.Create();
尝试
AddBezier(TabRect.Left,TabRect.Bottom,TabRect.Left+FTabShape.LeftEdgeWidth/2,TabRect.Bottom,TabRect.Left+FTabShape.LeftEdgeWidth/2,TabRect.Top,TabRect.Left+FTabShape.LeftEdgeWidth,TabRect.Top);
AddLine(TabRect.Left+FTabShape.LeftEdgeWidth、TabRect.Top、TabRect.Right-FTabShape.RightEdgeWidth、TabRect.Top);
AddBezier(TabRect.Right-FTabShape.rightedwidth,TabRect.Top,TabRect.Right-FTabShape.rightedwidth/2,TabRect.Top,TabRect.Right-FTabShape.rightedwidth/2,TabRect.Bottom,TabRect.Right,TabRect.Bottom);
linePath:=TGPGraphicsPath.Create;
尝试
linePath.AddPath(路径,false);
AddLine(TabRect.Right、TabRect.Bottom、TabRect.Left、TabRect.Bottom);
linGrBrush:=TGPLinearGradientBrush.Create(
MakePoint(0,TabRect.Top),
MakePoint(0,TabRect.Bottom),
startColor,
endColor);
尝试
图形绘制路径(笔、线路径);
图形填充路径(linGrBrush,path);
最后
免费的;
结束;
最后
linePath.Free;
结束;
最后
自由之路;
结束;
marginRight:=0;
如果选项卡显示关闭按钮(项目),则
开始
如果(HighLightTabClose=项目)和
(FTabCloseButton.ShowCircle)然后
开始
笔设置宽度(1);
SetColor(MakeGDIPColor(FTabCloseButton.CrossColorHotTrack,255));
SetColor(MakeGDIPColor(FTabCloseButton.CircleColorHotTrack,255));
图形.填充椭圆(画笔,选项卡右-FTabShape.RightEdgeWidth-7-2,
TabRect.Top+((TabRect.Bottom-TabRect.Top-7)div 2)-3,
(TabRect.Right-FTabShape.rightedwidth)-(TabRect.Right-FTabShape.rightedwidth-7)+6,
(TabRect.Top+((TabRect.Bottom-TabRect.Top+7)div 2))-(TabRect.Top+((TabRect.Bottom-TabRect.Top-7)div 2))+6);
图形.抽绳(画笔,TabRect.Right-FTabShape.RightEdgeWidth-5,TabRect.Top+((TabRect.Bottom-TabRect.Top-5)第2部分),
TabRect.Right-FTabShape.rightedwidth,TabRect.Top+((TabRect.Bottom-TabRect.Top+5)div 2));
图形绘制线(画笔,右TabRect.Right-FTabShape.RightEdgeWidth,右TabRect.Top+((下TabRect.Bottom-TabRect.Top-5)第2部分),
TabRect.Right-FTabShape.rightedwidth-5,TabRect.Top+((TabRect.Bottom-TabRect.Top+5)div 2));
结束
其他的
开始
笔设置宽度(2);
如果HighlightTabClose=项目,则
pen.SetColor(MakeGDIPColor(FTabCloseButton.CrossColorHotTrack,255))
其他的
SetColor(MakeGDIPColor(FTabCloseButton.CrossColorNormal,255));
图形绘制线(画笔,右TabRect.Right-FTabShape.RightEdgeWidth-7,右TabRect.Top+((下TabRect.Bottom-TabRect.Top-7)第2部分),
TabRect.Right-FTabShape.rightedwidth,TabRect.Top+((TabRect.Bottom-TabRect.Top+7)div 2));
图形绘制线(画笔,右TabRect.Right-FTabShape.RightEdgeWidth,右TabRect.Top+((下TabRect.Bottom-TabRect.Top-7)第2部分),
TabRect.Right-FTabShape.rightedwidth-7,TabRect.Top+((TabRect.Bottom-TabRect.Top+7)div 2));
结束;
边际收益率:=10;
结束;
solidBrush:=TGPSolidBrush.Create(MakeGDIPColor(textColor,255));
stringFormat:=TGPStringFormat.Create;
stringFormat.SetAlignment(StringAlignmentNear);
stringFormat.SetLineAlignment(StringAlignmentCenter);
SetTrimming(StringTrimmingEllipsisCharter);
SetFormatFlags(StringFormatFlagsNoWrap);
选择cliprgn(Canvas.Handle,0);
textStart:=TabRect.Left+FTabShape.LeftEdgeWidth;
iconX:=0;
iconY:=0;
如果分配了(图像)和(Item.ImageIndex-1),则
开始
iconY:=TabRect。
if rectF.Width > 10 then
begin
if (GetParentForm.GlassFrame.Enabled) and (GetParentForm.GlassFrame.SheetOfGlass) then
graphics.SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
graphics.DrawString(Item.DisplayCaption, -1, font, rectF, stringFormat, solidBrush);
end;
uses
GDIPAPI, GDIPOBJ;
procedure TForm1.FormCreate(Sender: TObject);
begin
Font.Color := clWhite;
GlassFrame.SheetOfGlass := True;
GlassFrame.Enabled := True;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
S: WideString;
GPFont: TGPFont;
GPGraphics: TGPGraphics;
GPSolidBrush: TGPSolidBrush;
GPGraphicsPath: TGPGraphicsPath;
begin
S := 'This is a sample text rendered on the sheet of Aero glass!';
GPFont := TGPFont.Create(Canvas.Handle, Font.Handle);
GPSolidBrush := TGPSolidBrush.Create(MakeColor(GetRValue(Font.Color),
GetGValue(Font.Color), GetBValue(Font.Color)));
GPGraphicsPath := TGPGraphicsPath.Create;
GPGraphicsPath.AddString(S, Length(S), TGPFontFamily.Create(Font.Name),
GPFont.GetStyle, GPFont.GetSize, MakePoint(20.0, 60.0), nil);
try
GPGraphics := TGPGraphics.Create(Canvas.Handle);
try
GPGraphics.SetSmoothingMode(SmoothingModeAntiAlias);
GPGraphics.FillPath(GPSolidBrush, GPGraphicsPath);
GPGraphics.DrawString(S, Length(S), GPFont, MakePoint(20.0, 20.0),
nil, GPSolidBrush);
GPGraphics.SetTextRenderingHint(
TextRenderingHintSingleBitPerPixelGridFit);
GPGraphics.DrawString(S, Length(S), GPFont, MakePoint(20.0, 40.0),
nil, GPSolidBrush);
finally
GPGraphics.Free;
end;
finally
GPFont.Free;
GPSolidBrush.Free;
GPGraphicsPath.Free;
end;
end;
procedure TForm1.FormPaint(Sender: TObject);
var
R: TRect;
ThemeData: HTHEME;
Opts: TDTTOpts;
begin
R := Rect(10, 10, 150, 30);
vcl.themes.DrawGlassText(Canvas.Handle, 'DrawGlassText Sample', R, 0, 3,
clBlack, TStyleManager.SystemStyle.GetElementDetails(ttsLabel));
OffsetRect(R, 160, 0);
ThemeData := OpenThemeData(Handle, 'textstyle');
Opts.dwSize := SizeOf(Opts);
Opts.crText := ColorToRGB(clBlack);
Opts.crShadow := $D0D0B0;
Opts.iTextShadowType := TST_SINGLE;
Opts.ptShadowOffset := Point(1, 1);
Opts.fApplyOverlay := True;
Opts.iGlowSize := 3;
Opts.dwFlags := DTT_TEXTCOLOR or DTT_SHADOWTYPE or DTT_SHADOWCOLOR
or DTT_SHADOWOFFSET or DTT_GLOWSIZE;
DrawThemeTextEx(ThemeData, Canvas.Handle, TEXT_LABEL, TS_NORMAL,
'DrawThemeTextEx Sample', -1, 0, @R, Opts);
OffsetRect(R, 180, 0);
Opts.crText := ColorToRGB(clBlack);
Opts.iGlowSize := 4;
Opts.fApplyOverlay := True;
Opts.dwFlags := DTT_TEXTCOLOR or DTT_GLOWSIZE;
DrawThemeTextEx(ThemeData, Canvas.Handle, TEXT_BODYTITLE, 0,
'Another Sample', -1, 0, @R, Opts);
CloseThemeData(ThemeData);
end;