First commit 25/07/1999
This commit is contained in:
150
ActImg/Copia de actimg.cpp
Normal file
150
ActImg/Copia de actimg.cpp
Normal file
@ -0,0 +1,150 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#include <vcl\vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "actimg.h"
|
||||
|
||||
#pragma package(smart_init)
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
// ValidCtrCheck is used to assure that the components created do not have
|
||||
// any pure virtual functions.
|
||||
//
|
||||
static inline TActiveImage *ValidCtrCheck()
|
||||
{
|
||||
return new TActiveImage(NULL);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TActiveImage::TActiveImage(TComponent* Owner)
|
||||
// : TGraphicControl(Owner)
|
||||
: TButton(Owner)
|
||||
{
|
||||
mcaptured = false;
|
||||
FGlyph = new Graphics::TCanvas;
|
||||
FGlyph->Brush->Color = clNone;
|
||||
FGlyph->Brush->Style = bsClear;
|
||||
FGlyph->CopyMode = cmSrcCopy;
|
||||
|
||||
GlyphNormal = new Graphics::TPicture;
|
||||
GlyphOver = new Graphics::TPicture;
|
||||
GlyphPress = new Graphics::TPicture;
|
||||
|
||||
vAutoSize = false;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Actimg
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TActiveImage)};
|
||||
RegisterComponents("JD Soft.", classes, 0);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::CreateParams(TCreateParams &Params)
|
||||
{
|
||||
TButton::CreateParams(Params); // La clase ascendente se ocupar<61> de establecer los par<61>metros generales
|
||||
// Params.ExStyle = Params.ExStyle | WS_EX_TRANSPARENT;
|
||||
Params.Style = Params.Style | BS_OWNERDRAW;
|
||||
TButton::ControlStyle = TControlStyle();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::CNMeasureItem(TWMMeasureItem& Mensaje)
|
||||
{
|
||||
Mensaje.MeasureItemStruct->itemWidth = Width;
|
||||
Mensaje.MeasureItemStruct->itemHeight = Height;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Cada vez que haya que dibujar el control se llamar<61> a este m<>todo
|
||||
void __fastcall TActiveImage::CNDrawItem(TWMDrawItem& Mensaje)
|
||||
{
|
||||
Graphics::TBitmap *Bitmap;
|
||||
|
||||
Bitmap = GlyphNormal->Bitmap;
|
||||
|
||||
if (Mensaje.DrawItemStruct->itemState & ODS_SELECTED) // El bot<6F>n est<73> pulsado
|
||||
Bitmap = GlyphPress->Bitmap;
|
||||
else
|
||||
// Si el bot<6F>n est<73> desactivado
|
||||
if (! Enabled )
|
||||
Bitmap = GlyphPress->Bitmap;
|
||||
else
|
||||
if ( mcaptured )
|
||||
Bitmap = GlyphOver->Bitmap;
|
||||
|
||||
FGlyph->Handle = Mensaje.DrawItemStruct->hDC;
|
||||
|
||||
FGlyph->BrushCopy( ClientRect, Bitmap, Rect( 0, 0, Bitmap->Width-1, Bitmap->Height-1 ), Bitmap->TransparentColor );
|
||||
|
||||
// El Handle de FCanvas ser<65> el Hdc enviado en Mensaje.DrawItemStruct,
|
||||
// lo que nos permitir<69> dibujar en la superficie del bot<6F>n
|
||||
FGlyph->Handle = 0;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
// Al cambiar el estado del bot<6F>n
|
||||
void __fastcall TActiveImage::SetButtonStyle(bool ADefault)
|
||||
{
|
||||
Refresh(); // simplemente redibujar
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TActiveImage::~TActiveImage()
|
||||
{
|
||||
delete FGlyph;
|
||||
delete GlyphNormal;
|
||||
delete GlyphOver;
|
||||
delete GlyphPress;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::MouseMove( Classes::TShiftState Shift, int X, int Y )
|
||||
{
|
||||
if( ! mcaptured )
|
||||
{
|
||||
SetCapture( Handle );
|
||||
mcaptured = true;
|
||||
Refresh();
|
||||
}
|
||||
if( (X<0) || (Y<0) || (X>Width) || (Y>Height))
|
||||
{
|
||||
ReleaseCapture();
|
||||
mcaptured = false;
|
||||
Refresh();
|
||||
}else{
|
||||
TButton::MouseMove( Shift, X, Y );
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::Click( void )
|
||||
{
|
||||
TButton::Click();
|
||||
ReleaseCapture();
|
||||
mcaptured = false;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphOver( Graphics::TPicture *val )
|
||||
{
|
||||
GlyphOver -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphPress( Graphics::TPicture *val )
|
||||
{
|
||||
GlyphPress -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphNormal( Graphics::TPicture *val )
|
||||
{
|
||||
GlyphNormal -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetAutoSize( bool val )
|
||||
{
|
||||
vAutoSize = val;
|
||||
// Facilitamos la anchura y altura del control
|
||||
if ( vAutoSize && ! GlyphNormal->Graphic->Empty )
|
||||
{
|
||||
Width = GlyphNormal->Width;
|
||||
Height = GlyphNormal->Height;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
Reference in New Issue
Block a user