pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r2835 - in branches/pingus_sdl: . src src/worldobjs


From: jsalmon3
Subject: [Pingus-CVS] r2835 - in branches/pingus_sdl: . src src/worldobjs
Date: Sat, 11 Aug 2007 08:26:09 +0200

Author: jsalmon3
Date: 2007-08-11 08:26:02 +0200 (Sat, 11 Aug 2007)
New Revision: 2835

Modified:
   branches/pingus_sdl/TODO
   branches/pingus_sdl/src/blitter.hpp
   branches/pingus_sdl/src/result_screen.cpp
   branches/pingus_sdl/src/sprite.cpp
   branches/pingus_sdl/src/sprite.hpp
   branches/pingus_sdl/src/start_screen.cpp
   branches/pingus_sdl/src/worldobjs/surface_background.cpp
Log:
Enabled the rest of the scale image code

Modified: branches/pingus_sdl/TODO
===================================================================
--- branches/pingus_sdl/TODO    2007-08-11 02:37:16 UTC (rev 2834)
+++ branches/pingus_sdl/TODO    2007-08-11 06:26:02 UTC (rev 2835)
@@ -52,8 +52,6 @@
 
 - src/components/pingus_counter.hpp font should be fixed-width/monospace
 
-- scaling images for different resolutions
-
 - the game is much slower then the Clanlib version
 
 Older Stuff:

Modified: branches/pingus_sdl/src/blitter.hpp
===================================================================
--- branches/pingus_sdl/src/blitter.hpp 2007-08-11 02:37:16 UTC (rev 2834)
+++ branches/pingus_sdl/src/blitter.hpp 2007-08-11 06:26:02 UTC (rev 2835)
@@ -56,15 +56,6 @@
 
   static void fill_rect(PixelBuffer target, const Rect& rect, const Color& 
color);
 
-  /** Creates a new surface (based on a canvas) with the given width
-      and height and stretches the source surface onto it
-
-      @param sur The source surface
-      @param width The new width of the surface.
-      @param height The new height of the surface.
-      @return A newly created surface, the caller is responsible to delete it. 
*/
-  ////static CL_Surface scale_surface (const CL_Surface& sur, int width, int 
height);
-
   /** Flip a surface horizontal */
   static PixelBuffer flip_horizontal (PixelBuffer sur);
 

Modified: branches/pingus_sdl/src/result_screen.cpp
===================================================================
--- branches/pingus_sdl/src/result_screen.cpp   2007-08-11 02:37:16 UTC (rev 
2834)
+++ branches/pingus_sdl/src/result_screen.cpp   2007-08-11 06:26:02 UTC (rev 
2835)
@@ -152,21 +152,13 @@
 ResultScreenComponent::ResultScreenComponent(Result arg_result)
   : result(arg_result)
 {
-  if (Display::get_width() == 800 && Display::get_height() == 600)
+  background = Resource::load_sprite("core/menu/startscreenbg");
+  if (!(Display::get_width() == 800 && Display::get_height() == 600))
     {
-      background = Resource::load_sprite("core/menu/startscreenbg");
+      SDL_Surface* s = Blitter::scale_surface(background.get_surface(),
+        Display::get_width(), Display::get_height());
+      background.set_surface(s);
     }
-#if 0
-  else
-    {
-      PixelBuffer pb = 
Blitter::scale_surface_to_canvas(Resource::load_pixelbuffer(
-                                                                               
    "core/menu/startscreenbg"), Display::get_width(), Display::get_height());
-      CL_SpriteDescription desc;
-      desc.add_frame(pb);
-      background = CL_Sprite(desc);
-    }
-  background.set_alignment(origin_center);
-#endif
        
   chalk_pingus.push_back(Resource::load_sprite("core/misc/chalk_pingu1"));
   chalk_pingus.push_back(Resource::load_sprite("core/misc/chalk_pingu2"));

Modified: branches/pingus_sdl/src/sprite.cpp
===================================================================
--- branches/pingus_sdl/src/sprite.cpp  2007-08-11 02:37:16 UTC (rev 2834)
+++ branches/pingus_sdl/src/sprite.cpp  2007-08-11 06:26:02 UTC (rev 2835)
@@ -46,6 +46,7 @@
   int      frame_delay;
 
   Size     array;
+  SpriteDescription* sprite_description;
 
   bool     loop;
   bool     loop_last_cycle;
@@ -68,7 +69,10 @@
         surface = IMG_Load("data/images/core/misc/404.png");
         assert(surface);
       }
-    
+
+    sprite_description = new SpriteDescription();
+    *sprite_description = desc;
+
     frame_pos = desc.frame_pos;
 
     frame_size.width  = (desc.frame_size.width  == -1) ? surface->w : 
desc.frame_size.width;
@@ -90,6 +94,7 @@
       frame_size(pixelbuffer.get_width(), pixelbuffer.get_height()),
       frame_delay(0),
       array(1,1),
+      sprite_description(NULL),
       loop(true),
       loop_last_cycle(false),
       finished(false),
@@ -110,6 +115,7 @@
   ~SpriteImpl()
   {
     SDL_FreeSurface(surface);
+    delete sprite_description;
   }
 
   void update(float delta)
@@ -169,6 +175,24 @@
   {
     finished = true;
   }
+
+  void set_surface(SDL_Surface* new_surface)
+  {
+    SDL_FreeSurface(surface);
+    surface = new_surface;
+
+    if (sprite_description)
+      {
+        frame_size.width  = (sprite_description->frame_size.width  == -1) ? 
surface->w : sprite_description->frame_size.width;
+        frame_size.height = (sprite_description->frame_size.height == -1) ? 
surface->h : sprite_description->frame_size.height;
+        offset = calc_origin(sprite_description->origin, frame_size) - 
sprite_description->offset;
+      }
+    else
+      {
+        frame_size.width = surface->w;
+        frame_size.height = surface->h;
+      }
+  }
 };
 
 Sprite::Sprite()
@@ -291,4 +315,20 @@
     impl->finish();
 }
 
+SDL_Surface*
+Sprite::get_surface() const
+{
+  if (impl.get())
+    return impl->surface;
+  else
+    return NULL;
+}
+
+void
+Sprite::set_surface(SDL_Surface* surface)
+{
+  if (impl.get())
+    impl->set_surface(surface);
+}
+
 /* EOF */

Modified: branches/pingus_sdl/src/sprite.hpp
===================================================================
--- branches/pingus_sdl/src/sprite.hpp  2007-08-11 02:37:16 UTC (rev 2834)
+++ branches/pingus_sdl/src/sprite.hpp  2007-08-11 06:26:02 UTC (rev 2835)
@@ -58,6 +58,8 @@
   void restart();
   void finish();
   operator bool();
+  SDL_Surface* get_surface() const;
+  void set_surface(SDL_Surface* surface);
 
 private:
   boost::shared_ptr<SpriteImpl> impl;

Modified: branches/pingus_sdl/src/start_screen.cpp
===================================================================
--- branches/pingus_sdl/src/start_screen.cpp    2007-08-11 02:37:16 UTC (rev 
2834)
+++ branches/pingus_sdl/src/start_screen.cpp    2007-08-11 06:26:02 UTC (rev 
2835)
@@ -134,21 +134,13 @@
 StartScreenComponent::StartScreenComponent(const PingusLevel& p)
   : plf(p)
 {
-  if (Display::get_width() == 800 && Display::get_height() == 600)
+  background = Resource::load_sprite("core/menu/startscreenbg");
+  if (!(Display::get_width() == 800 && Display::get_height() == 600))
     {
-      background = Resource::load_sprite("core/menu/startscreenbg");
+      SDL_Surface* s = Blitter::scale_surface(background.get_surface(),
+        Display::get_width(), Display::get_height());
+      background.set_surface(s);
     }
-  else
-    {
-#if 0
-      PixelBuffer pb = 
Blitter::scale_surface_to_canvas(Resource::load_pixelbuffer(
-                                                                               
       "core/menu/startscreenbg"), Display::get_width(), Display::get_height());
-      CL_SpriteDescription desc;
-      desc.add_frame(pb);
-      background = CL_Sprite(desc);
-#endif
-    }
-  ////background.set_alignment(origin_center);
   time_str = GameTime::ticks_to_realtime_string(plf.get_time());
 }
 

Modified: branches/pingus_sdl/src/worldobjs/surface_background.cpp
===================================================================
--- branches/pingus_sdl/src/worldobjs/surface_background.cpp    2007-08-11 
02:37:16 UTC (rev 2834)
+++ branches/pingus_sdl/src/worldobjs/surface_background.cpp    2007-08-11 
06:26:02 UTC (rev 2835)
@@ -66,26 +66,26 @@
   if (color.a > 1.0)
     std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
 
-#if 0
   PixelBuffer canvas = Resource::load_pixelbuffer(desc);
+  SDL_Surface* s = canvas.get_surface();
+  SDL_Surface* new_surface = NULL;
 
   // Scaling Code
   if (stretch_x && stretch_y)
     {
-      canvas = Blitter::scale_surface_to_canvas(canvas, world->get_width(), 
world->get_height());
+      new_surface = Blitter::scale_surface(s, world->get_width(), 
world->get_height());
     }
   else if (stretch_x && !stretch_y)
     {
       if (keep_aspect)
         {
           float aspect = canvas.get_height()/float(canvas.get_width());
-          canvas = Blitter::scale_surface_to_canvas(canvas,
-                                                    world->get_width(),
-                                                    
int(world->get_width()*aspect));
+          new_surface = Blitter::scale_surface(s,
+            world->get_width(), int(world->get_width()*aspect));
         }
       else
         {
-          canvas = Blitter::scale_surface_to_canvas(canvas, 
canvas.get_width(), world->get_height());
+          new_surface = Blitter::scale_surface(s, canvas.get_width(), 
world->get_height());
         }
     }
   else if (!stretch_x && stretch_y)
@@ -93,22 +93,20 @@
       if (keep_aspect)
         {
           float aspect = float(canvas.get_width())/canvas.get_height();
-          canvas = Blitter::scale_surface_to_canvas(canvas,
-                                                    int(world->get_height() * 
aspect),
-                                                    world->get_height());
+          new_surface = Blitter::scale_surface(s,
+            int(world->get_height() * aspect), world->get_height());
         }
       else
         {
-          canvas = Blitter::scale_surface_to_canvas(canvas, 
canvas.get_width(), world->get_height());
+          new_surface = Blitter::scale_surface(s, canvas.get_width(), 
world->get_height());
         }
     }
 
-  SpriteDescription sprite_desc;
-  sprite_desc.add_frame(canvas);
-  bg_surface = Sprite(sprite_desc);
-#else
-  bg_surface = Resource::load_sprite(desc);
-#endif
+  bg_surface = Sprite(canvas);
+  if (new_surface)
+    {
+      bg_surface.set_surface(new_surface);
+    }
 
   timer.stop();
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]