📄 sxskinform.pas
字号:
FTextBitmap.CombineMode:=cmMerge;
W:=TextRect.Right-TextRect.Left;
H:=TextRect.Bottom-TextRect.Top;
if FState.TextFont.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;
OffsetRect(TextRect,-Rect.Left,-Rect.Top);
if FState.TextFont.DoPrepaint and (FState.TextFont.SmoothLevel>0) then
FTextBitmap.DrawTo(Bitmap,TextRect.Left,TextRect.Top) else
DrawTextToBitmap(Bitmap);
end;
end;
end;
procedure TSXSkinCustomForm.DrawCaptionAndBorder(Rgn:HRGN);
var DC:HDC;
A:Integer;
Style:TSXSkinFormStyle;
FState:TSXSkinFormStateParam;
Rgn2:HRGN;
CB:TBitmap32;
procedure DrawStyleToRect(CElementID:Integer;const StyleName:String;X,Y,Width,Height:Integer);
var A:Integer;
B:TBitmap32;
GStyle:TSXSkinGeneralStyle;
ARect:TRect;
Rgn:HRGN;
begin
if (Width<=0) or (Height<=0) then exit;
if StyleName<>'' then
begin
B:=TBitmap32.Create;
try
B.SetSize(Width,Height);
B.Draw(Rect(0,0,Width,Height),Rect(X,Y,X+Width,Y+Height),DC);
A:=SkinLibrary.Styles.GetGStyleIndex(StyleName,Width,Height);
if A>=0 then
begin
GStyle:=TSXSkinGeneralStyle(SkinLibrary.Styles[A]);
ARect:=Rect(0,0,Width,Height);
Rgn:=CreateRectRgnIndirect(ARect);
GStyle.DrawToBitmap(FForm,CElementID,B,0,0,Width,Height,ARect,Rgn,
SkinLibrary);
DeleteObject(Rgn);
end;
B.DrawTo(DC,X,Y);
finally
B.Free;
end;
end;
end;
begin
if (SkinLibrary<>nil) and SkinLibrary.CanBeUsed and (FForm<>nil) then
begin
A:=SkinLibrary.Styles.GetIndexByName(SkinStyle);
if (A>=0) and (SkinLibrary.Styles[A] is TSXSkinFormStyle) then
begin
Style:=TSXSkinFormStyle(SkinLibrary.Styles[A]);
if (FCaptionHeight=0) and (Style.LeftFrameWidth=0) and
(Style.RightFrameWidth=0) and (Style.BottomFrameHeight=0) then exit;
GetCurrentFState(FState);
// Rgn2:=CreateRectRgn(0,0,0,0);
// CombineRgn(Rgn2,Rgn,0,RGN_COPY);
// OffsetRgn(Rgn2,-FForm.Left,-FForm.Top);
//DC:=GetDCEx(FForm.Handle,Rgn,DCX_CACHE or DCX_WINDOW or DCX_INTERSECTRGN);
DC:=GetWindowDC(FForm.Handle);
//SelectClipRgn(DC,Rgn2);
try
CB:=TBitmap32.Create;
try
CB.SetSize(FForm.Width,FCaptionHeight);
DrawCaptionToRect(CB,Rect(0,0,FForm.Width,FCaptionHeight));
CB.DrawTo(DC,0,0);
finally
CB.Free;
end;
//if RectInRegion(Rgn2,Rect(0,0,FForm.Width,FCaptionHeight)) then
// DrawStyleToRect(FState.CaptionStyle,0,0,FForm.Width,FCaptionHeight);
//if RectInRegion(Rgn2,Rect(0,FCaptionHeight,Style.LeftFrameWidth,FForm.Height-Style.BottomFrameHeight)) then
DrawStyleToRect(CEID_LeftFrame,FState.LeftFrameStyle,0,FCaptionHeight,
Style.LeftFrameWidth,FForm.Height-Style.BottomFrameHeight-FCaptionHeight);
//if RectInRegion(Rgn2,Rect(FForm.Width-Style.RightFrameWidth,FCaptionHeight,FForm.Width,FForm.Height-Style.BottomFrameHeight)) then
DrawStyleToRect(CEID_RightFrame,FState.RightFrameStyle,FForm.Width-Style.RightFrameWidth,
FCaptionHeight,Style.RightFrameWidth,FForm.Height-Style.BottomFrameHeight-FCaptionHeight);
//if RectInRegion(Rgn2,Rect(0,FForm.Height-Style.BottomFrameHeight,FForm.Width,FForm.Height)) then
DrawStyleToRect(CEID_BottomFrame,FState.BottomFrameStyle,0,FForm.Height-Style.BottomFrameHeight,
FForm.Width,Style.BottomFrameHeight);
finally
//SelectClipRgn(DC,0);
ReleaseDC(FForm.Handle,DC);
// DeleteObject(Rgn2);
end;
end;
end;
end;
function TSXSkinCustomForm.OnGetVariable(const VarName:String;var Error:Boolean):Single;
begin
Result:=0;
if VarName='W' then
begin
Result:=TmpWidth;
exit;
end;
if VarName='H' then
begin
Result:=TmpHeight;
exit;
end;
if VarName='DefCH' then
begin
Result:=GetSystemMetrics(SM_CYCAPTION)+GetSystemMetrics(SM_CYFRAME);
exit;
end;
if VarName='CH' then
begin
Result:=FCaptionHeight;
exit;
end;
if VarName='IL' then
begin
Result:=FIconRect.Left;
exit;
end;
if VarName='IT' then
begin
Result:=FIconRect.Top;
exit;
end;
if VarName='IR' then
begin
Result:=FIconRect.Right;
exit;
end;
if VarName='IB' then
begin
Result:=FIconRect.Bottom;
exit;
end;
Error:=True;
end;
procedure TSXSkinCustomForm.CalcCaptionElementsRects;
var FState:TSXSkinFormStateParam;
R:TRect;
Need:Boolean;
procedure ModifyTextRect;
const Margin=3;
begin
if R.Left<=FTextRect.Left then
FTextRect.Left:=R.Right+Margin else
if R.Right>=FTextRect.Right then
FTextRect.Right:=R.Left-Margin else
if R.Left-FTextRect.Left>FTextRect.Right-R.Right then
FTextRect.Right:=R.Left-Margin else
FTextRect.Left:=R.Right+Margin;
end;
begin
if (FForm=nil) or (csDesigning in ComponentState) then exit;
GetCurrentFState(FState,nil,nil);
//
Need:=(FForm.BorderStyle in [bsSizeable,bsSingle]) and (biSystemMenu in FForm.BorderIcons);
if Need and (FState.IconRect<>'') then
GetRectFromString(FState.IconRect,FIconRect,OnGetVariable) else
FIconRect:=Rect(0,0,0,0);
//
if FState.TextRect<>'' then
GetRectFromString(FState.TextRect,FTextRect,OnGetVariable) else
FTextRect:=Rect(0,0,0,0);
//
Need:=(FForm.BorderStyle in [bsSizeable,bsSingle,bsDialog,bsToolWindow,bsSizeToolWin]) and
(biSystemMenu in FForm.BorderIcons);
if Need and (FState.CloseRect<>'') then
GetRectFromString(FState.CloseRect,FCloseRect,OnGetVariable) else
FCloseRect:=Rect(0,0,0,0);
//
Need:=(FForm.BorderStyle in [bsSizeable,bsSingle]) and (biSystemMenu in FForm.BorderIcons) and
((biMinimize in FForm.BorderIcons) or (biMaximize in FForm.BorderIcons));
if Need and (FState.MaximizeRect<>'') then
GetRectFromString(FState.MaximizeRect,FMaximizeRect,OnGetVariable) else
FMaximizeRect:=Rect(0,0,0,0);
//
Need:=(FForm.BorderStyle in [bsSizeable,bsSingle]) and (biSystemMenu in FForm.BorderIcons) and
((biMinimize in FForm.BorderIcons) or (biMaximize in FForm.BorderIcons));
if Need and (FState.MinimizeRect<>'') then
GetRectFromString(FState.MinimizeRect,FMinimizeRect,OnGetVariable) else
FMinimizeRect:=Rect(0,0,0,0);
//
Need:=(FForm.BorderStyle in [bsSizeable,bsSingle,bsDialog]) and
(biSystemMenu in FForm.BorderIcons) and not (biMinimize in FForm.BorderIcons) and
not (biMaximize in FForm.BorderIcons) and (biHelp in FForm.BorderIcons);
if Need and (FState.HelpRect<>'') then
GetRectFromString(FState.HelpRect,FHelpRect,OnGetVariable) else
FHelpRect:=Rect(0,0,0,0);
//
if not IsRectEmpty(FTextRect) then
begin
if IntersectRect(R,FTextRect,FCloseRect) then
ModifyTextRect;
if IntersectRect(R,FTextRect,FMaximizeRect) then
ModifyTextRect;
if IntersectRect(R,FTextRect,FMinimizeRect) then
ModifyTextRect;
if IntersectRect(R,FTextRect,FHelpRect) then
ModifyTextRect;
if IntersectRect(R,FTextRect,FIconRect) then
ModifyTextRect;
end;
end;
procedure TSXSkinCustomForm.ResetMaskRegion;
var FState:TSXSkinFormStateParam;
R1:HRGN;
BH,RW,CH,CW:Integer;
SkinFilePath:String;
ZipFilePath:String;
procedure AddRegion(const MaskRegion:String;X,Y,Width,Height:Integer;Resized:Boolean);
var R2:HRGN;
begin
if MaskRegion<>'' then
begin
TmpWidth:=Width;
TmpHeight:=Height;
R2:=EvaluateRegion(MaskRegion,SkinFilePath,ZipFilePath,Width,Height,
SkinLibrary,Resized,OnGetVariable);
if (X<>0) or (Y<>0) then
OffsetRgn(R2,X,Y);
end else
begin
R2:=CreateRectRgn(X,Y,X+Width,Y+Height);
end;
CombineRgn(R1,R1,R2,RGN_OR);
DeleteObject(R2);
end;
begin
if (FForm=nil) or (csDesigning in ComponentState) then exit;
GetCurrentFState(FState,@SkinFilePath,@ZipFilePath);
if FState.FullMask<>'' then
begin
TmpWidth:=FForm.Width;
TmpHeight:=FForm.Height;
R1:=EvaluateRegion(FState.FullMask,SkinFilePath,ZipFilePath,FForm.Width,FForm.Height,
SkinLibrary,False,OnGetVariable);
SetWindowRgn(FForm.Handle,R1,True);
DeleteObject(R1);
exit;
end;
if ((FState.MaskLeftWidth<>0) or (FState.MaskRightWidth<>0)) and
((FState.MaskTopHeight<>0) or (FState.MaskBottomHeight<>0)) then
begin
R1:=CreateRectRgn(FState.MaskLeftWidth,FState.MaskTopHeight,
FForm.Width-FState.MaskRightWidth,
FForm.Height-FState.MaskBottomHeight);
//
BH:=FForm.Height-FState.MaskTopHeight;
if FState.MaskBottomHeight<BH then
BH:=FState.MaskBottomHeight;
RW:=FForm.Width-FState.MaskLeftWidth;
if FState.MaskRightWidth<RW then
RW:=FState.MaskRightWidth;
CH:=FForm.Height-FState.MaskTopHeight-FState.MaskBottomHeight;
if CH<0 then CH:=0;
CW:=FForm.Width-FState.MaskLeftWidth-FState.MaskRightWidth;
if CW<0 then CW:=0;
//
if FState.MaskTopHeight>0 then
begin
if FState.MaskLeftWidth>0 then
AddRegion(FState.MaskTopLeft,0,0,FState.MaskLeftWidth,FState.MaskTopHeight,True);
if CW>0 then
AddRegion(FState.MaskTop,FState.MaskLeftWidth,0,CW,FState.MaskTopHeight,False);
if RW>0 then
AddRegion(FState.MaskTopRight,FForm.Width-RW,0,RW,FState.MaskTopHeight,True);
end;
if CH>0 then
begin
if FState.MaskLeftWidth>0 then
AddRegion(FState.MaskLeft,0,FState.MaskTopHeight,FState.MaskLeftWidth,CH,False);
if RW>0 then
AddRegion(FState.MaskRight,FForm.Width-RW,FState.MaskTopHeight,RW,CH,False);
end;
if BH>0 then
begin
if FState.MaskLeftWidth>0 then
AddRegion(FState.MaskBottomLeft,0,FForm.Height-BH,FState.MaskLeftWidth,BH,True);
if CW>0 then
AddRegion(FState.MaskBottom,FState.MaskLeftWidth,FForm.Height-BH,CW,BH,False);
if RW>0 then
AddRegion(FState.MaskBottomRight,FForm.Width-RW,FForm.Height-BH,RW,BH,True);
end;
SetWindowRgn(FForm.Handle,R1,True);
DeleteObject(R1);
end else
begin
SetWindowRgn(FForm.Handle,0,True);
end;
end;
procedure TSXSkinCustomForm.CalcResizeRegions;
var FState:TSXSkinFormStateParam;
SkinFilePath:String;
ZipFilePath:String;
begin
if ResizeTopLeftRgn<>0 then
DeleteObject(ResizeTopLeftRgn);
if ResizeTopRightRgn<>0 then
DeleteObject(ResizeTopRightRgn);
if ResizeBottomLeftRgn<>0 then
DeleteObject(ResizeBottomLeftRgn);
if ResizeBottomRightRgn<>0 then
DeleteObject(ResizeBottomRightRgn);
if ResizeLeftRgn<>0 then
DeleteObject(ResizeLeftRgn);
if ResizeRightRgn<>0 then
DeleteObject(ResizeRightRgn);
if ResizeTopRgn<>0 then
DeleteObject(ResizeTopRgn);
if ResizeBottomRgn<>0 then
DeleteObject(ResizeBottomRgn);
if CaptionRgn<>0 then
DeleteObject(CaptionRgn);
//
if FForm=nil then exit;
TmpWidth:=FForm.Width;
TmpHeight:=FForm.Height;
GetCurrentFState(FState,@SkinFilePath,@ZipFilePath);
if FState.ResizeTopLeft<>'' then
ResizeTopLeftRgn:=EvaluateRegion(FState.ResizeTopLeft,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeTopRight<>'' then
ResizeTopRightRgn:=EvaluateRegion(FState.ResizeTopRight,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeBottomLeft<>'' then
ResizeBottomLeftRgn:=EvaluateRegion(FState.ResizeBottomLeft,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeBottomRight<>'' then
ResizeBottomRightRgn:=EvaluateRegion(FState.ResizeBottomRight,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeTop<>'' then
ResizeTopRgn:=EvaluateRegion(FState.ResizeTop,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeBottom<>'' then
ResizeBottomRgn:=EvaluateRegion(FState.ResizeBottom,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
if FState.ResizeLeft<>'' then
ResizeLeftRgn:=EvaluateRegion(FState.ResizeLeft,SkinFilePath,ZipFilePath,
FForm.Width,FForm.Height,SkinLibrary,False,OnGetVariable);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -