Move app::DocumentLocation to doc::Site

This is a first step to include the current selected range of layers
and frames inside the doc::Site structure. So in the future we'll not need
to know about the Timeline in commands that handle those ranges.
This commit is contained in:
David Capello 2015-04-20 16:27:09 -03:00
parent c5cf848d37
commit 21c4fd51d9
62 changed files with 375 additions and 340 deletions

View File

@ -233,7 +233,6 @@ add_library(app-lib
document.cpp
document_api.cpp
document_exporter.cpp
document_location.cpp
document_range.cpp
document_range_ops.cpp
document_undo.cpp

View File

@ -21,7 +21,6 @@
#include "app/console.h"
#include "app/crash/data_recovery.h"
#include "app/document_exporter.h"
#include "app/document_location.h"
#include "app/document_undo.h"
#include "app/file/file.h"
#include "app/file/file_formats_manager.h"
@ -65,6 +64,7 @@
#include "doc/image.h"
#include "doc/layer.h"
#include "doc/palette.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "render/render.h"
#include "scripting/engine.h"
@ -424,7 +424,7 @@ void App::initialize(const AppOptions& options)
// Scale all sprites
for (auto doc : ctx->documents()) {
ctx->setActiveDocument(doc);
ctx->setActiveDocument(static_cast<app::Document*>(doc));
ctx->executeCommand(command);
}
}
@ -664,9 +664,9 @@ void app_refresh_screen()
Context* context = UIContext::instance();
ASSERT(context != NULL);
DocumentLocation location = context->activeLocation();
Site site = context->activeSite();
if (Palette* pal = location.palette())
if (Palette* pal = site.palette())
set_current_palette(pal, false);
else
set_current_palette(NULL, false);

View File

@ -12,7 +12,7 @@
#include "app/cmd_transaction.h"
#include "app/context.h"
#include "app/document_location.h"
#include "doc/site.h"
namespace app {
@ -64,8 +64,8 @@ std::string CmdTransaction::onLabel() const
doc::SpritePosition CmdTransaction::calcSpritePosition()
{
app::DocumentLocation loc = context()->activeLocation();
return doc::SpritePosition(loc.layerIndex(), loc.frame());
doc::Site site = context()->activeSite();
return doc::SpritePosition(site.layerIndex(), site.frame());
}
} // namespace app

View File

@ -11,10 +11,10 @@
#include "app/color_picker.h"
#include "app/document_location.h"
#include "doc/cel.h"
#include "doc/image.h"
#include "doc/primitives.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "gfx/point.h"
#include "render/get_sprite_pixel.h"
@ -27,7 +27,7 @@ ColorPicker::ColorPicker()
{
}
void ColorPicker::pickColor(const DocumentLocation& location,
void ColorPicker::pickColor(const doc::Site& site,
const gfx::Point& pos, Mode mode)
{
m_alpha = 255;
@ -36,17 +36,17 @@ void ColorPicker::pickColor(const DocumentLocation& location,
// Get the color from the image
if (mode == FromComposition) { // Pick from the composed image
m_color = app::Color::fromImage(
location.sprite()->pixelFormat(),
render::get_sprite_pixel(location.sprite(), pos.x, pos.y, location.frame()));
site.sprite()->pixelFormat(),
render::get_sprite_pixel(site.sprite(), pos.x, pos.y, site.frame()));
doc::CelList cels;
location.sprite()->pickCels(pos.x, pos.y, location.frame(), 128, cels);
site.sprite()->pickCels(pos.x, pos.y, site.frame(), 128, cels);
if (!cels.empty())
m_layer = cels.front()->layer();
}
else { // Pick from the current layer
int u, v;
doc::Image* image = location.image(&u, &v, NULL);
doc::Image* image = site.image(&u, &v, NULL);
gfx::Point pt(pos.x-u, pos.y-v);
if (image && image->bounds().contains(pt)) {
@ -62,7 +62,7 @@ void ColorPicker::pickColor(const DocumentLocation& location,
}
m_color = app::Color::fromImage(image->pixelFormat(), imageColor);
m_layer = const_cast<Layer*>(location.layer());
m_layer = const_cast<Layer*>(site.layer());
}
}
}

View File

@ -13,8 +13,11 @@
#include "doc/layer.h"
#include "gfx/point.h"
namespace doc {
class Site;
}
namespace app {
class DocumentLocation;
class ColorPicker {
public:
@ -22,7 +25,7 @@ namespace app {
ColorPicker();
void pickColor(const DocumentLocation& location,
void pickColor(const doc::Site& site,
const gfx::Point& pos, Mode mode);
app::Color color() const { return m_color; }

View File

@ -12,7 +12,6 @@
#include "app/commands/command.h"
#include "app/context_access.h"
#include "app/document_api.h"
#include "app/document_location.h"
#include "app/modules/gui.h"
#include "app/settings/settings.h"
#include "app/ui/color_bar.h"

View File

@ -15,7 +15,6 @@
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/context_access.h"
#include "app/document_location.h"
#include "app/modules/gui.h"
#include "app/transaction.h"
#include "app/ui/color_bar.h"

View File

@ -54,7 +54,7 @@ void ClearCelCommand::onExecute(Context* context)
{
Transaction transaction(writer.context(), "Clear Cel");
// TODO the range of selected frames should be in the DocumentLocation.
// TODO the range of selected frames should be in doc::Site.
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
Sprite* sprite = writer.sprite();

View File

@ -58,7 +58,7 @@ public:
centerWindow();
load_window_pos(this, "ConfigureTool");
onSetActiveDocument(m_ctx->activeDocument());
onActiveDocumentChange(m_ctx->activeDocument());
}
~ToolsConfigurationWindow() {
@ -79,7 +79,7 @@ private:
return preferences().document(m_ctx->activeDocument());
}
void onSetActiveDocument(doc::Document* document) override {
void onActiveDocumentChange(doc::Document* document) override {
DocumentPreferences& docPref = this->docPref();
tiled()->setSelected(docPref.tiled.mode() != filters::TiledMode::NONE);

View File

@ -12,11 +12,13 @@
#include "app/app.h"
#include "app/commands/command.h"
#include "app/context_access.h"
#include "app/document.h"
#include "app/ui/main_window.h"
#include "app/ui/timeline.h"
#include "app/util/clipboard.h"
#include "doc/layer.h"
#include "doc/mask.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "ui/base.h"
@ -53,9 +55,9 @@ void CopyCommand::onExecute(Context* context)
if (range.enabled()) {
clipboard::copy_range(reader, range);
}
else if (reader.location()->document() &&
reader.location()->document()->isMaskVisible() &&
reader.location()->image()) {
else if (reader.site()->document() &&
static_cast<const app::Document*>(reader.site()->document())->isMaskVisible() &&
reader.site()->image()) {
clipboard::copy(reader);
}
}

View File

@ -14,7 +14,6 @@
#include "app/color_picker.h"
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/document_location.h"
#include "app/modules/editors.h"
#include "app/settings/settings.h"
#include "app/tools/tool.h"
@ -23,6 +22,7 @@
#include "app/ui/editor/editor.h"
#include "app/ui_context.h"
#include "doc/image.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "ui/manager.h"
#include "ui/system.h"
@ -80,7 +80,7 @@ void EyedropperCommand::onExecute(Context* context)
bool grabAlpha = settings->getGrabAlpha();
ColorPicker picker;
picker.pickColor(editor->getDocumentLocation(),
picker.pickColor(editor->getSite(),
pixelPos,
grabAlpha ?
ColorPicker::FromActiveLayer:

View File

@ -79,7 +79,7 @@ void FlipCommand::onExecute(Context* context)
Mask* mask = document->mask();
CelList cels;
DocumentLocation loc = *writer.location();
Site site = *writer.site();
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled())
cels = get_unique_cels(sprite, range);
@ -87,11 +87,11 @@ void FlipCommand::onExecute(Context* context)
cels.push_back(writer.cel());
for (Cel* cel : cels) {
loc.frame(cel->frame());
loc.layer(cel->layer());
site.frame(cel->frame());
site.layer(cel->layer());
int x, y;
Image* image = loc.image(&x, &y);
Image* image = site.image(&x, &y);
if (!image)
continue;

View File

@ -95,7 +95,7 @@ void FramePropertiesCommand::onExecute(Context* context)
break;
case CURRENT_RANGE: {
// TODO the range of selected frames should be in the DocumentLocation.
// TODO the range of selected frames should be in doc::Site.
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
firstFrame = range.frameBegin();

View File

@ -28,11 +28,11 @@ public:
}
protected:
void updateStatusBar(DocumentLocation& location) {
if (location.layer() != NULL)
void updateStatusBar(Site& site) {
if (site.layer() != NULL)
StatusBar::instance()
->setStatusText(1000, "Layer `%s' selected",
location.layer()->name().c_str());
site.layer()->name().c_str());
}
};
@ -63,19 +63,19 @@ void GotoPreviousLayerCommand::onExecute(Context* context)
{
const ContextReader reader(context);
const Sprite* sprite = reader.sprite();
DocumentLocation location = *reader.location();
Site site = *reader.site();
if (location.layerIndex() > 0)
location.layerIndex(location.layerIndex().previous());
if (site.layerIndex() > 0)
site.layerIndex(site.layerIndex().previous());
else
location.layerIndex(LayerIndex(sprite->countLayers()-1));
site.layerIndex(LayerIndex(sprite->countLayers()-1));
// Flash the current layer
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
current_editor->setLayer(location.layer());
current_editor->setLayer(site.layer());
current_editor->flashCurrentLayer();
updateStatusBar(location);
updateStatusBar(site);
}
class GotoNextLayerCommand : public GotoCommand {
@ -105,19 +105,19 @@ void GotoNextLayerCommand::onExecute(Context* context)
{
const ContextReader reader(context);
const Sprite* sprite = reader.sprite();
DocumentLocation location = *reader.location();
Site site = *reader.site();
if (location.layerIndex() < sprite->countLayers()-1)
location.layerIndex(location.layerIndex().next());
if (site.layerIndex() < sprite->countLayers()-1)
site.layerIndex(site.layerIndex().next());
else
location.layerIndex(LayerIndex(0));
site.layerIndex(LayerIndex(0));
// Flash the current layer
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
current_editor->setLayer(location.layer());
current_editor->setLayer(site.layer());
current_editor->flashCurrentLayer();
updateStatusBar(location);
updateStatusBar(site);
}
Command* CommandFactory::createGotoPreviousLayerCommand()

View File

@ -257,7 +257,7 @@ retry:;
try {
Sprite* sprite = document->sprite();
frame_t currentFrame = context->activeLocation().frame();
frame_t currentFrame = context->activeSite().frame();
render::Render render;
// As first step, we cut each tile and add them into "animation" list.

View File

@ -64,7 +64,7 @@ void MaskContentCommand::onExecute(Context* context)
gfx::Color color;
if (writer.layer()->isBackground()) {
ColorPicker picker;
picker.pickColor(*writer.location(), gfx::Point(0, 0), ColorPicker::FromComposition);
picker.pickColor(*writer.site(), gfx::Point(0, 0), ColorPicker::FromComposition);
color = color_utils::color_for_layer(picker.color(), writer.layer());
}
else

View File

@ -116,7 +116,7 @@ void NewFrameCommand::onExecute(Context* context)
StatusBar::instance()
->showTip(1000, "New frame %d/%d",
(int)context->activeLocation().frame()+1,
(int)context->activeSite().frame()+1,
(int)sprite->totalFrames());
App::instance()->getMainWindow()->popTimeline();

View File

@ -57,7 +57,7 @@ void RemoveFrameCommand::onExecute(Context* context)
Transaction transaction(writer.context(), "Remove Frame");
DocumentApi api = document->getApi(transaction);
// TODO the range of selected frames should be in the DocumentLocation.
// TODO the range of selected frames should be in doc::Site.
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
for (frame_t frame = range.frameEnd(),

View File

@ -62,7 +62,7 @@ void RemoveLayerCommand::onExecute(Context* context)
Transaction transaction(writer.context(), "Remove Layer");
DocumentApi api = document->getApi(transaction);
// TODO the range of selected layer should be in the DocumentLocation.
// TODO the range of selected layer should be in doc::Site.
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
if (range.layers() == sprite->countLayers()) {

View File

@ -70,8 +70,8 @@ void UndoCommand::onExecute(Context* context)
App::instance()->preferences().undo.gotoModified();
if (gotoModified) {
SpritePosition currentPosition(writer.location()->layerIndex(),
writer.location()->frame());
SpritePosition currentPosition(writer.site()->layerIndex(),
writer.site()->frame());
if (m_type == Undo)
spritePosition = undo->nextUndoSpritePosition();
@ -113,8 +113,8 @@ void UndoCommand::onExecute(Context* context)
// weren't able to reach before the undo).
if (gotoModified) {
SpritePosition currentPosition(
writer.location()->layerIndex(),
writer.location()->frame());
writer.site()->layerIndex(),
writer.site()->frame());
if (spritePosition != currentPosition) {
current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));

View File

@ -54,7 +54,7 @@ void UnlinkCelCommand::onExecute(Context* context)
{
Transaction transaction(writer.context(), "Unlink Cel");
// TODO the range of selected frames should be in the DocumentLocation.
// TODO the range of selected frames should be in doc::Site.
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
Sprite* sprite = writer.sprite();

View File

@ -27,6 +27,7 @@
#include "filters/replace_color_filter.h"
#include "doc/image.h"
#include "doc/mask.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "ui/ui.h"
@ -134,9 +135,9 @@ bool ReplaceColorCommand::onEnabled(Context* context)
void ReplaceColorCommand::onExecute(Context* context)
{
DocumentLocation location = context->activeLocation();
Site site = context->activeSite();
ReplaceColorFilterWrapper filter(location.layer());
ReplaceColorFilterWrapper filter(site.layer());
filter.setFrom(get_config_color(ConfigSection, "Color1", ColorBar::instance()->getFgColor()));
filter.setTo(get_config_color(ConfigSection, "Color2", ColorBar::instance()->getBgColor()));
filter.setTolerance(get_config_int(ConfigSection, "Tolerance", 0));

View File

@ -14,6 +14,7 @@
#include "app/cmd/copy_rect.h"
#include "app/cmd/unlink_cel.h"
#include "app/context_access.h"
#include "app/document.h"
#include "app/ini_file.h"
#include "app/modules/editors.h"
#include "app/transaction.h"
@ -23,6 +24,7 @@
#include "doc/images_collector.h"
#include "doc/layer.h"
#include "doc/mask.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "filters/filter.h"
#include "ui/manager.h"
@ -40,7 +42,7 @@ using namespace ui;
FilterManagerImpl::FilterManagerImpl(Context* context, Filter* filter)
: m_context(context)
, m_location(context->activeLocation())
, m_site(context->activeSite())
, m_filter(filter)
, m_dst(NULL)
, m_preview_mask(NULL)
@ -56,17 +58,22 @@ FilterManagerImpl::FilterManagerImpl(Context* context, Filter* filter)
m_targetOrig = TARGET_ALL_CHANNELS;
m_target = TARGET_ALL_CHANNELS;
Image* image = m_location.image(&offset_x, &offset_y);
Image* image = m_site.image(&offset_x, &offset_y);
if (image == NULL)
throw NoImageException();
init(m_location.layer(), image, offset_x, offset_y);
init(m_site.layer(), image, offset_x, offset_y);
}
FilterManagerImpl::~FilterManagerImpl()
{
}
app::Document* FilterManagerImpl::document()
{
return static_cast<app::Document*>(m_site.document());
}
void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
{
m_progressDelegate = progressDelegate;
@ -74,7 +81,7 @@ void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
PixelFormat FilterManagerImpl::pixelFormat() const
{
return m_location.sprite()->pixelFormat();
return m_site.sprite()->pixelFormat();
}
void FilterManagerImpl::setTarget(int target)
@ -83,14 +90,14 @@ void FilterManagerImpl::setTarget(int target)
m_target = target;
// The alpha channel of the background layer can't be modified.
if (m_location.layer() &&
m_location.layer()->isBackground())
if (m_site.layer() &&
m_site.layer()->isBackground())
m_target &= ~TARGET_ALPHA_CHANNEL;
}
void FilterManagerImpl::begin()
{
Document* document = m_location.document();
Document* document = static_cast<app::Document*>(m_site.document());
m_row = 0;
m_mask = (document->isMaskVisible() ? document->mask(): NULL);
@ -100,7 +107,7 @@ void FilterManagerImpl::begin()
void FilterManagerImpl::beginForPreview()
{
Document* document = m_location.document();
Document* document = static_cast<app::Document*>(m_site.document());
if (document->isMaskVisible())
m_preview_mask.reset(new Mask(*document->mask()));
@ -117,7 +124,7 @@ void FilterManagerImpl::beginForPreview()
{
Editor* editor = current_editor;
Sprite* sprite = m_location.sprite();
Sprite* sprite = m_site.sprite();
gfx::Rect vp = View::getView(editor)->getViewportBounds();
vp = editor->screenToEditor(vp);
vp = vp.createIntersect(sprite->bounds());
@ -162,7 +169,7 @@ bool FilterManagerImpl::applyStep()
m_maskIterator = m_maskBits.begin();
}
switch (m_location.sprite()->pixelFormat()) {
switch (m_site.sprite()->pixelFormat()) {
case IMAGE_RGB: m_filter->applyToRgba(this); break;
case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break;
case IMAGE_INDEXED: m_filter->applyToIndexed(this); break;
@ -199,9 +206,9 @@ void FilterManagerImpl::applyToTarget()
bool cancelled = false;
ImagesCollector images((m_target & TARGET_ALL_LAYERS ?
m_location.sprite()->folder():
m_location.layer()),
m_location.frame(),
m_site.sprite()->folder():
m_site.layer()),
m_site.frame(),
(m_target & TARGET_ALL_FRAMES) == TARGET_ALL_FRAMES,
true); // we will write in each image
if (images.empty())
@ -289,12 +296,12 @@ bool FilterManagerImpl::skipPixel()
Palette* FilterManagerImpl::getPalette()
{
return m_location.sprite()->palette(m_location.frame());
return m_site.sprite()->palette(m_site.frame());
}
RgbMap* FilterManagerImpl::getRgbMap()
{
return m_location.sprite()->rgbMap(m_location.frame());
return m_site.sprite()->rgbMap(m_site.frame());
}
void FilterManagerImpl::init(const Layer* layer, Image* image, int offset_x, int offset_y)
@ -302,7 +309,7 @@ void FilterManagerImpl::init(const Layer* layer, Image* image, int offset_x, int
m_offset_x = offset_x;
m_offset_y = offset_y;
if (!updateMask(m_location.document()->mask(), image))
if (!updateMask(static_cast<app::Document*>(m_site.document())->mask(), image))
throw InvalidAreaException();
m_src = image;

View File

@ -9,14 +9,14 @@
#define APP_COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED
#pragma once
#include "app/document_location.h"
#include "base/exception.h"
#include "base/unique_ptr.h"
#include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h"
#include "doc/image_bits.h"
#include "doc/image_traits.h"
#include "doc/pixel_format.h"
#include "doc/site.h"
#include "filters/filter_indexed_data.h"
#include "filters/filter_manager.h"
#include <cstring>
@ -72,7 +72,7 @@ namespace app {
void setProgressDelegate(IProgressDelegate* progressDelegate);
PixelFormat pixelFormat() const;
doc::PixelFormat pixelFormat() const;
void setTarget(Target target);
@ -82,11 +82,11 @@ namespace app {
bool applyStep();
void applyToTarget();
Document* document() { return m_location.document(); }
Sprite* sprite() { return m_location.sprite(); }
Layer* layer() { return m_location.layer(); }
frame_t frame() { return m_location.frame(); }
Image* destinationImage() const { return m_dst; }
app::Document* document();
doc::Sprite* sprite() { return m_site.sprite(); }
doc::Layer* layer() { return m_site.layer(); }
doc::frame_t frame() { return m_site.frame(); }
doc::Image* destinationImage() const { return m_dst; }
// Updates the current editor to show the progress of the preview.
void flush();
@ -98,30 +98,30 @@ namespace app {
Target getTarget() { return m_target; }
FilterIndexedData* getIndexedData() { return this; }
bool skipPixel();
const Image* getSourceImage() { return m_src; }
const doc::Image* getSourceImage() { return m_src; }
int x() { return m_x; }
int y() { return m_y+m_row; }
// FilterIndexedData implementation
Palette* getPalette();
RgbMap* getRgbMap();
doc::Palette* getPalette();
doc::RgbMap* getRgbMap();
private:
void init(const Layer* layer, Image* image, int offset_x, int offset_y);
void init(const doc::Layer* layer, doc::Image* image, int offset_x, int offset_y);
void apply(Transaction& transaction);
void applyToImage(Transaction& transaction, Layer* layer, Image* image, int x, int y);
bool updateMask(Mask* mask, const Image* image);
void applyToImage(Transaction& transaction, doc::Layer* layer, doc::Image* image, int x, int y);
bool updateMask(doc::Mask* mask, const doc::Image* image);
Context* m_context;
DocumentLocation m_location;
doc::Site m_site;
Filter* m_filter;
Image* m_src;
base::UniquePtr<Image> m_dst;
doc::Image* m_src;
base::UniquePtr<doc::Image> m_dst;
int m_row;
int m_x, m_y, m_w, m_h;
int m_offset_x, m_offset_y;
Mask* m_mask;
base::UniquePtr<Mask> m_preview_mask;
doc::Mask* m_mask;
base::UniquePtr<doc::Mask> m_preview_mask;
doc::ImageBits<doc::BitmapTraits> m_maskBits;
doc::ImageBits<doc::BitmapTraits>::iterator m_maskIterator;
Target m_targetOrig; // Original targets

View File

@ -16,7 +16,6 @@
#include "app/commands/commands.h"
#include "app/console.h"
#include "app/document.h"
#include "app/document_location.h"
#include "app/settings/settings.h"
#include <algorithm>
@ -52,14 +51,6 @@ app::Document* Context::activeDocument() const
return static_cast<app::Document*>(doc::Context::activeDocument());
}
DocumentLocation Context::activeLocation() const
{
DocumentLocation location;
onGetActiveLocation(&location);
ASSERT(location.document() == doc::Context::activeDocument());
return location;
}
void Context::executeCommand(const char* commandName)
{
Command* cmd = CommandsModule::instance()->getCommandByName(commandName);
@ -124,9 +115,4 @@ void Context::onCreateDocument(doc::CreateDocumentArgs* args)
args->setDocument(new app::Document(NULL));
}
void Context::onGetActiveLocation(DocumentLocation* location) const
{
// Without active location
}
} // namespace app

View File

@ -21,7 +21,6 @@
namespace app {
class Command;
class Document;
class DocumentLocation;
class ISettings;
class CommandPreconditionException : public base::Exception {
@ -50,7 +49,6 @@ namespace app {
void sendDocumentToTop(doc::Document* document);
app::Document* activeDocument() const;
DocumentLocation activeLocation() const;
void executeCommand(const char* commandName);
virtual void executeCommand(Command* command, const Params& params = Params());
@ -60,7 +58,6 @@ namespace app {
protected:
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
virtual void onGetActiveLocation(DocumentLocation* location) const;
private:
// Settings in this context.

View File

@ -10,7 +10,7 @@
#pragma once
#include "app/document_access.h"
#include "app/document_location.h"
#include "doc/site.h"
namespace app {
@ -20,35 +20,35 @@ namespace app {
class ContextAccess {
public:
const Context* context() const { return m_context; }
const DocumentLocation* location() const { return &m_location; }
const Site* site() const { return &m_site; }
const DocumentAccessT& document() const { return m_document; }
const Sprite* sprite() const { return m_location.sprite(); }
const Layer* layer() const { return m_location.layer(); }
frame_t frame() const { return m_location.frame(); }
const Cel* cel() const { return m_location.cel(); }
const Sprite* sprite() const { return m_site.sprite(); }
const Layer* layer() const { return m_site.layer(); }
frame_t frame() const { return m_site.frame(); }
const Cel* cel() const { return m_site.cel(); }
// You cannot change the location directly from a writable ContextAccess anyway.
const DocumentLocation* location() { return &m_location; }
// You cannot change the site directly from a writable ContextAccess anyway.
const Site* site() { return &m_site; }
Context* context() { return const_cast<Context*>(m_context); }
DocumentAccessT& document() { return m_document; }
Sprite* sprite() { return m_location.sprite(); }
Layer* layer() { return m_location.layer(); }
Cel* cel() { return m_location.cel(); }
Sprite* sprite() { return m_site.sprite(); }
Layer* layer() { return m_site.layer(); }
Cel* cel() { return m_site.cel(); }
Image* image(int* x = NULL, int* y = NULL, int* opacity = NULL) const {
return m_location.image(x, y, opacity);
return m_site.image(x, y, opacity);
}
Palette* palette() const {
return m_location.palette();
return m_site.palette();
}
protected:
ContextAccess(const Context* context, int timeout)
: m_context(context)
, m_document(context->activeDocument(), timeout)
, m_location(context->activeLocation())
, m_site(context->activeSite())
{
}
@ -56,14 +56,14 @@ namespace app {
ContextAccess(const Context* context, const DocumentReaderT& documentReader, int timeout)
: m_context(context)
, m_document(documentReader, timeout)
, m_location(context->activeLocation())
, m_site(context->activeSite())
{
}
private:
const Context* m_context;
DocumentAccessT m_document;
DocumentLocation m_location;
Site m_site;
};
// You can use this class to access to the given context to read the

View File

@ -13,9 +13,9 @@
#include "app/context.h"
#include "app/document.h"
#include "app/document_location.h"
#include "doc/cel.h"
#include "doc/layer.h"
#include "doc/site.h"
#include "doc/sprite.h"
namespace app {
@ -27,8 +27,8 @@ ContextFlags::ContextFlags()
void ContextFlags::update(Context* context)
{
DocumentLocation location = context->activeLocation();
Document* document = location.document();
Site site = context->activeSite();
Document* document = static_cast<Document*>(site.document());
m_flags = 0;
@ -41,14 +41,14 @@ void ContextFlags::update(Context* context)
if (document->isMaskVisible())
m_flags |= HasVisibleMask;
Sprite* sprite = location.sprite();
Sprite* sprite = site.sprite();
if (sprite) {
m_flags |= HasActiveSprite;
if (sprite->backgroundLayer())
m_flags |= HasBackgroundLayer;
Layer* layer = location.layer();
Layer* layer = site.layer();
if (layer) {
m_flags |= HasActiveLayer;
@ -64,7 +64,7 @@ void ContextFlags::update(Context* context)
if (layer->isImage()) {
m_flags |= ActiveLayerIsImage;
Cel* cel = layer->cel(location.frame());
Cel* cel = layer->cel(site.frame());
if (cel) {
m_flags |= HasActiveCel;

View File

@ -7,13 +7,15 @@
#include "tests/test.h"
#include "app/context.h"
#include "app/document.h"
#include "app/document_api.h"
#include "app/test_context.h"
#include "app/transaction.h"
#include "base/unique_ptr.h"
#include "doc/cel.h"
#include "doc/image.h"
#include "doc/primitives.h"
#include "doc/test_context.h"
using namespace app;
using namespace doc;
@ -21,7 +23,7 @@ using namespace doc;
typedef base::UniquePtr<app::Document> DocumentPtr;
TEST(DocumentApi, MoveCel) {
TestContext ctx;
TestContextT<app::Context> ctx;
DocumentPtr doc(static_cast<app::Document*>(ctx.documents().add(32, 16)));
Sprite* sprite = doc->sprite();
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());

View File

@ -7,15 +7,16 @@
#include "tests/test.h"
#include "app/context.h"
#include "app/document.h"
#include "app/document_api.h"
#include "app/document_range.h"
#include "app/document_range_ops.h"
#include "app/document_undo.h"
#include "app/test_context.h"
#include "app/transaction.h"
#include "base/unique_ptr.h"
#include "doc/doc.h"
#include "doc/test_context.h"
using namespace app;
using namespace doc;
@ -181,7 +182,7 @@ protected:
return (cel == NULL);
}
TestContext ctx;
TestContextT<app::Context> ctx;
DocumentPtr doc;
Sprite* sprite;
LayerImage* layer1;

View File

@ -12,8 +12,8 @@
#include "app/file/file.h"
#include "app/file/file_formats_manager.h"
#include "app/file/gif_options.h"
#include "app/test_context.h"
#include "doc/doc.h"
#include "doc/test_context.h"
#include "she/scoped_handle.h"
#include "she/system.h"
@ -26,7 +26,7 @@ public:
}
protected:
app::TestContext m_ctx;
doc::TestContextT<app::Context> m_ctx;
she::ScopedHandle<she::System> m_system;
};

View File

@ -15,7 +15,6 @@
#include "app/commands/params.h"
#include "app/console.h"
#include "app/document.h"
#include "app/document_location.h"
#include "app/ini_file.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"

View File

@ -1,40 +0,0 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
#ifndef APP_TEST_CONTEXT_H_INCLUDED
#define APP_TEST_CONTEXT_H_INCLUDED
#pragma once
#include "app/context.h"
#include "app/document.h"
#include "app/document_location.h"
#include "doc/layer.h"
#include "doc/sprite.h"
namespace app {
class TestContext : public app::Context {
public:
TestContext() : app::Context(NULL) {
}
protected:
void onGetActiveLocation(DocumentLocation* location) const override {
Document* doc = activeDocument();
if (!doc)
return;
location->document(doc);
location->sprite(doc->sprite());
location->layer(doc->sprite()->folder()->getFirstLayer());
location->frame(0);
}
};
} // namespace app
#endif

View File

@ -25,9 +25,7 @@ Transaction::Transaction(Context* ctx, const std::string& label, Modification mo
: m_ctx(ctx)
, m_cmds(NULL)
{
DocumentLocation location = m_ctx->activeLocation();
m_undo = location.document()->undoHistory();
m_undo = m_ctx->activeDocument()->undoHistory();
m_cmds = new CmdTransaction(label,
modification == Modification::ModifyDocument,
m_undo->savedCounter());

View File

@ -195,7 +195,7 @@ void ColorBar::setPaletteEditorButtonState(bool state)
m_paletteButton.setSelected(state);
}
void ColorBar::onSetActiveDocument(doc::Document* document)
void ColorBar::onActiveDocumentChange(doc::Document* document)
{
destroyRemap();
}

View File

@ -51,7 +51,7 @@ namespace app {
void setPaletteEditorButtonState(bool state);
// ContextObserver impl
void onSetActiveDocument(doc::Document* document) override;
void onActiveDocumentChange(doc::Document* document) override;
// Signals
Signal1<void, const app::Color&> FgColorChange;

View File

@ -13,7 +13,6 @@
#include "app/color.h"
#include "app/color_picker.h"
#include "app/color_utils.h"
#include "app/document_location.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
#include "app/ui/color_bar.h"
@ -22,6 +21,7 @@
#include "app/ui/editor/editor.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "ui/preferred_size_event.h"
#include "ui/ui.h"
@ -120,12 +120,12 @@ bool ColorButton::onProcessMessage(Message* msg)
// Pick a color from a editor
else if (picked->type == editor_type()) {
Editor* editor = static_cast<Editor*>(picked);
DocumentLocation location = editor->getDocumentLocation();
if (location.sprite()) {
Site site = editor->getSite();
if (site.sprite()) {
gfx::Point editorPos = editor->screenToEditor(mousePos);
ColorPicker picker;
picker.pickColor(location, editorPos, ColorPicker::FromComposition);
picker.pickColor(site, editorPos, ColorPicker::FromComposition);
color = picker.color();
}
}

View File

@ -208,9 +208,9 @@ DocumentView::~DocumentView()
delete m_editor;
}
void DocumentView::getDocumentLocation(DocumentLocation* location) const
void DocumentView::getSite(Site* site) const
{
m_editor->getDocumentLocation(location);
m_editor->getSite(site);
}
std::string DocumentView::getTabText()

View File

@ -14,13 +14,16 @@
#include "doc/document_observer.h"
#include "ui/box.h"
namespace doc {
class Site;
}
namespace ui {
class View;
}
namespace app {
class Document;
class DocumentLocation;
class Editor;
class DocumentView : public ui::Box
@ -37,7 +40,7 @@ namespace app {
~DocumentView();
Document* getDocument() const { return m_document; }
void getDocumentLocation(DocumentLocation* location) const;
void getSite(doc::Site* site) const;
Editor* getEditor() { return m_editor; }
bool isPreview() { return m_type == Preview; }

View File

@ -17,7 +17,6 @@
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/console.h"
#include "app/document_location.h"
#include "app/ini_file.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
@ -269,19 +268,19 @@ void Editor::setFrame(frame_t frame)
}
}
void Editor::getDocumentLocation(DocumentLocation* location) const
void Editor::getSite(Site* site) const
{
location->document(m_document);
location->sprite(m_sprite);
location->layer(m_layer);
location->frame(m_frame);
site->document(m_document);
site->sprite(m_sprite);
site->layer(m_layer);
site->frame(m_frame);
}
DocumentLocation Editor::getDocumentLocation() const
Site Editor::getSite() const
{
DocumentLocation location;
getDocumentLocation(&location);
return location;
Site site;
getSite(&site);
return site;
}
void Editor::setDefaultScroll()
@ -745,10 +744,10 @@ void Editor::flashCurrentLayer()
if (!App::instance()->preferences().experimental.flashLayer())
return;
DocumentLocation loc = getDocumentLocation();
Site site = getSite();
int x, y;
const Image* src_image = loc.image(&x, &y);
const Image* src_image = site.image(&x, &y);
if (src_image) {
m_renderEngine.removePreviewImage();
@ -1484,8 +1483,7 @@ void Editor::pasteImage(const Image* image, const gfx::Point& pos)
PixelsMovementPtr pixelsMovement(
new PixelsMovement(UIContext::instance(),
getDocumentLocation(),
image, gfx::Point(x, y), opacity, "Paste"));
getSite(), image, gfx::Point(x, y), opacity, "Paste"));
// Select the pasted image so the user can move it and transform it.
pixelsMovement->maskImage(image);

View File

@ -28,8 +28,9 @@
#include "ui/widget.h"
namespace doc {
class Sprite;
class Layer;
class Site;
class Sprite;
}
namespace gfx {
class Region;
@ -41,7 +42,6 @@ namespace ui {
namespace app {
class Context;
class DocumentLocation;
class DocumentView;
class EditorCustomizationDelegate;
class PixelsMovement;
@ -106,8 +106,8 @@ namespace app {
Layer* layer() { return m_layer; }
frame_t frame() { return m_frame; }
void getDocumentLocation(DocumentLocation* location) const;
DocumentLocation getDocumentLocation() const;
void getSite(Site* site) const;
Site getSite() const;
void setLayer(const Layer* layer);
void setFrame(frame_t frame);

View File

@ -32,6 +32,7 @@
#include "doc/cel.h"
#include "doc/image.h"
#include "doc/mask.h"
#include "doc/site.h"
#include "doc/sprite.h"
#include "gfx/region.h"
#include "render/render.h"
@ -44,14 +45,14 @@ static inline const base::Vector2d<double> point2Vector(const gfx::PointT<T>& pt
}
PixelsMovement::PixelsMovement(Context* context,
DocumentLocation location,
Site site,
const Image* moveThis, const gfx::Point& initialPos, int opacity,
const char* operationName)
: m_reader(context)
, m_location(location)
, m_document(location.document())
, m_sprite(location.sprite())
, m_layer(location.layer())
, m_site(site)
, m_document(static_cast<app::Document*>(site.document()))
, m_sprite(site.sprite())
, m_layer(site.layer())
, m_transaction(context, operationName)
, m_setMaskCmd(nullptr)
, m_isDragging(false)
@ -443,7 +444,7 @@ void PixelsMovement::stampImage()
{
// Expand the canvas to paste the image in the fully visible
// portion of sprite.
ExpandCelCanvas expand(m_location,
ExpandCelCanvas expand(m_site,
TiledMode::NONE, m_transaction,
ExpandCelCanvas::None);
@ -473,7 +474,7 @@ void PixelsMovement::dropImageTemporarily()
// TODO Add undo information so the user can undo each transformation step.
// Displace the pivot to the new location:
// Displace the pivot to the new site:
if (m_adjustPivot) {
m_adjustPivot = false;

View File

@ -11,11 +11,12 @@
#include "app/context_access.h"
#include "app/settings/settings_observers.h"
#include "app/ui/editor/handle_type.h"
#include "app/transaction.h"
#include "app/ui/editor/handle_type.h"
#include "base/shared_ptr.h"
#include "gfx/size.h"
#include "doc/algorithm/flip_type.h"
#include "doc/site.h"
#include "gfx/size.h"
namespace doc {
class Image;
@ -47,7 +48,7 @@ namespace app {
// The "moveThis" image specifies the chunk of pixels to be moved.
// The "x" and "y" parameters specify the initial position of the image.
PixelsMovement(Context* context,
DocumentLocation location,
Site site,
const Image* moveThis,
const gfx::Point& initialPos, int opacity,
const char* operationName);
@ -104,7 +105,7 @@ namespace app {
void updateDocumentMask();
const ContextReader m_reader;
DocumentLocation m_location;
Site m_site;
Document* m_document;
Sprite* m_sprite;
Layer* m_layer;

View File

@ -15,7 +15,6 @@
#include "app/color_picker.h"
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/document_location.h"
#include "app/ini_file.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
@ -145,10 +144,10 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
UIContext* context = UIContext::instance();
tools::Ink* clickedInk = editor->getCurrentEditorInk();
DocumentLocation location;
editor->getDocumentLocation(&location);
Document* document = location.document();
Layer* layer = location.layer();
Site site;
editor->getSite(&site);
app::Document* document = static_cast<app::Document*>(site.document());
Layer* layer = site.layer();
// When an editor is clicked the current view is changed.
context->setActiveView(editor->getDocumentView());
@ -164,7 +163,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
gfx::Point cursor = editor->screenToEditor(msg->position());
ColorPicker picker;
picker.pickColor(location, cursor, ColorPicker::FromComposition);
picker.pickColor(site, cursor, ColorPicker::FromComposition);
if (layer != picker.layer()) {
layer = picker.layer();
@ -217,7 +216,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
if (handle != NoHandle) {
int x, y, opacity;
Image* image = location.image(&x, &y, &opacity);
Image* image = site.image(&x, &y, &opacity);
if (layer && image) {
if (!layer->isEditable()) {
StatusBar::instance()->showTip(1000,
@ -370,7 +369,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
else if (ink->isEyedropper()) {
bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
ColorPicker picker;
picker.pickColor(editor->getDocumentLocation(),
picker.pickColor(editor->getSite(),
spritePos,
grabAlpha ?
ColorPicker::FromActiveLayer:
@ -416,12 +415,12 @@ void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleT
try {
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
Document* document = editor->document();
base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getDocumentLocation()));
base::UniquePtr<Image> tmpImage(new_image_from_mask(editor->getSite()));
gfx::Point origin = document->mask()->bounds().getOrigin();
int opacity = 255;
PixelsMovementPtr pixelsMovement(
new PixelsMovement(UIContext::instance(),
editor->getDocumentLocation(),
editor->getSite(),
tmpImage, origin, opacity,
"Transformation"));

View File

@ -112,7 +112,7 @@ public:
getInk()->isSlice() ||
getInk()->isZoom()) ? DoesntModifyDocument:
ModifyDocument))
, m_expandCelCanvas(editor->getDocumentLocation(),
, m_expandCelCanvas(editor->getSite(),
m_docPref.tiled.mode(),
m_transaction,
ExpandCelCanvas::Flags(

View File

@ -17,7 +17,6 @@
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/document.h"
#include "app/document_location.h"
#include "app/settings/settings.h"
#include "app/tools/ink.h"
#include "app/tools/tool.h"
@ -635,8 +634,7 @@ void KeyboardShortcuts::disableAccel(const ui::Accelerator& accel, KeyContext ke
KeyContext KeyboardShortcuts::getCurrentKeyContext()
{
app::Context* ctx = UIContext::instance();
DocumentLocation location = ctx->activeLocation();
Document* doc = location.document();
Document* doc = ctx->activeDocument();
if (doc &&
doc->isMaskVisible() &&

View File

@ -157,24 +157,24 @@ void Timeline::updateUsingEditor(Editor* editor)
else
return; // No editor specified.
DocumentLocation location;
Site site;
DocumentView* view = m_editor->getDocumentView();
view->getDocumentLocation(&location);
view->getSite(&site);
location.document()->addObserver(this);
site.document()->addObserver(this);
// If we are already in the same position as the "editor", we don't
// need to update the at all timeline.
if (m_document == location.document() &&
m_sprite == location.sprite() &&
m_layer == location.layer() &&
m_frame == location.frame())
if (m_document == site.document() &&
m_sprite == site.sprite() &&
m_layer == site.layer() &&
m_frame == site.frame())
return;
m_document = location.document();
m_sprite = location.sprite();
m_layer = location.layer();
m_frame = location.frame();
m_document = static_cast<app::Document*>(site.document());
m_sprite = site.sprite();
m_layer = site.layer();
m_frame = site.frame();
m_state = STATE_STANDBY;
m_hot.part = PART_NOTHING;
m_clk.part = PART_NOTHING;

View File

@ -11,7 +11,6 @@
#include "app/app.h"
#include "app/document.h"
#include "app/document_location.h"
#include "app/modules/editors.h"
#include "app/pref/preferences.h"
#include "app/settings/ui_settings_impl.h"
@ -26,15 +25,17 @@
#include "app/ui/workspace_tabs.h"
#include "app/ui_context.h"
#include "base/mutex.h"
#include "doc/site.h"
#include "doc/sprite.h"
namespace app {
UIContext* UIContext::m_instance = NULL;
UIContext* UIContext::m_instance = nullptr;
UIContext::UIContext()
: Context(new UISettingsImpl)
, m_lastSelectedView(NULL)
, m_lastSelectedDoc(nullptr)
, m_lastSelectedView(nullptr)
{
documents().addObserver(&App::instance()->preferences());
@ -81,8 +82,6 @@ void UIContext::setActiveView(DocumentView* docView)
(docView && docView->isPreview()))
return;
setActiveDocument(docView ? docView->getDocument(): NULL);
MainWindow* mainWin = App::instance()->getMainWindow();
if (docView) {
mainWin->getTabsBar()->selectTab(docView);
@ -112,6 +111,16 @@ void UIContext::setActiveView(DocumentView* docView)
m_lastSelectedView = docView;
}
void UIContext::setActiveDocument(Document* document)
{
m_lastSelectedDoc = document;
DocumentView* docView = getFirstDocumentView(document);
ASSERT(docView);
if (docView)
setActiveView(docView);
}
DocumentView* UIContext::getFirstDocumentView(Document* document) const
{
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
@ -138,14 +147,14 @@ Editor* UIContext::activeEditor()
void UIContext::onAddDocument(doc::Document* doc)
{
Context::onAddDocument(doc);
m_lastSelectedDoc = static_cast<app::Document*>(doc);
// We don't create views in batch mode.
if (!App::instance()->isGui())
return;
// Add a new view for this document
DocumentView* view = new DocumentView(static_cast<app::Document*>(doc), DocumentView::Normal);
DocumentView* view = new DocumentView(m_lastSelectedDoc, DocumentView::Normal);
// Add a tab with the new view for the document
App::instance()->getMainWindow()->getWorkspace()->addView(view);
@ -156,6 +165,9 @@ void UIContext::onAddDocument(doc::Document* doc)
void UIContext::onRemoveDocument(doc::Document* doc)
{
if (doc == m_lastSelectedDoc)
m_lastSelectedDoc = nullptr;
// We don't destroy views in batch mode.
if (isUiAvailable()) {
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
@ -175,22 +187,20 @@ void UIContext::onRemoveDocument(doc::Document* doc)
delete docView;
}
}
Context::onRemoveDocument(doc);
}
void UIContext::onGetActiveLocation(DocumentLocation* location) const
void UIContext::onGetActiveSite(Site* site) const
{
DocumentView* view = activeView();
if (view) {
view->getDocumentLocation(location);
view->getSite(site);
}
// Default/dummy location (maybe for batch/command line mode)
else if (Document* doc = activeDocument()) {
location->document(doc);
location->sprite(doc->sprite());
location->layer(doc->sprite()->indexToLayer(LayerIndex(0)));
location->frame(0);
// Default/dummy site (maybe for batch/command line mode)
else if (Document* doc = m_lastSelectedDoc) {
site->document(doc);
site->sprite(doc->sprite());
site->layer(doc->sprite()->indexToLayer(LayerIndex(0)));
site->frame(0);
}
}

View File

@ -29,6 +29,7 @@ namespace app {
DocumentView* activeView() const;
void setActiveView(DocumentView* documentView);
void setActiveDocument(Document* document);
DocumentView* getFirstDocumentView(Document* document) const;
@ -40,11 +41,12 @@ namespace app {
Editor* getEditorFor(Document* document);
protected:
virtual void onAddDocument(doc::Document* doc) override;
virtual void onRemoveDocument(doc::Document* doc) override;
virtual void onGetActiveLocation(DocumentLocation* location) const override;
void onAddDocument(doc::Document* doc) override;
void onRemoveDocument(doc::Document* doc) override;
void onGetActiveSite(doc::Site* site) const override;
private:
Document* m_lastSelectedDoc;
DocumentView* m_lastSelectedView;
static UIContext* m_instance;
};

View File

@ -16,7 +16,6 @@
#include "app/context_access.h"
#include "app/document.h"
#include "app/document_api.h"
#include "app/document_location.h"
#include "app/document_range.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
@ -83,7 +82,7 @@ namespace {
using namespace doc;
static void set_clipboard_image(Image* image, Palette* palette, bool set_system_clipboard);
static bool copy_from_document(const DocumentLocation& location);
static bool copy_from_document(const Site& site);
static bool first_time = true;
@ -120,20 +119,20 @@ static void set_clipboard_image(Image* image, Palette* palette, bool set_system_
clipboard_range.invalidate();
}
static bool copy_from_document(const DocumentLocation& location)
static bool copy_from_document(const Site& site)
{
const Document* document = location.document();
const app::Document* document = static_cast<const app::Document*>(site.document());
ASSERT(document != NULL);
ASSERT(document->isMaskVisible());
Image* image = new_image_from_mask(location);
Image* image = new_image_from_mask(site);
if (!image)
return false;
clipboard_pos = document->mask()->bounds().getOrigin();
const Palette* pal = document->sprite()->palette(location.frame());
const Palette* pal = document->sprite()->palette(site.frame());
set_clipboard_image(image, pal ? new Palette(*pal): NULL, true);
return true;
}
@ -175,7 +174,7 @@ void clipboard::cut(ContextWriter& writer)
ASSERT(writer.sprite() != NULL);
ASSERT(writer.layer() != NULL);
if (!copy_from_document(*writer.location())) {
if (!copy_from_document(*writer.site())) {
Console console;
console.printf("Can't copying an image portion from the current layer\n");
}
@ -195,7 +194,7 @@ void clipboard::copy(const ContextReader& reader)
{
ASSERT(reader.document() != NULL);
if (!copy_from_document(*reader.location())) {
if (!copy_from_document(*reader.site())) {
Console console;
console.printf("Can't copying an image portion from the current layer\n");
return;

View File

@ -18,7 +18,6 @@
#include "app/cmd/set_cel_position.h"
#include "app/context.h"
#include "app/document.h"
#include "app/document_location.h"
#include "app/transaction.h"
#include "app/util/range_utils.h"
#include "base/unique_ptr.h"
@ -26,6 +25,7 @@
#include "doc/image.h"
#include "doc/layer.h"
#include "doc/primitives.h"
#include "doc/site.h"
#include "doc/sprite.h"
namespace {
@ -53,11 +53,11 @@ static void create_buffers()
namespace app {
ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
ExpandCelCanvas::ExpandCelCanvas(Site site,
TiledMode tiledMode, Transaction& transaction, Flags flags)
: m_document(location.document())
, m_sprite(location.sprite())
, m_layer(location.layer())
: m_document(static_cast<app::Document*>(site.document()))
, m_sprite(site.sprite())
, m_layer(site.layer())
, m_cel(NULL)
, m_celImage(NULL)
, m_celCreated(false)
@ -71,7 +71,7 @@ ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
create_buffers();
if (m_layer->isImage()) {
m_cel = m_layer->cel(location.frame());
m_cel = m_layer->cel(site.frame());
if (m_cel)
m_celImage = m_cel->imageRef();
}
@ -79,7 +79,7 @@ ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
// Create a new cel
if (m_cel == NULL) {
m_celCreated = true;
m_cel = new Cel(location.frame(), ImageRef(NULL));
m_cel = new Cel(site.frame(), ImageRef(NULL));
}
m_origCelPos = m_cel->position();

View File

@ -20,12 +20,12 @@ namespace doc {
class Cel;
class Image;
class Layer;
class Site;
class Sprite;
}
namespace app {
class Document;
class DocumentLocation;
class Transaction;
using namespace filters;
@ -45,7 +45,7 @@ namespace app {
UseModifiedRegionAsUndoInfo = 2,
};
ExpandCelCanvas(DocumentLocation location,
ExpandCelCanvas(Site site,
TiledMode tiledMode, Transaction& undo, Flags flags);
~ExpandCelCanvas();

View File

@ -12,25 +12,25 @@
#include "app/util/new_image_from_mask.h"
#include "app/document.h"
#include "app/document_location.h"
#include "doc/image.h"
#include "doc/image_bits.h"
#include "doc/image_traits.h"
#include "doc/mask.h"
#include "doc/site.h"
namespace app {
using namespace doc;
Image* new_image_from_mask(const DocumentLocation& location)
Image* new_image_from_mask(const Site& site)
{
const Sprite* srcSprite = location.sprite();
const Mask* srcMask = location.document()->mask();
const Sprite* srcSprite = site.sprite();
const Mask* srcMask = static_cast<const app::Document*>(site.document())->mask();
const Image* srcMaskBitmap = srcMask->bitmap();
const gfx::Rect& srcBounds = srcMask->bounds();
int x, y, u, v, getx, gety;
Image *dst;
const Image *src = location.image(&x, &y);
const Image *src = site.image(&x, &y);
ASSERT(srcSprite);
ASSERT(srcMask);

View File

@ -11,12 +11,12 @@
namespace doc {
class Image;
class Site;
}
namespace app {
class DocumentLocation;
doc::Image* new_image_from_mask(const DocumentLocation& location);
doc::Image* new_image_from_mask(const doc::Site& site);
} // namespace app

View File

@ -42,6 +42,7 @@ add_library(doc-lib
primitives.cpp
remap.cpp
rgbmap.cpp
site.cpp
sprite.cpp
sprites.cpp
string_io.cpp

View File

@ -10,7 +10,7 @@
#include "doc/context.h"
#include <algorithm>
#include "doc/site.h"
namespace doc {
@ -23,30 +23,46 @@ Context::Context()
Context::~Context()
{
setActiveDocument(NULL);
m_docs.removeObserver(this);
}
Site Context::activeSite() const
{
Site site;
onGetActiveSite(&site);
return site;
}
Document* Context::activeDocument() const
{
return m_activeDoc;
Site site;
onGetActiveSite(&site);
return site.document();
}
void Context::setActiveDocument(Document* doc)
void Context::notifyActiveDocumentChanged(Document* doc)
{
m_activeDoc = doc;
notifyObservers(&ContextObserver::onSetActiveDocument, doc);
notifyObservers(&ContextObserver::onActiveDocumentChange, doc);
}
void Context::notifyActiveSiteChanged(Site* site)
{
notifyObservers(&ContextObserver::onActiveSiteChange, site);
}
void Context::onGetActiveSite(Site* site) const
{
ASSERT(false);
}
void Context::onAddDocument(Document* doc)
{
m_activeDoc = doc;
// Do nothing
}
void Context::onRemoveDocument(Document* doc)
{
if (m_activeDoc == doc)
setActiveDocument(!m_docs.empty() ? m_docs.back() : NULL);
// Do nothing
}
} // namespace doc

View File

@ -28,10 +28,14 @@ namespace doc {
const Documents& documents() const { return m_docs; }
Documents& documents() { return m_docs; }
Site activeSite() const;
Document* activeDocument() const;
void setActiveDocument(Document* doc);
// DocumentsObserver impl
protected:
void notifyActiveDocumentChanged(Document* doc);
void notifyActiveSiteChanged(Site* site);
virtual void onGetActiveSite(Site* site) const;
virtual void onAddDocument(Document* doc) override;
virtual void onRemoveDocument(Document* doc) override;

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (c) 2001-2014 David Capello
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
@ -11,11 +11,13 @@
namespace doc {
class Document;
class Site;
class ContextObserver {
public:
virtual ~ContextObserver() { }
virtual void onSetActiveDocument(Document* document) { }
virtual void onActiveDocumentChange(Document* document) { }
virtual void onActiveSiteChange(Site* site) { }
};
} // namespace doc

View File

@ -28,6 +28,7 @@
#include "doc/primitives_fast.h"
#include "doc/remap.h"
#include "doc/rgbmap.h"
#include "doc/site.h"
#include "doc/sprite.h"
#endif

View File

@ -1,42 +1,39 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/document_location.h"
#include "doc/site.h"
#include "doc/cel.h"
#include "doc/layer.h"
#include "doc/sprite.h"
namespace app {
namespace doc {
using namespace doc;
LayerIndex DocumentLocation::layerIndex() const
LayerIndex Site::layerIndex() const
{
return (m_sprite && m_layer ?
m_sprite->layerToIndex(m_layer): LayerIndex());
}
void DocumentLocation::layerIndex(LayerIndex layerIndex)
void Site::layerIndex(LayerIndex layerIndex)
{
ASSERT(m_sprite != NULL);
m_layer = m_sprite->indexToLayer(layerIndex);
}
Palette* DocumentLocation::palette()
Palette* Site::palette()
{
return (m_sprite ? m_sprite->palette(m_frame): NULL);
}
const Cel* DocumentLocation::cel() const
const Cel* Site::cel() const
{
if (m_layer)
return m_layer->cel(m_frame);
@ -44,7 +41,7 @@ const Cel* DocumentLocation::cel() const
return NULL;
}
Cel* DocumentLocation::cel()
Cel* Site::cel()
{
if (m_layer)
return m_layer->cel(m_frame);
@ -52,7 +49,7 @@ Cel* DocumentLocation::cel()
return NULL;
}
Image* DocumentLocation::image(int* x, int* y, int* opacity) const
Image* Site::image(int* x, int* y, int* opacity) const
{
Image* image = NULL;
@ -68,9 +65,9 @@ Image* DocumentLocation::image(int* x, int* y, int* opacity) const
return image;
}
Palette* DocumentLocation::palette() const
Palette* Site::palette() const
{
return (m_sprite ? m_sprite->palette(m_frame): NULL);
}
} // namespace app
} // namespace doc

View File

@ -1,36 +1,31 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef APP_DOCUMENT_LOCATION_H_INCLUDED
#define APP_DOCUMENT_LOCATION_H_INCLUDED
#ifndef DOC_SITE_H_INCLUDED
#define DOC_SITE_H_INCLUDED
#pragma once
#include "doc/frame.h"
#include "doc/layer_index.h"
namespace doc {
class Cel;
class Document;
class Image;
class Layer;
class Palette;
class Sprite;
}
namespace app {
class Document;
using namespace doc;
// Specifies the current location in a context. If we are in the
// UIContext, it means the location in the current Editor (current
// document, sprite, layer, frame, etc.).
class DocumentLocation {
// Specifies the current location in a context. E.g. the location in
// the current Editor (current document, sprite, layer, frame,
// etc.).
class Site {
public:
DocumentLocation()
Site()
: m_document(NULL)
, m_sprite(NULL)
, m_layer(NULL)

55
src/doc/test_context.h Normal file
View File

@ -0,0 +1,55 @@
// Aseprite Document Library
// Copyright (c) 2001-2015 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef DOC_TEST_CONTEXT_H_INCLUDED
#define DOC_TEST_CONTEXT_H_INCLUDED
#pragma once
#include "doc/context.h"
#include "doc/document.h"
#include "doc/layer.h"
#include "doc/site.h"
#include "doc/sprite.h"
namespace doc {
template<typename Base>
class TestContextT : public Base {
public:
TestContextT() : m_activeDoc(nullptr) {
}
protected:
void onGetActiveSite(Site* site) const override {
Document* doc = m_activeDoc;
if (!doc)
return;
site->document(doc);
site->sprite(doc->sprite());
site->layer(doc->sprite()->folder()->getFirstLayer());
site->frame(0);
}
void onAddDocument(Document* doc) override {
notifyActiveDocumentChanged(m_activeDoc = doc);
}
void onRemoveDocument(Document* doc) override {
if (m_activeDoc == doc)
notifyActiveDocumentChanged(m_activeDoc = nullptr);
}
private:
Document* m_activeDoc;
};
typedef TestContextT<Context> TestContext;
} // namespace doc
#endif