📄 sxskinbutton.pas
字号:
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 GStyle:=FDropDownGlyphStyle;
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.ResetButtonParams(Params:TSXSkinButtonResetParams=[]);
var OldGlyphRect:TRect;
OldTextRect:TRect;
OldDDGlyphRect:TRect;
GlyphChanged:Boolean;
TextChanged:Boolean;
DDGlyphChanged:Boolean;
GStyle:String;
A,W,H,X,Y:Integer;
BState:TSXSkinButtonStateParam;
SetBState:Boolean;
BStyle:TSXSkinButtonStyle;
Flags:Cardinal;
CaptionRect:TRect;
procedure DoSetBState;
begin
if not SetBState then
GetCurrentBState(BState);
end;
begin
if Parent=nil then exit;
OldGlyphRect:=FGlyphRect;
OldTextRect:=FTextRect;
OldDDGlyphRect:=FDropDownGlyphRect;
GlyphChanged:=False;
TextChanged:=False;
DDGlyphChanged:=False;
SetBState:=False;
if Params*[brpGlyph,brpGlyphOnStyleChange,brpGlyphOnSizeChange]<>[] then
begin
DoSetBState;
GetCurrentGlyphStyle(GStyle,@W,@H);
if brpGlyph in Params then GlyphChanged:=True else
begin
if brpGlyphOnSizeChange in Params then
GlyphChanged:=(W<>FGlyphRect.Right-FGlyphRect.Left) or
(H<>FGlyphRect.Bottom-FGlyphRect.Top);
if not GlyphChanged and (brpGlyphOnStyleChange in Params) then
GlyphChanged:=(FLastGlyphStyle<>GStyle) or not SameFilterData(FLastGlyphFilterData,BState.DefGlyphFilter);
end;
if GlyphChanged then FGlyphRect:=Rect(0,0,W,H);
FLastGlyphStyle:=GStyle;
FLastGlyphFilterData:=BState.DefGlyphFilter;
end;
if Params*[brpDDGlyph,brpDDGlyphOnStyleChange]<>[] then
begin
GetCurrentDropDownGlyphStyle(GStyle,@W,@H);
if brpDDGlyph in Params then DDGlyphChanged:=True else
begin
if brpDDGlyphOnStyleChange in Params then
DDGlyphChanged:=FLastDropDownGlyphStyle<>GStyle;
end;
if DDGlyphChanged then FDropDownGlyphRect:=Rect(0,0,W,H);
FLastDropDownGlyphStyle:=GStyle;
end;
if Params*[brpText,brpTextOnFontChange,brpTextIfWordWrap]<>[] then
begin
DoSetBState;
if brpText in Params then TextChanged:=True else
if FWordWrap and (brpTextIfWordWrap in Params) then TextChanged:=True else
if brpTextOnFontChange in Params then
TextChanged:=not SameFontData(BState.FD,FLastFontData);
if TextChanged then
begin
if FTextBitmap<>nil then
begin
FTextBitmap.Free;
FTextBitmap:=nil;
end;
FLastFontData:=BState.FD;
Canvas.Font.Name:=BState.FD.FontName;
Canvas.Font.Size:=BState.FD.FontSize;
Canvas.Font.Style:=BState.FD.FontStyle;
FTextRect:=ClientRect;
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]);
case FGlyphPosition of
gpLeftTop,
gpLeft,
gpLeftBottom,
gpRightTop,
gpRight,
gpRightBottom: begin
Dec(FTextRect.Right,FGlyphRect.Right-FGlyphRect.Left);
if (FLastGlyphStyle<>'') and (Caption<>'') then
Dec(FTextRect.Right,FTextOffset);
Dec(FTextRect.Right,FCaptionLeftOffset);
Dec(FTextRect.Right,FCaptionRightOffset);
Dec(FTextRect.Right,BState.CaptionLeftOffset);
Dec(FTextRect.Right,BState.CaptionRightOffset);
if FDropDown then
begin
Dec(FTextRect.Right,BStyle.DropDownGlyphOffset);
Dec(FTextRect.Right,FDropDownGlyphRect.Right-FDropDownGlyphRect.Left);
end;
//
Dec(FTextRect.Bottom,FCaptionTopOffset);
Dec(FTextRect.Bottom,FCaptionBottomOffset);
Dec(FTextRect.Bottom,BState.CaptionTopOffset);
Dec(FTextRect.Bottom,BState.CaptionBottomOffset);
end;
gpTop,
gpBottom: begin
Dec(FTextRect.Right,FCaptionLeftOffset);
Dec(FTextRect.Right,FCaptionRightOffset);
Dec(FTextRect.Right,BState.CaptionLeftOffset);
Dec(FTextRect.Right,BState.CaptionRightOffset);
if FDropDown then
begin
Dec(FTextRect.Right,BStyle.DropDownGlyphOffset);
Dec(FTextRect.Right,FDropDownGlyphRect.Right-FDropDownGlyphRect.Left);
end;
//
Dec(FTextRect.Right,FGlyphRect.Bottom-FGlyphRect.Top);
if (FLastGlyphStyle<>'') and (Caption<>'') then
Dec(FTextRect.Right,FTextOffset);
Dec(FTextRect.Bottom,FCaptionTopOffset);
Dec(FTextRect.Bottom,FCaptionBottomOffset);
Dec(FTextRect.Bottom,BState.CaptionTopOffset);
Dec(FTextRect.Bottom,BState.CaptionBottomOffset);
end;
end;
Flags:=DT_NOPREFIX or DT_NOCLIP or DT_TOP or DT_CALCRECT;
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;
if BState.FD.SmoothLevel=0 then
DrawText(Canvas.Handle,PChar(Caption),-1,FTextRect,Flags) else
DrawSmoothText(Canvas,Caption,FTextRect,Flags,BState.FD.SmoothLevel);
end;
end;
end;
FLastFontData:=BState.FD;
end;
//
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinButtonStyle) then
begin
DoSetBState;
BStyle:=TSXSkinButtonStyle(SkinLibrary.Styles[A]);
CaptionRect:=Rect(0,0,0,0);
//Setting CaptionRect.Right and CaptionRect.Bottom
case FGlyphPosition of
gpLeftTop,
gpLeft,
gpLeftBottom,
gpRightTop,
gpRight,
gpRightBottom: begin
Inc(CaptionRect.Right,FGlyphRect.Right-FGlyphRect.Left);
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(CaptionRect.Right,FTextOffset);
Inc(CaptionRect.Right,FTextRect.Right-FTextRect.Left);
if FDropDown then
begin
Inc(CaptionRect.Right,BStyle.DropDownGlyphOffset);
Inc(CaptionRect.Right,FDropDownGlyphRect.Right-FDropDownGlyphRect.Left);
end;
//
CaptionRect.Bottom:=Max(FGlyphRect.Bottom-FGlyphRect.Top,
FTextRect.Bottom-FTextRect.Top);
if FDropDown then
CaptionRect.Bottom:=Max(CaptionRect.Bottom,
FDropDownGlyphRect.Bottom-FDropDownGlyphRect.Top);
end;
gpTop,
gpBottom: begin
CaptionRect.Right:=Max(FGlyphRect.Right-FGlyphRect.Left,
FTextRect.Right-FTextRect.Left);
if FDropDown then
begin
Inc(CaptionRect.Right,BStyle.DropDownGlyphOffset);
Inc(CaptionRect.Right,FDropDownGlyphRect.Right-FDropDownGlyphRect.Left);
end;
//
Inc(CaptionRect.Bottom,FGlyphRect.Bottom-FGlyphRect.Top);
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(CaptionRect.Bottom,FTextOffset);
Inc(CaptionRect.Bottom,FTextRect.Bottom-FTextRect.Top);
if FDropDown then
CaptionRect.Bottom:=Max(CaptionRect.Bottom,
FDropDownGlyphRect.Bottom-FDropDownGlyphRect.Top);
end;
end;
//Offset CaptionRect to Button Center with Offsets
W:=(Width+FCaptionLeftOffset-FCaptionRightOffset+BState.CaptionLeftOffset-
BState.CaptionRightOffset-CaptionRect.Right) div 2;
H:=(Height+FCaptionTopOffset-FCaptionBottomOffset+BState.CaptionTopOffset-
BState.CaptionBottomOffset-CaptionRect.Bottom) div 2;
OffsetRect(CaptionRect,W,H);
//Setting FGlyphRect, FTextRect and FDropDownGlyphRect
OffsetRect(FGlyphRect,-FGlyphRect.Left,-FGlyphRect.Top);
OffsetRect(FTextRect,-FTextRect.Left,-FTextRect.Top);
OffsetRect(FDropDownGlyphRect,-FDropDownGlyphRect.Left,-FDropDownGlyphRect.Top);
case FGlyphPosition of
gpLeftTop: begin
OffsetRect(FGlyphRect,CaptionRect.Left,CaptionRect.Top);
//
X:=FGlyphRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,X,Y);
end;
gpTop: begin
X:=(CaptionRect.Left+CaptionRect.Right-FGlyphRect.Right) div 2;
OffsetRect(FGlyphRect,X,CaptionRect.Top);
//
X:=(CaptionRect.Left+CaptionRect.Right-FTextRect.Right) div 2;
Y:=FGlyphRect.Bottom;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(Y,FTextOffset);
OffsetRect(FTextRect,X,Y);
end;
gpRightTop: begin
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,CaptionRect.Left,Y);
//
X:=FTextRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
OffsetRect(FGlyphRect,X,CaptionRect.Top);
end;
gpRight: begin
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,CaptionRect.Left,Y);
//
X:=FTextRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
Y:=(CaptionRect.Top+CaptionRect.Bottom-FGlyphRect.Bottom) div 2;
OffsetRect(FGlyphRect,X,Y);
end;
gpRightBottom: begin
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,CaptionRect.Left,Y);
//
X:=FTextRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
Y:=CaptionRect.Bottom-FGlyphRect.Bottom;
OffsetRect(FGlyphRect,X,Y);
end;
gpBottom: begin
X:=(CaptionRect.Left+CaptionRect.Right-FTextRect.Right) div 2;
OffsetRect(FTextRect,X,CaptionRect.Top);
//
X:=(CaptionRect.Left+CaptionRect.Right-FGlyphRect.Right) div 2;
Y:=FTextRect.Bottom;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(Y,FTextOffset);
OffsetRect(FGlyphRect,X,Y);
end;
gpLeftBottom: begin
Y:=CaptionRect.Bottom-FGlyphRect.Bottom;
OffsetRect(FGlyphRect,CaptionRect.Left,Y);
//
X:=FGlyphRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,X,Y);
end;
gpLeft: begin
Y:=(CaptionRect.Top+CaptionRect.Bottom-FGlyphRect.Bottom) div 2;
OffsetRect(FGlyphRect,CaptionRect.Left,Y);
//
X:=FGlyphRect.Right;
if (FLastGlyphStyle<>'') and (Caption<>'') then
Inc(X,FTextOffset);
Y:=(CaptionRect.Top+CaptionRect.Bottom-FTextRect.Bottom) div 2;
OffsetRect(FTextRect,X,Y);
end;
end;
if FDropDown then
begin
X:=CaptionRect.Right-FDropDownGlyphRect.Right;
Y:=(CaptionRect.Top+CaptionRect.Bottom-FDropDownGlyphRect.Bottom) div 2;
OffsetRect(FDropDownGlyphRect,X,Y);
end;
end;
end;
//Invalidating Regions
if GlyphChanged or not EqualRect(OldGlyphRect,FGlyphRect) then
begin
if HandleAllocated then
begin
InvalidateRect(Handle,@OldGlyphRect,False);
InvalidateRect(Handle,@FGlyphRect,False);
end;
end;
if TextChanged or not EqualRect(OldTextRect,FTextRect) then
begin
if HandleAllocated then
begin
InvalidateRect(Handle,@OldTextRect,False);
InvalidateRect(Handle,@FTextRect,False);
end;
end;
if FDropDown and (DDGlyphChanged or not EqualRect(OldDDGlyphRect,FDropDownGlyphRect)) then
begin
if HandleAllocated then
begin
InvalidateRect(Handle,@OldDDGlyphRect,False);
InvalidateRect(Handle,@FDropDownGlyphRect,False);
end;
end;
//
if brpInvalidateOnStyleChange in Params then
begin
DoSetBState;
if (BState.Style<>FLastStyle) or (BState.OverStyle<>FLastOverStyle) then
begin
if HandleAllocate
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -