drawable-commands.c 3.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
/* 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 "config.h"

#include <string.h> 

#include <gtk/gtk.h>

#include "libgimpwidgets/gimpwidgets.h"

#include "gui-types.h"

#include "core/gimp.h"
#include "core/gimpcontext.h"
#include "core/gimpdrawable.h"
#include "core/gimpdrawable-desaturate.h"
#include "core/gimpdrawable-equalize.h"
34
#include "core/gimpdrawable-invert.h"
35 36 37
#include "core/gimpimage.h"

#include "widgets/gimpitemfactory.h"
38
#include "widgets/gimpitemlistview.h"
39

40 41
#include "display/gimpdisplay.h"

42 43 44 45 46 47
#include "drawable-commands.h"
#include "offset-dialog.h"

#include "libgimp/gimpintl.h"


48
#define return_if_no_image(gimage,data) \
49 50 51 52 53 54 55 56 57
  if (GIMP_IS_DISPLAY (data)) \
    gimage = ((GimpDisplay *) data)->gimage; \
  else if (GIMP_IS_GIMP (data)) \
    gimage = gimp_context_get_image (gimp_get_user_context (GIMP (data))); \
  else if (GIMP_IS_ITEM_LIST_VIEW (data)) \
    gimage = ((GimpItemListView *) data)->gimage; \
  else \
    gimage = NULL; \
  \
58 59 60
  if (! gimage) \
    return

61 62
#define return_if_no_drawable(gimage,drawable,data) \
  return_if_no_image (gimage,data); \
63 64 65 66 67 68 69 70 71 72 73 74 75
  drawable = gimp_image_active_drawable (gimage); \
  if (! drawable) \
    return


/*  public functions  */

void
drawable_desaturate_cmd_callback (GtkWidget *widget,
                                  gpointer   data)
{
  GimpImage    *gimage;
  GimpDrawable *active_drawable;
76
  return_if_no_drawable (gimage, active_drawable, data);
77 78 79 80 81 82 83 84

  if (! gimp_drawable_is_rgb (active_drawable))
    {
      g_message (_("Desaturate operates only on RGB color drawables."));
      return;
    }

  gimp_drawable_desaturate (active_drawable);
85
  gimp_image_flush (gimage);
86 87 88 89 90 91 92 93
}

void
drawable_invert_cmd_callback (GtkWidget *widget,
                              gpointer   data)
{
  GimpImage    *gimage;
  GimpDrawable *active_drawable;
94
  return_if_no_drawable (gimage, active_drawable, data);
95 96 97 98 99 100 101

  if (gimp_drawable_is_indexed (active_drawable))
    {
      g_message (_("Invert does not operate on indexed drawables."));
      return;
    }

102
  gimp_drawable_invert (active_drawable);
103
  gimp_image_flush (gimage);
104 105 106 107 108 109 110 111
}

void
drawable_equalize_cmd_callback (GtkWidget *widget,
                                gpointer   data)
{
  GimpImage    *gimage;
  GimpDrawable *active_drawable;
112
  return_if_no_drawable (gimage, active_drawable, data);
113 114 115 116 117 118 119 120

  if (gimp_drawable_is_indexed (active_drawable))
    {
      g_message (_("Equalize does not operate on indexed drawables."));
      return;
    }

  gimp_drawable_equalize (active_drawable, TRUE);
121
  gimp_image_flush (gimage);
122 123 124 125 126 127 128 129
}

void
drawable_offset_cmd_callback (GtkWidget *widget,
                              gpointer   data)
{
  GimpImage    *gimage;
  GimpDrawable *active_drawable;
130
  return_if_no_drawable (gimage, active_drawable, data);
131 132 133

  offset_dialog_create (active_drawable);
}