mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-23 18:39:55 +00:00
Remove Site::layerIndex() member
This commit is contained in:
parent
6bffc9f740
commit
ab86a1f5ee
@ -1,5 +1,5 @@
|
||||
// Aseprite
|
||||
// Copyright (C) 2001-2015 David Capello
|
||||
// Copyright (C) 2001-2016 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
|
||||
@ -16,104 +16,105 @@
|
||||
#include "app/modules/gui.h"
|
||||
#include "app/ui/editor/editor.h"
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "app/ui/timeline.h"
|
||||
#include "doc/layer.h"
|
||||
#include "doc/sprite.h"
|
||||
|
||||
namespace app {
|
||||
|
||||
class GotoCommand : public Command {
|
||||
class GotoLayerCommand : public Command {
|
||||
public:
|
||||
GotoCommand(const char* short_name, const char* friendly_name, CommandFlags flags)
|
||||
: Command(short_name, friendly_name, flags) {
|
||||
GotoLayerCommand(int offset,
|
||||
const char* shortName,
|
||||
const char* friendlyName,
|
||||
CommandFlags flags)
|
||||
: Command(shortName, friendlyName, flags),
|
||||
m_offset(offset) {
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
bool onEnabled(Context* context) override {
|
||||
return (current_editor &&
|
||||
current_editor->document());
|
||||
}
|
||||
|
||||
void onExecute(Context* context) override {
|
||||
Site site = current_editor->getSite();
|
||||
|
||||
// TODO add support for layer groups
|
||||
|
||||
Layer* layer = site.layer();
|
||||
if (!layer)
|
||||
return;
|
||||
|
||||
const auto& layers = layer->parent()->layers();
|
||||
auto it = std::find(layers.begin(), layers.end(), layer);
|
||||
if (it == layers.end())
|
||||
return;
|
||||
|
||||
if (m_offset > 0) {
|
||||
int i = m_offset;
|
||||
while (i-- > 0) {
|
||||
++it;
|
||||
if (it == layers.end())
|
||||
it = layers.begin();
|
||||
}
|
||||
}
|
||||
else if (m_offset < 0) {
|
||||
int i = m_offset;
|
||||
while (i++ < 0) {
|
||||
if (it == layers.begin())
|
||||
it = layers.end();
|
||||
--it;
|
||||
}
|
||||
}
|
||||
|
||||
site.layer(*it);
|
||||
|
||||
// Flash the current layer
|
||||
current_editor->setLayer(site.layer());
|
||||
current_editor->flashCurrentLayer();
|
||||
|
||||
updateStatusBar(site);
|
||||
}
|
||||
|
||||
void updateStatusBar(Site& site) {
|
||||
if (site.layer() != NULL)
|
||||
StatusBar::instance()
|
||||
->setStatusText(1000, "Layer `%s' selected",
|
||||
site.layer()->name().c_str());
|
||||
StatusBar::instance()->setStatusText(
|
||||
1000, "%s '%s' selected",
|
||||
(site.layer()->isGroup() ? "Group": "Layer"),
|
||||
site.layer()->name().c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
int m_offset;
|
||||
};
|
||||
|
||||
class GotoPreviousLayerCommand : public GotoLayerCommand {
|
||||
public:
|
||||
GotoPreviousLayerCommand()
|
||||
: GotoLayerCommand(-1, "GotoPreviousLayer",
|
||||
"Go to Previous Layer",
|
||||
CmdUIOnlyFlag) {
|
||||
}
|
||||
Command* clone() const override {
|
||||
return new GotoPreviousLayerCommand(*this);
|
||||
}
|
||||
};
|
||||
|
||||
class GotoPreviousLayerCommand : public GotoCommand {
|
||||
class GotoNextLayerCommand : public GotoLayerCommand {
|
||||
public:
|
||||
GotoPreviousLayerCommand();
|
||||
Command* clone() const override { return new GotoPreviousLayerCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
GotoNextLayerCommand()
|
||||
: GotoLayerCommand(+1, "GotoNextLayer",
|
||||
"Go to Next Layer",
|
||||
CmdUIOnlyFlag) {
|
||||
}
|
||||
Command* clone() const override {
|
||||
return new GotoNextLayerCommand(*this);
|
||||
}
|
||||
};
|
||||
|
||||
GotoPreviousLayerCommand::GotoPreviousLayerCommand()
|
||||
: GotoCommand("GotoPreviousLayer",
|
||||
"Go to Previous Layer",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool GotoPreviousLayerCommand::onEnabled(Context* context)
|
||||
{
|
||||
return (current_editor != nullptr &&
|
||||
current_editor->document());
|
||||
}
|
||||
|
||||
void GotoPreviousLayerCommand::onExecute(Context* context)
|
||||
{
|
||||
Site site = current_editor->getSite();
|
||||
|
||||
if (site.layerIndex() > 0)
|
||||
site.layerIndex(site.layerIndex().previous());
|
||||
else
|
||||
site.layerIndex(LayerIndex(site.sprite()->countLayers()-1));
|
||||
|
||||
// Flash the current layer
|
||||
current_editor->setLayer(site.layer());
|
||||
current_editor->flashCurrentLayer();
|
||||
|
||||
updateStatusBar(site);
|
||||
}
|
||||
|
||||
class GotoNextLayerCommand : public GotoCommand {
|
||||
public:
|
||||
GotoNextLayerCommand();
|
||||
Command* clone() const override { return new GotoNextLayerCommand(*this); }
|
||||
|
||||
protected:
|
||||
bool onEnabled(Context* context) override;
|
||||
void onExecute(Context* context) override;
|
||||
};
|
||||
|
||||
GotoNextLayerCommand::GotoNextLayerCommand()
|
||||
: GotoCommand("GotoNextLayer",
|
||||
"Go to Next Layer",
|
||||
CmdUIOnlyFlag)
|
||||
{
|
||||
}
|
||||
|
||||
bool GotoNextLayerCommand::onEnabled(Context* context)
|
||||
{
|
||||
return (current_editor != nullptr &&
|
||||
current_editor->document());
|
||||
}
|
||||
|
||||
void GotoNextLayerCommand::onExecute(Context* context)
|
||||
{
|
||||
Site site = current_editor->getSite();
|
||||
|
||||
if (site.layerIndex() < site.sprite()->countLayers()-1)
|
||||
site.layerIndex(site.layerIndex().next());
|
||||
else
|
||||
site.layerIndex(LayerIndex(0));
|
||||
|
||||
// Flash the current layer
|
||||
current_editor->setLayer(site.layer());
|
||||
current_editor->flashCurrentLayer();
|
||||
|
||||
updateStatusBar(site);
|
||||
}
|
||||
|
||||
Command* CommandFactory::createGotoPreviousLayerCommand()
|
||||
{
|
||||
return new GotoPreviousLayerCommand;
|
||||
|
@ -17,18 +17,6 @@
|
||||
|
||||
namespace doc {
|
||||
|
||||
LayerIndex Site::layerIndex() const
|
||||
{
|
||||
return (m_sprite && m_layer ?
|
||||
m_sprite->layerToIndex(m_layer): LayerIndex());
|
||||
}
|
||||
|
||||
void Site::layerIndex(LayerIndex layerIndex)
|
||||
{
|
||||
ASSERT(m_sprite != NULL);
|
||||
m_layer = m_sprite->indexToLayer(layerIndex);
|
||||
}
|
||||
|
||||
Palette* Site::palette()
|
||||
{
|
||||
return (m_sprite ? m_sprite->palette(m_frame): NULL);
|
||||
|
@ -9,7 +9,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "doc/frame.h"
|
||||
#include "doc/layer_index.h"
|
||||
|
||||
namespace doc {
|
||||
|
||||
@ -47,8 +46,6 @@ namespace doc {
|
||||
void layer(Layer* layer) { m_layer = layer; }
|
||||
void frame(frame_t frame) { m_frame = frame; }
|
||||
|
||||
LayerIndex layerIndex() const;
|
||||
void layerIndex(LayerIndex layerIndex);
|
||||
Palette* palette();
|
||||
Image* image(int* x = nullptr, int* y = nullptr, int* opacity = nullptr) const;
|
||||
Palette* palette() const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user