pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] r3758 - in trunk/pingus/src: . components


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3758 - in trunk/pingus/src: . components
Date: Thu, 10 Jul 2008 08:50:54 +0200

Author: grumbel
Date: 2008-07-10 08:50:52 +0200 (Thu, 10 Jul 2008)
New Revision: 3758

Modified:
   trunk/pingus/src/components/smallmap.cpp
   trunk/pingus/src/components/smallmap.hpp
   trunk/pingus/src/demo_session.cpp
   trunk/pingus/src/game_session.cpp
Log:
Resize handling for the SmallMap

Modified: trunk/pingus/src/components/smallmap.cpp
===================================================================
--- trunk/pingus/src/components/smallmap.cpp    2008-07-10 05:38:42 UTC (rev 
3757)
+++ trunk/pingus/src/components/smallmap.cpp    2008-07-10 06:50:52 UTC (rev 
3758)
@@ -29,41 +29,14 @@
 #include "playfield.hpp"
 #include "smallmap.hpp"
 
-SmallMap::SmallMap(Server* server_, Playfield* playfield_)
-  : server(server_),
+SmallMap::SmallMap(Server* server_, Playfield* playfield_, const Rect& rect)
+  : RectComponent(rect), 
+    server(server_),
     playfield(playfield_),
     gc_ptr(0)
-{
-  int max_width = 175;
-  int max_height = 100;
+{ 
+  image = std::auto_ptr<SmallMapImage>(new SmallMapImage(server, 
rect.get_width(), rect.get_height()));
 
-  int min_height = 70;
-  int min_width = 100;
-
-  World* world = server->get_world();
-
-  // Scaling values used in order to keep the aspect ratio
-  int x_scaling = world->get_width()  / max_width;
-  int y_scaling = world->get_height() / max_height;
-
-  // If at best one horizontal pixel in the smallmap represents more colmap
-  // pixels than one vertical pixel
-  if (x_scaling > y_scaling)
-    {
-      width  = max_width;
-      height = Math::max(min_height, world->get_height() / x_scaling);
-    }
-  else
-    {
-      width  = Math::max(min_width, world->get_width() / y_scaling);
-      height = max_height;
-    }
-  
-  x_pos   = 5;
-  y_pos   = Display::get_height() - height - 5;
-
-  image = std::auto_ptr<SmallMapImage>(new SmallMapImage(server, width, 
height));
-
   scroll_mode = false;
 }
 
@@ -72,7 +45,7 @@
 }
 
 void
-SmallMap::draw (DrawingContext& gc)
+SmallMap::draw(DrawingContext& gc)
 {
   // FIXME: This is potentially dangerous, since we don't know how
   // long 'gc' will be alive. Should use a DrawingContext for caching.
@@ -81,34 +54,34 @@
   World* const& world  = server->get_world();
   
   Vector2i of = playfield->get_pos();
-  Rect rect;
+  Rect view_rect;
 
   if (world->get_width() > gc.get_width())
     {
-      int rwidth = int(gc.get_width()  * width  / world->get_width());
-      rect.left  = x_pos + (of.x * width  / world->get_width()) - rwidth/2;
-      rect.right = rect.left + rwidth;
+      int rwidth = int(gc.get_width()  * rect.get_width()  / 
world->get_width());
+      view_rect.left  = rect.left + (of.x * rect.get_width()  / 
world->get_width()) - rwidth/2;
+      view_rect.right = view_rect.left + rwidth;
     }
   else
     {
-      rect.left  = x_pos;
-      rect.right = x_pos + width;
+      view_rect.left  = rect.left;
+      view_rect.right = rect.left + rect.get_width();
     }
 
   if (world->get_height() > gc.get_height())
     {
-      int rheight = int(gc.get_height() * height / world->get_height());
-      rect.top    = y_pos + (of.y * height / world->get_height()) - rheight/2;
-      rect.bottom = rect.top + rheight;
+      int rheight = int(gc.get_height() * rect.get_height() / 
world->get_height());
+      view_rect.top    = rect.top + (of.y * rect.get_height() / 
world->get_height()) - rheight/2;
+      view_rect.bottom = view_rect.top + rheight;
     }
   else
     {
-      rect.top    = y_pos;
-      rect.bottom = y_pos + height;
+      view_rect.top    = rect.top;
+      view_rect.bottom = rect.top + rect.get_height();
     }
   
-  gc.draw(image->get_surface(), Vector2i(x_pos, y_pos));
-  gc.draw_rect(rect.left, rect.top, rect.right, rect.bottom,
+  gc.draw(image->get_surface(), Vector2i(rect.left, rect.top));
+  gc.draw_rect(view_rect.left, view_rect.top, view_rect.right, 
view_rect.bottom,
                Color(0, 255, 0));
 
   server->get_world()->draw_smallmap(this);
@@ -117,8 +90,8 @@
   PinguHolder* pingus = world->get_pingus();
   for(PinguIter i = pingus->begin(); i != pingus->end(); ++i)
     {
-      int x = static_cast<int>(x_pos + ((*i)->get_x() * width  / 
world->get_width()));
-      int y = static_cast<int>(y_pos + ((*i)->get_y() * height / 
world->get_height()));
+      int x = static_cast<int>(rect.left + ((*i)->get_x() * rect.get_width()  
/ world->get_width()));
+      int y = static_cast<int>(rect.top + ((*i)->get_y() * rect.get_height() / 
world->get_height()));
 
       gc.draw_line(x, y, x, y-2, Color(255, 255, 0));
     }
@@ -136,8 +109,8 @@
 SmallMap::draw_sprite(Sprite sprite, Vector3f pos)
 {
   World* world = server->get_world();
-  float x = x_pos + (pos.x * width  / world->get_width());
-  float y = y_pos + (pos.y * height / world->get_height());
+  float x = rect.left + (pos.x * rect.get_width()  / world->get_width());
+  float y = rect.top + (pos.y * rect.get_height() / world->get_height());
 
   gc_ptr->draw(sprite, Vector3f(x, y));
 }
@@ -145,8 +118,8 @@
 bool
 SmallMap::is_at (int x, int y)
 {
-  return (x > x_pos && x < x_pos + (int)width
-         && y > y_pos && y < y_pos + (int)height);
+  return (x > rect.left && x < rect.left + (int)rect.get_width()
+         && y > rect.top && y < rect.top + (int)rect.get_height());
 }
 
 void
@@ -157,8 +130,8 @@
 
   if (scroll_mode)
     {
-      cx = (x - x_pos) * static_cast<int>(world->get_width()  / width);
-      cy = (y - y_pos) * static_cast<int>(world->get_height() / height);
+      cx = (x - rect.left) * static_cast<int>(world->get_width()  / 
rect.get_width());
+      cy = (y - rect.top) * static_cast<int>(world->get_height() / 
rect.get_height());
 
       playfield->set_viewpoint(cx, cy);
     }
@@ -172,8 +145,8 @@
   // set view to the given COs
   int cx, cy;
   World* world = server->get_world();
-  cx = (x - x_pos) * int(world->get_width()) / width;
-  cy = (y - y_pos) * int(world->get_height()) / height ;
+  cx = (x - rect.left) * int(world->get_width()) / rect.get_width();
+  cy = (y - rect.top) * int(world->get_height()) / rect.get_height();
   playfield->set_viewpoint(cx, cy);
 }
 

Modified: trunk/pingus/src/components/smallmap.hpp
===================================================================
--- trunk/pingus/src/components/smallmap.hpp    2008-07-10 05:38:42 UTC (rev 
3757)
+++ trunk/pingus/src/components/smallmap.hpp    2008-07-10 06:50:52 UTC (rev 
3758)
@@ -18,7 +18,7 @@
 #define HEADER_PINGUS_SMALLMAP_HPP
 
 #include "../sprite.hpp"
-#include "../gui/component.hpp"
+#include "../gui/rect_component.hpp"
 
 class Playfield;
 class Server;
@@ -26,7 +26,7 @@
 class SmallMapImage;
 
 /** This is the map that appears in the corner of the screen */
-class SmallMap : public GUI::Component
+class SmallMap : public GUI::RectComponent
 {
 private:
   Server*    server;
@@ -40,18 +40,6 @@
 
   std::auto_ptr<SmallMapImage> image;
 
-  /** Horizontal position of the small map */
-  int x_pos;
-
-  /** Vertical position of the small map */
-  int y_pos;
-
-  /** Width of the small map */
-  int width;
-
-  /** Height of the small map */
-  int height;
-
   /** Indicates whether the playfield should can be scrolled around depending
       on the position of the cursor in the small map */
   bool scroll_mode;
@@ -62,7 +50,7 @@
   DrawingContext* gc_ptr;
 
 public:
-  SmallMap(Server*, Playfield*);
+  SmallMap(Server*, Playfield*, const Rect& rect);
   virtual ~SmallMap();
 
   /*{ @name Stuff called from the GUIManager */

Modified: trunk/pingus/src/demo_session.cpp
===================================================================
--- trunk/pingus/src/demo_session.cpp   2008-07-10 05:38:42 UTC (rev 3757)
+++ trunk/pingus/src/demo_session.cpp   2008-07-10 06:50:52 UTC (rev 3758)
@@ -104,7 +104,7 @@
 
   gui_manager->add(playfield);
 
-  small_map    = new SmallMap(server.get(), playfield);
+  small_map    = new SmallMap(server.get(), playfield, Rect(Vector2i(5, 
size.height - 105), Size(175, 100)));
   gui_manager->add(small_map);
 
   gui_manager->add(new BButton(32+50, 32, "core/demo/fastforward",

Modified: trunk/pingus/src/game_session.cpp
===================================================================
--- trunk/pingus/src/game_session.cpp   2008-07-10 05:38:42 UTC (rev 3757)
+++ trunk/pingus/src/game_session.cpp   2008-07-10 06:50:52 UTC (rev 3758)
@@ -71,7 +71,7 @@
                                          Math::min(Display::get_height(), 
world_height))));
 
   pcounter     = new PingusCounter(get_server());
-  small_map    = new SmallMap(get_server(), playfield);
+  small_map    = new SmallMap(get_server(), playfield, Rect(Vector2i(5, 
size.height - 105), Size(175, 100)));
   time_display = new TimeDisplay(this);
 
   gui_manager->add(playfield);
@@ -380,17 +380,19 @@
   int world_width  = server->get_world()->get_width();
   int world_height = server->get_world()->get_height();
   
-  playfield->set_rect(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))));
+  playfield->set_rect(Rect(Vector2i(Math::max((size.width  - world_width)/2,  
0),
+                                    Math::max((size.height - world_height)/2, 
0)), 
+                           Size(Math::min(size.width,  world_width),
+                                Math::min(size.height, world_height))));
 
-  armageddon_button->set_rect(Rect(Vector2i(Display::get_width() - 40, 
Display::get_height() - 62),
+  armageddon_button->set_rect(Rect(Vector2i(size.width - 40, size.height - 62),
                                    Size(38, 60)));
-  forward_button->set_rect(Rect(Vector2i(Display::get_width() - 40*2, 
Display::get_height() - 62),
+  forward_button->set_rect(Rect(Vector2i(size.width - 40*2, size.height - 62),
                                 Size(38, 60)));
-  pause_button->set_rect(Rect(Vector2i(Display::get_width() - 40*3, 
Display::get_height() - 62),
+  pause_button->set_rect(Rect(Vector2i(size.width - 40*3, size.height - 62),
                                 Size(38, 60)));
+
+  small_map->set_rect(Rect(Vector2i(5, size.height - 105), Size(175, 100)));
 }
 
 /* EOF */





reply via email to

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