Author: ilor
Date: Sun Jul 13 00:28:19 2008
New Revision: 27956
URL: http://svn.gna.org/viewcvs/wesnoth?rev=27956&view=rev
Log:
add basic and partial brush support
Added:
trunk/src/editor2/brush.cpp (with props)
trunk/src/editor2/brush.hpp (with props)
Modified:
trunk/src/editor2/action.hpp
trunk/src/editor2/editor_controller.cpp
trunk/src/editor2/editor_controller.hpp
trunk/src/editor2/mouse_action.cpp
trunk/src/editor2/mouse_action.hpp
Modified: trunk/src/editor2/action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/action.hpp?rev=27956&r1=27955&r2=27956&view=diff
==============================================================================
--- trunk/src/editor2/action.hpp (original)
+++ trunk/src/editor2/action.hpp Sun Jul 13 00:28:19 2008
@@ -26,10 +26,6 @@
namespace editor2 {
-class brush
-{
-};
-
/**
* Replace contents of the entire map,
* Useful as a fallback undo method when something else would be impractical
@@ -168,14 +164,14 @@
{
public:
editor_action_paint_brush(gamemap::location loc,
- t_translation::t_terrain t, brush b)
+ t_translation::t_terrain t, const brush& b)
: editor_action_location_terrain(loc, t), b_(b)
{
}
editor_action_paste* perform(editor_map& map) const;
void perform_without_undo(editor_map& map) const;
protected:
- brush b_;
+ const brush& b_;
};
//flood fill
@@ -183,14 +179,12 @@
{
public:
editor_action_fill(gamemap::location loc,
- t_translation::t_terrain t, brush b)
- : editor_action_location_terrain(loc, t), b_(b)
+ t_translation::t_terrain t)
+ : editor_action_location_terrain(loc, t)
{
}
editor_action_fill* perform(editor_map& map) const;
void perform_without_undo(editor_map& map) const;
- protected:
- brush b_;
};
//resize map (streching / clipping behaviour?)
Added: trunk/src/editor2/brush.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/brush.cpp?rev=27956&view=auto
==============================================================================
--- trunk/src/editor2/brush.cpp (added)
+++ trunk/src/editor2/brush.cpp Sun Jul 13 00:28:19 2008
@@ -1,0 +1,63 @@
+/* $Id$ */
+/*
+ Copyright (C) 2008 by Tomasz Sniatowski <[EMAIL PROTECTED]>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+*/
+
+#include "brush.hpp"
+#include "editor_map.hpp"
+
+#include "../foreach.hpp"
+
+#include <vector>
+
+namespace editor2 {
+
+brush::brush()
+{
+}
+
+brush::brush(const config& cfg)
+{
+ int radius = lexical_cast_default<int>(cfg["radius"], 0);
+ if (radius > 0) {
+ std::vector<gamemap::location> in_radius =
+ editor_map::get_tiles_in_radius(gamemap::location(0,
0), radius);
+ foreach (gamemap::location& loc, in_radius) {
+ add_relative_location(loc.x, loc.y);
+ }
+ }
+ config::const_child_itors cfg_range = cfg.child_range("relative");
+ while (cfg_range.first != cfg_range.second) {
+ const config& relative = **cfg_range.first;
+ int x = lexical_cast_default<int>(relative["x"], 0);
+ int y = lexical_cast_default<int>(relative["y"], 0);
+ add_relative_location(x, y);
+ ++cfg_range.first;
+ }
+}
+
+void brush::add_relative_location(int relative_x, int relative_y)
+{
+ relative_tiles_.insert(gamemap::location(relative_x, relative_y));
+}
+
+std::set<gamemap::location> brush::project(const gamemap::location& hotspot)
const
+{
+ std::set<gamemap::location> result;
+ foreach (const gamemap::location& relative, relative_tiles_) {
+ result.insert(hotspot + relative);
+ }
+ return result;
+}
+
+
+} //end namespace editor2
Propchange: trunk/src/editor2/brush.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/editor2/brush.cpp
------------------------------------------------------------------------------
svn:keywords = 'Author Date Id Revision'
Added: trunk/src/editor2/brush.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/brush.hpp?rev=27956&view=auto
==============================================================================
--- trunk/src/editor2/brush.hpp (added)
+++ trunk/src/editor2/brush.hpp Sun Jul 13 00:28:19 2008
@@ -1,0 +1,57 @@
+/* $Id$ */
+/*
+ Copyright (C) 2008 by Tomasz Sniatowski <[EMAIL PROTECTED]>
+ Part of the Battle for Wesnoth Project http://www.wesnoth.org/
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2
+ or at your option any later version.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY.
+
+ See the COPYING file for more details.
+*/
+
+#ifndef EDITOR2_BRUSH_HPP_INCLUDED
+#define EDITOR2_BRUSH_HPP_INCLUDED
+
+#include "editor_map.hpp"
+
+#include "../config.hpp"
+
+#include <set>
+
+namespace editor2 {
+
+class brush
+{
+public:
+ /**
+ * Construct a default (empty) brush. Note that not even the hotspot is
affected by default
+ */
+ brush();
+
+ /**
+ * Construct a brush object from config
+ */
+ brush(const config& cfg);
+
+ /**
+ * Add a location to the brush. If it already exists nothing will
change.
+ */
+ void add_relative_location(int relative_x, int relative_y);
+
+ /**
+ * Get a set of locations affected (i.e. under the brush) when the
center (hotspot)
+ * is in given location
+ */
+ std::set<gamemap::location> project(const gamemap::location& hotspot)
const;
+
+protected:
+ std::set<gamemap::location> relative_tiles_;
+};
+
+
+} //end namespace editor2
+
+#endif
Propchange: trunk/src/editor2/brush.hpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: trunk/src/editor2/brush.hpp
------------------------------------------------------------------------------
svn:keywords = 'Author Date Id Revision'
Modified: trunk/src/editor2/editor_controller.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.cpp?rev=27956&r1=27955&r2=27956&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.cpp (original)
+++ trunk/src/editor2/editor_controller.cpp Sun Jul 13 00:28:19 2008
@@ -19,7 +19,6 @@
#include "../foreach.hpp"
#include "../hotkeys.hpp"
#include "../preferences.hpp"
-
#include "SDL.h"
@@ -42,6 +41,11 @@
gui_->invalidate_all();
gui_->draw();
events::raise_draw_event();
+ brushes_.push_back(brush());
+ brushes_[0].add_relative_location(0,0);
+ brushes_[0].add_relative_location(1,0);
+ brushes_[0].add_relative_location(-1,0);
+ set_brush(&brushes_[0]);
//redraw_everything();
}
@@ -210,6 +214,10 @@
} else {
LOG_ED << __FUNCTION__ << ": There is no mouse action
active!\n";
}
+ } else {
+ if (get_mouse_action() != NULL) {
+ get_mouse_action()->move(*gui_, x, y);
+ }
}
const gamemap::location new_hex = gui().hex_clicked_on(x,y);
gui().highlight_hex(new_hex);
Modified: trunk/src/editor2/editor_controller.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/editor_controller.hpp?rev=27956&r1=27955&r2=27956&view=diff
==============================================================================
--- trunk/src/editor2/editor_controller.hpp (original)
+++ trunk/src/editor2/editor_controller.hpp Sun Jul 13 00:28:19 2008
@@ -14,6 +14,7 @@
#ifndef EDITOR2_EDITOR_CONTROLLER_HPP_INCLUDED
#define EDITOR2_EDITOR_CONTROLLER_HPP_INCLUDED
+#include "brush.hpp"
#include "action_base.hpp"
#include "editor_common.hpp"
#include "editor_display.hpp"
@@ -133,6 +134,8 @@
* Action stack (i.e. undo and redo) maximum size
*/
static const int max_action_stack_size_;
+
+ std::vector<brush> brushes_;
};
} //end namespace editor2
Modified: trunk/src/editor2/mouse_action.cpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.cpp?rev=27956&r1=27955&r2=27956&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.cpp (original)
+++ trunk/src/editor2/mouse_action.cpp Sun Jul 13 00:28:19 2008
@@ -13,6 +13,7 @@
*/
#include "action.hpp"
+#include "brush.hpp"
#include "editor_common.hpp"
#include "editor_display.hpp"
#include "editor_mode.hpp"
@@ -22,6 +23,10 @@
namespace editor2 {
+void mouse_action::move(editor_display& disp, int x, int y)
+{
+}
+
editor_action* mouse_action::drag(editor_display& disp, int x, int y)
{
return NULL;
@@ -30,6 +35,16 @@
editor_action* mouse_action::drag_end(editor_display& disp, int x, int y)
{
return NULL;
+}
+
+void mouse_action_paint::move(editor_display& disp, int x, int y)
+{
+ disp.clear_highlighted_locs();
+ if (mode_.get_brush() != NULL) {
+ foreach (gamemap::location loc,
mode_.get_brush()->project(disp.hex_clicked_on(x,y))) {
+ disp.add_highlighted_loc(loc);
+ }
+ }
}
editor_action* mouse_action_paint::click(editor_display& disp, int x, int y)
Modified: trunk/src/editor2/mouse_action.hpp
URL:
http://svn.gna.org/viewcvs/wesnoth/trunk/src/editor2/mouse_action.hpp?rev=27956&r1=27955&r2=27956&view=diff
==============================================================================
--- trunk/src/editor2/mouse_action.hpp (original)
+++ trunk/src/editor2/mouse_action.hpp Sun Jul 13 00:28:19 2008
@@ -39,6 +39,8 @@
virtual ~mouse_action() {}
+ virtual void move(editor_display& disp, int x, int y);
+
/**
* A click, possibly the beginning of a drag
*/
@@ -65,6 +67,7 @@
: mouse_action(mode)
{
}
+ void move(editor_display& disp, int x, int y);
editor_action* click(editor_display& disp, int x, int y);
editor_action* drag(editor_display& disp, int x, int y);
editor_action* drag_end(editor_display& disp, int x, int y);
_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits