⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sxskinlibrary.pas

📁 skin components for design of your applicastions
💻 PAS
📖 第 1 页 / 共 5 页
字号:
function GetImageStretchFilterByName(const Name:String):TSXImageStretchFilter;

procedure GetColorFromString(const S:String;var A,R,G,B:Byte); overload;
function GetColorFromString(const S:String):TColor32; overload;

procedure GetRectFromString(const S:String;var R:TRect;OnGetVar:TSXOnGetVariable=nil);
procedure GetPolygonFromString(const S:String;P:TPolygon32;OnGetVar:TSXOnGetVariable=nil);

function CreateSkinStyleFromStream(S:TStream;Version:Integer;
          const RootPath,ZipFilePath:String;DestList1,DestList2:TSXSkinStyleList):TSXSkinStyle;
function CreateSkinStyleElementFromStream(S:TStream;Version:Integer;
          const RootPath,ZipFilePath:String):TSXSkinStyleElement;

procedure SaveFontData(S:TStream;const FD:TSXFontData);
procedure LoadFontData(S:TStream;var FD:TSXFontData);
procedure SaveFilterData(S:TStream;const Filter:TSXFilterData);
procedure LoadFilterData(S:TStream;var Filter:TSXFilterData);
procedure SaveTransformEffectData(S:TStream;const Effect:TSXTransformEffectData);
procedure LoadTransformEffectData(S:TStream;var Effect:TSXTransformEffectData);
procedure LoadStringsFromZIPSkinStream(Stream:TStream;SL:TStringList);
procedure LoadStringsFromSkinFile(const FilePath:String;SL:TStringList);

function StoredSkinCount:Integer;
function GetStoredSkinByIndex(Index:Integer):TSXStoredSkin;
function GetStoredSkinByZIPName(const FileName:String):TSXStoredSkin;

function GetNewCElementID:Integer;

var StdVariableComparer:TSXStdVariableComparer;

implementation

uses SXSkinUtils, jpeg, SXPNGUtils, SXSkinControl, Math, SXSkinBitmapManager,
     SXSkinRegionManager, SXSkinForm;

var SXStoredSkins:TList;
     InternalSkin:TSXStoredSkin;
     LastCElementID:Integer=0;

function StoredSkinCount:Integer;
begin
 Result:=SXStoredSkins.Count;
end;

function GetStoredSkinByIndex(Index:Integer):TSXStoredSkin;
begin
 if (Index>=0) and (Index<SXStoredSkins.Count) then
  Result:=SXStoredSkins[Index] else Result:=nil;
end;

function GetStoredSkinByZIPName(const FileName:String):TSXStoredSkin;
var A:Integer;
begin
 for A:=0 to SXStoredSkins.Count-1 do
  if SameText(FileName,TSXStoredSkin(SXStoredSkins[A]).FileName) then
   begin
    Result:=TSXStoredSkin(SXStoredSkins[A]);
    exit;
   end;
 Result:=nil;
end;

procedure CreateResourceSkins;
var RS:TResourceStream;
begin
 InternalSkin:=TSXStoredSkin.Create(nil);
 InternalSkin.FileName:='_internal.zip';
 RS:=TResourceStream.Create(HInstance,'INTERNAL_ZIP',RT_RCDATA);
 try
  InternalSkin.FStream.LoadFromStream(RS);
  InternalSkin.FStream.Seek(0,soFromBeginning);
 finally
  RS.Free;
 end;
 //
 RS:=TResourceStream.Create(HInstance,'GENERAL_ZIP',RT_RCDATA);
 try
  PreloadZipFile(RS,'_general.zip',nil);
 finally
  RS.Free;
 end;
end;

procedure GetRectFromString(const S:String;var R:TRect;OnGetVar:TSXOnGetVariable=nil);
var A,B,C,D:Integer;

 procedure SetWhatGot;
 var S2:String;
      E:Boolean;
 begin
  if B>A then
   begin
    S2:=Copy(S,A,B-A);
    if @OnGetVar=nil then
     D:=StrToIntDef(S2,0) else
      begin
       E:=False;
       D:=round(SXEvalMathString(S2,OnGetVar,E));
       if E then D:=0;
      end;
    case C of
     0: R.Left:=D;
     1: R.Top:=D;
     2: R.Right:=D;
     3: R.Bottom:=D;
    end;
   end;
 end;

begin
 R:=Rect(0,0,0,0);
 A:=1; B:=1; C:=0;
 while (B<=length(S)) and (C<4) do
  begin
   if S[B]=',' then
    begin
     SetWhatGot;
     Inc(C); Inc(B);
     A:=B;
    end else Inc(B);
  end;
 SetWhatGot; 
end;

procedure GetPolygonFromString(const S:String;P:TPolygon32;OnGetVar:TSXOnGetVariable=nil);
var A,B,C:Integer;
  LastX,D:Single;

 procedure SetWhatGot;
 var S2:String;
      E:Boolean;
 begin
  if B>A then
   begin
    S2:=Copy(S,A,B-A);
    if @OnGetVar=nil then
     D:=StrToIntDef(S2,0) else
      begin
       E:=False;
       D:=SXEvalMathString(S2,OnGetVar,E);
       if E then D:=0;
      end;
    if C and 1=0 then LastX:=D else
     P.Add(FixedPoint(LastX,D));
    Inc(C);
   end;
 end;

begin
 A:=1; B:=1; C:=0;
 while B<=length(S) do
  begin
   if S[B]=',' then
    begin
     SetWhatGot;
     Inc(B);
     A:=B;
    end else Inc(B);
  end;
 SetWhatGot;
end;

function HexDigit(C:Char):Byte;
begin
 if C in ['A'..'F'] then
  Result:=10+Ord(C)-Ord('A') else
 if C in ['a'..'f'] then
  Result:=10+Ord(C)-Ord('a') else
 if C in ['0'..'9'] then
  Result:=Ord(C)-Ord('0') else
   Result:=0;
end;

procedure GetColorFromString(const S:String;var A,R,G,B:Byte); 
var AA,BB,C,D:Integer;

 procedure SetWhatGot;
 var S2:String;
 begin
  if BB>AA then
   begin
    S2:=Copy(S,AA,BB-AA);
    D:=StrToIntDef(S2,0);
    case C of
     0: A:=D;
     1: R:=D;
     2: G:=D;
     3: B:=D;
    end;
   end;
 end;

 procedure SetAsWinColor(Color:TColor);
 var CL:TColor32;
 begin
  CL:=Color32(Color);
  R:=RedComponent(CL);
  G:=GreenComponent(CL);
  B:=BlueComponent(CL);
 end;

begin
 A:=255; R:=0; G:=0; B:=0;
 if S='' then exit;
 if S='ScrollBar' then
  begin
   SetAsWinColor(clScrollBar); exit;
  end;
 if S='Background' then
  begin
   SetAsWinColor(clBackground); exit;
  end;
 if S='ActiveCaption' then
  begin
   SetAsWinColor(clActiveCaption); exit;
  end;
 if S='InactiveCaption' then
  begin
   SetAsWinColor(clInactiveCaption); exit;
  end;
 if S='Menu' then
  begin
   SetAsWinColor(clMenu); exit;
  end;
 if S='Window' then
  begin
   SetAsWinColor(clWindow); exit;
  end;
 if S='WindowFrame' then
  begin
   SetAsWinColor(clWindowFrame); exit;
  end;
 if S='MenuText' then
  begin
   SetAsWinColor(clMenuText); exit;
  end;
 if S='WindowText' then
  begin
   SetAsWinColor(clWindowText); exit;
  end;
 if S='CaptionText' then
  begin
   SetAsWinColor(clCaptionText); exit;
  end;
 if S='ActiveBorder' then
  begin
   SetAsWinColor(clActiveBorder); exit;
  end;
 if S='InactiveBorder' then
  begin
   SetAsWinColor(clInactiveBorder); exit;
  end;
 if S='AppWorkSpace' then
  begin
   SetAsWinColor(clAppWorkSpace); exit;
  end;
 if S='Highlight' then
  begin
   SetAsWinColor(clHighlight); exit;
  end;
 if S='HighlightText' then
  begin
   SetAsWinColor(clHighlightText); exit;
  end;
 if S='BtnFace' then
  begin
   SetAsWinColor(clBtnFace); exit;
  end;
 if S='BtnShadow' then
  begin
   SetAsWinColor(clBtnShadow); exit;
  end;
 if S='GrayText' then
  begin
   SetAsWinColor(clGrayText); exit;
  end;
 if S='BtnText' then
  begin
   SetAsWinColor(clBtnText); exit;
  end;
 if S='InactiveCaptionText' then
  begin
   SetAsWinColor(clInactiveCaptionText); exit;
  end;
 if S='BtnHighlight' then
  begin
   SetAsWinColor(clBtnHighlight); exit;
  end;
 if S='3DDkShadow' then
  begin
   SetAsWinColor(cl3DDkShadow); exit;
  end;
 if S='3DLight' then
  begin
   SetAsWinColor(cl3DLight); exit;
  end;
 if S='InfoText' then
  begin
   SetAsWinColor(clInfoText); exit;
  end;
 if S='InfoBk' then
  begin
   SetAsWinColor(clInfoBk); exit;
  end;
 {$IFDEF COMPILER_9_UP}
 if S='HotLight' then
  begin
   SetAsWinColor(clHotLight); exit;
  end;
 {$ENDIF}
 if S='GradientActiveCaption' then
  begin
   SetAsWinColor(clGradientActiveCaption); exit;
  end;
 if S='GradientInactiveCaption' then
  begin
   SetAsWinColor(clGradientInactiveCaption); exit;
  end;
 {$IFDEF COMPILER_9_UP}
 if S='MenuHighlight' then
  begin
   SetAsWinColor(clMenuHighlight); exit;
  end;
 if S='MenuBar' then
  begin
   SetAsWinColor(clMenuBar); exit;
  end;
 {$ENDIF}
 if S[1] in ['#','$'] then
  begin
   if (length(S)<>7) and (length(S)<>9) then exit;
   if length(S)=7 then C:=2 else
    begin
     C:=4;
     A:=(HexDigit(S[2]) shl 4) or HexDigit(S[3]);
    end;
   R:=(HexDigit(S[C  ]) shl 4) or HexDigit(S[C+1]);
   G:=(HexDigit(S[C+2]) shl 4) or HexDigit(S[C+3]);
   B:=(HexDigit(S[C+4]) shl 4) or HexDigit(S[C+5]);
   exit;
  end;
 AA:=1; BB:=1; C:=0;
 while (BB<=length(S)) and (C<4) do
  begin
   if S[BB]=',' then
    begin
     SetWhatGot;
     Inc(C); Inc(BB);
     AA:=BB;
    end else Inc(BB);
  end;
 SetWhatGot;
end;

function GetColorFromString(const S:String):TColor32;
var A,R,G,B:Byte;
begin
 GetColorFromString(S,A,R,G,B);
 Result:=Color32(R,G,B,A);
end;

function GetAlignmentFromString(const S:String):TAlignment;
begin
 if S='Right' then Result:=taRightJustify else
  if S='Center' then Result:=taCenter else
   Result:=taLeftJustify;
end;

procedure ClearFontData(var FD:TSXFontData);
begin
 Finalize(FD);
 FillChar(FD,sizeof(FD),0);
end;

function SameFontData(const FD1,FD2:TSXFontData):Boolean;
begin
 Result:=(FD1.FontName=FD2.FontName) and (FD1.FontSize=FD2.FontSize) and
         (FD1.FontStyle=FD2.FontStyle) and (FD1.FontColor=FD2.FontColor) and
         (FD1.HasShadow=FD2.HasShadow) and (not FD1.HasShadow or
         (FD1.ShadowColor=FD2.ShadowColor)) and (FD1.DoPrepaint=FD2.DoPrepaint) and
         (FD1.SmoothLevel=FD2.SmoothLevel);
end;

procedure AddFontData(var FD:TSXFontData;FDToAdd:TSXFontData);
begin
 if not FD.SetFontName then
  begin
   FD.SetFontName:=FDToAdd.SetFontName;
   FD.FontName:=FDToAdd.FontName;
  end;
 if not FD.SetFontSize then
  begin
   FD.SetFontSize:=FDToAdd.SetFontSize;
   FD.FontSize:=FDToAdd.FontSize;
  end;
 if not FD.SetFontStyle then
  begin
   FD.SetFontStyle:=FDToAdd.SetFontStyle;
   FD.FontStyle:=FDToAdd.FontStyle;
  end;
 if not FD.SetFontColor then
  begin
   FD.SetFontColor:=FDToAdd.SetFontColor;
   FD.FontColor:=FDToAdd.FontColor;
  end;
 if not FD.SetHasShadow then
  begin
   FD.SetHasShadow:=FDToAdd.SetHasShadow;
   FD.HasShadow:=FDToAdd.HasShadow;
  end;
 if not FD.SetShadowColor then
  begin
   FD.SetShadowColor:=FDToAdd.SetShadowColor;
   FD.ShadowColor:=FDToAdd.ShadowColor;
  end;
 if not FD.SetSmoothLevel then
  begin
   FD.SetSmoothLevel:=FDToAdd.SetSmoothLevel;
   FD.SmoothLevel:=FDToAdd.SmoothLevel;
  end;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -