[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Windstille-devel] rev 331 - in trunk/src: . scripting
From: |
Ingo Ruhnke |
Subject: |
[Windstille-devel] rev 331 - in trunk/src: . scripting |
Date: |
Sat, 15 May 2004 22:26:26 +0200 |
Author: grumbel
Date: 2004-05-15 22:26:26 +0200 (Sat, 15 May 2004)
New Revision: 331
Added:
trunk/src/layer.cxx
trunk/src/layer.hxx
trunk/src/layer_impl.hxx
trunk/src/tilemap_layer.cxx
trunk/src/tilemap_layer.hxx
Removed:
trunk/src/tilemap.cxx
trunk/src/tilemap.hxx
Modified:
trunk/src/SConstruct
trunk/src/clanlib.i
trunk/src/editor.py
trunk/src/editor_map.cxx
trunk/src/editor_map.hxx
trunk/src/editor_map_component.hxx
trunk/src/editor_map_layer.hxx
trunk/src/flexlay.i
trunk/src/minimap.cxx
trunk/src/paint_command.cxx
trunk/src/paint_command.hxx
trunk/src/scripting/editor.cxx
trunk/src/scripting/editor.hxx
trunk/src/tile.cxx
trunk/src/tile_selection.cxx
trunk/src/tile_selection.hxx
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/tileset.cxx
trunk/src/tileset.hxx
trunk/src/tool_manager.cxx
Log:
- stuff
Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/SConstruct 2004-05-15 20:26:26 UTC (rev 331)
@@ -17,10 +17,10 @@
'tile_brush.hxx',
'editor.hxx',
'editor_map_layer.hxx',
- 'tilemap.hxx',
'editor_map.hxx',
'workspace.hxx',
'tileset.hxx',
+ 'editor_map.hxx',
'editor_map_component.hxx',
'flexlay.hxx',
'globals.hxx',
@@ -34,18 +34,20 @@
env.SharedLibrary(
target = '_flexlay.so',
source = [
+ 'blitter.cxx',
'flexlay_wrap.cxx',
'command_group.cxx',
'editor.cxx',
'scripting/editor.cxx',
'editor_grid_layer.cxx',
'editor_map.cxx',
+ 'editor_map_layer.cxx',
'editor_map_component.cxx',
'editor_mapsize_layer.cxx',
'editor_objmap.cxx',
- 'tilemap.cxx',
'flexlay.cxx',
'globals.cxx',
+ 'layer.cxx',
'graphic_context_state.cxx',
'gui_manager.cxx',
'minimap.cxx',
@@ -73,6 +75,7 @@
'tilemap_paint_tool.cxx',
'tilemap_select_tool.cxx',
'tilemap_tool.cxx',
+ 'tilemap_layer.cxx',
'tileset.cxx',
'tool_manager.cxx',
'workspace.cxx',
Modified: trunk/src/clanlib.i
===================================================================
--- trunk/src/clanlib.i 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/clanlib.i 2004-05-15 20:26:26 UTC (rev 331)
@@ -61,6 +61,7 @@
const std::string &title,
CL_Component *parent,
CL_StyleManager *style = NULL);
+ CL_Component* get_client_area();
};
class CL_Button : public CL_Component
Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/editor.py 2004-05-15 20:26:26 UTC (rev 331)
@@ -18,7 +18,97 @@
## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
from flexlay import *
+from supertux import *
+supertux_datadir = "/home/ingo/cvs/supertux/supertux/data/"
+
+def assoc_ref(lst, str):
+ if lst == []:
+ return False
+ elif lst[0][0] == str:
+ return lst[0][1:]
+ else:
+ return assoc_ref(lst[1:], str)
+
+def get_value_from_tree(spec, tree, default):
+ if spec == []:
+ return tree
+ elif spec == ['_']:
+ return tree[0]
+ elif tree == []:
+ return default
+ else:
+ el = assoc_ref(tree, spec[0])
+ if el:
+ return get_value_from_tree(spec[1:], el, default)
+ else:
+ return default
+
+def load_game_tiles(tileset, filename):
+ tree = sexpr_read_from_file(filename)
+ tree = tree[1:]
+ for i in tree:
+ if i[0] == "tile":
+ data = i[1:]
+ id = get_value_from_tree(['id', '_'], data, -1)
+ image = get_value_from_tree(['editor-images', '_'], data, False)
+
+ if not(image):
+ image = get_value_from_tree(['images', '_'], data,
"notile.png")
+
+ tileset.add_tile(id,
+ Tile(supertux_datadir + 'images/tilesets/' +
image,
+ CL_Color(255, 255, 255, 255),
+ CL_Color(255, 0, 0, 128)))
+
+class SuperTuxLevel:
+ me = None
+ name = "no name"
+ author = "no author"
+ width = 20
+ height = 15
+
+ foreground = None
+ interactive = None
+ background = None
+
+ editormap = None
+
+ def __init__(self, filename):
+ print "SuperTuxLevel:__init__"
+ self.me = self
+
+ tree = sexpr_read_from_file(filename)
+ data = tree[1:]
+
+ self.name = get_value_from_tree(["name", "_"], data, "no name")
+ self.author = get_value_from_tree(["name", "_"], data, "no author")
+
+ self.width = get_value_from_tree(["width", "_"], data, 20)
+ self.height = get_value_from_tree(["height""_"], data, 15)
+
+ self.foreground = TilemapLayer(tileset, self.width, self.height)
+ self.foreground.set_data(get_value_from_tree(["foreground-tm"], data,
[]))
+
+ self.interactive = TilemapLayer(tileset, self.width, self.height)
+ self.interactive.set_data(get_value_from_tree(["interactive-tm"],
data, []))
+
+ self.background = TilemapLayer(tileset, self.width, self.height)
+ self.background.set_data(get_value_from_tree(["background-tm"], data,
[]))
+
+ self.editormap = EditorMap()
+ self.editormap.add_layer(self.foreground)
+ self.editormap.add_layer(self.interactive)
+ self.editormap.add_layer(self.background)
+
+ def __del__(self):
+ print "SuperTuxLevel:__del__"
+
+ def activate(self, workspace):
+ editor_tilemap_set_current(self.interactive)
+ workspace.set_current_map(self.editormap)
+
+
flexlay = Flexlay()
flexlay.init()
@@ -30,10 +120,10 @@
workspace = Workspace(799, 599)
editor_map.set_workspace(workspace)
-m = EditorMap("Foobar")
+m = EditorMap()
workspace.set_current_map(m)
tileset = Tileset(32)
-tilemap = TileMap(tileset, 20, 10)
+tilemap = TilemapLayer(tileset, 20, 10)
m.add_layer(tilemap)
tile = Tile("/home/ingo/cvs/supertux/supertux/data/images/tilesets/bonus1.png",
CL_Color(255, 255, 255, 255),
@@ -42,6 +132,8 @@
tileset.add_tile(1, tile)
tileset.add_tile(2, tile)
+load_game_tiles(tileset,
"/home/ingo/cvs/supertux/supertux/data/images/tilesets/supertux.stgt")
+
editor_tilemap_set_current(tilemap)
tilemap_paint_tool_set_tilemap(tilemap)
@@ -89,6 +181,11 @@
gui.pop_component()
+tileselectorw = CL_Window(CL_Rect(CL_Point(150, 150), CL_Size(210, 210)),
"Tile Selector", gui.get_component())
+tileselector = TileSelector(5, 3, tileselectorw.get_client_area())
+tileselector.set_tileset(tileset)
+tileselector.set_tiles(range(1,100))
+
class Menu(CL_Menu):
def __init__(self):
CL_Menu.__init__(self, gui.get_component())
@@ -97,8 +194,13 @@
item = self.create_item(name)
connect(item.sig_clicked(), func)
+level = None
def menu_file_open():
print "File/Open"
+ level =
SuperTuxLevel('/home/ingo/cvs/supertux/supertux/data/levels/world1/level2.stl')
+ print "Loading done"
+ level.activate(workspace)
+ print "Activation done"
def menu_file_save():
print "File/Save"
@@ -110,6 +212,8 @@
a = menu.add_item("File/Open...", menu_file_open)
a = menu.add_item("File/Save...", menu_file_save)
a = menu.add_item("File/Save As...", menu_file_save_as)
+
+
gui.run()
flexlay.deinit()
Modified: trunk/src/editor_map.cxx
===================================================================
--- trunk/src/editor_map.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/editor_map.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -25,9 +25,8 @@
#include "editor_map.hxx"
#include "editor_map_component.hxx"
-EditorMap::EditorMap(const std::string& filename_)
- : filename(filename_),
- background_color(100, 80, 100),
+EditorMap::EditorMap()
+ : background_color(100, 80, 100),
foreground_color(255, 80, 255)
{
modified = false;
@@ -36,11 +35,12 @@
EditorMap::~EditorMap()
{
- scripts.clear();
- for(Layers::iterator i = layers.begin(); i != layers.end(); ++i)
+ /*
+ for(Layers::iterator i = layers.begin(); i != layers.end(); ++i)
{
delete (*i);
}
+*/
}
void
@@ -63,12 +63,6 @@
}
EditorMapLayer*
-EditorMap::get_layer_by_name(int i)
-{
- return layers[i];
-}
-
-EditorMapLayer*
EditorMap::get_layer(int i)
{
if (i >= 0 && i < static_cast<int>(layers.size()))
@@ -98,7 +92,7 @@
bool init = false;
CL_Rect rect;
-
+
for(Layers::iterator i = layers.begin(); i != layers.end(); ++i)
{
if ((*i)->has_bounding_rect())
Modified: trunk/src/editor_map.hxx
===================================================================
--- trunk/src/editor_map.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/editor_map.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -26,7 +26,7 @@
#include <ClanLib/Core/Math/point.h>
#include "field.hxx"
#include "editor_objmap.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "editor_map_layer.hxx"
class EditorMapComponent;
@@ -37,8 +37,6 @@
class EditorMap
{
private:
- std::string filename;
-
/** Flag if the map got modified, used for 'Some maps are unsaved'
style massages */
bool modified;
@@ -50,8 +48,6 @@
typedef std::vector<EditorMapLayer*> Layers;
Layers layers;
- std::vector<std::string> scripts;
-
CL_Color background_color;
CL_Color foreground_color;
@@ -60,12 +56,9 @@
SCMObj metadata;
#endif
public:
- EditorMap(const std::string& filename_);
+ EditorMap();
~EditorMap();
- std::string get_filename() const { return filename; }
- void set_filename(const std::string& f) { filename = f; }
-
void draw(EditorMapComponent* parent);
void add_layer(EditorMapLayer* layer);
@@ -76,7 +69,6 @@
int get_serial() const { return serial; }
- EditorMapLayer* get_layer_by_name(int i);
EditorMapLayer* get_layer(int i);
#ifdef SWIGGUILE
@@ -88,8 +80,6 @@
CL_Rect get_bounding_rect();
void set_background_color(const CL_Color& color);
-
- std::vector<std::string> get_scripts() { return scripts; }
};
#endif
Modified: trunk/src/editor_map_component.hxx
===================================================================
--- trunk/src/editor_map_component.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/editor_map_component.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -26,7 +26,6 @@
#include <ClanLib/Core/Math/point.h>
#include "field.hxx"
#include "editor_objmap.hxx"
-#include "tilemap.hxx"
#include "graphic_context_state.hxx"
class Workspace;
Modified: trunk/src/editor_map_layer.hxx
===================================================================
--- trunk/src/editor_map_layer.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/editor_map_layer.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -20,6 +20,8 @@
#ifndef HEADER_EDITOR_MAP_LAYER_HXX
#define HEADER_EDITOR_MAP_LAYER_HXX
+#include <ClanLib/Core/Math/rect.h>
+
class EditorMapComponent;
/** Each \a EditorMap consists out of one or more \a EditorMapLayer,
@@ -30,8 +32,8 @@
class EditorMapLayer
{
public:
- EditorMapLayer() {}
- virtual ~EditorMapLayer() {}
+ EditorMapLayer();
+ virtual ~EditorMapLayer();
virtual void draw(EditorMapComponent* parent) =0;
Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/flexlay.i 2004-05-15 20:26:26 UTC (rev 331)
@@ -17,7 +17,7 @@
#include "tile_brush.hxx"
#include "editor.hxx"
#include "editor_map_layer.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "editor_map.hxx"
#include "workspace.hxx"
#include "tileset.hxx"
@@ -47,7 +47,7 @@
%include "tile_brush.hxx"
%include "editor.hxx"
%include "editor_map_layer.hxx"
-%include "tilemap.hxx"
+%include "tilemap_layer.hxx"
%include "editor_map.hxx"
%include "workspace.hxx"
%include "tileset.hxx"
Added: trunk/src/layer.cxx
===================================================================
--- trunk/src/layer.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/layer.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -0,0 +1,46 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// 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 "layer_impl.hxx"
+#include "layer.hxx"
+
+Layer::Layer()
+ : impl(0)
+{
+}
+
+void
+Layer::draw(EditorMapComponent* parent)
+{
+ impl->draw(parent);
+}
+
+bool
+Layer::has_bounding_rect() const
+{
+ return impl->has_bounding_rect();
+}
+
+CL_Rect
+Layer::get_bounding_rect()
+{
+ return impl->get_bounding_rect();
+}
+
+/* EOF */
Added: trunk/src/layer.hxx
===================================================================
--- trunk/src/layer.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/layer.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -0,0 +1,46 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// 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_LAYER_HXX
+#define HEADER_LAYER_HXX
+
+#include <ClanLib/Core/System/sharedptr.h>
+#include <ClanLib/Core/Math/rect.h>
+
+class EditorMapComponent;
+class LayerImpl;
+
+/** */
+class Layer
+{
+private:
+public:
+ Layer();
+
+ void draw(EditorMapComponent* parent);
+ bool has_bounding_rect() const;
+ CL_Rect get_bounding_rect();
+
+private:
+ CL_SharedPtr<LayerImpl> impl;
+};
+
+#endif
+
+/* EOF */
Added: trunk/src/layer_impl.hxx
===================================================================
--- trunk/src/layer_impl.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/layer_impl.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -0,0 +1,38 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// 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_LAYER_IMPL_HXX
+#define HEADER_LAYER_IMPL_HXX
+
+#include <ClanLib/Core/Math/rect.h>
+
+class EditorMapComponent;
+
+class LayerImpl
+{
+private:
+public:
+ virtual void draw(EditorMapComponent* parent) =0;
+ virtual bool has_bounding_rect() const =0;
+ virtual CL_Rect get_bounding_rect() =0;
+};
+
+#endif
+
+/* EOF */
Modified: trunk/src/minimap.cxx
===================================================================
--- trunk/src/minimap.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/minimap.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -27,7 +27,7 @@
#include "tileset.hxx"
#include "editor_map.hxx"
#include "editor_map_component.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "workspace.hxx"
#include "minimap.hxx"
@@ -66,7 +66,7 @@
}
// FIXME: This doesn't work all that well
- TileMap* tilemap = TileMap::current();
+ TilemapLayer* tilemap = TilemapLayer::current();
int tile_size = tilemap->get_tileset()->get_tile_size();
if (tilemap && tilemap->get_height() != 0 && tilemap->get_width() != 0)
@@ -77,7 +77,7 @@
CL_Size small_tile(tile_size * get_width() / map_width + 1,
tile_size * get_height() / map_height + 1);
- Field<int>* field = tilemap->get_map();
+ Field<int>* field = tilemap->get_field();
if (0)
{
@@ -114,11 +114,11 @@
Minimap::update_minimap_surface()
{
// FIXME: This doesn't work all that well
- TileMap* tilemap = TileMap::current();
+ TilemapLayer* tilemap = TilemapLayer::current();
if (tilemap)
{
- Field<int>* field = tilemap->get_map();
+ Field<int>* field = tilemap->get_field();
CL_PixelBuffer buffer(tilemap->get_width(), tilemap->get_height(),
tilemap->get_width()*4, CL_PixelFormat::rgba8888);
@@ -155,7 +155,7 @@
Minimap::mouse_move(const CL_InputEvent& event)
{
// FIXME: This doesn't work all that well
- TileMap* tilemap = TileMap::current();
+ TilemapLayer* tilemap = TilemapLayer::current();
int tile_size = tilemap->get_tileset()->get_tile_size();
int map_width = tilemap->get_width() * tile_size;
int map_height = tilemap->get_height() * tile_size;
@@ -169,7 +169,7 @@
Minimap::mouse_down(const CL_InputEvent& event)
{
// FIXME: This doesn't work all that well
- TileMap* tilemap = TileMap::current();
+ TilemapLayer* tilemap = TilemapLayer::current();
int tile_size = tilemap->get_tileset()->get_tile_size();
int map_width = tilemap->get_width() * tile_size;
int map_height = tilemap->get_height() * tile_size;
Modified: trunk/src/paint_command.cxx
===================================================================
--- trunk/src/paint_command.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/paint_command.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -22,27 +22,18 @@
#include <sstream>
#include <ClanLib/Core/core_iostream.h>
#include <ClanLib/Core/Math/rect.h>
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "paint_command.hxx"
-PaintCommand::PaintCommand(TileMap* t, const TileBrush& b)
- : tilemap(t), field(t->get_map()), brush(b)
+PaintCommand::PaintCommand(TilemapLayer t, const TileBrush& b)
+ : tilemap(t), brush(b)
{
- undo_field = *field;
+ undo_field = *(tilemap.get_field());
redo_brush = 0;
undo_brush = 0;
}
-PaintCommand::PaintCommand(Field<int>* f, const TileBrush& b)
- : tilemap(0), field(f), brush(b)
-{
- undo_field = *field;
-
- redo_brush = 0;
- undo_brush = 0;
-}
-
PaintCommand::~PaintCommand()
{
delete redo_brush;
@@ -53,8 +44,7 @@
PaintCommand::add_point(const CL_Point& pos)
{
points.push_back(pos);
- if (tilemap)
- tilemap->draw_tile(brush, pos);
+ tilemap.draw_tile(brush, pos);
}
void
@@ -79,7 +69,7 @@
pos.x = rect.left;
pos.y = rect.top;
- redo_brush = new TileBrush(*field, rect.get_width(), rect.get_height(),
-pos.x, -pos.y);
+ redo_brush = new TileBrush(*(tilemap.get_field()), rect.get_width(),
rect.get_height(), -pos.x, -pos.y);
undo_brush = new TileBrush(undo_field, rect.get_width(), rect.get_height(),
-pos.x, -pos.y);
redo_brush->set_opaque();
@@ -91,13 +81,13 @@
void
PaintCommand::redo()
{
- TileMap::draw_tile(field, *redo_brush, pos);
+ TilemapLayer::draw_tile(tilemap.get_field(), *redo_brush, pos);
}
void
PaintCommand::undo()
{
- TileMap::draw_tile(field, *undo_brush, pos);
+ TilemapLayer::draw_tile(tilemap.get_field(), *undo_brush, pos);
}
std::string
@@ -105,7 +95,7 @@
{
std::stringstream s;
- s << "_ = PaintCommand(" << tilemap << ", " << &brush << ")" << std::endl;
+ s << "_ = PaintCommand(" << &tilemap << ", " << &brush << ")" << std::endl;
for(Points::iterator i = points.begin(); i != points.end(); ++i)
{
s << "_.add_paint(" << i->x << ", " << i->y << ")" << std::endl;
Modified: trunk/src/paint_command.hxx
===================================================================
--- trunk/src/paint_command.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/paint_command.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -24,10 +24,9 @@
#include <ClanLib/Core/Math/point.h>
#include "field.hxx"
#include "tile_brush.hxx"
+#include "tilemap_layer.hxx"
#include "command.hxx"
-class TileMap;
-
/** The PaintCommand provides functionality to draw onto an TileMap.
The user needs to supply a brush and a map to draw to and the
points to which should be drawn, undo, redo and the internals of
@@ -38,18 +37,18 @@
typedef std::vector<CL_Point> Points;
Points points;
- TileMap* tilemap;
- Field<int>* field;
- TileBrush brush;
- Field<int> undo_field;
+ TilemapLayer tilemap;
+ TileBrush brush;
- CL_Point pos;
- TileBrush* redo_brush;
- TileBrush* undo_brush;
+ /** Copy of the field used to generate undo informations */
+ Field<int> undo_field;
+
+ CL_Point pos;
+ TileBrush* redo_brush;
+ TileBrush* undo_brush;
public:
- PaintCommand(Field<int>* f, const TileBrush& b);
- PaintCommand(TileMap* t, const TileBrush& b);
+ PaintCommand(TilemapLayer t, const TileBrush& b);
virtual ~PaintCommand();
void add_point(const CL_Point& pos);
Modified: trunk/src/scripting/editor.cxx
===================================================================
--- trunk/src/scripting/editor.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/scripting/editor.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -34,7 +34,6 @@
#include "../editor.hxx"
#include "../tile_selector.hxx"
#include "../objmap_select_tool.hxx"
-#include "../tilemap.hxx"
#include "../object_selector.hxx"
#include "../editor_map.hxx"
#include "../editor_map_component.hxx"
@@ -58,7 +57,6 @@
#include "../editor_mapsize_layer.hxx"
#include "../editor_objmap.hxx"
#include "../editor_grid_layer.hxx"
-#include "../tilemap.hxx"
#include "../python_functor.hxx"
#include "editor.hxx"
@@ -208,7 +206,7 @@
void
editor_toggle_grid(EditorMapLayer* layer)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(layer);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(layer);
if (tilemap)
tilemap->set_draw_grid(!tilemap->get_draw_grid());
}
@@ -216,7 +214,7 @@
void
editor_toggle_attributes(EditorMapLayer* layer)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(layer);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(layer);
if (tilemap)
tilemap->set_draw_attribute(!tilemap->get_draw_attribute());
}
@@ -318,8 +316,8 @@
void
editor_tilemap_set_current(EditorMapLayer* layer)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(layer);
- TileMap::set_current(tilemap);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(layer);
+ TilemapLayer::set_current(tilemap);
}
int
@@ -471,7 +469,7 @@
void
editor_tilemap_resize(EditorMapLayer* m, int w, int h, int x, int y)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(m);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(m);
if (tilemap)
{
tilemap->resize(CL_Size(w, h), CL_Point(x, y));
@@ -484,12 +482,6 @@
TileMapPaintTool::current()->set_brush(brush);
}
-void
-tilemap_paint_tool_set_tilemap(EditorMapLayer* layer)
-{
- TileMapPaintTool::current()->set_tilemap(dynamic_cast<TileMap*>(layer));
-}
-
#ifdef SWIGGUILE
SCM
editor_get_tile_selection()
@@ -793,7 +785,7 @@
EditorMap*
editor_map_create()
{
- return new EditorMap("");
+ return new EditorMap();
}
void
@@ -808,16 +800,10 @@
return new EditorObjMap();
}
-EditorMapLayer*
-editor_tilemap_create(Tileset* tileset, int w, int h, int tile_size)
-{
- return new TileMap(tileset, w, h);
-}
-
void
editor_tilemap_save_png(EditorMapLayer* l, const char* filename)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
CL_PixelBuffer pixelbuffer = tilemap->create_pixelbuffer();
pixelbuffer.lock();
@@ -840,7 +826,7 @@
int
editor_tilemap_get_width(EditorMapLayer* l)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
return tilemap->get_width();
else
@@ -850,7 +836,7 @@
int
editor_tilemap_get_height(EditorMapLayer* l)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
return tilemap->get_height();
else
@@ -860,7 +846,7 @@
void
editor_tilemap_set_bgcolor(EditorMapLayer* l, int r, int g, int b, int a)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
{
tilemap->set_background_color(CL_Color(r, g, b, a));
@@ -870,7 +856,7 @@
void
editor_tilemap_set_fgcolor(EditorMapLayer* l, int r, int g, int b, int a)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
{
tilemap->set_foreground_color(CL_Color(r, g, b, a));
@@ -881,7 +867,7 @@
SCM
editor_tilemap_get_data(EditorMapLayer* l)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
{
Field<int>* field = tilemap->get_map();
@@ -901,7 +887,7 @@
void
editor_tilemap_set_data(EditorMapLayer* l, SCM lst)
{
- TileMap* tilemap = dynamic_cast<TileMap*>(l);
+ TilemapLayer* tilemap = dynamic_cast<TilemapLayer*>(l);
if (tilemap)
{
Field<int>* field = tilemap->get_map();
@@ -916,11 +902,6 @@
}
#endif
-std::string
-editor_map_get_filename(EditorMap* m)
-{
- return m->get_filename();
-}
bool
editor_map_is_modified(EditorMap* m)
@@ -934,13 +915,6 @@
m->set_unmodified();
}
-void
-editor_map_set_filename(EditorMap* m, const char* name)
-{
- return m->set_filename(name);
-}
-
-
/*
std::string scm2string(SCM s)
{
Modified: trunk/src/scripting/editor.hxx
===================================================================
--- trunk/src/scripting/editor.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/scripting/editor.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -66,7 +66,6 @@
int editor_get_brush_tile();
void editor_set_tool(int i);
void tilemap_paint_tool_set_brush(TileBrush brush);
-void tilemap_paint_tool_set_tilemap(EditorMapLayer* layer);
int editor_objectmap_duplicate_object(EditorMapLayer* layer, int id);
void editor_objectmap_set_pos (EditorMapLayer* layer, int id, int x,
int y);
@@ -93,12 +92,8 @@
EditorMapLayer* editor_grid_layer_create(int w, int h, int tile_size);
EditorMapLayer* editor_objmap_create();
-std::string editor_map_get_filename(EditorMap* m);
-void editor_map_set_filename(EditorMap* m, const char* name);
-
void editor_toggle_grid(EditorMapLayer* layer);
void editor_toggle_attributes(EditorMapLayer* layer);
-EditorMapLayer* editor_tilemap_create(Tileset* tileset, int w, int h, int
tile_size);
void editor_tilemap_resize(EditorMapLayer* , int w, int h, int x,
int y);
int editor_tilemap_get_width(EditorMapLayer* l);
int editor_tilemap_get_height(EditorMapLayer* l);
Modified: trunk/src/tile.cxx
===================================================================
--- trunk/src/tile.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tile.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -68,7 +68,9 @@
Tile::get_sprite()
{
if (sur)
- return sur;
+ {
+ return sur;
+ }
else
{
try {
Modified: trunk/src/tile_selection.cxx
===================================================================
--- trunk/src/tile_selection.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tile_selection.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -21,7 +21,7 @@
#include <iostream>
#include <ClanLib/Core/core_iostream.h>
#include "math.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "tileset.hxx"
#include "tile_selection.hxx"
@@ -35,7 +35,7 @@
}
void
-TileSelection::start(TileMap* tilemap_, const CL_Point& pos)
+TileSelection::start(TilemapLayer tilemap_, const CL_Point& pos)
{
tilemap = tilemap_;
active = true;
@@ -68,7 +68,7 @@
void
TileSelection::draw(const CL_Color& color)
{
- int tile_size = tilemap->get_tileset()->get_tile_size();
+ int tile_size = tilemap.get_tileset()->get_tile_size();
CL_Display::fill_rect(CL_Rect(selection.left * tile_size, selection.top
* tile_size,
selection.right * tile_size, selection.bottom
* tile_size),
Modified: trunk/src/tile_selection.hxx
===================================================================
--- trunk/src/tile_selection.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tile_selection.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -24,9 +24,8 @@
#include <ClanLib/Display/color.h>
#include <ClanLib/Core/Math/point.h>
#include "tile_brush.hxx"
+#include "tilemap_layer.hxx"
-class TileMap;
-
/** The TileSelection is a little helper class to manage rectangular
selections of tiles and provides a way to convert this selection
to a Brush which then can be used for either serialisation or be
@@ -34,7 +33,7 @@
class TileSelection
{
private:
- TileMap* tilemap;
+ TilemapLayer tilemap;
CL_Point start_pos;
CL_Rect selection;
bool active;
@@ -42,7 +41,7 @@
TileSelection();
~TileSelection();
- void start (TileMap* tilemap, const CL_Point& pos);
+ void start (TilemapLayer tilemap, const CL_Point& pos);
void update(const CL_Point& pos);
void clear();
Deleted: trunk/src/tilemap.cxx
===================================================================
--- trunk/src/tilemap.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -1,276 +0,0 @@
-// $Id: editor_tilemap.cxx,v 1.14 2003/09/26 14:29:36 grumbel Exp $
-//
-// Flexlay - A Generic 2D Game Editor
-// Copyright (C) 2000 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 <math.h>
-#include <iostream>
-#include <ClanLib/Display/display.h>
-#include <ClanLib/Display/pixel_buffer.h>
-#include <ClanLib/Display/pixel_format.h>
-#include <ClanLib/Display/palette.h>
-#include <ClanLib/gl.h>
-#include "tile.hxx"
-#include "tileset.hxx"
-#include "editor.hxx"
-#include "editor_map.hxx"
-#include "tile_brush.hxx"
-#include "editor_map_component.hxx"
-#include "editor_map_component.hxx"
-#include "tilemap_layer.hxx"
-#include "blitter.hxx"
-#include "editor_map_component.hxx"
-
-TileMap* TileMap::current_ = 0;
-
-TileMap::TileMap(Tileset* tileset_, int w, int h)
- : field(w, h)
-{
- // FIXME: Move this to the widget or to some more generic
- // map-properties thingy
- draw_grid = false;
- draw_attribute = false;
- hex_mode = false;
-
- for (int y = 0; y < field.get_height(); ++y)
- for (int x = 0; x < field.get_width(); ++x)
- field.at(x, y) = 0;
-
- background_color = CL_Color(0, 0, 0, 0);
- foreground_color = CL_Color(255, 255, 255, 255);
-
- if (!tileset_)
- tileset = Tileset::current();
- else
- tileset = tileset_;
-}
-
-TileMap::~TileMap()
-{
-}
-
-void
-TileMap::draw_tile(int id, int x, int y, bool attribute)
-{
- Tile* tile = tileset->create(id);
-
- if (tile)
- {
- CL_Sprite sprite = tile->get_sprite();
- sprite.set_alignment (origin_top_left, 0, 0);
-
- sprite.set_color(foreground_color);
-
- sprite.draw (x, y);
-
- if (attribute)
- CL_Display::fill_rect(CL_Rect(CL_Point(x, y),
CL_Size(tileset->get_tile_size(),
-
tileset->get_tile_size())),
- tile->get_attribute_color());
- }
-}
-
-void
-TileMap::draw(EditorMapComponent* parent)
-{
- int tile_size = tileset->get_tile_size();
-
- if (background_color.get_alpha() != 0)
- CL_Display::fill_rect(CL_Rect(CL_Point(0,0),
- CL_Size(field.get_width() * tile_size,
- field.get_height() * tile_size)),
- background_color);
- CL_Display::flush();
-
- CL_Rect rect = parent->get_clip_rect();
-
- int start_x = std::max(0, rect.left / tile_size);
- int start_y = std::max(0, rect.top / tile_size);
- int end_x = std::min(field.get_width(), rect.right / tile_size + 1);
- int end_y = std::min(field.get_height(), rect.bottom / tile_size + 1);
-
- for (int y = start_y; y < end_y; ++y)
- for (int x = start_x; x < end_x; ++x)
- {
- draw_tile(field.at(x, y),
- x * tile_size, y * tile_size,
- draw_attribute);
- }
-
- if (1 || draw_grid)
- {
- for (int y = start_y; y <= end_y; ++y)
- CL_Display::draw_line(start_x * tile_size,
- y * tile_size,
- end_x * tile_size,
- y * tile_size,
- y % 5 ? CL_Color(150, 150, 150) : CL_Color(255,
255, 255));
-
- for (int x = start_x; x <= end_x; ++x)
- CL_Display::draw_line(x * tile_size,
- start_y * tile_size,
- x * tile_size,
- end_y * tile_size,
- x % 5 ? CL_Color(150, 150, 150) : CL_Color(255,
255, 255));
- }
-
- CL_Display::flush();
-}
-
-int
-TileMap::get_tile (int x, int y)
-{
- if (x >= 0 && x < (int)field.get_width() &&
- y >= 0 && y < (int)field.get_height())
- return field.at(x, y);
- else
- return 0;
-}
-
-void
-TileMap::resize(const CL_Size& size, const CL_Point& point)
-{
- field.resize(size.width, size.height, point.x, point.y);
-}
-
-void
-TileMap::draw_tile(int id, const CL_Point& pos)
-{
- if (pos.x >= 0 && pos.x < field.get_width()
- && pos.y >= 0 && pos.y < field.get_height())
- {
- field.at(pos.x, pos.y) = id;
- }
-}
-
-void
-TileMap::draw_tile(const TileBrush& brush, const CL_Point& pos)
-{
- draw_tile(&field, brush, pos);
-}
-
-void
-TileMap::draw_tile(Field<int>* field, const TileBrush& brush, const CL_Point&
pos)
-{
- int start_x = std::max(0, -pos.x);
- int start_y = std::max(0, -pos.y);
-
- int end_x = std::min(brush.get_width(), field->get_width() - pos.x);
- int end_y = std::min(brush.get_height(), field->get_height() - pos.y);
-
- for (int y = start_y; y < end_y; ++y)
- for (int x = start_x; x < end_x; ++x)
- {
- if (brush.is_opaque() || brush.at(x, y) != 0)
- {
- field->at(pos.x + x, pos.y + y) = brush.at(x, y);
- }
- }
-}
-
-void
-TileMap::set_draw_attribute(bool t)
-{
- draw_attribute = t;
-}
-
-bool
-TileMap::get_draw_attribute() const
-{
- return draw_attribute;
-}
-
-void
-TileMap::set_draw_grid(bool t)
-{
- draw_grid = t;
-}
-
-bool
-TileMap::get_draw_grid() const
-{
- return draw_grid;
-}
-
-CL_PixelBuffer
-TileMap::create_pixelbuffer()
-{
- int tile_size = tileset->get_tile_size();
-
- CL_PixelBuffer pixelbuffer(get_width() * tile_size,
- get_height() * tile_size,
- get_width() * tile_size * 4,
- CL_PixelFormat::rgba8888);
-
- {
- pixelbuffer.lock();
- unsigned char* buf = static_cast<unsigned char*>(pixelbuffer.get_data());
-
- int width = pixelbuffer.get_width();
- int height = pixelbuffer.get_height();
-
- // Draw a nice gradient
- for(int y = 0; y < height; ++y)
- {
- for (int x = 0; x < width; ++x)
- {
- buf[4*(y*width + x) + 0] = 255;
- buf[4*(y*width + x) + 1] = 255;
- buf[4*(y*width + x) + 2] = 255*y/height;
- buf[4*(y*width + x) + 3] = 255*y/height;
- }
- }
- pixelbuffer.unlock();
- }
-
- for (int y = 0; y < get_height(); ++y)
- for (int x = 0; x < get_width(); ++x)
- {
- Tile* tile = tileset->create(field.at(x, y));
-
- if (tile)
- {
- CL_PixelBuffer buf = tile->get_pixelbuffer();
- if (buf)
- {
- blit(pixelbuffer, buf, x*tile_size, y*tile_size);
- }
- }
- }
-
- return pixelbuffer;
-}
-
-CL_Rect
-TileMap::get_bounding_rect()
-{
- return CL_Rect(CL_Point(0, 0),
- CL_Size(field.get_width() * tileset->get_tile_size(),
- field.get_height() * tileset->get_tile_size()));
-}
-
-CL_Point
-TileMap::world2tile(const CL_Point& pos) const
-{
- int x = pos.x / tileset->get_tile_size();
- int y = pos.y / tileset->get_tile_size();
-
- return CL_Point(pos.x < 0 ? x-1 : x,
- pos.y < 0 ? y-1 : y);
-}
-
-/* EOF */
Deleted: trunk/src/tilemap.hxx
===================================================================
--- trunk/src/tilemap.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -1,113 +0,0 @@
-// $Id: editor_tilemap.hxx,v 1.10 2003/09/26 14:29:36 grumbel Exp $
-//
-// Flexlay - A Generic 2D Game Editor
-// Copyright (C) 2000 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 FLEXLAY_TILEMAP_HXX
-#define FLEXLAY_TILEMAP_HXX
-
-#include <ClanLib/gui.h>
-#include <ClanLib/Display/color.h>
-#include "field.hxx"
-#include "editor_map_layer.hxx"
-
-class Tileset;
-class CL_PixelBuffer;
-class TileBrush;
-
-/** TileMap holds the tilemap data for the editor and provides
- functions to manipulate them. Each \a EditorTilemap is associated
- with a \a Tileset, which provides information on which ids are
- mapped to which Tiles, the tilemap itself only knows the ids of
- tiles. */
-class TileMap : public EditorMapLayer
-{
-private:
- Tileset* tileset;
- CL_Color background_color;
- CL_Color foreground_color;
- bool hex_mode;
-
- Field<int> field;
-
- bool draw_grid;
- bool draw_attribute;
-
- static TileMap* current_;
-
-public:
- static TileMap* current() { return current_; }
- static void set_current(TileMap* c) { current_ = c; }
-
- TileMap(Tileset* tileset, int w, int h);
- ~TileMap();
-
- void draw (EditorMapComponent* parent);
-
- /** Return a pointer to the raw field representing this map */
- Field<int>* get_field() { return &field; }
-
- Tileset* get_tileset() { return tileset; }
-
- int get_tile (int, int);
-
- /** @param x position of the old map in the new resized one
- @param y position of the old map in the new resized one
- @param w height of the new map
- @param h height of the new map */
- void resize(const CL_Size& size, const CL_Point& point);
-
- Field<int>* get_map() { return &field; }
-
- std::vector<int> get_data() { return field.get_data(); }
- void set_data(std::vector<int> d) { field.set_data(d); }
-
- /** Draw the gives brush to the map */
- void draw_tile(const TileBrush& brush, const CL_Point& pos);
-
- /** Draw the given single tile to the map */
- void draw_tile(int id, const CL_Point& pos);
-
- void draw_tile(int id, int x, int y, bool attribute);
-
- int get_width() const { return field.get_width(); }
- int get_height() const { return field.get_height(); }
-
- void set_background_color(const CL_Color& color) { background_color = color;
}
- void set_foreground_color(const CL_Color& color) { foreground_color = color;
}
-
- void set_draw_attribute(bool t);
- bool get_draw_attribute() const;
-
- void set_draw_grid(bool t);
- bool get_draw_grid() const;
-
- CL_PixelBuffer create_pixelbuffer();
-
- static void draw_tile(Field<int>* field, const TileBrush& brush, const
CL_Point& pos);
-
- bool has_bounding_rect() const { return true; }
- CL_Rect get_bounding_rect();
-
- /** Convert a coordinate given in world position into a tile
- coordinate */
- CL_Point world2tile(const CL_Point& pos) const;
-};
-
-#endif
-
-/* EOF */
Added: trunk/src/tilemap_layer.cxx
===================================================================
--- trunk/src/tilemap_layer.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_layer.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -0,0 +1,412 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// 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 <math.h>
+#include <iostream>
+#include <ClanLib/Display/display.h>
+#include <ClanLib/Display/pixel_buffer.h>
+#include <ClanLib/Display/pixel_format.h>
+#include <ClanLib/Display/palette.h>
+#include <ClanLib/gl.h>
+#include "tile.hxx"
+#include "tileset.hxx"
+#include "editor.hxx"
+#include "editor_map.hxx"
+#include "tile_brush.hxx"
+#include "editor_map_component.hxx"
+#include "editor_map_component.hxx"
+#include "blitter.hxx"
+#include "layer_impl.hxx"
+#include "editor_map_component.hxx"
+#include "tilemap_layer.hxx"
+
+TilemapLayer* TilemapLayer::current_ = 0;
+
+class TilemapLayerImpl
+{
+public:
+ TilemapLayerImpl() {}
+ virtual ~TilemapLayerImpl() {}
+
+ Tileset* tileset;
+ CL_Color background_color;
+ CL_Color foreground_color;
+ bool hex_mode;
+
+ Field<int> field;
+
+ bool draw_grid;
+ bool draw_attribute;
+
+ bool has_bounding_rect() const;
+ CL_Rect get_bounding_rect();
+ void draw(EditorMapComponent* parent);
+ void draw_tile(int id, int x, int y, bool attribute);
+};
+
+TilemapLayer::TilemapLayer()
+{
+}
+
+TilemapLayer::TilemapLayer(Tileset* tileset_, int w, int h)
+ : impl(new TilemapLayerImpl())
+{
+ current_ = this;
+
+ impl->field = Field<int>(w, h);
+
+ // FIXME: Move this to the widget or to some more generic
+ // map-properties thingy
+ impl->draw_grid = false;
+ impl->draw_attribute = false;
+ impl->hex_mode = false;
+
+ for (int y = 0; y < impl->field.get_height(); ++y)
+ for (int x = 0; x < impl->field.get_width(); ++x)
+ impl->field.at(x, y) = 0;
+
+ impl->background_color = CL_Color(0, 0, 0, 0);
+ impl->foreground_color = CL_Color(255, 255, 255, 255);
+
+ if (!tileset_)
+ impl->tileset = Tileset::current();
+ else
+ impl->tileset = tileset_;
+}
+
+TilemapLayer::~TilemapLayer()
+{
+}
+
+void
+TilemapLayer::draw_tile(int id, int x, int y, bool attribute)
+{
+ Tile* tile = impl->tileset->create(id);
+
+ if (tile)
+ {
+ CL_Sprite sprite = tile->get_sprite();
+ sprite.set_alignment (origin_top_left, 0, 0);
+
+ sprite.set_color(impl->foreground_color);
+
+ sprite.draw (x, y);
+
+ if (attribute)
+ CL_Display::fill_rect(CL_Rect(CL_Point(x, y),
CL_Size(impl->tileset->get_tile_size(),
+
impl->tileset->get_tile_size())),
+ tile->get_attribute_color());
+ }
+}
+
+void
+TilemapLayer::draw(EditorMapComponent* parent)
+{
+ impl->draw(parent);
+}
+
+void
+TilemapLayerImpl::draw_tile(int id, int x, int y, bool attribute)
+{
+ Tile* tile = tileset->create(id);
+
+ if (tile)
+ {
+ CL_Sprite sprite = tile->get_sprite();
+ sprite.set_alignment (origin_top_left, 0, 0);
+
+ sprite.set_color(foreground_color);
+
+ sprite.draw (x, y);
+
+ if (attribute)
+ CL_Display::fill_rect(CL_Rect(CL_Point(x, y),
CL_Size(tileset->get_tile_size(),
+
tileset->get_tile_size())),
+ tile->get_attribute_color());
+ }
+}
+
+void
+TilemapLayerImpl::draw(EditorMapComponent* parent)
+{
+ int tile_size = this->tileset->get_tile_size();
+
+ if (this->background_color.get_alpha() != 0)
+ CL_Display::fill_rect(CL_Rect(CL_Point(0,0),
+ CL_Size(this->field.get_width() * tile_size,
+ this->field.get_height() *
tile_size)),
+ this->background_color);
+ CL_Display::flush();
+
+ CL_Rect rect = parent->get_clip_rect();
+
+ int start_x = std::max(0, rect.left / tile_size);
+ int start_y = std::max(0, rect.top / tile_size);
+ int end_x = std::min(this->field.get_width(), rect.right / tile_size +
1);
+ int end_y = std::min(this->field.get_height(), rect.bottom / tile_size +
1);
+
+ for (int y = start_y; y < end_y; ++y)
+ for (int x = start_x; x < end_x; ++x)
+ {
+ draw_tile(this->field.at(x, y),
+ x * tile_size, y * tile_size,
+ this->draw_attribute);
+ }
+
+ if (this->draw_grid)
+ {
+ for (int y = start_y; y <= end_y; ++y)
+ CL_Display::draw_line(start_x * tile_size,
+ y * tile_size,
+ end_x * tile_size,
+ y * tile_size,
+ y % 5 ? CL_Color(150, 150, 150) : CL_Color(255,
255, 255));
+
+ for (int x = start_x; x <= end_x; ++x)
+ CL_Display::draw_line(x * tile_size,
+ start_y * tile_size,
+ x * tile_size,
+ end_y * tile_size,
+ x % 5 ? CL_Color(150, 150, 150) : CL_Color(255,
255, 255));
+ }
+
+ CL_Display::flush();
+}
+
+int
+TilemapLayer::get_tile (int x, int y)
+{
+ if (x >= 0 && x < (int)impl->field.get_width() &&
+ y >= 0 && y < (int)impl->field.get_height())
+ return impl->field.at(x, y);
+ else
+ return 0;
+}
+
+void
+TilemapLayer::resize(const CL_Size& size, const CL_Point& point)
+{
+ impl->field.resize(size.width, size.height, point.x, point.y);
+}
+
+void
+TilemapLayer::draw_tile(int id, const CL_Point& pos)
+{
+ if (pos.x >= 0 && pos.x < impl->field.get_width()
+ && pos.y >= 0 && pos.y < impl->field.get_height())
+ {
+ impl->field.at(pos.x, pos.y) = id;
+ }
+}
+
+void
+TilemapLayer::draw_tile(const TileBrush& brush, const CL_Point& pos)
+{
+ draw_tile(&impl->field, brush, pos);
+}
+
+void
+TilemapLayer::draw_tile(Field<int>* field, const TileBrush& brush, const
CL_Point& pos)
+{
+ int start_x = std::max(0, -pos.x);
+ int start_y = std::max(0, -pos.y);
+
+ int end_x = std::min(brush.get_width(), field->get_width() - pos.x);
+ int end_y = std::min(brush.get_height(), field->get_height() - pos.y);
+
+ for (int y = start_y; y < end_y; ++y)
+ for (int x = start_x; x < end_x; ++x)
+ {
+ if (brush.is_opaque() || brush.at(x, y) != 0)
+ {
+ field->at(pos.x + x, pos.y + y) = brush.at(x, y);
+ }
+ }
+}
+
+void
+TilemapLayer::set_draw_attribute(bool t)
+{
+ impl->draw_attribute = t;
+}
+
+bool
+TilemapLayer::get_draw_attribute() const
+{
+ return impl->draw_attribute;
+}
+
+void
+TilemapLayer::set_draw_grid(bool t)
+{
+ impl->draw_grid = t;
+}
+
+bool
+TilemapLayer::get_draw_grid() const
+{
+ return impl->draw_grid;
+}
+
+CL_PixelBuffer
+TilemapLayer::create_pixelbuffer()
+{
+ int tile_size = impl->tileset->get_tile_size();
+
+ CL_PixelBuffer pixelbuffer(get_width() * tile_size,
+ get_height() * tile_size,
+ get_width() * tile_size * 4,
+ CL_PixelFormat::rgba8888);
+
+ {
+ pixelbuffer.lock();
+ unsigned char* buf = static_cast<unsigned char*>(pixelbuffer.get_data());
+
+ int width = pixelbuffer.get_width();
+ int height = pixelbuffer.get_height();
+
+ // Draw a nice gradient
+ for(int y = 0; y < height; ++y)
+ {
+ for (int x = 0; x < width; ++x)
+ {
+ buf[4*(y*width + x) + 0] = 255;
+ buf[4*(y*width + x) + 1] = 255;
+ buf[4*(y*width + x) + 2] = 255*y/height;
+ buf[4*(y*width + x) + 3] = 255*y/height;
+ }
+ }
+ pixelbuffer.unlock();
+ }
+
+ for (int y = 0; y < get_height(); ++y)
+ for (int x = 0; x < get_width(); ++x)
+ {
+ Tile* tile = impl->tileset->create(impl->field.at(x, y));
+
+ if (tile)
+ {
+ CL_PixelBuffer buf = tile->get_pixelbuffer();
+ if (buf)
+ {
+ blit(pixelbuffer, buf, x*tile_size, y*tile_size);
+ }
+ }
+ }
+
+ return pixelbuffer;
+}
+
+CL_Rect
+TilemapLayer::get_bounding_rect()
+{
+ return impl->get_bounding_rect();
+}
+
+CL_Rect
+TilemapLayerImpl::get_bounding_rect()
+{
+ return CL_Rect(CL_Point(0, 0),
+ CL_Size(field.get_width() * tileset->get_tile_size(),
+ field.get_height() * tileset->get_tile_size()));
+}
+
+CL_Point
+TilemapLayer::world2tile(const CL_Point& pos) const
+{
+ int x = pos.x / impl->tileset->get_tile_size();
+ int y = pos.y / impl->tileset->get_tile_size();
+
+ return CL_Point(pos.x < 0 ? x-1 : x,
+ pos.y < 0 ? y-1 : y);
+}
+
+Field<int>*
+TilemapLayer::get_field()
+{
+ return &impl->field;
+}
+
+TilemapLayer*
+TilemapLayer::current()
+{
+ return current_;
+}
+
+void
+TilemapLayer::set_current(TilemapLayer* t)
+{
+ current_ = t;
+}
+
+Tileset*
+TilemapLayer::get_tileset()
+{
+ return impl->tileset;
+}
+
+std::vector<int>
+TilemapLayer::get_data()
+{
+ return impl->field.get_data();
+}
+
+void
+TilemapLayer::set_data(std::vector<int> d)
+{
+ impl->field.set_data(d);
+}
+
+void
+TilemapLayer::set_background_color(const CL_Color& color)
+{
+ impl->background_color = color;
+}
+
+void
+TilemapLayer::set_foreground_color(const CL_Color& color)
+{
+ impl->foreground_color = color;
+}
+
+int
+TilemapLayer::get_width() const
+{
+ return impl->field.get_width();
+}
+
+int
+TilemapLayer::get_height() const
+{
+ return impl->field.get_height();
+}
+
+bool
+TilemapLayer::has_bounding_rect() const
+{
+ return impl->has_bounding_rect();
+}
+
+bool
+TilemapLayerImpl::has_bounding_rect() const
+{
+ return true;
+}
+
+/* EOF */
Added: trunk/src/tilemap_layer.hxx
===================================================================
--- trunk/src/tilemap_layer.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_layer.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -0,0 +1,101 @@
+// $Id$
+//
+// Pingus - A free Lemmings clone
+// 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_LAYER_HXX
+#define HEADER_TILEMAP_LAYER_HXX
+
+#include <ClanLib/Core/System/sharedptr.h>
+#include <ClanLib/Display/pixel_buffer.h>
+#include "field.hxx"
+
+class Tileset;
+class TileBrush;
+class TilemapLayerImpl;
+class EditorMapComponent;
+
+/** */
+class TilemapLayer
+{
+private:
+ static TilemapLayer* current_;
+public:
+ static TilemapLayer* current();
+ static void set_current(TilemapLayer* t);
+
+ TilemapLayer();
+ TilemapLayer(Tileset* tileset, int w, int h);
+ ~TilemapLayer();
+
+ void draw(EditorMapComponent* parent);
+
+ Tileset* get_tileset();
+
+ int get_tile (int, int);
+
+ Field<int>* get_field();
+
+ /** @param x position of the old map in the new resized one
+ @param y position of the old map in the new resized one
+ @param w height of the new map
+ @param h height of the new map */
+ void resize(const CL_Size& size, const CL_Point& point);
+
+ std::vector<int> get_data();
+ void set_data(std::vector<int> d);
+
+ /** Draw the gives brush to the map */
+ void draw_tile(const TileBrush& brush, const CL_Point& pos);
+
+ /** Draw the given single tile to the map */
+ void draw_tile(int id, const CL_Point& pos);
+
+ void draw_tile(int id, int x, int y, bool attribute);
+
+ int get_width() const;
+ int get_height() const;
+
+ void set_background_color(const CL_Color& color);
+ void set_foreground_color(const CL_Color& color);
+
+ void set_draw_attribute(bool t);
+ bool get_draw_attribute() const;
+
+ void set_draw_grid(bool t);
+ bool get_draw_grid() const;
+
+ CL_PixelBuffer create_pixelbuffer();
+
+ static void draw_tile(Field<int>* field, const TileBrush& brush, const
CL_Point& pos);
+
+ bool has_bounding_rect() const;
+ CL_Rect get_bounding_rect();
+
+ /** Convert a coordinate given in world position into a tile
+ coordinate */
+ CL_Point world2tile(const CL_Point& pos) const;
+
+ bool is_null() const { return impl.is_null(); }
+
+private:
+ CL_SharedPtr<TilemapLayerImpl> impl;
+};
+
+#endif
+
+/* EOF */
Modified: trunk/src/tilemap_paint_tool.cxx
===================================================================
--- trunk/src/tilemap_paint_tool.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_paint_tool.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -23,7 +23,7 @@
#include <ClanLib/Display/keys.h>
#include <ClanLib/Display/display.h>
#include "globals.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "tileset.hxx"
#include "editor_map.hxx"
#include "editor_map_component.hxx"
@@ -49,7 +49,6 @@
command = 0;
mode = NONE;
- tilemap = 0;
}
TileMapPaintTool::~TileMapPaintTool()
@@ -59,7 +58,7 @@
void
TileMapPaintTool::draw()
{
- if (!tilemap)
+ if (tilemap.is_null())
return;
switch(mode)
@@ -72,7 +71,7 @@
break;
default:
- int tile_size = tilemap->get_tileset()->get_tile_size();
+ int tile_size = tilemap.get_tileset()->get_tile_size();
// Draw the brush:
for(int y = 0; y < brush.get_height(); ++y)
@@ -114,10 +113,10 @@
void
TileMapPaintTool::on_mouse_down(const CL_InputEvent& event)
{
- if (tilemap)
+ if (!tilemap.is_null())
{
EditorMapComponent* parent = EditorMapComponent::current();
- CL_Point pos =
tilemap->world2tile(parent->screen2world(event.mouse_pos));
+ CL_Point pos = tilemap.world2tile(parent->screen2world(event.mouse_pos));
switch (mode)
{
@@ -150,10 +149,10 @@
void
TileMapPaintTool::on_mouse_move(const CL_InputEvent& event)
{
- if (tilemap)
+ if (!tilemap.is_null())
{
EditorMapComponent* parent = EditorMapComponent::current();
- current_tile =
tilemap->world2tile(parent->screen2world(event.mouse_pos));
+ current_tile = tilemap.world2tile(parent->screen2world(event.mouse_pos));
switch (mode)
{
@@ -178,12 +177,12 @@
void
TileMapPaintTool::on_mouse_up (const CL_InputEvent& event)
{
- if (tilemap)
+ if (!tilemap.is_null())
{
EditorMapComponent::current()->get_workspace()->get_current_map()->modify();
EditorMapComponent* parent = EditorMapComponent::current();
- CL_Point pos =
tilemap->world2tile(parent->screen2world(event.mouse_pos));
+ CL_Point pos = tilemap.world2tile(parent->screen2world(event.mouse_pos));
switch (event.id)
{
@@ -197,7 +196,7 @@
Editor::current()->execute(command);
command = 0;
- tilemap->draw_tile(brush, pos);
+ tilemap.draw_tile(brush, pos);
last_draw = CL_Point(-1, -1);
}
break;
@@ -209,7 +208,7 @@
mode = NONE;
selection.update(pos);
- brush = selection.get_brush(*tilemap->get_field());
+ brush = selection.get_brush(*tilemap.get_field());
if ((brush.get_width() > 1 || brush.get_height() > 1)
&& !CL_Keyboard::get_keycode(CL_KEY_LSHIFT))
Modified: trunk/src/tilemap_paint_tool.hxx
===================================================================
--- trunk/src/tilemap_paint_tool.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_paint_tool.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -23,9 +23,9 @@
#include "tile_brush.hxx"
#include "tile_selection.hxx"
#include "tilemap_tool.hxx"
+#include "tilemap_layer.hxx"
class PaintCommand;
-class TileMap;
/** */
class TileMapPaintTool : public TileMapTool
@@ -40,7 +40,7 @@
PaintCommand* command;
- TileMap* tilemap;
+ TilemapLayer tilemap;
static TileMapPaintTool* current_;
public:
@@ -52,7 +52,7 @@
const TileBrush& get_brush() { return brush; }
void set_brush(const TileBrush& b);
void draw();
- void set_tilemap(TileMap* t) { tilemap = t; }
+ void set_tilemap(TilemapLayer t) { tilemap = t; }
private:
void on_mouse_down(const CL_InputEvent& event);
Modified: trunk/src/tilemap_select_tool.cxx
===================================================================
--- trunk/src/tilemap_select_tool.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_select_tool.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -21,7 +21,7 @@
#include <ClanLib/Display/keys.h>
#include <ClanLib/Display/input_event.h>
#include "globals.hxx"
-#include "tilemap.hxx"
+#include "tilemap_layer.hxx"
#include "editor_map.hxx"
#include "editor_map_component.hxx"
#include "tile_brush.hxx"
@@ -57,7 +57,7 @@
creating_selection = false;
parent->release_mouse();
-
selection.update(TileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
+
selection.update(TilemapLayer::current()->world2tile(parent->screen2world(event.mouse_pos)));
break;
}
}
@@ -73,8 +73,8 @@
{
creating_selection = true;
parent->capture_mouse();
- TileMap* tilemap = TileMap::current();
- selection.start(tilemap,
tilemap->world2tile(parent->screen2world(event.mouse_pos)));
+ TilemapLayer* tilemap = TilemapLayer::current();
+ selection.start(*tilemap,
tilemap->world2tile(parent->screen2world(event.mouse_pos)));
}
break;
@@ -92,14 +92,14 @@
if (creating_selection)
{
-
selection.update(TileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
+
selection.update(TilemapLayer::current()->world2tile(parent->screen2world(event.mouse_pos)));
}
}
TileBrush
TileMapSelectTool::get_selection() const
{
- TileMap* tilemap = TileMap::current();
+ TilemapLayer* tilemap = TilemapLayer::current();
return selection.get_brush(*tilemap->get_field());
}
Modified: trunk/src/tilemap_select_tool.hxx
===================================================================
--- trunk/src/tilemap_select_tool.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tilemap_select_tool.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -22,7 +22,6 @@
#include <ClanLib/Core/Math/rect.h>
#include <ClanLib/Core/Math/point.h>
-#include "tilemap.hxx"
#include "tile_selection.hxx"
#include "tilemap_tool.hxx"
Modified: trunk/src/tileset.cxx
===================================================================
--- trunk/src/tileset.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tileset.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -31,161 +31,41 @@
Tileset* Tileset::current_ = 0;
+typedef std::vector<Tile*> Tiles;
+typedef Tiles::iterator iterator;
+
+class TilesetImpl
+{
+public:
+ Tiles tiles;
+ int tile_size;
+};
+
Tileset::Tileset(int tile_size_)
+ : impl(new TilesetImpl())
{
+ std::cout << "Tileset::Tileset(" << tile_size_ << ")" << std::endl;
+ impl->tile_size = tile_size_;
current_ = this;
- tile_size = tile_size_;
}
Tileset::~Tileset()
{
std::cout << "Tileset: destroy" << std::endl;
-}
-
-void
-Tileset::add_tile(int id, Tile* tile)
-{
- // FIXME: Memleaky
- if (id >= int(tiles.size()))
- tiles.resize(id+1, 0);
-
- tiles[id] = tile;
-}
-
-#ifdef SWIGGUILE
-void
-Tileset::load_tile_file(const std::string& filename)
-{
- SCM input_stream = scm_open_file(gh_str02scm(filename.c_str()),
- gh_str02scm("r"));
- SCM tree = scm_read(input_stream);
-
- if (!(gh_symbol_p(gh_car(tree)) &&
gh_equal_p(gh_symbol2scm("windstille-tiles"), gh_car(tree))))
+ for(Tiles::iterator i = impl->tiles.begin(); i != impl->tiles.end(); ++i)
{
- std::cout << "Not a Windstille Tile File!" << std::endl;
+ delete *i;
}
- else
- {
- tree = gh_cdr(tree);
-
- while (!gh_null_p(tree))
- {
- SCM current = gh_car(tree);
-
- if (gh_pair_p(current))
- {
- SCM name = gh_car(current);
- SCM data = gh_cdr(current);
-
- if (gh_equal_p(gh_symbol2scm("tile"), name))
- {
- add_tile_from_scm(data);
- }
- else
- {
- std::cout << "Tileset: Unknown tag: " << scm2string(name) <<
std::endl;
- }
- }
- else
- {
- std::cout << "Tileset: Not a pair!" << std::endl;
- }
- tree = gh_cdr(tree);
- }
- }
}
void
-Tileset::add_tile_from_scm(SCM data)
+Tileset::add_tile(int id, const Tile& tile)
{
- // FIXME: Move this to scripting and add a Tileset::add()
- int id = 0;
- std::string image;
- CL_Color color(254, 254, 254, 254);
- CL_Color attribute_color(255, 255, 255, 100);
- unsigned char colmap[8];
-
- while (!gh_null_p(data))
- {
- SCM current = gh_car(data);
-
- if (gh_pair_p(current))
- {
- SCM name = gh_car(current);
- SCM data = gh_cdr(current);
+ if (id >= int(impl->tiles.size()))
+ impl->tiles.resize(id+1, 0);
- if (gh_equal_p(gh_symbol2scm("id"), name))
- {
- id = gh_scm2int(gh_car(data));
- }
- else if (gh_equal_p(gh_symbol2scm("color"), name))
- {
- color = CL_Color(gh_scm2int(gh_car(data)),
- gh_scm2int(gh_cadr(data)),
- gh_scm2int(gh_caddr(data)),
- gh_scm2int(gh_car(gh_cdddr(data))));
- }
- else if (gh_equal_p(gh_symbol2scm("attribute-color"), name))
- {
- attribute_color = CL_Color(gh_scm2int(gh_car(data)),
- gh_scm2int(gh_cadr(data)),
- gh_scm2int(gh_caddr(data)),
- gh_scm2int(gh_car(gh_cdddr(data))));
- }
- else if (gh_equal_p(gh_symbol2scm("image"), name))
- {
- image = scm2string(gh_car(data));
- }
- else if (gh_equal_p(gh_symbol2scm("colmap"), name))
- {
- colmap[0] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[1] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[2] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[3] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[4] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[5] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[6] = gh_scm2int(gh_car(data));
- data = gh_cdr(data);
- colmap[7] = gh_scm2int(gh_car(data));
- }
- }
- data = gh_cdr(data);
- }
-
- if (0) // Debugging code
- {
- std::cout << "Tile: id = " << id << "\n"
- << " image = " << image << "\n"
- << " colmap = "
- << int(colmap[0]) << ", "
- << int(colmap[1]) << ", "
- << int(colmap[2]) << ", "
- << int(colmap[3]) << ", "
- << int(colmap[4]) << ", "
- << int(colmap[5]) << ", "
- << int(colmap[6]) << ", "
- << int(colmap[7])
- << std::endl;
- }
-
- if (id < 0)
- std::cout << "Tile Id bug: " << id << std::endl;
- else
- {
- if (id >= int(tiles.size()))
- {
- tiles.resize(id+1);
- }
- tiles[id] = new Tile(image, color, attribute_color, colmap);
- }
+ impl->tiles[id] = new Tile(tile);
}
-#endif
Tile*
Tileset::create (int id)
@@ -198,8 +78,8 @@
}
else
{
- if (id > 0 && id < int(tiles.size()))
- return tiles[id];
+ if (id > 0 && id < int(impl->tiles.size()))
+ return impl->tiles[id];
else
return 0;
}
@@ -218,4 +98,10 @@
delete current_;
}
+int
+Tileset::get_tile_size() const
+{
+ return impl->tile_size;
+}
+
/* EOF */
Modified: trunk/src/tileset.hxx
===================================================================
--- trunk/src/tileset.hxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tileset.hxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -20,13 +20,12 @@
#ifndef TILESET_HXX
#define TILESET_HXX
-#ifdef SWIGGUILE
-#include <libguile.h>
-#endif
#include <map>
#include <string>
+#include <ClanLib/Core/System/sharedptr.h>
class Tile;
+class TilesetImpl;
/** A \a Tileset provides the mapping from an \a id to a \a Tile
structure. It also contains information of the tile_size and other
@@ -34,20 +33,9 @@
class Tileset
{
private:
- // FIXME: Replace ths with a vector, map is potentially slow
- //typedef std::map<int, Tile*> Tiles;
- typedef std::vector<Tile*> Tiles;
- Tiles tiles;
-
- int tile_size;
-
static Tileset* current_;
-public:
- typedef Tiles::iterator iterator;
-
- iterator begin() { return tiles.begin(); }
- iterator end() { return tiles.end(); }
+public:
/** Create an empty Tileset, so that the user can add stuff via
scripting to it */
Tileset(int tile_size_);
@@ -62,9 +50,9 @@
* @return on success the tile is returned, on failure 0 */
Tile* create(int id);
- int get_tile_size() const { return tile_size; }
+ int get_tile_size() const;
- void add_tile(int id, Tile* tile);
+ void add_tile(int id, const Tile& tile);
/** Create the default TileFactor*/
static void init();
@@ -76,10 +64,8 @@
static Tileset* current() { return current_; }
static void set_current(Tileset* c) { current_ = c; }
-#ifdef SWIGGUILE
- void load_tile_file(const std::string& filename);
- void add_tile_from_scm(SCM data);
-#endif
+private:
+ CL_SharedPtr<TilesetImpl> impl;
};
#endif
Modified: trunk/src/tool_manager.cxx
===================================================================
--- trunk/src/tool_manager.cxx 2004-05-15 18:58:29 UTC (rev 330)
+++ trunk/src/tool_manager.cxx 2004-05-15 20:26:26 UTC (rev 331)
@@ -22,7 +22,6 @@
#include "tilemap_select_tool.hxx"
#include "objmap_select_tool.hxx"
#include "zoom_tool.hxx"
-#include "tilemap.hxx"
#include "editor_map.hxx"
#include "editor_names.hxx"
#include "tool_manager.hxx"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Windstille-devel] rev 331 - in trunk/src: . scripting,
Ingo Ruhnke <=