aseprite/src/commands/cmd_eyedropper.cpp
David Capello 10781dcf5f Removed Context::getFg/BgColor member functions.
Modified color_get_*() so they do not need "imgtype" parameter.
ColorBar class is public (defined in colbar.h).
Added ColorBar::Fg/BgColorChange signals.
Converted palette editor widget to a C++ class (PalEdit derived from Widget).
Modified the "Palette Editor" (F4 key) to be non-modal (still WIP).
2010-04-10 17:01:56 -03:00

105 lines
2.9 KiB
C++

/* ASE - Allegro Sprite Editor
* Copyright (C) 2001-2010 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
*/
#include "config.h"
#include <allegro/unicode.h>
#include "jinete/jinete.h"
#include "commands/command.h"
#include "commands/params.h"
#include "app.h"
#include "modules/editors.h"
#include "raster/sprite.h"
#include "raster/image.h"
#include "widgets/colbar.h"
#include "widgets/editor.h"
//////////////////////////////////////////////////////////////////////
// eyedropper
class EyedropperCommand : public Command
{
/**
* True means "pick background color", false the foreground color.
*/
bool m_background;
public:
EyedropperCommand();
Command* clone() const { return new EyedropperCommand(*this); }
protected:
void load_params(Params* params);
void execute(Context* context);
};
EyedropperCommand::EyedropperCommand()
: Command("eyedropper",
"Eyedropper",
CmdUIOnlyFlag)
{
m_background = false;
}
void EyedropperCommand::load_params(Params* params)
{
std::string target = params->get("target");
if (target == "foreground") m_background = false;
else if (target == "background") m_background = true;
}
void EyedropperCommand::execute(Context* context)
{
JWidget widget = jmanager_get_mouse();
if (!widget || widget->type != editor_type())
return;
Editor* editor = static_cast<Editor*>(widget);
Sprite* sprite = editor->getSprite();
if (!sprite)
return;
// pixel position to get
int x, y;
editor->screen_to_editor(jmouse_x(0), jmouse_y(0), &x, &y);
// get the color from the image
color_t color = color_from_image(sprite->getImgType(),
sprite->getPixel(x, y));
if (color_type(color) != COLOR_TYPE_MASK) {
// TODO replace the color in the "context", not directly from the color-bar
// set the color of the color-bar
if (m_background)
app_get_colorbar()->setBgColor(color);
else
app_get_colorbar()->setFgColor(color);
}
}
//////////////////////////////////////////////////////////////////////
// CommandFactory
Command* CommandFactory::create_eyedropper_command()
{
return new EyedropperCommand;
}