📄 sxskinbutton.pas
字号:
GetCurrentTransformEffect(btButton,T,BTransform);
GetCurrentTransformEffect(btGlyph,T,GTransform);
GetCurrentTransformEffect(btDDGlyph,T,DDGTransform);
NeedThread:=HasTransformEffect(BTransform) or
HasTransformEffect(GTransform) or
HasTransformEffect(DDGTransform);
if NeedThread then
begin
CreateThreadIfNeeded;
if HasTransformEffect(GTransform) then
B:=CreateCurrentBlendedGlyph else B:=nil;
FLastGlyph.Free;
FLastGlyph:=B;
//
if HasTransformEffect(DDGTransform) then
B:=CreateCurrentBlendedDropDownGlyph else B:=nil;
FLastDropDownGlyph.Free;
FLastDropDownGlyph:=B;
//
if HasTransformEffect(BTransform) then
begin
B:=TBitmap32.Create;
B.DrawMode:=dmBlend;
B.CombineMode:=cmMerge;
B.SetSize(Width,Height);
B.Clear(0);
Rgn:=CreateRectRgn(0,0,Width,Height);
PaintCurrentBlendedBStyle(B,0,0,Rect(0,0,Width,Height),Rgn);
if not (HasTransformEffect(FLastButtonTransform) and (FDoneSteps<FLastButtonTransform.StepsNum)) and
BTransform.DrawCaption then
PaintCurrentOverStyleCaptionToBitmap(B.Handle,B.BoundsRect,Rect(0,0,Width,Height),Rgn,B,0,0);
DeleteObject(Rgn);
end else B:=nil;
FLastButton.Free;
FLastButton:=B;
//
FDoneSteps:=1;
if FThread.Suspended then
FThread.Resume;
end else
if (FThread<>nil) and not FThread.Suspended then
begin
FDoneSteps:=MaxInt;
FThread.Suspend;
end;
FLastButtonTransform:=BTransform;
FLastGlyphTransform:=GTransform;
FLastDDGlyphTransform:=DDGTransform;
end;
procedure TSXSkinCustomButton.SkinChanged;
begin
if not (csLoading in ComponentState) then
begin
FLastGlyph.Free;
FLastGlyph:=nil;
FLastDropDownGlyph.Free;
FLastDropDownGlyph:=nil;
FLastButton.Free;
FLastButton:=nil;
FTextBitmap.Free;
FTextBitmap:=nil;
if (FThread<>nil) and not FThread.Suspended then
FThread.Suspend;
ResetButtonParams([brpText,brpGlyph,brpDDGlyph]);
end;
inherited;
end;
function TSXSkinCustomButton.GetCaption:TCaption;
begin
Result:=inherited Caption;
end;
procedure TSXSkinCustomButton.SetCaption(const Value:TCaption);
begin
if Caption<>Value then
begin
inherited Caption:=Value;
if not (csLoading in ComponentState) then
ResetButtonParams([brpText]);
end;
end;
procedure TSXSkinCustomButton.SetBounds(ALeft,ATop,AWidth,AHeight:Integer);
begin
if (ALeft=Left) and (ATop=Top) and (AWidth=Width) and (AHeight=Height) then exit;
inherited SetBounds(ALeft,ATop,AWidth,AHeight);
if not (csLoading in ComponentState) then
ResetButtonParams([brpTextIfWordWrap]);
end;
procedure TSXSkinCustomButton.CMFontChanged(var Message:TMessage);
begin
inherited;
if not (csLoading in ComponentState) then
ResetButtonParams([brpTextOnFontChange]);
end;
procedure TSXSkinCustomButton.Loaded;
begin
inherited;
ResetButtonParams([brpText,brpGlyph,brpDDGlyph]);
end;
procedure TSXSkinCustomButton.WMSetFocus(var Msg:TWMSetFocus);
begin
if not (csLoading in ComponentState) then
StartGlyphChanging(gcaFocus);
FLastFocused:=True;
if not (csLoading in ComponentState) then
ResetButtonParams([brpInvalidateOnStyleChange]);
end;
procedure TSXSkinCustomButton.WMKillFocus(var Msg:TWMKillFocus);
begin
if not (csLoading in ComponentState) then
StartGlyphChanging(gcaUnfocus);
FLastFocused:=False;
if not (csLoading in ComponentState) then
ResetButtonParams([brpInvalidateOnStyleChange]);
if FDown then
begin
StartGlyphChanging(gcaUp);
FDown:=False;
ResetButtonParams([brpInvalidateOnStyleChange]);
end;
end;
procedure TSXSkinCustomButton.DoKeyDown(var Msg: TMessage);
begin
inherited;
if Enabled and (Msg.WParam in [VK_SPACE,VK_RETURN]) then
begin
StartGlyphChanging(gcaDown);
FDown:=True;
ResetButtonParams([brpTextOnFontChange,brpGlyphOnStyleChange,
brpDDGlyphOnStyleChange,brpInvalidateOnStyleChange]);
end;
end;
procedure TSXSkinCustomButton.DoKeyUp(var Msg: TMessage);
begin
inherited;
if Enabled and FDown then
begin
StartGlyphChanging(gcaUp);
FDown:=False;
ResetButtonParams([brpTextOnFontChange,brpGlyphOnStyleChange,
brpDDGlyphOnStyleChange,brpInvalidateOnStyleChange]);
if Msg.WParam in [VK_SPACE,VK_RETURN] then
begin
Click;
end;
end;
end;
procedure TSXSkinCustomButton.GetCurrentBState(var BState:TSXSkinButtonStateParam);
var A:Integer;
Style:TSXSkinButtonStyle;
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinButtonStyle) then
begin
Style:=TSXSkinButtonStyle(SkinLibrary.Styles[A]);
Style.GetCurrentBState(BState,FChecked,Enabled,FMouseOver,FDown,FLastFocused);
end;
end else
begin
Finalize(BState);
FillChar(BState,sizeof(BState),0);
end;
SetDefaultFontData(BState.FD,Font);
end;
procedure TSXSkinCustomButton.GetCurrentGlyphStyle(var GStyle:String;PGlyphWidth:PInteger=nil;
PGlyphHeight:PInteger=nil;PUseFilter:PBoolean=nil);
var A,B:Integer;
MSStyle:TSXSkinMultiStateStyle;
MSCStyle:TSXSkinMultiStateCheckStyle;
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;
if (PGlyphWidth<>nil) and (PGlyphWidth^=0) then
PGlyphWidth^:=T.GlyphWidth;
if (PGlyphHeight<>nil) and (PGlyphHeight^=0) then
PGlyphHeight^:=T.GlyphHeight;
end;
begin
GStyle:='';
if PGlyphWidth<>nil then PGlyphWidth^:=FGlyphWidth;
if PGlyphHeight<>nil then PGlyphHeight^:=FGlyphHeight;
if PUseFilter<>nil then PUseFilter^:=False;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(FGlyphStyle);
if A>=0 then
begin
if SkinLibrary.Styles[A] is TSXSkinMultiStateStyle then
begin
MSStyle:=TSXSkinMultiStateStyle(SkinLibrary.Styles[A]);
if not Enabled then
begin
SetGStyle(MSStyle.RStyle);
SetGStyle(MSStyle.NStyle);
end else
if FDown then
begin
SetGStyle(MSStyle.DStyle);
SetGStyle(MSStyle.NStyle);
end else
if FMouseOver then
begin
SetGStyle(MSStyle.HStyle);
SetGStyle(MSStyle.NStyle);
end else SetGStyle(MSStyle.NStyle);
end else
if SkinLibrary.Styles[A] is TSXSkinMultiStateCheckStyle then
begin
MSCStyle:=TSXSkinMultiStateCheckStyle(SkinLibrary.Styles[A]);
if FChecked then
begin
if not Enabled then
begin
SetGStyle(MSCStyle.RCStyle);
SetGStyle(MSCStyle.RUStyle);
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
end else
if FDown then
begin
SetGStyle(MSCStyle.DCStyle);
SetGStyle(MSCStyle.DUStyle);
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
end else
if FMouseOver then
begin
SetGStyle(MSCStyle.HCStyle);
SetGStyle(MSCStyle.HUStyle);
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
end else
begin
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
end;
end else
begin
if not Enabled then
begin
SetGStyle(MSCStyle.RUStyle);
SetGStyle(MSCStyle.NUStyle);
end else
if FDown then
begin
SetGStyle(MSCStyle.DUStyle);
SetGStyle(MSCStyle.NUStyle);
end else
if FMouseOver then
begin
SetGStyle(MSCStyle.HUStyle);
SetGStyle(MSCStyle.NUStyle);
end else SetGStyle(MSCStyle.NUStyle);
end;
end else
begin
GStyle:=FGlyphStyle;
if PUseFilter<>nil then
PUseFilter^:=True;
end;
end;
if (GStyle<>'') and ((PGlyphWidth<>nil) or (PGlyphHeight<>nil)) and
((PGlyphWidth^=0) and (PGlyphHeight^=0)) then
begin
A:=SkinLibrary.Styles.GetGStyleIndex(GStyle,0,0);
if A>=0 then
begin
GlyphStyle:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
for B:=0 to GlyphStyle.Elements.Count-1 do
if GlyphStyle.Elements[B] is TSXSkinStyleImageElement then
begin
Image:=TSXSkinStyleImageElement(GlyphStyle.Elements[B]);
Image.ValidateBitmap(SkinLibrary);
if Image.Bitmap<>nil then
begin
if (PGlyphWidth<>nil) and (PGlyphWidth^=0) then
PGlyphWidth^:=Image.Bitmap.Width;
if (PGlyphHeight<>nil) and (PGlyphHeight^=0) then
PGlyphHeight^:=Image.Bitmap.Height;
end;
end;
end;
end;
end;
end;
procedure TSXSkinCustomButton.GetCurrentDropDownGlyphStyle(var GStyle:String;PGlyphWidth:PInteger=nil;
PGlyphHeight:PInteger=nil);
var A,B:Integer;
BStyle:TSXSkinButtonStyle;
MSStyle:TSXSkinMultiStateStyle;
MSCStyle:TSXSkinMultiStateCheckStyle;
GlyphStyle:TSXSkinGeneralStyle;
Image:TSXSkinStyleImageElement;
procedure SetGStyle(const S:String); overload;
begin
if GStyle='' then GStyle:=S;
end;
begin
GStyle:='';
if PGlyphWidth<>nil then PGlyphWidth^:=FGlyphWidth;
if PGlyphHeight<>nil then PGlyphHeight^:=FGlyphHeight;
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinButtonStyle) then
begin
BStyle:=TSXSkinButtonStyle(SkinLibrary.Styles[A]);
if PGlyphWidth<>nil then PGlyphWidth^:=BStyle.DropDownGlyphWidth;
if PGlyphHeight<>nil then PGlyphHeight^:=BStyle.DropDownGlyphHeight;
end;
A:=SkinLibrary.Styles.GetIndexByName(FDropDownGlyphStyle);
if A>=0 then
begin
if SkinLibrary.Styles[A] is TSXSkinMultiStateStyle then
begin
MSStyle:=TSXSkinMultiStateStyle(SkinLibrary.Styles[A]);
if not Enabled then
begin
SetGStyle(MSStyle.RStyle);
SetGStyle(MSStyle.NStyle);
end else
if FDown then
begin
SetGStyle(MSStyle.DStyle);
SetGStyle(MSStyle.NStyle);
end else
if FMouseOver then
begin
SetGStyle(MSStyle.HStyle);
SetGStyle(MSStyle.NStyle);
end else SetGStyle(MSStyle.NStyle);
end else
if SkinLibrary.Styles[A] is TSXSkinMultiStateCheckStyle then
begin
MSCStyle:=TSXSkinMultiStateCheckStyle(SkinLibrary.Styles[A]);
if FChecked then
begin
if not Enabled then
begin
SetGStyle(MSCStyle.RCStyle);
SetGStyle(MSCStyle.RUStyle);
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
end else
if FDown then
begin
SetGStyle(MSCStyle.DCStyle);
SetGStyle(MSCStyle.DUStyle);
SetGStyle(MSCStyle.NCStyle);
SetGStyle(MSCStyle.NUStyle);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -