aseprite/src/context.cpp
David Capello cb97884026 - All tools stuff refactored in various files/components.
- Added classes: IToolLoop, Tool, ToolGroup, ToolInk, ToolController, ToolPointShape, ToolIntertwine, ToolBox, etc.
- Added ToolLoopManager.
- Removed old src/modules/tools.cpp.
- Added ISettings and UISettingsImpl, adding the tools settings (onion skinning, grid, tiled mode, etc.).
- Added App::PenSizeBeforeChange, PenSizeAfterChange, CurrentToolChange signals.
- Renamed Context::get_bg/fg_color to getBg/FgColor.
- Refactored Brush class to Pen and added PenType.
- Renamed tiled_t to TiledMode.
- get_config_rect now uses the new Rect class imported from Vaca instead of old jrect.
- Added default_skin.xml to load tool icons.
- Added pen preview in Editor::cursor stuff.
- Added Editor::decorators.

Note: This big patch is from some time ago. I did my best to pre-commit other small changes before this big one.
2010-03-07 17:47:45 -02:00

171 lines
3.6 KiB
C++

/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 David Capello
*
* 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 "config.h"
#include <cassert>
#include <algorithm>
#include "console.h"
#include "context.h"
#include "commands/command.h"
#include "raster/sprite.h"
Context::Context(ISettings* settings)
{
m_currentSprite = NULL;
m_settings = settings;
}
Context::~Context()
{
for (SpriteList::iterator
it = m_sprites.begin(); it != m_sprites.end(); ++it) {
Sprite* sprite = *it;
delete sprite;
}
m_sprites.clear();
delete m_settings;
}
const SpriteList& Context::get_sprite_list() const
{
return m_sprites;
}
Sprite* Context::get_first_sprite() const
{
if (!m_sprites.empty())
return m_sprites.front();
else
return NULL;
}
Sprite* Context::get_next_sprite(Sprite* sprite) const
{
assert(sprite != NULL);
SpriteList::const_iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite);
if (it != m_sprites.end()) {
++it;
if (it != m_sprites.end())
return *it;
}
return NULL;
}
/**
* Append the sprite to the context's sprites' list.
*/
void Context::add_sprite(Sprite* sprite)
{
assert(sprite != NULL);
m_sprites.push_front(sprite);
// generate on_add_sprite event
on_add_sprite(sprite);
}
void Context::remove_sprite(Sprite* sprite)
{
assert(sprite != NULL);
SpriteList::iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite);
assert(it != m_sprites.end());
// remove the item from the sprites list
m_sprites.erase(it);
// generate on_remove_sprite event
on_remove_sprite(sprite);
// the current sprite cannot be the removed sprite anymore
if (m_currentSprite == sprite)
set_current_sprite(NULL);
}
void Context::send_sprite_to_top(Sprite* sprite)
{
assert(sprite);
SpriteList::iterator it = std::find(m_sprites.begin(), m_sprites.end(), sprite);
assert(it != m_sprites.end());
// remove the item from the sprites list
m_sprites.erase(it);
// add it again
m_sprites.push_front(sprite);
}
Sprite* Context::get_current_sprite() const
{
return m_currentSprite;
}
void Context::set_current_sprite(Sprite* sprite)
{
m_currentSprite = sprite;
on_set_current_sprite(sprite);
}
void Context::execute_command(Command* command, Params* params)
{
Console console;
assert(command != NULL);
try {
if (params)
command->load_params(params);
if (command->enabled(this))
command->execute(this);
}
catch (ase_exception& e) {
e.show();
}
catch (std::exception& e) {
console.printf("An error ocurred executing the command.\n\nDetails:\n%s", e.what());
}
catch (...) {
console.printf("An unknown error ocurred executing the command.\n"
"Please try again or report this bug.\n\n"
"Details: Unknown exception caught.");
}
}
void Context::on_add_sprite(Sprite* sprite)
{
// do nothing
}
void Context::on_remove_sprite(Sprite* sprite)
{
// do nothing
}
void Context::on_set_current_sprite(Sprite* sprite)
{
// do nothing
}