2007-11-17 02:25:45 +08:00
|
|
|
/* ASE - Allegro Sprite Editor
|
2009-01-24 08:41:01 +08:00
|
|
|
* Copyright (C) 2001-2009 David Capello
|
2007-09-19 07:57:02 +08: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"
|
|
|
|
|
2007-12-05 09:30:50 +08:00
|
|
|
#include "jinete/jbox.h"
|
|
|
|
#include "jinete/jbutton.h"
|
|
|
|
#include "jinete/jhook.h"
|
|
|
|
#include "jinete/jlabel.h"
|
|
|
|
#include "jinete/jslider.h"
|
|
|
|
#include "jinete/jwidget.h"
|
|
|
|
#include "jinete/jwindow.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
#include "core/app.h"
|
|
|
|
#include "core/cfg.h"
|
2008-03-15 09:54:45 +08:00
|
|
|
#include "core/color.h"
|
2007-09-19 07:57:02 +08:00
|
|
|
#include "core/core.h"
|
|
|
|
#include "modules/editors.h"
|
|
|
|
#include "modules/gui.h"
|
|
|
|
#include "modules/sprites.h"
|
|
|
|
#include "raster/image.h"
|
|
|
|
#include "raster/mask.h"
|
|
|
|
#include "raster/sprite.h"
|
|
|
|
#include "raster/undo.h"
|
|
|
|
#include "util/misc.h"
|
|
|
|
#include "widgets/colbar.h"
|
|
|
|
#include "widgets/colbut.h"
|
|
|
|
|
|
|
|
static JWidget button_color, slider_fuzziness, check_preview;
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void button_1_command(JWidget widget);
|
|
|
|
static void button_2_command(JWidget widget);
|
2008-03-23 02:43:56 +08:00
|
|
|
static bool color_change_hook(JWidget widget, void *data);
|
|
|
|
static bool slider_change_hook(JWidget widget, void *data);
|
|
|
|
static bool preview_change_hook(JWidget widget, void *data);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static Mask *gen_mask();
|
|
|
|
static void mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
void dialogs_mask_color()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
JWidget window, box1, box2, box3, box4;
|
|
|
|
JWidget label_color, button_1, button_2;
|
|
|
|
JWidget label_fuzziness;
|
|
|
|
JWidget button_ok, button_cancel;
|
2009-06-01 10:59:15 +08:00
|
|
|
CurrentSprite sprite;
|
2007-09-19 07:57:02 +08:00
|
|
|
Image *image;
|
|
|
|
|
|
|
|
if (!is_interactive () || !sprite)
|
|
|
|
return;
|
|
|
|
|
2009-06-01 10:59:15 +08:00
|
|
|
image = GetImage(sprite);
|
2007-09-19 07:57:02 +08:00
|
|
|
if (!image)
|
|
|
|
return;
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
window = jwindow_new(_("Mask by Color"));
|
|
|
|
box1 = jbox_new(JI_VERTICAL);
|
|
|
|
box2 = jbox_new(JI_HORIZONTAL);
|
|
|
|
box3 = jbox_new(JI_HORIZONTAL);
|
|
|
|
box4 = jbox_new(JI_HORIZONTAL | JI_HOMOGENEOUS);
|
|
|
|
label_color = jlabel_new(_("Color:"));
|
2008-03-23 02:43:56 +08:00
|
|
|
button_color = colorbutton_new
|
2008-03-01 03:29:49 +08:00
|
|
|
(get_config_color("MaskColor", "Color",
|
|
|
|
colorbar_get_fg_color(app_get_colorbar())),
|
2008-01-07 23:10:17 +08:00
|
|
|
sprite->imgtype);
|
|
|
|
button_1 = jbutton_new("1");
|
|
|
|
button_2 = jbutton_new("2");
|
|
|
|
label_fuzziness = jlabel_new(_("Fuzziness:"));
|
2007-09-19 07:57:02 +08:00
|
|
|
slider_fuzziness =
|
2008-01-07 23:10:17 +08:00
|
|
|
jslider_new(0, 255, get_config_int("MaskColor", "Fuzziness", 0));
|
|
|
|
check_preview = jcheck_new(_("&Preview"));
|
|
|
|
button_ok = jbutton_new(_("&OK"));
|
|
|
|
button_cancel = jbutton_new(_("&Cancel"));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
if (get_config_bool("MaskColor", "Preview", TRUE))
|
|
|
|
jwidget_select(check_preview);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jbutton_add_command(button_1, button_1_command);
|
|
|
|
jbutton_add_command(button_2, button_2_command);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-03-23 02:43:56 +08:00
|
|
|
HOOK(button_color, SIGNAL_COLORBUTTON_CHANGE, color_change_hook, 0);
|
2008-01-07 23:10:17 +08:00
|
|
|
HOOK(slider_fuzziness, JI_SIGNAL_SLIDER_CHANGE, slider_change_hook, 0);
|
|
|
|
HOOK(check_preview, JI_SIGNAL_CHECK_CHANGE, preview_change_hook, 0);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_magnetic(button_ok, TRUE);
|
|
|
|
jwidget_expansive(button_color, TRUE);
|
|
|
|
jwidget_expansive(slider_fuzziness, TRUE);
|
|
|
|
jwidget_expansive(box2, TRUE);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
jwidget_add_child(window, box1);
|
2008-03-01 03:29:49 +08:00
|
|
|
jwidget_add_children(box1, box2, box3, check_preview, box4, NULL);
|
|
|
|
jwidget_add_children(box2, label_color, button_color, button_1, button_2, NULL);
|
|
|
|
jwidget_add_children(box3, label_fuzziness, slider_fuzziness, NULL);
|
|
|
|
jwidget_add_children(box4, button_ok, button_cancel, NULL);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* default position */
|
2008-01-07 23:10:17 +08:00
|
|
|
jwindow_remap(window);
|
|
|
|
jwindow_center(window);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* mask first preview */
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* load window configuration */
|
2008-01-07 23:10:17 +08:00
|
|
|
load_window_pos(window, "MaskColor");
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* open the window */
|
2008-01-07 23:10:17 +08:00
|
|
|
jwindow_open_fg(window);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-03-28 00:58:14 +08:00
|
|
|
if (jwindow_get_killer(window) == button_ok) {
|
2007-09-19 07:57:02 +08:00
|
|
|
Mask *mask;
|
|
|
|
|
|
|
|
/* undo */
|
2008-03-28 00:58:14 +08:00
|
|
|
if (undo_is_enabled(sprite->undo)) {
|
|
|
|
undo_set_label(sprite->undo, "Mask by Color");
|
2008-01-07 23:10:17 +08:00
|
|
|
undo_set_mask(sprite->undo, sprite);
|
2008-03-28 00:58:14 +08:00
|
|
|
}
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* change the mask */
|
2008-01-07 23:10:17 +08:00
|
|
|
mask = gen_mask();
|
|
|
|
sprite_set_mask(sprite, mask);
|
|
|
|
mask_free(mask);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-03-01 03:29:49 +08:00
|
|
|
set_config_color("MaskColor", "Color",
|
2008-03-23 02:43:56 +08:00
|
|
|
colorbutton_get_color(button_color));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
set_config_int("MaskColor", "Fuzziness",
|
|
|
|
jslider_get_value(slider_fuzziness));
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
set_config_bool("MaskColor", "Preview",
|
|
|
|
jwidget_is_selected(check_preview));
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* update boundaries and editors */
|
2007-11-19 22:23:15 +08:00
|
|
|
sprite_generate_mask_boundaries(sprite);
|
|
|
|
update_screen_for_sprite(sprite);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
/* save window configuration */
|
2007-11-19 22:23:15 +08:00
|
|
|
save_window_pos(window, "MaskColor");
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2007-11-19 22:23:15 +08:00
|
|
|
jwidget_free(window);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void button_1_command(JWidget widget)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-03-23 02:43:56 +08:00
|
|
|
colorbutton_set_color(button_color,
|
|
|
|
colorbar_get_fg_color(app_get_colorbar()));
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-01-07 23:10:17 +08:00
|
|
|
static void button_2_command(JWidget widget)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-03-23 02:43:56 +08:00
|
|
|
colorbutton_set_color(button_color,
|
|
|
|
colorbar_get_bg_color(app_get_colorbar()));
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
|
2008-03-23 02:43:56 +08:00
|
|
|
static bool color_change_hook(JWidget widget, void *data)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-23 02:43:56 +08:00
|
|
|
static bool slider_change_hook(JWidget widget, void *data)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-03-23 02:43:56 +08:00
|
|
|
static bool preview_change_hook(JWidget widget, void *data)
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_preview();
|
2007-09-19 07:57:02 +08:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static Mask *gen_mask()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
int xpos, ypos, color, fuzziness;
|
2009-06-01 10:59:15 +08:00
|
|
|
CurrentSprite sprite;
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2009-06-01 10:59:15 +08:00
|
|
|
Image* image = GetImage2(sprite, &xpos, &ypos, NULL);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2008-03-01 03:29:49 +08:00
|
|
|
color = get_color_for_image(sprite->imgtype,
|
2008-03-23 02:43:56 +08:00
|
|
|
colorbutton_get_color(button_color));
|
2008-01-07 23:10:17 +08:00
|
|
|
fuzziness = jslider_get_value(slider_fuzziness);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
2009-06-01 10:59:15 +08:00
|
|
|
Mask* mask = mask_new();
|
2008-01-07 23:10:17 +08:00
|
|
|
mask_by_color(mask, image, color, fuzziness);
|
|
|
|
mask_move(mask, xpos, ypos);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
return mask;
|
|
|
|
}
|
|
|
|
|
2008-10-01 09:27:51 +08:00
|
|
|
static void mask_preview()
|
2007-09-19 07:57:02 +08:00
|
|
|
{
|
|
|
|
if (jwidget_is_selected (check_preview)) {
|
2009-06-01 10:59:15 +08:00
|
|
|
CurrentSprite sprite;
|
2007-11-19 22:23:15 +08:00
|
|
|
Mask *mask = gen_mask();
|
2007-09-19 07:57:02 +08:00
|
|
|
Mask *old_mask = sprite->mask;
|
|
|
|
|
|
|
|
sprite->mask = mask;
|
|
|
|
|
2007-11-19 22:23:15 +08:00
|
|
|
sprite_generate_mask_boundaries(sprite);
|
|
|
|
update_screen_for_sprite(sprite);
|
2007-09-19 07:57:02 +08:00
|
|
|
|
|
|
|
sprite->mask = old_mask;
|
2007-11-19 22:23:15 +08:00
|
|
|
mask_free(mask);
|
2007-09-19 07:57:02 +08:00
|
|
|
}
|
|
|
|
}
|