Ability to move several frames in X or Y axis, fix #431

This commit is contained in:
David Capello 2014-08-25 08:27:42 -03:00
parent 0aea78318a
commit 8a3f7a6396
5 changed files with 34 additions and 15 deletions

View File

@ -23,17 +23,21 @@
#include "app/ui/editor/moving_cel_state.h"
#include "app/app.h"
#include "app/ui/editor/editor.h"
#include "app/ui/status_bar.h"
#include "app/context_access.h"
#include "app/document_api.h"
#include "app/document_range.h"
#include "app/ui/editor/editor.h"
#include "app/ui/main_window.h"
#include "app/ui/status_bar.h"
#include "app/ui/timeline.h"
#include "app/ui_context.h"
#include "app/undo_transaction.h"
#include "app/util/range_utils.h"
#include "raster/cel.h"
#include "raster/layer.h"
#include "raster/mask.h"
#include "raster/sprite.h"
#include "ui/message.h"
#include "app/ui_context.h"
#include "app/undo_transaction.h"
namespace app {
@ -91,14 +95,23 @@ bool MovingCelState::onMouseUp(Editor* editor, MouseMessage* msg)
UndoTransaction undoTransaction(writer.context(), "Cel Movement", undo::ModifyDocument);
DocumentApi api = document->getApi();
// And now we move the cel to the new position.
if (m_cel)
// And now we move the cel (or all selected range) to the new position.
int deltaX = m_celNewX - m_celStartX;
int deltaY = m_celNewY - m_celStartY;
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
for (Cel* cel : get_cels_in_range(writer.sprite(), range))
api.setCelPosition(writer.sprite(), cel, cel->x()+deltaX, cel->y()+deltaY);
}
else if (m_cel) {
api.setCelPosition(writer.sprite(), m_cel, m_celNewX, m_celNewY);
}
// Move selection if it was visible
if (m_maskVisible)
api.setMaskPosition(document->mask()->bounds().x + m_celNewX - m_celStartX,
document->mask()->bounds().y + m_celNewY - m_celStartY);
api.setMaskPosition(document->mask()->bounds().x + deltaX,
document->mask()->bounds().y + deltaY);
undoTransaction.commit();
}

View File

@ -46,6 +46,7 @@ UIContext* UIContext::m_instance = NULL;
UIContext::UIContext()
: Context(new UISettingsImpl)
, m_lastSelectedView(NULL)
{
ASSERT(m_instance == NULL);
m_instance = this;
@ -74,6 +75,9 @@ DocumentView* UIContext::activeView() const
void UIContext::setActiveView(DocumentView* docView)
{
if (m_lastSelectedView == docView) // Do nothing case
return;
setActiveDocument(docView ? docView->getDocument(): NULL);
if (docView != NULL) {
@ -108,6 +112,8 @@ void UIContext::setActiveView(DocumentView* docView)
title += defaultTitle;
set_window_title(title.c_str());
m_lastSelectedView = docView;
}
size_t UIContext::countViewsOf(Document* document) const

View File

@ -57,6 +57,7 @@ namespace app {
virtual void onGetActiveLocation(DocumentLocation* location) const override;
private:
DocumentView* m_lastSelectedView;
static UIContext* m_instance;
};

View File

@ -30,9 +30,10 @@ namespace app {
using namespace raster;
std::vector<Cel*> get_cels_in_range(Sprite* sprite, const DocumentRange& range)
// TODO the DocumentRange should be "iteratable" to replace this function
CelList get_cels_in_range(Sprite* sprite, const DocumentRange& range)
{
std::vector<Cel*> cels;
CelList cels;
for (LayerIndex layerIdx = range.layerBegin(); layerIdx <= range.layerEnd(); ++layerIdx) {
Layer* layer = sprite->indexToLayer(layerIdx);

View File

@ -20,16 +20,14 @@
#define APP_UTIL_RANGE_UTILS_H_INCLUDED
#pragma once
#include <vector>
#include "raster/object.h"
namespace raster {
class Sprite;
}
#include <vector>
namespace app {
class DocumentRange;
std::vector<Cel*> get_cels_in_range(raster::Sprite* sprite, const DocumentRange& range);
CelList get_cels_in_range(raster::Sprite* sprite, const DocumentRange& range);
} // namespace app