windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 373 - trunk/src


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 373 - trunk/src
Date: Mon, 31 May 2004 12:51:40 +0200

Author: grumbel
Date: 2004-05-31 12:51:40 +0200 (Mon, 31 May 2004)
New Revision: 373

Modified:
   trunk/src/editor.py
   trunk/src/editor_map_component.cxx
   trunk/src/flexlay.i
   trunk/src/graphic_context_state.cxx
   trunk/src/graphic_context_state.hxx
   trunk/src/supertux.py
Log:
- made GraphicContextState refcounted
- added zoom menu

Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/editor.py 2004-05-31 10:51:40 UTC (rev 373)
@@ -241,7 +241,7 @@
 # erase  = Icon(CL_Point(2, 32+1+2), 
make_sprite("../data/images/tools/stock-tool-eraser-22.png"), "Some tooltip", 
toolbar);
 # move   = Icon(CL_Point(2, 32*2+2), 
make_sprite("../data/images/tools/stock-tool-move-22.png"), "Some tooltip", 
toolbar);
 
-def menu_show_foreground():
+def gui_show_foreground():
     display_properties.layer = SuperTuxLevel.FOREGROUND
     display_properties.set(workspace.get_map().get_metadata())
     TilemapLayer_set_current(workspace.get_map().get_metadata().foreground)
@@ -250,7 +250,7 @@
     background_icon.set_up()
     minimap.update_minimap()
 
-def menu_show_background():
+def gui_show_background():
     display_properties.layer = SuperTuxLevel.BACKGROUND
     display_properties.set(workspace.get_map().get_metadata())
     TilemapLayer_set_current(workspace.get_map().get_metadata().background)
@@ -259,7 +259,7 @@
     background_icon.set_down()
     minimap.update_minimap()
 
-def menu_show_interactive():
+def gui_show_interactive():
     display_properties.layer = SuperTuxLevel.INTERACTIVE
     display_properties.set(workspace.get_map().get_metadata())
     TilemapLayer_set_current(workspace.get_map().get_metadata().interactive)
@@ -268,24 +268,24 @@
     background_icon.set_up()
     minimap.update_minimap()
 
-def menu_show_all():
+def gui_show_all():
     display_properties.show_all = True
     display_properties.current_only = False
     display_properties.set(workspace.get_map().get_metadata())
 
-def menu_show_current():
+def gui_show_current():
     display_properties.show_all = False
     display_properties.current_only = False
     display_properties.set(workspace.get_map().get_metadata())
 
-def menu_show_only_current():
+def gui_show_only_current():
     display_properties.show_all = False
     display_properties.current_only = True
     display_properties.set(workspace.get_map().get_metadata())
 
-foreground_icon.set_callback(menu_show_foreground)
-interactive_icon.set_callback(menu_show_interactive)
-background_icon.set_callback(menu_show_background)
+foreground_icon.set_callback(gui_show_foreground)
+interactive_icon.set_callback(gui_show_interactive)
+background_icon.set_callback(gui_show_background)
 eye_icon.set_callback(layer_menu.run)
 
 mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
@@ -305,9 +305,9 @@
 Menu.add_item = Menu_add_item
 del Menu_add_item
 
-layer_menu.add_item(mysprite, "Show all", menu_show_all)
-layer_menu.add_item(mysprite, "Show current", menu_show_current)
-layer_menu.add_item(mysprite, "Show only current", menu_show_only_current)
+layer_menu.add_item(mysprite, "Show all", gui_show_all)
+layer_menu.add_item(mysprite, "Show current", gui_show_current)
+layer_menu.add_item(mysprite, "Show only current", gui_show_only_current)
 
 supertux = SuperTuxGUI(load_supertux_tiles(), gui)
 
@@ -352,6 +352,18 @@
 menu.add_item("File/Save As...", gui_level_save_as)
 menu.add_item("File/Quit",  do_quit)
 
+def gui_set_zoom(zoom):
+    gc = editor_map.get_workspace().get_gc_state()
+    pos = gc.get_pos()
+    gc.set_zoom(zoom)
+    gc.set_pos(pos)
+
+menu.add_item("Zoom/1:4 (25%) ",  lambda: gui_set_zoom(0.25))
+menu.add_item("Zoom/1:2 (50%) ",  lambda: gui_set_zoom(0.5))
+menu.add_item("Zoom/1:1 (100%) ", lambda: gui_set_zoom(1.0)) 
+menu.add_item("Zoom/2:1 (200%) ", lambda: gui_set_zoom(2.0))
+menu.add_item("Zoom/4:1 (400%) ", lambda: gui_set_zoom(4.0))
+
 display_properties = DisplayProperties()
 
 mysprite = make_sprite("../data/images/icons16/stock_paste-16.png")
@@ -417,6 +429,11 @@
 save_dialog = FileDialog("Save SuperTux Level as...", "Save", "Cancel", 
gui.get_component())
 save_dialog.set_filename(config.datadir + "levels/")
 
+# Init the GUI, so that button state is in sync with internal state
+gui_show_interactive()
+gui_show_current()
+set_tilemap_paint_tool()
+
 gui.run()
 
 flexlay.deinit()

Modified: trunk/src/editor_map_component.cxx
===================================================================
--- trunk/src/editor_map_component.cxx  2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/editor_map_component.cxx  2004-05-31 10:51:40 UTC (rev 373)
@@ -122,13 +122,13 @@
 void
 EditorMapComponent::zoom_out(CL_Point pos)
 {
-  workspace.get_gc_state().set_zoom(pos, 
workspace.get_gc_state().get_zoom()/1.25f);
+  workspace.get_gc_state().set_zoom(CL_Pointf(pos.x, pos.y), 
workspace.get_gc_state().get_zoom()/1.25f);
 }
 
 void
 EditorMapComponent::zoom_in(CL_Point pos)
 {
-  workspace.get_gc_state().set_zoom(pos, 
workspace.get_gc_state().get_zoom()*1.25f);
+  workspace.get_gc_state().set_zoom(CL_Pointf(pos.x, pos.y), 
workspace.get_gc_state().get_zoom()*1.25f);
 }
 
 void

Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/flexlay.i 2004-05-31 10:51:40 UTC (rev 373)
@@ -44,6 +44,7 @@
 #include "menu.hxx"
 #include "menubar.hxx"
 #include "scrollbar.hxx"
+#include "graphic_context_state.hxx"
 
 #include "tilemap_paint_tool.hxx"
 #include "tilemap_select_tool.hxx"
@@ -97,6 +98,7 @@
 %include "tilemap_select_tool.hxx"
 %include "objmap_select_tool.hxx"
 %include "zoom_tool.hxx" 
+%include "graphic_context_state.hxx"
 
 
 /* EOF */

Modified: trunk/src/graphic_context_state.cxx
===================================================================
--- trunk/src/graphic_context_state.cxx 2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/graphic_context_state.cxx 2004-05-31 10:51:40 UTC (rev 373)
@@ -21,21 +21,39 @@
 #include <ClanLib/GUI/component.h>
 #include "graphic_context_state.hxx"
 
+class GraphicContextStateImpl
+{
+public:
+  int width;
+  int height;
+  
+  CL_Pointf offset;
+  float zoom;
+};
+
 GraphicContextState::GraphicContextState()
-  : width(1), height(1), offset(0,0), zoom(1.0f)
+  : impl(new GraphicContextStateImpl())
 {
+  impl->width  = 1;
+  impl->height = 1; 
+  impl->offset = CL_Pointf(0,0);
+  impl->zoom   = 1.0f;
 }
 
 GraphicContextState::GraphicContextState(int w, int h)
-  : width(w), height(h), offset(0,0), zoom(1.0f)
+  : impl(new GraphicContextStateImpl())
 {  
+  impl->width  = w;
+  impl->height = h;
+  impl->offset = CL_Pointf(0,0); 
+  impl->zoom   = 1.0f;
 }
 
 void
 GraphicContextState::set_size(int w, int h)
 {
-  width  = w;
-  height = h;
+  impl->width  = w;
+  impl->height = h;
 }
 
 void
@@ -43,7 +61,7 @@
 {
   CL_Display::push_modelview();
   CL_Display::add_scale(get_zoom(), get_zoom());
-  CL_Display::add_translate(offset.x, offset.y);
+  CL_Display::add_translate(impl->offset.x, impl->offset.y);
 }
 
 void
@@ -55,45 +73,45 @@
 CL_Rect
 GraphicContextState::get_clip_rect()
 {
-  return CL_Rect(CL_Point(int(-offset.x),
-                          int(-offset.y)),
-                 CL_Size(int(get_width()  / zoom),
-                         int(get_height() / zoom)));
+  return CL_Rect(CL_Point(int(-impl->offset.x),
+                          int(-impl->offset.y)),
+                 CL_Size(int(get_width()  / impl->zoom),
+                         int(get_height() / impl->zoom)));
 }
 
 void
 GraphicContextState::set_pos(const CL_Pointf& pos)
 {
-  offset.x = -pos.x + (get_width()/2  / zoom);
-  offset.y = -pos.y + (get_height()/2 / zoom);
+  impl->offset.x = -pos.x + (get_width()/2  / impl->zoom);
+  impl->offset.y = -pos.y + (get_height()/2 / impl->zoom);
 }
 
 CL_Pointf
 GraphicContextState::get_pos() const
 {
-  return CL_Pointf(-offset.x + (get_width()/2  / zoom),
-                   -offset.y + (get_height()/2  / zoom));
+  return CL_Pointf(-impl->offset.x + (get_width()/2  / impl->zoom),
+                   -impl->offset.y + (get_height()/2  / impl->zoom));
 }
 
 void
-GraphicContextState::set_zoom(CL_Point pos, float z)
+GraphicContextState::set_zoom(CL_Pointf pos, float z)
 {
-  float old_zoom = zoom;
+  float old_zoom = impl->zoom;
   set_zoom(z);
-  offset.x = pos.x/zoom - pos.x/old_zoom + offset.x;
-  offset.y = pos.y/zoom - pos.y/old_zoom + offset.y;
+  impl->offset.x = pos.x/impl->zoom - pos.x/old_zoom + impl->offset.x;
+  impl->offset.y = pos.y/impl->zoom - pos.y/old_zoom + impl->offset.y;
 }
 
 void
 GraphicContextState::set_zoom(float z)
 {
-  zoom = z;
+  impl->zoom = z;
 }
 
 float
 GraphicContextState::get_zoom()
 {
-  return zoom;
+  return impl->zoom;
 }
 
 void
@@ -110,22 +128,34 @@
   //std::cout << "Screen: " << screen_relation << " Zoom: " << rect_relation 
<< std::endl;
   if (rect_relation < screen_relation) // take width, ignore height
     {
-      zoom = get_width()/width; 
+      impl->zoom = get_width()/width; 
     }
   else // take height, ignore width
     {
-      zoom = get_height()/height;
+      impl->zoom = get_height()/height;
     }
 
-  offset.x = (get_width()  / (2*zoom)) - center_x;
-  offset.y = (get_height() / (2*zoom)) - center_y;
+  impl->offset.x = (get_width()  / (2*impl->zoom)) - center_x;
+  impl->offset.y = (get_height() / (2*impl->zoom)) - center_y;
 }
 
 CL_Pointf
 GraphicContextState::screen2world(const CL_Point& pos)
 {
-  return CL_Pointf((pos.x / zoom) - offset.x, 
-                   (pos.y / zoom) - offset.y);
+  return CL_Pointf((pos.x / impl->zoom) - impl->offset.x, 
+                   (pos.y / impl->zoom) - impl->offset.y);
 }
 
+int
+GraphicContextState::get_width()  const 
+{
+  return impl->width; 
+}
+
+int
+GraphicContextState::get_height() const 
+{ 
+  return impl->height; 
+}
+
 /* EOF */

Modified: trunk/src/graphic_context_state.hxx
===================================================================
--- trunk/src/graphic_context_state.hxx 2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/graphic_context_state.hxx 2004-05-31 10:51:40 UTC (rev 373)
@@ -22,21 +22,15 @@
 
 #include <ClanLib/Core/Math/point.h>
 #include <ClanLib/Core/Math/rect.h>
+#include "shared_ptr.hxx"
 
-class CL_Component;
+class GraphicContextStateImpl;
 
 /** Helper class for capturing the state of a GraphicContext, with
     additional convenience functions to make handling GraphicContexts
     easier */
 class GraphicContextState
 {
-private:
-  int width;
-  int height;
-  
-  CL_Pointf offset;
-  float zoom;
-
 public:
   GraphicContextState();
   GraphicContextState(int w, int h);
@@ -50,20 +44,23 @@
       visible on the screen */
   CL_Rect get_clip_rect();
 
-  int get_width()  const { return width; }
-  int get_height() const { return height; }
+  int get_width()  const;
+  int get_height() const;
 
   void      set_pos(const CL_Pointf& pos);
   CL_Pointf get_pos() const;
 
   /** Set zoom to z, while preserving the screen position pos at the same 
point */
-  void  set_zoom(CL_Point pos, float z);
+  void  set_zoom(CL_Pointf pos, float z);
   void  set_zoom(float z);
   float get_zoom(); 
 
   void zoom_to (const CL_Rect& rect);
 
   CL_Pointf screen2world(const CL_Point& pos);
+
+private:
+  SharedPtr<GraphicContextStateImpl> impl;
 };
 
 #endif

Modified: trunk/src/supertux.py
===================================================================
--- trunk/src/supertux.py       2004-05-31 09:57:12 UTC (rev 372)
+++ trunk/src/supertux.py       2004-05-31 10:51:40 UTC (rev 373)
@@ -196,10 +196,10 @@
     def set(self, map):
         if self.current_only:
             active   = CL_Color(255, 255, 255)
-            deactive = CL_Color(150, 150, 250, 150)
+            deactive = CL_Color(0, 0, 0, 10)
         else:
             active   = CL_Color(255, 255, 255)
-            deactive = CL_Color(0, 0, 0, 10)
+            deactive = CL_Color(150, 150, 250, 150)
 
         if (self.show_all):
             map.foreground.set_foreground_color(active)





reply via email to

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