Added Undoable::deselect_mask() member function.

This commit is contained in:
David Capello 2010-03-01 23:01:43 -02:00
parent c4afb1a236
commit cc7fd95559
3 changed files with 34 additions and 30 deletions

View File

@ -22,8 +22,8 @@
#include "modules/gui.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "raster/undo.h"
#include "sprite_wrappers.h"
#include "undoable.h"
//////////////////////////////////////////////////////////////////////
// deselect_mask
@ -46,38 +46,20 @@ DeselectMaskCommand::DeselectMaskCommand()
{
}
bool DeselectMaskCommand::enabled(Context* context)
{
const CurrentSpriteReader sprite(context);
return sprite && !sprite->mask->is_empty();
}
void DeselectMaskCommand::execute(Context* context)
bool DeselectMaskCommand::enabled(Context* context)
{
const CurrentSpriteReader sprite(context);
return sprite && !sprite->mask->is_empty();
}
void DeselectMaskCommand::execute(Context* context)
{
CurrentSpriteWriter sprite(context);
Mask *mask;
/* destroy the *deselected* mask */
mask = sprite_request_mask(sprite, "*deselected*");
if (mask) {
sprite_remove_mask(sprite, mask);
mask_free(mask);
{
Undoable undoable(sprite, "Mask Deselection");
undoable.deselect_mask();
undoable.commit();
}
/* save the selection in the repository */
mask = mask_new_copy(sprite->mask);
mask_set_name(mask, "*deselected*");
sprite_add_mask(sprite, mask);
/* undo */
if (undo_is_enabled(sprite->undo)) {
undo_set_label(sprite->undo, "Mask Deselection");
undo_set_mask(sprite->undo, sprite);
}
/* deselect the mask */
mask_none(sprite->mask);
sprite_generate_mask_boundaries(sprite);
update_screen_for_sprite(sprite);
}

View File

@ -1051,3 +1051,24 @@ void Undoable::set_mask_position(int x, int y)
m_sprite->mask->x = x;
m_sprite->mask->y = y;
}
void Undoable::deselect_mask()
{
// Destroy the *deselected* mask
Mask* mask = sprite_request_mask(m_sprite, "*deselected*");
if (mask) {
sprite_remove_mask(m_sprite, mask);
mask_free(mask);
}
// Save the selection in the repository
mask = mask_new_copy(m_sprite->mask);
mask_set_name(mask, "*deselected*");
sprite_add_mask(m_sprite, mask);
if (undo_is_enabled(m_sprite->undo))
undo_set_mask(m_sprite->undo, m_sprite);
/// Deselect the mask
mask_none(m_sprite->mask);
}

View File

@ -102,6 +102,7 @@ public:
// for mask
void copy_to_current_mask(Mask* mask);
void set_mask_position(int x, int y);
void deselect_mask();
};