More fixes
[supertux.git] / src / video / drawing_context.cpp
index d5a5be1..0b56308 100644 (file)
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include "video/drawing_context.hpp"
+
 #include <algorithm>
 #include <config.h>
 
-#include "video/drawing_context.hpp"
-
+#include "math/sizef.hpp"
 #include "supertux/gameconfig.hpp"
 #include "supertux/globals.hpp"
 #include "util/obstackpp.hpp"
 #include "video/texture_manager.hpp"
 #include "video/video_systems.hpp"
 
-static inline int next_po2(int val)
-{
-  int result = 1;
-  while(result < val)
-    result *= 2;
-
-  return result;
-}
-
 DrawingContext::DrawingContext() :
   renderer(0), 
   lightmap(0),
@@ -73,12 +65,12 @@ DrawingContext::init_renderer()
   delete renderer;
   delete lightmap;
 
-  renderer = new_renderer();
-  lightmap = new_lightmap();
+  renderer = VideoSystem::new_renderer();
+  lightmap = VideoSystem::new_lightmap();
 }
 
 void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                              float angle, const Color& color, const Blend& blend,
                              int layer)
 {
@@ -102,20 +94,20 @@ DrawingContext::draw_surface(const Surface* surface, const Vector& position,
   request->color = color;
   request->blend = blend;
 
-  request->request_data = const_cast<Surface*> (surface);
+  request->request_data = surface.get();
 
   requests->push_back(request);
 }
 
 void
-DrawingContext::draw_surface(const Surface* surface, const Vector& position,
+DrawingContext::draw_surface(SurfacePtr surface, const Vector& position,
                              int layer)
 {
   draw_surface(surface, position, 0.0f, Color(1.0f, 1.0f, 1.0f), Blend(), layer);
 }
 
 void
-DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
+DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source,
                                   const Vector& size, const Vector& dest, int layer)
 {
   assert(surface != 0);
@@ -132,7 +124,7 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
   SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest();
   surfacepartrequest->size = size;
   surfacepartrequest->source = source;
-  surfacepartrequest->surface = surface;
+  surfacepartrequest->surface = surface.get();
 
   // clip on screen borders
   if(request->pos.x < 0) {
@@ -155,7 +147,7 @@ DrawingContext::draw_surface_part(const Surface* surface, const Vector& source,
 }
 
 void
-DrawingContext::draw_text(const Font* font, const std::string& text,
+DrawingContext::draw_text(FontPtr font, const std::string& text,
                           const Vector& position, FontAlignment alignment, int layer, Color color)
 {
   DrawingRequest* request = new(obst) DrawingRequest();
@@ -169,7 +161,7 @@ DrawingContext::draw_text(const Font* font, const std::string& text,
   request->color = color;
 
   TextRequest* textrequest = new(obst) TextRequest();
-  textrequest->font = font;
+  textrequest->font = font.get();
   textrequest->text = text;
   textrequest->alignment = alignment;
   request->request_data = textrequest;
@@ -178,7 +170,7 @@ DrawingContext::draw_text(const Font* font, const std::string& text,
 }
 
 void
-DrawingContext::draw_center_text(const Font* font, const std::string& text,
+DrawingContext::draw_center_text(FontPtr font, const std::string& text,
                                  const Vector& position, int layer, Color color)
 {
   draw_text(font, text, Vector(position.x + SCREEN_WIDTH/2, position.y),
@@ -283,6 +275,14 @@ DrawingContext::draw_inverse_ellipse(const Vector& pos, const Vector& size, cons
   requests->push_back(request);     
 }
 
+Rectf
+DrawingContext::get_cliprect() const
+{
+  return Rectf(get_translation().x, get_translation().y,
+               get_translation().x + SCREEN_WIDTH, 
+               get_translation().y + SCREEN_HEIGHT);
+}
+
 void
 DrawingContext::get_light(const Vector& position, Color* color)
 {