📄 sxskinradiobutton.pas
字号:
if not (csLoading in ComponentState) then
ResetRadioButtonParams([rbrpTextOnFontChange,rbrpGlyphOnSizeChange,
rbrpGlyphOnStyleChange,rbrpInvalidateOnStyleChange]);
end;
end;
procedure TSXSkinCustomRadioButton.SetGlyphPosition(Value:TSXGlyphPosition);
begin
if Value<>FGlyphPosition then
begin
FGlyphPosition:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams;
end;
end;
procedure TSXSkinCustomRadioButton.SetAlignment(Value:TAlignment);
begin
if Value<>FAlignment then
begin
FAlignment:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams([rbrpText]);
end;
end;
procedure TSXSkinCustomRadioButton.SetVerticalAlignment(Value:TVerticalAlignment);
begin
if Value<>FVerticalAlignment then
begin
FVerticalAlignment:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams;
end;
end;
procedure TSXSkinCustomRadioButton.SetAutoSizeWidth(Value:Boolean);
begin
if Value<>FAutoSizeWidth then
begin
FAutoSizeWidth:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams;
end;
end;
procedure TSXSkinCustomRadioButton.SetAutoSizeHeight(Value:Boolean);
begin
if Value<>FAutoSizeHeight then
begin
FAutoSizeHeight:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams;
end;
end;
procedure TSXSkinCustomRadioButton.SetAutoAlignFirstLine(Value:Boolean);
begin
if Value<>FAutoAlignFirstLine then
begin
FAutoAlignFirstLine:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams;
end;
end;
procedure TSXSkinCustomRadioButton.SetChecked(Value:Boolean);
var A:Integer;
begin
if Value<>FChecked then
begin
FChecked:=Value;
if not (csLoading in ComponentState) then
begin
ResetRadioButtonParams([rbrpTextOnFontChange,rbrpGlyphOnSizeChange,
rbrpGlyphOnStyleChange,rbrpInvalidateOnStyleChange]);
if FChecked and (Parent<>nil) then
begin
for A:=0 to Parent.ControlCount-1 do
if (Parent.Controls[A]<>Self) and (Parent.Controls[A] is TSXSkinCustomRadioButton) and
TSXSkinCustomRadioButton(Parent.Controls[A]).Checked then
TSXSkinCustomRadioButton(Parent.Controls[A]).Checked:=False else
if (Parent.Controls[A]<>Self) and (Parent.Controls[A] is TSXSkinCustomGroupBox) and
(TSXSkinCustomGroupBox(Parent.Controls[A]).GlyphType=gtRadioButton) and
(TSXSkinCustomGroupBox(Parent.Controls[A]).State=cbChecked) then
TSXSkinCustomGroupBox(Parent.Controls[A]).State:=cbUnchecked;
end;
if FChecked and Assigned(FOnChange) then
FOnChange(Self);
end;
end;
end;
procedure TSXSkinCustomRadioButton.SetWordWrap(Value:Boolean);
begin
if Value<>FWordWrap then
begin
FWordWrap:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams([rbrpText]);
end;
end;
procedure TSXSkinCustomRadioButton.SetTextOffset(Value:Integer);
begin
if Value<>FTextOffset then
begin
FTextOffset:=Value;
if not (csLoading in ComponentState) then
ResetRadioButtonParams([rbrpText]);
end;
end;
function TSXSkinCustomRadioButton.OnGetVariable(const VarName:String;var Error:Boolean):Single;
begin
Result:=0;
if VarName='W' then
begin
Result:=Width; exit;
end;
if VarName='H' then
begin
Result:=Height; exit;
end;
if VarName='GlX' then
begin
Result:=FGlyphRect.Left; exit;
end;
if VarName='GlY' then
begin
Result:=FGlyphRect.Top; exit;
end;
if VarName='GlW' then
begin
Result:=FGlyphWidth; exit;
end;
if VarName='GlH' then
begin
Result:=FGlyphHeight; exit;
end;
if VarName='TL' then
begin
Result:=FTextRect.Left; exit;
end;
if VarName='TT' then
begin
Result:=FTextRect.Top; exit;
end;
if VarName='TR' then
begin
Result:=FTextRect.Right; exit;
end;
if VarName='TB' then
begin
Result:=FTextRect.Bottom; exit;
end;
Error:=True;
end;
procedure TSXSkinCustomRadioButton.GetCurrentRBState(var RBState:TSXSkinRadioButtonStateParam);
var A:Integer;
Style:TSXSkinRadioButtonStyle;
begin
Finalize(RBState);
FillChar(RBState,sizeof(RBState),0);
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinRadioButtonStyle) then
begin
Style:=TSXSkinRadioButtonStyle(SkinLibrary.Styles[A]);
Style.GetCurrentRBState(RBState,FChecked,FDown,FMouseOver,FLastFocused,Enabled);
end;
end;
SetDefaultFontData(RBState.FD,Font);
end;
function TSXSkinCustomRadioButton.CreateCurrentGlyph:TBitmap32;
var RBState:TSXSkinRadioButtonStateParam;
A:Integer;
procedure SetGlyphByStyleName(const StyleName:String;var BB:TBitmap32);
var C:Integer;
GlyphStyle:TSXSkinGeneralStyle;
Rgn:HRGN;
begin
C:=SkinLibrary.Styles.GetGStyleIndex(StyleName,FGlyphWidth,FGlyphHeight);
if C>=0 then
begin
GlyphStyle:=TSXSkinGeneralStyle(SkinLibrary.Styles[C]);
BB:=TBitmap32.Create;
BB.SetSize(FGlyphWidth,FGlyphHeight);
BB.Clear(0);
BB.DrawMode:=dmBlend;
BB.CombineMode:=cmMerge;
Rgn:=CreateRectRgn(0,0,BB.Width,BB.Height);
GlyphStyle.DrawToBitmap(Self,CEID_Glyph,BB,0,0,BB.Width,BB.Height,Rect(0,0,BB.Width,BB.Height),
Rgn,SkinLibrary);
DeleteObject(Rgn);
end;
end;
begin
Result:=nil;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinRadioButtonStyle) then
begin
GetCurrentRBState(RBState);
if RBState.GlyphStyle<>'' then
SetGlyphByStyleName(RBState.GlyphStyle,Result);
end;
end;
end;
function TSXSkinCustomRadioButton.CreateCurrentBlendedGlyph:TBitmap32;
var B:TBitmap32;
begin
Result:=CreateCurrentGlyph;
if (Result<>nil) and HasTransformEffect(FLastGlyphTransform) and
(FDoneSteps<FLastGlyphTransform.StepsNum) and (FLastGlyph<>nil) then
begin
B:=Result;
try
Result:=TBitmap32.Create;
Result.SetSize(B.Width,B.Height);
Result.DrawMode:=dmBlend;
Result.CombineMode:=cmMerge;
ApplyTransformEffectToBitmaps(FLastGlyph,B,FLastGlyphTransform,FDoneSteps,Result);
finally
B.Free;
end;
end;
end;
procedure TSXSkinCustomRadioButton.PaintCurrentCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var A:Integer;
RBState:TSXSkinRadioButtonStateParam;
Style:TSXSkinGeneralStyle;
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentRBState(RBState);
A:=SkinLibrary.Styles.GetGStyleIndex(RBState.Style,Width,Height);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Style.DrawToBitmap(Self,CEID_Back,Bitmap,X,Y,Width,Height,Rect,Rgn,SkinLibrary,VComparer);
end;
//
if HasTransformEffect(FLastRadioButtonTransform) and (FDoneSteps<FLastRadioButtonTransform.StepsNum) and
FLastRadioButtonTransform.DrawCaption then
begin
PaintCurrentOverStyleCaptionToBitmap(Bitmap.Handle,Rect,Rect,Rgn,Bitmap,X,Y);
end;
end;
end;
procedure TSXSkinCustomRadioButton.PaintCurrentBlendedCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var BB:TBitmap32;
CurCB:TBitmap32;
Rgn2:HRGN;
begin
if HasTransformEffect(FLastRadioButtonTransform) and
(FDoneSteps<FLastRadioButtonTransform.StepsNum) and (FLastRadioButton<>nil) then
begin
CurCB:=TBitmap32.Create;
BB:=TBitmap32.Create;
try
CurCB.DrawMode:=dmBlend;
CurCB.CombineMode:=cmMerge;
BB.DrawMode:=dmBlend;
BB.CombineMode:=cmMerge;
CurCB.SetSize(Width,Height);
CurCB.Clear(0);
Rgn2:=CreateRectRgn(0,0,Width,Height);
PaintCurrentCBStyle(CurCB,0,0,Types.Rect(0,0,Width,Height),Rgn2);
DeleteObject(Rgn2);
BB.SetSize(Width,Height);
ApplyTransformEffectToBitmaps(FLastRadioButton,CurCB,FLastRadioButtonTransform,FDoneSteps,BB);
BB.DrawTo(Bitmap,X-Rect.Left,Y-Rect.Top);
finally
BB.Free;
CurCB.Free;
end;
end else PaintCurrentCBStyle(Bitmap,X,Y,Rect,Rgn);
end;
procedure TSXSkinCustomRadioButton.PaintCurrentOverStyleCaptionToBitmap(DestCanvasHandle:HDC;
DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer);
var RBState:TSXSkinRadioButtonStateParam;
A,W,H:Integer;
Flags:Cardinal;
CurGlyph:TBitmap32;
TextRect,RR:TRect;
Style:TSXSkinGeneralstyle;
procedure DrawTextToBitmap(Bitmap:TBitmap32);
begin
Bitmap.Font:=Canvas.Font;
if RBState.FD.HasShadow then
begin
OffsetRect(TextRect,1,1);
if RBState.FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,RBState.FD.ShadowColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,RBState.FD.SmoothLevel,RBState.FD.ShadowColor);
OffsetRect(TextRect,-1,-1);
end;
if RBState.FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,RBState.FD.FontColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,RBState.FD.SmoothLevel,RBState.FD.FontColor);
end;
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinRadioButtonStyle) then
begin
GetCurrentRBState(RBState);
//OverStyle
if RBState.OverStyle<>'' then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(RBState.OverStyle,Width,Height);
if A>=0 then
begin
Style:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
Style.DrawToBitmap(Self,CEID_Back,Bitmap,X,Y,Width,Height,Rect,Rgn,SkinLibrary,VComparer);
end;
end;
//Glyph
if RectInRegion(Rgn,FGlyphRect) then
begin
CurGlyph:=CreateCurrentBlendedGlyph;
try
if CurGlyph<>nil then
Bitmap.Draw(X-Rect.Left+FGlyphRect.Left,Y-Rect.Top+FGlyphRect.Top,CurGlyph);
finally
CurGlyph.Free;
end;
end;
//Text
if (Caption<>'') and RectInRegion(Rgn,FTextRect) then
begin
FLastFocused:=Focused;
Bitmap.Font:=Canvas.Font;
Flags:=DT_NOPREFIX or DT_TOP;
case Alignment of
taLeftJustify: Flags:=Flags or DT_LEFT;
taRightJustify: Flags:=Flags or DT_RIGHT;
taCenter: Flags:=Flags or DT_CENTER;
end;
if FWordWrap then Flags:=Flags or DT_WORDBREAK;
TextRect:=FTextRect;
OffsetRect(TextRect,X-Rect.Left+FLastTextLeftOffset,Y-Rect.Top+FLastTextTopOffset);
Dec(TextRect.Right,FLastTextLeftOffset+FLastTextRightOffset);
Dec(TextRect.Bottom,FLastTextTopOffset+FLastTextBottomOffset);
if RBState.FD.DoPrepaint and (RBState.FD.SmoothLevel>0) and (FTextBitmap=nil) then
begin
FTextBitmap:=TBitmap32.Create;
FTextBitmap.DrawMode:=dmBlend;
FTextBitmap.CombineMode:=cmMerge;
W:=TextRect.Right-TextRect.Left;
H:=TextRect.Bottom-TextRect.Top;
if RBState.FD.HasShadow then
begin
Inc(W); Inc(H);
end;
FTextBitmap.SetSize(W,H);
FTextBitmap.Clear(0);
RR:=TextRect;
OffsetRect(TextRect,-TextRect.Left,-TextRect.Top);
DrawTextToBitmap(FTextBitmap);
TextRect:=RR;
end;
if RBState.FD.DoPrepaint and (RBState.FD.SmoothLevel>0) then
FTextBitmap.DrawTo(Bitmap,TextRect.Left,TextRect.Top) else
DrawTextToBitmap(Bitmap);
end;
end;
end;
end;
procedure TSXSkinCustomRadioButton.PaintRectToBitmap(DestCanvasHandle:HDC;
DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
WithSubItems:Boolean);
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
PaintCurrentBlendedCBStyle(Bitmap,X,Y,Rect,Rgn);
if not (HasTransformEffect(FLastRadioButtonTransform) and (FDoneSteps<FLastRadioButtonTransform.StepsNum) and
FLastRadioButtonTransform.DrawCaption) then
PaintCurrentOverStyleCaptionToBitmap(DestCanvasHandle,DestCanvasRect,Rect,Rgn,Bitmap,X,Y);
end;
inherited;
end;
procedure TSXSkinCustomRadioButton.InternalMouseEnter;
begin
if Enabled then
StartGlyphChanging(gcaHighlightIn);
FMouseOver:=True;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -