कम हो गया है I TIceTabSet (क्रोम टैब) घटक में कई अपडेट कर रहा हूं। इन परिवर्तनों में से एक पारदर्शिता जोड़ने के लिए है। पाठ से अलग सबकुछ ठीक काम करता है। चूंकि पृष्ठभूमि के अल्फा चैनल कम हो जाते हैं, पाठ अधिक से अधिक धुंधला हो जाता है। यहां एक स्क्रीनशॉट है।ग्लास पृष्ठभूमि पर ड्राइंग टेक्स्ट धुंधला हो जाता है क्योंकि अल्फा
यहाँ कोड है जो टैब खींचता है। इसमें से अधिकांश मूल TIceTabSet कोड है। मैंने टैब को पारदर्शी बनाने के लिए बस कुछ बदलाव जोड़े हैं। उदाहरण स्क्रीनशॉट के लिए भी कोड को थोड़ा बदल दिया गया है। नीचे DrawText कमांड है जहां पाठ कैनवास के लिए खींचा जाता है।
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;
आप पूर्ण स्रोत here डाउनलोड कर सकते हैं। कृपया ध्यान रखें कि यह एक काम प्रगति पर है। स्रोत पूर्ण होने पर मूल लेखक को वापस सबमिट किया जाएगा।
अद्यतन 1
रूप TLama निश्चित रूप से सुझाव दिया कोड बदलने में मदद करता है, लेकिन यह पूरी तरह से समस्या ठीक नहीं होती। यहाँ कैसे पाठ अब दिखाई देता है:
... यहाँ कैसे गूगल क्रोम दिखाई देता है:
अद्यतन 2
यह इस प्रकार से TextRenderingHintSingleBitPerPixelGridFit साथ दिखाई देता है ।
मैं सभी विकल्प की कोशिश की है और TextRenderingHintAntiAlias सबसे अच्छा परिणाम देता है।
बस एक कोड के बाकी के बारे में कुछ संकेत (मुझे पता है कि अपने काम अभी भी चल रहा है), लेकिन ऐसा लगता है कि आप अपनी ड्राइंग प्रक्रिया में मिश्रित फ़ॉन्ट गुण (मुझे लगता है कि आप इसके बारे में जानते हैं)। 'TIceTabProperties.FFont.OnChange' ईवेंट हैंडलर को लागू करना भी न भूलें, जहां 'फ़ॉन्ट' संपत्ति परिवर्तन को प्रतिबिंबित करने के लिए 'FIceTabSet'' को अमान्य करें। और समूहों में विधियों और गुणों के प्रारूपण और क्रम को रखने की कोशिश करें, मेरा मतलब है कि सेटर्स, संदेश हैंडलर और गुण स्पष्ट रूप से अलग समूहों में देखने के लिए सर्वोत्तम हैं। – TLama
@TLama: टिप्पणी के लिए धन्यवाद। मैं वर्तमान में सबकुछ काम करने की कोशिश कर रहा हूं, फिर मैं मौजूदा कोड को साफ करने जा रहा हूं (जो कि दो साल से अधिक पुराना है और काफी ध्यान देने की जरूरत है)। – norgepaul
क्या आपने ['TextRenderingHintSingleBitPerPixelGridFit'] (http://msdn.microsoft.com/en-us/library/ms534404%28v=vs.85%29.aspx) मोड की कोशिश की है? – TLama