//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "actimg.h"
//---------------------------------------------------------------------------
static inline TActiveImage *ValidCtrCheck()
{
	return new TActiveImage(NULL);
}
//---------------------------------------------------------------------------
__fastcall TActiveImage::TActiveImage(TComponent* Owner)
	: TImage(Owner)
{
	captured = false;
	GlyphNormal = new Graphics::TPicture;
	GlyphOver   = new Graphics::TPicture;
    GlyphPress  = new Graphics::TPicture;
}
//---------------------------------------------------------------------------
__fastcall TActiveImage::~TActiveImage()
{
	delete GlyphNormal;
	delete GlyphOver;
	delete GlyphPress;
}
//---------------------------------------------------------------------------
void __fastcall TActiveImage::MouseMove( Classes::TShiftState Shift, int X, int Y )
{
	if( !captured )
    {
		SetCapture( Parent );
		captured = true;
		GlyphNormal = Picture; // save old glyph
		Picture = GlyphOver; // show new glyph
	}
	if( (X<0) || (Y<0) || (X>Width) || (Y>Height))
    {
		ReleaseCapture();
		captured = false;
		Picture = GlyphNormal; // restore old glyph
	}else{
		TImage::MouseMove( Shift, X, Y );
	}
}
//---------------------------------------------------------------------------
void __fastcall TActiveImage::Click( void )
{
	TImage::Click();
	ReleaseCapture();
	captured = false;
	Picture = GlyphNormal;
}
//---------------------------------------------------------------------------
namespace Actimg
{
	void __fastcall Register()
	{
		TComponentClass classes[1] = {__classid(TActiveImage)};
		RegisterComponents("JD Soft.", classes, 0);
	}
}
//---------------------------------------------------------------------------
