Jump to content
  • Advertisement
Sign in to follow this  
ICUP

[SDL] Color Cursor

This topic is 3705 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I read the SDL DocWiki and said that if I wanted a color cursor, just use an SDL surface and blit it to where the cursor is. Makes sense to me, but, doesn't that mean I have to update the screen with every little mouse motion detected? I can't think of any other way to do it. That seems like a horrible way to do it since every time the mouse moves the whole screen gets updated which takes up alot of CPU usage, I think.

Share this post


Link to post
Share on other sites
Advertisement
A 'frame' just means each time you update the screen. You are constantly updating the screen, many times a second. (It's rare for people not to update continually, when using modern PCs)

What you would do, is store the current location of the mouse in your event queue:

int MouseX, MouseY;

...

while(SDL_PollEvent(&event))
{
...
if(event.type == SDL_MOUSEMOTION)
{
//Get the location the mouse, and store it in MouseX, and MouseY.
MouseX = event.mouse.motion.x;
MouseY = event.mouse.motion.y;
}

...
}
And in the part of your code where you draw everything to the screen, right before you call SDL_Flip(), draw the mouse.


SDL_Surface *mousePointer;

...
SDL_Rect rect;
rect.x = MouseX;
rect.y = MouseY;

SDL_BlitSurface(mousePointer, NULL, screen, &rect);

SDL_Flip(screen);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!