mirror of
https://github.com/aseprite/aseprite.git
synced 2025-03-11 13:14:17 +00:00
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:
parent
c5cf848d37
commit
21c4fd51d9
@ -233,7 +233,6 @@ add_library(app-lib
|
|||||||
document.cpp
|
document.cpp
|
||||||
document_api.cpp
|
document_api.cpp
|
||||||
document_exporter.cpp
|
document_exporter.cpp
|
||||||
document_location.cpp
|
|
||||||
document_range.cpp
|
document_range.cpp
|
||||||
document_range_ops.cpp
|
document_range_ops.cpp
|
||||||
document_undo.cpp
|
document_undo.cpp
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
#include "app/crash/data_recovery.h"
|
#include "app/crash/data_recovery.h"
|
||||||
#include "app/document_exporter.h"
|
#include "app/document_exporter.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/document_undo.h"
|
#include "app/document_undo.h"
|
||||||
#include "app/file/file.h"
|
#include "app/file/file.h"
|
||||||
#include "app/file/file_formats_manager.h"
|
#include "app/file/file_formats_manager.h"
|
||||||
@ -65,6 +64,7 @@
|
|||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/palette.h"
|
#include "doc/palette.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "render/render.h"
|
#include "render/render.h"
|
||||||
#include "scripting/engine.h"
|
#include "scripting/engine.h"
|
||||||
@ -424,7 +424,7 @@ void App::initialize(const AppOptions& options)
|
|||||||
|
|
||||||
// Scale all sprites
|
// Scale all sprites
|
||||||
for (auto doc : ctx->documents()) {
|
for (auto doc : ctx->documents()) {
|
||||||
ctx->setActiveDocument(doc);
|
ctx->setActiveDocument(static_cast<app::Document*>(doc));
|
||||||
ctx->executeCommand(command);
|
ctx->executeCommand(command);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -664,9 +664,9 @@ void app_refresh_screen()
|
|||||||
Context* context = UIContext::instance();
|
Context* context = UIContext::instance();
|
||||||
ASSERT(context != NULL);
|
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);
|
set_current_palette(pal, false);
|
||||||
else
|
else
|
||||||
set_current_palette(NULL, false);
|
set_current_palette(NULL, false);
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include "app/cmd_transaction.h"
|
#include "app/cmd_transaction.h"
|
||||||
|
|
||||||
#include "app/context.h"
|
#include "app/context.h"
|
||||||
#include "app/document_location.h"
|
#include "doc/site.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
@ -64,8 +64,8 @@ std::string CmdTransaction::onLabel() const
|
|||||||
|
|
||||||
doc::SpritePosition CmdTransaction::calcSpritePosition()
|
doc::SpritePosition CmdTransaction::calcSpritePosition()
|
||||||
{
|
{
|
||||||
app::DocumentLocation loc = context()->activeLocation();
|
doc::Site site = context()->activeSite();
|
||||||
return doc::SpritePosition(loc.layerIndex(), loc.frame());
|
return doc::SpritePosition(site.layerIndex(), site.frame());
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -11,10 +11,10 @@
|
|||||||
|
|
||||||
#include "app/color_picker.h"
|
#include "app/color_picker.h"
|
||||||
|
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/primitives.h"
|
#include "doc/primitives.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
#include "render/get_sprite_pixel.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)
|
const gfx::Point& pos, Mode mode)
|
||||||
{
|
{
|
||||||
m_alpha = 255;
|
m_alpha = 255;
|
||||||
@ -36,17 +36,17 @@ void ColorPicker::pickColor(const DocumentLocation& location,
|
|||||||
// Get the color from the image
|
// Get the color from the image
|
||||||
if (mode == FromComposition) { // Pick from the composed image
|
if (mode == FromComposition) { // Pick from the composed image
|
||||||
m_color = app::Color::fromImage(
|
m_color = app::Color::fromImage(
|
||||||
location.sprite()->pixelFormat(),
|
site.sprite()->pixelFormat(),
|
||||||
render::get_sprite_pixel(location.sprite(), pos.x, pos.y, location.frame()));
|
render::get_sprite_pixel(site.sprite(), pos.x, pos.y, site.frame()));
|
||||||
|
|
||||||
doc::CelList cels;
|
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())
|
if (!cels.empty())
|
||||||
m_layer = cels.front()->layer();
|
m_layer = cels.front()->layer();
|
||||||
}
|
}
|
||||||
else { // Pick from the current layer
|
else { // Pick from the current layer
|
||||||
int u, v;
|
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);
|
gfx::Point pt(pos.x-u, pos.y-v);
|
||||||
|
|
||||||
if (image && image->bounds().contains(pt)) {
|
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_color = app::Color::fromImage(image->pixelFormat(), imageColor);
|
||||||
m_layer = const_cast<Layer*>(location.layer());
|
m_layer = const_cast<Layer*>(site.layer());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,11 @@
|
|||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "gfx/point.h"
|
#include "gfx/point.h"
|
||||||
|
|
||||||
|
namespace doc {
|
||||||
|
class Site;
|
||||||
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
class DocumentLocation;
|
|
||||||
|
|
||||||
class ColorPicker {
|
class ColorPicker {
|
||||||
public:
|
public:
|
||||||
@ -22,7 +25,7 @@ namespace app {
|
|||||||
|
|
||||||
ColorPicker();
|
ColorPicker();
|
||||||
|
|
||||||
void pickColor(const DocumentLocation& location,
|
void pickColor(const doc::Site& site,
|
||||||
const gfx::Point& pos, Mode mode);
|
const gfx::Point& pos, Mode mode);
|
||||||
|
|
||||||
app::Color color() const { return m_color; }
|
app::Color color() const { return m_color; }
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/document_api.h"
|
#include "app/document_api.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
#include "app/settings/settings.h"
|
#include "app/settings/settings.h"
|
||||||
#include "app/ui/color_bar.h"
|
#include "app/ui/color_bar.h"
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/commands/commands.h"
|
#include "app/commands/commands.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
#include "app/ui/color_bar.h"
|
#include "app/ui/color_bar.h"
|
||||||
|
@ -54,7 +54,7 @@ void ClearCelCommand::onExecute(Context* context)
|
|||||||
{
|
{
|
||||||
Transaction transaction(writer.context(), "Clear Cel");
|
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();
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
Sprite* sprite = writer.sprite();
|
Sprite* sprite = writer.sprite();
|
||||||
|
@ -58,7 +58,7 @@ public:
|
|||||||
centerWindow();
|
centerWindow();
|
||||||
load_window_pos(this, "ConfigureTool");
|
load_window_pos(this, "ConfigureTool");
|
||||||
|
|
||||||
onSetActiveDocument(m_ctx->activeDocument());
|
onActiveDocumentChange(m_ctx->activeDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
~ToolsConfigurationWindow() {
|
~ToolsConfigurationWindow() {
|
||||||
@ -79,7 +79,7 @@ private:
|
|||||||
return preferences().document(m_ctx->activeDocument());
|
return preferences().document(m_ctx->activeDocument());
|
||||||
}
|
}
|
||||||
|
|
||||||
void onSetActiveDocument(doc::Document* document) override {
|
void onActiveDocumentChange(doc::Document* document) override {
|
||||||
DocumentPreferences& docPref = this->docPref();
|
DocumentPreferences& docPref = this->docPref();
|
||||||
|
|
||||||
tiled()->setSelected(docPref.tiled.mode() != filters::TiledMode::NONE);
|
tiled()->setSelected(docPref.tiled.mode() != filters::TiledMode::NONE);
|
||||||
|
@ -12,11 +12,13 @@
|
|||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
|
#include "app/document.h"
|
||||||
#include "app/ui/main_window.h"
|
#include "app/ui/main_window.h"
|
||||||
#include "app/ui/timeline.h"
|
#include "app/ui/timeline.h"
|
||||||
#include "app/util/clipboard.h"
|
#include "app/util/clipboard.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "ui/base.h"
|
#include "ui/base.h"
|
||||||
|
|
||||||
@ -53,9 +55,9 @@ void CopyCommand::onExecute(Context* context)
|
|||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
clipboard::copy_range(reader, range);
|
clipboard::copy_range(reader, range);
|
||||||
}
|
}
|
||||||
else if (reader.location()->document() &&
|
else if (reader.site()->document() &&
|
||||||
reader.location()->document()->isMaskVisible() &&
|
static_cast<const app::Document*>(reader.site()->document())->isMaskVisible() &&
|
||||||
reader.location()->image()) {
|
reader.site()->image()) {
|
||||||
clipboard::copy(reader);
|
clipboard::copy(reader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
#include "app/color_picker.h"
|
#include "app/color_picker.h"
|
||||||
#include "app/commands/command.h"
|
#include "app/commands/command.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/settings/settings.h"
|
#include "app/settings/settings.h"
|
||||||
#include "app/tools/tool.h"
|
#include "app/tools/tool.h"
|
||||||
@ -23,6 +22,7 @@
|
|||||||
#include "app/ui/editor/editor.h"
|
#include "app/ui/editor/editor.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
#include "ui/system.h"
|
#include "ui/system.h"
|
||||||
@ -80,7 +80,7 @@ void EyedropperCommand::onExecute(Context* context)
|
|||||||
bool grabAlpha = settings->getGrabAlpha();
|
bool grabAlpha = settings->getGrabAlpha();
|
||||||
|
|
||||||
ColorPicker picker;
|
ColorPicker picker;
|
||||||
picker.pickColor(editor->getDocumentLocation(),
|
picker.pickColor(editor->getSite(),
|
||||||
pixelPos,
|
pixelPos,
|
||||||
grabAlpha ?
|
grabAlpha ?
|
||||||
ColorPicker::FromActiveLayer:
|
ColorPicker::FromActiveLayer:
|
||||||
|
@ -79,7 +79,7 @@ void FlipCommand::onExecute(Context* context)
|
|||||||
Mask* mask = document->mask();
|
Mask* mask = document->mask();
|
||||||
CelList cels;
|
CelList cels;
|
||||||
|
|
||||||
DocumentLocation loc = *writer.location();
|
Site site = *writer.site();
|
||||||
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
|
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled())
|
if (range.enabled())
|
||||||
cels = get_unique_cels(sprite, range);
|
cels = get_unique_cels(sprite, range);
|
||||||
@ -87,11 +87,11 @@ void FlipCommand::onExecute(Context* context)
|
|||||||
cels.push_back(writer.cel());
|
cels.push_back(writer.cel());
|
||||||
|
|
||||||
for (Cel* cel : cels) {
|
for (Cel* cel : cels) {
|
||||||
loc.frame(cel->frame());
|
site.frame(cel->frame());
|
||||||
loc.layer(cel->layer());
|
site.layer(cel->layer());
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
Image* image = loc.image(&x, &y);
|
Image* image = site.image(&x, &y);
|
||||||
if (!image)
|
if (!image)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ void FramePropertiesCommand::onExecute(Context* context)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CURRENT_RANGE: {
|
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();
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
firstFrame = range.frameBegin();
|
firstFrame = range.frameBegin();
|
||||||
|
@ -28,11 +28,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void updateStatusBar(DocumentLocation& location) {
|
void updateStatusBar(Site& site) {
|
||||||
if (location.layer() != NULL)
|
if (site.layer() != NULL)
|
||||||
StatusBar::instance()
|
StatusBar::instance()
|
||||||
->setStatusText(1000, "Layer `%s' selected",
|
->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 ContextReader reader(context);
|
||||||
const Sprite* sprite = reader.sprite();
|
const Sprite* sprite = reader.sprite();
|
||||||
DocumentLocation location = *reader.location();
|
Site site = *reader.site();
|
||||||
|
|
||||||
if (location.layerIndex() > 0)
|
if (site.layerIndex() > 0)
|
||||||
location.layerIndex(location.layerIndex().previous());
|
site.layerIndex(site.layerIndex().previous());
|
||||||
else
|
else
|
||||||
location.layerIndex(LayerIndex(sprite->countLayers()-1));
|
site.layerIndex(LayerIndex(sprite->countLayers()-1));
|
||||||
|
|
||||||
// Flash the current layer
|
// Flash the current layer
|
||||||
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
|
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();
|
current_editor->flashCurrentLayer();
|
||||||
|
|
||||||
updateStatusBar(location);
|
updateStatusBar(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
class GotoNextLayerCommand : public GotoCommand {
|
class GotoNextLayerCommand : public GotoCommand {
|
||||||
@ -105,19 +105,19 @@ void GotoNextLayerCommand::onExecute(Context* context)
|
|||||||
{
|
{
|
||||||
const ContextReader reader(context);
|
const ContextReader reader(context);
|
||||||
const Sprite* sprite = reader.sprite();
|
const Sprite* sprite = reader.sprite();
|
||||||
DocumentLocation location = *reader.location();
|
Site site = *reader.site();
|
||||||
|
|
||||||
if (location.layerIndex() < sprite->countLayers()-1)
|
if (site.layerIndex() < sprite->countLayers()-1)
|
||||||
location.layerIndex(location.layerIndex().next());
|
site.layerIndex(site.layerIndex().next());
|
||||||
else
|
else
|
||||||
location.layerIndex(LayerIndex(0));
|
site.layerIndex(LayerIndex(0));
|
||||||
|
|
||||||
// Flash the current layer
|
// Flash the current layer
|
||||||
ASSERT(current_editor != NULL && "Current editor cannot be null when we have a current sprite");
|
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();
|
current_editor->flashCurrentLayer();
|
||||||
|
|
||||||
updateStatusBar(location);
|
updateStatusBar(site);
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* CommandFactory::createGotoPreviousLayerCommand()
|
Command* CommandFactory::createGotoPreviousLayerCommand()
|
||||||
|
@ -257,7 +257,7 @@ retry:;
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Sprite* sprite = document->sprite();
|
Sprite* sprite = document->sprite();
|
||||||
frame_t currentFrame = context->activeLocation().frame();
|
frame_t currentFrame = context->activeSite().frame();
|
||||||
render::Render render;
|
render::Render render;
|
||||||
|
|
||||||
// As first step, we cut each tile and add them into "animation" list.
|
// As first step, we cut each tile and add them into "animation" list.
|
||||||
|
@ -64,7 +64,7 @@ void MaskContentCommand::onExecute(Context* context)
|
|||||||
gfx::Color color;
|
gfx::Color color;
|
||||||
if (writer.layer()->isBackground()) {
|
if (writer.layer()->isBackground()) {
|
||||||
ColorPicker picker;
|
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());
|
color = color_utils::color_for_layer(picker.color(), writer.layer());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -116,7 +116,7 @@ void NewFrameCommand::onExecute(Context* context)
|
|||||||
|
|
||||||
StatusBar::instance()
|
StatusBar::instance()
|
||||||
->showTip(1000, "New frame %d/%d",
|
->showTip(1000, "New frame %d/%d",
|
||||||
(int)context->activeLocation().frame()+1,
|
(int)context->activeSite().frame()+1,
|
||||||
(int)sprite->totalFrames());
|
(int)sprite->totalFrames());
|
||||||
|
|
||||||
App::instance()->getMainWindow()->popTimeline();
|
App::instance()->getMainWindow()->popTimeline();
|
||||||
|
@ -57,7 +57,7 @@ void RemoveFrameCommand::onExecute(Context* context)
|
|||||||
Transaction transaction(writer.context(), "Remove Frame");
|
Transaction transaction(writer.context(), "Remove Frame");
|
||||||
DocumentApi api = document->getApi(transaction);
|
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();
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
for (frame_t frame = range.frameEnd(),
|
for (frame_t frame = range.frameEnd(),
|
||||||
|
@ -62,7 +62,7 @@ void RemoveLayerCommand::onExecute(Context* context)
|
|||||||
Transaction transaction(writer.context(), "Remove Layer");
|
Transaction transaction(writer.context(), "Remove Layer");
|
||||||
DocumentApi api = document->getApi(transaction);
|
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();
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
if (range.layers() == sprite->countLayers()) {
|
if (range.layers() == sprite->countLayers()) {
|
||||||
|
@ -70,8 +70,8 @@ void UndoCommand::onExecute(Context* context)
|
|||||||
App::instance()->preferences().undo.gotoModified();
|
App::instance()->preferences().undo.gotoModified();
|
||||||
|
|
||||||
if (gotoModified) {
|
if (gotoModified) {
|
||||||
SpritePosition currentPosition(writer.location()->layerIndex(),
|
SpritePosition currentPosition(writer.site()->layerIndex(),
|
||||||
writer.location()->frame());
|
writer.site()->frame());
|
||||||
|
|
||||||
if (m_type == Undo)
|
if (m_type == Undo)
|
||||||
spritePosition = undo->nextUndoSpritePosition();
|
spritePosition = undo->nextUndoSpritePosition();
|
||||||
@ -113,8 +113,8 @@ void UndoCommand::onExecute(Context* context)
|
|||||||
// weren't able to reach before the undo).
|
// weren't able to reach before the undo).
|
||||||
if (gotoModified) {
|
if (gotoModified) {
|
||||||
SpritePosition currentPosition(
|
SpritePosition currentPosition(
|
||||||
writer.location()->layerIndex(),
|
writer.site()->layerIndex(),
|
||||||
writer.location()->frame());
|
writer.site()->frame());
|
||||||
|
|
||||||
if (spritePosition != currentPosition) {
|
if (spritePosition != currentPosition) {
|
||||||
current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));
|
current_editor->setLayer(sprite->indexToLayer(spritePosition.layerIndex()));
|
||||||
|
@ -54,7 +54,7 @@ void UnlinkCelCommand::onExecute(Context* context)
|
|||||||
{
|
{
|
||||||
Transaction transaction(writer.context(), "Unlink Cel");
|
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();
|
Timeline::Range range = App::instance()->getMainWindow()->getTimeline()->range();
|
||||||
if (range.enabled()) {
|
if (range.enabled()) {
|
||||||
Sprite* sprite = writer.sprite();
|
Sprite* sprite = writer.sprite();
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "filters/replace_color_filter.h"
|
#include "filters/replace_color_filter.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
|
||||||
@ -134,9 +135,9 @@ bool ReplaceColorCommand::onEnabled(Context* context)
|
|||||||
|
|
||||||
void ReplaceColorCommand::onExecute(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.setFrom(get_config_color(ConfigSection, "Color1", ColorBar::instance()->getFgColor()));
|
||||||
filter.setTo(get_config_color(ConfigSection, "Color2", ColorBar::instance()->getBgColor()));
|
filter.setTo(get_config_color(ConfigSection, "Color2", ColorBar::instance()->getBgColor()));
|
||||||
filter.setTolerance(get_config_int(ConfigSection, "Tolerance", 0));
|
filter.setTolerance(get_config_int(ConfigSection, "Tolerance", 0));
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "app/cmd/copy_rect.h"
|
#include "app/cmd/copy_rect.h"
|
||||||
#include "app/cmd/unlink_cel.h"
|
#include "app/cmd/unlink_cel.h"
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
|
#include "app/document.h"
|
||||||
#include "app/ini_file.h"
|
#include "app/ini_file.h"
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
@ -23,6 +24,7 @@
|
|||||||
#include "doc/images_collector.h"
|
#include "doc/images_collector.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "filters/filter.h"
|
#include "filters/filter.h"
|
||||||
#include "ui/manager.h"
|
#include "ui/manager.h"
|
||||||
@ -40,7 +42,7 @@ using namespace ui;
|
|||||||
|
|
||||||
FilterManagerImpl::FilterManagerImpl(Context* context, Filter* filter)
|
FilterManagerImpl::FilterManagerImpl(Context* context, Filter* filter)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
, m_location(context->activeLocation())
|
, m_site(context->activeSite())
|
||||||
, m_filter(filter)
|
, m_filter(filter)
|
||||||
, m_dst(NULL)
|
, m_dst(NULL)
|
||||||
, m_preview_mask(NULL)
|
, m_preview_mask(NULL)
|
||||||
@ -56,17 +58,22 @@ FilterManagerImpl::FilterManagerImpl(Context* context, Filter* filter)
|
|||||||
m_targetOrig = TARGET_ALL_CHANNELS;
|
m_targetOrig = TARGET_ALL_CHANNELS;
|
||||||
m_target = 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)
|
if (image == NULL)
|
||||||
throw NoImageException();
|
throw NoImageException();
|
||||||
|
|
||||||
init(m_location.layer(), image, offset_x, offset_y);
|
init(m_site.layer(), image, offset_x, offset_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
FilterManagerImpl::~FilterManagerImpl()
|
FilterManagerImpl::~FilterManagerImpl()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app::Document* FilterManagerImpl::document()
|
||||||
|
{
|
||||||
|
return static_cast<app::Document*>(m_site.document());
|
||||||
|
}
|
||||||
|
|
||||||
void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
|
void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
|
||||||
{
|
{
|
||||||
m_progressDelegate = progressDelegate;
|
m_progressDelegate = progressDelegate;
|
||||||
@ -74,7 +81,7 @@ void FilterManagerImpl::setProgressDelegate(IProgressDelegate* progressDelegate)
|
|||||||
|
|
||||||
PixelFormat FilterManagerImpl::pixelFormat() const
|
PixelFormat FilterManagerImpl::pixelFormat() const
|
||||||
{
|
{
|
||||||
return m_location.sprite()->pixelFormat();
|
return m_site.sprite()->pixelFormat();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterManagerImpl::setTarget(int target)
|
void FilterManagerImpl::setTarget(int target)
|
||||||
@ -83,14 +90,14 @@ void FilterManagerImpl::setTarget(int target)
|
|||||||
m_target = target;
|
m_target = target;
|
||||||
|
|
||||||
// The alpha channel of the background layer can't be modified.
|
// The alpha channel of the background layer can't be modified.
|
||||||
if (m_location.layer() &&
|
if (m_site.layer() &&
|
||||||
m_location.layer()->isBackground())
|
m_site.layer()->isBackground())
|
||||||
m_target &= ~TARGET_ALPHA_CHANNEL;
|
m_target &= ~TARGET_ALPHA_CHANNEL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FilterManagerImpl::begin()
|
void FilterManagerImpl::begin()
|
||||||
{
|
{
|
||||||
Document* document = m_location.document();
|
Document* document = static_cast<app::Document*>(m_site.document());
|
||||||
|
|
||||||
m_row = 0;
|
m_row = 0;
|
||||||
m_mask = (document->isMaskVisible() ? document->mask(): NULL);
|
m_mask = (document->isMaskVisible() ? document->mask(): NULL);
|
||||||
@ -100,7 +107,7 @@ void FilterManagerImpl::begin()
|
|||||||
|
|
||||||
void FilterManagerImpl::beginForPreview()
|
void FilterManagerImpl::beginForPreview()
|
||||||
{
|
{
|
||||||
Document* document = m_location.document();
|
Document* document = static_cast<app::Document*>(m_site.document());
|
||||||
|
|
||||||
if (document->isMaskVisible())
|
if (document->isMaskVisible())
|
||||||
m_preview_mask.reset(new Mask(*document->mask()));
|
m_preview_mask.reset(new Mask(*document->mask()));
|
||||||
@ -117,7 +124,7 @@ void FilterManagerImpl::beginForPreview()
|
|||||||
|
|
||||||
{
|
{
|
||||||
Editor* editor = current_editor;
|
Editor* editor = current_editor;
|
||||||
Sprite* sprite = m_location.sprite();
|
Sprite* sprite = m_site.sprite();
|
||||||
gfx::Rect vp = View::getView(editor)->getViewportBounds();
|
gfx::Rect vp = View::getView(editor)->getViewportBounds();
|
||||||
vp = editor->screenToEditor(vp);
|
vp = editor->screenToEditor(vp);
|
||||||
vp = vp.createIntersect(sprite->bounds());
|
vp = vp.createIntersect(sprite->bounds());
|
||||||
@ -162,7 +169,7 @@ bool FilterManagerImpl::applyStep()
|
|||||||
m_maskIterator = m_maskBits.begin();
|
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_RGB: m_filter->applyToRgba(this); break;
|
||||||
case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break;
|
case IMAGE_GRAYSCALE: m_filter->applyToGrayscale(this); break;
|
||||||
case IMAGE_INDEXED: m_filter->applyToIndexed(this); break;
|
case IMAGE_INDEXED: m_filter->applyToIndexed(this); break;
|
||||||
@ -199,9 +206,9 @@ void FilterManagerImpl::applyToTarget()
|
|||||||
bool cancelled = false;
|
bool cancelled = false;
|
||||||
|
|
||||||
ImagesCollector images((m_target & TARGET_ALL_LAYERS ?
|
ImagesCollector images((m_target & TARGET_ALL_LAYERS ?
|
||||||
m_location.sprite()->folder():
|
m_site.sprite()->folder():
|
||||||
m_location.layer()),
|
m_site.layer()),
|
||||||
m_location.frame(),
|
m_site.frame(),
|
||||||
(m_target & TARGET_ALL_FRAMES) == TARGET_ALL_FRAMES,
|
(m_target & TARGET_ALL_FRAMES) == TARGET_ALL_FRAMES,
|
||||||
true); // we will write in each image
|
true); // we will write in each image
|
||||||
if (images.empty())
|
if (images.empty())
|
||||||
@ -289,12 +296,12 @@ bool FilterManagerImpl::skipPixel()
|
|||||||
|
|
||||||
Palette* FilterManagerImpl::getPalette()
|
Palette* FilterManagerImpl::getPalette()
|
||||||
{
|
{
|
||||||
return m_location.sprite()->palette(m_location.frame());
|
return m_site.sprite()->palette(m_site.frame());
|
||||||
}
|
}
|
||||||
|
|
||||||
RgbMap* FilterManagerImpl::getRgbMap()
|
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)
|
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_x = offset_x;
|
||||||
m_offset_y = offset_y;
|
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();
|
throw InvalidAreaException();
|
||||||
|
|
||||||
m_src = image;
|
m_src = image;
|
||||||
|
@ -9,14 +9,14 @@
|
|||||||
#define APP_COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED
|
#define APP_COMMANDS_FILTERS_FILTER_MANAGER_IMPL_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "base/exception.h"
|
#include "base/exception.h"
|
||||||
#include "base/unique_ptr.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_bits.h"
|
||||||
#include "doc/image_traits.h"
|
#include "doc/image_traits.h"
|
||||||
#include "doc/pixel_format.h"
|
#include "doc/pixel_format.h"
|
||||||
|
#include "doc/site.h"
|
||||||
|
#include "filters/filter_indexed_data.h"
|
||||||
|
#include "filters/filter_manager.h"
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ namespace app {
|
|||||||
|
|
||||||
void setProgressDelegate(IProgressDelegate* progressDelegate);
|
void setProgressDelegate(IProgressDelegate* progressDelegate);
|
||||||
|
|
||||||
PixelFormat pixelFormat() const;
|
doc::PixelFormat pixelFormat() const;
|
||||||
|
|
||||||
void setTarget(Target target);
|
void setTarget(Target target);
|
||||||
|
|
||||||
@ -82,11 +82,11 @@ namespace app {
|
|||||||
bool applyStep();
|
bool applyStep();
|
||||||
void applyToTarget();
|
void applyToTarget();
|
||||||
|
|
||||||
Document* document() { return m_location.document(); }
|
app::Document* document();
|
||||||
Sprite* sprite() { return m_location.sprite(); }
|
doc::Sprite* sprite() { return m_site.sprite(); }
|
||||||
Layer* layer() { return m_location.layer(); }
|
doc::Layer* layer() { return m_site.layer(); }
|
||||||
frame_t frame() { return m_location.frame(); }
|
doc::frame_t frame() { return m_site.frame(); }
|
||||||
Image* destinationImage() const { return m_dst; }
|
doc::Image* destinationImage() const { return m_dst; }
|
||||||
|
|
||||||
// Updates the current editor to show the progress of the preview.
|
// Updates the current editor to show the progress of the preview.
|
||||||
void flush();
|
void flush();
|
||||||
@ -98,30 +98,30 @@ namespace app {
|
|||||||
Target getTarget() { return m_target; }
|
Target getTarget() { return m_target; }
|
||||||
FilterIndexedData* getIndexedData() { return this; }
|
FilterIndexedData* getIndexedData() { return this; }
|
||||||
bool skipPixel();
|
bool skipPixel();
|
||||||
const Image* getSourceImage() { return m_src; }
|
const doc::Image* getSourceImage() { return m_src; }
|
||||||
int x() { return m_x; }
|
int x() { return m_x; }
|
||||||
int y() { return m_y+m_row; }
|
int y() { return m_y+m_row; }
|
||||||
|
|
||||||
// FilterIndexedData implementation
|
// FilterIndexedData implementation
|
||||||
Palette* getPalette();
|
doc::Palette* getPalette();
|
||||||
RgbMap* getRgbMap();
|
doc::RgbMap* getRgbMap();
|
||||||
|
|
||||||
private:
|
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 apply(Transaction& transaction);
|
||||||
void applyToImage(Transaction& transaction, Layer* layer, Image* image, int x, int y);
|
void applyToImage(Transaction& transaction, doc::Layer* layer, doc::Image* image, int x, int y);
|
||||||
bool updateMask(Mask* mask, const Image* image);
|
bool updateMask(doc::Mask* mask, const doc::Image* image);
|
||||||
|
|
||||||
Context* m_context;
|
Context* m_context;
|
||||||
DocumentLocation m_location;
|
doc::Site m_site;
|
||||||
Filter* m_filter;
|
Filter* m_filter;
|
||||||
Image* m_src;
|
doc::Image* m_src;
|
||||||
base::UniquePtr<Image> m_dst;
|
base::UniquePtr<doc::Image> m_dst;
|
||||||
int m_row;
|
int m_row;
|
||||||
int m_x, m_y, m_w, m_h;
|
int m_x, m_y, m_w, m_h;
|
||||||
int m_offset_x, m_offset_y;
|
int m_offset_x, m_offset_y;
|
||||||
Mask* m_mask;
|
doc::Mask* m_mask;
|
||||||
base::UniquePtr<Mask> m_preview_mask;
|
base::UniquePtr<doc::Mask> m_preview_mask;
|
||||||
doc::ImageBits<doc::BitmapTraits> m_maskBits;
|
doc::ImageBits<doc::BitmapTraits> m_maskBits;
|
||||||
doc::ImageBits<doc::BitmapTraits>::iterator m_maskIterator;
|
doc::ImageBits<doc::BitmapTraits>::iterator m_maskIterator;
|
||||||
Target m_targetOrig; // Original targets
|
Target m_targetOrig; // Original targets
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "app/commands/commands.h"
|
#include "app/commands/commands.h"
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/settings/settings.h"
|
#include "app/settings/settings.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
@ -52,14 +51,6 @@ app::Document* Context::activeDocument() const
|
|||||||
return static_cast<app::Document*>(doc::Context::activeDocument());
|
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)
|
void Context::executeCommand(const char* commandName)
|
||||||
{
|
{
|
||||||
Command* cmd = CommandsModule::instance()->getCommandByName(commandName);
|
Command* cmd = CommandsModule::instance()->getCommandByName(commandName);
|
||||||
@ -124,9 +115,4 @@ void Context::onCreateDocument(doc::CreateDocumentArgs* args)
|
|||||||
args->setDocument(new app::Document(NULL));
|
args->setDocument(new app::Document(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::onGetActiveLocation(DocumentLocation* location) const
|
|
||||||
{
|
|
||||||
// Without active location
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
namespace app {
|
namespace app {
|
||||||
class Command;
|
class Command;
|
||||||
class Document;
|
class Document;
|
||||||
class DocumentLocation;
|
|
||||||
class ISettings;
|
class ISettings;
|
||||||
|
|
||||||
class CommandPreconditionException : public base::Exception {
|
class CommandPreconditionException : public base::Exception {
|
||||||
@ -50,7 +49,6 @@ namespace app {
|
|||||||
void sendDocumentToTop(doc::Document* document);
|
void sendDocumentToTop(doc::Document* document);
|
||||||
|
|
||||||
app::Document* activeDocument() const;
|
app::Document* activeDocument() const;
|
||||||
DocumentLocation activeLocation() const;
|
|
||||||
|
|
||||||
void executeCommand(const char* commandName);
|
void executeCommand(const char* commandName);
|
||||||
virtual void executeCommand(Command* command, const Params& params = Params());
|
virtual void executeCommand(Command* command, const Params& params = Params());
|
||||||
@ -60,7 +58,6 @@ namespace app {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
|
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
|
||||||
virtual void onGetActiveLocation(DocumentLocation* location) const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Settings in this context.
|
// Settings in this context.
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "app/document_access.h"
|
#include "app/document_access.h"
|
||||||
#include "app/document_location.h"
|
#include "doc/site.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
@ -20,35 +20,35 @@ namespace app {
|
|||||||
class ContextAccess {
|
class ContextAccess {
|
||||||
public:
|
public:
|
||||||
const Context* context() const { return m_context; }
|
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 DocumentAccessT& document() const { return m_document; }
|
||||||
const Sprite* sprite() const { return m_location.sprite(); }
|
const Sprite* sprite() const { return m_site.sprite(); }
|
||||||
const Layer* layer() const { return m_location.layer(); }
|
const Layer* layer() const { return m_site.layer(); }
|
||||||
frame_t frame() const { return m_location.frame(); }
|
frame_t frame() const { return m_site.frame(); }
|
||||||
const Cel* cel() const { return m_location.cel(); }
|
const Cel* cel() const { return m_site.cel(); }
|
||||||
|
|
||||||
// You cannot change the location directly from a writable ContextAccess anyway.
|
// You cannot change the site directly from a writable ContextAccess anyway.
|
||||||
const DocumentLocation* location() { return &m_location; }
|
const Site* site() { return &m_site; }
|
||||||
|
|
||||||
Context* context() { return const_cast<Context*>(m_context); }
|
Context* context() { return const_cast<Context*>(m_context); }
|
||||||
DocumentAccessT& document() { return m_document; }
|
DocumentAccessT& document() { return m_document; }
|
||||||
Sprite* sprite() { return m_location.sprite(); }
|
Sprite* sprite() { return m_site.sprite(); }
|
||||||
Layer* layer() { return m_location.layer(); }
|
Layer* layer() { return m_site.layer(); }
|
||||||
Cel* cel() { return m_location.cel(); }
|
Cel* cel() { return m_site.cel(); }
|
||||||
|
|
||||||
Image* image(int* x = NULL, int* y = NULL, int* opacity = NULL) const {
|
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 {
|
Palette* palette() const {
|
||||||
return m_location.palette();
|
return m_site.palette();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ContextAccess(const Context* context, int timeout)
|
ContextAccess(const Context* context, int timeout)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
, m_document(context->activeDocument(), timeout)
|
, 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)
|
ContextAccess(const Context* context, const DocumentReaderT& documentReader, int timeout)
|
||||||
: m_context(context)
|
: m_context(context)
|
||||||
, m_document(documentReader, timeout)
|
, m_document(documentReader, timeout)
|
||||||
, m_location(context->activeLocation())
|
, m_site(context->activeSite())
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const Context* m_context;
|
const Context* m_context;
|
||||||
DocumentAccessT m_document;
|
DocumentAccessT m_document;
|
||||||
DocumentLocation m_location;
|
Site m_site;
|
||||||
};
|
};
|
||||||
|
|
||||||
// You can use this class to access to the given context to read the
|
// You can use this class to access to the given context to read the
|
||||||
|
@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
#include "app/context.h"
|
#include "app/context.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
@ -27,8 +27,8 @@ ContextFlags::ContextFlags()
|
|||||||
|
|
||||||
void ContextFlags::update(Context* context)
|
void ContextFlags::update(Context* context)
|
||||||
{
|
{
|
||||||
DocumentLocation location = context->activeLocation();
|
Site site = context->activeSite();
|
||||||
Document* document = location.document();
|
Document* document = static_cast<Document*>(site.document());
|
||||||
|
|
||||||
m_flags = 0;
|
m_flags = 0;
|
||||||
|
|
||||||
@ -41,14 +41,14 @@ void ContextFlags::update(Context* context)
|
|||||||
if (document->isMaskVisible())
|
if (document->isMaskVisible())
|
||||||
m_flags |= HasVisibleMask;
|
m_flags |= HasVisibleMask;
|
||||||
|
|
||||||
Sprite* sprite = location.sprite();
|
Sprite* sprite = site.sprite();
|
||||||
if (sprite) {
|
if (sprite) {
|
||||||
m_flags |= HasActiveSprite;
|
m_flags |= HasActiveSprite;
|
||||||
|
|
||||||
if (sprite->backgroundLayer())
|
if (sprite->backgroundLayer())
|
||||||
m_flags |= HasBackgroundLayer;
|
m_flags |= HasBackgroundLayer;
|
||||||
|
|
||||||
Layer* layer = location.layer();
|
Layer* layer = site.layer();
|
||||||
if (layer) {
|
if (layer) {
|
||||||
m_flags |= HasActiveLayer;
|
m_flags |= HasActiveLayer;
|
||||||
|
|
||||||
@ -64,7 +64,7 @@ void ContextFlags::update(Context* context)
|
|||||||
if (layer->isImage()) {
|
if (layer->isImage()) {
|
||||||
m_flags |= ActiveLayerIsImage;
|
m_flags |= ActiveLayerIsImage;
|
||||||
|
|
||||||
Cel* cel = layer->cel(location.frame());
|
Cel* cel = layer->cel(site.frame());
|
||||||
if (cel) {
|
if (cel) {
|
||||||
m_flags |= HasActiveCel;
|
m_flags |= HasActiveCel;
|
||||||
|
|
||||||
|
@ -7,13 +7,15 @@
|
|||||||
|
|
||||||
#include "tests/test.h"
|
#include "tests/test.h"
|
||||||
|
|
||||||
|
#include "app/context.h"
|
||||||
|
#include "app/document.h"
|
||||||
#include "app/document_api.h"
|
#include "app/document_api.h"
|
||||||
#include "app/test_context.h"
|
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/primitives.h"
|
#include "doc/primitives.h"
|
||||||
|
#include "doc/test_context.h"
|
||||||
|
|
||||||
using namespace app;
|
using namespace app;
|
||||||
using namespace doc;
|
using namespace doc;
|
||||||
@ -21,7 +23,7 @@ using namespace doc;
|
|||||||
typedef base::UniquePtr<app::Document> DocumentPtr;
|
typedef base::UniquePtr<app::Document> DocumentPtr;
|
||||||
|
|
||||||
TEST(DocumentApi, MoveCel) {
|
TEST(DocumentApi, MoveCel) {
|
||||||
TestContext ctx;
|
TestContextT<app::Context> ctx;
|
||||||
DocumentPtr doc(static_cast<app::Document*>(ctx.documents().add(32, 16)));
|
DocumentPtr doc(static_cast<app::Document*>(ctx.documents().add(32, 16)));
|
||||||
Sprite* sprite = doc->sprite();
|
Sprite* sprite = doc->sprite();
|
||||||
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
LayerImage* layer1 = dynamic_cast<LayerImage*>(sprite->folder()->getFirstLayer());
|
||||||
|
@ -7,15 +7,16 @@
|
|||||||
|
|
||||||
#include "tests/test.h"
|
#include "tests/test.h"
|
||||||
|
|
||||||
|
#include "app/context.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_api.h"
|
#include "app/document_api.h"
|
||||||
#include "app/document_range.h"
|
#include "app/document_range.h"
|
||||||
#include "app/document_range_ops.h"
|
#include "app/document_range_ops.h"
|
||||||
#include "app/document_undo.h"
|
#include "app/document_undo.h"
|
||||||
#include "app/test_context.h"
|
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
#include "doc/doc.h"
|
#include "doc/doc.h"
|
||||||
|
#include "doc/test_context.h"
|
||||||
|
|
||||||
using namespace app;
|
using namespace app;
|
||||||
using namespace doc;
|
using namespace doc;
|
||||||
@ -181,7 +182,7 @@ protected:
|
|||||||
return (cel == NULL);
|
return (cel == NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TestContext ctx;
|
TestContextT<app::Context> ctx;
|
||||||
DocumentPtr doc;
|
DocumentPtr doc;
|
||||||
Sprite* sprite;
|
Sprite* sprite;
|
||||||
LayerImage* layer1;
|
LayerImage* layer1;
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
#include "app/file/file.h"
|
#include "app/file/file.h"
|
||||||
#include "app/file/file_formats_manager.h"
|
#include "app/file/file_formats_manager.h"
|
||||||
#include "app/file/gif_options.h"
|
#include "app/file/gif_options.h"
|
||||||
#include "app/test_context.h"
|
|
||||||
#include "doc/doc.h"
|
#include "doc/doc.h"
|
||||||
|
#include "doc/test_context.h"
|
||||||
#include "she/scoped_handle.h"
|
#include "she/scoped_handle.h"
|
||||||
#include "she/system.h"
|
#include "she/system.h"
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
app::TestContext m_ctx;
|
doc::TestContextT<app::Context> m_ctx;
|
||||||
she::ScopedHandle<she::System> m_system;
|
she::ScopedHandle<she::System> m_system;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/ini_file.h"
|
#include "app/ini_file.h"
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
|
@ -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
|
|
@ -25,9 +25,7 @@ Transaction::Transaction(Context* ctx, const std::string& label, Modification mo
|
|||||||
: m_ctx(ctx)
|
: m_ctx(ctx)
|
||||||
, m_cmds(NULL)
|
, m_cmds(NULL)
|
||||||
{
|
{
|
||||||
DocumentLocation location = m_ctx->activeLocation();
|
m_undo = m_ctx->activeDocument()->undoHistory();
|
||||||
|
|
||||||
m_undo = location.document()->undoHistory();
|
|
||||||
m_cmds = new CmdTransaction(label,
|
m_cmds = new CmdTransaction(label,
|
||||||
modification == Modification::ModifyDocument,
|
modification == Modification::ModifyDocument,
|
||||||
m_undo->savedCounter());
|
m_undo->savedCounter());
|
||||||
|
@ -195,7 +195,7 @@ void ColorBar::setPaletteEditorButtonState(bool state)
|
|||||||
m_paletteButton.setSelected(state);
|
m_paletteButton.setSelected(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ColorBar::onSetActiveDocument(doc::Document* document)
|
void ColorBar::onActiveDocumentChange(doc::Document* document)
|
||||||
{
|
{
|
||||||
destroyRemap();
|
destroyRemap();
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace app {
|
|||||||
void setPaletteEditorButtonState(bool state);
|
void setPaletteEditorButtonState(bool state);
|
||||||
|
|
||||||
// ContextObserver impl
|
// ContextObserver impl
|
||||||
void onSetActiveDocument(doc::Document* document) override;
|
void onActiveDocumentChange(doc::Document* document) override;
|
||||||
|
|
||||||
// Signals
|
// Signals
|
||||||
Signal1<void, const app::Color&> FgColorChange;
|
Signal1<void, const app::Color&> FgColorChange;
|
||||||
|
@ -13,7 +13,6 @@
|
|||||||
#include "app/color.h"
|
#include "app/color.h"
|
||||||
#include "app/color_picker.h"
|
#include "app/color_picker.h"
|
||||||
#include "app/color_utils.h"
|
#include "app/color_utils.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
#include "app/modules/gui.h"
|
#include "app/modules/gui.h"
|
||||||
#include "app/ui/color_bar.h"
|
#include "app/ui/color_bar.h"
|
||||||
@ -22,6 +21,7 @@
|
|||||||
#include "app/ui/editor/editor.h"
|
#include "app/ui/editor/editor.h"
|
||||||
#include "app/ui/skin/skin_theme.h"
|
#include "app/ui/skin/skin_theme.h"
|
||||||
#include "app/ui/status_bar.h"
|
#include "app/ui/status_bar.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "ui/preferred_size_event.h"
|
#include "ui/preferred_size_event.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
@ -120,12 +120,12 @@ bool ColorButton::onProcessMessage(Message* msg)
|
|||||||
// Pick a color from a editor
|
// Pick a color from a editor
|
||||||
else if (picked->type == editor_type()) {
|
else if (picked->type == editor_type()) {
|
||||||
Editor* editor = static_cast<Editor*>(picked);
|
Editor* editor = static_cast<Editor*>(picked);
|
||||||
DocumentLocation location = editor->getDocumentLocation();
|
Site site = editor->getSite();
|
||||||
if (location.sprite()) {
|
if (site.sprite()) {
|
||||||
gfx::Point editorPos = editor->screenToEditor(mousePos);
|
gfx::Point editorPos = editor->screenToEditor(mousePos);
|
||||||
|
|
||||||
ColorPicker picker;
|
ColorPicker picker;
|
||||||
picker.pickColor(location, editorPos, ColorPicker::FromComposition);
|
picker.pickColor(site, editorPos, ColorPicker::FromComposition);
|
||||||
color = picker.color();
|
color = picker.color();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,9 +208,9 @@ DocumentView::~DocumentView()
|
|||||||
delete m_editor;
|
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()
|
std::string DocumentView::getTabText()
|
||||||
|
@ -14,13 +14,16 @@
|
|||||||
#include "doc/document_observer.h"
|
#include "doc/document_observer.h"
|
||||||
#include "ui/box.h"
|
#include "ui/box.h"
|
||||||
|
|
||||||
|
namespace doc {
|
||||||
|
class Site;
|
||||||
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
class View;
|
class View;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
class Document;
|
class Document;
|
||||||
class DocumentLocation;
|
|
||||||
class Editor;
|
class Editor;
|
||||||
|
|
||||||
class DocumentView : public ui::Box
|
class DocumentView : public ui::Box
|
||||||
@ -37,7 +40,7 @@ namespace app {
|
|||||||
~DocumentView();
|
~DocumentView();
|
||||||
|
|
||||||
Document* getDocument() const { return m_document; }
|
Document* getDocument() const { return m_document; }
|
||||||
void getDocumentLocation(DocumentLocation* location) const;
|
void getSite(doc::Site* site) const;
|
||||||
Editor* getEditor() { return m_editor; }
|
Editor* getEditor() { return m_editor; }
|
||||||
|
|
||||||
bool isPreview() { return m_type == Preview; }
|
bool isPreview() { return m_type == Preview; }
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include "app/commands/commands.h"
|
#include "app/commands/commands.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/console.h"
|
#include "app/console.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/ini_file.h"
|
#include "app/ini_file.h"
|
||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
#include "app/modules/gui.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);
|
site->document(m_document);
|
||||||
location->sprite(m_sprite);
|
site->sprite(m_sprite);
|
||||||
location->layer(m_layer);
|
site->layer(m_layer);
|
||||||
location->frame(m_frame);
|
site->frame(m_frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
DocumentLocation Editor::getDocumentLocation() const
|
Site Editor::getSite() const
|
||||||
{
|
{
|
||||||
DocumentLocation location;
|
Site site;
|
||||||
getDocumentLocation(&location);
|
getSite(&site);
|
||||||
return location;
|
return site;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::setDefaultScroll()
|
void Editor::setDefaultScroll()
|
||||||
@ -745,10 +744,10 @@ void Editor::flashCurrentLayer()
|
|||||||
if (!App::instance()->preferences().experimental.flashLayer())
|
if (!App::instance()->preferences().experimental.flashLayer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
DocumentLocation loc = getDocumentLocation();
|
Site site = getSite();
|
||||||
|
|
||||||
int x, y;
|
int x, y;
|
||||||
const Image* src_image = loc.image(&x, &y);
|
const Image* src_image = site.image(&x, &y);
|
||||||
if (src_image) {
|
if (src_image) {
|
||||||
m_renderEngine.removePreviewImage();
|
m_renderEngine.removePreviewImage();
|
||||||
|
|
||||||
@ -1484,8 +1483,7 @@ void Editor::pasteImage(const Image* image, const gfx::Point& pos)
|
|||||||
|
|
||||||
PixelsMovementPtr pixelsMovement(
|
PixelsMovementPtr pixelsMovement(
|
||||||
new PixelsMovement(UIContext::instance(),
|
new PixelsMovement(UIContext::instance(),
|
||||||
getDocumentLocation(),
|
getSite(), image, gfx::Point(x, y), opacity, "Paste"));
|
||||||
image, gfx::Point(x, y), opacity, "Paste"));
|
|
||||||
|
|
||||||
// Select the pasted image so the user can move it and transform it.
|
// Select the pasted image so the user can move it and transform it.
|
||||||
pixelsMovement->maskImage(image);
|
pixelsMovement->maskImage(image);
|
||||||
|
@ -28,8 +28,9 @@
|
|||||||
#include "ui/widget.h"
|
#include "ui/widget.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Sprite;
|
|
||||||
class Layer;
|
class Layer;
|
||||||
|
class Site;
|
||||||
|
class Sprite;
|
||||||
}
|
}
|
||||||
namespace gfx {
|
namespace gfx {
|
||||||
class Region;
|
class Region;
|
||||||
@ -41,7 +42,6 @@ namespace ui {
|
|||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
class Context;
|
class Context;
|
||||||
class DocumentLocation;
|
|
||||||
class DocumentView;
|
class DocumentView;
|
||||||
class EditorCustomizationDelegate;
|
class EditorCustomizationDelegate;
|
||||||
class PixelsMovement;
|
class PixelsMovement;
|
||||||
@ -106,8 +106,8 @@ namespace app {
|
|||||||
Layer* layer() { return m_layer; }
|
Layer* layer() { return m_layer; }
|
||||||
frame_t frame() { return m_frame; }
|
frame_t frame() { return m_frame; }
|
||||||
|
|
||||||
void getDocumentLocation(DocumentLocation* location) const;
|
void getSite(Site* site) const;
|
||||||
DocumentLocation getDocumentLocation() const;
|
Site getSite() const;
|
||||||
|
|
||||||
void setLayer(const Layer* layer);
|
void setLayer(const Layer* layer);
|
||||||
void setFrame(frame_t frame);
|
void setFrame(frame_t frame);
|
||||||
|
@ -32,6 +32,7 @@
|
|||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
#include "gfx/region.h"
|
#include "gfx/region.h"
|
||||||
#include "render/render.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,
|
PixelsMovement::PixelsMovement(Context* context,
|
||||||
DocumentLocation location,
|
Site site,
|
||||||
const Image* moveThis, const gfx::Point& initialPos, int opacity,
|
const Image* moveThis, const gfx::Point& initialPos, int opacity,
|
||||||
const char* operationName)
|
const char* operationName)
|
||||||
: m_reader(context)
|
: m_reader(context)
|
||||||
, m_location(location)
|
, m_site(site)
|
||||||
, m_document(location.document())
|
, m_document(static_cast<app::Document*>(site.document()))
|
||||||
, m_sprite(location.sprite())
|
, m_sprite(site.sprite())
|
||||||
, m_layer(location.layer())
|
, m_layer(site.layer())
|
||||||
, m_transaction(context, operationName)
|
, m_transaction(context, operationName)
|
||||||
, m_setMaskCmd(nullptr)
|
, m_setMaskCmd(nullptr)
|
||||||
, m_isDragging(false)
|
, m_isDragging(false)
|
||||||
@ -443,7 +444,7 @@ void PixelsMovement::stampImage()
|
|||||||
{
|
{
|
||||||
// Expand the canvas to paste the image in the fully visible
|
// Expand the canvas to paste the image in the fully visible
|
||||||
// portion of sprite.
|
// portion of sprite.
|
||||||
ExpandCelCanvas expand(m_location,
|
ExpandCelCanvas expand(m_site,
|
||||||
TiledMode::NONE, m_transaction,
|
TiledMode::NONE, m_transaction,
|
||||||
ExpandCelCanvas::None);
|
ExpandCelCanvas::None);
|
||||||
|
|
||||||
@ -473,7 +474,7 @@ void PixelsMovement::dropImageTemporarily()
|
|||||||
|
|
||||||
// TODO Add undo information so the user can undo each transformation step.
|
// 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) {
|
if (m_adjustPivot) {
|
||||||
m_adjustPivot = false;
|
m_adjustPivot = false;
|
||||||
|
|
||||||
|
@ -11,11 +11,12 @@
|
|||||||
|
|
||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/settings/settings_observers.h"
|
#include "app/settings/settings_observers.h"
|
||||||
#include "app/ui/editor/handle_type.h"
|
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
|
#include "app/ui/editor/handle_type.h"
|
||||||
#include "base/shared_ptr.h"
|
#include "base/shared_ptr.h"
|
||||||
#include "gfx/size.h"
|
|
||||||
#include "doc/algorithm/flip_type.h"
|
#include "doc/algorithm/flip_type.h"
|
||||||
|
#include "doc/site.h"
|
||||||
|
#include "gfx/size.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Image;
|
class Image;
|
||||||
@ -47,7 +48,7 @@ namespace app {
|
|||||||
// The "moveThis" image specifies the chunk of pixels to be moved.
|
// The "moveThis" image specifies the chunk of pixels to be moved.
|
||||||
// The "x" and "y" parameters specify the initial position of the image.
|
// The "x" and "y" parameters specify the initial position of the image.
|
||||||
PixelsMovement(Context* context,
|
PixelsMovement(Context* context,
|
||||||
DocumentLocation location,
|
Site site,
|
||||||
const Image* moveThis,
|
const Image* moveThis,
|
||||||
const gfx::Point& initialPos, int opacity,
|
const gfx::Point& initialPos, int opacity,
|
||||||
const char* operationName);
|
const char* operationName);
|
||||||
@ -104,7 +105,7 @@ namespace app {
|
|||||||
void updateDocumentMask();
|
void updateDocumentMask();
|
||||||
|
|
||||||
const ContextReader m_reader;
|
const ContextReader m_reader;
|
||||||
DocumentLocation m_location;
|
Site m_site;
|
||||||
Document* m_document;
|
Document* m_document;
|
||||||
Sprite* m_sprite;
|
Sprite* m_sprite;
|
||||||
Layer* m_layer;
|
Layer* m_layer;
|
||||||
|
@ -15,7 +15,6 @@
|
|||||||
#include "app/color_picker.h"
|
#include "app/color_picker.h"
|
||||||
#include "app/commands/commands.h"
|
#include "app/commands/commands.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/ini_file.h"
|
#include "app/ini_file.h"
|
||||||
#include "app/settings/settings.h"
|
#include "app/settings/settings.h"
|
||||||
#include "app/tools/ink.h"
|
#include "app/tools/ink.h"
|
||||||
@ -145,10 +144,10 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
|||||||
|
|
||||||
UIContext* context = UIContext::instance();
|
UIContext* context = UIContext::instance();
|
||||||
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
tools::Ink* clickedInk = editor->getCurrentEditorInk();
|
||||||
DocumentLocation location;
|
Site site;
|
||||||
editor->getDocumentLocation(&location);
|
editor->getSite(&site);
|
||||||
Document* document = location.document();
|
app::Document* document = static_cast<app::Document*>(site.document());
|
||||||
Layer* layer = location.layer();
|
Layer* layer = site.layer();
|
||||||
|
|
||||||
// When an editor is clicked the current view is changed.
|
// When an editor is clicked the current view is changed.
|
||||||
context->setActiveView(editor->getDocumentView());
|
context->setActiveView(editor->getDocumentView());
|
||||||
@ -164,7 +163,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
|||||||
gfx::Point cursor = editor->screenToEditor(msg->position());
|
gfx::Point cursor = editor->screenToEditor(msg->position());
|
||||||
|
|
||||||
ColorPicker picker;
|
ColorPicker picker;
|
||||||
picker.pickColor(location, cursor, ColorPicker::FromComposition);
|
picker.pickColor(site, cursor, ColorPicker::FromComposition);
|
||||||
|
|
||||||
if (layer != picker.layer()) {
|
if (layer != picker.layer()) {
|
||||||
layer = picker.layer();
|
layer = picker.layer();
|
||||||
@ -217,7 +216,7 @@ bool StandbyState::onMouseDown(Editor* editor, MouseMessage* msg)
|
|||||||
|
|
||||||
if (handle != NoHandle) {
|
if (handle != NoHandle) {
|
||||||
int x, y, opacity;
|
int x, y, opacity;
|
||||||
Image* image = location.image(&x, &y, &opacity);
|
Image* image = site.image(&x, &y, &opacity);
|
||||||
if (layer && image) {
|
if (layer && image) {
|
||||||
if (!layer->isEditable()) {
|
if (!layer->isEditable()) {
|
||||||
StatusBar::instance()->showTip(1000,
|
StatusBar::instance()->showTip(1000,
|
||||||
@ -370,7 +369,7 @@ bool StandbyState::onUpdateStatusBar(Editor* editor)
|
|||||||
else if (ink->isEyedropper()) {
|
else if (ink->isEyedropper()) {
|
||||||
bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
|
bool grabAlpha = UIContext::instance()->settings()->getGrabAlpha();
|
||||||
ColorPicker picker;
|
ColorPicker picker;
|
||||||
picker.pickColor(editor->getDocumentLocation(),
|
picker.pickColor(editor->getSite(),
|
||||||
spritePos,
|
spritePos,
|
||||||
grabAlpha ?
|
grabAlpha ?
|
||||||
ColorPicker::FromActiveLayer:
|
ColorPicker::FromActiveLayer:
|
||||||
@ -416,12 +415,12 @@ void StandbyState::transformSelection(Editor* editor, MouseMessage* msg, HandleT
|
|||||||
try {
|
try {
|
||||||
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
|
EditorCustomizationDelegate* customization = editor->getCustomizationDelegate();
|
||||||
Document* document = editor->document();
|
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();
|
gfx::Point origin = document->mask()->bounds().getOrigin();
|
||||||
int opacity = 255;
|
int opacity = 255;
|
||||||
PixelsMovementPtr pixelsMovement(
|
PixelsMovementPtr pixelsMovement(
|
||||||
new PixelsMovement(UIContext::instance(),
|
new PixelsMovement(UIContext::instance(),
|
||||||
editor->getDocumentLocation(),
|
editor->getSite(),
|
||||||
tmpImage, origin, opacity,
|
tmpImage, origin, opacity,
|
||||||
"Transformation"));
|
"Transformation"));
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public:
|
|||||||
getInk()->isSlice() ||
|
getInk()->isSlice() ||
|
||||||
getInk()->isZoom()) ? DoesntModifyDocument:
|
getInk()->isZoom()) ? DoesntModifyDocument:
|
||||||
ModifyDocument))
|
ModifyDocument))
|
||||||
, m_expandCelCanvas(editor->getDocumentLocation(),
|
, m_expandCelCanvas(editor->getSite(),
|
||||||
m_docPref.tiled.mode(),
|
m_docPref.tiled.mode(),
|
||||||
m_transaction,
|
m_transaction,
|
||||||
ExpandCelCanvas::Flags(
|
ExpandCelCanvas::Flags(
|
||||||
|
@ -17,7 +17,6 @@
|
|||||||
#include "app/commands/commands.h"
|
#include "app/commands/commands.h"
|
||||||
#include "app/commands/params.h"
|
#include "app/commands/params.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/settings/settings.h"
|
#include "app/settings/settings.h"
|
||||||
#include "app/tools/ink.h"
|
#include "app/tools/ink.h"
|
||||||
#include "app/tools/tool.h"
|
#include "app/tools/tool.h"
|
||||||
@ -635,8 +634,7 @@ void KeyboardShortcuts::disableAccel(const ui::Accelerator& accel, KeyContext ke
|
|||||||
KeyContext KeyboardShortcuts::getCurrentKeyContext()
|
KeyContext KeyboardShortcuts::getCurrentKeyContext()
|
||||||
{
|
{
|
||||||
app::Context* ctx = UIContext::instance();
|
app::Context* ctx = UIContext::instance();
|
||||||
DocumentLocation location = ctx->activeLocation();
|
Document* doc = ctx->activeDocument();
|
||||||
Document* doc = location.document();
|
|
||||||
|
|
||||||
if (doc &&
|
if (doc &&
|
||||||
doc->isMaskVisible() &&
|
doc->isMaskVisible() &&
|
||||||
|
@ -157,24 +157,24 @@ void Timeline::updateUsingEditor(Editor* editor)
|
|||||||
else
|
else
|
||||||
return; // No editor specified.
|
return; // No editor specified.
|
||||||
|
|
||||||
DocumentLocation location;
|
Site site;
|
||||||
DocumentView* view = m_editor->getDocumentView();
|
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
|
// If we are already in the same position as the "editor", we don't
|
||||||
// need to update the at all timeline.
|
// need to update the at all timeline.
|
||||||
if (m_document == location.document() &&
|
if (m_document == site.document() &&
|
||||||
m_sprite == location.sprite() &&
|
m_sprite == site.sprite() &&
|
||||||
m_layer == location.layer() &&
|
m_layer == site.layer() &&
|
||||||
m_frame == location.frame())
|
m_frame == site.frame())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_document = location.document();
|
m_document = static_cast<app::Document*>(site.document());
|
||||||
m_sprite = location.sprite();
|
m_sprite = site.sprite();
|
||||||
m_layer = location.layer();
|
m_layer = site.layer();
|
||||||
m_frame = location.frame();
|
m_frame = site.frame();
|
||||||
m_state = STATE_STANDBY;
|
m_state = STATE_STANDBY;
|
||||||
m_hot.part = PART_NOTHING;
|
m_hot.part = PART_NOTHING;
|
||||||
m_clk.part = PART_NOTHING;
|
m_clk.part = PART_NOTHING;
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
#include "app/app.h"
|
#include "app/app.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/pref/preferences.h"
|
#include "app/pref/preferences.h"
|
||||||
#include "app/settings/ui_settings_impl.h"
|
#include "app/settings/ui_settings_impl.h"
|
||||||
@ -26,15 +25,17 @@
|
|||||||
#include "app/ui/workspace_tabs.h"
|
#include "app/ui/workspace_tabs.h"
|
||||||
#include "app/ui_context.h"
|
#include "app/ui_context.h"
|
||||||
#include "base/mutex.h"
|
#include "base/mutex.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
UIContext* UIContext::m_instance = NULL;
|
UIContext* UIContext::m_instance = nullptr;
|
||||||
|
|
||||||
UIContext::UIContext()
|
UIContext::UIContext()
|
||||||
: Context(new UISettingsImpl)
|
: Context(new UISettingsImpl)
|
||||||
, m_lastSelectedView(NULL)
|
, m_lastSelectedDoc(nullptr)
|
||||||
|
, m_lastSelectedView(nullptr)
|
||||||
{
|
{
|
||||||
documents().addObserver(&App::instance()->preferences());
|
documents().addObserver(&App::instance()->preferences());
|
||||||
|
|
||||||
@ -81,8 +82,6 @@ void UIContext::setActiveView(DocumentView* docView)
|
|||||||
(docView && docView->isPreview()))
|
(docView && docView->isPreview()))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
setActiveDocument(docView ? docView->getDocument(): NULL);
|
|
||||||
|
|
||||||
MainWindow* mainWin = App::instance()->getMainWindow();
|
MainWindow* mainWin = App::instance()->getMainWindow();
|
||||||
if (docView) {
|
if (docView) {
|
||||||
mainWin->getTabsBar()->selectTab(docView);
|
mainWin->getTabsBar()->selectTab(docView);
|
||||||
@ -112,6 +111,16 @@ void UIContext::setActiveView(DocumentView* docView)
|
|||||||
m_lastSelectedView = 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
|
DocumentView* UIContext::getFirstDocumentView(Document* document) const
|
||||||
{
|
{
|
||||||
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
||||||
@ -138,14 +147,14 @@ Editor* UIContext::activeEditor()
|
|||||||
|
|
||||||
void UIContext::onAddDocument(doc::Document* doc)
|
void UIContext::onAddDocument(doc::Document* doc)
|
||||||
{
|
{
|
||||||
Context::onAddDocument(doc);
|
m_lastSelectedDoc = static_cast<app::Document*>(doc);
|
||||||
|
|
||||||
// We don't create views in batch mode.
|
// We don't create views in batch mode.
|
||||||
if (!App::instance()->isGui())
|
if (!App::instance()->isGui())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Add a new view for this document
|
// 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
|
// Add a tab with the new view for the document
|
||||||
App::instance()->getMainWindow()->getWorkspace()->addView(view);
|
App::instance()->getMainWindow()->getWorkspace()->addView(view);
|
||||||
@ -156,6 +165,9 @@ void UIContext::onAddDocument(doc::Document* doc)
|
|||||||
|
|
||||||
void UIContext::onRemoveDocument(doc::Document* doc)
|
void UIContext::onRemoveDocument(doc::Document* doc)
|
||||||
{
|
{
|
||||||
|
if (doc == m_lastSelectedDoc)
|
||||||
|
m_lastSelectedDoc = nullptr;
|
||||||
|
|
||||||
// We don't destroy views in batch mode.
|
// We don't destroy views in batch mode.
|
||||||
if (isUiAvailable()) {
|
if (isUiAvailable()) {
|
||||||
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
Workspace* workspace = App::instance()->getMainWindow()->getWorkspace();
|
||||||
@ -175,22 +187,20 @@ void UIContext::onRemoveDocument(doc::Document* doc)
|
|||||||
delete docView;
|
delete docView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context::onRemoveDocument(doc);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIContext::onGetActiveLocation(DocumentLocation* location) const
|
void UIContext::onGetActiveSite(Site* site) const
|
||||||
{
|
{
|
||||||
DocumentView* view = activeView();
|
DocumentView* view = activeView();
|
||||||
if (view) {
|
if (view) {
|
||||||
view->getDocumentLocation(location);
|
view->getSite(site);
|
||||||
}
|
}
|
||||||
// Default/dummy location (maybe for batch/command line mode)
|
// Default/dummy site (maybe for batch/command line mode)
|
||||||
else if (Document* doc = activeDocument()) {
|
else if (Document* doc = m_lastSelectedDoc) {
|
||||||
location->document(doc);
|
site->document(doc);
|
||||||
location->sprite(doc->sprite());
|
site->sprite(doc->sprite());
|
||||||
location->layer(doc->sprite()->indexToLayer(LayerIndex(0)));
|
site->layer(doc->sprite()->indexToLayer(LayerIndex(0)));
|
||||||
location->frame(0);
|
site->frame(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,7 @@ namespace app {
|
|||||||
|
|
||||||
DocumentView* activeView() const;
|
DocumentView* activeView() const;
|
||||||
void setActiveView(DocumentView* documentView);
|
void setActiveView(DocumentView* documentView);
|
||||||
|
void setActiveDocument(Document* document);
|
||||||
|
|
||||||
DocumentView* getFirstDocumentView(Document* document) const;
|
DocumentView* getFirstDocumentView(Document* document) const;
|
||||||
|
|
||||||
@ -40,11 +41,12 @@ namespace app {
|
|||||||
Editor* getEditorFor(Document* document);
|
Editor* getEditorFor(Document* document);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void onAddDocument(doc::Document* doc) override;
|
void onAddDocument(doc::Document* doc) override;
|
||||||
virtual void onRemoveDocument(doc::Document* doc) override;
|
void onRemoveDocument(doc::Document* doc) override;
|
||||||
virtual void onGetActiveLocation(DocumentLocation* location) const override;
|
void onGetActiveSite(doc::Site* site) const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Document* m_lastSelectedDoc;
|
||||||
DocumentView* m_lastSelectedView;
|
DocumentView* m_lastSelectedView;
|
||||||
static UIContext* m_instance;
|
static UIContext* m_instance;
|
||||||
};
|
};
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
#include "app/context_access.h"
|
#include "app/context_access.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_api.h"
|
#include "app/document_api.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/document_range.h"
|
#include "app/document_range.h"
|
||||||
#include "app/modules/editors.h"
|
#include "app/modules/editors.h"
|
||||||
#include "app/modules/gfx.h"
|
#include "app/modules/gfx.h"
|
||||||
@ -83,7 +82,7 @@ namespace {
|
|||||||
using namespace doc;
|
using namespace doc;
|
||||||
|
|
||||||
static void set_clipboard_image(Image* image, Palette* palette, bool set_system_clipboard);
|
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;
|
static bool first_time = true;
|
||||||
|
|
||||||
@ -120,20 +119,20 @@ static void set_clipboard_image(Image* image, Palette* palette, bool set_system_
|
|||||||
clipboard_range.invalidate();
|
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 != NULL);
|
||||||
ASSERT(document->isMaskVisible());
|
ASSERT(document->isMaskVisible());
|
||||||
|
|
||||||
Image* image = new_image_from_mask(location);
|
Image* image = new_image_from_mask(site);
|
||||||
if (!image)
|
if (!image)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
clipboard_pos = document->mask()->bounds().getOrigin();
|
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);
|
set_clipboard_image(image, pal ? new Palette(*pal): NULL, true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -175,7 +174,7 @@ void clipboard::cut(ContextWriter& writer)
|
|||||||
ASSERT(writer.sprite() != NULL);
|
ASSERT(writer.sprite() != NULL);
|
||||||
ASSERT(writer.layer() != NULL);
|
ASSERT(writer.layer() != NULL);
|
||||||
|
|
||||||
if (!copy_from_document(*writer.location())) {
|
if (!copy_from_document(*writer.site())) {
|
||||||
Console console;
|
Console console;
|
||||||
console.printf("Can't copying an image portion from the current layer\n");
|
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);
|
ASSERT(reader.document() != NULL);
|
||||||
|
|
||||||
if (!copy_from_document(*reader.location())) {
|
if (!copy_from_document(*reader.site())) {
|
||||||
Console console;
|
Console console;
|
||||||
console.printf("Can't copying an image portion from the current layer\n");
|
console.printf("Can't copying an image portion from the current layer\n");
|
||||||
return;
|
return;
|
||||||
|
@ -18,7 +18,6 @@
|
|||||||
#include "app/cmd/set_cel_position.h"
|
#include "app/cmd/set_cel_position.h"
|
||||||
#include "app/context.h"
|
#include "app/context.h"
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "app/transaction.h"
|
#include "app/transaction.h"
|
||||||
#include "app/util/range_utils.h"
|
#include "app/util/range_utils.h"
|
||||||
#include "base/unique_ptr.h"
|
#include "base/unique_ptr.h"
|
||||||
@ -26,6 +25,7 @@
|
|||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/primitives.h"
|
#include "doc/primitives.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
@ -53,11 +53,11 @@ static void create_buffers()
|
|||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
|
ExpandCelCanvas::ExpandCelCanvas(Site site,
|
||||||
TiledMode tiledMode, Transaction& transaction, Flags flags)
|
TiledMode tiledMode, Transaction& transaction, Flags flags)
|
||||||
: m_document(location.document())
|
: m_document(static_cast<app::Document*>(site.document()))
|
||||||
, m_sprite(location.sprite())
|
, m_sprite(site.sprite())
|
||||||
, m_layer(location.layer())
|
, m_layer(site.layer())
|
||||||
, m_cel(NULL)
|
, m_cel(NULL)
|
||||||
, m_celImage(NULL)
|
, m_celImage(NULL)
|
||||||
, m_celCreated(false)
|
, m_celCreated(false)
|
||||||
@ -71,7 +71,7 @@ ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
|
|||||||
create_buffers();
|
create_buffers();
|
||||||
|
|
||||||
if (m_layer->isImage()) {
|
if (m_layer->isImage()) {
|
||||||
m_cel = m_layer->cel(location.frame());
|
m_cel = m_layer->cel(site.frame());
|
||||||
if (m_cel)
|
if (m_cel)
|
||||||
m_celImage = m_cel->imageRef();
|
m_celImage = m_cel->imageRef();
|
||||||
}
|
}
|
||||||
@ -79,7 +79,7 @@ ExpandCelCanvas::ExpandCelCanvas(DocumentLocation location,
|
|||||||
// Create a new cel
|
// Create a new cel
|
||||||
if (m_cel == NULL) {
|
if (m_cel == NULL) {
|
||||||
m_celCreated = true;
|
m_celCreated = true;
|
||||||
m_cel = new Cel(location.frame(), ImageRef(NULL));
|
m_cel = new Cel(site.frame(), ImageRef(NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_origCelPos = m_cel->position();
|
m_origCelPos = m_cel->position();
|
||||||
|
@ -20,12 +20,12 @@ namespace doc {
|
|||||||
class Cel;
|
class Cel;
|
||||||
class Image;
|
class Image;
|
||||||
class Layer;
|
class Layer;
|
||||||
|
class Site;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
class Document;
|
class Document;
|
||||||
class DocumentLocation;
|
|
||||||
class Transaction;
|
class Transaction;
|
||||||
|
|
||||||
using namespace filters;
|
using namespace filters;
|
||||||
@ -45,7 +45,7 @@ namespace app {
|
|||||||
UseModifiedRegionAsUndoInfo = 2,
|
UseModifiedRegionAsUndoInfo = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
ExpandCelCanvas(DocumentLocation location,
|
ExpandCelCanvas(Site site,
|
||||||
TiledMode tiledMode, Transaction& undo, Flags flags);
|
TiledMode tiledMode, Transaction& undo, Flags flags);
|
||||||
~ExpandCelCanvas();
|
~ExpandCelCanvas();
|
||||||
|
|
||||||
|
@ -12,25 +12,25 @@
|
|||||||
#include "app/util/new_image_from_mask.h"
|
#include "app/util/new_image_from_mask.h"
|
||||||
|
|
||||||
#include "app/document.h"
|
#include "app/document.h"
|
||||||
#include "app/document_location.h"
|
|
||||||
#include "doc/image.h"
|
#include "doc/image.h"
|
||||||
#include "doc/image_bits.h"
|
#include "doc/image_bits.h"
|
||||||
#include "doc/image_traits.h"
|
#include "doc/image_traits.h"
|
||||||
#include "doc/mask.h"
|
#include "doc/mask.h"
|
||||||
|
#include "doc/site.h"
|
||||||
|
|
||||||
namespace app {
|
namespace app {
|
||||||
|
|
||||||
using namespace doc;
|
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 Sprite* srcSprite = site.sprite();
|
||||||
const Mask* srcMask = location.document()->mask();
|
const Mask* srcMask = static_cast<const app::Document*>(site.document())->mask();
|
||||||
const Image* srcMaskBitmap = srcMask->bitmap();
|
const Image* srcMaskBitmap = srcMask->bitmap();
|
||||||
const gfx::Rect& srcBounds = srcMask->bounds();
|
const gfx::Rect& srcBounds = srcMask->bounds();
|
||||||
int x, y, u, v, getx, gety;
|
int x, y, u, v, getx, gety;
|
||||||
Image *dst;
|
Image *dst;
|
||||||
const Image *src = location.image(&x, &y);
|
const Image *src = site.image(&x, &y);
|
||||||
|
|
||||||
ASSERT(srcSprite);
|
ASSERT(srcSprite);
|
||||||
ASSERT(srcMask);
|
ASSERT(srcMask);
|
||||||
|
@ -11,12 +11,12 @@
|
|||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
class Image;
|
class Image;
|
||||||
|
class Site;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace app {
|
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
|
} // namespace app
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ add_library(doc-lib
|
|||||||
primitives.cpp
|
primitives.cpp
|
||||||
remap.cpp
|
remap.cpp
|
||||||
rgbmap.cpp
|
rgbmap.cpp
|
||||||
|
site.cpp
|
||||||
sprite.cpp
|
sprite.cpp
|
||||||
sprites.cpp
|
sprites.cpp
|
||||||
string_io.cpp
|
string_io.cpp
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#include "doc/context.h"
|
#include "doc/context.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include "doc/site.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
@ -23,30 +23,46 @@ Context::Context()
|
|||||||
|
|
||||||
Context::~Context()
|
Context::~Context()
|
||||||
{
|
{
|
||||||
setActiveDocument(NULL);
|
|
||||||
m_docs.removeObserver(this);
|
m_docs.removeObserver(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Site Context::activeSite() const
|
||||||
|
{
|
||||||
|
Site site;
|
||||||
|
onGetActiveSite(&site);
|
||||||
|
return site;
|
||||||
|
}
|
||||||
|
|
||||||
Document* Context::activeDocument() const
|
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::onActiveDocumentChange, doc);
|
||||||
notifyObservers(&ContextObserver::onSetActiveDocument, doc);
|
}
|
||||||
|
|
||||||
|
void Context::notifyActiveSiteChanged(Site* site)
|
||||||
|
{
|
||||||
|
notifyObservers(&ContextObserver::onActiveSiteChange, site);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Context::onGetActiveSite(Site* site) const
|
||||||
|
{
|
||||||
|
ASSERT(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::onAddDocument(Document* doc)
|
void Context::onAddDocument(Document* doc)
|
||||||
{
|
{
|
||||||
m_activeDoc = doc;
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
void Context::onRemoveDocument(Document* doc)
|
void Context::onRemoveDocument(Document* doc)
|
||||||
{
|
{
|
||||||
if (m_activeDoc == doc)
|
// Do nothing
|
||||||
setActiveDocument(!m_docs.empty() ? m_docs.back() : NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
@ -28,10 +28,14 @@ namespace doc {
|
|||||||
const Documents& documents() const { return m_docs; }
|
const Documents& documents() const { return m_docs; }
|
||||||
Documents& documents() { return m_docs; }
|
Documents& documents() { return m_docs; }
|
||||||
|
|
||||||
|
Site activeSite() const;
|
||||||
Document* activeDocument() 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 onAddDocument(Document* doc) override;
|
||||||
virtual void onRemoveDocument(Document* doc) override;
|
virtual void onRemoveDocument(Document* doc) override;
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite Document Library
|
// 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.
|
// This file is released under the terms of the MIT license.
|
||||||
// Read LICENSE.txt for more information.
|
// Read LICENSE.txt for more information.
|
||||||
@ -11,11 +11,13 @@
|
|||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
class Document;
|
class Document;
|
||||||
|
class Site;
|
||||||
|
|
||||||
class ContextObserver {
|
class ContextObserver {
|
||||||
public:
|
public:
|
||||||
virtual ~ContextObserver() { }
|
virtual ~ContextObserver() { }
|
||||||
virtual void onSetActiveDocument(Document* document) { }
|
virtual void onActiveDocumentChange(Document* document) { }
|
||||||
|
virtual void onActiveSiteChange(Site* site) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace doc
|
} // namespace doc
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
#include "doc/primitives_fast.h"
|
#include "doc/primitives_fast.h"
|
||||||
#include "doc/remap.h"
|
#include "doc/remap.h"
|
||||||
#include "doc/rgbmap.h"
|
#include "doc/rgbmap.h"
|
||||||
|
#include "doc/site.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -1,42 +1,39 @@
|
|||||||
// Aseprite
|
// Aseprite Document Library
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This file is released under the terms of the MIT license.
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// Read LICENSE.txt for more information.
|
||||||
// published by the Free Software Foundation.
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "app/document_location.h"
|
#include "doc/site.h"
|
||||||
|
|
||||||
#include "doc/cel.h"
|
#include "doc/cel.h"
|
||||||
#include "doc/layer.h"
|
#include "doc/layer.h"
|
||||||
#include "doc/sprite.h"
|
#include "doc/sprite.h"
|
||||||
|
|
||||||
namespace app {
|
namespace doc {
|
||||||
|
|
||||||
using namespace doc;
|
LayerIndex Site::layerIndex() const
|
||||||
|
|
||||||
LayerIndex DocumentLocation::layerIndex() const
|
|
||||||
{
|
{
|
||||||
return (m_sprite && m_layer ?
|
return (m_sprite && m_layer ?
|
||||||
m_sprite->layerToIndex(m_layer): LayerIndex());
|
m_sprite->layerToIndex(m_layer): LayerIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DocumentLocation::layerIndex(LayerIndex layerIndex)
|
void Site::layerIndex(LayerIndex layerIndex)
|
||||||
{
|
{
|
||||||
ASSERT(m_sprite != NULL);
|
ASSERT(m_sprite != NULL);
|
||||||
m_layer = m_sprite->indexToLayer(layerIndex);
|
m_layer = m_sprite->indexToLayer(layerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
Palette* DocumentLocation::palette()
|
Palette* Site::palette()
|
||||||
{
|
{
|
||||||
return (m_sprite ? m_sprite->palette(m_frame): NULL);
|
return (m_sprite ? m_sprite->palette(m_frame): NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
const Cel* DocumentLocation::cel() const
|
const Cel* Site::cel() const
|
||||||
{
|
{
|
||||||
if (m_layer)
|
if (m_layer)
|
||||||
return m_layer->cel(m_frame);
|
return m_layer->cel(m_frame);
|
||||||
@ -44,7 +41,7 @@ const Cel* DocumentLocation::cel() const
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cel* DocumentLocation::cel()
|
Cel* Site::cel()
|
||||||
{
|
{
|
||||||
if (m_layer)
|
if (m_layer)
|
||||||
return m_layer->cel(m_frame);
|
return m_layer->cel(m_frame);
|
||||||
@ -52,7 +49,7 @@ Cel* DocumentLocation::cel()
|
|||||||
return NULL;
|
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;
|
Image* image = NULL;
|
||||||
|
|
||||||
@ -68,9 +65,9 @@ Image* DocumentLocation::image(int* x, int* y, int* opacity) const
|
|||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
Palette* DocumentLocation::palette() const
|
Palette* Site::palette() const
|
||||||
{
|
{
|
||||||
return (m_sprite ? m_sprite->palette(m_frame): NULL);
|
return (m_sprite ? m_sprite->palette(m_frame): NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace app
|
} // namespace doc
|
@ -1,36 +1,31 @@
|
|||||||
// Aseprite
|
// Aseprite Document Library
|
||||||
// Copyright (C) 2001-2015 David Capello
|
// Copyright (c) 2001-2015 David Capello
|
||||||
//
|
//
|
||||||
// This program is free software; you can redistribute it and/or modify
|
// This file is released under the terms of the MIT license.
|
||||||
// it under the terms of the GNU General Public License version 2 as
|
// Read LICENSE.txt for more information.
|
||||||
// published by the Free Software Foundation.
|
|
||||||
|
|
||||||
#ifndef APP_DOCUMENT_LOCATION_H_INCLUDED
|
#ifndef DOC_SITE_H_INCLUDED
|
||||||
#define APP_DOCUMENT_LOCATION_H_INCLUDED
|
#define DOC_SITE_H_INCLUDED
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "doc/frame.h"
|
#include "doc/frame.h"
|
||||||
#include "doc/layer_index.h"
|
#include "doc/layer_index.h"
|
||||||
|
|
||||||
namespace doc {
|
namespace doc {
|
||||||
|
|
||||||
class Cel;
|
class Cel;
|
||||||
|
class Document;
|
||||||
class Image;
|
class Image;
|
||||||
class Layer;
|
class Layer;
|
||||||
class Palette;
|
class Palette;
|
||||||
class Sprite;
|
class Sprite;
|
||||||
}
|
|
||||||
|
|
||||||
namespace app {
|
// Specifies the current location in a context. E.g. the location in
|
||||||
class Document;
|
// the current Editor (current document, sprite, layer, frame,
|
||||||
|
// etc.).
|
||||||
using namespace doc;
|
class Site {
|
||||||
|
|
||||||
// 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 {
|
|
||||||
public:
|
public:
|
||||||
DocumentLocation()
|
Site()
|
||||||
: m_document(NULL)
|
: m_document(NULL)
|
||||||
, m_sprite(NULL)
|
, m_sprite(NULL)
|
||||||
, m_layer(NULL)
|
, m_layer(NULL)
|
55
src/doc/test_context.h
Normal file
55
src/doc/test_context.h
Normal 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
|
Loading…
x
Reference in New Issue
Block a user