Skip to content

Commit

Permalink
Status bar can change opacity of several cels (related to issue #225)
Browse files Browse the repository at this point in the history
  • Loading branch information
dacap committed Aug 24, 2014
1 parent 0b3ec08 commit 6b2c5cc
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -248,6 +248,7 @@ add_library(app-lib
util/misc.cpp
util/msk_file.cpp
util/pic_file.cpp
util/range_utils.cpp
util/render.cpp
webserver.cpp
widget_loader.cpp
Expand Down
25 changes: 19 additions & 6 deletions src/app/ui/status_bar.cpp
Expand Up @@ -24,6 +24,7 @@
#include "app/commands/commands.h"
#include "app/commands/params.h"
#include "app/context_access.h"
#include "app/document_range.h"
#include "app/modules/editors.h"
#include "app/modules/gfx.h"
#include "app/modules/gui.h"
Expand All @@ -32,10 +33,13 @@
#include "app/tools/tool.h"
#include "app/ui/color_button.h"
#include "app/ui/editor/editor.h"
#include "app/ui/main_window.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui/status_bar.h"
#include "app/ui/timeline.h"
#include "app/ui_context.h"
#include "app/util/misc.h"
#include "app/util/range_utils.h"
#include "base/bind.h"
#include "gfx/size.h"
#include "raster/cel.h"
Expand Down Expand Up @@ -574,14 +578,23 @@ static void slider_change_hook(Slider* slider)
{
try {
ContextWriter writer(UIContext::instance());
Cel* cel = writer.cel();
if (cel) {
// Update the opacity
cel->setOpacity(slider->getValue());

// Update the editors
update_screen_for_document(writer.document());
// Clear of several frames is handled with RemoveCel command.
DocumentRange range = App::instance()->getMainWindow()->getTimeline()->range();
if (range.enabled()) {
for (Cel* cel : get_cels_in_range(writer.sprite(), range))
cel->setOpacity(slider->getValue());
}
else {
Cel* cel = writer.cel();
if (cel) {
// Update the opacity
cel->setOpacity(slider->getValue());
}
}

// Update the editors
update_screen_for_document(writer.document());
}
catch (LockedDocumentException&) {
// do nothing
Expand Down
56 changes: 56 additions & 0 deletions src/app/util/range_utils.cpp
@@ -0,0 +1,56 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "app/context_access.h"
#include "app/document.h"
#include "app/document_range.h"
#include "raster/layer.h"
#include "raster/sprite.h"

namespace app {

using namespace raster;

std::vector<Cel*> get_cels_in_range(Sprite* sprite, const DocumentRange& range)
{
std::vector<Cel*> cels;

for (LayerIndex layerIdx = range.layerBegin(); layerIdx <= range.layerEnd(); ++layerIdx) {
Layer* layer = sprite->indexToLayer(layerIdx);
if (!layer->isImage())
continue;

LayerImage* layerImage = static_cast<LayerImage*>(layer);

for (FrameNumber frame = range.frameEnd(),
begin = range.frameBegin().previous();
frame != begin;
frame = frame.previous()) {
Cel* cel = layerImage->getCel(frame);
if (cel)
cels.push_back(cel);
}
}
return cels;
}

} // namespace app
36 changes: 36 additions & 0 deletions src/app/util/range_utils.h
@@ -0,0 +1,36 @@
/* Aseprite
* Copyright (C) 2001-2014 David Capello
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef APP_UTIL_RANGE_UTILS_H_INCLUDED
#define APP_UTIL_RANGE_UTILS_H_INCLUDED
#pragma once

#include <vector>

namespace raster {
class Sprite;
}

namespace app {
class DocumentRange;

std::vector<Cel*> get_cels_in_range(raster::Sprite* sprite, const DocumentRange& range);

} // namespace app

#endif

0 comments on commit 6b2c5cc

Please sign in to comment.