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;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
|
58
ActImg/Copia de actimg.h
Normal file
58
ActImg/Copia de actimg.h
Normal file
@ -0,0 +1,58 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#ifndef ActImgH
|
||||
#define ActImgH
|
||||
//---------------------------------------------------------------------------
|
||||
#include <vcl\SysUtils.hpp>
|
||||
#include <vcl\Controls.hpp>
|
||||
#include <vcl\Classes.hpp>
|
||||
#include <vcl\Forms.hpp>
|
||||
#include <vcl\ExtCtrls.hpp>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PACKAGE TActiveImage : // public TGraphicControl
|
||||
public TButton
|
||||
{
|
||||
private:
|
||||
bool mcaptured;
|
||||
void __fastcall MouseMove( Classes::TShiftState Shift, int X, int Y);
|
||||
|
||||
TCanvas * FGlyph; // Para dibujar
|
||||
// Mensaje de Windows solicitando el tama<6D>o del control
|
||||
void __fastcall CNMeasureItem(TWMMeasureItem& Mensaje);
|
||||
// Mensaje de Windows solicitando que el control sea dibujado
|
||||
void __fastcall CNDrawItem(TWMDrawItem& Mensaje);
|
||||
BEGIN_MESSAGE_MAP
|
||||
MESSAGE_HANDLER(CN_MEASUREITEM, TWMMeasureItem, CNMeasureItem);
|
||||
MESSAGE_HANDLER(CN_DRAWITEM, TWMDrawItem, CNDrawItem);
|
||||
END_MESSAGE_MAP(TButton);
|
||||
|
||||
protected:
|
||||
// Par<61>metros para la creaci<63>n del control
|
||||
void __fastcall CreateParams(TCreateParams &Params);
|
||||
// Cambio del estado del bot<6F>n
|
||||
void __fastcall SetButtonStyle(bool ADefault);
|
||||
|
||||
void __fastcall SetGlyphOver( Graphics::TPicture *val );
|
||||
void __fastcall SetGlyphPress( Graphics::TPicture *val );
|
||||
void __fastcall SetGlyphNormal( Graphics::TPicture *val );
|
||||
|
||||
bool vAutoSize;
|
||||
void __fastcall SetAutoSize( bool val );
|
||||
|
||||
void __fastcall Click( void );
|
||||
|
||||
|
||||
public:
|
||||
Graphics::TPicture *GlyphOver,*GlyphNormal, *GlyphPress;
|
||||
|
||||
__fastcall TActiveImage(TComponent* Owner);
|
||||
__fastcall ~TActiveImage();
|
||||
|
||||
__published:
|
||||
__property Graphics::TPicture *Picture_Normal={read=GlyphNormal, write=SetGlyphNormal};
|
||||
__property Graphics::TPicture *Picture_Over={read=GlyphOver, write=SetGlyphOver};
|
||||
__property Graphics::TPicture *Picture_Press={read=GlyphPress, write=SetGlyphPress};
|
||||
__property bool AutoSize={read=vAutoSize, write=SetAutoSize, default=false };
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
168
ActImg/actimg.cpp
Normal file
168
ActImg/actimg.cpp
Normal file
@ -0,0 +1,168 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#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);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
#define FGlyph Canvas
|
||||
__fastcall TActiveImage::TActiveImage(TComponent* Owner)
|
||||
: TCustomControl(Owner)
|
||||
{
|
||||
CState = CSt_NORMAL;
|
||||
|
||||
Width = 50;
|
||||
Height = 50;
|
||||
|
||||
FGlyph->Brush->Color = clNone;
|
||||
FGlyph->Brush->Style = bsClear;
|
||||
FGlyph->CopyMode = cmSrcCopy;
|
||||
|
||||
RCanvas = Canvas;
|
||||
|
||||
GlyphNormal = new Graphics::TBitmap;
|
||||
GlyphOver = new Graphics::TBitmap;
|
||||
GlyphPress = new Graphics::TBitmap;
|
||||
|
||||
vAutoSize = false;
|
||||
|
||||
MouseCaptured = false;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
namespace Actimg
|
||||
{
|
||||
void __fastcall PACKAGE Register()
|
||||
{
|
||||
TComponentClass classes[1] = {__classid(TActiveImage)};
|
||||
RegisterComponents("JD Soft.", classes, 0);
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::Paint()
|
||||
{
|
||||
Graphics::TBitmap *Bitmap;
|
||||
|
||||
Brush->Color = clNone;
|
||||
Brush->Style = bsClear;
|
||||
|
||||
switch ( CState )
|
||||
{
|
||||
case CSt_PRESS:
|
||||
Bitmap = GlyphPress;
|
||||
break;
|
||||
case CSt_OVER:
|
||||
Bitmap = GlyphOver;
|
||||
break;
|
||||
case CSt_NORMAL:
|
||||
default:
|
||||
Bitmap = GlyphNormal;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( ! Bitmap -> Empty )
|
||||
FGlyph->BrushCopy( ClientRect, Bitmap, Rect( 0, 0, Bitmap->Width-1, Bitmap->Height-1 ), Bitmap->TransparentColor );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TActiveImage::~TActiveImage()
|
||||
{
|
||||
delete GlyphNormal;
|
||||
delete GlyphOver;
|
||||
delete GlyphPress;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::MouseMove( Classes::TShiftState Shift, int X, int Y )
|
||||
{
|
||||
/*
|
||||
if( CState != CSt_OVER && CState != CSt_PRESS )
|
||||
{
|
||||
if ( !MouseCaptured && SetCapture( Handle ) != NULL ) MouseCaptured = true;
|
||||
CState = CSt_OVER;
|
||||
Refresh();
|
||||
}
|
||||
if( (X<0) || (Y<0) || (X>Width) || (Y>Height))
|
||||
{
|
||||
if ( ReleaseCapture() != 0 ) MouseCaptured = false;
|
||||
CState = CSt_NORMAL;
|
||||
Refresh();
|
||||
}else{
|
||||
TCustomControl::MouseMove( Shift, X, Y );
|
||||
}
|
||||
*/
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::MouseDown( TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
|
||||
{
|
||||
CState = CSt_PRESS;
|
||||
Refresh();
|
||||
// if ( ReleaseCapture() != 0 ) MouseCaptured = false;
|
||||
TCustomControl::MouseDown( Button, Shift, X, Y );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::MouseUp( TMouseButton Button, Classes::TShiftState Shift, int X, int Y)
|
||||
{
|
||||
CState = CSt_NORMAL;
|
||||
// if ( ReleaseCapture() != 0 ) { MouseCaptured = false; Refresh(); }
|
||||
TCustomControl::MouseUp( Button, Shift, X, Y );
|
||||
MouseMove( Shift, X, Y );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphOver( Graphics::TBitmap *val )
|
||||
{
|
||||
GlyphOver -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphPress( Graphics::TBitmap *val )
|
||||
{
|
||||
GlyphPress -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetGlyphNormal( Graphics::TBitmap *val )
|
||||
{
|
||||
GlyphNormal -> Assign( val );
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::SetAutoSize( bool val )
|
||||
{
|
||||
vAutoSize = val;
|
||||
// Facilitamos la anchura y altura del control
|
||||
if ( vAutoSize && ! GlyphNormal->Empty )
|
||||
{
|
||||
Width = GlyphNormal->Width;
|
||||
Height = GlyphNormal->Height;
|
||||
}
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TActiveImage::CreateParams(TCreateParams &Params)
|
||||
{
|
||||
TCustomControl::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::CMMouseEnter ( TMessage& Msg )
|
||||
{
|
||||
CState = CSt_OVER;
|
||||
Refresh();
|
||||
inherited::Dispatch ( &Msg );
|
||||
}
|
||||
|
||||
void __fastcall TActiveImage::CMMouseLeave ( TMessage& Msg )
|
||||
{
|
||||
CState = CSt_NORMAL;
|
||||
Refresh();
|
||||
inherited::Dispatch ( &Msg );
|
||||
}
|
||||
|
||||
|
BIN
ActImg/actimg.dcr
Normal file
BIN
ActImg/actimg.dcr
Normal file
Binary file not shown.
72
ActImg/actimg.h
Normal file
72
ActImg/actimg.h
Normal file
@ -0,0 +1,72 @@
|
||||
//---------------------------------------------------------------------------
|
||||
#ifndef ActImgH
|
||||
#define ActImgH
|
||||
//---------------------------------------------------------------------------
|
||||
#include <vcl\SysUtils.hpp>
|
||||
#include <vcl\Controls.hpp>
|
||||
#include <vcl\Classes.hpp>
|
||||
#include <vcl\Forms.hpp>
|
||||
#include <vcl\ExtCtrls.hpp>
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
class PACKAGE TActiveImage : public TCustomControl
|
||||
{
|
||||
private:
|
||||
// bool mcaptured;
|
||||
enum CStates { CSt_NORMAL, CSt_PRESS, CSt_OVER } CState;
|
||||
void __fastcall MouseMove( Classes::TShiftState Shift, int X, int Y);
|
||||
void __fastcall MouseDown( TMouseButton Button, Classes::TShiftState Shift, int X, int Y);
|
||||
void __fastcall MouseUp( TMouseButton Button, Classes::TShiftState Shift, int X, int Y);
|
||||
|
||||
protected:
|
||||
bool MouseCaptured;
|
||||
|
||||
void __fastcall Paint();
|
||||
|
||||
void __fastcall CreateParams(TCreateParams &Params);
|
||||
|
||||
void __fastcall SetGlyphOver( Graphics::TBitmap *val );
|
||||
void __fastcall SetGlyphPress( Graphics::TBitmap *val );
|
||||
void __fastcall SetGlyphNormal( Graphics::TBitmap *val );
|
||||
|
||||
bool vAutoSize;
|
||||
void __fastcall SetAutoSize( bool val );
|
||||
|
||||
MESSAGE void __fastcall CMMouseEnter ( TMessage& Msg );
|
||||
MESSAGE void __fastcall CMMouseLeave ( TMessage& Msg );
|
||||
|
||||
public:
|
||||
Graphics::TBitmap *GlyphOver,*GlyphNormal, *GlyphPress;
|
||||
Graphics::TCanvas *RCanvas;
|
||||
|
||||
__fastcall TActiveImage(TComponent* Owner);
|
||||
__fastcall ~TActiveImage();
|
||||
|
||||
__published:
|
||||
__property Graphics::TBitmap *Glyph_Normal={read=GlyphNormal, write=SetGlyphNormal};
|
||||
__property Graphics::TBitmap *Glyph_Over={read=GlyphOver, write=SetGlyphOver};
|
||||
__property Graphics::TBitmap *Glyph_Press={read=GlyphPress, write=SetGlyphPress};
|
||||
__property bool AutoSize={read=vAutoSize, write=SetAutoSize, default=false };
|
||||
/*
|
||||
__property TMouseEvent OnMouseDown = {read=FOnMouseDown, write=FOnMouseDown};
|
||||
__property TMouseMoveEvent OnMouseMove = {read=FOnMouseMove, write=FOnMouseMove};
|
||||
__property TMouseEvent OnMouseUp = {read=FOnMouseUp, write=FOnMouseUp};
|
||||
|
||||
__property Classes::TNotifyEvent OnClick = {read=FOnClick, write=FOnClick};
|
||||
__property Classes::TNotifyEvent OnDblClick = {read=FOnDblClick, write=FOnDblClick};
|
||||
*/
|
||||
__property OnMouseDown;
|
||||
__property OnMouseMove;
|
||||
__property OnMouseUp;
|
||||
|
||||
__property OnClick;
|
||||
__property OnDblClick;
|
||||
|
||||
BEGIN_MESSAGE_MAP
|
||||
VCL_MESSAGE_HANDLER ( CM_MOUSEENTER, TMessage, CMMouseEnter )
|
||||
VCL_MESSAGE_HANDLER ( CM_MOUSELEAVE, TMessage, CMMouseLeave )
|
||||
END_MESSAGE_MAP(inherited);
|
||||
|
||||
};
|
||||
//---------------------------------------------------------------------------
|
||||
#endif
|
BIN
ActImg/actimg.obj
Normal file
BIN
ActImg/actimg.obj
Normal file
Binary file not shown.
Reference in New Issue
Block a user