drawable.c 2.76 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
26
#include "libgimp/gimpintl.h"

27
gint
28
29
drawable_ID (GimpDrawable *drawable)
{
30
31
32
  if (drawable)
    return drawable->ID;
  else
33
34
    g_warning ("drawable_ID called on a NULL pointer");

35
  return 0;
36
37
38
}

void
39
drawable_fill (GimpDrawable *drawable,
40
	       GimpFillType  fill_type)
41
{
42
43
44
  guchar r, g, b, a;

  a = 255;
45
46
47
48

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

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

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

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

64
65
    case NO_FILL:
      return;
66

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

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

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

90
  if (! drawable)
Elliot Lee's avatar
Elliot Lee committed
91
92
    return;

93
  if (! (gimage = gimp_drawable_gimage (drawable)))
94
95
    return;

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

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

void
drawable_apply_image (GimpDrawable *drawable, 
107
108
109
110
111
112
		      gint          x1,
		      gint          y1,
		      gint          x2,
		      gint          y2, 
		      TileManager  *tiles,
		      gint          sparse)
113
114
115
116
117
118
119
120
121
122
123
{
  if (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);
    }
}