pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r2853 - in branches/pingus_sdl/src: . components


From: grumbel at BerliOS
Subject: [Pingus-CVS] r2853 - in branches/pingus_sdl/src: . components
Date: Sun, 12 Aug 2007 14:50:13 +0200

Author: grumbel
Date: 2007-08-12 14:50:12 +0200 (Sun, 12 Aug 2007)
New Revision: 2853

Modified:
   branches/pingus_sdl/src/client.cpp
   branches/pingus_sdl/src/client.hpp
   branches/pingus_sdl/src/components/playfield.cpp
   branches/pingus_sdl/src/components/playfield.hpp
   branches/pingus_sdl/src/graphic_context_state.cpp
   branches/pingus_sdl/src/graphic_context_state.hpp
Log:
- small levels on a large display are now properly centered
- removed a full screen draw_fillrect() and replaced it by four that just draw 
a black border where needed
- added Rect handling to GraphicContextState, Playfield can thus be used at 
sizes smaller then the screen

Modified: branches/pingus_sdl/src/client.cpp
===================================================================
--- branches/pingus_sdl/src/client.cpp  2007-08-12 06:26:34 UTC (rev 2852)
+++ branches/pingus_sdl/src/client.cpp  2007-08-12 12:50:12 UTC (rev 2853)
@@ -31,9 +31,10 @@
 #include "gui/cursor.hpp"
 #include "true_server.hpp"
 #include "components/button_panel.hpp"
+#include "world.hpp"
+#include "math.hpp"
 #include "gui/gui_manager.hpp"
 
-
 Client::Client (TrueServer * s)
   : server       (s),
     skip_frame   (0),
@@ -50,8 +51,15 @@
 
   // These object will get deleted by the gui_manager
   button_panel = new ButtonPanel(this, 2, Display::get_height()/2);
-  playfield    = new Playfield(this, Rect(Vector2i(0, 0), 
Size(Display::get_width(), 
-                                                               
Display::get_height())));
+
+  int world_width  = server->get_world()->get_width();
+  int world_height = server->get_world()->get_height();
+
+  playfield    = new Playfield(this, 
Rect(Vector2i(Math::max((Display::get_width()  - world_width)/2,  0),
+                                                   
Math::max((Display::get_height() - world_height)/2, 0)), 
+                                          Size(Math::min(Display::get_width(), 
 world_width),
+                                               
Math::min(Display::get_height(), world_height))));
+
   hurry_up     = new HurryUp(this);
   pcounter     = new PingusCounter(get_server());
   small_map    = new SmallMap(this);
@@ -78,6 +86,27 @@
 }
 
 void
+Client::draw_background (DrawingContext& gc)
+{
+  Rect rect = playfield->get_rect();
+  if (rect != Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height())))
+  {
+    // top
+    gc.draw_fillrect(0, 0, Display::get_width()-1, rect.top,
+                 Color(0,0,0));
+    // bottom
+    gc.draw_fillrect(0, rect.bottom, Display::get_width()-1, 
Display::get_height()-1,
+                 Color(0,0,0));
+    // left
+    gc.draw_fillrect(0, rect.top, rect.left, rect.bottom,
+                 Color(0,0,0));
+    // right
+    gc.draw_fillrect(rect.right, rect.top, Display::get_width()-1, rect.bottom,
+                 Color(0,0,0));
+  }
+}
+
+void
 Client::update (const GameDelta& delta)
 {
   GUIScreen::update (delta);

Modified: branches/pingus_sdl/src/client.hpp
===================================================================
--- branches/pingus_sdl/src/client.hpp  2007-08-12 06:26:34 UTC (rev 2852)
+++ branches/pingus_sdl/src/client.hpp  2007-08-12 12:50:12 UTC (rev 2853)
@@ -62,7 +62,6 @@
   TimeDisplay*   time_display;
   SmallMap*      small_map;
   HurryUp*       hurry_up;
-
   bool enabled;
 
 public:
@@ -79,7 +78,7 @@
 
   /** Update all parts of the world */
   void update (const GameDelta&);
-
+  void draw_background (DrawingContext& gc);
   //void process_events ();
 
   ButtonPanel* get_button_panel () { return button_panel; }

Modified: branches/pingus_sdl/src/components/playfield.cpp
===================================================================
--- branches/pingus_sdl/src/components/playfield.cpp    2007-08-12 06:26:34 UTC 
(rev 2852)
+++ branches/pingus_sdl/src/components/playfield.cpp    2007-08-12 12:50:12 UTC 
(rev 2853)
@@ -40,7 +40,7 @@
     // We keep the SceneContext has member variable so that we don't
     // have to reallocate it every frame, which is quite a costly operation
     scene_context(new SceneContext()),
-    state(rect.get_width(), rect.get_height()),
+    state(rect),
     cap(client->get_button_panel())
 {
   world              = client->get_server()->get_world();
@@ -55,10 +55,10 @@
 }
 
 void
-Playfield::draw (DrawingContext& gc)
+Playfield::draw(DrawingContext& gc)
 {
   scene_context->clear();
-  scene_context->set_cliprect(Rect(Vector2i(0, 0), Size(world->get_width(), 
world->get_height())));
+  scene_context->set_cliprect(rect);
 
   //scene_context->light().fill_screen(Color(50, 50, 50));
  
@@ -66,11 +66,7 @@
 
   cap.set_pingu(current_pingu);
   cap.draw(*scene_context);
-  
-  // Blank out the entire window in case the screen resolution is larger
-  // than the current level.
-  gc.draw_fillrect(0, 0, (float)Display::get_width(), 
(float)Display::get_height(),
-                   Color(0,0,0), -15000);
+
   world->draw(*scene_context);
  
   // Draw the scrolling band

Modified: branches/pingus_sdl/src/components/playfield.hpp
===================================================================
--- branches/pingus_sdl/src/components/playfield.hpp    2007-08-12 06:26:34 UTC 
(rev 2852)
+++ branches/pingus_sdl/src/components/playfield.hpp    2007-08-12 12:50:12 UTC 
(rev 2853)
@@ -62,6 +62,7 @@
   
   Vector2i mouse_pos;
   Vector2f old_state_pos;
+
 public:
   Playfield (Client*, const Rect& rect);
   virtual ~Playfield();
@@ -93,7 +94,7 @@
   void set_server(Server*);
 
   bool is_at (int x, int y) { UNUSED_ARG(x); UNUSED_ARG(y); return true; }
-
+  Rect get_rect() const { return rect; }
 private:
   Playfield (const Playfield&);
   Playfield& operator= (const Playfield&);

Modified: branches/pingus_sdl/src/graphic_context_state.cpp
===================================================================
--- branches/pingus_sdl/src/graphic_context_state.cpp   2007-08-12 06:26:34 UTC 
(rev 2852)
+++ branches/pingus_sdl/src/graphic_context_state.cpp   2007-08-12 12:50:12 UTC 
(rev 2853)
@@ -24,8 +24,7 @@
 class GraphicContextStateImpl
 {
 public:
-  int width;
-  int height;
+  Rect rect;
   
   Vector2f offset;
   float zoom;
@@ -38,8 +37,7 @@
 GraphicContextState::GraphicContextState()
   : impl(new GraphicContextStateImpl())
 {
-  impl->width      = Display::get_width();
-  impl->height     = Display::get_height(); 
+  impl->rect       = Rect(Vector2i(0,0), Size(Display::get_width(), 
Display::get_height()));
   impl->offset     = Vector2f(0,0);
   impl->zoom       = 1.0f;
   impl->rotation   = 0;
@@ -49,14 +47,23 @@
 GraphicContextState::GraphicContextState(int w, int h)
   : impl(new GraphicContextStateImpl())
 {  
-  impl->width      = w;
-  impl->height     = h;
+  impl->rect       = Rect(Vector2i(0,0), Size(w, h));
   impl->offset     = Vector2f(0,0); 
   impl->zoom       = 1.0f;
   impl->rotation   = 0;
   impl->have_limit = false;
 }
 
+GraphicContextState::GraphicContextState(const Rect& rect)
+  : impl(new GraphicContextStateImpl())
+{
+  impl->rect       = rect;
+  impl->offset     = Vector2f(0,0); 
+  impl->zoom       = 1.0f;
+  impl->rotation   = 0;
+  impl->have_limit = false;  
+}
+
 void
 GraphicContextState::set_limit(const Rect& limit)
 {
@@ -73,8 +80,7 @@
 void
 GraphicContextState::set_size(int w, int h)
 {
-  impl->width  = w;
-  impl->height = h;
+  impl->rect = Rect(Vector2i(impl->rect.left, impl->rect.top), Size(w, h));
 }
 
 void
@@ -82,9 +88,11 @@
 {
   gc.push_modelview();
 
-  gc.translate((float)impl->width/2, (float)impl->height/2);
+  gc.translate((float)impl->rect.left, (float)impl->rect.top);
+
+  gc.translate((float)get_width()/2, (float)get_height()/2);
   gc.rotate(impl->rotation);
-  gc.translate(-(float)impl->width/2, -(float)impl->height/2);
+  gc.translate(-(float)get_width()/2, -(float)get_height()/2);
 
   gc.scale(get_zoom(), get_zoom());
   gc.translate(impl->offset.x, impl->offset.y);
@@ -95,9 +103,11 @@
 {
   gc.push_modelview();
 
-  gc.translate((float)impl->width/2, (float)impl->height/2);
+  gc.translate((float)impl->rect.left, (float)impl->rect.top);
+
+  gc.translate((float)get_width()/2, (float)get_height()/2);
   gc.rotate(impl->rotation);
-  gc.translate(-(float)impl->width/2, -(float)impl->height/2);
+  gc.translate(-(float)get_width()/2, -(float)get_height()/2);
 
   gc.scale(get_zoom(), get_zoom());
   gc.translate(impl->offset.x, impl->offset.y);
@@ -115,33 +125,6 @@
   gc.pop_modelview();
 }
 
-#if 0
-void
-GraphicContextState::push(CL_GraphicContext* gc)
-{
-  if (gc == 0)
-    gc = CL_Display::get_current_window()->get_gc();
-  
-  gc->push_modelview();
-
-  gc->add_translate(impl->width/2, impl->height/2);
-  gc->add_rotate(impl->rotation, 0, 0, 1.0);
-  gc->add_translate(-impl->width/2, -impl->height/2);
-
-  gc->add_scale(get_zoom(), get_zoom());
-  gc->add_translate(impl->offset.x, impl->offset.y);
-}
-
-void
-GraphicContextState::pop(CL_GraphicContext* gc)
-{
-  if (gc == 0)
-    gc = CL_Display::get_current_window()->get_gc();
-  
-  gc->pop_modelview();
-}
-#endif 
-
 Rect
 GraphicContextState::get_clip_rect()
 {
@@ -241,15 +224,17 @@
 Vector2f
 GraphicContextState::screen2world(const Vector2i& pos_)
 {
-  Vector2f pos((float)pos_.x, (float)pos_.y);
+  Vector2f pos(float(pos_.x),
+               float(pos_.y));
+
   float sa = (float)sin(-impl->rotation/180.0f*M_PI);
   float ca = (float)cos(-impl->rotation/180.0f*M_PI);
 
-  float dx = pos.x - (float)impl->width/2;
-  float dy = pos.y - (float)impl->height/2;
+  float dx = pos.x - (float)get_width()/2;
+  float dy = pos.y - (float)get_height()/2;
 
-  pos.x = impl->width/2  + (ca * dx - sa * dy);
-  pos.y = impl->height/2 + (sa * dx + ca * dy);
+  pos.x = get_width()/2  + (ca * dx - sa * dy);
+  pos.y = get_height()/2 + (sa * dx + ca * dy);
 
   Vector2f p((float(pos.x) / impl->zoom) - impl->offset.x, 
              (float(pos.y) / impl->zoom) - impl->offset.y);
@@ -272,13 +257,13 @@
 int
 GraphicContextState::get_width()  const 
 {
-  return impl->width; 
+  return impl->rect.get_width(); 
 }
 
 int
 GraphicContextState::get_height() const 
 { 
-  return impl->height; 
+  return impl->rect.get_height(); 
 }
 
 /* EOF */

Modified: branches/pingus_sdl/src/graphic_context_state.hpp
===================================================================
--- branches/pingus_sdl/src/graphic_context_state.hpp   2007-08-12 06:26:34 UTC 
(rev 2852)
+++ branches/pingus_sdl/src/graphic_context_state.hpp   2007-08-12 12:50:12 UTC 
(rev 2853)
@@ -38,6 +38,7 @@
 public:
   GraphicContextState();
   GraphicContextState(int w, int h);
+  GraphicContextState(const Rect& rect);
 
   /** Limit the graphic context to the given limits rectangle, meaning
       that no point of the current visible region will be outside the
@@ -47,11 +48,6 @@
 
   void set_size(int w, int h);
 
-#if 0
-  void push(CL_GraphicContext* gc = 0);
-  void pop (CL_GraphicContext* gc = 0);
-#endif 
-
   void push(DrawingContext& gc);
   void pop (DrawingContext& gc);
 





reply via email to

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