PDA

View Full Version : Mouse Input



Soudeus
03-24-2007, 11:11 AM
Hello. Im trying to implement a simple drag feature where the user clicks the left mouse button, then an image is picked up and follows the mouse, and dropped wherever the user lets off the mouse button. My problem lies with the actual mouse input. If anyone could give me a rough idea how to go about this would be appreciated. Right now I connect a function to the CL_Mouse::sig_key_down() but it seems to get called many times while the user is holding the mouse button or something...

Seth
03-24-2007, 10:52 PM
To do something like this, you really need to tap TWO kinds of mouse messages:


CL_SlotContainer m_slot; //in the .h somewhere

//init the mouse stuff
m_slots.connect(CL_Mouse::sig_key_down(),this, &EntEditor::OnMouseDown);
m_slots.connect(CL_Mouse::sig_key_up(),this, &EntEditor::OnMouseUp);


Then, just keep track of when the button is pushed and released yourself from these messages.


void EntEditor::OnMouseDown(const CL_InputEvent &key)
{
switch(key.id)
{
case CL_MOUSE_RIGHT:
printf ("they just pushed the right mouse button DOWN");
break;
}
}

void EntEditor::OnMouseUp(const CL_InputEvent &key)
{
switch(key.id)
{
case CL_MOUSE_RIGHT:
printf ("they just RELEASED the right mouse button");
break;
}
}

psvieira
04-25-2007, 01:57 PM
To make the image follow the mouse, you can add this to the code write by Seth:



m_slots.connect(CL_Mouse::sig_move(),this, &EntEditor::OnMouseMove);

void EntEditor::OnMouseMove(const CL_InputEvent &key)
{
image.posX = key.mouse_pos.x;
image.posY = key.mouse_pos.y;
}