pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3785 - in trunk/pingus/src: . display


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3785 - in trunk/pingus/src: . display
Date: Fri, 11 Jul 2008 13:33:38 +0200

Author: grumbel
Date: 2008-07-11 13:33:37 +0200 (Fri, 11 Jul 2008)
New Revision: 3785

Modified:
   trunk/pingus/src/display/drawing_context.cpp
   trunk/pingus/src/display/framebuffer.cpp
   trunk/pingus/src/font.cpp
   trunk/pingus/src/font.hpp
   trunk/pingus/src/fps_counter.cpp
   trunk/pingus/src/sprite_impl.cpp
Log:
Change some more code to use Framebuffer

Modified: trunk/pingus/src/display/drawing_context.cpp
===================================================================
--- trunk/pingus/src/display/drawing_context.cpp        2008-07-11 11:33:29 UTC 
(rev 3784)
+++ trunk/pingus/src/display/drawing_context.cpp        2008-07-11 11:33:37 UTC 
(rev 3785)
@@ -53,7 +53,7 @@
   virtual ~FontDrawingRequest() {}
 
   void render(Framebuffer& fb, const Rect& rect) {
-    font.draw(origin, static_cast<int>(pos.x + rect.left), 
static_cast<int>(pos.y + rect.top), text, fb.get_screen());
+    font.render(origin, static_cast<int>(pos.x + rect.left), 
static_cast<int>(pos.y + rect.top), text, fb);
   }
 };
 

Modified: trunk/pingus/src/display/framebuffer.cpp
===================================================================
--- trunk/pingus/src/display/framebuffer.cpp    2008-07-11 11:33:29 UTC (rev 
3784)
+++ trunk/pingus/src/display/framebuffer.cpp    2008-07-11 11:33:37 UTC (rev 
3785)
@@ -145,13 +145,33 @@
 }
 
 void
-Framebuffer::draw_surface(SDL_Surface* sur, const Vector2i& pos)
+Framebuffer::draw_surface(SDL_Surface* src, const Vector2i& pos)
 {
+  SDL_Rect dstrect;
+  dstrect.x = (Sint16)pos.x;
+  dstrect.y = (Sint16)pos.y;
+  dstrect.w = 0;
+  dstrect.h = 0;  
+
+  SDL_BlitSurface(src, NULL, screen, &dstrect);
 }
 
 void
-Framebuffer::draw_surface(SDL_Surface* sur, const Vector2i& pos, const Rect& 
rect)
+Framebuffer::draw_surface(SDL_Surface* src, const Vector2i& pos, const Rect& 
rect)
 {
+  SDL_Rect dstrect;
+  dstrect.x = (Sint16)pos.x;
+  dstrect.y = (Sint16)pos.y;
+  dstrect.w = 0;
+  dstrect.h = 0;  
+
+  SDL_Rect srcrect;
+  srcrect.x = rect.left;
+  srcrect.y = rect.top;
+  srcrect.w = rect.get_width();
+  srcrect.h = rect.get_height();
+
+  SDL_BlitSurface(src, &srcrect, screen, &dstrect);
 }
 
 void

Modified: trunk/pingus/src/font.cpp
===================================================================
--- trunk/pingus/src/font.cpp   2008-07-11 11:33:29 UTC (rev 3784)
+++ trunk/pingus/src/font.cpp   2008-07-11 11:33:37 UTC (rev 3785)
@@ -21,8 +21,8 @@
 #include "font.hpp"
 #include "line_iterator.hpp"
 #include "font_description.hpp"
-#include "display/display.hpp"
-
+#include "display/framebuffer.hpp"
+
 static bool vline_empty(SDL_Surface* surface, int x, Uint8 threshold)
 {
   if (x >= surface->w)
@@ -40,7 +40,7 @@
     }
   return true;
 }
-
+
 class FontImpl
 {
 public:
@@ -164,26 +164,24 @@
     SDL_FreeSurface(surface);
   }
 
-  void draw(Origin origin, int x, int y_, const std::string& text, 
SDL_Surface* target)
+  void render(Origin origin, int x, int y_, const std::string& text, 
Framebuffer& fb)
   {
     float y = float(y_);
     // FIXME: only origins top_left, top_right and top_center to work right now
     LineIterator it(text);
     while(it.next()) {
-      draw_line(origin, x, int(y), it.get(), target);
+      render_line(origin, x, int(y), it.get(), fb);
       y += vertical_spacing;
     }
   }
 
-  void draw_line(Origin origin, int x, int y, const std::string& text, 
SDL_Surface* target)
+  void render_line(Origin origin, int x, int y, const std::string& text, 
Framebuffer& fb)
   {
     Vector2i offset = calc_origin(origin, get_size(text));
 
     float dstx = float(x - offset.x);
     float dsty = float(y - offset.y);
-
-    if (!target) target = Display::get_screen();
-
+    
     for(std::string::size_type i = 0; i < text.size(); ++i)
       {
         if (text[i] == ' ')
@@ -196,7 +194,7 @@
             if (srcrect.w != 0 && srcrect.h != 0)
               {
                SDL_Rect dstrect = { int(dstx), int(dsty), 0, 0 };
-                SDL_BlitSurface(surface, &srcrect, target, &dstrect);
+                SDL_BlitSurface(surface, &srcrect, fb.get_screen(), &dstrect);
                 dstx += srcrect.w + char_spacing;
               }
             else
@@ -250,7 +248,7 @@
     return Rect(Vector2i(x, y), get_size(str));
   }
 };
-
+
 Font::Font()
 {
 }
@@ -261,17 +259,17 @@
 }
 
 void
-Font::draw(int x, int y, const std::string& text, SDL_Surface* target)
+Font::render(int x, int y, const std::string& text, Framebuffer& fb)
 {
   if (impl)
-    impl->draw(origin_top_left, x,y,text, target);
+    impl->render(origin_top_left, x,y,text, fb);
 }
 
 void
-Font::draw(Origin origin, int x, int y, const std::string& text, SDL_Surface* 
target)
+Font::render(Origin origin, int x, int y, const std::string& text, 
Framebuffer& fb)
 {
   if (impl)
-    impl->draw(origin, x,y,text, target); 
+    impl->render(origin, x,y,text, fb); 
 }
 
 int
@@ -318,5 +316,5 @@
   else
     return Rect();
 }
-
+
 /* EOF */

Modified: trunk/pingus/src/font.hpp
===================================================================
--- trunk/pingus/src/font.hpp   2008-07-11 11:33:29 UTC (rev 3784)
+++ trunk/pingus/src/font.hpp   2008-07-11 11:33:37 UTC (rev 3785)
@@ -26,16 +26,16 @@
 
 class FontImpl;
 class FontDescription;
-
-/** */
+class Framebuffer;
+
 class Font
 {
 public:
   Font();
   Font(const FontDescription& desc);
 
-  void draw(int x, int y, const std::string& text, SDL_Surface* target = 0);
-  void draw(Origin origin, int x, int y, const std::string& text, SDL_Surface* 
target = 0);
+  void render(int x, int y, const std::string& text, Framebuffer& fb);
+  void render(Origin origin, int x, int y, const std::string& text, 
Framebuffer& fb);
 
   int  get_height() const;
   int  get_width(char) const;
@@ -46,7 +46,7 @@
 private:
   boost::shared_ptr<FontImpl> impl;
 };
-
+
 #endif
 
 /* EOF */

Modified: trunk/pingus/src/fps_counter.cpp
===================================================================
--- trunk/pingus/src/fps_counter.cpp    2008-07-11 11:33:29 UTC (rev 3784)
+++ trunk/pingus/src/fps_counter.cpp    2008-07-11 11:33:37 UTC (rev 3785)
@@ -21,7 +21,7 @@
 #include "display/display.hpp"
 
 FPSCounter fps_counter;
-
+
 FPSCounter::FPSCounter()
 {
   start_time = SDL_GetTicks();
@@ -40,12 +40,12 @@
 
   if (odd_frame)
     {
-      Fonts::pingus_small.draw(origin_center, Display::get_width()/2, 34, 
fps_string);
+      Fonts::pingus_small.render(origin_center, Display::get_width()/2, 34, 
fps_string, Display::get_framebuffer());
       odd_frame = false;
     }
   else
     {
-      Fonts::pingus_small.draw(origin_center, Display::get_width()/2, 34, "+ " 
+ std::string(fps_string) + " +");
+      Fonts::pingus_small.render(origin_center, Display::get_width()/2, 34, "+ 
" + std::string(fps_string) + " +", Display::get_framebuffer());
       odd_frame = true;
     }
 }
@@ -66,6 +66,5 @@
       start_time = SDL_GetTicks();
     }
 }
-
-
+
 /* EOF */

Modified: trunk/pingus/src/sprite_impl.cpp
===================================================================
--- trunk/pingus/src/sprite_impl.cpp    2008-07-11 11:33:29 UTC (rev 3784)
+++ trunk/pingus/src/sprite_impl.cpp    2008-07-11 11:33:37 UTC (rev 3785)
@@ -115,21 +115,12 @@
 {
   if (!optimized)
     optimize();
-
-  SDL_Rect dstrect;
-  dstrect.x = (Sint16)(x - offset.x);
-  dstrect.y = (Sint16)(y - offset.y);
-  dstrect.w = 0;
-  dstrect.h = 0;  
-
-  SDL_Rect srcrect;
-  srcrect.w = frame_size.width;
-  srcrect.h = frame_size.height;
-
-  srcrect.x = frame_pos.x + (srcrect.w * (frame%array.width));
-  srcrect.y = frame_pos.y + (srcrect.h * (frame/array.width));
-
-  SDL_BlitSurface(surface.get_surface(), &srcrect, fb.get_screen(), &dstrect);
+  
+  fb.draw_surface(surface.get_surface(), 
+                  Vector2i(static_cast<int>(x - offset.x), static_cast<int>(y 
- offset.y)),
+                  Rect(frame_pos + Vector2i(frame_size.width  * 
(frame%array.width),
+                                            frame_size.height * 
(frame/array.width)),
+                       frame_size));
 }
 
 void





reply via email to

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