Commit 7058d4c6 authored by Seth Burgess's avatar Seth Burgess

Added Qmasks 7-6-99 <sjburges@gimp.org>

 	* pixmaps/qmasknosel.xpm
        * pixmaps/qmasksel.xpm: Ugly pixmaps that tigert promised to replace

        * app/channel.[ch]
        * app/channel_cmds.c : made some of the private structures accessible
          through exported functions to keep things a bit clean

        * app/interface.c
        * app/gdisplay.[ch]
        * app/gimpimageP.h
        * app/gimpimage.[ch]
        * app/undo.[ch]: added qmasks

        * app/Makefile.am
        * app/qmask.[ch]: added new files for qmask support

        * tools/pdbgen/pdb/channel.pdb: changed some channel stuff to keep
          things a bit more private
parent 5a1c6e43
Tue Jul 6 20:55 CST 1999 Seth Burgess <sjburges@gimp.org>
* pixmaps/qmasknosel.xpm
* pixmaps/qmasksel.xpm: Ugly pixmaps that tigert promised to replace
* app/channel.[ch]
* app/channel_cmds.c : made some of the private structures accessible
through exported functions to keep things a bit clean
* app/interface.c
* app/gdisplay.[ch]
* app/gimpimageP.h
* app/gimpimage.[ch]
* app/undo.[ch]: added qmasks
* app/Makefile.am
* app/qmask.[ch]: added new files for qmask support
* tools/pdbgen/pdb: changed some channel stuff to keep things a bit
more private
Wed Jul 7 03:54:54 MEST 1999 Sven Neumann <sven@gimp.org>
* plug-ins/script-fu/script-fu.c: Fixed typo.
......
......@@ -329,6 +329,8 @@ gimp_SOURCES = \
procedural_db.c \
procedural_db.h \
procedural_db_cmds.c \
qmask.c \
qmask.h \
rect_select.c \
rect_select.h \
rect_selectP.h \
......
/* 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>
#include <string.h>
#include "appenv.h"
#include "channel.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 ();
}
undo_push_group_end (gimg);
}
}
void
qmask_activate(GtkWidget *w,
GDisplay *gdisp)
{
GimpImage *gimg;
GimpChannel *gmask;
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 no selection */
gmask = channel_new(gimg,
gimg->width,
gimg->height,
"Qmask",
(int)(255*opacity)/100,
color);
gimp_image_add_channel (gimg, gmask, 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);
}
}
/* 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>
#include <string.h>
#include "appenv.h"
#include "channel.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 ();
}
undo_push_group_end (gimg);
}
}
void
qmask_activate(GtkWidget *w,
GDisplay *gdisp)
{
GimpImage *gimg;
GimpChannel *gmask;
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 no selection */
gmask = channel_new(gimg,
gimg->width,
gimg->height,
"Qmask",
(int)(255*opacity)/100,
color);
gimp_image_add_channel (gimg, gmask, 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);
}
}
......@@ -236,6 +236,24 @@ channel_get_name (Channel *channel)
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
void
channel_set_color (Channel *channel, gchar *color)
{
int i;
if (color)
{
for (i = 0; i < 3; i++)
channel->col[i] = color[i];
}
}
void
channel_set_opacity (Channel *channel, gint opacity)
{
if (opacity >=0 && opacity <= 100)
channel->opacity = (int) (opacity*255)/100;
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -86,6 +86,9 @@ void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
void channel_set_opacity (Channel *, int );
void channel_set_color (Channel *, gchar *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -642,7 +642,7 @@ channel_set_opacity_invoker (Argument *args)
success = FALSE;
if (success)
channel->opacity = (int) ((opacity * 255) / 100);
channel_set_opacity (channel, opacity);
return procedural_db_return_args (&channel_set_opacity_proc, success);
}
......@@ -754,8 +754,7 @@ channel_set_color_invoker (Argument *args)
color = (guchar *) args[1].value.pdb_pointer;
if (success)
for (i = 0; i < 3; i++)
channel->col[i] = color[i];
channel_set_color(channel, color);
return procedural_db_return_args (&channel_set_color_proc, success);
}
......
......@@ -236,6 +236,24 @@ channel_get_name (Channel *channel)
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
void
channel_set_color (Channel *channel, gchar *color)
{
int i;
if (color)
{
for (i = 0; i < 3; i++)
channel->col[i] = color[i];
}
}
void
channel_set_opacity (Channel *channel, gint opacity)
{
if (opacity >=0 && opacity <= 100)
channel->opacity = (int) (opacity*255)/100;
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -86,6 +86,9 @@ void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
void channel_set_opacity (Channel *, int );
void channel_set_color (Channel *, gchar *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -236,6 +236,24 @@ channel_get_name (Channel *channel)
return gimp_drawable_get_name(GIMP_DRAWABLE(channel));
}
void
channel_set_color (Channel *channel, gchar *color)
{
int i;
if (color)
{
for (i = 0; i < 3; i++)
channel->col[i] = color[i];
}
}
void
channel_set_opacity (Channel *channel, gint opacity)
{
if (opacity >=0 && opacity <= 100)
channel->opacity = (int) (opacity*255)/100;
}
Channel *
channel_get_ID (int ID)
{
......
......@@ -86,6 +86,9 @@ void channel_unref (Channel *);
char * channel_get_name (Channel *);
void channel_set_name (Channel *, char *);
void channel_set_opacity (Channel *, int );
void channel_set_color (Channel *, gchar *);
Channel * channel_get_ID (int);
void channel_delete (Channel *);
void channel_scale (Channel *, int, int);
......
......@@ -1711,6 +1711,22 @@ gimp_image_get_channel_by_tattoo (GimpImage *gimage, Tattoo tattoo)
}
Channel *
gimp_image_get_channel_by_name (GimpImage *gimage, char *name)
{
Channel *channel;
GSList *channels = gimage->channels;
while (channels)
{
channel = (Channel *) channels->data;
if (! strcmp(channel_get_name(channel),name) )
return channel;
channels = g_slist_next (channels);
}
return NULL;
}
int
gimp_image_get_component_active (GimpImage *gimage, ChannelType type)
{
......
......@@ -178,6 +178,7 @@ Layer * gimp_image_get_active_layer (GimpImage *);
Channel * gimp_image_get_active_channel (GimpImage *);
Layer * gimp_image_get_layer_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_name (GimpImage *, char *);
Channel * gimp_image_get_mask (GimpImage *);
int gimp_image_get_component_active (GimpImage *, ChannelType);
int gimp_image_get_component_visible (GimpImage *, ChannelType);
......
......@@ -1711,6 +1711,22 @@ gimp_image_get_channel_by_tattoo (GimpImage *gimage, Tattoo tattoo)
}
Channel *
gimp_image_get_channel_by_name (GimpImage *gimage, char *name)
{
Channel *channel;
GSList *channels = gimage->channels;
while (channels)
{
channel = (Channel *) channels->data;
if (! strcmp(channel_get_name(channel),name) )
return channel;
channels = g_slist_next (channels);
}
return NULL;
}
int
gimp_image_get_component_active (GimpImage *gimage, ChannelType type)
{
......
......@@ -178,6 +178,7 @@ Layer * gimp_image_get_active_layer (GimpImage *);
Channel * gimp_image_get_active_channel (GimpImage *);
Layer * gimp_image_get_layer_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_name (GimpImage *, char *);
Channel * gimp_image_get_mask (GimpImage *);
int gimp_image_get_component_active (GimpImage *, ChannelType);
int gimp_image_get_component_visible (GimpImage *, ChannelType);
......
......@@ -1711,6 +1711,22 @@ gimp_image_get_channel_by_tattoo (GimpImage *gimage, Tattoo tattoo)
}
Channel *
gimp_image_get_channel_by_name (GimpImage *gimage, char *name)
{
Channel *channel;
GSList *channels = gimage->channels;
while (channels)
{
channel = (Channel *) channels->data;
if (! strcmp(channel_get_name(channel),name) )
return channel;
channels = g_slist_next (channels);
}
return NULL;
}
int
gimp_image_get_component_active (GimpImage *gimage, ChannelType type)
{
......
......@@ -178,6 +178,7 @@ Layer * gimp_image_get_active_layer (GimpImage *);
Channel * gimp_image_get_active_channel (GimpImage *);
Layer * gimp_image_get_layer_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_tattoo (GimpImage *, Tattoo);
Channel * gimp_image_get_channel_by_name (GimpImage *, char *);
Channel * gimp_image_get_mask (GimpImage *);
int gimp_image_get_component_active (GimpImage *, ChannelType);
int gimp_image_get_component_visible (GimpImage *, ChannelType);
......
/* 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>
#include <string.h>
#include "appenv.h"
#include "channel.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 ();
}
undo_push_group_end (gimg);
}
}
void
qmask_activate(GtkWidget *w,
GDisplay *gdisp)
{
GimpImage *gimg;
GimpChannel *gmask;
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 no selection */
gmask = channel_new(gimg,
gimg->width,
gimg->height,
"Qmask",
(int)(255*opacity)/100,
color);
gimp_image_add_channel (gimg, gmask, 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);
}
}