mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-30 06:32:42 +00:00
Added change_color command to change FG color-index with keyboard (Ilija Melentijevic idea).
This commit is contained in:
parent
8f1eac61a9
commit
e4dd1905fb
@ -21,7 +21,7 @@
|
|||||||
<key command="cut" shortcut="Ctrl+X" /> <key command="cut" shortcut="Shift+Del" />
|
<key command="cut" shortcut="Ctrl+X" /> <key command="cut" shortcut="Shift+Del" />
|
||||||
<key command="copy" shortcut="Ctrl+C" /> <key command="copy" shortcut="Ctrl+Ins" />
|
<key command="copy" shortcut="Ctrl+C" /> <key command="copy" shortcut="Ctrl+Ins" />
|
||||||
<key command="paste" shortcut="Ctrl+V" /> <key command="paste" shortcut="Shift+Ins" />
|
<key command="paste" shortcut="Ctrl+V" /> <key command="paste" shortcut="Shift+Ins" />
|
||||||
<key command="clear" shortcut="Ctrl+B" /> <key command="clear" shortcut="Ctrl+Del" />
|
<key command="clear" shortcut="Del" /> <key command="clear" shortcut="Backspace" />
|
||||||
<key command="flip" shortcut="Shift+H">
|
<key command="flip" shortcut="Shift+H">
|
||||||
<param name="target" value="mask" />
|
<param name="target" value="mask" />
|
||||||
<param name="orientation" value="horizontal" />
|
<param name="orientation" value="horizontal" />
|
||||||
@ -82,6 +82,30 @@
|
|||||||
<param name="target" value="foreground" />
|
<param name="target" value="foreground" />
|
||||||
</key>
|
</key>
|
||||||
<key command="switch_colors" shortcut="X" />
|
<key command="switch_colors" shortcut="X" />
|
||||||
|
<key command="change_color" shortcut="9">
|
||||||
|
<param name="target" value="foreground" />
|
||||||
|
<param name="change" value="decrement-index" />
|
||||||
|
</key>
|
||||||
|
<key command="change_color" shortcut="0">
|
||||||
|
<param name="target" value="foreground" />
|
||||||
|
<param name="change" value="increment-index" />
|
||||||
|
</key>
|
||||||
|
<key command="change_color" shortcut="[">
|
||||||
|
<param name="target" value="foreground" />
|
||||||
|
<param name="change" value="decrement-index" />
|
||||||
|
</key>
|
||||||
|
<key command="change_color" shortcut="]">
|
||||||
|
<param name="target" value="foreground" />
|
||||||
|
<param name="change" value="increment-index" />
|
||||||
|
</key>
|
||||||
|
<key command="change_color" shortcut="Ctrl+9">
|
||||||
|
<param name="target" value="background" />
|
||||||
|
<param name="change" value="decrement-index" />
|
||||||
|
</key>
|
||||||
|
<key command="change_color" shortcut="Ctrl+0">
|
||||||
|
<param name="target" value="background" />
|
||||||
|
<param name="change" value="increment-index" />
|
||||||
|
</key>
|
||||||
</commands>
|
</commands>
|
||||||
<tools>
|
<tools>
|
||||||
<key tool="rectangular_marquee" shortcut="M" />
|
<key tool="rectangular_marquee" shortcut="M" />
|
||||||
|
@ -11,6 +11,7 @@ COMMON_SOURCES = \
|
|||||||
src/commands/cmd_background_from_layer.cpp \
|
src/commands/cmd_background_from_layer.cpp \
|
||||||
src/commands/cmd_canvas_size.cpp \
|
src/commands/cmd_canvas_size.cpp \
|
||||||
src/commands/cmd_cel_properties.cpp \
|
src/commands/cmd_cel_properties.cpp \
|
||||||
|
src/commands/cmd_change_color.cpp \
|
||||||
src/commands/cmd_change_image_type.cpp \
|
src/commands/cmd_change_image_type.cpp \
|
||||||
src/commands/cmd_clear.cpp \
|
src/commands/cmd_clear.cpp \
|
||||||
src/commands/cmd_close_file.cpp \
|
src/commands/cmd_close_file.cpp \
|
||||||
|
114
src/commands/cmd_change_color.cpp
Normal file
114
src/commands/cmd_change_color.cpp
Normal file
@ -0,0 +1,114 @@
|
|||||||
|
/* ASE - Allegro Sprite Editor
|
||||||
|
* Copyright (C) 2001-2009 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 <string>
|
||||||
|
|
||||||
|
#include "commands/command.h"
|
||||||
|
#include "commands/params.h"
|
||||||
|
#include "core/app.h"
|
||||||
|
#include "widgets/colbar.h"
|
||||||
|
|
||||||
|
class ChangeColorCommand : public Command
|
||||||
|
{
|
||||||
|
enum Change {
|
||||||
|
None,
|
||||||
|
IncrementIndex,
|
||||||
|
DecrementIndex,
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True means "change background color", false the foreground color.
|
||||||
|
*/
|
||||||
|
bool m_background;
|
||||||
|
|
||||||
|
Change m_change;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ChangeColorCommand();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void load_params(Params* params);
|
||||||
|
void execute(Context* context);
|
||||||
|
};
|
||||||
|
|
||||||
|
ChangeColorCommand::ChangeColorCommand()
|
||||||
|
: Command("change_color",
|
||||||
|
"Change Color",
|
||||||
|
CmdUIOnlyFlag)
|
||||||
|
{
|
||||||
|
m_background = false;
|
||||||
|
m_change = None;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeColorCommand::load_params(Params* params)
|
||||||
|
{
|
||||||
|
std::string target = params->get("target");
|
||||||
|
if (target == "foreground") m_background = false;
|
||||||
|
else if (target == "background") m_background = true;
|
||||||
|
|
||||||
|
std::string change = params->get("change");
|
||||||
|
if (change == "increment-index") m_change = IncrementIndex;
|
||||||
|
else if (change == "decrement-index") m_change = DecrementIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChangeColorCommand::execute(Context* context)
|
||||||
|
{
|
||||||
|
JWidget colorbar = app_get_colorbar();
|
||||||
|
color_t color = m_background ? colorbar_get_bg_color(colorbar):
|
||||||
|
colorbar_get_fg_color(colorbar);
|
||||||
|
int imgtype = app_get_current_image_type();
|
||||||
|
|
||||||
|
switch (m_change) {
|
||||||
|
case None:
|
||||||
|
// do nothing
|
||||||
|
break;
|
||||||
|
case IncrementIndex:
|
||||||
|
if (color_type(color) == COLOR_TYPE_INDEX) {
|
||||||
|
int index = color_get_index(imgtype, color);
|
||||||
|
if (index < 255) // TODO use sprite palette limit
|
||||||
|
color = color_index(index+1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
color = color_index(0);
|
||||||
|
break;
|
||||||
|
case DecrementIndex:
|
||||||
|
if (color_type(color) == COLOR_TYPE_INDEX) {
|
||||||
|
int index = color_get_index(imgtype, color);
|
||||||
|
if (index > 0)
|
||||||
|
color = color_index(index-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
color = color_index(0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_background)
|
||||||
|
colorbar_set_bg_color(colorbar, color);
|
||||||
|
else
|
||||||
|
colorbar_set_fg_color(colorbar, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
// CommandFactory
|
||||||
|
|
||||||
|
Command* CommandFactory::create_change_color_command()
|
||||||
|
{
|
||||||
|
return new ChangeColorCommand;
|
||||||
|
}
|
@ -22,6 +22,7 @@ FOR_EACH_COMMAND(autocrop_sprite)
|
|||||||
FOR_EACH_COMMAND(background_from_layer)
|
FOR_EACH_COMMAND(background_from_layer)
|
||||||
FOR_EACH_COMMAND(canvas_size)
|
FOR_EACH_COMMAND(canvas_size)
|
||||||
FOR_EACH_COMMAND(cel_properties)
|
FOR_EACH_COMMAND(cel_properties)
|
||||||
|
FOR_EACH_COMMAND(change_color)
|
||||||
FOR_EACH_COMMAND(change_image_type)
|
FOR_EACH_COMMAND(change_image_type)
|
||||||
FOR_EACH_COMMAND(clear)
|
FOR_EACH_COMMAND(clear)
|
||||||
FOR_EACH_COMMAND(close_all_files)
|
FOR_EACH_COMMAND(close_all_files)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user