SDL_BlitSurface() clipping redundancy?

I’ve been working with SDL for a few days now creating a crude widget set.
Everything’s been fine up until I realized that my widgets weren’t being
clipped correctly when they were drawing themselves to the screen (each widget
has its own clipping rectangle information). I couldn’t find any problem in my
container widget code (which actually sets the clipping rectangles in each
child widget) so I decided to see what gdb had to say…

The actual SDL_BlitSurface call was being made with the arguments
(widgetSurface, NULL, SDL_GetVideoSurface(), &clippingRect) and I confirmed
with gdb that widgetSurface->w was in fact greater than clippingRect.w. I
doubted that there were any bugs in SDL_BlitSurface(), so I created a second
clipping rectangle (relative to the widget surface instead of relative to the
screen) and passed it as the second argument to SDL_BlitSurface() and
everything was fine.

I have no problem with creating two separate clipping rectangles, but it seems
a little redundant to me. Am I doing something wrong here or not looking at
this from the correct angle? Here’s basically what I’m having to do now (with
absolute values inserted instead of variables)…

SDL_Rect rect1 = {0, 0, 50, 100};
SDL_Rect rect2 = {300, 200, 50, 100};

SDL_BlitSurface(surface, &rect1, SDL_GetVideoSurface(), &rect2);
SDL_UpdateRects(SDL_GetVideoSurface(), 1, &rect2);

what I’d rather do, but for some reason won’t work…

SDL_Rect rect = {300, 200, 50, 100};

SDL_BlitSurface(surface, NULL, SDL_GetVideoSurface(), &rect);
SDL_UpdateRects(SDL_GetVideoSurface(), 1, &rect);

Any help/explanation you can provide would be greatly appreciated. Sorry if
the formatting on this post sucks, but I’m not too familiar with slrn or vi.

-Chris

I have no problem with creating two separate clipping rectangles, but it seems
a little redundant to me. Am I doing something wrong here or not looking at
this from the correct angle?

The source rectangle specifies size and position within the source surface.
The destination rectangle specifies position within the destination surface.
The width/height of the destination rectangle is ignored.
The destination rectangle is updated with the position/size of the actual
blit, so it can be used in calls to SDL_UpdateRects() later.

what I’d rather do, but for some reason won’t work…

SDL_Rect rect = {300, 200, 50, 100};

SDL_BlitSurface(surface, NULL, SDL_GetVideoSurface(), &rect);
SDL_UpdateRects(SDL_GetVideoSurface(), 1, &rect);

This should work — it would copy the entire source surface to position
(300,200) of the screen. The (50, 100) you specified is ignored.

The above is how SDL 1.1.6 works. Older versions may differ

wrote

The actual SDL_BlitSurface call was being made with the arguments
(widgetSurface, NULL, SDL_GetVideoSurface(), &clippingRect) and I confirmed
with gdb that widgetSurface->w was in fact greater than clippingRect.w.

ah, here’s your problem. i’m pretty sure the destination rectangle in
SDL_Blit does not actually do any clipping, it seems to be more of a
destination position. you’ll actually want to call SDL_SetClipRect()
to create real clipping.

sorry if this is wrong, i just put this up in a hurry without checking
the code. i hope this is correct, since this is the way i have been
using SDL_Blit, and this is how i interpreted it :]