📄 sxskinlibrary.pas
字号:
unit SXSkinLibrary;
////////////////////////////////////////////////////////////////////////////////
// SXSkinComponents: Skinnable Visual Controls for Delphi and C++Builder //
//----------------------------------------------------------------------------//
// Version: 1.2.1 //
// Author: Alexey Sadovnikov //
// Web Site: http://www.saarixx.info/sxskincomponents/ //
// E-Mail: sxskincomponents@saarixx.info //
//----------------------------------------------------------------------------//
// LICENSE: //
// 1. You may freely distribute this file. //
// 2. You may not make any changes to this file. //
// 3. The only person who may change this file is Alexey Sadovnikov. //
// 4. You may use this file in your freeware projects. //
// 5. If you want to use this file in your shareware or commercial project, //
// you should purchase a project license or a personal license of //
// SXSkinComponents: http://saarixx.info/sxskincomponents/en/purchase.htm //
// 6. You may freely use, distribute and modify skins for SXSkinComponents. //
// 7. You may create skins for SXSkinComponents. //
//----------------------------------------------------------------------------//
// Copyright (C) 2006-2007, Alexey Sadovnikov. All Rights Reserved. //
////////////////////////////////////////////////////////////////////////////////
interface
{$I Compilers.inc}
{$R WinXP.RES}
{$R InternalZip.RES}
uses Windows, Classes, Forms, SysUtils, IniFiles, GR32, Controls, GR32_Blend,
SXMathEval, GR32_Polygons, Dialogs, Graphics, Types, SXBitmap32Utils,
StdCtrls, GR32_Resamplers, SXZipUtils;
const SXSkinComponents_Version:Integer=10200;
SXSkinComponents_VersionStr:String='1.2.0';
SXS_Header='SXSkinComponents Binary Skin';
SXSuppVersion:array[0..1]of Integer=(10100, 10200);
VARSTD_W = 1;
VARSTD_H = 2;
type
{$IFNDEF COMPILER_9_UP}
TVerticalAlignment=(taAlignTop,
taAlignBottom,
taVerticalCenter);
{$ENDIF}
TSXGlyphPosition=(gpLeftTop, gpTop,
gpRightTop, gpRight,
gpRightBottom, gpBottom,
gpLeftBottom, gpLeft);
TSXGlyphChangeAction=(gcaHighlightIn,
gcaHighlightOut,
gcaDown,
gcaUp,
gcaCheck,
gcaUncheck,
gcaEnable,
gcaDisable,
gcaFocus,
gcaUnfocus);
TSXTransformEffectType=(tetBlend,
tetNone,
tetClear,
tetFade,
tetOverDraw,
tetSlide);
TSXTransformEffectDirection=(tedLeft,
tedRight,
tedTop,
tedBottom,
tedLeftRight,
tedTopBottom,
tedLeftTop,
tedLeftBottom,
tedRightTop,
tedRightBottom);
TSXTransformEffectData=record
SetOldType:Boolean;
SetOldDirection:Boolean;
SetOldDirOut:Boolean;
SetOldInverted:Boolean;
SetOldOnTop:Boolean;
SetNewType:Boolean;
SetNewDirection:Boolean;
SetNewDirOut:Boolean;
SetNewInverted:Boolean;
SetStepsNum:Boolean;
SetOffset:Boolean;
SetDrawCaption:Boolean;
//
OldType:TSXTransformEffectType;
OldDirection:TSXTransformEffectDirection;
OldDirOut:Boolean;
OldInverted:Boolean;
OldOnTop:Boolean;
NewType:TSXTransformEffectType;
NewDirection:TSXTransformEffectDirection;
NewDirOut:Boolean;
NewInverted:Boolean;
StepsNum:Integer;
Offset:Integer;
DrawCaption:Boolean;
end;
TSXSkinStyleElementType=(ssetUnknown,
ssetImage,
ssetBoxTile,
ssetFigure,
ssetText,
ssetStyle);
TSXVariableComparer=class;
ISXVariableComparerNotify=interface
procedure VCNotification(VComparer:TSXVariableComparer);
end;
TSXVariableComparer=class
protected
CurValList:TList;
function VarListOnGetVariable(const VarName:String;var Error:Boolean):Single; virtual; abstract;
public
OnGetVariable:TSXOnGetVariable;
function GetVarListForRect(const S:String):TList; virtual;
function GetVarListForPoly(const S:String):TList; virtual;
function GetVarValsForVarList(VarList:TList):TList; virtual; abstract;
function Changed(VarList:TList;OldVarVals:TList):Boolean; virtual; abstract;
procedure Update(VarList:TList;VarVals:TList); virtual; abstract;
procedure DestroyVarList(VarList:TList); virtual; abstract;
procedure DestroyVarVals(VarList:TList;VarVals:TList); virtual; abstract;
end;
TSXStdVariableComparer=class(TSXVariableComparer)
private
Width:Integer;
Height:Integer;
function GetValue(VarID:Integer):Integer;
function IntOnGetVariable(const VarName:String;var Error:Boolean):Single;
protected
function VarListOnGetVariable(const VarName:String;var Error:Boolean):Single; override;
public
procedure SetSize(AWidth,AHeight:Integer);
procedure GetSize(var AWidth,AHeight:Integer);
function GetVarValsForVarList(VarList:TList):TList; override;
function Changed(VarList:TList;OldVarVals:TList):Boolean; override;
procedure Update(VarList:TList;VarVals:TList); override;
procedure DestroyVarList(VarList:TList); override;
procedure DestroyVarVals(VarList:TList;VarVals:TList); override;
constructor Create;
end;
TSXSkinStyleElement=class
private
FControl:TControl;
FCElementID:Integer;
public
Name:String;
procedure Assign(Element:TSXSkinStyleElement); virtual;
function GetCopy:TSXSkinStyleElement; virtual;
procedure SetProperty(const Name,Value,SkinFilePath:String); virtual;
procedure SaveToStream(S:TStream;const RootPath:String); virtual;
procedure LoadFromStream(S:TStream;Version:Integer;
const RootPath,ZipFilePath:String); virtual;
end;
TSXSkinStyleElementList=class
protected
FItem:TList;
function Get(Index:Integer):TSXSkinStyleElement;
procedure Put(Index:Integer;Item:TSXSkinStyleElement);
function GetCount:Integer;
public
procedure Assign(ElementList:TSXSkinStyleElementList);
function GetIndexByName(const Name:String):Integer;
procedure Add(SXSkinStyleElement:TSXSkinStyleElement);
procedure Delete(Index:Integer);
procedure SaveToStream(S:TStream;const RootPath:String);
procedure LoadFromStream(S:TStream;Version:Integer;const RootPath,ZipFilePath:String;
DoClear:Boolean=True);
procedure Clear;
constructor Create;
destructor Destroy; override;
property Item[Index:Integer]:TSXSkinStyleElement read Get write Put; default;
property Count:Integer read GetCount;
end;
TSXSkinStyleImageType=(ssitAutoDetect,
ssitJPEG,
ssitPNG);
TSXSkinLibrary=class;
TSXImageFilterType=(iftNone,
iftLighten,
iftLightenHorizG,
iftLightenVertG,
iftDarken,
iftDarkenHorizG,
iftDarkenVertG,
iftAlpha,
iftMonochrome,
iftColorOverlay,
iftColorOverlayHorizG,
iftColorOverlayVertG);
TSXFilterData=record
SetAType:Boolean;
SetValue:Boolean;
SetColor:Boolean;
SetColor2:Boolean;
//
AType:TSXImageFilterType;
Value:Integer;
Color:TColor32;
Color2:TColor32;
end;
TSXImageResizeMode=(irmNone,
irmTile,
irmStretch);
TSXImageStretchFilter=(isfNearest,
isfLinear,
isfSpline,
isfLanczos,
isfMitchell);
TSXSkinStyleImageElement=class(TSXSkinStyleElement)
public
ImageType:TSXSkinStyleImageType;
LoadedPath:String; //Is used for loading and saving only
Path:String;
ZipFilePath:String;
Transparent:Boolean;
Bitmap:TBitmap32;
Filter:TSXFilterData;
ResizeMode:TSXImageResizeMode;
StretchFilter:TSXImageStretchFilter;
OffsetX:Integer;
OffsetY:Integer;
ResizedWidth:Integer;
ResizedHeight:Integer;
Centered:Boolean;
DrawRect:String;
procedure Assign(Element:TSXSkinStyleElement); override;
function GetCopy:TSXSkinStyleElement; override;
procedure SetProperty(const Name,Value,SkinFilePath:String); override;
procedure ValidateBitmap(SkinLibrary:TSXSkinLibrary);
procedure SaveToStream(S:TStream;const RootPath:String); override;
procedure LoadFromStream(S:TStream;Version:Integer;
const RootPath,ZipFilePath:String); override;
constructor Create;
destructor Destroy; override;
end;
TSXSkinStyleStyleElement=class(TSXSkinStyleElement)
public
Style:String;
Filter:TSXFilterData;
DrawRect:String;
procedure Assign(Element:TSXSkinStyleElement); override;
function GetCopy:TSXSkinStyleElement; override;
procedure SetProperty(const Name,Value,SkinFilePath:String); override;
procedure SaveToStream(S:TStream;const RootPath:String); override;
procedure LoadFromStream(S:TStream;Version:Integer;
const RootPath,ZipFilePath:String); override;
end;
TSXSkinStyleBoxTileElement=class(TSXSkinStyleElement)
public
ZipFilePath:String;
CenterPath:String;
LeftPath:String;
TopPath:String;
RightPath:String;
BottomPath:String;
TopLeftPath:String;
TopRightPath:String;
BottomRightPath:String;
BottomLeftPath:String;
//
CenterColor:TColor32;
LeftColor:TColor32;
TopColor:TColor32;
RightColor:TColor32;
BottomColor:TColor32;
TopLeftColor:TColor32;
TopRightColor:TColor32;
BottomRightColor:TColor32;
BottomLeftColor:TColor32;
//
SetCenterColor:Boolean;
SetLeftColor:Boolean;
SetTopColor:Boolean;
SetRightColor:Boolean;
SetBottomColor:Boolean;
SetTopLeftColor:Boolean;
SetTopRightColor:Boolean;
SetBottomRightColor:Boolean;
SetBottomLeftColor:Boolean;
SetResizeMode:Boolean;
//
SetCenter:Boolean;
SetLeft:Boolean;
SetTop:Boolean;
SetRight:Boolean;
SetBottom:Boolean;
SetTopLeft:Boolean;
SetTopRight:Boolean;
SetBottomRight:Boolean;
SetBottomLeft:Boolean;
//
CenterBitmap:TBitmap32;
LeftBitmap:TBitmap32;
TopBitmap:TBitmap32;
RightBitmap:TBitmap32;
BottomBitmap:TBitmap32;
TopLeftBitmap:TBitmap32;
TopRightBitmap:TBitmap32;
BottomRightBitmap:TBitmap32;
BottomLeftBitmap:TBitmap32;
Transparent:Boolean;
Filter:TSXFilterData;
ResizeMode:TSXImageResizeMode;
//
LoadedPathTemplate:String; //Is used for loading and saving only
PathTemplate:String;
DrawRect:String;
procedure Assign(Element:TSXSkinStyleElement); override;
function GetCopy:TSXSkinStyleElement; override;
function GetPixelAt(PX,PY,Width,Height:Integer;AOnGetVariable:TSXOnGetVariable=nil):TColor32;
procedure DrawToBitmap(B:TBitmap32;X,Y,Width,Height:Integer;DrawRgn:HRGN;
AOnGetVariable:TSXOnGetVariable=nil);
procedure SetProperty(const Name,Value,SkinFilePath:String); override;
procedure ValidateBitmaps(SkinLibrary:TSXSkinLibrary);
procedure SaveToStream(S:TStream;const RootPath:String); override;
procedure LoadFromStream(S:TStream;Version:Integer;
const RootPath,ZipFilePath:String); override;
constructor Create;
destructor Destroy; override;
end;
TSXSkinStyleFigureType=(ssftRectangle,
ssftEllipse,
ssftRoundRectangle,
ssftLine,
ssftSolidFill,
ssftFocusRectangle,
ssftPolygon,
ssftEraseRect);
TSXFigureControlPreparedData=class
private
Control:TControl;
CElementID:Integer;
RectValueVarList:TList;
RectValueVarVals:TList;
PolyValueVarList:TList;
PolyValueVarVals:TList;
VComparer:TSXVariableComparer;
Rect:TRect;
Polygon1:TPolygon32;
Polygon1Offset:TPoint;
Polygon2:TPolygon32;
Polygon2Offset:TPoint;
public
destructor Destroy; override;
end;
TSXFigureControlPreparedDataList=class
protected
FItem:TList;
function Get(Index:Integer):TSXFigureControlPreparedData;
procedure Put(Index:Integer;Item:TSXFigureControlPreparedData);
function GetCount:Integer;
public
function GetIndexToInsert(CElementID:Integer):Integer;
function GetIndexByControl(CElementID:Integer):Integer;
procedure Add(SXFigureControlPreparedData:TSXFigureControlPreparedData);
procedure Delete(Index:Integer);
procedure Clear;
constructor Create;
destructor Destroy; override;
property Item[Index:Integer]:TSXFigureControlPreparedData read Get write Put; default;
property Count:Integer read GetCount;
end;
TSXSkinStyleFigureElement=class(TSXSkinStyleElement)
public
HasBorder:Boolean;
HasFill:Boolean;
Antialiased:Boolean;
FigureType:TSXSkinStyleFigureType;
BorderColor:TColor32;
FillColor:TColor32;
FillColor2:TColor32;
GradientFill:Boolean;
VertGradientFill:Boolean;
Roundness:Integer;
RectValue:String;
PolyValue:String;
CornersStyle:TSXCorners;
BorderThickness:Single;
ControlsData:TSXFigureControlPreparedDataList;
procedure Assign(Element:TSXSkinStyleElement); override;
function GetCopy:TSXSkinStyleElement; override;
procedure DrawToBitmap(B:TBitmap32;X,Y:Integer);
function OnGetVariable(const VarName:String;var Error:Boolean):Single;
procedure EvalPrePaintParams(Control:TControl;CElementID:Integer;
VComparer:TSXVariableComparer=nil;Changed:Boolean=False);
procedure SetProperty(const Name,Value,SkinFilePath:String); override;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -