[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Windstille-devel] rev 358 - trunk/src
From: |
Ingo Ruhnke |
Subject: |
[Windstille-devel] rev 358 - trunk/src |
Date: |
Sat, 29 May 2004 00:55:42 +0200 |
Author: grumbel
Date: 2004-05-29 00:55:42 +0200 (Sat, 29 May 2004)
New Revision: 358
Modified:
trunk/src/editor.cxx
trunk/src/editor.hxx
trunk/src/editor.py
trunk/src/editor_map.cxx
trunk/src/editor_map.hxx
trunk/src/editor_map_component.cxx
trunk/src/minimap.cxx
trunk/src/object_selector.cxx
trunk/src/objmap_select_tool.cxx
trunk/src/simpleed.cxx
trunk/src/tilemap_paint_tool.cxx
trunk/src/workspace.cxx
trunk/src/workspace.hxx
Log:
- moved undo/redo to document level
- hooked up undo/redo to gui
Modified: trunk/src/editor.cxx
===================================================================
--- trunk/src/editor.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -24,7 +24,6 @@
#include <ClanLib/guistylesilver.h>
#include "gui_manager.hxx"
-#include "command.hxx"
#include "editor.hxx"
#include "editor_map.hxx"
#include "tile_selector.hxx"
@@ -58,40 +57,4 @@
std::cout << "Starting GUI manager busy loop... done" << std::endl;
}
-void
-Editor::execute(Command command)
-{
- redo_stack.clear();
-
- command.execute();
-
- //std::cout << command->serialize() << std::endl;
-
- undo_stack.push_back(command);
-}
-
-void
-Editor::undo()
-{
- if (!undo_stack.empty())
- {
- Command command = undo_stack.back();
- undo_stack.pop_back();
- command.undo();
- redo_stack.push_back(command);
- }
-}
-
-void
-Editor::redo()
-{
- if (!redo_stack.empty())
- {
- Command command = redo_stack.back();
- redo_stack.pop_back();
- command.redo();
- undo_stack.push_back(command);
- }
-}
-
/* EOF */
Modified: trunk/src/editor.hxx
===================================================================
--- trunk/src/editor.hxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor.hxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -26,21 +26,14 @@
class ToolManager;
class EditorMap;
class GUIManager;
-class Command;
/** */
class Editor
{
private:
GUIManager* manager;
-
ToolManager* tool_manager;
- typedef std::vector<Command> Commands;
-
- Commands undo_stack;
- Commands redo_stack;
-
static Editor* current_;
public:
static Editor* current() { return current_; }
@@ -53,18 +46,6 @@
void run();
- // FIXME: Move undo stuff to EditorMap or some other per map class
-
- /** Execute a command and place it on the undo stack, commands given
- to this function will be deleted by the Editor class, so they
- have to be new'ed */
- void execute(Command command);
-
- /** Move backward in the undo stack */
- void undo();
-
- /** Move forward in the undo stack */
- void redo();
private:
Editor (const Editor&);
Editor& operator= (const Editor&);
Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor.py 2004-05-28 22:55:42 UTC (rev 358)
@@ -17,6 +17,7 @@
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+import sys
from flexlay import *
from supertux import *
@@ -32,7 +33,7 @@
editor_map.set_workspace(workspace)
m = EditorMap()
-workspace.set_current_map(m)
+workspace.set_map(m)
tileset = load_supertux_tiles()
tilemap = TilemapLayer(tileset, 200, 15)
@@ -53,7 +54,7 @@
_.add_point(CL_Point(2,2))
_.add_point(CL_Point(3,3))
_.add_point(CL_Point(4,4))
- _.execute()
+ m.execute(_.to_command())
print "Draw something done"
window = Window(CL_Rect(50, 50, 450, 400), "My Window", gui.get_component())
@@ -101,8 +102,8 @@
undo_icon = Icon(CL_Point(32*5.1+2, 2),
make_sprite("../data/images/icons24/stock_undo.png"), "Some tooltip", willow);
redo_icon = Icon(CL_Point(32*6.1+2, 2),
make_sprite("../data/images/icons24/stock_redo.png"), "Some tooltip", willow);
-undo_icon.set_callback(do_something)
-redo_icon.set_callback(do_something)
+undo_icon.set_callback(m.undo)
+redo_icon.set_callback(m.redo)
toolbar = Panel(CL_Rect(CL_Point(0, 23+33), CL_Size(33, 256)),
gui.get_component())
Modified: trunk/src/editor_map.cxx
===================================================================
--- trunk/src/editor_map.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor_map.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -44,6 +44,11 @@
/** Metadata attached to this map (ie. mapname, description, scripts, etc.)
*/
MetaData metadata;
+
+ typedef std::vector<Command> Commands;
+
+ Commands undo_stack;
+ Commands redo_stack;
};
EditorMap::EditorMap()
@@ -159,4 +164,36 @@
impl-> background_color = color;
}
+void
+EditorMap::execute(Command command)
+{
+ impl->redo_stack.clear();
+ command.execute();
+ impl->undo_stack.push_back(command);
+}
+
+void
+EditorMap::undo()
+{
+ if (!impl->undo_stack.empty())
+ {
+ Command command = impl->undo_stack.back();
+ impl->undo_stack.pop_back();
+ command.undo();
+ impl->redo_stack.push_back(command);
+ }
+}
+
+void
+EditorMap::redo()
+{
+ if (!impl->redo_stack.empty())
+ {
+ Command command = impl->redo_stack.back();
+ impl->redo_stack.pop_back();
+ command.redo();
+ impl->undo_stack.push_back(command);
+ }
+}
+
/* EOF */
Modified: trunk/src/editor_map.hxx
===================================================================
--- trunk/src/editor_map.hxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor_map.hxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -28,7 +28,9 @@
#include "object_layer.hxx"
#include "tilemap_layer.hxx"
#include "layer.hxx"
+#include "command.hxx"
+class Command;
class EditorMapComponent;
class EditorMapImpl;
class TileMapTool;
@@ -60,6 +62,16 @@
void set_background_color(const CL_Color& color);
+ /** Execute a command and place it on the undo stack, commands given
+ to this function will be deleted by the Editor class, so they
+ have to be new'ed */
+ void execute(Command command);
+
+ /** Move backward in the undo stack */
+ void undo();
+
+ /** Move forward in the undo stack */
+ void redo();
private:
CL_SharedPtr<EditorMapImpl> impl;
};
Modified: trunk/src/editor_map_component.cxx
===================================================================
--- trunk/src/editor_map_component.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/editor_map_component.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -97,11 +97,11 @@
EditorMapComponent::draw ()
{
// Update scrollbars (FIXME: move me to function)
- scrollbar_v->set_range(0,
workspace.get_current_map().get_bounding_rect().get_height());
+ scrollbar_v->set_range(0,
workspace.get_map().get_bounding_rect().get_height());
scrollbar_v->set_pagesize(get_height()/workspace.get_gc_state().get_zoom());
scrollbar_v->set_pos(workspace.get_gc_state().get_pos().y);
- scrollbar_h->set_range(0,
workspace.get_current_map().get_bounding_rect().get_width());
+ scrollbar_h->set_range(0,
workspace.get_map().get_bounding_rect().get_width());
scrollbar_h->set_pagesize(get_width()/workspace.get_gc_state().get_zoom());
scrollbar_h->set_pos(workspace.get_gc_state().get_pos().x);
Modified: trunk/src/minimap.cxx
===================================================================
--- trunk/src/minimap.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/minimap.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -64,12 +64,12 @@
Minimap::draw()
{
// FIXME: Do this only on map changes
- if (impl->last_serial !=
impl->parent->get_workspace().get_current_map().get_serial())
- // || editor_map != parent->get_workspace().get_current_map())
+ if (impl->last_serial !=
impl->parent->get_workspace().get_map().get_serial())
+ // || editor_map != parent->get_workspace().get_map())
{
impl->update_minimap_surface();
- impl->last_serial =
impl->parent->get_workspace().get_current_map().get_serial();
- impl->editor_map = impl->parent->get_workspace().get_current_map();
+ impl->last_serial = impl->parent->get_workspace().get_map().get_serial();
+ impl->editor_map = impl->parent->get_workspace().get_map();
}
if (0)
Modified: trunk/src/object_selector.cxx
===================================================================
--- trunk/src/object_selector.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/object_selector.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -87,7 +87,7 @@
drag_obj.data,
drag_obj.sprite);
ObjectAddCommand command(objmap, obj);
- Editor::current()->execute(command.to_command());
+ Workspace::current().get_map().execute(command.to_command());
}
drag_obj.sprite = CL_Sprite();
}
Modified: trunk/src/objmap_select_tool.cxx
===================================================================
--- trunk/src/objmap_select_tool.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/objmap_select_tool.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -83,7 +83,7 @@
case DRAG:
if (move_command)
{
- Editor::current()->execute(move_command->to_command());
+
Workspace::current().get_map().execute(move_command->to_command());
move_command = 0;
}
state = NONE;
Modified: trunk/src/simpleed.cxx
===================================================================
--- trunk/src/simpleed.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/simpleed.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -54,7 +54,7 @@
EditorMapComponent editor_map(CL_Rect(0, 0, 799, 599), gui->get_component());
Workspace workspace(799, 599);
editor_map.set_workspace(workspace);
- workspace.set_current_map(m);
+ workspace.set_map(m);
new CL_Button(CL_Rect(CL_Point(50, 150),
CL_Size(100, 25)),
Modified: trunk/src/tilemap_paint_tool.cxx
===================================================================
--- trunk/src/tilemap_paint_tool.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/tilemap_paint_tool.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -182,7 +182,7 @@
{
if (!tilemap.is_null())
{
-
EditorMapComponent::current()->get_workspace().get_current_map().modify();
+ EditorMapComponent::current()->get_workspace().get_map().modify();
EditorMapComponent* parent = EditorMapComponent::current();
CL_Point pos = tilemap.world2tile(parent->screen2world(event.mouse_pos));
@@ -196,7 +196,7 @@
mode = NONE;
command->add_point(pos);
- Editor::current()->execute(command->to_command());
+ Workspace::current().get_map().execute(command->to_command());
command = 0;
tilemap.draw_tile(brush, pos);
Modified: trunk/src/workspace.cxx
===================================================================
--- trunk/src/workspace.cxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/workspace.cxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -29,7 +29,7 @@
#include "tool_manager.hxx"
#include "workspace.hxx"
-Workspace* Workspace::current_ = 0;
+Workspace Workspace::current_;
class WorkspaceImpl
{
@@ -45,10 +45,14 @@
EditorMap editor_map;
};
+Workspace::Workspace()
+{
+}
+
Workspace::Workspace(int w, int h)
: impl(new WorkspaceImpl())
{
- current_ = this;
+ current_ = *this;
impl->gc_state = GraphicContextState(w, h);
impl->scrolling = false;
@@ -137,13 +141,13 @@
}
EditorMap
-Workspace::get_current_map()
+Workspace::get_map()
{
return impl->editor_map;
}
void
-Workspace::set_current_map(EditorMap m)
+Workspace::set_map(EditorMap m)
{
impl->editor_map = m;
}
Modified: trunk/src/workspace.hxx
===================================================================
--- trunk/src/workspace.hxx 2004-05-28 21:54:21 UTC (rev 357)
+++ trunk/src/workspace.hxx 2004-05-28 22:55:42 UTC (rev 358)
@@ -31,11 +31,12 @@
class Workspace
{
private:
- static Workspace* current_;
+ static Workspace current_;
public:
- static void set_current(Workspace* w) { current_ = w; }
- static Workspace* current() { return current_; }
+ static void set_current(Workspace w) { current_ = w; }
+ static Workspace current() { return current_; }
+ Workspace();
Workspace(int w, int h);
void draw();
@@ -44,8 +45,8 @@
void mouse_down(const CL_InputEvent& event);
void mouse_move(const CL_InputEvent& event);
- EditorMap get_current_map();
- void set_current_map(EditorMap m);
+ EditorMap get_map();
+ void set_map(EditorMap m);
GraphicContextState& get_gc_state();
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Windstille-devel] rev 358 - trunk/src,
Ingo Ruhnke <=