Jump to content

How to change the cursor in sdl?

- - - - -

  • Please log in to reply
5 replies to this topic

#1
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
i wanna change the cursor in my sdl project, but i am not quite sure how.

the simplest way i have figured out is to use SDL_ShowCursor (0); (i think thats the name of the function) to hide the cursor, and then i'd blit the cursor image to the screen at the invisible cursors current x and y coordinates.

is there any easier way to do this?

#2
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
Here, this looks useful: SDL_CreateCursor - SDL Wiki'

---------- Post added at 05:44 PM ---------- Previous post was at 05:43 PM ----------

Oh, and this: SDL_SetCursor - SDL Wiki'
Latinamne loqueris?

#3
bbqroast

bbqroast

    Codecall Addict

  • Members
  • PipPipPipPipPipPipPip
  • 552 posts
  • Location:/etc/passwd
Those functions should do it, but for a more DIY option:
1. Use the unit32 flag when creating your window to hide the cursor.
2. Create a class with an x and y variable, a function that blits the image to the screen at the x and y variables and one that updates the x and y to the event.motion.x/y variable.
3. When mouse motion is detected (in your event loop) call the updating function.
4. Every frame call the blitting function.
Please, write clearly with proper structure. Double spacing makes the text feel un-jointed, Capitalizing Every Word Means People Stop Before Every Word Sub-Consciously Which Is A Pain In The Backside, and use code tags! (The right most styling box).

#4
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
ok thanks.

#5
mebob

mebob

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 490 posts
I'd assume that the SDL functions would use OS API functions to do it though so it would have better performance.
Latinamne loqueris?

#6
even821

even821

    Learning Programmer

  • Members
  • PipPipPip
  • 70 posts
ok il keep that in mind




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users