How to make a Button?

Hi!

I’m a brand new sdl user and i would like to know one or two things

1- how can i make a button? i.e. how can i specify an area in which the
mouse has an effect (and none outside)?
2- how can i create a eraser ?

Thx…

I’m also looking for some sites where i could find a lots of examples (but
libsdl.org)

Thx again :)_________________________________________________________________
MSN Photos est le moyen le plus simple de partager, modifier et imprimer vos
photos pr?f?r?es. http://photos.msn.fr/Support/WorldWide.aspx

Hi!

I’m a brand new sdl user and i would like to know one or two things

1- how can i make a button? i.e. how can i specify an area in which the
mouse has an effect (and none outside)?

With just plain ol’ SDL, there’s no concept of widgets. So, to do this,
you simply need to pay attention to mouse clicks (SDL_MOUSEBUTTONDOWN
events) and test to see if the event occured within the area of your
button (check the “.button.x” and “.button.y” parts of your SDL_Event
variable).

2- how can i create a eraser ?

This question is pretty vague. What are you erasing? What should appear
behind it?

If it’s simply the matter of erasing to black or white or some other
solid color, you could use SDL_FillRect(). If you want some kind of
’shaped’ eraser (again, which erases to some solid color), just create
an image of the shape, and either use an alpha channel (ie, use a PNG
format image and load it using libSDL_image) or a color key, to make
the parts ‘outside’ of the shape see-through, and then SDL_BlitSurface() it
onto your window (or whatever surface you’re ‘erasing’ into).

If it’s a matter of erasing some object and showing some background which
was there to begin with, you could simply SDL_BlitSurface() from
a particular small rectangle source on your original background image
(assuming it was available in some SDL_Surface* somewhere), or, the more
complicated way would be to copy what was ‘behind’ the object before
drawing it, and then redraw that back onto the screen when you erase it
(again, using SDL_BlitSurface() both times… you’ll probably want to
create a new small surface for this ‘behind’ copying, for each of the objects
you’re going to be drawing and erasing.)

Frankly, what I do depends on the kind of game and complexity of the
screen (and how lazy I am… sorry :^) ). In Mad Bomber, I erase the
bomber, the bombs, the water droplets, and the buckets by actually
SDL_BlitSurface()'ing small pieces a static background image.

In Defendguin, since there’s SO much going on (and the background is
generally black), I simply erase the ENTIRE screen and redraw everything
all over again. CPU-intensive, but it’s about all I can do when I have
huge parts of the screen scrolling, and the rest covered in hundreds of
tiny-to-small-sized objects.

In Circus Linux!, the background is actually two animated frames[*],
so here, too, I erase the entire screen (but this time, I just blit the
appropriate frame of the animated background, rather than doing a
full-screen SDL_FillRect() of black).

[*] - There is a “–low” command-line option which reduces the number of
frames blitted, and loses the fullscreen background animation.
It helps a lot on slower boxes, I hope. :slight_smile:

-bill!On Wed, Mar 13, 2002 at 05:21:13PM +0000, olivier caignart wrote:

I’m a brand new sdl user and i would like to know one or two things

1- how can i make a button? i.e. how can i specify an area in which the
mouse has an effect (and none outside)?
2- how can i create a eraser ?

You should use a high level toolkit like GTK+ or Qt instead. SDL does not
directly support things like buttons and scrollbars and menubars, etc.
There are add-on libraries that add this functionality, but it’s probably
not what you want, either.

Can we put this question at the very top of the FAQ, if it isn’t there
already?

–ryan.

I’m a brand new sdl user and i would like to know one or two things

1- how can i make a button? i.e. how can i specify an area in which the
mouse has an effect (and none outside)?
2- how can i create a eraser ?

You should use a high level toolkit like GTK+ or Qt instead. SDL does not
directly support things like buttons and scrollbars and menubars, etc.
There are add-on libraries that add this functionality, but it’s probably
not what you want, either.

Can we put this question at the very top of the FAQ, if it isn’t there
already?

You forgot to mention the plethora of “fullscreen GUI” libraries available
on the SDL libraries page.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment