home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / drawable.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  3.1 KB  |  128 lines

  1. /* The GIMP -- an image manipulation program
  2.  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3.  *
  4.  * This program is free software; you can redistribute it and/or modify
  5.  * it under the terms of the GNU General Public License as published by
  6.  * the Free Software Foundation; either version 2 of the License, or
  7.  * (at your option) any later version.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  *
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17.  */
  18.  
  19. #include "config.h"
  20.  
  21. #include <gtk/gtk.h>
  22.  
  23. #include "drawable.h"
  24. #include "drawable_pvt.h"
  25. #include "gimpcontext.h"
  26. #include "gdisplay.h"
  27. #include "undo.h"
  28.  
  29.  
  30. gint
  31. drawable_ID (GimpDrawable *drawable)
  32. {
  33.   g_return_val_if_fail (drawable != NULL, -1);
  34.   g_return_val_if_fail (GIMP_IS_DRAWABLE (drawable), -1);
  35.  
  36.   return drawable->ID;
  37. }
  38.  
  39. void
  40. drawable_fill (GimpDrawable *drawable,
  41.            GimpFillType  fill_type)
  42. {
  43.   guchar r, g, b, a;
  44.  
  45.   g_return_if_fail (drawable != NULL);
  46.   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
  47.  
  48.   a = 255;
  49.  
  50.   switch (fill_type)
  51.     {
  52.     case FOREGROUND_FILL:
  53.       gimp_context_get_foreground (NULL, &r, &g, &b);
  54.       break;
  55.  
  56.     case BACKGROUND_FILL:
  57.       gimp_context_get_background (NULL, &r, &g, &b);
  58.       break;
  59.  
  60.     case WHITE_FILL:
  61.       r = g = b = 255;
  62.       break;
  63.  
  64.     case TRANSPARENT_FILL:
  65.       a = r = g = b = 0;
  66.       break;
  67.  
  68.     case NO_FILL:
  69.       return;
  70.  
  71.     default:
  72.       g_warning ("unknown fill type");
  73.       a = r = g = b = 0;
  74.       break;
  75.     }
  76.  
  77.   gimp_drawable_fill (drawable,r,g,b,a);
  78.   
  79.   drawable_update (drawable, 0, 0,
  80.            gimp_drawable_width  (drawable),
  81.            gimp_drawable_height (drawable));
  82. }
  83.  
  84. void
  85. drawable_update (GimpDrawable *drawable,
  86.          gint          x,
  87.          gint          y,
  88.          gint          w,
  89.          gint          h)
  90. {
  91.   GimpImage *gimage;
  92.   gint offset_x, offset_y;
  93.  
  94.   g_return_if_fail (drawable != NULL);
  95.   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
  96.  
  97.   gimage = gimp_drawable_gimage (drawable);
  98.   g_return_if_fail (gimage != NULL);
  99.  
  100.   gimp_drawable_offsets (drawable, &offset_x, &offset_y);
  101.   x += offset_x;
  102.   y += offset_y;
  103.   gdisplays_update_area (gimage, x, y, w, h);
  104.  
  105.   /*  invalidate the preview  */
  106.   gimp_drawable_invalidate_preview (drawable, FALSE);
  107. }
  108.  
  109. void
  110. drawable_apply_image (GimpDrawable *drawable, 
  111.               gint          x1,
  112.               gint          y1,
  113.               gint          x2,
  114.               gint          y2, 
  115.               TileManager  *tiles,
  116.               gint          sparse)
  117. {
  118.   g_return_if_fail (drawable != NULL);
  119.   g_return_if_fail (GIMP_IS_DRAWABLE (drawable));
  120.  
  121.   if (! tiles)
  122.     undo_push_image (drawable->gimage, drawable, 
  123.              x1, y1, x2, y2);
  124.   else
  125.     undo_push_image_mod (drawable->gimage, drawable, 
  126.              x1, y1, x2, y2, tiles, sparse);
  127. }
  128.