Reputation: 706
Hi guys I am here to beat dead horse..
Basically what I am doing is assigning stuff onto a map.
The map: A wxStaticBitmap object with the background uploaded by user The bomb(lol): A wxStaticBitmap object
I managed to merge bomb into arbitrary position on map now with wxMemoryDC + wxDC.
However,I am totally stuck with setting "bomb" with mouse.I want to click somewhere on the map and somehow the bomb will be dropped at the very position I just clicked.
I took a stab with wxMouseEvent and EVT_MOTION(well,like macro ones declared on top) Obviously they only work with wxWindow or wxFrame.
I was wondering how I am gonna bind mouse event to staticbitmap probably by Connect() but I did not find a proper usage regarding to bomb assignment...
Upvotes: 1
Views: 1079
Reputation: 1
You can do it like this to connect mouse-move, mouse left key down and mouse left key up:
thiri = new wxStaticBitmap(this, wxID_ANY, wxImage(966, 680), /*image start point*/wxPoint(0,0), /* canvas size to display*/ wxSize(966, 680));
// mouse event on image
thiri->Connect( wxEVT_LEFT_DOWN, wxMouseEventHandler(Panel::OnMouseLeftDown), NULL, this );
thiri->Connect( wxEVT_MOTION, wxMouseEventHandler(Panel::OnMouseMove), NULL, this );
thiri->Connect( wxEVT_LEFT_UP, wxMouseEventHandler(Panel::OnMouseLeftUp), NULL, this);
Upvotes: 0
Reputation: 113
The best and simplest solution I've found is to Connect own event handler to wxStaticBitmap like this:
sb->Connect(wxID_ANY,wxEVT_MOTION,
wxMouseEventHandler(MyFrame::OnMouse),NULL,this);
Upvotes: 1
Reputation: 20457
In general, it is best to create a single wxPanel as the child of the frame, then create all your widgets as children of the wxPanel. This way most everything works as you naturally expect and you hit fewer gotchas.
Upvotes: 0