windstille-devel
[Top][All Lists]
Advanced

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

[Windstille-devel] rev 363 - trunk/src


From: Ingo Ruhnke
Subject: [Windstille-devel] rev 363 - trunk/src
Date: Sat, 29 May 2004 20:53:44 +0200

Author: grumbel
Date: 2004-05-29 20:53:43 +0200 (Sat, 29 May 2004)
New Revision: 363

Added:
   trunk/src/tool.cxx
   trunk/src/tool.hxx
Removed:
   trunk/src/tilemap_tool.cxx
   trunk/src/tilemap_tool.hxx
Modified:
   trunk/src/SConstruct
   trunk/src/editor.py
   trunk/src/editor_map.hxx
   trunk/src/editor_map_component.cxx
   trunk/src/editor_map_component.hxx
   trunk/src/objmap_select_tool.cxx
   trunk/src/objmap_select_tool.hxx
   trunk/src/supertux.py
   trunk/src/tile.cxx
   trunk/src/tile_selector.cxx
   trunk/src/tilemap_paint_tool.cxx
   trunk/src/tilemap_paint_tool.hxx
   trunk/src/tilemap_select_tool.cxx
   trunk/src/tilemap_select_tool.hxx
   trunk/src/tool_manager.cxx
   trunk/src/tool_manager.hxx
   trunk/src/workspace.cxx
   trunk/src/zoom_tool.cxx
   trunk/src/zoom_tool.hxx
Log:
- cleaned up tool classes
- made them refcounted and such

Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct        2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/SConstruct        2004-05-29 18:53:43 UTC (rev 363)
@@ -106,9 +106,9 @@
     'tile_selector.cxx',
     'tilemap_paint_tool.cxx',
     'tilemap_select_tool.cxx',
-    'tilemap_tool.cxx',
     'tilemap_layer.cxx',
     'tileset.cxx',
+    'tool.cxx',
     'tool_manager.cxx',
     'workspace.cxx',
     'window.cxx',

Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/editor.py 2004-05-29 18:53:43 UTC (rev 363)
@@ -19,11 +19,12 @@
 
 import sys
 from flexlay import *
-from supertux import *
 
 flexlay = Flexlay()
 flexlay.init()
 
+from supertux import *
+
 editor = Editor()
 gui = editor.get_gui_manager()
 

Modified: trunk/src/editor_map.hxx
===================================================================
--- trunk/src/editor_map.hxx    2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/editor_map.hxx    2004-05-29 18:53:43 UTC (rev 363)
@@ -33,7 +33,6 @@
 class Command;
 class EditorMapComponent;
 class EditorMapImpl;
-class TileMapTool;
 
 /** Object which represents a level, quirled together with the GUI
     stuff */

Modified: trunk/src/editor_map_component.cxx
===================================================================
--- trunk/src/editor_map_component.cxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/editor_map_component.cxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -25,7 +25,6 @@
 #include "editor_names.hxx"
 #include "editor_map.hxx"
 #include "tool_manager.hxx"
-#include "tilemap_tool.hxx"
 #include "editor.hxx"
 #include "workspace.hxx"
 #include "scrollbar.hxx"

Modified: trunk/src/editor_map_component.hxx
===================================================================
--- trunk/src/editor_map_component.hxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/editor_map_component.hxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -30,7 +30,6 @@
 #include "workspace.hxx"
 
 class Scrollbar;
-class TileMapTool;
 
 /** Object which represents a level, quirled together with the GUI
     stuff */

Modified: trunk/src/objmap_select_tool.cxx
===================================================================
--- trunk/src/objmap_select_tool.cxx    2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/objmap_select_tool.cxx    2004-05-29 18:53:43 UTC (rev 363)
@@ -30,15 +30,43 @@
 #include "editor.hxx"
 #include "objmap_object.hxx"
 #include "object_move_command.hxx"
+#include "object_delete_command.hxx"
+#include "tool_impl.hxx"
 #include "objmap_select_tool.hxx"
 
 extern CL_ResourceManager* resources;
 
+class ObjMapSelectToolImpl : public ToolImpl
+{
+public:
+  CL_Signal_v1<CL_Menu*> on_popup_menu_display;
+
+  enum { DRAG, SELECT, NONE } state;
+
+  /** the position on which the object was clicked, relative to the
+      object */
+  CL_Point offset;
+
+  CL_Point drag_start;
+  CL_Rect selection_rect;
+
+  ObjMapSelectTool::Selection selection;
+  ObjectMoveCommand*   move_command;
+  ObjectDeleteCommand* delete_command;
+
+  void draw();
+
+  void on_mouse_up  (const CL_InputEvent& event);
+  void on_mouse_down(const CL_InputEvent& event);
+  void on_mouse_move(const CL_InputEvent& event);
+};
+
 ObjMapSelectTool::ObjMapSelectTool()
+  : impl(new ObjMapSelectToolImpl())
 {
-  state = NONE;
-  offset = CL_Point(0, 0);
-  move_command = 0;
+  impl->state = ObjMapSelectToolImpl::NONE;
+  impl->offset = CL_Point(0, 0);
+  impl->move_command = 0;
 }
 
 ObjMapSelectTool::~ObjMapSelectTool()
@@ -46,9 +74,33 @@
 }
  
 void
-ObjMapSelectTool::draw()
+ObjMapSelectTool::clear_selection()
 {
-  for (Selection::iterator i = selection.begin(); i != selection.end(); ++i)
+  impl->selection.clear(); 
+}
+
+ObjMapSelectTool::Selection
+ObjMapSelectTool::get_selection() const 
+{ 
+  return impl->selection;
+}
+
+void
+ObjMapSelectTool::set_selection(const Selection& sel) 
+{ 
+  impl->selection = sel; 
+}
+
+CL_Signal_v1<CL_Menu*>& 
+ObjMapSelectTool::sig_on_popup_menu_display()
+{
+  return impl->on_popup_menu_display; 
+}
+
+void
+ObjMapSelectToolImpl::draw()
+{
+  for (ObjMapSelectTool::Selection::iterator i = selection.begin(); i != 
selection.end(); ++i)
     {
       (*i)->draw();
       CL_Display::draw_rect((*i)->get_bound_rect(), CL_Color(255, 0, 0));
@@ -67,7 +119,7 @@
 }
 
 void
-ObjMapSelectTool::on_mouse_up(const CL_InputEvent& event)
+ObjMapSelectToolImpl::on_mouse_up(const CL_InputEvent& event)
 {
   ObjectLayer objmap = ObjectLayer::current();
 
@@ -117,7 +169,7 @@
 }
 
 void
-ObjMapSelectTool::on_mouse_down(const CL_InputEvent& event)
+ObjMapSelectToolImpl::on_mouse_down(const CL_InputEvent& event)
 {
   ObjectLayer objmap = ObjectLayer::current();
 
@@ -136,7 +188,8 @@
             {
               if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT))
                 {
-                  Selection::iterator i = std::find(selection.begin(), 
selection.end(), obj);
+                  ObjMapSelectTool::Selection::iterator i
+                    = std::find(selection.begin(), selection.end(), obj);
                   if (i == selection.end())
                     selection.push_back(obj);
                   else
@@ -156,7 +209,8 @@
                     }
 
                   move_command = new ObjectMoveCommand(objmap);
-                  for (Selection::iterator i = selection.begin(); i != 
selection.end(); ++i)
+                  for (ObjMapSelectTool::Selection::iterator i = 
selection.begin();
+                       i != selection.end(); ++i)
                     {
                       move_command->add_obj((*i)->get_handle());
                     }
@@ -178,7 +232,7 @@
 }
 
 void
-ObjMapSelectTool::on_mouse_move(const CL_InputEvent& event)
+ObjMapSelectToolImpl::on_mouse_move(const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
   CL_Point pos = parent->screen2world(event.mouse_pos);
@@ -186,7 +240,8 @@
   switch(state)
     {
     case DRAG:
-      for (Selection::iterator i = selection.begin(); i != selection.end(); 
++i)
+      for (ObjMapSelectTool::Selection::iterator i = selection.begin(); 
+           i != selection.end(); ++i)
         {
           (*i)->set_pos((*i)->get_pos() + (pos - drag_start));
         }
@@ -204,4 +259,10 @@
     }
 }
 
+Tool
+ObjMapSelectTool::to_tool()
+{
+  return Tool(impl); 
+}
+
 /* EOF */

Modified: trunk/src/objmap_select_tool.hxx
===================================================================
--- trunk/src/objmap_select_tool.hxx    2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/objmap_select_tool.hxx    2004-05-29 18:53:43 UTC (rev 363)
@@ -20,56 +20,31 @@
 #ifndef HEADER_OBJMAP_SELECT_TOOL_HXX
 #define HEADER_OBJMAP_SELECT_TOOL_HXX
 
-#include "tilemap_tool.hxx"
 #include "object_layer.hxx"
 #include "object_brush.hxx"
+#include "tool.hxx"
 
 class CL_Menu;
-class EditorMap;
-class ObjectMoveCommand;
-class ObjectDeleteCommand;
+class ObjMapSelectToolImpl;
 
 /** */
-class ObjMapSelectTool : public TileMapTool
+class ObjMapSelectTool
 {
 public:
   typedef std::vector<ObjectLayer::Obj*> Selection; 
 
-private:
-  CL_Signal_v1<CL_Menu*> on_popup_menu_display;
-
-  enum { DRAG, SELECT, NONE } state;
-
-  /** the position on which the object was clicked, relative to the
-      object */
-  CL_Point offset;
-
-  CL_Point drag_start;
-  CL_Rect selection_rect;
-
-  Selection selection;
-  ObjectMoveCommand* move_command;
-  ObjectDeleteCommand* delete_command;
-
-public:
   ObjMapSelectTool();
   ~ObjMapSelectTool();
 
-  void draw();
+  void clear_selection();
+  Selection get_selection() const;
+  void set_selection(const Selection& sel);
 
-  void on_mouse_up  (const CL_InputEvent& event);
-  void on_mouse_down(const CL_InputEvent& event);
-  void on_mouse_move(const CL_InputEvent& event);
+  CL_Signal_v1<CL_Menu*>& sig_on_popup_menu_display();
 
-  void clear_selection() { selection.clear(); }
-  Selection get_selection() const { return selection; }
-  void set_selection(const Selection& sel) { selection = sel; }
-
-  CL_Signal_v1<CL_Menu*>& sig_on_popup_menu_display() { return 
on_popup_menu_display; }
-
+  Tool to_tool();
 private:
-  ObjMapSelectTool (const ObjMapSelectTool&);
-  ObjMapSelectTool& operator= (const ObjMapSelectTool&);
+  SharedPtr<ObjMapSelectToolImpl> impl;
 };
 
 #endif

Modified: trunk/src/supertux.py
===================================================================
--- trunk/src/supertux.py       2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/supertux.py       2004-05-29 18:53:43 UTC (rev 363)
@@ -36,7 +36,7 @@
 
             tileset.add_tile(id,
                              Tile(supertux_datadir + 'images/tilesets/' + 
image,
-                                  CL_Color(255, 255, 255, 255),
+                                  CL_Color(254, 254, 254, 254),
                                   CL_Color(255,   0,   0, 128)))
 
 class SuperTuxLevel:

Modified: trunk/src/tile.cxx
===================================================================
--- trunk/src/tile.cxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tile.cxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -114,20 +114,26 @@
 CL_PixelBuffer
 Tile::get_pixelbuffer()
 {      
-  if (impl->pixelbuffer)
-    return impl->pixelbuffer;
-  {
-    if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, 
".jpg"))
-      {
-        impl->pixelbuffer = 
CL_PixelBuffer(*CL_ProviderFactory::load(impl->filename));
-      }
-    else
-      {
-        //CL_SpriteDescription descr(impl->filename, resources);
-        //impl->pixelbuffer = 
CL_PixelBuffer(*(descr.get_frames().begin()->first));
-        assert(0);
-      }
-    return impl->pixelbuffer;
+  try {
+    if (impl->pixelbuffer)
+      return impl->pixelbuffer;
+    {
+      if (has_suffix(impl->filename, ".png") || has_suffix(impl->filename, 
".jpg"))
+        {
+          impl->pixelbuffer = 
CL_PixelBuffer(*CL_ProviderFactory::load(impl->filename));
+        }
+      else
+        {
+          //CL_SpriteDescription descr(impl->filename, resources);
+          //impl->pixelbuffer = 
CL_PixelBuffer(*(descr.get_frames().begin()->first));
+          assert(0);
+        }
+      return impl->pixelbuffer;
+    }
+  } catch(CL_Error& err) {
+    std::cout << "CL_Error: " << err.message << std::endl;
+    std::cout << "          filename = " << impl->filename << std::endl;
+    return CL_PixelBuffer();
   }
 }
 

Modified: trunk/src/tile_selector.cxx
===================================================================
--- trunk/src/tile_selector.cxx 2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tile_selector.cxx 2004-05-29 18:53:43 UTC (rev 363)
@@ -67,7 +67,7 @@
       brush.set_opaque();
       brush.at(0, 0) = mouse_over_tile;
 
-      TileMapPaintTool::current()->set_brush(brush);
+      TileMapPaintTool::current().set_brush(brush);
     }
   else if (event.id == CL_MOUSE_MIDDLE)
     {
@@ -134,9 +134,9 @@
           CL_Display::draw_rect(rect, CL_Color(0,0,0,128));
         }
 
-      if (TileMapPaintTool::current()->get_brush().get_width() == 1
-          && TileMapPaintTool::current()->get_brush().get_height() == 1
-          && TileMapPaintTool::current()->get_brush().at(0, 0) == i)
+      if (TileMapPaintTool::current().get_brush().get_width() == 1
+          && TileMapPaintTool::current().get_brush().get_height() == 1
+          && TileMapPaintTool::current().get_brush().at(0, 0) == i)
         {
           CL_Display::fill_rect(rect,
                                 CL_Color(0,0,255, 100));

Modified: trunk/src/tilemap_paint_tool.cxx
===================================================================
--- trunk/src/tilemap_paint_tool.cxx    2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_paint_tool.cxx    2004-05-29 18:53:43 UTC (rev 363)
@@ -22,6 +22,7 @@
 #include <ClanLib/Display/keyboard.h>
 #include <ClanLib/Display/keys.h>
 #include <ClanLib/Display/display.h>
+
 #include "globals.hxx"
 #include "tilemap_layer.hxx"
 #include "tileset.hxx"
@@ -32,23 +33,46 @@
 #include "workspace.hxx"
 #include "paint_command.hxx"
 #include "editor_names.hxx"
+#include "tile_selection.hxx"
+#include "tool_impl.hxx"
 #include "tilemap_paint_tool.hxx"
 
-TileMapPaintTool* TileMapPaintTool::current_ = 0; 
+TileMapPaintTool TileMapPaintTool::current_;
 
+class TileMapPaintToolImpl : public ToolImpl
+{
+public:
+  enum { PAINTING, SELECTING, NONE } mode;
+
+  TileSelection selection;
+  TileBrush brush;
+  CL_Point last_draw;
+  CL_Point current_tile;
+
+  PaintCommand* command;
+
+  void draw();
+
+  void on_mouse_down(const CL_InputEvent& event);
+  void on_mouse_move(const CL_InputEvent& event);
+  void on_mouse_up  (const CL_InputEvent& event);
+};
+
 TileMapPaintTool::TileMapPaintTool()
+  : impl(new TileMapPaintToolImpl())
 {
-  last_draw = CL_Point(-1, -1);
+  impl->last_draw = CL_Point(-1, -1);
 
-  current_  = this;
-  brush = TileBrush(1, 1);
-  brush.at(0, 0) = 0;
-  brush.set_opaque();
-  current_tile = CL_Point(0,0);
+  current_  = *this;
+  
+  impl->brush = TileBrush(1, 1);
+  impl->brush.at(0, 0) = 0;
+  impl->brush.set_opaque();
+  impl->current_tile = CL_Point(0,0);
 
-  command = 0;
+  impl->command = 0;
 
-  mode = NONE;
+  impl->mode = TileMapPaintToolImpl::NONE;
 }
 
 TileMapPaintTool::~TileMapPaintTool()
@@ -56,7 +80,7 @@
 }
 
 void
-TileMapPaintTool::draw()
+TileMapPaintToolImpl::draw()
 {
   TilemapLayer tilemap = TilemapLayer::current();
 
@@ -65,7 +89,7 @@
 
   switch(mode)
     {
-    case SELECTING:
+    case TileMapPaintToolImpl::SELECTING:
       if (CL_Keyboard::get_keycode(CL_KEY_LSHIFT))
         selection.draw(CL_Color(255,  128, 128, 100));
       else 
@@ -112,8 +136,14 @@
     }
 }
 
+const TileBrush& 
+TileMapPaintTool::get_brush() 
+{
+  return impl->brush; 
+}
+
 void
-TileMapPaintTool::on_mouse_down(const CL_InputEvent& event)
+TileMapPaintToolImpl::on_mouse_down(const CL_InputEvent& event)
 {
   TilemapLayer tilemap = TilemapLayer::current();
 
@@ -124,11 +154,11 @@
 
       switch (mode)
         {
-        case NONE:
+        case TileMapPaintToolImpl::NONE:
           switch (event.id)
             {
             case CL_MOUSE_LEFT:
-              mode = PAINTING;
+              mode = TileMapPaintToolImpl::PAINTING;
               parent->capture_mouse();
               command = new PaintCommand(tilemap, brush);
               command->add_point(pos);
@@ -136,7 +166,7 @@
               break;
     
             case CL_MOUSE_RIGHT:
-              mode = SELECTING;
+              mode = TileMapPaintToolImpl::SELECTING;
               parent->capture_mouse();
 
               selection.start(tilemap, pos);
@@ -151,7 +181,7 @@
 }
  
 void
-TileMapPaintTool::on_mouse_move(const CL_InputEvent& event)
+TileMapPaintToolImpl::on_mouse_move(const CL_InputEvent& event)
 {
   TilemapLayer tilemap = TilemapLayer::current();
 
@@ -181,7 +211,7 @@
 }
 
 void
-TileMapPaintTool::on_mouse_up  (const CL_InputEvent& event)
+TileMapPaintToolImpl::on_mouse_up  (const CL_InputEvent& event)
 {
   TilemapLayer tilemap = TilemapLayer::current();
 
@@ -239,7 +269,13 @@
 void
 TileMapPaintTool::set_brush(const TileBrush& b)
 {
-  brush = b;
+  impl->brush = b;
 }
 
+Tool
+TileMapPaintTool::to_tool()
+{ 
+  return Tool(impl);
+}
+
 /* EOF */

Modified: trunk/src/tilemap_paint_tool.hxx
===================================================================
--- trunk/src/tilemap_paint_tool.hxx    2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_paint_tool.hxx    2004-05-29 18:53:43 UTC (rev 363)
@@ -20,41 +20,29 @@
 #ifndef HEADER_TILEMAP_PAINT_TOOL_HXX
 #define HEADER_TILEMAP_PAINT_TOOL_HXX
 
+#include "tool.hxx"
 #include "tile_brush.hxx"
-#include "tile_selection.hxx"
-#include "tilemap_tool.hxx"
 #include "tilemap_layer.hxx"
 
-class PaintCommand;
+class TileMapPaintToolImpl;
 
 /** */
-class TileMapPaintTool : public TileMapTool
+class TileMapPaintTool
 {
 private:
-  enum { PAINTING, SELECTING, NONE } mode;
-
-  TileSelection selection;
-  TileBrush brush;
-  CL_Point last_draw;
-  CL_Point current_tile;
-
-  PaintCommand* command;
-
-  static TileMapPaintTool* current_; 
+  static TileMapPaintTool current_; 
 public:
-  static TileMapPaintTool* current() { return current_; } 
+  static TileMapPaintTool current() { return current_; } 
 
   TileMapPaintTool();
-  virtual ~TileMapPaintTool();
+  ~TileMapPaintTool();
   
-  const TileBrush& get_brush() { return brush; }
+  const TileBrush& get_brush();
   void set_brush(const TileBrush& b);
-  void draw();
 
+  Tool to_tool();
 private:
-  void on_mouse_down(const CL_InputEvent& event);
-  void on_mouse_move(const CL_InputEvent& event);
-  void on_mouse_up  (const CL_InputEvent& event);
+  SharedPtr<TileMapPaintToolImpl> impl;
 };
 
 #endif

Modified: trunk/src/tilemap_select_tool.cxx
===================================================================
--- trunk/src/tilemap_select_tool.cxx   2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_select_tool.cxx   2004-05-29 18:53:43 UTC (rev 363)
@@ -22,15 +22,30 @@
 #include <ClanLib/Display/input_event.h>
 #include "globals.hxx"
 #include "tilemap_layer.hxx"
+#include "tool_impl.hxx"
 #include "editor_map.hxx"
 #include "editor_map_component.hxx"
 #include "tile_brush.hxx"
 #include "editor_names.hxx"
 #include "tilemap_select_tool.hxx"
 
+class TileMapSelectToolImpl : public ToolImpl
+{
+public:
+  TileSelection  selection;
+  bool creating_selection;
+
+  void draw();
+  
+  void on_mouse_up  (const CL_InputEvent& event);
+  void on_mouse_down(const CL_InputEvent& event);
+  void on_mouse_move(const CL_InputEvent& event);
+};
+
 TileMapSelectTool::TileMapSelectTool()
+  : impl(new TileMapSelectToolImpl())
 {
-  creating_selection = false;
+  impl->creating_selection = false;
 }
 
 TileMapSelectTool::~TileMapSelectTool()
@@ -38,7 +53,7 @@
 }
 
 void
-TileMapSelectTool::draw()
+TileMapSelectToolImpl::draw()
 {
   if (selection.is_active())
     {
@@ -47,7 +62,7 @@
 }
 
 void
-TileMapSelectTool::on_mouse_up  (const CL_InputEvent& event)
+TileMapSelectToolImpl::on_mouse_up  (const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -63,7 +78,7 @@
 }
 
 void
-TileMapSelectTool::on_mouse_down(const CL_InputEvent& event)
+TileMapSelectToolImpl::on_mouse_down(const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -86,7 +101,7 @@
 }
 
 void
-TileMapSelectTool::on_mouse_move(const CL_InputEvent& event)
+TileMapSelectToolImpl::on_mouse_move(const CL_InputEvent& event)
 { 
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -100,7 +115,13 @@
 TileMapSelectTool::get_selection() const
 {
   TilemapLayer tilemap = TilemapLayer::current();
-  return selection.get_brush(*tilemap.get_field());
+  return impl->selection.get_brush(*tilemap.get_field());
 }
 
+Tool
+TileMapSelectTool::to_tool()
+{
+  return Tool(impl); 
+}
+
 /* EOF */

Modified: trunk/src/tilemap_select_tool.hxx
===================================================================
--- trunk/src/tilemap_select_tool.hxx   2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_select_tool.hxx   2004-05-29 18:53:43 UTC (rev 363)
@@ -22,32 +22,24 @@
 
 #include <ClanLib/Core/Math/rect.h>
 #include <ClanLib/Core/Math/point.h>
+#include "tool.hxx"
 #include "tile_selection.hxx"
-#include "tilemap_tool.hxx"
 
+class TileMapSelectToolImpl;
+
 /** */
-class TileMapSelectTool : public TileMapTool
+class TileMapSelectTool
 {
-private:
-  TileSelection  selection;
-  bool creating_selection;
-
 public:
   TileMapSelectTool();
   ~TileMapSelectTool();
 
-  void draw();
-  
-  void on_mouse_up  (const CL_InputEvent& event);
-  void on_mouse_down(const CL_InputEvent& event);
-  void on_mouse_move(const CL_InputEvent& event);
-
   /** Convert the selection into a TileBrush */
   TileBrush get_selection() const;
 
+  Tool to_tool();
 private:
-  TileMapSelectTool (const TileMapSelectTool&);
-  TileMapSelectTool& operator= (const TileMapSelectTool&);
+  SharedPtr<TileMapSelectToolImpl> impl;
 };
 
 #endif

Deleted: trunk/src/tilemap_tool.cxx
===================================================================
--- trunk/src/tilemap_tool.cxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_tool.cxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -1,24 +0,0 @@
-//  $Id: tilemap_tool.cxx,v 1.1 2003/09/23 19:10:05 grumbel Exp $
-//
-//  Flexlay - A Generic 2D Game Editor
-//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-//
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#include "tilemap_tool.hxx"
-
-
-
-/* EOF */

Deleted: trunk/src/tilemap_tool.hxx
===================================================================
--- trunk/src/tilemap_tool.hxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tilemap_tool.hxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -1,48 +0,0 @@
-//  $Id: tilemap_tool.hxx,v 1.1 2003/09/23 19:10:05 grumbel Exp $
-// 
-//  Flexlay - A Generic 2D Game Editor
-//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
-//
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
-//
-//  This program is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//  GNU General Public License for more details.
-// 
-//  You should have received a copy of the GNU General Public License
-//  along with this program; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
-#ifndef HEADER_TILEMAP_TOOL_HXX
-#define HEADER_TILEMAP_TOOL_HXX
-
-class EditorMapComponent;
-class CL_InputEvent;
-
-/** */
-class TileMapTool
-{
-protected:
-
-public:
-  TileMapTool() {}
-  virtual ~TileMapTool() {}
-
-  virtual void draw() {}
-
-  virtual void on_mouse_up  (const CL_InputEvent& event) {}
-  virtual void on_mouse_down(const CL_InputEvent& event) {}
-  virtual void on_mouse_move(const CL_InputEvent& event) {}
-
-private:
-  TileMapTool (const TileMapTool&);
-  TileMapTool& operator= (const TileMapTool&);
-};
-
-#endif
-
-/* EOF */

Copied: trunk/src/tool.cxx (from rev 342, trunk/src/tilemap_tool.cxx)
===================================================================
--- trunk/src/tilemap_tool.cxx  2004-05-18 19:35:22 UTC (rev 342)
+++ trunk/src/tool.cxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -0,0 +1,60 @@
+//  $Id: tilemap_tool.cxx,v 1.1 2003/09/23 19:10:05 grumbel Exp $
+//
+//  Flexlay - A Generic 2D Game Editor
+//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#include "tool_impl.hxx"
+#include "tool.hxx"
+
+Tool::Tool(SharedPtr<ToolImpl> impl_)
+  : impl(impl_)
+{
+}
+
+Tool::~Tool() 
+{
+}
+
+void
+Tool::draw()
+{
+  if (impl.get())
+    impl->draw();
+}
+
+void
+Tool::on_mouse_up  (const CL_InputEvent& event)
+{
+  if (impl.get())
+    impl->on_mouse_up(event);
+}
+
+void
+Tool::on_mouse_down(const CL_InputEvent& event)
+{
+  if (impl.get())
+    impl->on_mouse_down(event);
+}
+
+void
+Tool::on_mouse_move(const CL_InputEvent& event)
+{
+  if (impl.get())
+    impl->on_mouse_move(event);
+}
+
+/* EOF */

Copied: trunk/src/tool.hxx (from rev 342, trunk/src/tilemap_tool.hxx)
===================================================================
--- trunk/src/tilemap_tool.hxx  2004-05-18 19:35:22 UTC (rev 342)
+++ trunk/src/tool.hxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -0,0 +1,51 @@
+//  $Id: tilemap_tool.hxx,v 1.1 2003/09/23 19:10:05 grumbel Exp $
+// 
+//  Flexlay - A Generic 2D Game Editor
+//  Copyright (C) 2002 Ingo Ruhnke <address@hidden>
+//
+//  This program is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU General Public License
+//  as published by the Free Software Foundation; either version 2
+//  of the License, or (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+// 
+//  You should have received a copy of the GNU General Public License
+//  along with this program; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+#ifndef HEADER_TILEMAP_TOOL_HXX
+#define HEADER_TILEMAP_TOOL_HXX
+
+class EditorMapComponent;
+class CL_InputEvent;
+
+#include "shared_ptr.hxx"
+
+class ToolImpl;
+
+/** */
+class Tool
+{
+protected:
+
+public:
+  Tool(SharedPtr<ToolImpl> impl_);
+  ~Tool();
+
+  void draw();
+
+  void on_mouse_up  (const CL_InputEvent& event);
+  void on_mouse_down(const CL_InputEvent& event);
+  void on_mouse_move(const CL_InputEvent& event);
+
+private:
+  SharedPtr<ToolImpl> impl;
+};
+
+#endif
+
+/* EOF */

Modified: trunk/src/tool_manager.cxx
===================================================================
--- trunk/src/tool_manager.cxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tool_manager.cxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -29,19 +29,18 @@
 ToolManager::ToolManager()
 {
   // FIXME: move this to scripting too
-  tools.push_back(new TileMapPaintTool  ());
-  tools.push_back(new TileMapSelectTool ());
-  tools.push_back(0); //new TileMapDiamondTool());
-  tools.push_back(new ObjMapSelectTool  ());
-  tools.push_back(new ZoomTool());
+  tools.push_back(TileMapPaintTool().to_tool());
+  tools.push_back(TileMapSelectTool().to_tool());
+  //tools.push_back(Tool()); //new TileMapDiamondTool());
+  tools.push_back(ObjMapSelectTool().to_tool());
+  tools.push_back(ZoomTool().to_tool());
 
-  tool = tools[0]; 
+  //tool = tools[0]; 
+  tool = 0;
 }
 
 ToolManager::~ToolManager()
 {
-  for(Tools::iterator i = tools.begin(); i != tools.end(); ++i)
-    delete *i;
 }
 
 void
@@ -49,10 +48,10 @@
 {
   if (i >= 0 && i < int(tools.size()))
     {
-      if (tool != tools[i])
+      if (tool != i)
         {
           on_tool_change();
-          tool = tools[i];
+          tool = i;
         }
     }
   else
@@ -61,19 +60,16 @@
     }
 }
 
-TileMapTool*
-ToolManager::get_tool_by_name(int i)
-{
-  if (i >= 0 && i < static_cast<int>(tools.size()))
-    return tools[i];
-  else
-    return 0;  
-}
-
 CL_Signal_v0&
 ToolManager::sig_tool_change()
 {
   return on_tool_change;
 }
 
+Tool
+ToolManager::current_tool()
+{
+  return tools[tool]; 
+}
+
 /* EOF */

Modified: trunk/src/tool_manager.hxx
===================================================================
--- trunk/src/tool_manager.hxx  2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/tool_manager.hxx  2004-05-29 18:53:43 UTC (rev 363)
@@ -21,18 +21,17 @@
 #define HEADER_TOOL_MANAGER_HXX
 
 #include <vector>
+#include "tool.hxx"
 
-class TileMapTool;
-
 /** The ToolManager is a simple class which holds all available tools
     and keep track of which on is the currently selected one. */
 class ToolManager
 {
 private:
-  typedef std::vector<TileMapTool*> Tools;
+  typedef std::vector<Tool> Tools;
   Tools tools;
 
-  TileMapTool* tool;
+  int tool;
   CL_Signal_v0 on_tool_change;
 public:
   ToolManager();
@@ -40,8 +39,7 @@
 
   // random stuff
   void set_tool(int i);
-  TileMapTool* get_tool_by_name(int i);
-  TileMapTool* current_tool() { return tool; }
+  Tool current_tool();
 
   CL_Signal_v0& sig_tool_change();
 };

Modified: trunk/src/workspace.cxx
===================================================================
--- trunk/src/workspace.cxx     2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/workspace.cxx     2004-05-29 18:53:43 UTC (rev 363)
@@ -24,7 +24,7 @@
 #include "editor_map.hxx"
 #include "editor_map_component.hxx"
 #include "editor_names.hxx"
-#include "tilemap_tool.hxx"
+#include "tool.hxx"
 #include "tileset.hxx"
 #include "tool_manager.hxx"
 #include "workspace.hxx"
@@ -70,7 +70,7 @@
   impl->editor_map.draw(EditorMapComponent::current());
   
   if (1) // has_mouse_over()) FIXME: Seperate cursor and state here
-    Editor::current()->get_tool_manager()->current_tool()->draw();
+    Editor::current()->get_tool_manager()->current_tool().draw();
     
   CL_Display::flush();
 
@@ -84,7 +84,7 @@
     {
     case CL_MOUSE_LEFT:
     case CL_MOUSE_RIGHT:
-      
Editor::current()->get_tool_manager()->current_tool()->on_mouse_up(event);
+      Editor::current()->get_tool_manager()->current_tool().on_mouse_up(event);
       break;
 
     case CL_MOUSE_MIDDLE:
@@ -102,7 +102,7 @@
 void
 Workspace::mouse_move(const CL_InputEvent& event)
 {
-  Editor::current()->get_tool_manager()->current_tool()->on_mouse_move(event);
+  Editor::current()->get_tool_manager()->current_tool().on_mouse_move(event);
 
   if (impl->scrolling)
     {
@@ -120,7 +120,7 @@
     {
     case CL_MOUSE_LEFT:
     case CL_MOUSE_RIGHT:
-      
Editor::current()->get_tool_manager()->current_tool()->on_mouse_down(event);
+      
Editor::current()->get_tool_manager()->current_tool().on_mouse_down(event);
       break;
 
     case CL_MOUSE_MIDDLE:

Modified: trunk/src/zoom_tool.cxx
===================================================================
--- trunk/src/zoom_tool.cxx     2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/zoom_tool.cxx     2004-05-29 18:53:43 UTC (rev 363)
@@ -20,11 +20,27 @@
 #include <ClanLib/Display/keys.h>
 #include <ClanLib/Display/display.h>
 #include "editor_map_component.hxx"
+#include "tool_impl.hxx"
 #include "zoom_tool.hxx"
 
+class ZoomToolImpl : public ToolImpl
+{
+public:
+  enum { CREATE_ZOOM_RECT, NONE } state;
+
+  CL_Rect zoom_rect;
+
+  void draw();
+  
+  void on_mouse_up  (const CL_InputEvent& event);
+  void on_mouse_down(const CL_InputEvent& event);
+  void on_mouse_move(const CL_InputEvent& event);
+};
+
 ZoomTool::ZoomTool()
+  : impl(new ZoomToolImpl())
 {
-  state = NONE;
+  impl->state = ZoomToolImpl::NONE;
 }
 
 ZoomTool::~ZoomTool()
@@ -32,7 +48,7 @@
 }
 
 void
-ZoomTool::draw()
+ZoomToolImpl::draw()
 {
   switch (state)
     {
@@ -49,7 +65,7 @@
 }
 
 void
-ZoomTool::on_mouse_up  (const CL_InputEvent& event)
+ZoomToolImpl::on_mouse_up  (const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -81,7 +97,7 @@
 }
 
 void
-ZoomTool::on_mouse_down(const CL_InputEvent& event)
+ZoomToolImpl::on_mouse_down(const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -122,7 +138,7 @@
 }
 
 void
-ZoomTool::on_mouse_move(const CL_InputEvent& event)
+ZoomToolImpl::on_mouse_move(const CL_InputEvent& event)
 {
   EditorMapComponent* parent = EditorMapComponent::current();
 
@@ -140,4 +156,10 @@
     }
 }
 
+Tool
+ZoomTool::to_tool()
+{
+  return Tool(impl); 
+}  
+
 /* EOF */

Modified: trunk/src/zoom_tool.hxx
===================================================================
--- trunk/src/zoom_tool.hxx     2004-05-29 16:42:05 UTC (rev 362)
+++ trunk/src/zoom_tool.hxx     2004-05-29 18:53:43 UTC (rev 363)
@@ -22,28 +22,20 @@
 
 #include <ClanLib/Core/Math/rect.h>
 #include <ClanLib/Display/input_event.h>
-#include "tilemap_tool.hxx"
+#include "tool.hxx"
 
+class ZoomToolImpl;
+
 /** */
-class ZoomTool : public TileMapTool
+class ZoomTool
 {
-private:
-  enum { CREATE_ZOOM_RECT, NONE } state;
-
-  CL_Rect zoom_rect;
 public:
   ZoomTool();
   ~ZoomTool();
-  
-  void draw();
 
+  Tool to_tool();
 private:
-  void on_mouse_up  (const CL_InputEvent& event);
-  void on_mouse_down(const CL_InputEvent& event);
-  void on_mouse_move(const CL_InputEvent& event);
- 
-  ZoomTool (const ZoomTool&);
-  ZoomTool& operator= (const ZoomTool&);
+  SharedPtr<ZoomToolImpl> impl;
 };
 
 #endif





reply via email to

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