📄 sxskingroupbox.pas
字号:
FCaptionAlignment:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams;
end;
end;
procedure TSXSkinCustomGroupBox.SetWordWrap(Value:Boolean);
begin
if Value<>FWordWrap then
begin
FWordWrap:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams([gbrpText]);
end;
end;
procedure TSXSkinCustomGroupBox.SetGlyphType(Value:TSXGroupBoxGlyphType);
begin
if Value<>FGlyphType then
begin
FGlyphType:=Value;
if not (csLoading in ComponentState) then
begin
if csDesigning in ComponentState then
begin
case FGlyphType of
gtNone: FGlyphStyle:='';
gtCheckBox: if Copy(FGlyphStyle,1,9)<>'_CheckBox' then
FGlyphStyle:='_CheckBox';
gtRadioButton: if Copy(FGlyphStyle,1,12)<>'_RadioButton' then
FGlyphStyle:='_RadioButton';
end;
TabStop:=FGlyphType in [gtCheckBox,gtRadioButton];
end;
ResetGroupBoxParams([gbrpGlyphOnStyleChange,gbrpGlyphOnSizeChange]);
end;
end;
end;
procedure TSXSkinCustomGroupBox.SetTextOffset(Value:Integer);
begin
if Value<>FTextOffset then
begin
FTextOffset:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams([gbrpTextIfWordWrap]);
end;
end;
procedure TSXSkinCustomGroupBox.SetGlyphPosition(Value:TSXGroupBoxGlyphPosition);
begin
if Value<>FGlyphPosition then
begin
FGlyphPosition:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams;
end;
end;
procedure TSXSkinCustomGroupBox.SetUseLabelStyle(Value:Boolean);
begin
if Value<>FUseLabelStyle then
begin
FUseLabelStyle:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams([gbrpTextOnFontChange]);
end;
end;
procedure TSXSkinCustomGroupBox.SetAllowGrayed(Value:Boolean);
begin
if Value<>FAllowGrayed then
begin
FAllowGrayed:=Value;
if not FAllowGrayed and (State=cbGrayed) then
State:=cbUnchecked;
end;
end;
procedure TSXSkinCustomGroupBox.SetChecked(Value:Boolean);
begin
if Value<>GetChecked then
begin
if Value then State:=cbChecked else
State:=cbUnchecked;
end;
end;
procedure TSXSkinCustomGroupBox.SetGlyphStyle(const Value:String);
begin
if Value<>FGlyphStyle then
begin
FGlyphStyle:=Value;
if not (csLoading in ComponentState) then
ResetGroupBoxParams([gbrpGlyphOnStyleChange,gbrpTextIfWordWrap,gbrpTransparentRect]);
end;
end;
procedure TSXSkinCustomGroupBox.SetState(Value:TCheckBoxState);
var A:Integer;
begin
if Value<>FState then
begin
FState:=Value;
if not (csLoading in ComponentState) then
begin
ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
gbrpTransparentRect]);
if (FGlyphType=gtRadioButton) and (FState=cbChecked) 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 Assigned(FOnChange) then
FOnChange(Self);
end;
end;
end;
function TSXSkinCustomGroupBox.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='CL' then
begin
Result:=FCaptionRect.Left; exit;
end;
if VarName='CT' then
begin
Result:=FCaptionRect.Top; exit;
end;
if VarName='CR' then
begin
Result:=FCaptionRect.Right; exit;
end;
if VarName='CB' then
begin
Result:=FCaptionRect.Bottom; 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:=FGlyphRect.Right-FGlyphRect.Left; exit;
end;
if VarName='GlH' then
begin
Result:=FGlyphRect.Bottom-FGlyphRect.Top; 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 TSXSkinCustomGroupBox.GetCurrentGBState(var GBState:TSXSkinGroupBoxStateParam);
var A:Integer;
Style:TSXSkinGroupBoxStyle;
begin
Finalize(GBState);
FillChar(GBState,sizeof(GBState),0);
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinGroupBoxStyle) then
begin
Style:=TSXSkinGroupBoxStyle(SkinLibrary.Styles[A]);
Style.GetCurrentGBState(GBState,FMouseOver,FLastFocused,Enabled);
end;
end;
end;
procedure TSXSkinCustomGroupBox.PaintRectToBitmap(DestCanvasHandle:HDC;
DestCanvasRect:TRect;Rect:TRect;Rgn:HRGN;Bitmap:TBitmap32;X,Y:Integer;
WithSubItems:Boolean);
var A:Integer;
W,H:Integer;
GBState:TSXSkinGroupBoxStateParam;
RR:TRect;
FD:TSXFontData;
Style:TSXSkinGeneralStyle;
CurGlyph:TBitmap32;
TextRect:TRect;
Flags:Cardinal;
procedure DrawTextToBitmap(Bitmap:TBitmap32);
begin
Bitmap.Font:=Canvas.Font;
if FD.HasShadow then
begin
OffsetRect(TextRect,1,1);
if FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,FD.ShadowColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,FD.SmoothLevel,FD.ShadowColor);
OffsetRect(TextRect,-1,-1);
end;
if FD.SmoothLevel=0 then
DrawAlphaText(Bitmap,Caption,TextRect,Flags,FD.FontColor) else
DrawSmoothText(Bitmap,Caption,TextRect,Flags,FD.SmoothLevel,FD.FontColor);
end;
begin
FLastFocused:=Focused and TabStop;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
GetCurrentGBState(GBState);
//Style
A:=SkinLibrary.Styles.GetGStyleIndex(GBState.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;
//OverStyle
if GBState.OverStyle<>'' then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(GBState.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
GetCurrentGlyphStyle(FLastGlyphStyle);
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;
GetCurrentFontData(FD);
Flags:=DT_NOPREFIX or DT_NOCLIP or DT_TOP;
case FAlignment 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 FD.DoPrepaint and (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 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 FD.DoPrepaint and (FD.SmoothLevel>0) then
FTextBitmap.DrawTo(Bitmap,TextRect.Left,TextRect.Top) else
DrawTextToBitmap(Bitmap);
end;
end;
inherited;
end;
procedure TSXSkinCustomGroupBox.CMMouseLeave(var Msg:TMessage);
begin
if Enabled then
InternalMouseLeave;
end;
procedure TSXSkinCustomGroupBox.InternalMouseEnter;
begin
StartGlyphChanging(gcaHighlightIn);
FMouseOver:=True;
ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
gbrpTransparentRect]);
if Assigned(FOnMouseEnter) then
FOnMouseEnter(Self);
end;
procedure TSXSkinCustomGroupBox.InternalMouseLeave;
begin
if FMouseOver then
begin
StartGlyphChanging(gcaHighlightOut);
FMouseOver:=False;
ResetGroupBoxParams([gbrpTextOnFontChange,gbrpGlyphOnSizeChange,
gbrpGlyphOnStyleChange,gbrpInvalidateOnStyleChange,
gbrpTransparentRect]);
if Assigned(FOnMouseLeave) then
FOnMouseLeave(Self);
end;
end;
procedure TSXSkinCustomGroupBox.SkinChanged;
begin
if not (csLoading in ComponentState) then
begin
FLastGlyph.Free;
FLastGlyph:=nil;
if (FThread<>nil) and not FThread.Suspended then
FThread.Suspend;
ResetGroupBoxParams([gbrpText,gbrpGlyph,gbrpTransparentRect,gbrpInvalidateOnStyleChange]);
end;
inherited;
end;
function TSXSkinCustomGroupBox.GetCaption:TCaption;
begin
Result:=inherited Caption;
end;
function TSXSkinCustomGroupBox.GetChecked:Boolean;
begin
Result:=State<>cbUnchecked;
end;
procedure TSXSkinCustomGroupBox.SetCaption(const Value:TCaption);
begin
if csLoading in ComponentState then
begin
inherited Caption:=Value;
exit;
end;
if Caption<>Value then
begin
inherited Caption:=Value;
ResetGroupBoxParams([gbrpText]);
end;
end;
procedure TSXSkinCustomGroupBox.SetBounds(ALeft,ATop,AWidth,AHeight:Integer);
var DoReset:Boolean;
begin
if (ALeft=Left) and (ATop=Top) and (AWidth=Width) and (AHeight=Height) then exit;
DoReset:=(Width<>AWidth) or (Height<>AHeight);
inherited SetBounds(ALeft,ATop,AWidth,AHeight);
if not (csLoading in ComponentState) then
begin
if DoReset then
ResetGroupBoxParams([gbrpTextIfWordWrap,gbrpTransparentRect]) else
ResetGroupBoxParams([gbrpTransparentRect]);
end;
end;
procedure TSXSkinCustomGroupBox.CMFontChanged(var Message:TMessage);
begin
inherited;
if not (csLoading in ComponentState) then
ResetGroupBoxParams([gbrpTextOnFontChange]);
end;
procedure TSXSkinCustomGroupBox.GetCurrentGlyphStyle(var GStyle:String;
PGlyphWidth:PInteger=nil;PGlyphHeight:PInteger=nil);
var A,B:Integer;
GBStyle:TSXSkinGroupBoxStyle;
CBStyle:TSXSkinCheckBoxStyle;
CBState:TSXSkinCheckBoxStateParam;
RBStyle:TSXSkinRadioButtonStyle;
RBState:TSXSkinRadioButtonStateParam;
MSStyle:TSXSkinMultiStateStyle;
GlyphStyle:TSXSkinGeneralStyle;
Image:TSXSkinStyleImageElement;
procedure SetGStyle(const S:String); overload;
begin
if GStyle='' then GStyle:=S;
end;
procedure SetGStyle(const T:TSXSkinCheckBoxStateParam); overload;
begin
if GStyle='' then GStyle:=T.GlyphStyle;
if (PGlyphWidth<>nil) and (PGlyphWidth^=0) then
PGlyphWidth^:=T.GlyphWidth;
if (PGlyphHeight<>nil) and (PGlyphHeight^=0) then
PGlyphHeight^:=T.GlyphHeight;
end;
procedure SetGStyle(const T:TSXSkinRadioButtonStateParam); overload;
begin
if GStyle='' then GStyle:=T.GlyphStyle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -