📄 sxskincheckbox.pas
字号:
if Enabled<>Value then
begin
if not (csLoading in ComponentState) then
begin
if Enabled then
StartGlyphChanging(gcaDisable) else
StartGlyphChanging(gcaEnable);
end;
inherited;
if not Enabled then
begin
FMouseOver:=False;
FDown:=False;
end;
if not (csLoading in ComponentState) then
ResetCheckBoxParams([cbrpTextOnFontChange,cbrpGlyphOnSizeChange,
cbrpGlyphOnStyleChange,cbrpInvalidateOnStyleChange]);
end;
end;
procedure TSXSkinCustomCheckBox.SetGlyphPosition(Value:TSXGlyphPosition);
begin
if Value<>FGlyphPosition then
begin
FGlyphPosition:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams;
end;
end;
procedure TSXSkinCustomCheckBox.SetAlignment(Value:TAlignment);
begin
if Value<>FAlignment then
begin
FAlignment:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams([cbrpText]);
end;
end;
procedure TSXSkinCustomCheckBox.SetVerticalAlignment(Value:TVerticalAlignment);
begin
if Value<>FVerticalAlignment then
begin
FVerticalAlignment:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams;
end;
end;
procedure TSXSkinCustomCheckBox.SetAutoSizeWidth(Value:Boolean);
begin
if Value<>FAutoSizeWidth then
begin
FAutoSizeWidth:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams;
end;
end;
procedure TSXSkinCustomCheckBox.SetAutoSizeHeight(Value:Boolean);
begin
if Value<>FAutoSizeHeight then
begin
FAutoSizeHeight:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams;
end;
end;
procedure TSXSkinCustomCheckBox.SetState(Value:TCheckBoxState);
begin
if Value<>FState then
begin
FState:=Value;
if not (csLoading in ComponentState) then
begin
ResetCheckBoxParams([cbrpTextOnFontChange,cbrpGlyphOnSizeChange,
cbrpGlyphOnStyleChange,cbrpInvalidateOnStyleChange]);
if Assigned(FOnChange) then
FOnChange(Self);
end;
end;
end;
procedure TSXSkinCustomCheckBox.SetAutoAlignFirstLine(Value:Boolean);
begin
if Value<>FAutoAlignFirstLine then
begin
FAutoAlignFirstLine:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams;
end;
end;
procedure TSXSkinCustomCheckBox.SetAllowGrayed(Value:Boolean);
begin
if Value<>FAllowGrayed then
begin
FAllowGrayed:=Value;
if not (csLoading in ComponentState) then
begin
if not FAllowGrayed and (State=cbGrayed) then
State:=cbUnchecked;
end;
end;
end;
procedure TSXSkinCustomCheckBox.SetChecked(Value:Boolean);
begin
if Value<>GetChecked then
begin
if Value then State:=cbChecked else
State:=cbUnchecked;
end;
end;
procedure TSXSkinCustomCheckBox.SetWordWrap(Value:Boolean);
begin
if Value<>FWordWrap then
begin
FWordWrap:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams([cbrpText]);
end;
end;
procedure TSXSkinCustomCheckBox.SetTextOffset(Value:Integer);
begin
if Value<>FTextOffset then
begin
FTextOffset:=Value;
if not (csLoading in ComponentState) then
ResetCheckBoxParams([cbrpText]);
end;
end;
function TSXSkinCustomCheckBox.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 TSXSkinCustomCheckBox.GetCurrentCBState(var CBState:TSXSkinCheckBoxStateParam);
var A:Integer;
Style:TSXSkinCheckBoxStyle;
begin
Finalize(CBState);
FillChar(CBState,sizeof(CBState),0);
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinCheckBoxStyle) then
begin
Style:=TSXSkinCheckBoxStyle(SkinLibrary.Styles[A]);
Style.GetCurrentCBState(CBState,FState,FDown,FMouseOver,FLastFocused,Enabled);
end;
end;
SetDefaultFontData(CBState.FD,Font);
end;
function TSXSkinCustomCheckBox.CreateCurrentGlyph:TBitmap32;
var CBState:TSXSkinCheckBoxStateParam;
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 TSXSkinCheckBoxStyle) then
begin
GetCurrentCBState(CBState);
if CBState.GlyphStyle<>'' then
SetGlyphByStyleName(CBState.GlyphStyle,Result);
end;
end;
end;
function TSXSkinCustomCheckBox.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 TSXSkinCustomCheckBox.PaintCurrentCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var A:Integer;
CBState:TSXSkinCheckBoxStateParam;
Style:TSXSkinGeneralStyle;
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentCBState(CBState);
A:=SkinLibrary.Styles.GetGStyleIndex(CBState.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(FLastCheckBoxTransform) and (FDoneSteps<FLastCheckBoxTransform.StepsNum) and
FLastCheckBoxTransform.DrawCaption then
begin
PaintCurrentOverStyleCaptionToBitmap(Bitmap.Handle,Rect,Rect,Rgn,Bitmap,X,Y);
end;
end;
end;
procedure TSXSkinCustomCheckBox.PaintCurrentBlendedCBStyle(Bitmap:TBitmap32;X,Y:Integer;Rect:TRect;Rgn:HRGN);
var BB:TBitmap32;
CurCB:TBitmap32;
Rgn2:HRGN;
begin
if HasTransformEffect(FLastCheckBoxTransform) and
(FDoneSteps<FLastCheckBoxTransform.StepsNum) and (FLastCheckBox<>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(FLastCheckBox,CurCB,FLastCheckBoxTransform,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 TSXSkinCustomCheckBox.PaintCurrentOverStyleCaptionToBitmap(DestCanvasHandle:HDC;
DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer);
var CBState:TSXSkinCheckBoxStateParam;
A,W,H:Integer;
Flags:Cardinal;
CurGlyph:TBitmap32;
TextRect,RR:TRect;
Style:TSXSkinGeneralstyle;
procedure DrawTextToBitmap(Bitmap:TBitmap32);
begin
Bitmap.Font:=Canvas.Font;
if CBState.FD.HasShadow then
begin
OffsetRect(TextRect,1,1);
if CBState.FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,CBState.FD.ShadowColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,CBState.FD.SmoothLevel,CBState.FD.ShadowColor);
OffsetRect(TextRect,-1,-1);
end;
if CBState.FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,CBState.FD.FontColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,CBState.FD.SmoothLevel,CBState.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 TSXSkinCheckBoxStyle) then
begin
GetCurrentCBState(CBState);
//OverStyle
if CBState.OverStyle<>'' then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(CBState.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
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 CBState.FD.DoPrepaint and (CBState.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 CBState.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 CBState.FD.DoPrepaint and (CBState.FD.SmoothLevel>0) then
FTextBitmap.DrawTo(Bitmap,TextRect.Left,TextRect.Top) else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -