From 383fd3f1ae88215a551ee53cc88b952b82a65136 Mon Sep 17 00:00:00 2001 From: David Capello Date: Fri, 14 Aug 2015 14:28:46 -0300 Subject: [PATCH] Fix eyedropper for tiled mode (fix #529) --- src/app/color_picker.cpp | 26 ++++++++++++++++++++++---- src/app/tools/point_shape.cpp | 11 +++-------- src/app/util/wrap_value.h | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 src/app/util/wrap_value.h diff --git a/src/app/color_picker.cpp b/src/app/color_picker.cpp index 75167cd9c..8ed99ad94 100644 --- a/src/app/color_picker.cpp +++ b/src/app/color_picker.cpp @@ -11,6 +11,9 @@ #include "app/color_picker.h" +#include "app/document.h" +#include "app/pref/preferences.h" +#include "app/util/wrap_value.h" #include "doc/cel.h" #include "doc/image.h" #include "doc/primitives.h" @@ -28,19 +31,34 @@ ColorPicker::ColorPicker() } void ColorPicker::pickColor(const doc::Site& site, - const gfx::Point& pos, Mode mode) + const gfx::Point& _pos, Mode mode) { + const doc::Sprite* sprite = site.sprite(); + gfx::Point pos = _pos; + m_alpha = 255; m_color = app::Color::fromMask(); + // Check tiled mode + if (sprite && site.document()) { + const app::Document* doc = static_cast(site.document()); + DocumentPreferences& docPref = Preferences::instance().document(doc); + + if (int(docPref.tiled.mode()) & int(filters::TiledMode::X_AXIS)) + pos.x = wrap_value(pos.x, site.sprite()->width()); + + if (int(docPref.tiled.mode()) & int(filters::TiledMode::Y_AXIS)) + pos.y = wrap_value(pos.y, site.sprite()->height()); + } + // Get the color from the image if (mode == FromComposition) { // Pick from the composed image m_color = app::Color::fromImage( - site.sprite()->pixelFormat(), - render::get_sprite_pixel(site.sprite(), pos.x, pos.y, site.frame())); + sprite->pixelFormat(), + render::get_sprite_pixel(sprite, pos.x, pos.y, site.frame())); doc::CelList cels; - site.sprite()->pickCels(pos.x, pos.y, site.frame(), 128, cels); + sprite->pickCels(pos.x, pos.y, site.frame(), 128, cels); if (!cels.empty()) m_layer = cels.front()->layer(); } diff --git a/src/app/tools/point_shape.cpp b/src/app/tools/point_shape.cpp index 785226fd3..a7326c057 100644 --- a/src/app/tools/point_shape.cpp +++ b/src/app/tools/point_shape.cpp @@ -13,6 +13,7 @@ #include "app/tools/ink.h" #include "app/tools/tool_loop.h" +#include "app/util/wrap_value.h" #include "doc/image.h" namespace app { @@ -29,10 +30,7 @@ void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop) // Tiled in Y axis if (int(tiledMode) & int(TiledMode::Y_AXIS)) { size = loop->getDstImage()->height(); // size = image height - if (y < 0) - y = size - (-(y+1) % size) - 1; - else - y = y % size; + y = wrap_value(y, size); } else if (y < 0 || y >= loop->getDstImage()->height()) return; @@ -48,10 +46,7 @@ void PointShape::doInkHline(int x1, int y, int x2, ToolLoop* loop) loop->getInk()->inkHline(0, y, size-1, loop); else { x = x1; - if (x < 0) - x = size - (-(x+1) % size) - 1; - else - x = x % size; + x = wrap_value(x, size); if (x+w-1 <= size-1) loop->getInk()->inkHline(x, y, x+w-1, loop); diff --git a/src/app/util/wrap_value.h b/src/app/util/wrap_value.h new file mode 100644 index 000000000..ad312731c --- /dev/null +++ b/src/app/util/wrap_value.h @@ -0,0 +1,24 @@ +// 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_WRAP_VALUE_H_INCLUDED +#define APP_WRAP_VALUE_H_INCLUDED +#pragma once + +namespace app { + + template + inline T wrap_value(const T x, const T size) { + if (x < T(0)) + return size - (-(x+1) % size) - 1; + else + return x % size; + } + +} // namespace app + +#endif