From 67a40ebb46ba3daabaf6e029dab37200fc562ac9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20=C5=9Aniatowski?= Date: Mon, 7 Jul 2008 14:54:13 +0100 Subject: [PATCH] editor2: Add selection handling in editor_map and editor_display --- src/editor2/editor_display.cpp | 6 ++++-- src/editor2/editor_display.hpp | 4 +++- src/editor2/editor_map.cpp | 26 ++++++++++++++++++++++++++ src/editor2/editor_map.hpp | 10 ++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/src/editor2/editor_display.cpp b/src/editor2/editor_display.cpp index d5fc8d375e3..29e62440b90 100644 --- a/src/editor2/editor_display.cpp +++ b/src/editor2/editor_display.cpp @@ -17,7 +17,7 @@ namespace editor2 { -editor_display::editor_display(CVideo& video, const gamemap& map, +editor_display::editor_display(CVideo& video, const editor_map& map, const config& theme_cfg, const config& cfg, const config& level) : display(video, map, theme_cfg, cfg, level) @@ -35,7 +35,9 @@ image::TYPE editor_display::get_image_type(const gamemap::location& loc) return image::BRIGHTENED; } else if (highlighted_locations_.find(loc) != highlighted_locations_.end()) { return image::SEMI_BRIGHTENED; - } + } else if (map().in_selection(loc)) { + return image::SEMI_BRIGHTENED; + } return image::SCALED_TO_HEX; } diff --git a/src/editor2/editor_display.hpp b/src/editor2/editor_display.hpp index 4bc4a3639ed..dee3ae7bc67 100644 --- a/src/editor2/editor_display.hpp +++ b/src/editor2/editor_display.hpp @@ -14,6 +14,7 @@ #ifndef EDITOR2_EDITOR_DISPLAY_HPP_INCLUDED #define EDITOR2_EDITOR_DISPLAY_HPP_INCLUDED +#include "editor_map.hpp" #include "../display.hpp" namespace editor2 { @@ -21,12 +22,13 @@ namespace editor2 { class editor_display : public display { public: - editor_display(CVideo& video, const gamemap& map, const config& theme_cfg, + editor_display(CVideo& video, const editor_map& map, const config& theme_cfg, const config& cfg, const config& level); bool in_editor() const { return true; } protected: + const editor_map& map() { return static_cast(map_); } void pre_draw(); /** * The editor uses different rules for terrain highligting (e.g. selections) diff --git a/src/editor2/editor_map.cpp b/src/editor2/editor_map.cpp index eba457b4455..0a08c99a6b3 100644 --- a/src/editor2/editor_map.cpp +++ b/src/editor2/editor_map.cpp @@ -55,4 +55,30 @@ std::vector editor_map::get_tiles_in_radius(const gamemap::lo return res; } +bool editor_map::in_selection(const gamemap::location& loc) const +{ + return selection_.find(loc) != selection_.end(); +} +bool editor_map::add_to_selection(const gamemap::location& loc) +{ + return selection_.insert(loc).second; +} +bool editor_map::remove_from_selection(const gamemap::location& loc) +{ + return selection_.erase(loc); +} +void editor_map::clear_selection() +{ + selection_.clear(); +} +void editor_map::invert_selection() +{ + +} +void editor_map::select_all() +{ + clear_selection(); + invert_selection(); +} + } //end namespace editor2 diff --git a/src/editor2/editor_map.hpp b/src/editor2/editor_map.hpp index 5035ee85fc2..ff1b175cad5 100644 --- a/src/editor2/editor_map.hpp +++ b/src/editor2/editor_map.hpp @@ -29,6 +29,16 @@ public: editor_map(const config& terrain_cfg, const std::string& data); std::vector get_tiles_in_radius(const gamemap::location& center, const unsigned int radius); static editor_map new_map(const config& terrain_cfg, size_t width, size_t height, t_translation::t_terrain filler); + + bool in_selection(const gamemap::location& loc) const; + bool add_to_selection(const gamemap::location& loc); + bool remove_from_selection(const gamemap::location& loc); + const std::set selection() const { return selection_; } + void clear_selection(); + void invert_selection(); + void select_all(); +protected: + std::set selection_; };