home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2002 April / pcpro0402.iso / essentials / graphics / Gimp / gimp-src-20001226.exe / src / gimp / app / ellipse_select.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-12-17  |  4.6 KB  |  164 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 <stdlib.h>
  22.  
  23. #include <glib.h>
  24.  
  25. #include "apptypes.h"
  26.  
  27. #include "appenv.h"
  28. #include "edit_selection.h"
  29. #include "ellipse_select.h"
  30. #include "gdisplay.h"
  31. #include "gimage_mask.h"
  32. #include "rect_select.h"
  33. /*  private header file for rect_select data structure  */
  34. #include "rect_selectP.h"
  35. #include "selection_options.h"
  36.  
  37.  
  38. /*  the ellipse selection tool options  */
  39. SelectionOptions * ellipse_options = NULL;
  40.  
  41.  
  42. /*************************************/
  43. /*  Ellipsoidal selection apparatus  */
  44.  
  45. void
  46. ellipse_select (GimpImage *gimage,
  47.         gint       x,
  48.         gint       y,
  49.         gint       w,
  50.         gint       h,
  51.         SelectOps  op,
  52.         gboolean   antialias,
  53.         gboolean   feather,
  54.         gdouble    feather_radius)
  55. {
  56.   Channel *new_mask;
  57.  
  58.   /*  if applicable, replace the current selection  */
  59.   if (op == SELECTION_REPLACE)
  60.     gimage_mask_clear (gimage);
  61.   else
  62.     gimage_mask_undo (gimage);
  63.  
  64.   /*  if feathering for rect, make a new mask with the
  65.    *  rectangle and feather that with the old mask
  66.    */
  67.   if (feather)
  68.     {
  69.       new_mask = channel_new_mask (gimage, gimage->width, gimage->height);
  70.       channel_combine_ellipse (new_mask, ADD, x, y, w, h, antialias);
  71.       channel_feather (new_mask, gimage_get_mask (gimage),
  72.                feather_radius,
  73.                feather_radius,
  74.                op, 0, 0);
  75.       channel_delete (new_mask);
  76.     }
  77.   else if (op == SELECTION_INTERSECT)
  78.     {
  79.       new_mask = channel_new_mask (gimage, gimage->width, gimage->height);
  80.       channel_combine_ellipse (new_mask, ADD, x, y, w, h, antialias);
  81.       channel_combine_mask (gimage_get_mask (gimage), new_mask, op, 0, 0);
  82.       channel_delete (new_mask);
  83.     }
  84.   else
  85.     channel_combine_ellipse (gimage_get_mask (gimage), op,
  86.                  x, y, w, h, antialias);
  87. }
  88.  
  89. void
  90. ellipse_select_draw (Tool *tool)
  91. {
  92.   GDisplay      *gdisp;
  93.   EllipseSelect *ellipse_sel;
  94.   gint x1, y1;
  95.   gint x2, y2;
  96.  
  97.   gdisp = (GDisplay *) tool->gdisp_ptr;
  98.   ellipse_sel = (EllipseSelect *) tool->private;
  99.  
  100.   x1 = MIN (ellipse_sel->x, ellipse_sel->x + ellipse_sel->w);
  101.   y1 = MIN (ellipse_sel->y, ellipse_sel->y + ellipse_sel->h);
  102.   x2 = MAX (ellipse_sel->x, ellipse_sel->x + ellipse_sel->w);
  103.   y2 = MAX (ellipse_sel->y, ellipse_sel->y + ellipse_sel->h);
  104.  
  105.   gdisplay_transform_coords (gdisp, x1, y1, &x1, &y1, 0);
  106.   gdisplay_transform_coords (gdisp, x2, y2, &x2, &y2, 0);
  107.  
  108.   gdk_draw_arc (ellipse_sel->core->win,
  109.         ellipse_sel->core->gc, 0,
  110.         x1, y1, (x2 - x1), (y2 - y1), 0, 23040);
  111. }
  112.  
  113. static void
  114. ellipse_select_options_reset (void)
  115. {
  116.   selection_options_reset (ellipse_options);
  117. }
  118.  
  119. Tool *
  120. tools_new_ellipse_select  (void)
  121. {
  122.   Tool          *tool;
  123.   EllipseSelect *private;
  124.  
  125.   /*  The tool options  */
  126.   if (!ellipse_options)
  127.     {
  128.       ellipse_options =
  129.     selection_options_new (ELLIPSE_SELECT, ellipse_select_options_reset);
  130.       tools_register (ELLIPSE_SELECT, (ToolOptions *) ellipse_options);
  131.     }
  132.  
  133.   tool = tools_new_tool (ELLIPSE_SELECT);
  134.   private = g_new0 (EllipseSelect, 1);
  135.  
  136.   private->core = draw_core_new (ellipse_select_draw);
  137.   /*  Make the selection static, not blinking  */
  138.   private->x = private->y = 0;
  139.   private->w = private->h = 0;
  140.  
  141.   tool->private = (void *) private;
  142.  
  143.   tool->button_press_func   = rect_select_button_press;
  144.   tool->button_release_func = rect_select_button_release;
  145.   tool->motion_func         = rect_select_motion;
  146.   tool->modifier_key_func   = rect_select_modifier_update;
  147.   tool->cursor_update_func  = rect_select_cursor_update;
  148.   tool->oper_update_func    = rect_select_oper_update;
  149.   tool->control_func        = rect_select_control;
  150.  
  151.   return tool;
  152. }
  153.  
  154. void
  155. tools_free_ellipse_select (Tool *tool)
  156. {
  157.   EllipseSelect *ellipse_sel;
  158.  
  159.   ellipse_sel = (EllipseSelect *) tool->private;
  160.  
  161.   draw_core_free (ellipse_sel->core);
  162.   g_free (ellipse_sel);
  163. }
  164.