i want to have a wxToggleButton with an wxAnimationCtrl in it.
But the Button i currently have only gets the Click events of the Button. When i click onto the Animation into the Button, then the Button change not his State.
I can get the events of the wxAnimationCtrl and handel them but the Button its self does not toggle.
My Qustion is what do i have to do that the Button by Clicks on the wxAnimationCtrl behaves the same as by Clicks on the Button.
wxAnimatedButton.h:
Code: Select all
class wxAnimatedButton : public wxToggleButton
{
public:
wxAnimatedButton( wxWindow *parent,
wxWindowID id,
wxUChar *animationBytes1,
WXUINT animationlen1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
const wxString& name = "animatedButton")
{Create(parent, id, animationBytes1, animationlen1, pos, size, name);};
~wxAnimatedButton();
bool Create(wxWindow *parent,
wxWindowID id,
wxUChar *animationBytes1,
WXUINT animationlen1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
const wxString& name = "animatedButton");
void SetPos(const wxPoint& pos);
void StartAnimation( void );
void StopAnimation( void );
private:
wxAnimation *animation;
wxAnimationCtrl *ctrl;
wxMemoryInputStream *mis;
int mBorderStyle;
protected:
};
/****************************************************/
// Define a custom event handler
class wxAniBtnEvtHandler : public wxEvtHandler
{
public:
wxAniBtnEvtHandler( wxWindowID id, wxAnimatedButton* button ) { mID = id; pButton = button;}
private:
void OnLeftMouseDown(wxMouseEvent &event);
void OnLeftMouseUp(wxMouseEvent &event);
void OnMouseMove(wxMouseEvent &event);
wxWindowID mID;
wxAnimatedButton* pButton;
DECLARE_EVENT_TABLE()
};
Code: Select all
#include "wxAnimatedButton.h"
//-----------------------------------------------------------------------------------
//EVENT TABLE //
//-----------------------------------------------------------------------------------
//Zuordnung was ausgelöst werden soll wenn etwas passiert
BEGIN_EVENT_TABLE (wxAniBtnEvtHandler, wxEvtHandler)
EVT_LEFT_DOWN(wxAniBtnEvtHandler::OnLeftMouseDown)
EVT_LEFT_UP(wxAniBtnEvtHandler::OnLeftMouseUp)
EVT_MOTION(wxAniBtnEvtHandler::OnMouseMove)
END_EVENT_TABLE()
//------------------------------------------------------------------+
wxAnimatedButton :: ~wxAnimatedButton(void)
{
// Controller löschen
wxDELETE( ctrl );
// Animation löschen
wxDELETE( animation );
// Bildinformationspuffer freigeben
wxDELETE( mis );
}
//------------------------------------------------------------------+
bool wxAnimatedButton::Create(wxWindow *parent, wxWindowID id,
wxUChar *animationBytes1, WXUINT animationlen1,
const wxPoint& pos, const wxSize& size, const wxString& name)
{
ctrl = NULL;
mBorderStyle = wxBORDER_RAISED;
mClicked = false;
// Animation erstellen
animation = new wxAnimation( );
// Bildinformationspuffer laden
mis = new wxMemoryInputStream( animationBytes1, animationlen1 * sizeof( wxUChar ) );
wxSize panelSize(0,0);
// Glückte der Ladevorgang
if( animation -> Load( *mis, wxANIMATION_TYPE_GIF ) )
{
// Controller erstellen
ctrl = new wxAnimationCtrl( parent, id, *animation1 );
panelSize = ctrl->GetSize();
wxDELETE( ctrl );
panelSize.x += 10;
panelSize.y += 10;
if(size != wxDefaultSize)
panelSize = size;
}
if(!wxToggleButton::Create (parent, id, "Ani", pos, panelSize, mBorderStyle))
{
return false;
}
// this->PushEventHandler(new wxAniBtnEvtHandler(id, this));
// Glückte der Ladevorgang
if( animation -> IsOk() )
{
// Controller erstellen
ctrl = new wxAnimationCtrl( this, id, *animation, wxPoint(2, 2) );
ctrl->PushEventHandler(new wxAniBtnEvtHandler(id, this));
// Animation anzeigen
ctrl -> Show( true );
}
SetValidator(wxDefaultValidator);
return true;
}
//------------------------------------------------------------------+
//------------------------------------------------------------------+
void wxAnimatedButton::SetPos(const wxPoint& pos)
{
Move(pos);
}
//------------------------------------------------------------------+
//------------------------------------------------------------------+
void wxAnimatedButton :: StartAnimation( void )
{
// wurde die Animation korrekt geladen
if( ctrl != NULL )
{
// Animation anzeigen und starten
ctrl -> Show( true );
ctrl -> Play( );
}
}
//------------------------------------------------------------------+
//------------------------------------------------------------------+
void wxAnimatedButton :: StopAnimation( void )
{
// wurde die Animation korrekt geladen
if( ctrl != NULL )
{
// Animation stoppen
ctrl -> Stop( );
}
}
//-----------------------------------------------------------------------------------
void wxAniBtnEvtHandler::OnLeftMouseDown(wxMouseEvent &event)
{
wxPostEvent( pButton, event );
}
//-----------------------------------------------------------------------------------
void wxAniBtnEvtHandler::OnLeftMouseUp(wxMouseEvent &event)
{
wxPostEvent( pButton, event );
}
//-----------------------------------------------------------------------------------
void wxAniBtnEvtHandler::OnMouseMove(wxMouseEvent &event)
{
wxPostEvent( pButton, event );
// event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
// event.Skip(); //alternate Code i tryed
}