drawable.c 2.96 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 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
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17
 */
18
#include "drawable.h"
19
#include "drawable_pvt.h"
20
#include "gimpcontext.h"
21 22
#include "gimpimageF.h"
#include "gdisplay.h"
23
#include "undo.h"
24

25
gint
26 27
drawable_ID (GimpDrawable *drawable)
{
28 29
  g_return_val_if_fail (drawable != NULL, -1);
  g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
30

31
  return drawable->ID;
32 33 34
}

void
35
drawable_fill (GimpDrawable *drawable,
36
	       GimpFillType  fill_type)
37
{
38 39
  guchar r, g, b, a;

40 41 42
  g_return_if_fail (drawable != NULL);
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));

43
  a = 255;
44 45 46 47

  switch (fill_type)
    {
    case FOREGROUND_FILL:
48
      gimp_context_get_foreground (NULL, &r, &g, &b);
49
      break;
50

51
    case BACKGROUND_FILL:
52
      gimp_context_get_background (NULL, &r, &g, &b);
53
      break;
54

55
    case WHITE_FILL:
56
      r = g = b = 255;
57
      break;
58

59
    case TRANSPARENT_FILL:
60
      a = r = g = b = 0;
61
      break;
62

63 64
    case NO_FILL:
      return;
65

66
    default:
67
      g_warning ("unknown fill type");
68
      a = r = g = b = 0;
69 70
      break;
    }
71 72

  gimp_drawable_fill (drawable,r,g,b,a);
73 74
  
  drawable_update (drawable, 0, 0,
75
		   gimp_drawable_width  (drawable),
76
		   gimp_drawable_height (drawable));
Elliot Lee's avatar
Elliot Lee committed
77 78 79
}

void
80 81 82 83 84
drawable_update (GimpDrawable *drawable,
		 gint          x,
		 gint          y,
		 gint          w,
		 gint          h)
Elliot Lee's avatar
Elliot Lee committed
85
{
86
  GimpImage *gimage;
87
  gint offset_x, offset_y;
Elliot Lee's avatar
Elliot Lee committed
88

89 90
  g_return_if_fail (drawable != NULL);
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
Elliot Lee's avatar
Elliot Lee committed
91

92 93
  gimage = gimp_drawable_gimage (drawable);
  g_return_if_fail (gimage != NULL);
94

95
  gimp_drawable_offsets (drawable, &offset_x, &offset_y);
Elliot Lee's avatar
Elliot Lee committed
96 97
  x += offset_x;
  y += offset_y;
98
  gdisplays_update_area (gimage, x, y, w, h);
Elliot Lee's avatar
Elliot Lee committed
99 100

  /*  invalidate the preview  */
101
  gimp_drawable_invalidate_preview (drawable);
Elliot Lee's avatar
Elliot Lee committed
102
}
103 104 105

void
drawable_apply_image (GimpDrawable *drawable, 
106 107 108 109 110 111
		      gint          x1,
		      gint          y1,
		      gint          x2,
		      gint          y2, 
		      TileManager  *tiles,
		      gint          sparse)
112
{
113 114 115 116 117 118 119 120 121
  g_return_if_fail (drawable != NULL);
  g_return_if_fail (GIMP_IS_DRAWABLE (drawable));

  if (! tiles)
    undo_push_image (drawable->gimage, drawable, 
		     x1, y1, x2, y2);
  else
    undo_push_image_mod (drawable->gimage, drawable, 
			 x1, y1, x2, y2, tiles, sparse);
122
}