Results 1 to 3 of 3

Thread: Mouse Input

  1. #1

    Default Mouse Input

    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...

  2. #2
    Administrator Seth's Avatar
    Join Date
    Jul 2002
    Location
    Japan
    Posts
    5,343

    Default

    To do something like this, you really need to tap TWO kinds of mouse messages:

    Code:
    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.

    Code:
    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;
            }
    }
    Seth A. Robinson
    Robinson Technologies

  3. #3

    Default

    To make the image follow the mouse, you can add this to the code write by Seth:

    Code:
    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;
    }

Similar Threads

  1. Display targets and input
    By void_kill in forum Official ClanLib SDK Forums
    Replies: 0
    Last Post: 03-23-2007, 11:56 PM

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •