gimp/app/actions/qmask-commands.c

165 lines
4.6 KiB
C
Raw Normal View History

/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* 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 <glib.h>
#include <stdlib.h>
app/makefile.cygwin app/makefile.msc plug-ins/makefile.cygwin * app/makefile.cygwin * app/makefile.msc * plug-ins/makefile.cygwin * plug-ins/makefile.msc * modules/makefile.cygwin * modules/makefile.msc * tools/gcg/makefile.cygwin: Various updates. GCC-compiled DLL name change. * app/context_manager.c: Include paint_options.h for prototype. * app/gimpimage.c (gimp_image_initialize_projection): Break out of loop as soon as possible. * app/menus.c (menus_last_opened_cmd_callback): Check if referring to entry not in list. * app/module_db.c (valid_module_name): (Win32) Require module DLL names to include name of compiler built with. * app/paths_dialog.c (paths_draw_segment_points): No use to draw lines if we have less that two points. * app/qmask.c: Include stdio.h and floating_sel.h. * libgimp/makefile.cygwin: New file. * libgimp/Makefile.am: Distribute above file. * libgimp/gimp.def: Update. * libgimp/gimpenv.c (gimp_directory): Don't warn about missing home directory on Win32, it is perfectly natural. * plug-ins/sel2path/global.h: Bypass unused declarations, some of which clash with functions in MSVCRT. * plug-ins/sel2path/math.c * modules/colorsel_water.c: Define M_PI if necessary. * plug-ins/sel2path/sel2path.c: Include config.h and glib.h. Define rint() if needed. * plug-ins/sel2path/vector.c: Include glib.h (for hypot() renaming on Win32; In the MS C runtime, as hypot() is non-ANSI, it's called _hypot(), sigh). * plug-ins/sinus/sinus_logo.h: Use indexed format, it is easier on some compilers than the huge string.
1999-07-15 00:02:32 +08:00
#include <stdio.h>
#include <string.h>
#include "appenv.h"
#include "channel.h"
app/makefile.cygwin app/makefile.msc plug-ins/makefile.cygwin * app/makefile.cygwin * app/makefile.msc * plug-ins/makefile.cygwin * plug-ins/makefile.msc * modules/makefile.cygwin * modules/makefile.msc * tools/gcg/makefile.cygwin: Various updates. GCC-compiled DLL name change. * app/context_manager.c: Include paint_options.h for prototype. * app/gimpimage.c (gimp_image_initialize_projection): Break out of loop as soon as possible. * app/menus.c (menus_last_opened_cmd_callback): Check if referring to entry not in list. * app/module_db.c (valid_module_name): (Win32) Require module DLL names to include name of compiler built with. * app/paths_dialog.c (paths_draw_segment_points): No use to draw lines if we have less that two points. * app/qmask.c: Include stdio.h and floating_sel.h. * libgimp/makefile.cygwin: New file. * libgimp/Makefile.am: Distribute above file. * libgimp/gimp.def: Update. * libgimp/gimpenv.c (gimp_directory): Don't warn about missing home directory on Win32, it is perfectly natural. * plug-ins/sel2path/global.h: Bypass unused declarations, some of which clash with functions in MSVCRT. * plug-ins/sel2path/math.c * modules/colorsel_water.c: Define M_PI if necessary. * plug-ins/sel2path/sel2path.c: Include config.h and glib.h. Define rint() if needed. * plug-ins/sel2path/vector.c: Include glib.h (for hypot() renaming on Win32; In the MS C runtime, as hypot() is non-ANSI, it's called _hypot(), sigh). * plug-ins/sinus/sinus_logo.h: Use indexed format, it is easier on some compilers than the huge string.
1999-07-15 00:02:32 +08:00
#include "floating_sel.h"
#include "gdisplayF.h"
#include "gimpcontext.h"
#include "gimage_mask.h"
#include "gimpimage.h"
#include "global_edit.h"
#include "qmask.h"
#include "undo.h"
/* Global variables */
/* Prototypes */
/* Static variables */
void
qmask_buttons_update (GDisplay *gdisp)
{
g_assert(gdisp);
g_assert(gdisp->gimage);
if (gdisp->gimage->qmask_state != GTK_TOGGLE_BUTTON(gdisp->qmaskon)->active)
{
/* Disable toggle from doing anything */
gtk_signal_handler_block_by_func(GTK_OBJECT(gdisp->qmaskoff),
(GtkSignalFunc) qmask_deactivate,
gdisp);
gtk_signal_handler_block_by_func(GTK_OBJECT(gdisp->qmaskon),
(GtkSignalFunc) qmask_activate,
gdisp);
/* Change the state of the buttons */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gdisp->qmaskon),
gdisp->gimage->qmask_state);
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(gdisp->qmaskoff),
!gdisp->gimage->qmask_state);
/* Enable toggle again */
gtk_signal_handler_unblock_by_func(GTK_OBJECT(gdisp->qmaskoff),
(GtkSignalFunc) qmask_deactivate,
gdisp);
gtk_signal_handler_unblock_by_func(GTK_OBJECT(gdisp->qmaskon),
(GtkSignalFunc) qmask_activate,
gdisp);
/* Flush event queue */
/* while (g_main_iteration(FALSE)); */
}
}
void
qmask_deactivate(GtkWidget *w,
GDisplay *gdisp)
{
GimpImage *gimg;
GimpChannel *gmask;
if (gdisp)
{
gimg = gdisp->gimage;
if (!gimg) return;
if (!gdisp->gimage->qmask_state) {
return; /* if already set do nothing */
}
undo_push_group_start (gimg, QMASK_UNDO);
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
{
gimage_mask_load (gimg, gmask);
gimage_remove_channel(gimg, gmask);
undo_push_qmask(gimg,1);
gdisp->gimage->qmask_state = 0;
gdisplays_flush ();
}
else
gdisp->gimage->qmask_state = 0;
undo_push_group_end (gimg);
}
}
void
qmask_activate(GtkWidget *w,
GDisplay *gdisp)
{
GimpImage *gimg;
GimpChannel *gmask;
GimpLayer *layer;
unsigned char color[3] = {255,0,0};
double opacity = 50;
if (gdisp)
{
gimg = gdisp->gimage;
if (!gimg) return;
if (gdisp->gimage->qmask_state) {
return; /* If already set, do nothing */
}
if ( (gmask = gimp_image_get_channel_by_name (gimg, "Qmask")) )
return; /* do nothing if Qmask already exists */
undo_push_group_start (gimg, QMASK_UNDO);
if (gimage_mask_is_empty(gimg))
{
if ((layer = gimage_floating_sel (gimg)))
{
floating_sel_to_layer (layer);
printf ("111111!!!11!\n");
}
/* if no selection */
gmask = channel_new(gimg,
gimg->width,
gimg->height,
"Qmask",
(int)(255*opacity)/100,
color);
gimp_image_add_channel (gimg, gmask, 0);
gimp_drawable_fill (GIMP_DRAWABLE(gmask), 0, 0, 0, 0);
/* edit_clear(gimg,GIMP_DRAWABLE(gmask)); */
undo_push_qmask(gimg,0);
gdisp->gimage->qmask_state = 1;
gdisplays_flush();
}
else
{ /* if selection */
gmask = channel_copy (gimage_get_mask (gimg));
gimp_image_add_channel (gimg, gmask, 0);
channel_set_color(gmask, color);
channel_set_name(gmask, "Qmask");
channel_set_opacity(gmask, opacity);
gimage_mask_none (gimg); /* Clear the selection */
undo_push_qmask(gimg,0);
gdisp->gimage->qmask_state = 1;
gdisplays_flush();
}
undo_push_group_end(gimg);
}
}