Fix drawing issues with the editor tools.

This commit is contained in:
fendrin 2013-05-03 20:43:53 +02:00
parent 8ab9659f36
commit 734d30dbf9
6 changed files with 104 additions and 110 deletions

View file

@ -257,66 +257,34 @@ editor_action_select* editor_action_select::clone() const
{
return new editor_action_select(*this);
}
void editor_action_select::extend(const editor_map& map, const std::set<map_location>& locs)
void editor_action_select::extend(const editor_map& /*map*/, const std::set<map_location>& locs)
{
BOOST_FOREACH(const map_location& loc, locs) {
LOG_ED << "Checking " << loc << "\n";
if (map.in_selection(loc)) {
LOG_ED << "Extending by " << loc << "\n";
area_.insert(loc);
}
LOG_ED << "Extending by " << loc << "\n";
area_.insert(loc);
}
}
editor_action* editor_action_select::perform(map_context& mc) const
{
std::set<map_location> undo_locs;
BOOST_FOREACH(const map_location& loc, area_) {
if (!mc.get_map().in_selection(loc)) {
undo_locs.insert(loc);
mc.add_changed_location(loc);
}
}
perform_without_undo(mc);
return new editor_action_deselect(undo_locs);
}
void editor_action_select::perform_without_undo(map_context& mc) const
{
BOOST_FOREACH(const map_location& loc, area_) {
mc.get_map().add_to_selection(loc);
undo_locs.insert(loc);
mc.add_changed_location(loc);
}
}
editor_action_deselect* editor_action_deselect::clone() const
{
return new editor_action_deselect(*this);
}
void editor_action_deselect::extend(const editor_map& map, const std::set<map_location>& locs)
{
BOOST_FOREACH(const map_location& loc, locs) {
LOG_ED << "Checking " << loc << "\n";
if (!map.in_selection(loc)) {
LOG_ED << "Extending by " << loc << "\n";
area_.insert(loc);
}
}
}
editor_action* editor_action_deselect::perform(map_context& mc) const
{
std::set<map_location> undo_locs;
BOOST_FOREACH(const map_location& loc, area_) {
if (mc.get_map().in_selection(loc)) {
undo_locs.insert(loc);
mc.add_changed_location(loc);
}
}
perform_without_undo(mc);
return new editor_action_select(undo_locs);
}
void editor_action_deselect::perform_without_undo(map_context& mc) const
void editor_action_select::perform_without_undo(map_context& mc) const
{
BOOST_FOREACH(const map_location& loc, area_) {
mc.get_map().remove_from_selection(loc);
// if (undo_locs)
if (!mc.get_map().in_selection(loc))
mc.get_map().add_to_selection(loc);
else
mc.get_map().remove_from_selection(loc);
mc.add_changed_location(loc);
}
}
@ -325,7 +293,7 @@ editor_action_select_all* editor_action_select_all::clone() const
{
return new editor_action_select_all(*this);
}
editor_action_deselect* editor_action_select_all::perform(map_context& mc) const
editor_action_select* editor_action_select_all::perform(map_context& mc) const
{
std::set<map_location> current = mc.get_map().selection();
mc.get_map().select_all();
@ -335,7 +303,7 @@ editor_action_deselect* editor_action_select_all::perform(map_context& mc) const
current.begin(), current.end(),
std::inserter(undo_locs, undo_locs.begin()));
mc.set_everything_changed();
return new editor_action_deselect(undo_locs);
return new editor_action_select(undo_locs);
}
void editor_action_select_all::perform_without_undo(map_context& mc) const
{

View file

@ -313,23 +313,6 @@ class editor_action_select : public editor_action_area
const char* get_name() const { return "select"; }
};
/**
* Deselect the given locations
*/
class editor_action_deselect : public editor_action_area
{
public:
editor_action_deselect(const std::set<map_location>& area)
: editor_action_area(area)
{
}
editor_action_deselect* clone() const;
void extend(const editor_map& map, const std::set<map_location>& locs);
editor_action* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "deselect"; }
};
/**
* Select the entire map
*/
@ -340,7 +323,7 @@ class editor_action_select_all : public editor_action
{
}
editor_action_select_all* clone() const;
editor_action_deselect* perform(map_context& mc) const;
editor_action_select* perform(map_context& mc) const;
void perform_without_undo(map_context& mc) const;
const char* get_name() const { return "select_all"; }
};

View file

@ -179,7 +179,7 @@ void mouse_action::set_terrain_mouse_overlay(editor_display& disp, const t_trans
SDL_Rect rcDestLeft = create_rect(offset, quarter_size, 0, 0);
sdl_blit ( image_fg, NULL, image, &rcDestLeft );
// Blit left side
// Blit right side
image_bg = scale_surface(image_bg, new_size, new_size);
SDL_Rect rcDestRight = create_rect(half_size, quarter_size, 0, 0);
sdl_blit ( image_bg, NULL, image, &rcDestRight );
@ -327,9 +327,9 @@ editor_action* mouse_action_select::click_perform_left(
}
editor_action* mouse_action_select::click_perform_right(
editor_display& /*disp*/, const std::set<map_location>& hexes)
editor_display& /*disp*/, const std::set<map_location>& /*hexes*/)
{
return new editor_action_chain(new editor_action_deselect(hexes));
return NULL;
}
void mouse_action_select::set_mouse_overlay(editor_display& disp)
@ -373,6 +373,12 @@ editor_action* mouse_action_paste::click_right(editor_display& /*disp*/, int /*x
return NULL;
}
editor_action* mouse_action_select::click_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
{
return NULL;
}
void mouse_action_paste::set_mouse_overlay(editor_display& disp)
{
disp.set_mouseover_hex_overlay(NULL); //TODO

View file

@ -51,7 +51,7 @@ public:
/**
* Mouse move (not a drag). Never changes anything (other than temporary highlihts and similar)
*/
void move(editor_display& disp, const map_location& hex);
virtual void move(editor_display& disp, const map_location& hex);
/**
* Unconditionally update the brush highlights for the current tool when hex is the center location
@ -312,6 +312,12 @@ public:
*/
editor_action* click_perform_left(editor_display& disp, const std::set<map_location>& hexes);
/**
* Right click does nothing for now
*/
editor_action* click_right(editor_display& disp, int x, int y);
/**
* Right click/drag deselects
*/
@ -319,6 +325,7 @@ public:
virtual void set_mouse_overlay(editor_display& disp);
bool has_context_menu() const { return true; };
bool supports_brushes() { return true; }
};

View file

@ -20,9 +20,29 @@
#include "../../editor_display.hpp"
#include "gui/dialogs/unit_create.hpp"
#include "map_location.hpp"
namespace editor {
void mouse_action_unit::move(editor_display& disp, const map_location& hex)
{
if (hex != previous_move_hex_) {
update_brush_highlights(disp, hex);
std::set<map_location> adjacent_set;
map_location adjacent[6];
get_adjacent_tiles(previous_move_hex_, adjacent);
for (int i = 0; i < 6; i++)
adjacent_set.insert(adjacent[i]);
disp.invalidate(adjacent_set);
previous_move_hex_ = hex;
}
}
editor_action* mouse_action_unit::click_left(editor_display& disp, int x, int y)
{
start_hex_ = disp.hex_clicked_on(x, y);
@ -30,17 +50,10 @@ editor_action* mouse_action_unit::click_left(editor_display& disp, int x, int y)
return NULL;
}
// const unit_map& units = disp.map().get_units();
// const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
// if (unit_it != units.end()) {
// std::stringstream filename;
// filename << unit_it->absolute_image() << unit_it->image_mods();
// surface image(image::get_image(filename.str()));
// disp.set_mouseover_hex_overlay(image);
//TODO set the mouse pointer to a dragging one.
//}
const unit_map& units = disp.get_units();
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it != units.end())
set_unit_mouse_overlay(disp, unit_it->type());
click_ = true;
return NULL;
@ -56,6 +69,7 @@ editor_action* mouse_action_unit::drag_left(editor_display& disp, int x, int y,
editor_action* mouse_action_unit::up_left(editor_display& disp, int x, int y)
{
if (!click_) return NULL;
click_ = false;
map_location hex = disp.hex_clicked_on(x, y);
if (!disp.get_map().on_board(hex)) {
return NULL;
@ -91,10 +105,10 @@ editor_action* mouse_action_unit::drag_end_left(editor_display& disp, int x, int
if (!disp.get_map().on_board(hex))
return NULL;
//const unit_map& units = disp.map().get_units();
//const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
//if (unit_it == units.end())
// return NULL;
const unit_map& units = disp.get_units();
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it == units.end())
return NULL;
action = new editor_action_unit_replace(start_hex_, hex);
return action;
@ -107,13 +121,13 @@ editor_action* mouse_action_unit::click_right(editor_display& disp, int x, int y
start_hex_ = hex;
previous_move_hex_ = hex;
//const unit_map& units = disp.get_editor_map().get_const_units();
//const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
/*
const unit_map& units = disp.get_units();
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it != units.end()) {
old_direction_ = unit_it->facing();
}
*/
click_ = true;
return NULL;
}
@ -127,32 +141,32 @@ editor_action* mouse_action_unit::drag_right(editor_display& disp, int x, int y,
click_ = (start_hex_ == hex);
previous_move_hex_ = hex;
//const unit_map& units = disp.map().get_units();
const unit_map& units = disp.get_units();
//const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
//if (unit_it != units.end()) {
// for (map_location::DIRECTION new_direction = map_location::NORTH;
// new_direction <= map_location::NORTH_WEST;
// new_direction = map_location::DIRECTION(new_direction +1)){
// if (unit_it->get_location().get_direction(new_direction, 1) == hex) {
// return new editor_action_unit_facing(start_hex_, new_direction, old_direction_);
// }
// }
//}
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it != units.end()) {
for (map_location::DIRECTION new_direction = map_location::NORTH;
new_direction <= map_location::NORTH_WEST;
new_direction = map_location::DIRECTION(new_direction +1)){
if (unit_it->get_location().get_direction(new_direction, 1) == hex) {
return new editor_action_unit_facing(start_hex_, new_direction, old_direction_);
}
}
}
return NULL;
}
editor_action* mouse_action_unit::up_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
editor_action* mouse_action_unit::up_right(editor_display& disp, int /*x*/, int /*y*/)
{
if (!click_) return NULL;
click_ = false;
//const unit_map& units = disp.map().get_units();
//const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
//if (unit_it != units.end()) {
// return new editor_action_unit_delete(start_hex_);
//}
const unit_map& units = disp.get_units();
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it != units.end()) {
return new editor_action_unit_delete(start_hex_);
}
return NULL;
}
@ -167,11 +181,11 @@ editor_action* mouse_action_unit::drag_end_right(editor_display& disp, int x, in
if(new_direction_ != old_direction_) {
//const unit_map& units = disp.map().get_units();
//const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
// if (unit_it != units.end()) {
// return new editor_action_unit_facing(start_hex_, new_direction_, old_direction_);
// }
const unit_map& units = disp.get_units();
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
if (unit_it != units.end()) {
return new editor_action_unit_facing(start_hex_, new_direction_, old_direction_);
}
}
return NULL;
@ -181,12 +195,25 @@ editor_action* mouse_action_unit::drag_end_right(editor_display& disp, int x, in
void mouse_action_unit::set_mouse_overlay(editor_display& disp)
{
const unit_type& u = unit_palette_.selected_fg_item();
set_unit_mouse_overlay(disp, u);
}
void mouse_action_unit::set_unit_mouse_overlay(editor_display& disp, const unit_type& u)
{
std::stringstream filename;
filename << u.image() << "~RC(" << u.flag_rgb() << '>'
<< team::get_side_color_index(disp.viewing_side()) << ')';
surface image(image::get_image(filename.str()));
Uint8 alpha = 196;
//TODO don't hardcode
int size = 72;
//int size = image->w;
int zoom = static_cast<int>(size * disp.get_zoom_factor());
// Add the alpha factor and scale the image
image = scale_surface(adjust_surface_alpha(image, alpha), zoom, zoom);
disp.set_mouseover_hex_overlay(image);
}

View file

@ -38,6 +38,8 @@ public:
{
}
void move(editor_display& disp, const map_location& hex);
/**
* TODO
*/
@ -79,6 +81,7 @@ public:
editor_action* drag_end_right(editor_display& disp, int x, int y);
virtual void set_mouse_overlay(editor_display& disp);
void set_unit_mouse_overlay(editor_display& disp, const unit_type& u);
private:
bool click_;