在首頁區,看到很多實現QQ表情列表管理功能的代碼,但是貌似沒發現Delphi的實現版本,這裡我將我以前寫的IM中的表情管理的一個表情框控件共享出來,提供給對Delphi還有感情的愛好者參考使用。介紹我就不多說了,有興趣的直接下代碼看吧,用法也簡單,直接使用TDxFaceGrid就行。代碼中集合了表情包的實現邏輯(包括表情包的導入和導出等),具體例子我是沒寫,有興趣的可以參考參考!
代碼
unit DxFaceControl;
interface
uses Windows,SysUtils,Messages,Classes,Controls,Graphics,GIFImg,ExtCtrls,NativeXML,frxmd5,AES;
type
//表情節點
TDxFace = class
private
FFaceFileName: string;
FFaceFileMD5: string;
FFaceTags: TStringList;
procedure SetFaceFileName(const Value: string);
procedure SetFaceTags(const Value: TStringList);
public
constructor Create;
destructor Destroy;override;
//表情文件的MD5碼
property FaceFileMD5: string read FFaceFileMD5;
property FaceFileName: string read FFaceFileName write SetFaceFileName;//表情文件的位置
property FaceTags: TStringList read FFaceTags write SetFaceTags;
end;
TDxFaces = class
private
FacesList: TList;
FPackageName: string;
Width: Integer;
Height: Integer;
RowCount: Integer;
ColCount: Integer;
FaceFilePack: string;
procedure InitFaces(FilePackName: string);
procedure clearFace;
function GetFaces(index: integer): TDxFace;
procedure SetFaces(index: integer;Value: TDxFace);
function GetCount: Integer;
public
constructor Create(FilePackName: string);
destructor Destroy;override;
property PackageName: string read FPackageName;
property Faces[index: integer]: TDxFace read GetFaces write SetFaces;
property Count: Integer read GetCount;
procedure AddFaces(FaceFile: string;FaceName: string);//添加表情信息
end;
//表情包列表
TDxFacePackages = class
private
FacePackages: TStringList;//表情包列表
UserId: string;
procedure ClearPackages;
procedure LoadPacks;
function GetCount: Integer;
function GetFaces(index: integer): TDxFaces;
public
constructor Create(ClIEntUserId: string);//根據進入的用戶來獲得表情包
destructor Destroy;override;
procedure DeleteFacePackage(PakName: string);
procedure AddPackage(FacePack: TDxFaces);overload;//添加表情包
function AddPackage(PackFileName: string): TDxFaces;overload;//通過XML文件來創建添加包
property Count: Integer read GetCount;
property Faces[index: integer]: TDxFaces read GetFaces;
end;
TOnGetFaceEvent = procedure(Sender: TObject;Face: TDxFace) of object;
TDxFaceGrid = class(TCustomControl)
private
FFaceWidth: Integer;
FFaceHeight: Integer;
FRowCount: Integer;
FColCount: Integer;
FImages: TList;
Faces: TDxFaces;
CurSelectRect: TRect;
FFrameColor: TColor;
FGridLineColor: TColor;
FSelFrameColor: TColor;
FOnGetFace: TOnGetFaceEvent;
FPageIndex: Integer;
TotalCount: Integer;
FaceSelfCreate: Boolean;
procedure SetFaceWidth(const Value: Integer);
procedure SetFaceHeight(const Value: Integer);
procedure SetRowCount(const Value: Integer);
procedure SetColCount(const Value: Integer);
function GetImage(ACol, ARow: Integer): TImage;
procedure SetFrameColor(const Value: TColor);
procedure SetGridLine(const Value: TColor);
procedure SetSelFrameColor(const Value: TColor);
function GetPageCount: Integer;
procedure SetPageIndex(const Value: Integer);
protected
procedure CreateWnd;override;
procedure CalcWH;
procedure InitImageItems;
procedure Paint;override;
procedure DoImgEnter(Sender: TObject);
procedure DoImgLeave(Sender: TObject);
procedure DoImgClick(Sender: TObject);
public
constructor Create(AOwner: TComponent);overload;override;
constructor Create(AOwner: TComponent;PackFileName: string);reintroduce;overload;
constructor Create(AOwner: TComponent;FacePack: TDxFaces);reintroduce;overload;
destructor Destroy;override;
property FaceWidth: Integer read FFaceWidth write SetFaceWidth default 24;
property FaceHeight: Integer read FFaceHeight write SetFaceHeight default 24;
property RowCount: Integer read FRowCount write SetRowCount default 8;
property ColCount: Integer read FColCount write SetColCount default 15;
property Image[ACol,ARow: Integer]: TImage read GetImage;
property FrameColor: TColor read FFrameColor write SetFrameColor default $AEAEAE;
property GridLine: TColor read FGridLineColor write SetGridLine default $F6E6DF;
property SelFrameColor: TColor read FSelFrameColor write SetSelFrameColor default clBlue;
property OnGetFace: TOnGetFaceEvent read FOnGetFace write FOnGetFace;
property PageCount: Integer read GetPageCount;//頁面數量
property PageIndex: Integer read FPageIndex write SetPageIndex default 0;
end;
implementation
end.
本文示例源代碼或素材下載