Skip to content

Instantly share code, notes, and snippets.

@lighth7015
Last active March 30, 2020 19:47
Show Gist options
  • Save lighth7015/51987fc010b5efb03ee4f79a62e080fc to your computer and use it in GitHub Desktop.
Save lighth7015/51987fc010b5efb03ee4f79a62e080fc to your computer and use it in GitHub Desktop.
Dialog designer?
class DesignerForm: public wxPanel {
DECLARE_DYNAMIC_CLASS( DesignerForm )
DECLARE_EVENT_TABLE()
auto Designable(wxControl* instance) {
auto handler = [this, instance]( wxMouseEvent& cursor ) {
wxControl& control(*instance);
wxPrintf ( "Mouse event. ID = %d\n", control.GetId());
};
instance->Bind(wxEVT_LEFT_DOWN, handler);
instance->Bind(wxEVT_LEFT_UP, handler);
/**
* For some reason, the supplied control
* can't tell if it is being dragged.
*/
instance->Bind(wxEVT_MOTION, handler);
return instance;
}
void OnMouseEvent( wxMouseEvent& cursor ) {
if (cursor.Dragging()) {
puts( "Dragging event." );
}
}
protected:
static wxColor background;
wxControl *active;
public:
bool Create( wxWindow* parent ) {
bool success = false;
if (( success = wxPanel::Create( parent, wxID_ANY, wxPoint( 10, 10 ), wxSize( 100, 100 )))) {
SetBackgroundColour(background);
Designable(new wxButton( this, wxID_ANY ));
}
return success;
}
};
IMPLEMENT_CLASS( DesignerForm, wxPanel )
/*
* Designer event table definition
*/
BEGIN_EVENT_TABLE( DesignerForm, wxPanel )
EVT_MOUSE_EVENTS( DesignerForm::OnMouseEvent )
END_EVENT_TABLE()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment