wxWidgets Mouse event problem

Mar 4, 2012 at 2:10pm
hi my name is henry, there's something wrong with this code and I don't know what it is:

void MyFrame::OnMouse(wxMouseEvent& event)
{
	wxPoint Start(event.GetPosition());
	wxClientDC dc(this);
	if(event.LeftUp()==true)
		dc.DrawLine(Start,event.GetPosition());
}


This function executes when an EVT_LEFT_DOWN is generated

It The event table works but the if bit doesn't please help me.
Last edited on Mar 4, 2012 at 5:55pm
Mar 4, 2012 at 11:39pm
EVT_LEFT_DOWN is when the user presses the left click.

event.LeftUp() is checking to see if the user is releasing the left click.

If you want to be notified when the users presses and released, you need to catch EVT_LEFT_DOWN and EVT_LEFT_UP

Also...

1
2
3
4
wxPoint Start(event.GetPosition());  // <- start is the current position
//...
dc.DrawLine(Start,event.GetPosition());  // <- so you're drawing a line FROM the current position
//  TO the current position (ie:  the line goes nowhere) 


To solve this problem you need to do two things:

1) You need to give 'Start' a broader scope. Its value needs to be remembered between function calls. The quick and dirty way to do this is to make it static, but a better way would be to make it a member of MyFrame.

2) You need to only set 'Start' when the user clicks (ie: check event.LeftDown).
Topic archived. No new replies allowed.