The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
SDL_ShowCursor
julien CLEMENT
Guest

On Mac OS 10.5, I can't hide the mouse cursor
with SDL_ShowCursor(0).
I've tried SDL_SelectMouse(0) before and it's the same.
Julien




_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
greenrat


Joined: 12 Jan 2010
Posts: 2
use this code Smile

Code:
static const char *HideArrow[] = {
  /* width height num_colors chars_per_pixel */
  "    32    32        3            1",
  /* colors */
  "X c #000000",
  ". c #ffffff",
  "  c None",
  /* pixels */
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "                                ",
  "0,0"
};


//Create cursor on my mask cursor
static SDL_Cursor *init_system_cursor(const char *image[])
{
  int i, row, col;
  Uint8 data[4*32];
  Uint8 mask[4*32];
  int hot_x, hot_y;

  i = -1;
  for ( row=0; row<32; ++row ) {
    for ( col=0; col<32; ++col ) {
      if ( col % 8 ) {
        data[i] <<= 1;
        mask[i] <<= 1;
      } else {
        ++i;
        data[i] = mask[i] = 0;
      }
      switch (image[4+row][col]) {
        case 'X':
          data[i] |= 0x01;
          mask[i] |= 0x01;
          break;
        case '.':
          mask[i] |= 0x01;
          break;
        case ' ':
          break;
      }
    }
  }
  sscanf(image[4+row], "%d,%d", &hot_x, &hot_y);
  return SDL_CreateCursor(data, mask, 32, 32, hot_x, hot_y);
}


   SDL_Cursor *bHidenCursor;

...
  //On application init
  // Hide cursor
   bHidenCursor=init_system_cursor(HideArrow);
   SDL_SetCursor(bHidenCursor);
...
  //On application close
    SDL_FreeCursor(bHidenCursor);
hardcoder


Joined: 06 Jan 2010
Posts: 84
Location: Poznan, Poland
I have the same problem under Vista, is this code only solution?
greenrat


Joined: 12 Jan 2010
Posts: 2
hmmm I'm use XP, use this

Code:
SDL_Event evt;   
while(SDL_PollEvent(&evt)) {   
  switch(evt.type) {   
  case SDL_ACTIVEEVENT:   
   if(evt.active.state != SDL_APPMOUSEFOCUS) {   
     if(evt.active.gain == 1) {   
      SDL_ShowCursor(0);   
     }   
     else {   
      SDL_ShowCursor(1);   
     }   
   }   
   break;   
  }   
Hyejung


Joined: 22 Mar 2010
Posts: 5
SDL version : SDL 1.3
OS: OSX (leopard/snow leopard)
Used: SDL_WINDOW_OPENGL, and cocoa for creating window

I wanted to have:
full screen without mouse cursor

Problem:
Original mouse cursor did not hide.
(This job is on TODO list for SDL1.3)

My temporal solution FOR THE PEOPLE really really need to hide cursor right now:

1. Go to src/video/cocoa
2. Modify SDL_cocoawindow.m
I put these lines before return (end of the function).

Code:

int Cocoa_CreateWindow(_THIS, SDL_Window * window)
{
    ........
    if (window->flags & SDL_WINDOW_FULLSCREEN)
        [NSCursor hide];
    return 0;
}
Re: SDL_ShowCursor
mandarx


Joined: 19 Dec 2009
Posts: 61
Location: Inside Volcano Etna
Code:
 SDL_ShowCursor(SDL_DISABLE);


best regards
MandarX
SDL_ShowCursor
zoltan
Guest

Be careful with that function. At least on Linux and SDL 1.2, if you have
full-screen mode and you turn the cursor *on*, then it will jump to an
unpredictable location. There was some discussion about that on the list a
year or two ago. The behaviour is actually not a bug, but a feature (with
a rather convoluted explanation), but the conclusion was that it was a bad
feature. However, it has not been fixed.

As a workaround, you should write a little wrapper around
SDL_ShowCursor(), something like this:

void MyShowCursor( int show )
{
int x, y;

SDL_GetMouseState( &x, &y );
SDL_ShowCursor( show ? SDL_ENABLE : SDL_DISABLE );
SDL_WarpMouse( x, y );
}

Zoltan

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Hyejung


Joined: 22 Mar 2010
Posts: 5
SDL version: SDL 1.3
OS: OSX
Used : SDL_WINDOW_OPENGL
---------------------------------------

You are right.
It is nor right to do actually. Embarrassed

I saw that hiding/showing cursor is on TODO list in SDL1.3.
But I needed to hide cursor really.

So that temporal solution is just for the people really need to hide cursor right now, and don't need to have a function disable/enable mouse cursor.

And
I will try to wrap it like you suggested. If I do, I will post it again.

Thank you.