2007-11-16 18:25:45 +00:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2010-02-01 21:25:40 +00:00
|
|
|
* Copyright (C) 2001-2010 David Capello
|
2007-09-18 23:57:02 +00:00
|
|
|
*
|
|
|
|
* 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.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2007-12-05 01:30:50 +00:00
|
|
|
#include "jinete/jbox.h"
|
|
|
|
#include "jinete/jbutton.h"
|
|
|
|
#include "jinete/jhook.h"
|
2010-03-09 02:42:31 +00:00
|
|
|
#include "jinete/jtheme.h"
|
2007-12-05 01:30:50 +00:00
|
|
|
#include "jinete/jwidget.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
#include "core/cfg.h"
|
2008-04-12 03:09:53 +00:00
|
|
|
#include "effect/effect.h"
|
2007-09-18 23:57:02 +00:00
|
|
|
#include "modules/gfx.h"
|
|
|
|
#include "modules/gui.h"
|
|
|
|
#include "raster/image.h"
|
|
|
|
#include "widgets/target.h"
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
static bool channel_change_hook(JWidget widget, void *data);
|
|
|
|
static bool images_change_hook(JWidget widget, void *data);
|
2008-04-12 03:09:53 +00:00
|
|
|
static int get_target_image_gfx(int target);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
/**
|
|
|
|
* Creates a new button to handle "targets" to apply some effect in
|
|
|
|
* the sprite
|
|
|
|
*
|
|
|
|
* user_data[0] = target flags (TARGET_RED_CHANNEL, etc.)
|
|
|
|
*/
|
2007-09-18 23:57:02 +00:00
|
|
|
JWidget target_button_new(int imgtype, bool with_channels)
|
|
|
|
{
|
|
|
|
#define ADD(box, widget, hook) \
|
|
|
|
if (widget) { \
|
2010-03-09 02:42:31 +00:00
|
|
|
jwidget_set_border(widget, 2 * jguiscale()); \
|
2008-01-07 15:10:17 +00:00
|
|
|
jwidget_add_child(box, widget); \
|
|
|
|
HOOK(widget, \
|
|
|
|
widget->type == JI_BUTTON ? \
|
|
|
|
JI_SIGNAL_BUTTON_SELECT: JI_SIGNAL_CHECK_CHANGE, hook, vbox); \
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
int default_targets = 0;
|
2007-09-18 23:57:02 +00:00
|
|
|
JWidget vbox, hbox;
|
|
|
|
JWidget r=NULL, g=NULL, b=NULL, k=NULL, a=NULL, index=NULL, images=NULL;
|
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
vbox = jbox_new(JI_VERTICAL);
|
|
|
|
hbox = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-01-07 15:10:17 +00:00
|
|
|
jwidget_noborders(vbox);
|
|
|
|
jwidget_noborders(hbox);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
if (with_channels) {
|
|
|
|
switch (imgtype) {
|
|
|
|
|
|
|
|
case IMAGE_RGB:
|
|
|
|
case IMAGE_INDEXED:
|
|
|
|
r = check_button_new("R", 2, 0, 0, 0);
|
|
|
|
g = check_button_new("G", 0, 0, 0, 0);
|
|
|
|
b = check_button_new("B", 0, (imgtype == IMAGE_RGB) ? 0: 2, 0, 0);
|
2008-04-12 03:09:53 +00:00
|
|
|
|
2010-01-26 00:38:05 +00:00
|
|
|
r->setName("r");
|
|
|
|
g->setName("g");
|
|
|
|
b->setName("b");
|
2008-04-12 03:09:53 +00:00
|
|
|
|
|
|
|
if (imgtype == IMAGE_RGB) {
|
2007-09-18 23:57:02 +00:00
|
|
|
a = check_button_new("A", 0, 2, 0, 0);
|
2010-01-26 00:38:05 +00:00
|
|
|
a->setName("a");
|
2008-04-12 03:09:53 +00:00
|
|
|
}
|
|
|
|
else {
|
2007-09-18 23:57:02 +00:00
|
|
|
index = check_button_new("Index", 0, 0, 0, 0);
|
2010-01-26 00:38:05 +00:00
|
|
|
index->setName("i");
|
2008-04-12 03:09:53 +00:00
|
|
|
}
|
2007-09-18 23:57:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case IMAGE_GRAYSCALE:
|
|
|
|
k = check_button_new("K", 2, 0, 0, 0);
|
|
|
|
a = check_button_new("A", 0, 2, 0, 0);
|
|
|
|
|
2010-01-26 00:38:05 +00:00
|
|
|
k->setName("k");
|
|
|
|
a->setName("a");
|
2007-09-18 23:57:02 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create the button to select "image" target */
|
|
|
|
images = jbutton_new(NULL);
|
|
|
|
jbutton_set_bevel(images,
|
2008-04-12 03:09:53 +00:00
|
|
|
with_channels ? 0: 2,
|
|
|
|
with_channels ? 0: 2, 2, 2);
|
2010-03-24 20:49:46 +00:00
|
|
|
setup_mini_look(images);
|
2008-04-12 03:09:53 +00:00
|
|
|
add_gfxicon_to_button(images, get_target_image_gfx(default_targets),
|
2008-01-07 15:10:17 +00:00
|
|
|
JI_CENTER | JI_MIDDLE);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
/* make hierarchy */
|
2008-03-22 18:43:56 +00:00
|
|
|
ADD(hbox, r, channel_change_hook);
|
|
|
|
ADD(hbox, g, channel_change_hook);
|
|
|
|
ADD(hbox, b, channel_change_hook);
|
|
|
|
ADD(hbox, k, channel_change_hook);
|
|
|
|
ADD(hbox, a, channel_change_hook);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
|
|
|
if (with_channels)
|
2008-01-07 15:10:17 +00:00
|
|
|
jwidget_add_child(vbox, hbox);
|
2007-09-18 23:57:02 +00:00
|
|
|
else
|
|
|
|
jwidget_free(hbox);
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
ADD(vbox, index, channel_change_hook);
|
|
|
|
ADD(vbox, images, images_change_hook);
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
vbox->user_data[0] = (void *)default_targets;
|
2007-09-18 23:57:02 +00:00
|
|
|
return vbox;
|
|
|
|
}
|
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
int target_button_get_target(JWidget widget)
|
|
|
|
{
|
2009-02-21 19:57:57 +00:00
|
|
|
return (size_t)widget->user_data[0];
|
2008-04-12 03:09:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void target_button_set_target(JWidget widget, int target)
|
|
|
|
{
|
|
|
|
JWidget w;
|
|
|
|
|
|
|
|
#define ACTIVATE_TARGET(name, TARGET) \
|
|
|
|
w = jwidget_find_name(widget, name); \
|
|
|
|
if (w != NULL) { \
|
|
|
|
if ((target & TARGET) == TARGET) \
|
|
|
|
jwidget_select(w); \
|
|
|
|
else \
|
|
|
|
jwidget_deselect(w); \
|
|
|
|
}
|
|
|
|
|
|
|
|
ACTIVATE_TARGET("r", TARGET_RED_CHANNEL);
|
|
|
|
ACTIVATE_TARGET("g", TARGET_GREEN_CHANNEL);
|
|
|
|
ACTIVATE_TARGET("b", TARGET_BLUE_CHANNEL);
|
|
|
|
ACTIVATE_TARGET("a", TARGET_ALPHA_CHANNEL);
|
|
|
|
ACTIVATE_TARGET("k", TARGET_GRAY_CHANNEL);
|
|
|
|
ACTIVATE_TARGET("i", TARGET_INDEX_CHANNEL);
|
|
|
|
|
|
|
|
widget->user_data[0] = (void *)target;
|
|
|
|
}
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
static bool channel_change_hook(JWidget widget, void *data)
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2008-04-12 03:09:53 +00:00
|
|
|
JWidget target_button = (JWidget)data;
|
2009-02-21 19:57:57 +00:00
|
|
|
int target = (size_t)target_button->user_data[0];
|
2008-04-12 03:09:53 +00:00
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
switch (*widget->name) {
|
|
|
|
case 'r': flag = TARGET_RED_CHANNEL; break;
|
|
|
|
case 'g': flag = TARGET_GREEN_CHANNEL; break;
|
|
|
|
case 'b': flag = TARGET_BLUE_CHANNEL; break;
|
|
|
|
case 'k': flag = TARGET_GRAY_CHANNEL; break;
|
|
|
|
case 'a': flag = TARGET_ALPHA_CHANNEL; break;
|
|
|
|
case 'i': flag = TARGET_INDEX_CHANNEL; break;
|
2007-09-18 23:57:02 +00:00
|
|
|
default:
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
if (jwidget_is_selected(widget))
|
|
|
|
target |= flag;
|
|
|
|
else
|
|
|
|
target &= ~flag;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
target_button->user_data[0] = (void *)target;
|
|
|
|
|
|
|
|
jwidget_emit_signal(target_button, SIGNAL_TARGET_BUTTON_CHANGE);
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
2008-03-22 18:43:56 +00:00
|
|
|
static bool images_change_hook(JWidget widget, void *data)
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2008-04-12 03:09:53 +00:00
|
|
|
JWidget target_button = (JWidget)data;
|
2009-02-21 19:57:57 +00:00
|
|
|
int target = (size_t)target_button->user_data[0];
|
2008-04-12 03:09:53 +00:00
|
|
|
|
|
|
|
/* rotate target */
|
|
|
|
if (target & TARGET_ALL_FRAMES) {
|
|
|
|
target &= ~TARGET_ALL_FRAMES;
|
2007-09-18 23:57:02 +00:00
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
if (target & TARGET_ALL_LAYERS)
|
|
|
|
target &= ~TARGET_ALL_LAYERS;
|
|
|
|
else
|
|
|
|
target |= TARGET_ALL_LAYERS;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
target |= TARGET_ALL_FRAMES;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_gfxicon_in_button(widget, get_target_image_gfx(target));
|
|
|
|
|
|
|
|
target_button->user_data[0] = (void *)target;
|
|
|
|
jwidget_emit_signal(target_button, SIGNAL_TARGET_BUTTON_CHANGE);
|
2010-01-30 16:43:13 +00:00
|
|
|
return true;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
|
2008-04-12 03:09:53 +00:00
|
|
|
static int get_target_image_gfx(int target)
|
2007-09-18 23:57:02 +00:00
|
|
|
{
|
2008-04-12 03:09:53 +00:00
|
|
|
if (target & TARGET_ALL_FRAMES) {
|
|
|
|
return target & TARGET_ALL_LAYERS ?
|
|
|
|
GFX_TARGET_FRAMES_LAYERS:
|
|
|
|
GFX_TARGET_FRAMES;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return target & TARGET_ALL_LAYERS ?
|
|
|
|
GFX_TARGET_LAYERS:
|
|
|
|
GFX_TARGET_ONE;
|
2007-09-18 23:57:02 +00:00
|
|
|
}
|
|
|
|
}
|