Fix eyedropper for tiled mode (fix #529)

This commit is contained in:
David Capello 2015-08-14 14:28:46 -03:00
parent 8e47e507fd
commit 383fd3f1ae
3 changed files with 49 additions and 12 deletions

View File

@ -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<const app::Document*>(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();
}

View File

@ -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);

24
src/app/util/wrap_value.h Normal file
View File

@ -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<typename T>
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