pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/worldmap pingus.hxx,1.18,1.19 worldma


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldmap pingus.hxx,1.18,1.19 worldmap.cxx,1.25,1.26 worldmap.hxx,1.17,1.18
Date: 2 Nov 2002 14:46:31 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/worldmap
In directory dark:/tmp/cvs-serv22287/worldmap

Modified Files:
        pingus.hxx worldmap.cxx worldmap.hxx 
Log Message:
quick&dirty scroll implementation for the worldmap

Index: pingus.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/pingus.hxx,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- pingus.hxx  15 Oct 2002 19:13:33 -0000      1.18
+++ pingus.hxx  2 Nov 2002 14:46:29 -0000       1.19
@@ -99,6 +99,7 @@
 
   /** Set the pingu to the position of a given node */
   void set_position (NodeId node); 
+  Vector get_pos() const { return pos; }
 
   float get_z_pos() const;
 

Index: worldmap.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.cxx,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- worldmap.cxx        29 Oct 2002 12:48:33 -0000      1.25
+++ worldmap.cxx        2 Nov 2002 14:46:29 -0000       1.26
@@ -39,6 +39,7 @@
 #include "drawable.hxx"
 #include "dot.hxx"
 #include "path_graph.hxx"
+#include "../math.hxx"
 
 namespace WorldMapNS {
 
@@ -51,7 +52,10 @@
 };
 
 WorldMap::WorldMap(const std::string& arg_filename) 
-  : filename(arg_filename)
+  : display_gc (0, 0, CL_Display::get_width()-1, CL_Display::get_height()-1, 
+                0, 0),
+    filename(arg_filename),
+    width(1161), height(600) // FIXME: ugly..
 {
   xmlDocPtr doc = xmlParseFile(filename.c_str());
   
@@ -164,11 +168,23 @@
 void
 WorldMap::draw (GraphicContext& gc)
 {
+  Vector pingu_pos = pingus->get_pos();
+
+  pingu_pos.x = Math::mid(float(display_gc.get_width()/2), 
+                          pingu_pos.x, 
+                          float(width - display_gc.get_width()/2));
+
+  pingu_pos.y = Math::mid(float(display_gc.get_height()/2), 
+                          pingu_pos.y, 
+                          float(height - display_gc.get_height()/2));
+  
+  display_gc.set_offset(-pingu_pos.x, -pingu_pos.y);
+
   std::stable_sort(drawables.begin(), drawables.end(), z_pos_sorter());
 
   for (DrawableLst::iterator i = drawables.begin (); i != drawables.end (); 
++i)
     {
-      (*i)->draw (gc);
+      (*i)->draw (display_gc);
     }
 }
 
@@ -202,13 +218,15 @@
 void
 WorldMap::on_primary_button_press(int x, int y)
 {
+  const Vector& click_pos = display_gc.screen_to_world(Vector(x, y));
+
   std::cout << "<position>\n"
-            << "  <x-pos>" << x << "</x-pos>\n"
-            << "  <y-pos>" << y << "</y-pos>\n"
+            << "  <x-pos>" << click_pos.x << "</x-pos>\n"
+            << "  <y-pos>" << click_pos.y << "</y-pos>\n"
             << "  <z-pos>0</z-pos>\n"
             << "</position>\n\n" << std::endl;
 
-  Dot* dot = path_graph->get_dot(x, y);
+  Dot* dot = path_graph->get_dot(click_pos.x, click_pos.y);
   if (dot)
     {
       std::cout << "Clicked on: " << dot->get_name() << std::endl;

Index: worldmap.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldmap/worldmap.hxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- worldmap.hxx        13 Oct 2002 23:02:29 -0000      1.17
+++ worldmap.hxx        2 Nov 2002 14:46:29 -0000       1.18
@@ -23,6 +23,7 @@
 #include <vector>
 #include "../libxmlfwd.hxx"
 #include "stat.hxx"
+#include "../display_graphic_context.hxx"
 
 class GraphicContext;
 class CL_Key;
@@ -46,11 +47,17 @@
 class WorldMap
 {
 private:
+  // FIXME: We should use a ScrollGC or something like that here
+  DisplayGraphicContext display_gc;
+
   /** name of the file to parse */
   std::string filename;
 
   typedef std::vector<Drawable*>   ObjectLst;
   typedef std::vector<Drawable*> DrawableLst;
+
+  int width;
+  int height;
 
   Pingus* pingus;
 





reply via email to

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