[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Windstille-devel] rev 328 - in trunk/src: . scripting
From: |
Ingo Ruhnke |
Subject: |
[Windstille-devel] rev 328 - in trunk/src: . scripting |
Date: |
Sat, 15 May 2004 13:52:53 +0200 |
Author: grumbel
Date: 2004-05-15 13:52:53 +0200 (Sat, 15 May 2004)
New Revision: 328
Added:
trunk/src/tilemap.cxx
trunk/src/tilemap.hxx
Removed:
trunk/src/editor_tilemap.cxx
trunk/src/editor_tilemap.hxx
trunk/src/flexlay_python.cxx
Modified:
trunk/src/SConstruct
trunk/src/editor.py
trunk/src/editor_map.hxx
trunk/src/editor_map_component.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/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/tool_manager.cxx
Log:
- changed EditorTileMap to TileMap (or should I better use Tilemap?)
Modified: trunk/src/SConstruct
===================================================================
--- trunk/src/SConstruct 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/SConstruct 2004-05-15 11:52:53 UTC (rev 328)
@@ -5,7 +5,30 @@
SWIGFLAGS='-c++ -python',
SHLIBPREFIX='')
-Depends('flexlay_wrap.cxx', ['flexlay.i', 'clanlib.i'])
+Depends('flexlay_wrap.cxx', ['flexlay.i',
+ 'clanlib.i',
+ 'scripting/editor.hxx',
+ 'command.hxx',
+ 'paint_command.hxx',
+ 'object_move_command.hxx',
+ 'object_add_command.hxx',
+ 'scripting/editor.hxx',
+ 'tile.hxx',
+ 'tile_brush.hxx',
+ 'editor.hxx',
+ 'editor_map_layer.hxx',
+ 'tilemap.hxx',
+ 'editor_map.hxx',
+ 'workspace.hxx',
+ 'tileset.hxx',
+ 'editor_map_component.hxx',
+ 'flexlay.hxx',
+ 'globals.hxx',
+ 'python_functor.hxx',
+ 'gui_manager.hxx',
+ 'tile_selector.hxx',
+ 'object_brush.hxx',
+ 'object_selector.hxx'])
env.Command('flexlay_wrap.cxx', 'flexlay.i', "swig -python -c++ $SOURCE")
env.SharedLibrary(
@@ -20,7 +43,7 @@
'editor_map_component.cxx',
'editor_mapsize_layer.cxx',
'editor_objmap.cxx',
- 'editor_tilemap.cxx',
+ 'tilemap.cxx',
'flexlay.cxx',
'globals.cxx',
'graphic_context_state.cxx',
Modified: trunk/src/editor.py
===================================================================
--- trunk/src/editor.py 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/editor.py 2004-05-15 11:52:53 UTC (rev 328)
@@ -33,7 +33,7 @@
m = EditorMap("Foobar")
workspace.set_current_map(m)
tileset = Tileset(32)
-tilemap = EditorTileMap(tileset, 20, 10)
+tilemap = TileMap(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),
Modified: trunk/src/editor_map.hxx
===================================================================
--- trunk/src/editor_map.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/editor_map.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -26,7 +26,7 @@
#include <ClanLib/Core/Math/point.h>
#include "field.hxx"
#include "editor_objmap.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "editor_map_layer.hxx"
class EditorMapComponent;
Modified: trunk/src/editor_map_component.hxx
===================================================================
--- trunk/src/editor_map_component.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/editor_map_component.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -26,7 +26,7 @@
#include <ClanLib/Core/Math/point.h>
#include "field.hxx"
#include "editor_objmap.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "graphic_context_state.hxx"
class Workspace;
Deleted: trunk/src/editor_tilemap.cxx
===================================================================
--- trunk/src/editor_tilemap.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/editor_tilemap.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -1,366 +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 "editor_tilemap.hxx"
-#include "editor_map_component.hxx"
-
-EditorTileMap* EditorTileMap::current_ = 0;
-
-EditorTileMap::EditorTileMap(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_;
-}
-
-EditorTileMap::~EditorTileMap()
-{
-}
-
-void
-EditorTileMap::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
-EditorTileMap::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
-EditorTileMap::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
-EditorTileMap::resize(const CL_Size& size, const CL_Point& point)
-{
- field.resize(size.width, size.height, point.x, point.y);
-}
-
-void
-EditorTileMap::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
-EditorTileMap::draw_tile(const TileBrush& brush, const CL_Point& pos)
-{
- draw_tile(&field, brush, pos);
-}
-
-void
-EditorTileMap::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
-EditorTileMap::set_draw_attribute(bool t)
-{
- draw_attribute = t;
-}
-
-bool
-EditorTileMap::get_draw_attribute() const
-{
- return draw_attribute;
-}
-
-void
-EditorTileMap::set_draw_grid(bool t)
-{
- draw_grid = t;
-}
-
-bool
-EditorTileMap::get_draw_grid() const
-{
- return draw_grid;
-}
-
-void
-blit(CL_PixelBuffer& target, CL_PixelBuffer& brush, int x_pos, int y_pos)
-{
- target.lock();
- brush.lock();
-
- int start_x = std::max(0, -x_pos);
- int start_y = std::max(0, -y_pos);
-
- int end_x = std::min(brush.get_width(), target.get_width() - x_pos);
- int end_y = std::min(brush.get_height(), target.get_height() - y_pos);
-
- unsigned char* target_buf = static_cast<unsigned char*>(target.get_data());
- unsigned char* brush_buf = static_cast<unsigned char*>(brush.get_data());
-
- int target_width = target.get_width();
- int brush_width = brush.get_width();
-
- if (brush.get_format().get_type() == pixelformat_rgba)
- {
- if (brush.get_format().get_depth() == 32)
- {
- for (int y = start_y; y < end_y; ++y)
- for (int x = start_x; x < end_x; ++x)
- {
- int target_pos = (y + y_pos) * target_width + x + x_pos;
- int brush_pos = y * brush_width + x;
-
- unsigned char a = brush_buf[4*brush_pos + 0];
- unsigned char r = brush_buf[4*brush_pos + 1];
- unsigned char g = brush_buf[4*brush_pos + 2];
- unsigned char b = brush_buf[4*brush_pos + 3];
-
- unsigned char ta = target_buf[4*target_pos + 0];
- unsigned char tr = target_buf[4*target_pos + 1];
- unsigned char tg = target_buf[4*target_pos + 2];
- unsigned char tb = target_buf[4*target_pos + 3];
-
- float alpha = a/255.0f;
-
- target_buf[4*target_pos + 0] = std::min(255, ta + a);
- target_buf[4*target_pos + 1] = std::min(255, int((1-alpha)*tr
+ alpha*r));
- target_buf[4*target_pos + 2] = std::min(255, int((1-alpha)*tg
+ alpha*g));
- target_buf[4*target_pos + 3] = std::min(255, int((1-alpha)*tb
+ alpha*b));
- }
- }
- else if (brush.get_format().get_depth() == 24)
- {
- for (int y = start_y; y < end_y; ++y)
- for (int x = start_x; x < end_x; ++x)
- {
- int target_pos = (y + y_pos) * target_width + x + x_pos;
- int brush_pos = y * brush_width + x;
-
- target_buf[4*target_pos + 0] = 255;
- target_buf[4*target_pos + 1] = brush_buf[3*brush_pos + 0];
- target_buf[4*target_pos + 2] = brush_buf[3*brush_pos + 1];
- target_buf[4*target_pos + 3] = brush_buf[3*brush_pos + 2];
- }
- }
- else
- {
- std::cout << "Unsupported bpp: " << brush.get_format().get_depth()
<< std::endl;
- }
- }
- else if (brush.get_format().get_type() == pixelformat_index)
- {
- CL_Palette palette = brush.get_palette();
- for (int y = start_y; y < end_y; ++y)
- for (int x = start_x; x < end_x; ++x)
- {
- int target_pos = (y + y_pos) * target_width + x + x_pos;
- int brush_pos = y * brush_width + x;
-
- target_buf[4*target_pos + 0] = 255;
- target_buf[4*target_pos + 1] =
palette.colors[brush_buf[brush_pos]].get_blue();
- target_buf[4*target_pos + 2] =
palette.colors[brush_buf[brush_pos]].get_green();
- target_buf[4*target_pos + 3] =
palette.colors[brush_buf[brush_pos]].get_red();
- }
- }
- else
- {
- assert(!"Unknown pixelformat type");
- }
-
-
-
- brush.unlock();
- target.unlock();
-}
-
-CL_PixelBuffer
-EditorTileMap::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
-EditorTileMap::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
-EditorTileMap::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/editor_tilemap.hxx
===================================================================
--- trunk/src/editor_tilemap.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/editor_tilemap.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -1,112 +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 EDITORTILEMAP_HXX
-#define EDITORTILEMAP_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;
-
-/** EditorTileMap 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 EditorTileMap : 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 EditorTileMap* current_;
-public:
- static EditorTileMap* current() { return current_; }
- static void set_current(EditorTileMap* c) { current_ = c; }
-
- EditorTileMap(Tileset* tileset, int w, int h);
- ~EditorTileMap();
-
- 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 */
Modified: trunk/src/flexlay.i
===================================================================
--- trunk/src/flexlay.i 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/flexlay.i 2004-05-15 11:52:53 UTC (rev 328)
@@ -17,7 +17,7 @@
#include "tile_brush.hxx"
#include "editor.hxx"
#include "editor_map_layer.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "editor_map.hxx"
#include "workspace.hxx"
#include "tileset.hxx"
@@ -46,7 +46,7 @@
%include "tile_brush.hxx"
%include "editor.hxx"
%include "editor_map_layer.hxx"
-%include "editor_tilemap.hxx"
+%include "tilemap.hxx"
%include "editor_map.hxx"
%include "workspace.hxx"
%include "tileset.hxx"
Deleted: trunk/src/flexlay_python.cxx
===================================================================
--- trunk/src/flexlay_python.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/flexlay_python.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -1,159 +0,0 @@
-#include <string>
-#include <ClanLib/display.h>
-#include <ClanLib/core.h>
-#include <ClanLib/gl.h>
-#include <ClanLib/gui.h>
-#include <Python.h>
-#include <boost/python.hpp>
-#include <iostream>
-
-#include "command.hxx"
-#include "paint_command.hxx"
-
-#include "scripting/editor.hxx"
-#include "tile.hxx"
-#include "tile_brush.hxx"
-#include "editor.hxx"
-#include "editor_map.hxx"
-#include "workspace.hxx"
-#include "tileset.hxx"
-#include "editor_map_component.hxx"
-#include "flexlay.hxx"
-#include "globals.hxx"
-#include "python_functor.hxx"
-#include "gui_manager.hxx"
-
-void
-clerror_translator(CL_Error const& err)
-{
- PyErr_SetString(PyExc_UserWarning, ("CL_Error: " + err.message).c_str());
-}
-
-void flexlay_init() { flexlay.init(); }
-void flexlay_deinit() { flexlay.deinit(); }
-
-void sig_connect(CL_Signal_v0& sig, boost::python::object obj)
-{
- std::cout << "Connecting functor: " << std::endl;
- new CL_Slot(sig.connect_functor(PythonFunctor(boost::python::object(obj))));
-}
-
-void foobar(CL_Menu* menu)
-{
- std::cout << "Do foobar" << menu << std::endl;
-}
-
-BOOST_PYTHON_MODULE(flexlay)
-{
- using namespace boost::python;
-
- def("flexlay_init", &flexlay_init);
- def("flexlay_deinit", &flexlay_deinit);
- def("editor_set_brush_tile", editor_set_brush_tile);
-
- register_exception_translator<CL_Error>(&clerror_translator);
-
- class_<GUIManager>("GUIManager")
- .def("run", &GUIManager::run)
- .def("quit", &GUIManager::quit)
- .def("push_component", &GUIManager::push_component)
- .def("pop_component", &GUIManager::pop_component)
- .def("get_component", &GUIManager::get_component,
- return_value_policy<reference_existing_object>());
-
- class_<CL_Size>("Size", init<int, int>())
- .def_readwrite("width", &CL_Size::width)
- .def_readwrite("height", &CL_Size::height);
-
- class_<CL_Point>("Point", init<int, int>())
- .def_readwrite("x", &CL_Point::x)
- .def_readwrite("y", &CL_Point::y);
-
- class_<CL_Rect>("Rect", init<int, int, int, int>())
- .def(init<CL_Point, CL_Size>())
- .def_readwrite("left", &CL_Rect::left)
- .def_readwrite("right", &CL_Rect::right)
- .def_readwrite("top", &CL_Rect::top)
- .def_readwrite("bottom", &CL_Rect::bottom);
-
- class_<CL_Signal_v0, boost::noncopyable>("Signal_v0", no_init);
-
- class_<CL_Component, boost::noncopyable>("Component", no_init);
-
- def("connect", &sig_connect);
-
- class_<CL_Window, bases<CL_Component>, CL_Window, boost::noncopyable>
- ("Window", init<CL_Rect, std::string, CL_Component*>());
-
- class_<CL_Button, boost::noncopyable, bases<CL_Component> >
- ("Button", init<CL_Rect, std::string, CL_Component*>())
- .def("sig_clicked", &CL_Button::sig_clicked,
- return_value_policy<reference_existing_object>());
-
- class_<CL_MenuNode, boost::noncopyable>("MenuNode", no_init);
-
- class_<CL_Menu, bases<CL_Component>, CL_Menu, boost::noncopyable>
- ("Menu", init<CL_Component*>())
- .def("add_item", &CL_Menu::create_item,
- return_value_policy<reference_existing_object>())
- .def("foobar", &foobar);
-
- class_<Workspace, bases<>, Workspace, boost::noncopyable>
- ("Workspace", init<int, int>())
- .def("set_map", &Workspace::set_current_map);
-
- class_<Editor, bases<>, Editor, boost::noncopyable>
- ("Editor", init<>())
- .def("get_gui", &Editor::get_gui_manager,
- return_value_policy<reference_existing_object>());
-
- class_<EditorMap>
- ("EditorMap", init<std::string>())
- .def("add", &EditorMap::add_layer);
-
- class_<EditorMapLayer, bases<>, EditorMapLayer, boost::noncopyable>
- ("EditorMapLayer", no_init);
-
- class_<EditorMapComponent, bases<CL_Component>, EditorMapComponent,
boost::noncopyable>
- ("EditorMapComponent", init<CL_Rect, CL_Component*>())
- .def("set_zoom", &EditorMapComponent::set_zoom)
- .def("set_workspace", &EditorMapComponent::set_workspace);
-
- class_<CL_Color>("Color", init<int, int, int, int>())
- .add_property("red", &CL_Color::set_red, &CL_Color::set_red)
- .add_property("green", &CL_Color::set_green, &CL_Color::set_green)
- .add_property("blue", &CL_Color::set_blue, &CL_Color::set_blue)
- .add_property("alpha", &CL_Color::set_alpha, &CL_Color::set_alpha);
-
- class_<Tile>("Tile", init<std::string, CL_Color, CL_Color>());
-
- class_<Tileset>("Tileset", init<int>())
- .def("get_tilesize", &Tileset::get_tile_size)
- .def("add_tile", &Tileset::add_tile);
-
- class_<EditorTileMap, bases<EditorMapLayer>, EditorTileMap,
boost::noncopyable>
- ("TileMap", init<Tileset*, int, int>())
- .def("get_tile", &EditorTileMap::get_tile)
- .def("resize", &EditorTileMap::resize);
-
- class_<TileBrush>
- ("TileBrush", init<int, int>())
- .def("set_opaque", &TileBrush::set_opaque)
- .def("set_transparent", &TileBrush::set_transparent)
- .def("auto_crop", &TileBrush::auto_crop);
-
- class_<Command, boost::noncopyable>
- ("Command", no_init)
- .def("execute", &Command::execute)
- .def("undo", &Command::undo)
- .def("redo", &Command::redo);
-
- class_<PaintCommand, bases<Command>, PaintCommand, boost::noncopyable>
- ("PaintCommand", init<EditorTileMap*, TileBrush>())
- .def("add_point", &PaintCommand::add_point);
-
- def("tilemap_set_current", &EditorTileMap::set_current);
- def("tilemap_paint_tool_set_tilemap", &tilemap_paint_tool_set_tilemap);
-}
-
-/* EOF */
Modified: trunk/src/minimap.cxx
===================================================================
--- trunk/src/minimap.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/minimap.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -27,7 +27,7 @@
#include "tileset.hxx"
#include "editor_map.hxx"
#include "editor_map_component.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "workspace.hxx"
#include "minimap.hxx"
@@ -66,7 +66,7 @@
}
// FIXME: This doesn't work all that well
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::current();
int tile_size = tilemap->get_tileset()->get_tile_size();
if (tilemap && tilemap->get_height() != 0 && tilemap->get_width() != 0)
@@ -114,7 +114,7 @@
Minimap::update_minimap_surface()
{
// FIXME: This doesn't work all that well
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::current();
if (tilemap)
{
@@ -155,7 +155,7 @@
Minimap::mouse_move(const CL_InputEvent& event)
{
// FIXME: This doesn't work all that well
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::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
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::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 01:05:27 UTC (rev 327)
+++ trunk/src/paint_command.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -22,10 +22,10 @@
#include <sstream>
#include <ClanLib/Core/core_iostream.h>
#include <ClanLib/Core/Math/rect.h>
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "paint_command.hxx"
-PaintCommand::PaintCommand(EditorTileMap* t, const TileBrush& b)
+PaintCommand::PaintCommand(TileMap* t, const TileBrush& b)
: tilemap(t), field(t->get_map()), brush(b)
{
undo_field = *field;
@@ -91,13 +91,13 @@
void
PaintCommand::redo()
{
- EditorTileMap::draw_tile(field, *redo_brush, pos);
+ TileMap::draw_tile(field, *redo_brush, pos);
}
void
PaintCommand::undo()
{
- EditorTileMap::draw_tile(field, *undo_brush, pos);
+ TileMap::draw_tile(field, *undo_brush, pos);
}
std::string
Modified: trunk/src/paint_command.hxx
===================================================================
--- trunk/src/paint_command.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/paint_command.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -26,19 +26,19 @@
#include "tile_brush.hxx"
#include "command.hxx"
-class EditorTileMap;
+class TileMap;
-/** The PaintCommand provides functionality to draw onto an
- EditorTileMap. 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 drawing are handled by the PaintCommand itself. */
+/** 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
+ drawing are handled by the PaintCommand itself. */
class PaintCommand : public Command
{
private:
typedef std::vector<CL_Point> Points;
Points points;
- EditorTileMap* tilemap;
+ TileMap* tilemap;
Field<int>* field;
TileBrush brush;
Field<int> undo_field;
@@ -49,7 +49,7 @@
public:
PaintCommand(Field<int>* f, const TileBrush& b);
- PaintCommand(EditorTileMap* t, const TileBrush& b);
+ PaintCommand(TileMap* 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 01:05:27 UTC (rev 327)
+++ trunk/src/scripting/editor.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -34,7 +34,7 @@
#include "../editor.hxx"
#include "../tile_selector.hxx"
#include "../objmap_select_tool.hxx"
-#include "../editor_tilemap.hxx"
+#include "../tilemap.hxx"
#include "../object_selector.hxx"
#include "../editor_map.hxx"
#include "../editor_map_component.hxx"
@@ -58,7 +58,7 @@
#include "../editor_mapsize_layer.hxx"
#include "../editor_objmap.hxx"
#include "../editor_grid_layer.hxx"
-#include "../editor_tilemap.hxx"
+#include "../tilemap.hxx"
#include "../python_functor.hxx"
#include "editor.hxx"
@@ -208,7 +208,7 @@
void
editor_toggle_grid(EditorMapLayer* layer)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(layer);
+ TileMap* tilemap = dynamic_cast<TileMap*>(layer);
if (tilemap)
tilemap->set_draw_grid(!tilemap->get_draw_grid());
}
@@ -216,7 +216,7 @@
void
editor_toggle_attributes(EditorMapLayer* layer)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(layer);
+ TileMap* tilemap = dynamic_cast<TileMap*>(layer);
if (tilemap)
tilemap->set_draw_attribute(!tilemap->get_draw_attribute());
}
@@ -318,8 +318,8 @@
void
editor_tilemap_set_current(EditorMapLayer* layer)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(layer);
- EditorTileMap::set_current(tilemap);
+ TileMap* tilemap = dynamic_cast<TileMap*>(layer);
+ TileMap::set_current(tilemap);
}
int
@@ -471,7 +471,7 @@
void
editor_tilemap_resize(EditorMapLayer* m, int w, int h, int x, int y)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(m);
+ TileMap* tilemap = dynamic_cast<TileMap*>(m);
if (tilemap)
{
tilemap->resize(CL_Size(w, h), CL_Point(x, y));
@@ -487,7 +487,7 @@
void
tilemap_paint_tool_set_tilemap(EditorMapLayer* layer)
{
-
TileMapPaintTool::current()->set_tilemap(dynamic_cast<EditorTileMap*>(layer));
+ TileMapPaintTool::current()->set_tilemap(dynamic_cast<TileMap*>(layer));
}
#ifdef SWIGGUILE
@@ -811,13 +811,13 @@
EditorMapLayer*
editor_tilemap_create(Tileset* tileset, int w, int h, int tile_size)
{
- return new EditorTileMap(tileset, w, h);
+ return new TileMap(tileset, w, h);
}
void
editor_tilemap_save_png(EditorMapLayer* l, const char* filename)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
CL_PixelBuffer pixelbuffer = tilemap->create_pixelbuffer();
pixelbuffer.lock();
@@ -840,7 +840,7 @@
int
editor_tilemap_get_width(EditorMapLayer* l)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
return tilemap->get_width();
else
@@ -850,7 +850,7 @@
int
editor_tilemap_get_height(EditorMapLayer* l)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
return tilemap->get_height();
else
@@ -860,7 +860,7 @@
void
editor_tilemap_set_bgcolor(EditorMapLayer* l, int r, int g, int b, int a)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
{
tilemap->set_background_color(CL_Color(r, g, b, a));
@@ -870,7 +870,7 @@
void
editor_tilemap_set_fgcolor(EditorMapLayer* l, int r, int g, int b, int a)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
{
tilemap->set_foreground_color(CL_Color(r, g, b, a));
@@ -881,7 +881,7 @@
SCM
editor_tilemap_get_data(EditorMapLayer* l)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
{
Field<int>* field = tilemap->get_map();
@@ -901,7 +901,7 @@
void
editor_tilemap_set_data(EditorMapLayer* l, SCM lst)
{
- EditorTileMap* tilemap = dynamic_cast<EditorTileMap*>(l);
+ TileMap* tilemap = dynamic_cast<TileMap*>(l);
if (tilemap)
{
Field<int>* field = tilemap->get_map();
Modified: trunk/src/tile_selection.cxx
===================================================================
--- trunk/src/tile_selection.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tile_selection.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -21,7 +21,7 @@
#include <iostream>
#include <ClanLib/Core/core_iostream.h>
#include "math.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "tileset.hxx"
#include "tile_selection.hxx"
@@ -35,7 +35,7 @@
}
void
-TileSelection::start(EditorTileMap* tilemap_, const CL_Point& pos)
+TileSelection::start(TileMap* tilemap_, const CL_Point& pos)
{
tilemap = tilemap_;
active = true;
Modified: trunk/src/tile_selection.hxx
===================================================================
--- trunk/src/tile_selection.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tile_selection.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -25,7 +25,7 @@
#include <ClanLib/Core/Math/point.h>
#include "tile_brush.hxx"
-class EditorTileMap;
+class TileMap;
/** The TileSelection is a little helper class to manage rectangular
selections of tiles and provides a way to convert this selection
@@ -34,7 +34,7 @@
class TileSelection
{
private:
- EditorTileMap* tilemap;
+ TileMap* tilemap;
CL_Point start_pos;
CL_Rect selection;
bool active;
@@ -42,7 +42,7 @@
TileSelection();
~TileSelection();
- void start (EditorTileMap* tilemap, const CL_Point& pos);
+ void start (TileMap* tilemap, const CL_Point& pos);
void update(const CL_Point& pos);
void clear();
Copied: trunk/src/tilemap.cxx (from rev 325, trunk/src/editor_tilemap.cxx)
===================================================================
--- trunk/src/editor_tilemap.cxx 2004-05-14 23:38:21 UTC (rev 325)
+++ trunk/src/tilemap.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -0,0 +1,366 @@
+// $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.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;
+}
+
+void
+blit(CL_PixelBuffer& target, CL_PixelBuffer& brush, int x_pos, int y_pos)
+{
+ target.lock();
+ brush.lock();
+
+ int start_x = std::max(0, -x_pos);
+ int start_y = std::max(0, -y_pos);
+
+ int end_x = std::min(brush.get_width(), target.get_width() - x_pos);
+ int end_y = std::min(brush.get_height(), target.get_height() - y_pos);
+
+ unsigned char* target_buf = static_cast<unsigned char*>(target.get_data());
+ unsigned char* brush_buf = static_cast<unsigned char*>(brush.get_data());
+
+ int target_width = target.get_width();
+ int brush_width = brush.get_width();
+
+ if (brush.get_format().get_type() == pixelformat_rgba)
+ {
+ if (brush.get_format().get_depth() == 32)
+ {
+ for (int y = start_y; y < end_y; ++y)
+ for (int x = start_x; x < end_x; ++x)
+ {
+ int target_pos = (y + y_pos) * target_width + x + x_pos;
+ int brush_pos = y * brush_width + x;
+
+ unsigned char a = brush_buf[4*brush_pos + 0];
+ unsigned char r = brush_buf[4*brush_pos + 1];
+ unsigned char g = brush_buf[4*brush_pos + 2];
+ unsigned char b = brush_buf[4*brush_pos + 3];
+
+ unsigned char ta = target_buf[4*target_pos + 0];
+ unsigned char tr = target_buf[4*target_pos + 1];
+ unsigned char tg = target_buf[4*target_pos + 2];
+ unsigned char tb = target_buf[4*target_pos + 3];
+
+ float alpha = a/255.0f;
+
+ target_buf[4*target_pos + 0] = std::min(255, ta + a);
+ target_buf[4*target_pos + 1] = std::min(255, int((1-alpha)*tr
+ alpha*r));
+ target_buf[4*target_pos + 2] = std::min(255, int((1-alpha)*tg
+ alpha*g));
+ target_buf[4*target_pos + 3] = std::min(255, int((1-alpha)*tb
+ alpha*b));
+ }
+ }
+ else if (brush.get_format().get_depth() == 24)
+ {
+ for (int y = start_y; y < end_y; ++y)
+ for (int x = start_x; x < end_x; ++x)
+ {
+ int target_pos = (y + y_pos) * target_width + x + x_pos;
+ int brush_pos = y * brush_width + x;
+
+ target_buf[4*target_pos + 0] = 255;
+ target_buf[4*target_pos + 1] = brush_buf[3*brush_pos + 0];
+ target_buf[4*target_pos + 2] = brush_buf[3*brush_pos + 1];
+ target_buf[4*target_pos + 3] = brush_buf[3*brush_pos + 2];
+ }
+ }
+ else
+ {
+ std::cout << "Unsupported bpp: " << brush.get_format().get_depth()
<< std::endl;
+ }
+ }
+ else if (brush.get_format().get_type() == pixelformat_index)
+ {
+ CL_Palette palette = brush.get_palette();
+ for (int y = start_y; y < end_y; ++y)
+ for (int x = start_x; x < end_x; ++x)
+ {
+ int target_pos = (y + y_pos) * target_width + x + x_pos;
+ int brush_pos = y * brush_width + x;
+
+ target_buf[4*target_pos + 0] = 255;
+ target_buf[4*target_pos + 1] =
palette.colors[brush_buf[brush_pos]].get_blue();
+ target_buf[4*target_pos + 2] =
palette.colors[brush_buf[brush_pos]].get_green();
+ target_buf[4*target_pos + 3] =
palette.colors[brush_buf[brush_pos]].get_red();
+ }
+ }
+ else
+ {
+ assert(!"Unknown pixelformat type");
+ }
+
+
+
+ brush.unlock();
+ target.unlock();
+}
+
+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 */
Copied: trunk/src/tilemap.hxx (from rev 327, trunk/src/editor_tilemap.hxx)
===================================================================
--- trunk/src/editor_tilemap.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tilemap.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -0,0 +1,112 @@
+// $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 */
Modified: trunk/src/tilemap_paint_tool.cxx
===================================================================
--- trunk/src/tilemap_paint_tool.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tilemap_paint_tool.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -23,7 +23,7 @@
#include <ClanLib/Display/keys.h>
#include <ClanLib/Display/display.h>
#include "globals.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "tileset.hxx"
#include "editor_map.hxx"
#include "editor_map_component.hxx"
Modified: trunk/src/tilemap_paint_tool.hxx
===================================================================
--- trunk/src/tilemap_paint_tool.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tilemap_paint_tool.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -25,7 +25,7 @@
#include "tilemap_tool.hxx"
class PaintCommand;
-class EditorTileMap;
+class TileMap;
/** */
class TileMapPaintTool : public TileMapTool
@@ -40,7 +40,7 @@
PaintCommand* command;
- EditorTileMap* tilemap;
+ TileMap* 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(EditorTileMap* t) { tilemap = t; }
+ void set_tilemap(TileMap* 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 01:05:27 UTC (rev 327)
+++ trunk/src/tilemap_select_tool.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -21,7 +21,7 @@
#include <ClanLib/Display/keys.h>
#include <ClanLib/Display/input_event.h>
#include "globals.hxx"
-#include "editor_tilemap.hxx"
+#include "tilemap.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(EditorTileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
+
selection.update(TileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
break;
}
}
@@ -73,7 +73,7 @@
{
creating_selection = true;
parent->capture_mouse();
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::current();
selection.start(tilemap,
tilemap->world2tile(parent->screen2world(event.mouse_pos)));
}
break;
@@ -92,14 +92,14 @@
if (creating_selection)
{
-
selection.update(EditorTileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
+
selection.update(TileMap::current()->world2tile(parent->screen2world(event.mouse_pos)));
}
}
TileBrush
TileMapSelectTool::get_selection() const
{
- EditorTileMap* tilemap = EditorTileMap::current();
+ TileMap* tilemap = TileMap::current();
return selection.get_brush(*tilemap->get_field());
}
Modified: trunk/src/tilemap_select_tool.hxx
===================================================================
--- trunk/src/tilemap_select_tool.hxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tilemap_select_tool.hxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -22,7 +22,7 @@
#include <ClanLib/Core/Math/rect.h>
#include <ClanLib/Core/Math/point.h>
-#include "editor_tilemap.hxx"
+#include "tilemap.hxx"
#include "tile_selection.hxx"
#include "tilemap_tool.hxx"
Modified: trunk/src/tool_manager.cxx
===================================================================
--- trunk/src/tool_manager.cxx 2004-05-15 01:05:27 UTC (rev 327)
+++ trunk/src/tool_manager.cxx 2004-05-15 11:52:53 UTC (rev 328)
@@ -22,7 +22,7 @@
#include "tilemap_select_tool.hxx"
#include "objmap_select_tool.hxx"
#include "zoom_tool.hxx"
-#include "editor_tilemap.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 328 - in trunk/src: . scripting,
Ingo Ruhnke <=