www.pudn.com > DirectShowPlayer.rar > Skinned.pas
// Skinned
// Copyright © 2001 Pulsar Studio / Lord Trancos.
unit Skinned;
// --------------------------------------------------------------------
interface
uses Windows, Classes, Messages, Forms, Graphics, ExtCtrls;
var
Skin : TBitmap = NIL;
const
SKIN_CHKVAL_FALSE = 0;
SKIN_CHKVAL_TRUE = 1;
// Main functions.
function skinInit: boolean;
function skinLoad(_filename: string): boolean;
procedure skinClose;
// TImage functions.
procedure skinImgSetCell(var _img: TImage; _cell: byte);
function skinImgGetCell(_img: TImage): byte;
procedure skinImgSetValue(var _img: TImage; _value: byte);
function skinImgGetValue(_img: TImage): byte;
function skinInitImg(var _img: TImage; _srcPoint: TPoint): boolean;
function skinImgInside(_img: TImage; _x, _y: Integer): boolean;
procedure skinImgUpdate(_img: TImage);
function skinImgChecked(_img: TImage): boolean;
// --------------------------------------------------------------------
implementation
// --------------------------------------------------------------------
function skinInit: boolean;
begin
try
Skin := TBitmap.Create;
Result := true;
except
Result := false;
end;
end;
// --------------------------------------------------------------------
procedure skinClose;
begin
if Assigned(Skin) then
begin
Skin.Free;
Skin := NIL
end;
end;
// --------------------------------------------------------------------
function skinLoad(_filename: string): boolean;
begin
Result := false;
if Assigned(Skin) then
try
Skin.LoadFromFile(_filename);
Result := true;
except
end;
end;
// --------------------------------------------------------------------
procedure skinImgSetCell(var _img: TImage; _cell: byte);
begin
_img.Tag := (_img.Tag and $FFFFFFF0) + (_cell and $F);
end;
// -------------------------------------------------------------------
function skinImgGetCell(_img: TImage): byte;
begin
Result := (_img.Tag and $F);
end;
// -------------------------------------------------------------------
procedure skinImgSetValue(var _img: TImage; _value: byte);
begin
_img.Tag := (_img.Tag and $FFFFFF0F) + ((_value and $F) shl 4);
end;
// -------------------------------------------------------------------
function skinImgGetValue(_img: TImage): byte;
begin
Result := ((_img.Tag shr 4) and $F);
end;
// -------------------------------------------------------------------
procedure skinImgSetSrcPoint(var _img: TImage; _p: TPoint);
var _l : longint;
begin
_l := ((_p.x and $FFF) shl 20) + ((_p.y and $FFF) shl 8);
_img.Tag := (_img.Tag and $FF) + _l;
end;
// -------------------------------------------------------------------
function skinImgGetSrcPoint(_img: TImage): TPoint;
begin
Result.x := (_img.Tag shr 20) and $FFF;
Result.y := (_img.Tag shr 8) and $FFF;
end;
// --------------------------------------------------------------------
function skinInitImg(var _img: TImage; _srcPoint: TPoint): boolean;
begin
try
_img.Picture.Bitmap.Width := _img.Width;
_img.Picture.Bitmap.Height := _img.Height;
skinImgSetSrcPoint(_img, _srcPoint);
Result := true;
except
Result := false;
end;
end;
// --------------------------------------------------------------------
function skinImgInside(_img: TImage; _x, _y: Integer): boolean;
begin
Result := (_x > -1) and (_y > -1) and
(_x < _img.Width) and (_y < _img.Height);
end;
// --------------------------------------------------------------------
procedure skinImgUpdate(_img: TImage);
var _src : TRect;
_dst : TRect;
_srcPoint : TPoint;
begin
// Get source point.
_srcPoint := skinImgGetSrcPoint(_img);
// Get Source rect. (skin.bmp).
_src.Left := (_srcPoint.x);
_src.Top := (_srcPoint.y) + (_img.Height * skinImgGetCell(_img));
_src.Right := (_src.Left + _img.Width);
_src.Bottom := (_src.Top + _img.Height);
// Dest. rect.
_dst := Rect(0, 0, _img.Width, _img.Height);
// Draw
_img.Picture.Bitmap.Canvas.CopyRect(_dst, Skin.Canvas, _src);
end;
// --------------------------------------------------------------------
function skinImgChecked(_img: TImage): boolean;
var _val : byte;
begin
_val := skinImgGetValue(_img);
Result := (_val = SKIN_CHKVAL_TRUE);
end;
// --------------------------------------------------------------------
end.