Thread: Mouse activity

  1. #1
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    Mouse activity

    SDL_events.h has this struct for mouse actions >

    Code:
    typedef struct SDL_MouseButtonEvent {
    	Uint8 type;	/* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
    	Uint8 which;	/* The mouse device index */
    	Uint8 button;	/* The mouse button index */
    	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
    	Uint16 x, y;	/* The X/Y coordinates of the mouse at press time */
    } SDL_MouseButtonEvent;
    I am trying to use the members x and y so i can return my pointing device co-ordinates,

    By using another struct in the header i have got event polling working for simple button down/up events, eg 'click on the window to close' actions, but these events test conditions rather than store new values in a variable for me to pass on, and this is where i am stuck, i have tried >

    Code:
      
    int done = 0;
    int startx = 0;
    
    while(done == 0)
      {
        SDL_Event testEvent;
        SDL_MouseButtonEvent newXY; 
        
        while ( SDL_PollEvent(&testEvent) )
        {
          if ( testEvent.type == SDL_QUIT )  {  done = 1;  }
    
          if ( testEvent.type == SDL_KEYDOWN )
          {
            if ( testEvent.key.keysym.sym == SDLK_ESCAPE ) { done = 1; }
          }
          if ( testEvent.type == SDL_MOUSEBUTTONDOWN )
          {
              startx = newXY.x;  
              
          }
        }
    
       // Continue working here...
      }
    a watch on startx shows a random value 20013, so this is wrong so far. Wrong i think because the member 'x' value is unassigned to start with so i need to get the mouse co-ordinates from somewhere else because this struct is not like a function that returns the value of 'x'... so how is it used in any useful way?
    Last edited by rogster001; 09-03-2009 at 02:32 AM.

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472
    I am trying again with SDL_GetMouseState();

  3. #3
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,472

    got it started

    Code:
    int mx = 0;
    int my = 0;
    
    if ( testEvent.type == SDL_MOUSEBUTTONDOWN )
          {
             mx = testEvent.button.x;
             my = testEvent.button.y;  
             done = 1;
          }
    this returns the co-ords nicely for me, however what i would like to do really is click on my window, 'drag' with button down and have a square 'selected area' frame appear, one thing at a time i suppose though.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need Help in Mouse Pointer
    By obaid in forum C++ Programming
    Replies: 3
    Last Post: 12-07-2006, 03:33 AM
  2. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  3. Mouse scroll stopped working
    By Waldo2k2 in forum Tech Board
    Replies: 2
    Last Post: 10-12-2004, 11:25 AM
  4. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM