[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r2836 - in branches/pingus_sdl/src: . display
From: |
jsalmon3 |
Subject: |
[Pingus-CVS] r2836 - in branches/pingus_sdl/src: . display |
Date: |
Sat, 11 Aug 2007 09:35:59 +0200 |
Author: jsalmon3
Date: 2007-08-11 09:35:53 +0200 (Sat, 11 Aug 2007)
New Revision: 2836
Modified:
branches/pingus_sdl/src/display/drawing_context.cpp
branches/pingus_sdl/src/world.cpp
Log:
Use the clip rect to prevent drawing outside the viewport at higher resolutions
Modified: branches/pingus_sdl/src/display/drawing_context.cpp
===================================================================
--- branches/pingus_sdl/src/display/drawing_context.cpp 2007-08-11 06:26:02 UTC
(rev 2835)
+++ branches/pingus_sdl/src/display/drawing_context.cpp 2007-08-11 07:35:53 UTC
(rev 2836)
@@ -21,6 +21,7 @@
#include <iostream>
#include <algorithm>
#include "drawing_context.hpp"
+#include "math.hpp"
#include "gui/display.hpp"
#include "../sprite.hpp"
#include "../font.hpp"
@@ -62,16 +63,37 @@
{
private:
Sprite sprite;
+ SDL_Rect clip_rect;
+ SDL_Rect Intersection(SDL_Rect* r1, SDL_Rect* r2)
+ {
+ SDL_Rect rect;
+ rect.x = Math::max(r1->x, r2->y);
+ rect.y = Math::max(r1->y, r2->y);
+ int endx = Math::min(r1->x + r1->w, r2->x + r2->w);
+ rect.w = Math::max(endx - rect.x, 0);
+ int endy = Math::min(r1->y + r1->h, r2->y + r2->h);
+ rect.h = Math::max(endy - rect.y, 0);
+ return rect;
+ }
+
public:
SpriteDrawingRequest(const Sprite& sprite_, const Vector3f& pos_)
: DrawingRequest(pos_),
sprite(sprite_)
- {}
+ {
+ SDL_GetClipRect(Display::get_screen(), &clip_rect);
+ }
virtual ~SpriteDrawingRequest() {}
void draw(SDL_Surface* target) {
+ SDL_Rect orig_rect;
+ SDL_Rect rect;
+ SDL_GetClipRect(Display::get_screen(), &orig_rect);
+ rect = Intersection(&orig_rect, &clip_rect);
+ SDL_SetClipRect(Display::get_screen(), &rect);
sprite.draw(pos.x, pos.y, target);
+ SDL_SetClipRect(Display::get_screen(), &orig_rect);
}
};
Modified: branches/pingus_sdl/src/world.cpp
===================================================================
--- branches/pingus_sdl/src/world.cpp 2007-08-11 06:26:02 UTC (rev 2835)
+++ branches/pingus_sdl/src/world.cpp 2007-08-11 07:35:53 UTC (rev 2836)
@@ -29,6 +29,7 @@
#include "particles/rain_particle_holder.hpp"
#include "particles/smoke_particle_holder.hpp"
#include "particles/snow_particle_holder.hpp"
+#include "gui/display.hpp"
#include "pingu.hpp"
#include "display/scene_context.hpp"
#include "pingus_level.hpp"
@@ -119,10 +120,17 @@
gc.light().fill_screen(Color(ambient_light));
+ SDL_Rect orig_rect;
+ SDL_Rect rect = { 0, 0, this->get_width(), this->get_height() };
+ SDL_GetClipRect(Display::get_screen(), &orig_rect);
+ SDL_SetClipRect(Display::get_screen(), &rect);
+
for(WorldObjIter obj = world_obj.begin(); obj != world_obj.end(); ++obj)
{
(*obj)->draw(gc);
}
+
+ SDL_SetClipRect(Display::get_screen(), &orig_rect);
}
void
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r2836 - in branches/pingus_sdl/src: . display,
jsalmon3 <=