From d162376d47d93c527cf48bfd655f31426c102bb5 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Fri, 2 Nov 2001 09:31:21 +0000 Subject: [PATCH] app/display/Makefile.am app/display/gimpdisplay-callbacks.[ch] 2001-11-01 Michael Natterer * app/display/Makefile.am * app/display/gimpdisplay-callbacks.[ch] * app/display/gimpdisplay-render.[ch] * app/display/gimpdisplay-scale.[ch] * app/display/gimpdisplay-scroll.[ch]: removed and added as gimpdisplayshell-foo.[ch] because they are all methods of the shell. * app/display/gimpdisplay.[ch] * app/display/gimpdisplayshell.[ch]: moved the "offset" and "size" variables from GimpDisplay to GimpDisplayShell. GimpDisplay should know nothing about screen coordinates. The gdisplay_[un]transform_foo() methods are still part of GimpDisplay but will be moved to GimpDisplayShell as soon as the tools' vitrual functions speak in image coordinates instead of GdkEvents. * app/display/gimpdisplayshell-callbacks.[ch]: prefixed all functions with gimp_display_shell_*. Moved some stuff to a "realize" callback File still has to be renamed. * app/display/gimpdisplay-foreach.[ch]: removed gdisplays_shrink_wrap(). * app/gui/menus.c * app/gui/view-commands.[ch] * app/display/gimpdisplayshell-scale.[ch]: implemented "Zoom to Fit Window" function (#57670). * app/nav_window.c * app/display/gimpdisplay-handlers.c * app/display/gimpdisplayshell-render.[ch] * app/display/gimpdisplayshell-scale.[ch] * app/display/gimpdisplayshell-scroll.[ch] * app/gui/colormap-dialog.c * app/gui/gui.c * app/gui/preferences-dialog.c * app/tools/gimpmagnifytool.c * app/tools/gimpmovetool.c * app/widgets/gimppreview.c: changed according to variable and filename changes. * app/tools/tool_manager.c: tool_manager_select_tool(): send the active tool a "HALT" command before selecting the new one. Fixes stale tool dialogs which were there because some other hack was removed (This is IMHO the right place to shut down the active tool). * app/tools/gimpcroptool.c: don't shrink wrap after cropping but let gimprc.allow_resize_windows decide. * app/tools/gimpselectiontool.c: gimage_mask_value() takes image, not screen coordinates. A good example of how braindead it is to pass GdkEvents to tools :-) Fixes incorrect cursor and oper update of the selection tools. * app/tools/gimptransformtool.c * app/undo.c: removed (#if 0 for now) some strange code which did manual exposing of GimpDisplayShell areas. This was definitely a hack and should not be there given the image emits correct "update" signals. --- ChangeLog | 69 +- app/actions/view-commands.c | 20 +- app/actions/view-commands.h | 6 +- app/core/gimp-transform-region.c | 13 +- app/core/gimpdrawable-transform.c | 13 +- app/core/gimpimage-undo-push.c | 45 +- app/core/gimpprojection.c | 49 +- app/core/gimpprojection.h | 9 - app/dialogs/preferences-dialog.c | 2 +- app/display/Makefile.am | 16 +- app/display/gimpdisplay-callbacks.c | 1146 ---------------------- app/display/gimpdisplay-callbacks.h | 67 -- app/display/gimpdisplay-foreach.c | 18 - app/display/gimpdisplay-foreach.h | 1 - app/display/gimpdisplay-handlers.c | 8 +- app/display/gimpdisplay-render.c | 891 ----------------- app/display/gimpdisplay-render.h | 43 - app/display/gimpdisplay-scale.c | 327 ------ app/display/gimpdisplay-scale.h | 36 - app/display/gimpdisplay-scroll.c | 170 ---- app/display/gimpdisplay-scroll.h | 30 - app/display/gimpdisplay.c | 49 +- app/display/gimpdisplay.h | 9 - app/display/gimpdisplayshell-callbacks.c | 338 ++++--- app/display/gimpdisplayshell-callbacks.h | 85 +- app/display/gimpdisplayshell-draw.c | 174 ++-- app/display/gimpdisplayshell-draw.h | 8 + app/display/gimpdisplayshell-render.c | 6 +- app/display/gimpdisplayshell-scale.c | 173 +++- app/display/gimpdisplayshell-scale.h | 1 + app/display/gimpdisplayshell-scroll.c | 44 +- app/display/gimpdisplayshell.c | 174 ++-- app/display/gimpdisplayshell.h | 8 + app/display/gimpnavigationeditor.c | 32 +- app/display/gimpnavigationview.c | 32 +- app/gui/colormap-dialog.c | 2 +- app/gui/gui.c | 2 +- app/gui/menus.c | 9 +- app/gui/preferences-dialog.c | 2 +- app/gui/view-commands.c | 20 +- app/gui/view-commands.h | 6 +- app/menus/menus.c | 9 +- app/nav_window.c | 32 +- app/tools/gimpcroptool.c | 8 +- app/tools/gimpmagnifytool.c | 17 +- app/tools/gimpmovetool.c | 2 +- app/tools/gimpselectiontool.c | 10 +- app/tools/gimptransformtool.c | 13 +- app/tools/tool_manager.c | 8 +- app/undo.c | 45 +- app/widgets/gimpcolormapeditor.c | 2 +- app/widgets/gimpitemfactory.c | 9 +- app/widgets/gimppreview.c | 2 +- app/widgets/gimppreviewrenderer.c | 2 +- app/widgets/gimpview.c | 2 +- app/widgets/gimpviewrenderer.c | 2 +- po/ChangeLog | 4 + po/POTFILES.in | 2 +- 58 files changed, 951 insertions(+), 3371 deletions(-) delete mode 100644 app/display/gimpdisplay-callbacks.c delete mode 100644 app/display/gimpdisplay-callbacks.h delete mode 100644 app/display/gimpdisplay-render.c delete mode 100644 app/display/gimpdisplay-render.h delete mode 100644 app/display/gimpdisplay-scale.c delete mode 100644 app/display/gimpdisplay-scale.h delete mode 100644 app/display/gimpdisplay-scroll.c delete mode 100644 app/display/gimpdisplay-scroll.h diff --git a/ChangeLog b/ChangeLog index 72bd8e6611..f88d3ba7e5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,68 @@ +2001-11-01 Michael Natterer + + * app/display/Makefile.am + * app/display/gimpdisplay-callbacks.[ch] + * app/display/gimpdisplay-render.[ch] + * app/display/gimpdisplay-scale.[ch] + * app/display/gimpdisplay-scroll.[ch]: removed and added as + gimpdisplayshell-foo.[ch] because they are all methods of the + shell. + + * app/display/gimpdisplay.[ch] + * app/display/gimpdisplayshell.[ch]: moved the "offset" and "size" + variables from GimpDisplay to GimpDisplayShell. GimpDisplay + should know nothing about screen coordinates. + + The gdisplay_[un]transform_foo() methods are still part of + GimpDisplay but will be moved to GimpDisplayShell as soon as the + tools' vitrual functions speak in image coordinates instead of + GdkEvents. + + * app/display/gimpdisplayshell-callbacks.[ch]: prefixed all + functions with gimp_display_shell_*. Moved some stuff to a + "realize" callback File still has to be renamed. + + * app/display/gimpdisplay-foreach.[ch]: removed + gdisplays_shrink_wrap(). + + * app/gui/menus.c + * app/gui/view-commands.[ch] + * app/display/gimpdisplayshell-scale.[ch]: implemented "Zoom to + Fit Window" function (#57670). + + * app/nav_window.c + * app/display/gimpdisplay-handlers.c + * app/display/gimpdisplayshell-render.[ch] + * app/display/gimpdisplayshell-scale.[ch] + * app/display/gimpdisplayshell-scroll.[ch] + * app/gui/colormap-dialog.c + * app/gui/gui.c + * app/gui/preferences-dialog.c + * app/tools/gimpmagnifytool.c + * app/tools/gimpmovetool.c + * app/widgets/gimppreview.c: changed according to variable + and filename changes. + + * app/tools/tool_manager.c: tool_manager_select_tool(): send the + active tool a "HALT" command before selecting the new one. Fixes + stale tool dialogs which were there because some other hack was + removed (This is IMHO the right place to shut down the active + tool). + + * app/tools/gimpcroptool.c: don't shrink wrap after cropping but + let gimprc.allow_resize_windows decide. + + * app/tools/gimpselectiontool.c: gimage_mask_value() takes image, + not screen coordinates. A good example of how braindead it is to + pass GdkEvents to tools :-) Fixes incorrect cursor and oper + update of the selection tools. + + * app/tools/gimptransformtool.c + * app/undo.c: removed (#if 0 for now) some strange code which did + manual exposing of GimpDisplayShell areas. This was definitely a + hack and should not be there given the image emits correct + "update" signals. + 2001-11-01 DindinX * plug-ins/common/bz2.c: fix a little typo in a comment @@ -13,7 +78,7 @@ GimpDisplayShell has all the widgets and handles painting and exposing of the result. Nobody should actually be required to - update ot look at it as it should be a view on the GimpDisplay + update or look at it as it should be a view on the GimpDisplay object. Much stuff is still in the wrong place and the functions don't @@ -27,7 +92,7 @@ functions. * app/display/gimpdisplay-handlers.[ch]: new files: signal - handlers for GimpImage signals. Mostly from app/gui.c. + handlers for GimpImage signals. Mostly from gui/gui.c. * app/display/gimpdisplay.[ch]: removed all widgets and other GUI stuff. There is still much undecided here... diff --git a/app/actions/view-commands.c b/app/actions/view-commands.c index 20c73b4063..3e0e5b7317 100644 --- a/app/actions/view-commands.c +++ b/app/actions/view-commands.c @@ -30,9 +30,9 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplay-selection.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scale.h" #include "info-dialog.h" #include "info-window.h" @@ -49,8 +49,8 @@ void -view_zoomin_cmd_callback (GtkWidget *widget, - gpointer data) +view_zoom_in_cmd_callback (GtkWidget *widget, + gpointer data) { GimpDisplay *gdisp; return_if_no_display (gdisp, data); @@ -59,8 +59,8 @@ view_zoomin_cmd_callback (GtkWidget *widget, } void -view_zoomout_cmd_callback (GtkWidget *widget, - gpointer data) +view_zoom_out_cmd_callback (GtkWidget *widget, + gpointer data) { GimpDisplay *gdisp; return_if_no_display (gdisp, data); @@ -68,6 +68,16 @@ view_zoomout_cmd_callback (GtkWidget *widget, gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_OUT); } +void +view_zoom_fit_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpDisplay *gdisp; + return_if_no_display (gdisp, data); + + gimp_display_shell_scale_fit (GIMP_DISPLAY_SHELL (gdisp->shell)); +} + void view_zoom_cmd_callback (GtkWidget *widget, gpointer data, diff --git a/app/actions/view-commands.h b/app/actions/view-commands.h index acef8add06..915fa91fa7 100644 --- a/app/actions/view-commands.h +++ b/app/actions/view-commands.h @@ -20,9 +20,11 @@ #define __VIEW_COMMANDS_H__ -void view_zoomin_cmd_callback (GtkWidget *widget, +void view_zoom_in_cmd_callback (GtkWidget *widget, gpointer data); -void view_zoomout_cmd_callback (GtkWidget *widget, +void view_zoom_out_cmd_callback (GtkWidget *widget, + gpointer data); +void view_zoom_fit_cmd_callback (GtkWidget *widget, gpointer data); void view_zoom_cmd_callback (GtkWidget *widget, gpointer data, diff --git a/app/core/gimp-transform-region.c b/app/core/gimp-transform-region.c index f592a4984c..8a4e2d392d 100644 --- a/app/core/gimp-transform-region.c +++ b/app/core/gimp-transform-region.c @@ -602,7 +602,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, TransformUndo *tu; PathUndo *pundo; gboolean new_layer; - gint i, x, y; + gint i; gimp_set_busy (gdisp->gimage->gimp); @@ -683,11 +683,17 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, */ tool->preserve = FALSE; +#ifdef __GNUC__ +#warning FIXME: investigate why display update was done here +#endif +#if 0 /* Flush the gdisplays */ if (gdisp->disp_xoffset || gdisp->disp_yoffset) { - x = shell->canvas->allocation.width; - y = shell->canvas->allocation.height; + gint x, y; + + x = shell->disp_width; + y = shell->disp_height; if (gdisp->disp_yoffset) { @@ -710,6 +716,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, gdisp->disp_width, gdisp->disp_height); } } +#endif gimp_unset_busy (gdisp->gimage->gimp); diff --git a/app/core/gimpdrawable-transform.c b/app/core/gimpdrawable-transform.c index f592a4984c..8a4e2d392d 100644 --- a/app/core/gimpdrawable-transform.c +++ b/app/core/gimpdrawable-transform.c @@ -602,7 +602,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, TransformUndo *tu; PathUndo *pundo; gboolean new_layer; - gint i, x, y; + gint i; gimp_set_busy (gdisp->gimage->gimp); @@ -683,11 +683,17 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, */ tool->preserve = FALSE; +#ifdef __GNUC__ +#warning FIXME: investigate why display update was done here +#endif +#if 0 /* Flush the gdisplays */ if (gdisp->disp_xoffset || gdisp->disp_yoffset) { - x = shell->canvas->allocation.width; - y = shell->canvas->allocation.height; + gint x, y; + + x = shell->disp_width; + y = shell->disp_height; if (gdisp->disp_yoffset) { @@ -710,6 +716,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, gdisp->disp_width, gdisp->disp_height); } } +#endif gimp_unset_busy (gdisp->gimage->gimp); diff --git a/app/core/gimpimage-undo-push.c b/app/core/gimpimage-undo-push.c index 46cc7a837b..01b7c2f2a2 100644 --- a/app/core/gimpimage-undo-push.c +++ b/app/core/gimpimage-undo-push.c @@ -391,13 +391,11 @@ pop_stack (GimpImage *gimage, GSList **unstack_ptr, UndoState state) { - Undo *object; - GSList *stack; - GSList *tmp; - gint status = 0; - gint in_group = 0; - gint x, y; - GimpDisplay *gdisp; + Undo *object; + GSList *stack; + GSList *tmp; + gboolean status = FALSE; + gboolean in_group = FALSE; /* Keep popping until we pop a valid object * or get to the end of a group if we're in one @@ -407,21 +405,26 @@ pop_stack (GimpImage *gimage, stack = *stack_ptr; object = (Undo *) stack->data; + if (object->group_boundary) { - in_group = (in_group) ? 0 : 1; + in_group = ! in_group; + if (in_group) gimage->undo_levels += (state == UNDO) ? -1 : 1; - if (status && !in_group) - status = 1; + if (status && ! in_group) + status = TRUE; else - status = 0; + status = FALSE; } else { TRC (("undo_pop: %s\n", undo_type_to_name (object->type))); - status = (* object->pop_func) (gimage, state, object->type, + + status = (* object->pop_func) (gimage, + state, + object->type, object->data); if (object->dirties_image) @@ -437,19 +440,26 @@ pop_stack (GimpImage *gimage, } } - if (!in_group) + if (! in_group) gimage->undo_levels += (state == UNDO) ? -1 : 1; } - *unstack_ptr = g_slist_prepend (*unstack_ptr, (gpointer) object); + *unstack_ptr = g_slist_prepend (*unstack_ptr, object); tmp = stack; *stack_ptr = g_slist_next (*stack_ptr); tmp->next = NULL; g_slist_free (tmp); - if (status && !in_group) + if (status && ! in_group) { +#ifdef __GNUC__ +#warning FIXME: investigate why display update was done here +#endif +#if 0 + GimpDisplay *gdisp; + gint x, y; + /* Flush any image updates and displays */ gdisp = gimp_context_get_display (gimp_get_user_context (gimage->gimp)); @@ -488,8 +498,7 @@ pop_stack (GimpImage *gimage, } } } - - gdisplays_flush (); +#endif /* If the mode_changed flag was set */ if (mode_changed) @@ -527,6 +536,8 @@ pop_stack (GimpImage *gimage, gimp_image_undo_event (gimage, (state == UNDO)? UNDO_POPPED : UNDO_REDO); + gdisplays_flush (); + return TRUE; } } diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c index aa6dc72347..aba1efa2d3 100644 --- a/app/core/gimpprojection.c +++ b/app/core/gimpprojection.c @@ -122,15 +122,6 @@ gimp_display_init (GimpDisplay *gdisp) gdisp->scale = 0; gdisp->dot_for_dot = gimprc.default_dot_for_dot; - - gdisp->offset_x = 0; - gdisp->offset_y = 0; - - gdisp->disp_width = 0; - gdisp->disp_height = 0; - gdisp->disp_xoffset = 0; - gdisp->disp_yoffset = 0; - gdisp->draw_guides = TRUE; gdisp->snap_to_guides = TRUE; @@ -281,10 +272,8 @@ gdisplay_reconnect (GimpDisplay *gdisp, gdisp->gimage->width, gdisp->gimage->height); - gimp_display_shell_update_title (GIMP_DISPLAY_SHELL (gdisp->shell)); gimp_display_shell_resize_cursor_label (GIMP_DISPLAY_SHELL (gdisp->shell)); gimp_display_shell_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell)); - gimp_display_shell_expose_full (GIMP_DISPLAY_SHELL (gdisp->shell)); } static gint @@ -584,7 +573,7 @@ gimp_display_paint_area (GimpDisplay *gdisp, &x1, &y1, FALSE, FALSE); gdisplay_untransform_coords (gdisp, - gdisp->disp_width, gdisp->disp_height, + shell->disp_width, shell->disp_height, &x2, &y2, FALSE, FALSE); @@ -632,11 +621,11 @@ gdisplay_transform_coords (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = (gint) (scalex * (x + offset_x) - gdisp->offset_x); - *ny = (gint) (scaley * (y + offset_y) - gdisp->offset_y); + *nx = (gint) (scalex * (x + offset_x) - shell->offset_x); + *ny = (gint) (scaley * (y + offset_y) - shell->offset_y); - *nx += gdisp->disp_xoffset; - *ny += gdisp->disp_yoffset; + *nx += shell->disp_xoffset; + *ny += shell->disp_yoffset; } void @@ -660,8 +649,8 @@ gdisplay_untransform_coords (GimpDisplay *gdisp, shell = GIMP_DISPLAY_SHELL (gdisp->shell); - x -= gdisp->disp_xoffset; - y -= gdisp->disp_yoffset; + x -= shell->disp_xoffset; + y -= shell->disp_yoffset; /* transform from screen coordinates to image coordinates */ scalex = SCALEFACTOR_X (gdisp); @@ -679,13 +668,13 @@ gdisplay_untransform_coords (GimpDisplay *gdisp, if (round) { - *nx = ROUND ((x + gdisp->offset_x) / scalex - offset_x); - *ny = ROUND ((y + gdisp->offset_y) / scaley - offset_y); + *nx = ROUND ((x + shell->offset_x) / scalex - offset_x); + *ny = ROUND ((y + shell->offset_y) / scaley - offset_y); } else { - *nx = (int) ((x + gdisp->offset_x) / scalex - offset_x); - *ny = (int) ((y + gdisp->offset_y) / scaley - offset_y); + *nx = (int) ((x + shell->offset_x) / scalex - offset_x); + *ny = (int) ((y + shell->offset_y) / scaley - offset_y); } } @@ -723,11 +712,11 @@ gdisplay_transform_coords_f (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = scalex * (x + offset_x) - gdisp->offset_x; - *ny = scaley * (y + offset_y) - gdisp->offset_y; + *nx = scalex * (x + offset_x) - shell->offset_x; + *ny = scaley * (y + offset_y) - shell->offset_y; - *nx += gdisp->disp_xoffset; - *ny += gdisp->disp_yoffset; + *nx += shell->disp_xoffset; + *ny += shell->disp_yoffset; } void @@ -750,8 +739,8 @@ gdisplay_untransform_coords_f (GimpDisplay *gdisp, shell = GIMP_DISPLAY_SHELL (gdisp->shell); - x -= gdisp->disp_xoffset; - y -= gdisp->disp_yoffset; + x -= shell->disp_xoffset; + y -= shell->disp_yoffset; /* transform from screen coordinates to gimp coordinates */ scalex = SCALEFACTOR_X (gdisp); @@ -767,8 +756,8 @@ gdisplay_untransform_coords_f (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = (x + gdisp->offset_x) / scalex - offset_x; - *ny = (y + gdisp->offset_y) / scaley - offset_y; + *nx = (x + shell->offset_x) / scalex - offset_x; + *ny = (y + shell->offset_y) / scaley - offset_y; } void diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h index 0497bbbf12..5df383e355 100644 --- a/app/core/gimpprojection.h +++ b/app/core/gimpprojection.h @@ -100,15 +100,6 @@ struct _GimpDisplay gint scale; /* scale factor from original raw image */ gboolean dot_for_dot; /* is monitor resolution being ignored? */ - - gint offset_x; - gint offset_y; - - gint disp_width; /* width of drawing area */ - gint disp_height; /* height of drawing area */ - gint disp_xoffset; - gint disp_yoffset; - gboolean draw_guides; /* should the guides be drawn? */ gboolean snap_to_guides; /* should the guides be snapped to? */ diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c index 3faedd55ed..39b757d00d 100644 --- a/app/dialogs/preferences-dialog.c +++ b/app/dialogs/preferences-dialog.c @@ -38,7 +38,7 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "tools/tool_manager.h" diff --git a/app/display/Makefile.am b/app/display/Makefile.am index 2f5b69754f..9ae9d58312 100644 --- a/app/display/Makefile.am +++ b/app/display/Makefile.am @@ -8,23 +8,23 @@ libappdisplay_a_SOURCES = @STRIP_BEGIN@ \ gimpdisplay.h \ gimpdisplay-area.c \ gimpdisplay-area.h \ - gimpdisplay-callbacks.c \ - gimpdisplay-callbacks.h \ gimpdisplay-foreach.c \ gimpdisplay-foreach.h \ gimpdisplay-handlers.c \ gimpdisplay-handlers.h \ gimpdisplay-marching-ants.h \ - gimpdisplay-render.c \ - gimpdisplay-render.h \ - gimpdisplay-scale.c \ - gimpdisplay-scale.h \ - gimpdisplay-scroll.c \ - gimpdisplay-scroll.h \ gimpdisplay-selection.c \ gimpdisplay-selection.h \ gimpdisplayshell.c \ gimpdisplayshell.h \ + gimpdisplayshell-callbacks.c \ + gimpdisplayshell-callbacks.h \ + gimpdisplayshell-render.c \ + gimpdisplayshell-render.h \ + gimpdisplayshell-scale.c \ + gimpdisplayshell-scale.h \ + gimpdisplayshell-scroll.c \ + gimpdisplayshell-scroll.h \ \ gximage.c \ gximage.h \ diff --git a/app/display/gimpdisplay-callbacks.c b/app/display/gimpdisplay-callbacks.c deleted file mode 100644 index 5723695e50..0000000000 --- a/app/display/gimpdisplay-callbacks.c +++ /dev/null @@ -1,1146 +0,0 @@ -/* 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 - -#include -#include - -#include "libgimpcolor/gimpcolor.h" - -#include "display-types.h" -#include "gui/gui-types.h" - -#include "base/pixel-region.h" -#include "base/temp-buf.h" -#include "base/tile-manager.h" - -#include "paint-funcs/paint-funcs.h" - -#include "core/gimp.h" -#include "core/gimpbuffer.h" -#include "core/gimpcontext.h" -#include "core/gimpedit.h" -#include "core/gimpimage.h" -#include "core/gimplayer.h" -#include "core/gimppattern.h" -#include "core/gimptoolinfo.h" - -#include "tools/gimpbucketfilltool.h" -#include "tools/gimpfuzzyselecttool.h" -#include "tools/gimpmovetool.h" -#include "tools/tool_manager.h" - -#include "widgets/gimpcursor.h" -#include "widgets/gimpdialogfactory.h" -#include "widgets/gimpwidgets-utils.h" - -#include "gui/dialogs.h" -#include "gui/info-window.h" -#include "gui/layer-select.h" - -#include "gimpdisplay.h" -#include "gimpdisplay-callbacks.h" -#include "gimpdisplay-foreach.h" -#include "gimpdisplay-selection.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" -#include "gimpdisplayshell.h" - -#include "devices.h" -#include "gimprc.h" -#include "undo.h" - -#include "libgimp/gimpintl.h" - - -static void -gdisplay_redraw (GimpDisplayShell *shell, - gint x, - gint y, - gint w, - gint h) -{ - glong x1, y1, x2, y2; /* coordinate of rectangle corners */ - - x1 = x; - y1 = y; - x2 = (x + w); - y2 = (y + h); - - x1 = CLAMP (x1, 0, shell->gdisp->disp_width); - y1 = CLAMP (y1, 0, shell->gdisp->disp_height); - x2 = CLAMP (x2, 0, shell->gdisp->disp_width); - y2 = CLAMP (y2, 0, shell->gdisp->disp_height); - - if ((x2 - x1) && (y2 - y1)) - { - gimp_display_shell_add_expose_area (shell, - x1, y1, - (x2 - x1), (y2 - y1)); - gimp_display_shell_flush (shell); - } -} - -static void -gdisplay_check_device_cursor (GimpDisplayShell *shell) -{ - GList *list; - - /* gdk_devices_list() returns an internal list, so we shouldn't - * free it afterwards - */ - for (list = gdk_devices_list (); list; list = g_list_next (list)) - { - GdkDevice *device = (GdkDevice *) list->data; - - if (device == current_device) - { - shell->draw_cursor = ! device->has_cursor; - break; - } - } -} - -static int -key_to_state (gint key) -{ - switch (key) - { - case GDK_Alt_L: - case GDK_Alt_R: - return GDK_MOD1_MASK; - case GDK_Shift_L: - case GDK_Shift_R: - return GDK_SHIFT_MASK; - case GDK_Control_L: - case GDK_Control_R: - return GDK_CONTROL_MASK; - default: - return 0; - } -} - -static void -gdisplay_vscrollbar_update (GtkAdjustment *adjustment, - GimpDisplayShell *shell) -{ - gimp_display_shell_scroll (shell, 0, (adjustment->value - shell->gdisp->offset_y)); -} - -static void -gdisplay_hscrollbar_update (GtkAdjustment *adjustment, - GimpDisplayShell *shell) -{ - gimp_display_shell_scroll (shell, (adjustment->value - shell->gdisp->offset_x), 0); -} - -gboolean -gdisplay_shell_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell) -{ - switch (event->type) - { - case GDK_KEY_PRESS: - case GDK_BUTTON_PRESS: - /* Setting the context's display automatically sets the image, too */ - gimp_context_set_display (gimp_get_user_context (shell->gdisp->gimage->gimp), - shell->gdisp); - - break; - default: - break; - } - - return FALSE; -} - -gboolean -gdisplay_canvas_events (GtkWidget *canvas, - GdkEvent *event, - GimpDisplayShell *shell) -{ - GimpDisplay *gdisp; - GimpTool *active_tool; - GdkEventExpose *eevent; - GdkEventMotion *mevent; - GdkEventButton *bevent; - GdkEventScroll *sevent; - GdkEventKey *kevent; - gdouble tx = 0; - gdouble ty = 0; - guint state = 0; - gint return_val = FALSE; - static gboolean scrolling = FALSE; - static gint scroll_start_x = 0; - static gint scroll_start_y = 0; - static guint key_signal_id = 0; - gboolean update_cursor = FALSE; - - if (! canvas->window) - return FALSE; - - gdisp = shell->gdisp; - - active_tool = tool_manager_get_active (gdisp->gimage->gimp); - - /* If this is the first event... */ - if (! gdisp->select) - { - /* create the selection object */ - gdisp->select = selection_create (shell->canvas->window, - gdisp, - gdisp->gimage->height, - gdisp->gimage->width, - gimprc.marching_speed); - - gdisp->disp_width = shell->canvas->allocation.width; - gdisp->disp_height = shell->canvas->allocation.height; - - /* create GC for scrolling */ - shell->scroll_gc = gdk_gc_new (shell->canvas->window); - gdk_gc_set_exposures (shell->scroll_gc, TRUE); - - /* set up the scrollbar observers */ - g_signal_connect (G_OBJECT (shell->hsbdata), "value_changed", - G_CALLBACK (gdisplay_hscrollbar_update), - shell); - g_signal_connect (G_OBJECT (shell->vsbdata), "value_changed", - G_CALLBACK (gdisplay_vscrollbar_update), - shell); - - /* setup scale properly */ - gimp_display_shell_scale_setup (shell); - } - - /* Find out what device the event occurred upon */ - if (! gdisp->gimage->gimp->busy && devices_check_change (event)) - gdisplay_check_device_cursor (shell); - - switch (event->type) - { - case GDK_EXPOSE: - eevent = (GdkEventExpose *) event; - - gdisplay_redraw (shell, - eevent->area.x, eevent->area.y, - eevent->area.width, eevent->area.height); - break; - - case GDK_CONFIGURE: - if ((gdisp->disp_width != shell->canvas->allocation.width) || - (gdisp->disp_height != shell->canvas->allocation.height)) - { - gdisp->disp_width = shell->canvas->allocation.width; - gdisp->disp_height = shell->canvas->allocation.height; - - gimp_display_shell_scale_resize (shell, FALSE, FALSE); - } - break; - - case GDK_LEAVE_NOTIFY: - if (((GdkEventCrossing *) event)->mode != GDK_CROSSING_NORMAL) - return TRUE; - gimp_display_shell_update_cursor (shell, 0, 0); - gtk_label_set_text (GTK_LABEL (shell->cursor_label), ""); - info_window_update_extended (gdisp, -1, -1); - - case GDK_PROXIMITY_OUT: - shell->proximity = FALSE; - break; - - case GDK_ENTER_NOTIFY: - if (((GdkEventCrossing *) event)->mode != GDK_CROSSING_NORMAL) - return TRUE; - /* Actually, should figure out tx,ty here */ - break; - - case GDK_BUTTON_PRESS: - bevent = (GdkEventButton *) event; - state = bevent->state; - - /* ignore new mouse events */ - if (gdisp->gimage->gimp->busy) - return TRUE; - - switch (bevent->button) - { - case 1: - state |= GDK_BUTTON1_MASK; - gtk_grab_add (canvas); - - /* This is a hack to prevent other stuff being run in the middle of - * a tool operation (like changing image types.... brrrr). We just - * block all the keypress event. A better solution is to implement - * some sort of locking for images. - * Note that this is dependent on specific GTK behavior, and isn't - * guaranteed to work in future versions of GTK. - * -Yosh - */ - if (key_signal_id == 0) - key_signal_id = g_signal_connect (G_OBJECT (canvas), - "key_press_event", - G_CALLBACK (gtk_true), - NULL); - - /* FIXME!!! This code is ugly */ - - if (active_tool && (GIMP_IS_MOVE_TOOL (active_tool) || - ! gimp_image_is_empty (gdisp->gimage))) - { - if (active_tool->auto_snap_to) - { - gimp_display_shell_snap_point (shell, - bevent->x, bevent->y, - &tx, &ty); - bevent->x = tx; - bevent->y = ty; - update_cursor = TRUE; - } - - /* reset the current tool if ... */ - if ((/* it has no drawable */ - ! active_tool->drawable || - - /* or a drawable different from the current one */ - (gimp_image_active_drawable (gdisp->gimage) != - active_tool->drawable)) && - - /* and doesn't want to be preserved across drawable changes */ - ! active_tool->preserve) - { - tool_manager_initialize_tool (gdisp->gimage->gimp, - active_tool, gdisp); - - active_tool = tool_manager_get_active (gdisp->gimage->gimp); - } - - /* otherwise set it's drawable if it has none */ - else if (! active_tool->drawable) - { - active_tool->drawable = - gimp_image_active_drawable (gdisp->gimage); - } - - gimp_tool_button_press (active_tool, bevent, gdisp); - } - break; - - case 2: - { - GdkCursor *cursor; - - state |= GDK_BUTTON2_MASK; - - scrolling = TRUE; - scroll_start_x = bevent->x + gdisp->offset_x; - scroll_start_y = bevent->y + gdisp->offset_y; - - gtk_grab_add (canvas); - - cursor = gimp_cursor_new (GDK_FLEUR, - GIMP_TOOL_CURSOR_NONE, - GIMP_CURSOR_MODIFIER_NONE); - gdk_window_set_cursor (shell->canvas->window, cursor); - gdk_cursor_unref (cursor); - } - break; - - case 3: - state |= GDK_BUTTON3_MASK; - gimp_item_factory_popup_with_data (shell->ifactory, gdisp->gimage); - return_val = TRUE; - break; - - default: - break; - } - break; - - case GDK_BUTTON_RELEASE: - bevent = (GdkEventButton *) event; - state = bevent->state; - - /* ugly side condition: all operations which set busy cursors are - * invoked on BUTTON_RELEASE, thus no new BUTTON_PRESS events are - * accepted while Gimp is busy, thus it should be safe to block - * BUTTON_RELEASE. --Mitch - * - * ugly: fuzzy_select sets busy cursors while ACTIVE. - */ - if (gdisp->gimage->gimp->busy && - ! (GIMP_IS_FUZZY_SELECT_TOOL (active_tool) && - active_tool->state == ACTIVE)) - return TRUE; - - switch (bevent->button) - { - case 1: - state &= ~GDK_BUTTON1_MASK; - - /* Lame hack. See above */ - if (key_signal_id) - { - g_signal_handler_disconnect (G_OBJECT (canvas), key_signal_id); - key_signal_id = 0; - } - - gtk_grab_remove (canvas); - - if (active_tool && (GIMP_IS_MOVE_TOOL (active_tool) || - ! gimp_image_is_empty (gdisp->gimage))) - { - if (active_tool->state == ACTIVE) - { - if (active_tool->auto_snap_to) - { - gimp_display_shell_snap_point (shell, - bevent->x, bevent->y, - &tx, &ty); - bevent->x = tx; - bevent->y = ty; - update_cursor = TRUE; - } - - gimp_tool_button_release (active_tool, bevent, gdisp); - } - } - break; - - case 2: - state &= ~GDK_BUTTON2_MASK; - scrolling = FALSE; - gtk_grab_remove (canvas); - gimp_display_shell_real_install_tool_cursor (shell, - shell->current_cursor, - shell->tool_cursor, - GIMP_CURSOR_MODIFIER_NONE, - TRUE); - break; - - case 3: - state &= ~GDK_BUTTON3_MASK; - break; - - default: - break; - } - break; - - case GDK_SCROLL: - sevent = (GdkEventScroll *) event; - state = sevent->state; - - if (state & GDK_SHIFT_MASK) - { - if (sevent->direction == GDK_SCROLL_UP) - gimp_display_shell_scale (shell, GIMP_ZOOM_IN); - else - gimp_display_shell_scale (shell, GIMP_ZOOM_OUT); - } - else - { - GtkAdjustment *adj; - gdouble value; - - if (state & GDK_CONTROL_MASK) - adj = shell->hsbdata; - else - adj = shell->vsbdata; - - value = adj->value + ((sevent->direction == GDK_SCROLL_UP) ? - -adj->page_increment / 2 : - adj->page_increment / 2); - value = CLAMP (value, adj->lower, adj->upper - adj->page_size); - - gtk_adjustment_set_value (adj, value); - } - - return_val = TRUE; - break; - - case GDK_MOTION_NOTIFY: - mevent = (GdkEventMotion *) event; - state = mevent->state; - - /* for the same reason we block BUTTON_RELEASE, - * we block MOTION_NOTIFY. --Mitch - * - * ugly: fuzzy_select sets busy cursors while ACTIVE. - */ - if (gdisp->gimage->gimp->busy && - ! (GIMP_IS_FUZZY_SELECT_TOOL (active_tool) && - active_tool->state == ACTIVE)) - return TRUE; - - /* Ask for the pointer position, but ignore it except for cursor - * handling, so motion events sync with the button press/release events - */ - if (mevent->is_hint) - { -#ifdef __GNUC__ -#warning FIXME: replace gdk_input_window_get_pointer() -#endif -#if 0 - gdk_input_window_get_pointer (canvas->window, current_device, &tx, &ty, - NULL, NULL, NULL, NULL); -#endif - } - else - { - tx = mevent->x; - ty = mevent->y; - } - update_cursor = TRUE; - - if (! shell->proximity) - { - shell->proximity = TRUE; - gdisplay_check_device_cursor (shell); - } - - if (active_tool && (GIMP_IS_MOVE_TOOL(active_tool) || - ! gimp_image_is_empty (gdisp->gimage)) && - (mevent->state & GDK_BUTTON1_MASK)) - { - if (active_tool->state == ACTIVE) - { - /* if the first mouse button is down, check for automatic - * scrolling... - */ - if ((mevent->state & GDK_BUTTON1_MASK) && - !active_tool->scroll_lock) - { - if (mevent->x < 0 || - mevent->y < 0 || - mevent->x > gdisp->disp_width || - mevent->y > gdisp->disp_height) - { - gdouble child_x, child_y; - gint off_x, off_y; - - off_x = off_y = 0; - - /* The cases for scrolling */ - if (mevent->x < 0) - off_x = mevent->x; - else if (mevent->x > gdisp->disp_width) - off_x = mevent->x - gdisp->disp_width; - - if (mevent->y < 0) - off_y = mevent->y; - else if (mevent->y > gdisp->disp_height) - off_y = mevent->y - gdisp->disp_height; - - if (gimp_display_shell_scroll (shell, off_x, off_y)) - { -#ifdef __GNUC__ -#warning FIXME: replace gdk_input_window_get_pointer() -#endif -#if 0 - gdk_input_window_get_pointer (shell->canvas->window, mevent->deviceid, - &child_x, &child_y, - NULL, NULL, NULL, NULL); - - if (child_x == mevent->x && child_y == mevent->y) - /* Put this event back on the queue -- so it keeps scrolling */ - gdk_event_put ((GdkEvent *) mevent); -#endif - } - } - } - - if (active_tool->auto_snap_to) - { - gimp_display_shell_snap_point (shell, - mevent->x, mevent->y, - &tx, &ty); - mevent->x = tx; - mevent->y = ty; - update_cursor = TRUE; - } - - gimp_tool_motion (active_tool, mevent, gdisp); - } - } - else if ((mevent->state & GDK_BUTTON2_MASK) && scrolling) - { - gimp_display_shell_scroll (shell, - (scroll_start_x - mevent->x - - gdisp->offset_x), - (scroll_start_y - mevent->y - - gdisp->offset_y)); - } - - if (/* Should we have a tool... */ - active_tool && - /* and this event is NOT driving - * button press handlers ... - */ - !(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) - { - /* ...then preconditions to modify a tool - * operator state have been met. - */ - gimp_tool_oper_update (active_tool, mevent, gdisp); - } - - break; - - case GDK_KEY_PRESS: - kevent = (GdkEventKey *) event; - state = kevent->state; - - /* ignore any key presses */ - if (gdisp->gimage->gimp->busy) - return TRUE; - - switch (kevent->keyval) - { - case GDK_Left: case GDK_Right: - case GDK_Up: case GDK_Down: - if (active_tool && ! gimp_image_is_empty (gdisp->gimage)) - gimp_tool_arrow_key (active_tool, kevent, gdisp); - - return_val = TRUE; - break; - - case GDK_Tab: - if (kevent->state & GDK_MOD1_MASK && - !gimp_image_is_empty (gdisp->gimage)) - layer_select_init (gdisp->gimage, 1, kevent->time); - - if (kevent->state & GDK_CONTROL_MASK && - !gimp_image_is_empty (gdisp->gimage)) - layer_select_init (gdisp->gimage, -1, kevent->time); - - /* Hide or show all dialogs */ - if (! kevent->state) - gimp_dialog_factories_toggle (global_dialog_factory, - "gimp:toolbox"); - - return_val = TRUE; - break; - - /* Update the state based on modifiers being pressed */ - case GDK_Alt_L: case GDK_Alt_R: - case GDK_Shift_L: case GDK_Shift_R: - case GDK_Control_L: case GDK_Control_R: - state |= key_to_state (kevent->keyval); - /* For all modifier keys: call the tools modifier_key_func */ - if (active_tool && !gimp_image_is_empty (gdisp->gimage)) - { -#if 0 - gdk_input_window_get_pointer (canvas->window, current_device, - &tx, &ty, NULL, NULL, NULL, NULL); -#endif - gimp_tool_modifier_key (active_tool, kevent, gdisp); - return_val = TRUE; - } - break; - } - break; - - case GDK_KEY_RELEASE: - kevent = (GdkEventKey *) event; - state = kevent->state; - - /* ignore any key releases */ - if (gdisp->gimage->gimp->busy) - return TRUE; - - switch (kevent->keyval) - { - case GDK_Alt_L: case GDK_Alt_R: - case GDK_Shift_L: case GDK_Shift_R: - case GDK_Control_L: case GDK_Control_R: - state &= ~key_to_state (kevent->keyval); - /* For all modifier keys: call the tools modifier_key_func */ - if (active_tool && !gimp_image_is_empty (gdisp->gimage)) - { -#if 0 - gdk_input_window_get_pointer (canvas->window, current_device, - &tx, &ty, NULL, NULL, NULL, NULL); -#endif - gimp_tool_modifier_key (active_tool, kevent, gdisp); - return_val = TRUE; - } - break; - } - - return_val = TRUE; - break; - - default: - break; - } - - /* if we reached this point in gimp_busy mode, return now */ - if (gdisp->gimage->gimp->busy) - return TRUE; - - /* Cursor update support - * no_cursor_updating is TRUE (=1) when - * /File/Preferences.../Interface/... - * Image Windows/Disable Cursor Updating is TOGGLED ON - */ - if (! gimprc.no_cursor_updating) - { - active_tool = tool_manager_get_active (gdisp->gimage->gimp); - - if (active_tool && !gimp_image_is_empty (gdisp->gimage) && - !(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) - { - GdkEventMotion me; - me.x = tx; me.y = ty; - me.state = state; - gimp_tool_cursor_update (active_tool, &me, gdisp); - } - else if (gimp_image_is_empty (gdisp->gimage)) - { - gimp_display_shell_install_tool_cursor (shell, - GIMP_BAD_CURSOR, - GIMP_TOOL_CURSOR_NONE, - GIMP_CURSOR_MODIFIER_NONE); - } - } - - if (update_cursor) - gimp_display_shell_update_cursor (shell, tx, ty); - - return return_val; -} - -gboolean -gdisplay_hruler_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) -{ - GimpDisplay *gdisp; - - gdisp = shell->gdisp; - - if (gdisp->gimage->gimp->busy) - return TRUE; - - if (event->button == 1) - { - GimpToolInfo *tool_info; - GimpTool *active_tool; - - tool_info = tool_manager_get_info_by_type (gdisp->gimage->gimp, - GIMP_TYPE_MOVE_TOOL); - - if (tool_info) - { - gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp), - tool_info); - - active_tool = tool_manager_get_active (gdisp->gimage->gimp); - - if (active_tool) - { - gimp_move_tool_start_hguide (active_tool, gdisp); - gtk_grab_add (shell->canvas); - } - } - } - - return FALSE; -} - -gboolean -gdisplay_vruler_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) -{ - GimpDisplay *gdisp; - - gdisp = shell->gdisp; - - if (gdisp->gimage->gimp->busy) - return TRUE; - - if (event->button == 1) - { - GimpToolInfo *tool_info; - GimpTool *active_tool; - - tool_info = tool_manager_get_info_by_type (gdisp->gimage->gimp, - GIMP_TYPE_MOVE_TOOL); - - if (tool_info) - { - gimp_context_set_tool (gimp_get_user_context (gdisp->gimage->gimp), - tool_info); - - active_tool = tool_manager_get_active (gdisp->gimage->gimp); - - if (active_tool) - { - gimp_move_tool_start_vguide (active_tool, gdisp); - gtk_grab_add (shell->canvas); - } - } - } - - return FALSE; -} - -static void -gdisplay_origin_menu_position (GtkMenu *menu, - gint *x, - gint *y, - gpointer data) -{ - GtkWidget *origin; - gint origin_x; - gint origin_y; - - origin = (GtkWidget *) data; - - gdk_window_get_origin (origin->window, &origin_x, &origin_y); - - *x = origin_x + origin->allocation.x + origin->allocation.width - 1; - *y = origin_y + origin->allocation.y + (origin->allocation.height - 1) / 2; - - if (*x + GTK_WIDGET (menu)->allocation.width > gdk_screen_width ()) - *x -= (GTK_WIDGET (menu)->allocation.width + origin->allocation.width); - - if (*y + GTK_WIDGET (menu)->allocation.height > gdk_screen_height ()) - *y -= (GTK_WIDGET (menu)->allocation.height); -} - -gboolean -gdisplay_origin_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) -{ - GimpDisplay *gdisp; - - gdisp = shell->gdisp; - - if (! gdisp->gimage->gimp->busy && event->button == 1) - { - gint x, y; - - gdisplay_origin_menu_position (GTK_MENU (shell->ifactory->widget), - &x, &y, widget); - - gtk_item_factory_popup_with_data (shell->ifactory, - gdisp->gimage, NULL, - x, y, - 1, event->time); - } - - /* Return TRUE to stop signal emission so the button doesn't grab the - * pointer away from us. - */ - return TRUE; -} - -void -gdisplay_drop_drawable (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpDrawable *drawable; - GimpDisplay *gdisp; - GimpImage *src_gimage; - GimpLayer *new_layer; - GimpImage *dest_gimage; - gint src_width, src_height; - gint dest_width, dest_height; - gint off_x, off_y; - TileManager *tiles; - PixelRegion srcPR, destPR; - guchar bg[MAX_CHANNELS]; - gint bytes; - GimpImageBaseType type; - - gdisp = GIMP_DISPLAY_SHELL (data)->gdisp; - - if (gdisp->gimage->gimp->busy) - return; - - drawable = GIMP_DRAWABLE (viewable); - - src_gimage = gimp_drawable_gimage (drawable); - src_width = gimp_drawable_width (drawable); - src_height = gimp_drawable_height (drawable); - - switch (gimp_drawable_type (drawable)) - { - case RGB_GIMAGE: case RGBA_GIMAGE: - bytes = 4; type = RGB; - break; - case GRAY_GIMAGE: case GRAYA_GIMAGE: - bytes = 2; type = GRAY; - break; - case INDEXED_GIMAGE: case INDEXEDA_GIMAGE: - bytes = 4; type = INDEXED; - break; - default: - bytes = 3; type = RGB; - break; - } - - gimp_image_get_background (src_gimage, drawable, bg); - - tiles = tile_manager_new (src_width, src_height, bytes); - - pixel_region_init (&srcPR, gimp_drawable_data (drawable), - 0, 0, src_width, src_height, FALSE); - pixel_region_init (&destPR, tiles, - 0, 0, src_width, src_height, TRUE); - - if (type == INDEXED) - { - /* If the layer is indexed...we need to extract pixels */ - extract_from_region (&srcPR, &destPR, NULL, - gimp_drawable_cmap (drawable), bg, type, - gimp_drawable_has_alpha (drawable), FALSE); - } - else if (bytes > srcPR.bytes) - { - /* If the layer doesn't have an alpha channel, add one */ - add_alpha_region (&srcPR, &destPR); - } - else - { - /* Otherwise, do a straight copy */ - copy_region (&srcPR, &destPR); - } - - dest_gimage = gdisp->gimage; - dest_width = dest_gimage->width; - dest_height = dest_gimage->height; - - undo_push_group_start (dest_gimage, EDIT_PASTE_UNDO); - - new_layer = - gimp_layer_new_from_tiles (dest_gimage, - gimp_image_base_type_with_alpha (dest_gimage), - tiles, - _("Pasted Layer"), - OPAQUE_OPACITY, NORMAL_MODE); - - tile_manager_destroy (tiles); - - if (new_layer) - { - gimp_drawable_set_gimage (GIMP_DRAWABLE (new_layer), dest_gimage); - - off_x = (dest_gimage->width - src_width) / 2; - off_y = (dest_gimage->height - src_height) / 2; - - gimp_layer_translate (new_layer, off_x, off_y); - - gimp_image_add_layer (dest_gimage, new_layer, -1); - - undo_push_group_end (dest_gimage); - - gdisplays_flush (); - - gimp_context_set_display (gimp_get_user_context (gdisp->gimage->gimp), - gdisp); - } -} - -static void -gdisplay_bucket_fill (GimpDisplay *gdisp, - BucketFillMode fill_mode, - guchar orig_color[], - TempBuf *orig_pat_buf) -{ - GimpImage *gimage; - GimpDrawable *drawable; - TileManager *buf_tiles; - PixelRegion bufPR; - GimpToolInfo *tool_info; - GimpContext *context; - gint x1, x2, y1, y2; - gint bytes; - gboolean has_alpha; - - guchar color[3]; - TempBuf *pat_buf = NULL; - gboolean new_buf = FALSE; - - gimage = gdisp->gimage; - - if (gimage->gimp->busy) - return; - - drawable = gimp_image_active_drawable (gimage); - - if (! drawable) - return; - - gimp_set_busy (gimage->gimp); - - /* Get the bucket fill context */ - tool_info = tool_manager_get_info_by_type (gimage->gimp, - GIMP_TYPE_BUCKET_FILL_TOOL); - - if (tool_info && tool_info->context) - { - context = tool_info->context; - } - else - { - context = gimp_get_user_context (gimage->gimp); - } - - /* Transform the passed data for the dest image */ - if (fill_mode == FG_BUCKET_FILL) - { - gimp_image_transform_color (gimage, drawable, orig_color, color, RGB); - } - else - { - if (((orig_pat_buf->bytes == 3) && ! gimp_drawable_is_rgb (drawable)) || - ((orig_pat_buf->bytes == 1) && ! gimp_drawable_is_gray (drawable))) - { - guchar *d1, *d2; - gint size; - - if ((orig_pat_buf->bytes == 1) && gimp_drawable_is_rgb (drawable)) - pat_buf = temp_buf_new (orig_pat_buf->width, orig_pat_buf->height, - 3, 0, 0, NULL); - else - pat_buf = temp_buf_new (orig_pat_buf->width, orig_pat_buf->height, - 1, 0, 0, NULL); - - d1 = temp_buf_data (orig_pat_buf); - d2 = temp_buf_data (pat_buf); - - size = orig_pat_buf->width * orig_pat_buf->height; - while (size--) - { - gimp_image_transform_color (gimage, drawable, d1, d2, - (orig_pat_buf->bytes == 3) ? RGB : GRAY); - d1 += orig_pat_buf->bytes; - d2 += pat_buf->bytes; - } - - new_buf = TRUE; - } - else - { - pat_buf = orig_pat_buf; - } - } - - gimp_drawable_mask_bounds (drawable, &x1, &y1, &x2, &y2); - bytes = gimp_drawable_bytes (drawable); - has_alpha = gimp_drawable_has_alpha (drawable); - - /* Fill the region */ - buf_tiles = tile_manager_new ((x2 - x1), (y2 - y1), bytes); - pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), TRUE); - bucket_fill_region (fill_mode, &bufPR, NULL, - color, pat_buf, x1, y1, has_alpha); - - /* Apply it to the image */ - pixel_region_init (&bufPR, buf_tiles, 0, 0, (x2 - x1), (y2 - y1), FALSE); - gimp_image_apply_image (gimage, drawable, &bufPR, TRUE, - gimp_context_get_opacity (context) * 255, - gimp_context_get_paint_mode (context), - NULL, x1, y1); - tile_manager_destroy (buf_tiles); - - /* Update the displays */ - gimp_drawable_update (drawable, - x1, y1, - (x2 - x1), (y2 - y1)); - gdisplays_flush (); - - if (new_buf) - temp_buf_free (pat_buf); - - gimp_unset_busy (gimage->gimp); -} - -void -gdisplay_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpDisplay *gdisp; - - gdisp = GIMP_DISPLAY_SHELL (data)->gdisp; - - if (GIMP_IS_PATTERN (viewable)) - { - gdisplay_bucket_fill (gdisp, - PATTERN_BUCKET_FILL, - NULL, - GIMP_PATTERN (viewable)->mask); - } -} - -void -gdisplay_drop_color (GtkWidget *widget, - const GimpRGB *drop_color, - gpointer data) -{ - GimpDisplay *gdisp; - guchar color[4]; - - gdisp = GIMP_DISPLAY_SHELL (data)->gdisp; - - gimp_rgba_get_uchar (drop_color, - &color[0], - &color[1], - &color[2], - &color[3]); - - gdisplay_bucket_fill (gdisp, - FG_BUCKET_FILL, - color, - NULL); -} - -void -gdisplay_drop_buffer (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) -{ - GimpBuffer *buffer; - GimpDisplay *gdisp; - - gdisp = GIMP_DISPLAY_SHELL (data)->gdisp; - - if (gdisp->gimage->gimp->busy) - return; - - buffer = GIMP_BUFFER (viewable); - - /* FIXME: popup a menu for selecting "Paste Into" */ - - gimp_edit_paste (gdisp->gimage, - gimp_image_active_drawable (gdisp->gimage), - buffer->tiles, - FALSE); - - gdisplays_flush (); -} diff --git a/app/display/gimpdisplay-callbacks.h b/app/display/gimpdisplay-callbacks.h deleted file mode 100644 index 216652984d..0000000000 --- a/app/display/gimpdisplay-callbacks.h +++ /dev/null @@ -1,67 +0,0 @@ -/* 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. - */ - -#ifndef __GIMP_DISPLAY_CALLBACKS_H__ -#define __GIMP_DISPLAY_CALLBACKS_H__ - - -#define CANVAS_EVENT_MASK (GDK_EXPOSURE_MASK | \ - GDK_POINTER_MOTION_MASK | \ - GDK_POINTER_MOTION_HINT_MASK | \ - GDK_BUTTON_PRESS_MASK | \ - GDK_BUTTON_RELEASE_MASK | \ - GDK_STRUCTURE_MASK | \ - GDK_ENTER_NOTIFY_MASK | \ - GDK_LEAVE_NOTIFY_MASK | \ - GDK_KEY_PRESS_MASK | \ - GDK_KEY_RELEASE_MASK | \ - GDK_PROXIMITY_OUT_MASK) - - -gboolean gdisplay_shell_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell); -gboolean gdisplay_canvas_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell); - -gboolean gdisplay_hruler_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); -gboolean gdisplay_vruler_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); -gboolean gdisplay_origin_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); - -void gdisplay_drop_drawable (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -void gdisplay_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -void gdisplay_drop_color (GtkWidget *widget, - const GimpRGB *color, - gpointer data); -void gdisplay_drop_buffer (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); - - -#endif /* __GIMP_DISPLAY_CALLBACKS_H__ */ diff --git a/app/display/gimpdisplay-foreach.c b/app/display/gimpdisplay-foreach.c index 94bcbaceca..3376aa3a38 100644 --- a/app/display/gimpdisplay-foreach.c +++ b/app/display/gimpdisplay-foreach.c @@ -26,7 +26,6 @@ #include "gimpdisplay.h" #include "gimpdisplay-foreach.h" -#include "gimpdisplay-scale.h" #include "gimpdisplayshell.h" #include "nav_window.h" @@ -59,23 +58,6 @@ gdisplays_expose_guide (GimpImage *gimage, } } -void -gdisplays_shrink_wrap (GimpImage *gimage) -{ - GimpDisplay *gdisp; - GSList *list; - - g_return_if_fail (GIMP_IS_IMAGE (gimage)); - - for (list = display_list; list; list = g_slist_next (list)) - { - gdisp = (GimpDisplay *) list->data; - - if (gdisp->gimage == gimage) - gimp_display_shell_scale_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell)); - } -} - void gdisplays_expose_full (void) { diff --git a/app/display/gimpdisplay-foreach.h b/app/display/gimpdisplay-foreach.h index cf949c0628..ed8ed07ef3 100644 --- a/app/display/gimpdisplay-foreach.h +++ b/app/display/gimpdisplay-foreach.h @@ -28,7 +28,6 @@ void gdisplays_reconnect (GimpImage *old, GimpImage *new); void gdisplays_expose_guide (GimpImage *gimage, GimpGuide *guide); -void gdisplays_shrink_wrap (GimpImage *gimage); void gdisplays_expose_full (void); gboolean gdisplays_dirty (void); void gdisplays_delete (void); diff --git a/app/display/gimpdisplay-handlers.c b/app/display/gimpdisplay-handlers.c index 51fc82bbe8..f88c2f95db 100644 --- a/app/display/gimpdisplay-handlers.c +++ b/app/display/gimpdisplay-handlers.c @@ -26,8 +26,10 @@ #include "gimpdisplay.h" #include "gimpdisplay-handlers.h" -#include "gimpdisplay-scale.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-scale.h" + +#include "gimprc.h" /* local function prototypes */ @@ -230,7 +232,9 @@ gimp_display_size_changed_handler (GimpImage *gimage, gdisp->gimage->height); gimp_display_shell_resize_cursor_label (GIMP_DISPLAY_SHELL (gdisp->shell)); - gimp_display_shell_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell)); + + gimp_display_shell_scale_resize (GIMP_DISPLAY_SHELL (gdisp->shell), + gimprc.allow_resize_windows, TRUE); } static void diff --git a/app/display/gimpdisplay-render.c b/app/display/gimpdisplay-render.c deleted file mode 100644 index 865e6168cf..0000000000 --- a/app/display/gimpdisplay-render.c +++ /dev/null @@ -1,891 +0,0 @@ -/* 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 -#include - -#include - -#include "display-types.h" - -#include "base/tile-manager.h" -#include "base/tile.h" - -#include "core/gimpimage.h" - -#include "gimpdisplay.h" -#include "gimpdisplay-render.h" -#include "gimpdisplayshell.h" -#include "gximage.h" - -#include "gimprc.h" - - -#define MAX_PREVIEW_SIZE 256 /* EEK */ - - -typedef struct _RenderInfo RenderInfo; - -typedef void (* RenderFunc) (RenderInfo *info); - -struct _RenderInfo -{ - GimpDisplay *gdisp; - TileManager *src_tiles; - guint *alpha; - guchar *scale; - guchar *src; - guchar *dest; - gint x, y; - gint w, h; - gfloat scalex; - gfloat scaley; - gint src_x, src_y; - gint src_bpp; - gint dest_bpp; - gint dest_bpl; - gint dest_width; - gint byte_order; -}; - - -/* accelerate transparency of image scaling */ -guchar *render_check_buf = NULL; -guchar *render_empty_buf = NULL; -guchar *render_temp_buf = NULL; -guchar *render_blend_dark_check = NULL; -guchar *render_blend_light_check = NULL; - - -static guchar *tile_buf = NULL; -static guint check_mod = 0; -static guint check_shift = 0; -static guint tile_shift = 0; -static guchar check_combos[6][2] = -{ - { 204, 255 }, - { 102, 153 }, - { 0, 51 }, - { 255, 255 }, - { 127, 127 }, - { 0, 0 } -}; - - -void -render_setup (GimpCheckType check_type, - GimpCheckSize check_size) -{ - gint i, j; - - if (check_type < LIGHT_CHECKS || check_type > BLACK_ONLY) - g_error ("invalid check_type argument to render_setup: %d", check_type); - if (check_size < SMALL_CHECKS || check_size > LARGE_CHECKS) - g_error ("invalid check_size argument to render_setup: %d", check_size); - - /* based on the tile size, determine the tile shift amount - * (assume here that tile_height and tile_width are equal) - */ - tile_shift = 0; - while ((1 << tile_shift) < TILE_WIDTH) - tile_shift++; - - /* allocate a buffer for arranging information from a row of tiles */ - if (! tile_buf) - tile_buf = g_new (guchar, GXIMAGE_WIDTH * MAX_CHANNELS); - - if (! render_blend_dark_check) - render_blend_dark_check = g_new (guchar, 65536); - if (! render_blend_light_check) - render_blend_light_check = g_new (guchar, 65536); - - for (i = 0; i < 256; i++) - for (j = 0; j < 256; j++) - { - render_blend_dark_check [(i << 8) + j] = (guchar) - ((j * i + check_combos[check_type][0] * (255 - i)) / 255); - render_blend_light_check [(i << 8) + j] = (guchar) - ((j * i + check_combos[check_type][1] * (255 - i)) / 255); - } - - switch (check_size) - { - case SMALL_CHECKS: - check_mod = 0x3; - check_shift = 2; - break; - case MEDIUM_CHECKS: - check_mod = 0x7; - check_shift = 3; - break; - case LARGE_CHECKS: - check_mod = 0xf; - check_shift = 4; - break; - } - - g_free (render_check_buf); - g_free (render_empty_buf); - g_free (render_temp_buf); - - /* calculate check buffer for previews */ - if (TRUE /* preview_size */) - { - render_check_buf = g_new (guchar, (MAX_PREVIEW_SIZE + 4) * 3); - - for (i = 0; i < (MAX_PREVIEW_SIZE + 4); i++) - { - if (i & 0x4) - { - render_check_buf[i * 3 + 0] = render_blend_dark_check[0]; - render_check_buf[i * 3 + 1] = render_blend_dark_check[0]; - render_check_buf[i * 3 + 2] = render_blend_dark_check[0]; - } - else - { - render_check_buf[i * 3 + 0] = render_blend_light_check[0]; - render_check_buf[i * 3 + 1] = render_blend_light_check[0]; - render_check_buf[i * 3 + 2] = render_blend_light_check[0]; - } - } - - render_empty_buf = g_new0 (guchar, (MAX_PREVIEW_SIZE + 4) * 3); - render_temp_buf = g_new (guchar, (MAX_PREVIEW_SIZE + 4) * 3); - } - else - { - render_check_buf = NULL; - render_empty_buf = NULL; - render_temp_buf = NULL; - } -} - -void -render_free (void) -{ - g_free (tile_buf); - g_free (render_check_buf); -} - - -/* Render Image functions */ - -static void render_image_rgb (RenderInfo *info); -static void render_image_rgb_a (RenderInfo *info); -static void render_image_gray (RenderInfo *info); -static void render_image_gray_a (RenderInfo *info); -static void render_image_indexed (RenderInfo *info); -static void render_image_indexed_a (RenderInfo *info); - -static void render_image_init_info (RenderInfo *info, - GimpDisplay *gdisp, - gint x, - gint y, - gint w, - gint h); -static guint * render_image_init_alpha (gint mult); -static guchar * render_image_accelerate_scaling (gint width, - gint start, - gfloat scalex); -static guchar * render_image_tile_fault (RenderInfo *info); - - -static RenderFunc render_funcs[6] = -{ - render_image_rgb, - render_image_rgb_a, - render_image_gray, - render_image_gray_a, - render_image_indexed, - render_image_indexed_a, -}; - - -/*****************************************************************/ -/* This function is the core of the display--it offsets and */ -/* scales the image according to the current parameters in the */ -/* gdisp object. It handles color, grayscale, 8, 15, 16, 24, */ -/* & 32 bit output depths. */ -/*****************************************************************/ - -void -render_image (GimpDisplay *gdisp, - gint x, - gint y, - gint w, - gint h) -{ - RenderInfo info; - gint image_type; - - render_image_init_info (&info, gdisp, x, y, w, h); - - image_type = gimp_image_projection_type (gdisp->gimage); - - if ((image_type < 0) || (image_type > 5)) - { - g_message ("unknown gimage projection type: %d", - gimp_image_projection_type (gdisp->gimage)); - return; - } - - if ((info.dest_bpp < 1) || (info.dest_bpp > 4)) - { - g_message ("unsupported destination bytes per pixel: %d", info.dest_bpp); - return; - } - - /* Currently, only RGBA and GRAYA projection types are used - the rest - * are in case of future need. -- austin, 28th Nov 1998. - */ - if (image_type != RGBA_GIMAGE && image_type != GRAYA_GIMAGE) - g_warning ("using untested projection type %d", image_type); - - (* render_funcs[image_type]) (&info); -} - - -/*************************/ -/* 8 Bit functions */ -/*************************/ - -static void -render_image_indexed (RenderInfo *info) -{ - guchar *src; - guchar *dest; - guchar *cmap; - gulong val; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - cmap = gimp_image_cmap (info->gdisp->gimage); - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= ((gint) error) - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - g_return_if_fail (src != NULL); - - for (x = info->x; x < xe; x++) - { - val = src[INDEXED_PIX] * 3; - src += 1; - - dest[0] = cmap[val+0]; - dest[1] = cmap[val+1]; - dest[2] = cmap[val+2]; - dest += 3; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_indexed_a (RenderInfo *info) -{ - guchar *src; - guchar *dest; - guint *alpha; - guchar *cmap; - gulong r, g, b; - gulong val; - guint a; - gint dark_light; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - cmap = gimp_image_cmap (info->gdisp->gimage); - alpha = info->alpha; - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= ((gint) error) - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0) && (y & check_mod)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - dark_light = (y >> check_shift) + (info->x >> check_shift); - - g_return_if_fail (src != NULL); - - for (x = info->x; x < xe; x++) - { - a = alpha[src[ALPHA_I_PIX]]; - val = src[INDEXED_PIX] * 3; - src += 2; - - if (dark_light & 0x1) - { - r = render_blend_dark_check[(a | cmap[val + 0])]; - g = render_blend_dark_check[(a | cmap[val + 1])]; - b = render_blend_dark_check[(a | cmap[val + 2])]; - } - else - { - r = render_blend_light_check[(a | cmap[val + 0])]; - g = render_blend_light_check[(a | cmap[val + 1])]; - b = render_blend_light_check[(a | cmap[val + 2])]; - } - - dest[0] = r; - dest[1] = g; - dest[2] = b; - dest += 3; - - if (((x + 1) & check_mod) == 0) - dark_light += 1; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_gray (RenderInfo *info) -{ - guchar *src; - guchar *dest; - gulong val; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= ((gint) error) - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - g_return_if_fail (src != NULL); - - for (x = info->x; x < xe; x++) - { - val = src[GRAY_PIX]; - src += 1; - - dest[0] = val; - dest[1] = val; - dest[2] = val; - dest += 3; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_gray_a (RenderInfo *info) -{ - guchar *src; - guchar *dest; - guint *alpha; - gulong val; - guint a; - gint dark_light; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - alpha = info->alpha; - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= ((gint) error) - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0) && (y & check_mod)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - dark_light = (y >> check_shift) + (info->x >> check_shift); - - g_return_if_fail (src != NULL); - - for (x = info->x; x < xe; x++) - { - a = alpha[src[ALPHA_G_PIX]]; - if (dark_light & 0x1) - val = render_blend_dark_check[(a | src[GRAY_PIX])]; - else - val = render_blend_light_check[(a | src[GRAY_PIX])]; - src += 2; - - dest[0] = val; - dest[1] = val; - dest[2] = val; - dest += 3; - - if (((x + 1) & check_mod) == 0) - dark_light += 1; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_rgb (RenderInfo *info) -{ - guchar *src; - guchar *dest; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= (gint) error - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - g_return_if_fail (src != NULL); - - /* replace this with memcpy, or better yet, avoid it altogether? */ - for (x = info->x; x < xe; x++) - { - dest[0] = src[0]; - dest[1] = src[1]; - dest[2] = src[2]; - - src += 3; - dest += 3; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_rgb_a (RenderInfo *info) -{ - guchar *src; - guchar *dest; - guint *alpha; - gulong r, g, b; - guint a; - gint dark_light; - gint byte_order; - gint y, ye; - gint x, xe; - gint initial; - gfloat error; - gfloat step; - - alpha = info->alpha; - - y = info->y; - ye = info->y + info->h; - xe = info->x + info->w; - - step = 1.0 / info->scaley; - - error = y * step; - error -= ((gint) error) - step; - - initial = TRUE; - byte_order = info->byte_order; - info->src = render_image_tile_fault (info); - - for (; y < ye; y++) - { - if (!initial && (error < 1.0) && (y & check_mod)) - { - memcpy (info->dest, info->dest - info->dest_bpl, info->dest_width); - } - else - { - src = info->src; - dest = info->dest; - - dark_light = (y >> check_shift) + (info->x >> check_shift); - - g_return_if_fail (src != NULL); - - for (x = info->x; x < xe; x++) - { - a = alpha[src[ALPHA_PIX]]; - if (dark_light & 0x1) - { - r = render_blend_dark_check[(a | src[RED_PIX])]; - g = render_blend_dark_check[(a | src[GREEN_PIX])]; - b = render_blend_dark_check[(a | src[BLUE_PIX])]; - } - else - { - r = render_blend_light_check[(a | src[RED_PIX])]; - g = render_blend_light_check[(a | src[GREEN_PIX])]; - b = render_blend_light_check[(a | src[BLUE_PIX])]; - } - - src += 4; - - dest[0] = r; - dest[1] = g; - dest[2] = b; - dest += 3; - - if (((x + 1) & check_mod) == 0) - dark_light += 1; - } - } - - info->dest += info->dest_bpl; - - initial = FALSE; - - if (error >= 1.0) - { - info->src_y += (int)error; - error -= (int)error; - info->src = render_image_tile_fault (info); - initial = TRUE; - } - - error += step; - } -} - -static void -render_image_init_info (RenderInfo *info, - GimpDisplay *gdisp, - gint x, - gint y, - gint w, - gint h) -{ - info->gdisp = gdisp; - info->src_tiles = gimp_image_projection (gdisp->gimage); - info->x = x + gdisp->offset_x; - info->y = y + gdisp->offset_y; - info->w = w; - info->h = h; - info->scalex = SCALEFACTOR_X (gdisp); - info->scaley = SCALEFACTOR_Y (gdisp); - info->src_x = UNSCALEX (gdisp, info->x); - info->src_y = UNSCALEY (gdisp, info->y); - info->src_bpp = gimp_image_projection_bytes (gdisp->gimage); - info->dest = gximage_get_data (); - info->dest_bpp = gximage_get_bpp (); - info->dest_bpl = gximage_get_bpl (); - info->dest_width = info->w * info->dest_bpp; - info->byte_order = gximage_get_byte_order (); - info->scale = render_image_accelerate_scaling (w, info->x, info->scalex); - info->alpha = NULL; - - switch (gimp_image_projection_type (gdisp->gimage)) - { - case RGBA_GIMAGE: - case GRAYA_GIMAGE: - case INDEXEDA_GIMAGE: - info->alpha = - render_image_init_alpha (gimp_image_projection_opacity (gdisp->gimage)); - break; - default: - /* nothing special needs doing */ - break; - } -} - -static guint* -render_image_init_alpha (gint mult) -{ - static guint *alpha_mult = NULL; - static gint alpha_val = -1; - - gint i; - - if (alpha_val != mult) - { - if (!alpha_mult) - alpha_mult = g_new (guint, 256); - - alpha_val = mult; - for (i = 0; i < 256; i++) - alpha_mult[i] = ((mult * i) / 255) << 8; - } - - return alpha_mult; -} - -static guchar* -render_image_accelerate_scaling (gint width, - gint start, - gfloat scalex) -{ - static guchar *scale = NULL; - - gfloat error; - gfloat step; - gint i; - - if (!scale) - scale = g_new (guchar, GXIMAGE_WIDTH + 1); - - step = 1.0 / scalex; - - error = start * step; - error -= ((int)error) - step; - - for (i = 0; i <= width; i++) - { - scale[i] = ((int)error); - error += step - (int)error; - } - - return scale; -} - -static guchar * -render_image_tile_fault (RenderInfo *info) -{ - Tile *tile; - guchar *data; - guchar *dest; - guchar *scale; - gint width; - gint tilex; - gint tiley; - gint srctilex, srctiley; - gint step; - gint bpp = info->src_bpp; - gint x, b; - - tilex = info->src_x / TILE_WIDTH; - tiley = info->src_y / TILE_HEIGHT; - - tile = tile_manager_get_tile (info->src_tiles, - srctilex=info->src_x, srctiley=info->src_y, - TRUE, FALSE); - if (!tile) - return NULL; - - data = tile_data_pointer (tile, - info->src_x % TILE_WIDTH, - info->src_y % TILE_HEIGHT); - scale = info->scale; - dest = tile_buf; - - x = info->src_x; - width = info->w; - - while (width--) - { - for (b = 0; b < bpp; b++) - *dest++ = data[b]; - - step = *scale++; - if (step != 0) - { - x += step; - data += step * bpp; - - if ((x >> tile_shift) != tilex) - { - tile_release (tile, FALSE); - tilex += 1; - - tile = tile_manager_get_tile (info->src_tiles, srctilex=x, - srctiley=info->src_y, TRUE, FALSE); - if (!tile) - return tile_buf; - - data = tile_data_pointer (tile, - x % TILE_WIDTH, - info->src_y % TILE_HEIGHT); - } - } - } - - tile_release (tile, FALSE); - - return tile_buf; -} diff --git a/app/display/gimpdisplay-render.h b/app/display/gimpdisplay-render.h deleted file mode 100644 index c2cc4100c3..0000000000 --- a/app/display/gimpdisplay-render.h +++ /dev/null @@ -1,43 +0,0 @@ -/* 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. - */ - -#ifndef __GIMP_DISPLAY_RENDER_H__ -#define __GIMP_DISPLAY_RENDER_H__ - - -/* Functions */ -void render_setup (GimpCheckType check_type, - GimpCheckSize check_size); -void render_free (void); -void render_image (GimpDisplay *gdisp, - gint x, - gint y, - gint w, - gint h); - -/* - * Extern variables - */ -extern guchar *render_check_buf; -extern guchar *render_empty_buf; -extern guchar *render_temp_buf; -extern guchar *render_blend_dark_check; -extern guchar *render_blend_light_check; - - -#endif /* __GIMP_DISPLAY_RENDER_H__ */ diff --git a/app/display/gimpdisplay-scale.c b/app/display/gimpdisplay-scale.c deleted file mode 100644 index d9396ae9fe..0000000000 --- a/app/display/gimpdisplay-scale.c +++ /dev/null @@ -1,327 +0,0 @@ -/* 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 - -#include - -#include "libgimpbase/gimpbase.h" - -#include "display-types.h" - -#include "core/gimpimage.h" - -#include "tools/gimptool.h" -#include "tools/tool_manager.h" - -#include "gimpdisplay.h" -#include "gimpdisplay-foreach.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" -#include "gimpdisplayshell.h" - -#include "gimprc.h" -#include "nav_window.h" - - -/* local function prototypes */ - -static gdouble img2real (GimpDisplay *gdisp, - gboolean xdir, - gdouble a); - - -/* public functions */ - -void -gimp_display_shell_scale_setup (GimpDisplayShell *shell) -{ - GtkRuler *hruler; - GtkRuler *vruler; - gfloat sx, sy; - gfloat stepx, stepy; - gint image_width, image_height; - - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - image_width = shell->gdisp->gimage->width; - image_height = shell->gdisp->gimage->height; - - sx = SCALEX (shell->gdisp, image_width); - sy = SCALEY (shell->gdisp, image_height); - stepx = SCALEFACTOR_X (shell->gdisp); - stepy = SCALEFACTOR_Y (shell->gdisp); - - shell->hsbdata->value = shell->gdisp->offset_x; - shell->hsbdata->upper = sx; - shell->hsbdata->page_size = MIN (sx, shell->gdisp->disp_width); - shell->hsbdata->page_increment = shell->gdisp->disp_width / 2; - shell->hsbdata->step_increment = stepx; - - shell->vsbdata->value = shell->gdisp->offset_y; - shell->vsbdata->upper = sy; - shell->vsbdata->page_size = MIN (sy, shell->gdisp->disp_height); - shell->vsbdata->page_increment = shell->gdisp->disp_height / 2; - shell->vsbdata->step_increment = stepy; - - gtk_adjustment_changed (shell->hsbdata); - gtk_adjustment_changed (shell->vsbdata); - - hruler = GTK_RULER (shell->hrule); - vruler = GTK_RULER (shell->vrule); - - hruler->lower = 0; - hruler->upper = img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, shell->gdisp->disp_width)); - hruler->max_size = img2real (shell->gdisp, TRUE, - MAX (image_width, image_height)); - - vruler->lower = 0; - vruler->upper = img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, shell->gdisp->disp_height)); - vruler->max_size = img2real (shell->gdisp, FALSE, - MAX (image_width, image_height)); - - if (sx < shell->gdisp->disp_width) - { - shell->gdisp->disp_xoffset = (shell->gdisp->disp_width - sx) / 2; - - hruler->lower -= img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->disp_xoffset)); - hruler->upper -= img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->disp_xoffset)); - } - else - { - shell->gdisp->disp_xoffset = 0; - - hruler->lower += img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->offset_x)); - hruler->upper += img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->offset_x)); - } - - if (sy < shell->gdisp->disp_height) - { - shell->gdisp->disp_yoffset = (shell->gdisp->disp_height - sy) / 2; - - vruler->lower -= img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->disp_yoffset)); - vruler->upper -= img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->disp_yoffset)); - } - else - { - shell->gdisp->disp_yoffset = 0; - - vruler->lower += img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->offset_y)); - vruler->upper += img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->offset_y)); - } - - gtk_widget_queue_draw (GTK_WIDGET (hruler)); - gtk_widget_queue_draw (GTK_WIDGET (vruler)); - - nav_dialog_update_window_marker (shell->nav_dialog); - - if (shell->nav_popup) - nav_dialog_update_window_marker (shell->nav_popup); - -#if 0 - g_print ("offset_x: %d\n" - "offset_y: %d\n" - "disp_width: %d\n" - "disp_height: %d\n" - "disp_xoffset: %d\n" - "disp_yoffset: %d\n\n", - shell->gdisp->offset_x, shell->gdisp->offset_y, - shell->gdisp->disp_width, shell->gdisp->disp_height, - shell->gdisp->disp_xoffset, shell->gdisp->disp_yoffset); -#endif -} - -void -gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *shell, - gboolean dot_for_dot) -{ - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - if (dot_for_dot != shell->gdisp->dot_for_dot) - { - shell->gdisp->dot_for_dot = dot_for_dot; - - gimp_display_shell_resize_cursor_label (shell); - gimp_display_shell_scale_resize (shell, - gimprc.allow_resize_windows, TRUE); - } -} - -void -gimp_display_shell_scale (GimpDisplayShell *shell, - GimpZoomType zoom_type) -{ - guchar scalesrc, scaledest; - gdouble offset_x, offset_y; - glong sx, sy; - - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - /* user zoom control, so resolution versions not needed -- austin */ - scalesrc = SCALESRC (shell->gdisp); - scaledest = SCALEDEST (shell->gdisp); - - offset_x = shell->gdisp->offset_x + (shell->gdisp->disp_width / 2.0); - offset_y = shell->gdisp->offset_y + (shell->gdisp->disp_height / 2.0); - - offset_x *= ((double) scalesrc / (double) scaledest); - offset_y *= ((double) scalesrc / (double) scaledest); - - switch (zoom_type) - { - case GIMP_ZOOM_IN: - if (scalesrc > 1) - scalesrc--; - else - if (scaledest < 0x10) - scaledest++; - else - return; - break; - - case GIMP_ZOOM_OUT: - if (scaledest > 1) - scaledest--; - else - if (scalesrc < 0x10) - scalesrc++; - else - return; - break; - - default: - scalesrc = zoom_type % 100; - if (scalesrc < 1) - scalesrc = 1; - else if (scalesrc > 0x10) - scalesrc = 0x10; - scaledest = zoom_type / 100; - if (scaledest < 1) - scaledest = 1; - else if (scaledest > 0x10) - scaledest = 0x10; - break; - } - - sx = (shell->gdisp->gimage->width * scaledest) / scalesrc; - sy = (shell->gdisp->gimage->height * scaledest) / scalesrc; - - /* The slider value is a short, so make sure we are within its - * range. If we are trying to scale past it, then stop the scale - */ - if (sx < 0xffff && sy < 0xffff) - { - shell->gdisp->scale = (scaledest << 8) + scalesrc; - - /* set the offsets */ - offset_x *= ((gdouble) scaledest / (gdouble) scalesrc); - offset_y *= ((gdouble) scaledest / (gdouble) scalesrc); - - shell->gdisp->offset_x = (gint) (offset_x - (shell->gdisp->disp_width / 2)); - shell->gdisp->offset_y = (gint) (offset_y - (shell->gdisp->disp_height / 2)); - - /* resize the display */ - gimp_display_shell_scale_resize (shell, gimprc.allow_resize_windows, TRUE); - } -} - -void -gimp_display_shell_scale_resize (GimpDisplayShell *shell, - gboolean resize_window, - gboolean redisplay) -{ - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - /* freeze the active tool */ - tool_manager_control_active (shell->gdisp->gimage->gimp, PAUSE, - shell->gdisp); - - if (resize_window) - gimp_display_shell_shrink_wrap (shell); - - gimp_display_shell_scroll_clamp_offsets (shell); - gimp_display_shell_scale_setup (shell); - - if (resize_window || redisplay) - { - gimp_display_shell_expose_full (shell); - gdisplays_flush (); - - /* title may have changed if it includes the zoom ratio */ - gimp_display_shell_update_title (shell); - } - - /* re-enable the active tool */ - tool_manager_control_active (shell->gdisp->gimage->gimp, RESUME, - shell->gdisp); -} - - -void -gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell) -{ - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - gimp_display_shell_scale_resize (shell, TRUE, TRUE); -} - - -/* private functions */ - -/* scale image coord to realworld units (cm, inches, pixels) - * - * 27/Feb/1999 I tried inlining this, but the result was slightly - * slower (poorer cache locality, probably) -- austin - */ -static gdouble -img2real (GimpDisplay *gdisp, - gboolean xdir, - gdouble a) -{ - gdouble res; - - if (gdisp->dot_for_dot) - return a; - - if (xdir) - res = gdisp->gimage->xresolution; - else - res = gdisp->gimage->yresolution; - - return a * gimp_unit_get_factor (gdisp->gimage->unit) / res; -} diff --git a/app/display/gimpdisplay-scale.h b/app/display/gimpdisplay-scale.h deleted file mode 100644 index 2b5e160f7a..0000000000 --- a/app/display/gimpdisplay-scale.h +++ /dev/null @@ -1,36 +0,0 @@ -/* 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. - */ - -#ifndef __GIMP_DISPLAY_SHELL_SCALE_H__ -#define __GIMP_DISPLAY_SHELL_SCALE_H__ - - -void gimp_display_shell_scale_setup (GimpDisplayShell *shell); - -void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *gdisp, - gboolean dot_for_dot); - -void gimp_display_shell_scale (GimpDisplayShell *gdisp, - GimpZoomType zoom_type); -void gimp_display_shell_scale_resize (GimpDisplayShell *shell, - gboolean resize_window, - gboolean redisplay); -void gimp_display_shell_scale_shrink_wrap (GimpDisplayShell *shell); - - -#endif /* __GIMP_DISPLAY_SHELL_SCALE_H__ */ diff --git a/app/display/gimpdisplay-scroll.c b/app/display/gimpdisplay-scroll.c deleted file mode 100644 index 5c74870561..0000000000 --- a/app/display/gimpdisplay-scroll.c +++ /dev/null @@ -1,170 +0,0 @@ -/* 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 - -#include - -#include "display-types.h" - -#include "core/gimpimage.h" - -#include "tools/gimptool.h" -#include "tools/tool_manager.h" - -#include "gimpdisplay.h" -#include "gimpdisplay-foreach.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" -#include "gimpdisplayshell.h" - -#include "gimprc.h" -#include "nav_window.h" - - -gboolean -gimp_display_shell_scroll (GimpDisplayShell *shell, - gint x_offset, - gint y_offset) -{ - gint old_x, old_y; - gint src_x, src_y; - gint dest_x, dest_y; - GdkEvent *event; - - g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); - - old_x = shell->gdisp->offset_x; - old_y = shell->gdisp->offset_y; - - shell->gdisp->offset_x += x_offset; - shell->gdisp->offset_y += y_offset; - - gimp_display_shell_scroll_clamp_offsets (shell); - - /* the actual changes in offset */ - x_offset = (shell->gdisp->offset_x - old_x); - y_offset = (shell->gdisp->offset_y - old_y); - - if (x_offset || y_offset) - { - /* FIXME: I'm sure this is useless if all other places are correct --mitch - */ - gimp_display_shell_scale_setup (shell); - - src_x = (x_offset < 0) ? 0 : x_offset; - src_y = (y_offset < 0) ? 0 : y_offset; - dest_x = (x_offset < 0) ? -x_offset : 0; - dest_y = (y_offset < 0) ? -y_offset : 0; - - /* reset the old values so that the tool can accurately redraw */ - shell->gdisp->offset_x = old_x; - shell->gdisp->offset_y = old_y; - - /* freeze the active tool */ - tool_manager_control_active (shell->gdisp->gimage->gimp, PAUSE, - shell->gdisp); - - /* set the offsets back to the new values */ - shell->gdisp->offset_x += x_offset; - shell->gdisp->offset_y += y_offset; - - gdk_draw_drawable (shell->canvas->window, - shell->scroll_gc, - shell->canvas->window, - src_x, src_y, - dest_x, dest_y, - (shell->gdisp->disp_width - abs (x_offset)), - (shell->gdisp->disp_height - abs (y_offset))); - - /* re-enable the active tool */ - tool_manager_control_active (shell->gdisp->gimage->gimp, RESUME, - shell->gdisp); - - /* scale the image into the exposed regions */ - if (x_offset) - { - src_x = (x_offset < 0) ? 0 : shell->gdisp->disp_width - x_offset; - src_y = 0; - - gimp_display_shell_add_expose_area (shell, - src_x, src_y, - abs (x_offset), - shell->gdisp->disp_height); - } - - if (y_offset) - { - src_x = 0; - src_y = (y_offset < 0) ? 0 : shell->gdisp->disp_height - y_offset; - - gimp_display_shell_add_expose_area (shell, - src_x, src_y, - shell->gdisp->disp_width, - abs (y_offset)); - } - - if (x_offset || y_offset) - gdisplay_flush (shell->gdisp); - - nav_dialog_update_window_marker (shell->nav_dialog); - - if (shell->nav_popup) - nav_dialog_update_window_marker (shell->nav_popup); - - /* Make sure graphics expose events are processed before scrolling - * again - */ - while ((event = gdk_event_get_graphics_expose (shell->canvas->window))) - { - gtk_widget_event (shell->canvas, event); - - if (event->expose.count == 0) - { - gdk_event_free (event); - break; - } - - gdk_event_free (event); - } - - return TRUE; - } - - return FALSE; -} - -void -gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell) -{ - gint sx, sy; - - g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); - - sx = SCALEX (shell->gdisp, shell->gdisp->gimage->width); - sy = SCALEY (shell->gdisp, shell->gdisp->gimage->height); - - shell->gdisp->offset_x = CLAMP (shell->gdisp->offset_x, 0, - MAX (sx - shell->gdisp->disp_width, 0)); - - shell->gdisp->offset_y = CLAMP (shell->gdisp->offset_y, 0, - MAX (sy - shell->gdisp->disp_height, 0)); -} - diff --git a/app/display/gimpdisplay-scroll.h b/app/display/gimpdisplay-scroll.h deleted file mode 100644 index 482e62ad63..0000000000 --- a/app/display/gimpdisplay-scroll.h +++ /dev/null @@ -1,30 +0,0 @@ -/* 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. - */ - -#ifndef __GIMP_DISPLAY_SHELL_SCROLL_H__ -#define __GIMP_DISPLAY_SHELL_SCROLL_H__ - - -gboolean gimp_display_shell_scroll (GimpDisplayShell *shell, - gint x_offset, - gint y_offset); - -void gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell); - - -#endif /* __GIMP_DISPLAY_SHELL_SCROLL_H__ */ diff --git a/app/display/gimpdisplay.c b/app/display/gimpdisplay.c index aa6dc72347..aba1efa2d3 100644 --- a/app/display/gimpdisplay.c +++ b/app/display/gimpdisplay.c @@ -122,15 +122,6 @@ gimp_display_init (GimpDisplay *gdisp) gdisp->scale = 0; gdisp->dot_for_dot = gimprc.default_dot_for_dot; - - gdisp->offset_x = 0; - gdisp->offset_y = 0; - - gdisp->disp_width = 0; - gdisp->disp_height = 0; - gdisp->disp_xoffset = 0; - gdisp->disp_yoffset = 0; - gdisp->draw_guides = TRUE; gdisp->snap_to_guides = TRUE; @@ -281,10 +272,8 @@ gdisplay_reconnect (GimpDisplay *gdisp, gdisp->gimage->width, gdisp->gimage->height); - gimp_display_shell_update_title (GIMP_DISPLAY_SHELL (gdisp->shell)); gimp_display_shell_resize_cursor_label (GIMP_DISPLAY_SHELL (gdisp->shell)); gimp_display_shell_shrink_wrap (GIMP_DISPLAY_SHELL (gdisp->shell)); - gimp_display_shell_expose_full (GIMP_DISPLAY_SHELL (gdisp->shell)); } static gint @@ -584,7 +573,7 @@ gimp_display_paint_area (GimpDisplay *gdisp, &x1, &y1, FALSE, FALSE); gdisplay_untransform_coords (gdisp, - gdisp->disp_width, gdisp->disp_height, + shell->disp_width, shell->disp_height, &x2, &y2, FALSE, FALSE); @@ -632,11 +621,11 @@ gdisplay_transform_coords (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = (gint) (scalex * (x + offset_x) - gdisp->offset_x); - *ny = (gint) (scaley * (y + offset_y) - gdisp->offset_y); + *nx = (gint) (scalex * (x + offset_x) - shell->offset_x); + *ny = (gint) (scaley * (y + offset_y) - shell->offset_y); - *nx += gdisp->disp_xoffset; - *ny += gdisp->disp_yoffset; + *nx += shell->disp_xoffset; + *ny += shell->disp_yoffset; } void @@ -660,8 +649,8 @@ gdisplay_untransform_coords (GimpDisplay *gdisp, shell = GIMP_DISPLAY_SHELL (gdisp->shell); - x -= gdisp->disp_xoffset; - y -= gdisp->disp_yoffset; + x -= shell->disp_xoffset; + y -= shell->disp_yoffset; /* transform from screen coordinates to image coordinates */ scalex = SCALEFACTOR_X (gdisp); @@ -679,13 +668,13 @@ gdisplay_untransform_coords (GimpDisplay *gdisp, if (round) { - *nx = ROUND ((x + gdisp->offset_x) / scalex - offset_x); - *ny = ROUND ((y + gdisp->offset_y) / scaley - offset_y); + *nx = ROUND ((x + shell->offset_x) / scalex - offset_x); + *ny = ROUND ((y + shell->offset_y) / scaley - offset_y); } else { - *nx = (int) ((x + gdisp->offset_x) / scalex - offset_x); - *ny = (int) ((y + gdisp->offset_y) / scaley - offset_y); + *nx = (int) ((x + shell->offset_x) / scalex - offset_x); + *ny = (int) ((y + shell->offset_y) / scaley - offset_y); } } @@ -723,11 +712,11 @@ gdisplay_transform_coords_f (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = scalex * (x + offset_x) - gdisp->offset_x; - *ny = scaley * (y + offset_y) - gdisp->offset_y; + *nx = scalex * (x + offset_x) - shell->offset_x; + *ny = scaley * (y + offset_y) - shell->offset_y; - *nx += gdisp->disp_xoffset; - *ny += gdisp->disp_yoffset; + *nx += shell->disp_xoffset; + *ny += shell->disp_yoffset; } void @@ -750,8 +739,8 @@ gdisplay_untransform_coords_f (GimpDisplay *gdisp, shell = GIMP_DISPLAY_SHELL (gdisp->shell); - x -= gdisp->disp_xoffset; - y -= gdisp->disp_yoffset; + x -= shell->disp_xoffset; + y -= shell->disp_yoffset; /* transform from screen coordinates to gimp coordinates */ scalex = SCALEFACTOR_X (gdisp); @@ -767,8 +756,8 @@ gdisplay_untransform_coords_f (GimpDisplay *gdisp, offset_x = offset_y = 0; } - *nx = (x + gdisp->offset_x) / scalex - offset_x; - *ny = (y + gdisp->offset_y) / scaley - offset_y; + *nx = (x + shell->offset_x) / scalex - offset_x; + *ny = (y + shell->offset_y) / scaley - offset_y; } void diff --git a/app/display/gimpdisplay.h b/app/display/gimpdisplay.h index 0497bbbf12..5df383e355 100644 --- a/app/display/gimpdisplay.h +++ b/app/display/gimpdisplay.h @@ -100,15 +100,6 @@ struct _GimpDisplay gint scale; /* scale factor from original raw image */ gboolean dot_for_dot; /* is monitor resolution being ignored? */ - - gint offset_x; - gint offset_y; - - gint disp_width; /* width of drawing area */ - gint disp_height; /* height of drawing area */ - gint disp_xoffset; - gint disp_yoffset; - gboolean draw_guides; /* should the guides be drawn? */ gboolean snap_to_guides; /* should the guides be snapped to? */ diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index 5723695e50..b1bd18a63a 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -57,12 +57,12 @@ #include "gui/layer-select.h" #include "gimpdisplay.h" -#include "gimpdisplay-callbacks.h" #include "gimpdisplay-foreach.h" #include "gimpdisplay-selection.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-callbacks.h" +#include "gimpdisplayshell-scale.h" +#include "gimpdisplayshell-scroll.h" #include "devices.h" #include "gimprc.h" @@ -72,11 +72,11 @@ static void -gdisplay_redraw (GimpDisplayShell *shell, - gint x, - gint y, - gint w, - gint h) +gimp_display_shell_redraw (GimpDisplayShell *shell, + gint x, + gint y, + gint w, + gint h) { glong x1, y1, x2, y2; /* coordinate of rectangle corners */ @@ -85,10 +85,10 @@ gdisplay_redraw (GimpDisplayShell *shell, x2 = (x + w); y2 = (y + h); - x1 = CLAMP (x1, 0, shell->gdisp->disp_width); - y1 = CLAMP (y1, 0, shell->gdisp->disp_height); - x2 = CLAMP (x2, 0, shell->gdisp->disp_width); - y2 = CLAMP (y2, 0, shell->gdisp->disp_height); + x1 = CLAMP (x1, 0, shell->disp_width); + y1 = CLAMP (y1, 0, shell->disp_height); + x2 = CLAMP (x2, 0, shell->disp_width); + y2 = CLAMP (y2, 0, shell->disp_height); if ((x2 - x1) && (y2 - y1)) { @@ -100,7 +100,7 @@ gdisplay_redraw (GimpDisplayShell *shell, } static void -gdisplay_check_device_cursor (GimpDisplayShell *shell) +gimp_display_shell_check_device_cursor (GimpDisplayShell *shell) { GList *list; @@ -119,7 +119,7 @@ gdisplay_check_device_cursor (GimpDisplayShell *shell) } } -static int +static gint key_to_state (gint key) { switch (key) @@ -139,23 +139,23 @@ key_to_state (gint key) } static void -gdisplay_vscrollbar_update (GtkAdjustment *adjustment, - GimpDisplayShell *shell) +gimp_display_shell_vscrollbar_update (GtkAdjustment *adjustment, + GimpDisplayShell *shell) { - gimp_display_shell_scroll (shell, 0, (adjustment->value - shell->gdisp->offset_y)); + gimp_display_shell_scroll (shell, 0, (adjustment->value - shell->offset_y)); } static void -gdisplay_hscrollbar_update (GtkAdjustment *adjustment, - GimpDisplayShell *shell) +gimp_display_shell_hscrollbar_update (GtkAdjustment *adjustment, + GimpDisplayShell *shell) { - gimp_display_shell_scroll (shell, (adjustment->value - shell->gdisp->offset_x), 0); + gimp_display_shell_scroll (shell, (adjustment->value - shell->offset_x), 0); } gboolean -gdisplay_shell_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell) +gimp_display_shell_events (GtkWidget *widget, + GdkEvent *event, + GimpDisplayShell *shell) { switch (event->type) { @@ -173,10 +173,44 @@ gdisplay_shell_events (GtkWidget *widget, return FALSE; } +void +gimp_display_shell_canvas_realize (GtkWidget *canvas, + GimpDisplayShell *shell) +{ + GimpDisplay *gdisp; + + gdisp = shell->gdisp; + + /* create the selection object */ + gdisp->select = selection_create (canvas->window, + gdisp, + gdisp->gimage->height, + gdisp->gimage->width, + gimprc.marching_speed); + + shell->disp_width = canvas->allocation.width; + shell->disp_height = canvas->allocation.height; + + /* create GC for scrolling */ + shell->scroll_gc = gdk_gc_new (shell->canvas->window); + gdk_gc_set_exposures (shell->scroll_gc, TRUE); + + /* set up the scrollbar observers */ + g_signal_connect (G_OBJECT (shell->hsbdata), "value_changed", + G_CALLBACK (gimp_display_shell_hscrollbar_update), + shell); + g_signal_connect (G_OBJECT (shell->vsbdata), "value_changed", + G_CALLBACK (gimp_display_shell_vscrollbar_update), + shell); + + /* setup scale properly */ + gimp_display_shell_scale_setup (shell); +} + gboolean -gdisplay_canvas_events (GtkWidget *canvas, - GdkEvent *event, - GimpDisplayShell *shell) +gimp_display_shell_canvas_events (GtkWidget *canvas, + GdkEvent *event, + GimpDisplayShell *shell) { GimpDisplay *gdisp; GimpTool *active_tool; @@ -185,72 +219,53 @@ gdisplay_canvas_events (GtkWidget *canvas, GdkEventButton *bevent; GdkEventScroll *sevent; GdkEventKey *kevent; - gdouble tx = 0; - gdouble ty = 0; - guint state = 0; - gint return_val = FALSE; + gdouble tx = 0; + gdouble ty = 0; + guint state = 0; + gboolean return_val = FALSE; + gboolean update_cursor = FALSE; + static gboolean scrolling = FALSE; static gint scroll_start_x = 0; static gint scroll_start_y = 0; static guint key_signal_id = 0; - gboolean update_cursor = FALSE; if (! canvas->window) - return FALSE; + { + g_warning ("imp_display_shell_canvas_events(): called unrealized"); + return FALSE; + } gdisp = shell->gdisp; active_tool = tool_manager_get_active (gdisp->gimage->gimp); - /* If this is the first event... */ + /* FIXME */ if (! gdisp->select) { - /* create the selection object */ - gdisp->select = selection_create (shell->canvas->window, - gdisp, - gdisp->gimage->height, - gdisp->gimage->width, - gimprc.marching_speed); - - gdisp->disp_width = shell->canvas->allocation.width; - gdisp->disp_height = shell->canvas->allocation.height; - - /* create GC for scrolling */ - shell->scroll_gc = gdk_gc_new (shell->canvas->window); - gdk_gc_set_exposures (shell->scroll_gc, TRUE); - - /* set up the scrollbar observers */ - g_signal_connect (G_OBJECT (shell->hsbdata), "value_changed", - G_CALLBACK (gdisplay_hscrollbar_update), - shell); - g_signal_connect (G_OBJECT (shell->vsbdata), "value_changed", - G_CALLBACK (gdisplay_vscrollbar_update), - shell); - - /* setup scale properly */ - gimp_display_shell_scale_setup (shell); + gimp_display_shell_canvas_realize (shell->canvas, shell); } /* Find out what device the event occurred upon */ if (! gdisp->gimage->gimp->busy && devices_check_change (event)) - gdisplay_check_device_cursor (shell); + gimp_display_shell_check_device_cursor (shell); switch (event->type) { case GDK_EXPOSE: eevent = (GdkEventExpose *) event; - gdisplay_redraw (shell, - eevent->area.x, eevent->area.y, - eevent->area.width, eevent->area.height); + gimp_display_shell_redraw (shell, + eevent->area.x, eevent->area.y, + eevent->area.width, eevent->area.height); break; case GDK_CONFIGURE: - if ((gdisp->disp_width != shell->canvas->allocation.width) || - (gdisp->disp_height != shell->canvas->allocation.height)) + if ((shell->disp_width != shell->canvas->allocation.width) || + (shell->disp_height != shell->canvas->allocation.height)) { - gdisp->disp_width = shell->canvas->allocation.width; - gdisp->disp_height = shell->canvas->allocation.height; + shell->disp_width = shell->canvas->allocation.width; + shell->disp_height = shell->canvas->allocation.height; gimp_display_shell_scale_resize (shell, FALSE, FALSE); } @@ -285,6 +300,7 @@ gdisplay_canvas_events (GtkWidget *canvas, { case 1: state |= GDK_BUTTON1_MASK; + gtk_grab_add (canvas); /* This is a hack to prevent other stuff being run in the middle of @@ -317,6 +333,7 @@ gdisplay_canvas_events (GtkWidget *canvas, } /* reset the current tool if ... */ + if ((/* it has no drawable */ ! active_tool->drawable || @@ -351,15 +368,15 @@ gdisplay_canvas_events (GtkWidget *canvas, state |= GDK_BUTTON2_MASK; scrolling = TRUE; - scroll_start_x = bevent->x + gdisp->offset_x; - scroll_start_y = bevent->y + gdisp->offset_y; + scroll_start_x = bevent->x + shell->offset_x; + scroll_start_y = bevent->y + shell->offset_y; gtk_grab_add (canvas); cursor = gimp_cursor_new (GDK_FLEUR, GIMP_TOOL_CURSOR_NONE, GIMP_CURSOR_MODIFIER_NONE); - gdk_window_set_cursor (shell->canvas->window, cursor); + gdk_window_set_cursor (canvas->window, cursor); gdk_cursor_unref (cursor); } break; @@ -387,7 +404,7 @@ gdisplay_canvas_events (GtkWidget *canvas, * ugly: fuzzy_select sets busy cursors while ACTIVE. */ if (gdisp->gimage->gimp->busy && - ! (GIMP_IS_FUZZY_SELECT_TOOL (active_tool) && + ! (GIMP_IS_FUZZY_SELECT_TOOL (active_tool) && active_tool->state == ACTIVE)) return TRUE; @@ -494,79 +511,80 @@ gdisplay_canvas_events (GtkWidget *canvas, /* Ask for the pointer position, but ignore it except for cursor * handling, so motion events sync with the button press/release events */ - if (mevent->is_hint) - { #ifdef __GNUC__ #warning FIXME: replace gdk_input_window_get_pointer() #endif #if 0 + if (mevent->is_hint) + { gdk_input_window_get_pointer (canvas->window, current_device, &tx, &ty, NULL, NULL, NULL, NULL); -#endif } else { +#endif tx = mevent->x; ty = mevent->y; +#if 0 } +#endif update_cursor = TRUE; if (! shell->proximity) { shell->proximity = TRUE; - gdisplay_check_device_cursor (shell); + gimp_display_shell_check_device_cursor (shell); } - if (active_tool && (GIMP_IS_MOVE_TOOL(active_tool) || - ! gimp_image_is_empty (gdisp->gimage)) && - (mevent->state & GDK_BUTTON1_MASK)) + if ((mevent->state & GDK_BUTTON1_MASK) && + + active_tool && (GIMP_IS_MOVE_TOOL (active_tool) || + ! gimp_image_is_empty (gdisp->gimage))) { if (active_tool->state == ACTIVE) { /* if the first mouse button is down, check for automatic * scrolling... */ - if ((mevent->state & GDK_BUTTON1_MASK) && - !active_tool->scroll_lock) - { - if (mevent->x < 0 || - mevent->y < 0 || - mevent->x > gdisp->disp_width || - mevent->y > gdisp->disp_height) + if ((mevent->x < 0 || + mevent->y < 0 || + mevent->x > shell->disp_width || + mevent->y > shell->disp_height) && + ! active_tool->scroll_lock) + { + gint off_x, off_y; + + off_x = off_y = 0; + + /* The cases for scrolling */ + if (mevent->x < 0) + off_x = mevent->x; + else if (mevent->x > shell->disp_width) + off_x = mevent->x - shell->disp_width; + + if (mevent->y < 0) + off_y = mevent->y; + else if (mevent->y > shell->disp_height) + off_y = mevent->y - shell->disp_height; + + if (gimp_display_shell_scroll (shell, off_x, off_y)) { - gdouble child_x, child_y; - gint off_x, off_y; - - off_x = off_y = 0; - - /* The cases for scrolling */ - if (mevent->x < 0) - off_x = mevent->x; - else if (mevent->x > gdisp->disp_width) - off_x = mevent->x - gdisp->disp_width; - - if (mevent->y < 0) - off_y = mevent->y; - else if (mevent->y > gdisp->disp_height) - off_y = mevent->y - gdisp->disp_height; - - if (gimp_display_shell_scroll (shell, off_x, off_y)) - { #ifdef __GNUC__ #warning FIXME: replace gdk_input_window_get_pointer() #endif #if 0 - gdk_input_window_get_pointer (shell->canvas->window, mevent->deviceid, - &child_x, &child_y, - NULL, NULL, NULL, NULL); + gdouble child_x, child_y; - if (child_x == mevent->x && child_y == mevent->y) - /* Put this event back on the queue -- so it keeps scrolling */ - gdk_event_put ((GdkEvent *) mevent); + gdk_input_window_get_pointer (shell->canvas->window, mevent->deviceid, + &child_x, &child_y, + NULL, NULL, NULL, NULL); + + if (child_x == mevent->x && child_y == mevent->y) + /* Put this event back on the queue -- so it keeps scrolling */ + gdk_event_put ((GdkEvent *) mevent); #endif - } } - } + } if (active_tool->auto_snap_to) { @@ -585,9 +603,9 @@ gdisplay_canvas_events (GtkWidget *canvas, { gimp_display_shell_scroll (shell, (scroll_start_x - mevent->x - - gdisp->offset_x), + shell->offset_x), (scroll_start_y - mevent->y - - gdisp->offset_y)); + shell->offset_y)); } if (/* Should we have a tool... */ @@ -646,7 +664,7 @@ gdisplay_canvas_events (GtkWidget *canvas, case GDK_Control_L: case GDK_Control_R: state |= key_to_state (kevent->keyval); /* For all modifier keys: call the tools modifier_key_func */ - if (active_tool && !gimp_image_is_empty (gdisp->gimage)) + if (active_tool && ! gimp_image_is_empty (gdisp->gimage)) { #if 0 gdk_input_window_get_pointer (canvas->window, current_device, @@ -674,7 +692,7 @@ gdisplay_canvas_events (GtkWidget *canvas, case GDK_Control_L: case GDK_Control_R: state &= ~key_to_state (kevent->keyval); /* For all modifier keys: call the tools modifier_key_func */ - if (active_tool && !gimp_image_is_empty (gdisp->gimage)) + if (active_tool && ! gimp_image_is_empty (gdisp->gimage)) { #if 0 gdk_input_window_get_pointer (canvas->window, current_device, @@ -697,21 +715,21 @@ gdisplay_canvas_events (GtkWidget *canvas, if (gdisp->gimage->gimp->busy) return TRUE; - /* Cursor update support - * no_cursor_updating is TRUE (=1) when - * /File/Preferences.../Interface/... - * Image Windows/Disable Cursor Updating is TOGGLED ON - */ + /* cursor update support */ + if (! gimprc.no_cursor_updating) { active_tool = tool_manager_get_active (gdisp->gimage->gimp); - if (active_tool && !gimp_image_is_empty (gdisp->gimage) && - !(state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) + if (active_tool && ! gimp_image_is_empty (gdisp->gimage) && + ! (state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK))) { GdkEventMotion me; - me.x = tx; me.y = ty; + + me.x = tx; + me.y = ty; me.state = state; + gimp_tool_cursor_update (active_tool, &me, gdisp); } else if (gimp_image_is_empty (gdisp->gimage)) @@ -730,9 +748,9 @@ gdisplay_canvas_events (GtkWidget *canvas, } gboolean -gdisplay_hruler_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) +gimp_display_shell_hruler_button_press (GtkWidget *widget, + GdkEventButton *event, + GimpDisplayShell *shell) { GimpDisplay *gdisp; @@ -768,9 +786,9 @@ gdisplay_hruler_button_press (GtkWidget *widget, } gboolean -gdisplay_vruler_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) +gimp_display_shell_vruler_button_press (GtkWidget *widget, + GdkEventButton *event, + GimpDisplayShell *shell) { GimpDisplay *gdisp; @@ -806,10 +824,10 @@ gdisplay_vruler_button_press (GtkWidget *widget, } static void -gdisplay_origin_menu_position (GtkMenu *menu, - gint *x, - gint *y, - gpointer data) +gimp_display_shell_origin_menu_position (GtkMenu *menu, + gint *x, + gint *y, + gpointer data) { GtkWidget *origin; gint origin_x; @@ -830,9 +848,9 @@ gdisplay_origin_menu_position (GtkMenu *menu, } gboolean -gdisplay_origin_button_press (GtkWidget *widget, - GdkEventButton *event, - GimpDisplayShell *shell) +gimp_display_shell_origin_button_press (GtkWidget *widget, + GdkEventButton *event, + GimpDisplayShell *shell) { GimpDisplay *gdisp; @@ -842,8 +860,8 @@ gdisplay_origin_button_press (GtkWidget *widget, { gint x, y; - gdisplay_origin_menu_position (GTK_MENU (shell->ifactory->widget), - &x, &y, widget); + gimp_display_shell_origin_menu_position (GTK_MENU (shell->ifactory->widget), + &x, &y, widget); gtk_item_factory_popup_with_data (shell->ifactory, gdisp->gimage, NULL, @@ -858,9 +876,9 @@ gdisplay_origin_button_press (GtkWidget *widget, } void -gdisplay_drop_drawable (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) +gimp_display_shell_drop_drawable (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) { GimpDrawable *drawable; GimpDisplay *gdisp; @@ -966,10 +984,10 @@ gdisplay_drop_drawable (GtkWidget *widget, } static void -gdisplay_bucket_fill (GimpDisplay *gdisp, - BucketFillMode fill_mode, - guchar orig_color[], - TempBuf *orig_pat_buf) +gimp_display_shell_bucket_fill (GimpDisplay *gdisp, + BucketFillMode fill_mode, + guchar orig_color[], + TempBuf *orig_pat_buf) { GimpImage *gimage; GimpDrawable *drawable; @@ -1081,9 +1099,9 @@ gdisplay_bucket_fill (GimpDisplay *gdisp, } void -gdisplay_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) +gimp_display_shell_drop_pattern (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) { GimpDisplay *gdisp; @@ -1091,17 +1109,17 @@ gdisplay_drop_pattern (GtkWidget *widget, if (GIMP_IS_PATTERN (viewable)) { - gdisplay_bucket_fill (gdisp, - PATTERN_BUCKET_FILL, - NULL, - GIMP_PATTERN (viewable)->mask); + gimp_display_shell_bucket_fill (gdisp, + PATTERN_BUCKET_FILL, + NULL, + GIMP_PATTERN (viewable)->mask); } } void -gdisplay_drop_color (GtkWidget *widget, - const GimpRGB *drop_color, - gpointer data) +gimp_display_shell_drop_color (GtkWidget *widget, + const GimpRGB *drop_color, + gpointer data) { GimpDisplay *gdisp; guchar color[4]; @@ -1114,16 +1132,16 @@ gdisplay_drop_color (GtkWidget *widget, &color[2], &color[3]); - gdisplay_bucket_fill (gdisp, - FG_BUCKET_FILL, - color, - NULL); + gimp_display_shell_bucket_fill (gdisp, + FG_BUCKET_FILL, + color, + NULL); } void -gdisplay_drop_buffer (GtkWidget *widget, - GimpViewable *viewable, - gpointer data) +gimp_display_shell_drop_buffer (GtkWidget *widget, + GimpViewable *viewable, + gpointer data) { GimpBuffer *buffer; GimpDisplay *gdisp; diff --git a/app/display/gimpdisplayshell-callbacks.h b/app/display/gimpdisplayshell-callbacks.h index 216652984d..c462beae92 100644 --- a/app/display/gimpdisplayshell-callbacks.h +++ b/app/display/gimpdisplayshell-callbacks.h @@ -16,52 +16,55 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#ifndef __GIMP_DISPLAY_CALLBACKS_H__ -#define __GIMP_DISPLAY_CALLBACKS_H__ +#ifndef __GIMP_DISPLAY_SHELL_CALLBACKS_H__ +#define __GIMP_DISPLAY_SHELL_CALLBACKS_H__ -#define CANVAS_EVENT_MASK (GDK_EXPOSURE_MASK | \ - GDK_POINTER_MOTION_MASK | \ - GDK_POINTER_MOTION_HINT_MASK | \ - GDK_BUTTON_PRESS_MASK | \ - GDK_BUTTON_RELEASE_MASK | \ - GDK_STRUCTURE_MASK | \ - GDK_ENTER_NOTIFY_MASK | \ - GDK_LEAVE_NOTIFY_MASK | \ - GDK_KEY_PRESS_MASK | \ - GDK_KEY_RELEASE_MASK | \ - GDK_PROXIMITY_OUT_MASK) +#define GIMP_DISPLAY_SHELL_CANVAS_EVENT_MASK (GDK_EXPOSURE_MASK | \ + GDK_POINTER_MOTION_MASK | \ + GDK_POINTER_MOTION_HINT_MASK | \ + GDK_BUTTON_PRESS_MASK | \ + GDK_BUTTON_RELEASE_MASK | \ + GDK_STRUCTURE_MASK | \ + GDK_ENTER_NOTIFY_MASK | \ + GDK_LEAVE_NOTIFY_MASK | \ + GDK_KEY_PRESS_MASK | \ + GDK_KEY_RELEASE_MASK | \ + GDK_PROXIMITY_OUT_MASK) -gboolean gdisplay_shell_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell); -gboolean gdisplay_canvas_events (GtkWidget *widget, - GdkEvent *event, - GimpDisplayShell *shell); +gboolean gimp_display_shell_events (GtkWidget *widget, + GdkEvent *event, + GimpDisplayShell *shell); -gboolean gdisplay_hruler_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); -gboolean gdisplay_vruler_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); -gboolean gdisplay_origin_button_press (GtkWidget *widget, - GdkEventButton *bevent, - GimpDisplayShell *shell); +void gimp_display_shell_canvas_realize (GtkWidget *widget, + GimpDisplayShell *shell); +gboolean gimp_display_shell_canvas_events (GtkWidget *widget, + GdkEvent *event, + GimpDisplayShell *shell); -void gdisplay_drop_drawable (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -void gdisplay_drop_pattern (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); -void gdisplay_drop_color (GtkWidget *widget, - const GimpRGB *color, - gpointer data); -void gdisplay_drop_buffer (GtkWidget *widget, - GimpViewable *viewable, - gpointer data); +gboolean gimp_display_shell_hruler_button_press (GtkWidget *widget, + GdkEventButton *bevent, + GimpDisplayShell *shell); +gboolean gimp_display_shell_vruler_button_press (GtkWidget *widget, + GdkEventButton *bevent, + GimpDisplayShell *shell); +gboolean gimp_display_shell_origin_button_press (GtkWidget *widget, + GdkEventButton *bevent, + GimpDisplayShell *shell); + +void gimp_display_shell_drop_drawable (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); +void gimp_display_shell_drop_pattern (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); +void gimp_display_shell_drop_color (GtkWidget *widget, + const GimpRGB *color, + gpointer data); +void gimp_display_shell_drop_buffer (GtkWidget *widget, + GimpViewable *viewable, + gpointer data); -#endif /* __GIMP_DISPLAY_CALLBACKS_H__ */ +#endif /* __GIMP_DISPLAY_SHELL_CALLBACKS_H__ */ diff --git a/app/display/gimpdisplayshell-draw.c b/app/display/gimpdisplayshell-draw.c index 83c7c05f51..d3a845e51b 100644 --- a/app/display/gimpdisplayshell-draw.c +++ b/app/display/gimpdisplayshell-draw.c @@ -48,10 +48,10 @@ #include "gimpdisplay.h" #include "gimpdisplay-area.h" -#include "gimpdisplay-callbacks.h" -#include "gimpdisplay-render.h" #include "gimpdisplay-selection.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-callbacks.h" +#include "gimpdisplayshell-render.h" #include "gximage.h" #include "colormaps.h" @@ -176,6 +176,14 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->gdisp = NULL; shell->ifactory = NULL; + shell->offset_x = 0; + shell->offset_y = 0; + + shell->disp_width = 0; + shell->disp_height = 0; + shell->disp_xoffset = 0; + shell->disp_yoffset = 0; + shell->proximity = FALSE; shell->display_areas = NULL; @@ -406,10 +414,10 @@ gimp_display_shell_new (GimpDisplay *gdisp) /* active display callback */ g_signal_connect (G_OBJECT (shell), "button_press_event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); g_signal_connect (G_OBJECT (shell), "key_press_event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); /* dnd stuff */ @@ -420,22 +428,22 @@ gimp_display_shell_new (GimpDisplay *gdisp) GDK_ACTION_COPY); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_LAYER, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_PATTERN, - gdisplay_drop_pattern, + gimp_display_shell_drop_pattern, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_BUFFER, - gdisplay_drop_buffer, + gimp_display_shell_drop_buffer, shell); gimp_dnd_color_dest_set (GTK_WIDGET (shell), - gdisplay_drop_color, + gimp_display_shell_drop_color, shell); /* connect the "F1" help key */ @@ -546,7 +554,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); g_signal_connect (G_OBJECT (shell->origin), "button_press_event", - G_CALLBACK (gdisplay_origin_button_press), + G_CALLBACK (gimp_display_shell_origin_button_press), shell); gimp_help_set_help_data (shell->origin, NULL, "#origin_button"); @@ -565,7 +573,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->hrule)->motion_notify_event), shell->hrule); g_signal_connect (G_OBJECT (shell->hrule), "button_press_event", - G_CALLBACK (gdisplay_hruler_button_press), + G_CALLBACK (gimp_display_shell_hruler_button_press), shell); gimp_help_set_help_data (shell->hrule, NULL, "#ruler"); @@ -579,7 +587,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->vrule)->motion_notify_event), shell->vrule); g_signal_connect (G_OBJECT (shell->vrule), "button_press_event", - G_CALLBACK (gdisplay_vruler_button_press), + G_CALLBACK (gimp_display_shell_vruler_button_press), shell); gimp_help_set_help_data (shell->vrule, NULL, "#ruler"); @@ -588,16 +596,26 @@ gimp_display_shell_new (GimpDisplay *gdisp) shell->canvas = gtk_drawing_area_new (); gtk_widget_set_name (shell->canvas, "gimp-canvas"); gtk_drawing_area_size (GTK_DRAWING_AREA (shell->canvas), n_width, n_height); - gtk_widget_set_events (shell->canvas, CANVAS_EVENT_MASK); + gtk_widget_set_events (shell->canvas, GIMP_DISPLAY_SHELL_CANVAS_EVENT_MASK); gtk_widget_set_extension_events (shell->canvas, GDK_EXTENSION_EVENTS_ALL); GTK_WIDGET_SET_FLAGS (shell->canvas, GTK_CAN_FOCUS); +#if 0 + + FIXME + + g_signal_connect (G_OBJECT (shell->canvas), "realize", + G_CALLBACK (gimp_display_shell_canvas_events), + shell); +#endif + /* set the active display before doing any other canvas event processing */ g_signal_connect (G_OBJECT (shell->canvas), "event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); + g_signal_connect (G_OBJECT (shell->canvas), "event", - G_CALLBACK (gdisplay_canvas_events), + G_CALLBACK (gimp_display_shell_canvas_events), shell); /* create the contents of the lower_hbox *********************************/ @@ -651,7 +669,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) /* EEK */ gdisp->shell = GTK_WIDGET (shell); gtk_widget_realize (GTK_WIDGET (shell)); - + /* create the pixmaps ****************************************************/ if (! qmasksel_pixmap) { @@ -1194,10 +1212,10 @@ gimp_display_shell_mask_bounds (GimpDisplayShell *shell, gdisplay_transform_coords (shell->gdisp, *x2, *y2, x2, y2, 0); /* Make sure the extents are within bounds */ - *x1 = CLAMP (*x1, 0, shell->gdisp->disp_width); - *y1 = CLAMP (*y1, 0, shell->gdisp->disp_height); - *x2 = CLAMP (*x2, 0, shell->gdisp->disp_width); - *y2 = CLAMP (*y2, 0, shell->gdisp->disp_height); + *x1 = CLAMP (*x1, 0, shell->disp_width); + *y1 = CLAMP (*y1, 0, shell->disp_height); + *x2 = CLAMP (*x2, 0, shell->disp_width); + *y2 = CLAMP (*y2, 0, shell->disp_height); return TRUE; } @@ -1215,10 +1233,10 @@ gimp_display_shell_add_expose_area (GimpDisplayShell *shell, area = g_new (GimpArea, 1); - area->x1 = CLAMP (x, 0, shell->gdisp->disp_width); - area->y1 = CLAMP (y, 0, shell->gdisp->disp_height); - area->x2 = CLAMP (x + w, 0, shell->gdisp->disp_width); - area->y2 = CLAMP (y + h, 0, shell->gdisp->disp_height); + area->x1 = CLAMP (x, 0, shell->disp_width); + area->y1 = CLAMP (y, 0, shell->disp_height); + area->x2 = CLAMP (x + w, 0, shell->disp_width); + area->y2 = CLAMP (y + h, 0, shell->disp_height); shell->display_areas = gimp_display_area_list_process (shell->display_areas, area); @@ -1246,11 +1264,11 @@ gimp_display_shell_expose_guide (GimpDisplayShell *shell, switch (guide->orientation) { case ORIENTATION_HORIZONTAL: - gimp_display_shell_add_expose_area (shell, 0, y, shell->gdisp->disp_width, 1); + gimp_display_shell_add_expose_area (shell, 0, y, shell->disp_width, 1); break; case ORIENTATION_VERTICAL: - gimp_display_shell_add_expose_area (shell, x, 0, 1, shell->gdisp->disp_height); + gimp_display_shell_add_expose_area (shell, x, 0, 1, shell->disp_height); break; default: @@ -1265,8 +1283,8 @@ gimp_display_shell_expose_full (GimpDisplayShell *shell) gimp_display_shell_add_expose_area (shell, 0, 0, - shell->gdisp->disp_width, - shell->gdisp->disp_height); + shell->disp_width, + shell->disp_height); } void @@ -1431,7 +1449,8 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, gint y) { GimpImage *gimage; - gint new_cursor; + gboolean new_cursor; + gboolean flush = FALSE; gchar buffer[CURSOR_STR_LENGTH]; gint t_x; gint t_y; @@ -1455,10 +1474,19 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, if (! new_cursor) { shell->have_cursor = FALSE; - gdisplay_flush (shell->gdisp); + flush = TRUE; } } + shell->have_cursor = new_cursor; + shell->cursor_x = x; + shell->cursor_y = y; + + if (new_cursor || flush) + { + gdisplay_flush (shell->gdisp); + } + gdisplay_untransform_coords (shell->gdisp, x, y, &t_x, &t_y, FALSE, FALSE); if (t_x < 0 || @@ -1473,29 +1501,23 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, { if (shell->gdisp->dot_for_dot) { - g_snprintf (buffer, CURSOR_STR_LENGTH, - shell->cursor_format_str, "", t_x, ", ", t_y); + g_snprintf (buffer, sizeof (buffer), shell->cursor_format_str, + "", t_x, ", ", t_y); } else /* show real world units */ { gdouble unit_factor = gimp_unit_get_factor (gimage->unit); - g_snprintf (buffer, CURSOR_STR_LENGTH, shell->cursor_format_str, + g_snprintf (buffer, sizeof (buffer), shell->cursor_format_str, "", (gdouble) t_x * unit_factor / gimage->xresolution, ", ", (gdouble) t_y * unit_factor / gimage->yresolution); } + gtk_label_set_text (GTK_LABEL (shell->cursor_label), buffer); info_window_update_extended (shell->gdisp, t_x, t_y); } - - shell->have_cursor = new_cursor; - shell->cursor_x = x; - shell->cursor_y = y; - - if (new_cursor) - gdisplay_flush (shell->gdisp); } void @@ -1735,8 +1757,8 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) width = SCALEX (shell->gdisp, shell->gdisp->gimage->width); height = SCALEY (shell->gdisp, shell->gdisp->gimage->height); - disp_width = shell->gdisp->disp_width; - disp_height = shell->gdisp->disp_height; + disp_width = shell->disp_width; + disp_height = shell->disp_height; shell_width = GTK_WIDGET (shell)->allocation.width; shell_height = GTK_WIDGET (shell)->allocation.height; @@ -1789,8 +1811,8 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) border_x, border_y); #endif /* RESIZE_DEBUG */ - shell->gdisp->disp_width = width; - shell->gdisp->disp_height = height; + shell->disp_width = width; + shell->disp_height = height; allocation.width = width + border_x; allocation.height = height + border_y; @@ -1799,10 +1821,10 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) * changes because our caller has to do a full display update anyway */ g_signal_handlers_block_by_func (G_OBJECT (shell->canvas), - gdisplay_shell_events, + gimp_display_shell_events, shell); g_signal_handlers_block_by_func (G_OBJECT (shell->canvas), - gdisplay_canvas_events, + gimp_display_shell_canvas_events, shell); gtk_widget_size_allocate (GTK_WIDGET (shell), &allocation); @@ -1828,21 +1850,21 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) } g_signal_handlers_unblock_by_func (G_OBJECT (shell->canvas), - gdisplay_shell_events, + gimp_display_shell_events, shell); g_signal_handlers_unblock_by_func (G_OBJECT (shell->canvas), - gdisplay_canvas_events, + gimp_display_shell_canvas_events, shell); } /* If the width or height of the display has changed, recalculate * the display offsets... */ - if (disp_width != shell->gdisp->disp_width || - disp_height != shell->gdisp->disp_height) + if (disp_width != shell->disp_width || + disp_height != shell->disp_height) { - shell->gdisp->offset_x += (disp_width - shell->gdisp->disp_width) / 2; - shell->gdisp->offset_y += (disp_height - shell->gdisp->disp_height) / 2; + shell->offset_x += (disp_width - shell->disp_width) / 2; + shell->offset_y += (disp_height - shell->disp_height) / 2; } } @@ -1889,65 +1911,65 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, sy = SCALEY (shell->gdisp, shell->gdisp->gimage->height); /* Bounds check */ - x1 = CLAMP (x, 0, shell->gdisp->disp_width); - y1 = CLAMP (y, 0, shell->gdisp->disp_height); - x2 = CLAMP (x + w, 0, shell->gdisp->disp_width); - y2 = CLAMP (y + h, 0, shell->gdisp->disp_height); + x1 = CLAMP (x, 0, shell->disp_width); + y1 = CLAMP (y, 0, shell->disp_height); + x2 = CLAMP (x + w, 0, shell->disp_width); + y2 = CLAMP (y + h, 0, shell->disp_height); - if (y1 < shell->gdisp->disp_yoffset) + if (y1 < shell->disp_yoffset) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, x, y, - w, shell->gdisp->disp_yoffset - y); + w, shell->disp_yoffset - y); /* X X X . # . . . . */ - y1 = shell->gdisp->disp_yoffset; + y1 = shell->disp_yoffset; } - if (x1 < shell->gdisp->disp_xoffset) + if (x1 < shell->disp_xoffset) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, x, y1, - shell->gdisp->disp_xoffset - x, h); + shell->disp_xoffset - x, h); /* . . . X # . X . . */ - x1 = shell->gdisp->disp_xoffset; + x1 = shell->disp_xoffset; } - if (x2 > (shell->gdisp->disp_xoffset + sx)) + if (x2 > (shell->disp_xoffset + sx)) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, - shell->gdisp->disp_xoffset + sx, y1, - x2 - (shell->gdisp->disp_xoffset + sx), h - (y1 - y)); + shell->disp_xoffset + sx, y1, + x2 - (shell->disp_xoffset + sx), h - (y1 - y)); /* . . . . # X . . X */ - x2 = shell->gdisp->disp_xoffset + sx; + x2 = shell->disp_xoffset + sx; } - if (y2 > (shell->gdisp->disp_yoffset + sy)) + if (y2 > (shell->disp_yoffset + sy)) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, - x1, shell->gdisp->disp_yoffset + sy, - x2 - x1, y2 - (shell->gdisp->disp_yoffset + sy)); + x1, shell->disp_yoffset + sy, + x2 - x1, y2 - (shell->disp_yoffset + sy)); /* . . . . # . . X . */ - y2 = shell->gdisp->disp_yoffset + sy; + y2 = shell->disp_yoffset + sy; } /* display the image in GXIMAGE_WIDTH x GXIMAGE_HEIGHT sized chunks */ @@ -1959,14 +1981,14 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, dy = MIN (y2 - i, GXIMAGE_HEIGHT); render_image (shell->gdisp, - j - shell->gdisp->disp_xoffset, i - shell->gdisp->disp_yoffset, + j - shell->disp_xoffset, i - shell->disp_yoffset, dx, dy); #if 0 /* Invalidate the projection just after we render it! */ gimp_image_invalidate_without_render (shell->gdisp->gimage, - j - shell->gdisp->disp_xoffset, - i - shell->gdisp->disp_yoffset, + j - shell->disp_xoffset, + i - shell->disp_yoffset, dx, dy, 0, 0, 0, 0); #endif @@ -1982,8 +2004,8 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, gximage_put (shell->canvas->window, j, i, dx, dy, - shell->gdisp->offset_x, - shell->gdisp->offset_y); + shell->offset_x, + shell->offset_y); } } } diff --git a/app/display/gimpdisplayshell-draw.h b/app/display/gimpdisplayshell-draw.h index ec74f71cb0..cac2a147f1 100644 --- a/app/display/gimpdisplayshell-draw.h +++ b/app/display/gimpdisplayshell-draw.h @@ -50,6 +50,14 @@ struct _GimpDisplayShell GtkItemFactory *ifactory; + gint offset_x; /* offset of display image into raw image */ + gint offset_y; + + gint disp_width; /* width of drawing area */ + gint disp_height; /* height of drawing area */ + gint disp_xoffset; + gint disp_yoffset; + gboolean proximity; /* is a device in proximity */ GSList *display_areas; /* display areas list */ diff --git a/app/display/gimpdisplayshell-render.c b/app/display/gimpdisplayshell-render.c index 865e6168cf..f1216baab7 100644 --- a/app/display/gimpdisplayshell-render.c +++ b/app/display/gimpdisplayshell-render.c @@ -31,8 +31,8 @@ #include "core/gimpimage.h" #include "gimpdisplay.h" -#include "gimpdisplay-render.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-render.h" #include "gximage.h" #include "gimprc.h" @@ -744,8 +744,8 @@ render_image_init_info (RenderInfo *info, { info->gdisp = gdisp; info->src_tiles = gimp_image_projection (gdisp->gimage); - info->x = x + gdisp->offset_x; - info->y = y + gdisp->offset_y; + info->x = x + GIMP_DISPLAY_SHELL (gdisp->shell)->offset_x; + info->y = y + GIMP_DISPLAY_SHELL (gdisp->shell)->offset_y; info->w = w; info->h = h; info->scalex = SCALEFACTOR_X (gdisp); diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index d9396ae9fe..c18fa21e18 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -33,9 +33,9 @@ #include "gimpdisplay.h" #include "gimpdisplay-foreach.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-scale.h" +#include "gimpdisplayshell-scroll.h" #include "gimprc.h" #include "nav_window.h" @@ -69,16 +69,16 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) stepx = SCALEFACTOR_X (shell->gdisp); stepy = SCALEFACTOR_Y (shell->gdisp); - shell->hsbdata->value = shell->gdisp->offset_x; + shell->hsbdata->value = shell->offset_x; shell->hsbdata->upper = sx; - shell->hsbdata->page_size = MIN (sx, shell->gdisp->disp_width); - shell->hsbdata->page_increment = shell->gdisp->disp_width / 2; + shell->hsbdata->page_size = MIN (sx, shell->disp_width); + shell->hsbdata->page_increment = shell->disp_width / 2; shell->hsbdata->step_increment = stepx; - shell->vsbdata->value = shell->gdisp->offset_y; + shell->vsbdata->value = shell->offset_y; shell->vsbdata->upper = sy; - shell->vsbdata->page_size = MIN (sy, shell->gdisp->disp_height); - shell->vsbdata->page_increment = shell->gdisp->disp_height / 2; + shell->vsbdata->page_size = MIN (sy, shell->disp_height); + shell->vsbdata->page_increment = shell->disp_height / 2; shell->vsbdata->step_increment = stepy; gtk_adjustment_changed (shell->hsbdata); @@ -89,60 +89,60 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) hruler->lower = 0; hruler->upper = img2real (shell->gdisp, TRUE, - FUNSCALEX (shell->gdisp, shell->gdisp->disp_width)); + FUNSCALEX (shell->gdisp, shell->disp_width)); hruler->max_size = img2real (shell->gdisp, TRUE, MAX (image_width, image_height)); vruler->lower = 0; vruler->upper = img2real (shell->gdisp, FALSE, - FUNSCALEY (shell->gdisp, shell->gdisp->disp_height)); + FUNSCALEY (shell->gdisp, shell->disp_height)); vruler->max_size = img2real (shell->gdisp, FALSE, MAX (image_width, image_height)); - if (sx < shell->gdisp->disp_width) + if (sx < shell->disp_width) { - shell->gdisp->disp_xoffset = (shell->gdisp->disp_width - sx) / 2; + shell->disp_xoffset = (shell->disp_width - sx) / 2; hruler->lower -= img2real (shell->gdisp, TRUE, FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->disp_xoffset)); + (gdouble) shell->disp_xoffset)); hruler->upper -= img2real (shell->gdisp, TRUE, FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->disp_xoffset)); + (gdouble) shell->disp_xoffset)); } else { - shell->gdisp->disp_xoffset = 0; + shell->disp_xoffset = 0; hruler->lower += img2real (shell->gdisp, TRUE, FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->offset_x)); + (gdouble) shell->offset_x)); hruler->upper += img2real (shell->gdisp, TRUE, FUNSCALEX (shell->gdisp, - (gdouble) shell->gdisp->offset_x)); + (gdouble) shell->offset_x)); } - if (sy < shell->gdisp->disp_height) + if (sy < shell->disp_height) { - shell->gdisp->disp_yoffset = (shell->gdisp->disp_height - sy) / 2; + shell->disp_yoffset = (shell->disp_height - sy) / 2; vruler->lower -= img2real (shell->gdisp, FALSE, FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->disp_yoffset)); + (gdouble) shell->disp_yoffset)); vruler->upper -= img2real (shell->gdisp, FALSE, FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->disp_yoffset)); + (gdouble) shell->disp_yoffset)); } else { - shell->gdisp->disp_yoffset = 0; + shell->disp_yoffset = 0; vruler->lower += img2real (shell->gdisp, FALSE, FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->offset_y)); + (gdouble) shell->offset_y)); vruler->upper += img2real (shell->gdisp, FALSE, FUNSCALEY (shell->gdisp, - (gdouble) shell->gdisp->offset_y)); + (gdouble) shell->offset_y)); } gtk_widget_queue_draw (GTK_WIDGET (hruler)); @@ -160,9 +160,9 @@ gimp_display_shell_scale_setup (GimpDisplayShell *shell) "disp_height: %d\n" "disp_xoffset: %d\n" "disp_yoffset: %d\n\n", - shell->gdisp->offset_x, shell->gdisp->offset_y, - shell->gdisp->disp_width, shell->gdisp->disp_height, - shell->gdisp->disp_xoffset, shell->gdisp->disp_yoffset); + shell->offset_x, shell->offset_y, + shell->disp_width, shell->disp_height, + shell->disp_xoffset, shell->disp_yoffset); #endif } @@ -196,8 +196,8 @@ gimp_display_shell_scale (GimpDisplayShell *shell, scalesrc = SCALESRC (shell->gdisp); scaledest = SCALEDEST (shell->gdisp); - offset_x = shell->gdisp->offset_x + (shell->gdisp->disp_width / 2.0); - offset_y = shell->gdisp->offset_y + (shell->gdisp->disp_height / 2.0); + offset_x = shell->offset_x + (shell->disp_width / 2.0); + offset_y = shell->offset_y + (shell->disp_height / 2.0); offset_x *= ((double) scalesrc / (double) scaledest); offset_y *= ((double) scalesrc / (double) scaledest); @@ -252,14 +252,125 @@ gimp_display_shell_scale (GimpDisplayShell *shell, offset_x *= ((gdouble) scaledest / (gdouble) scalesrc); offset_y *= ((gdouble) scaledest / (gdouble) scalesrc); - shell->gdisp->offset_x = (gint) (offset_x - (shell->gdisp->disp_width / 2)); - shell->gdisp->offset_y = (gint) (offset_y - (shell->gdisp->disp_height / 2)); + shell->offset_x = (gint) (offset_x - (shell->disp_width / 2)); + shell->offset_y = (gint) (offset_y - (shell->disp_height / 2)); /* resize the display */ gimp_display_shell_scale_resize (shell, gimprc.allow_resize_windows, TRUE); } } +void +gimp_display_shell_scale_fit (GimpDisplayShell *shell) +{ + gint image_width; + gint image_height; + gdouble zoom_x; + gdouble zoom_y; + gdouble zoom_factor; + gdouble zoom_delta; + gdouble min_zoom_delta = G_MAXFLOAT; + gint scalesrc = 1; + gint scaledest = 1; + gint i; + gint best_i = 0x10; + + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + image_width = shell->gdisp->gimage->width; + image_height = shell->gdisp->gimage->height; + + if (! shell->gdisp->dot_for_dot) + { + image_width = ROUND (image_width * + gimprc.monitor_xres / + shell->gdisp->gimage->xresolution); + image_height = ROUND (image_height * + gimprc.monitor_yres / + shell->gdisp->gimage->yresolution); + } + + zoom_x = (gdouble) shell->disp_width / (gdouble) image_width; + zoom_y = (gdouble) shell->disp_height / (gdouble) image_height; + + if ((gdouble) image_height * zoom_x <= (gdouble) shell->disp_height) + { + zoom_factor = zoom_x; + } + else + { + zoom_factor = zoom_y; + } + + if (zoom_factor < 1.0) + { + for (i = 0x10; i > 0; i--) + { + scalesrc = i; + scaledest = floor ((gdouble) scalesrc * zoom_factor); + + if (scaledest < 0x1) + { + scaledest = 0x1; + } + + zoom_delta = ABS ((gdouble) scaledest / (gdouble) scalesrc - + zoom_factor); + + if (zoom_delta <= min_zoom_delta) + { + min_zoom_delta = zoom_delta; + best_i = i; + } + } + + scalesrc = best_i; + scaledest = floor ((gdouble) scalesrc * zoom_factor); + + if (scaledest < 0x1) + { + scaledest = 0x1; + } + } + else + { + for (i = 0x10; i > 0; i--) + { + scaledest = i; + scalesrc = ceil ((gdouble) scaledest / zoom_factor); + + if (scalesrc < 0x1) + { + scalesrc = 0x1; + } + + zoom_delta = ABS ((gdouble) scaledest / (gdouble) scalesrc - + zoom_factor); + + if (zoom_delta <= min_zoom_delta) + { + min_zoom_delta = zoom_delta; + best_i = i; + } + } + + scaledest = best_i; + scalesrc = ceil ((gdouble) scaledest / zoom_factor); + + if (scalesrc < 0x1) + { + scalesrc = 0x1; + } + } + + shell->gdisp->scale = (scaledest << 8) + scalesrc; + + shell->offset_x = 0; + shell->offset_y = 0; + + gimp_display_shell_scale_resize (shell, FALSE, TRUE); +} + void gimp_display_shell_scale_resize (GimpDisplayShell *shell, gboolean resize_window, diff --git a/app/display/gimpdisplayshell-scale.h b/app/display/gimpdisplayshell-scale.h index 2b5e160f7a..ab470b8c1d 100644 --- a/app/display/gimpdisplayshell-scale.h +++ b/app/display/gimpdisplayshell-scale.h @@ -27,6 +27,7 @@ void gimp_display_shell_scale_set_dot_for_dot (GimpDisplayShell *gdisp, void gimp_display_shell_scale (GimpDisplayShell *gdisp, GimpZoomType zoom_type); +void gimp_display_shell_scale_fit (GimpDisplayShell *gdisp); void gimp_display_shell_scale_resize (GimpDisplayShell *shell, gboolean resize_window, gboolean redisplay); diff --git a/app/display/gimpdisplayshell-scroll.c b/app/display/gimpdisplayshell-scroll.c index 5c74870561..0f1d907520 100644 --- a/app/display/gimpdisplayshell-scroll.c +++ b/app/display/gimpdisplayshell-scroll.c @@ -31,9 +31,9 @@ #include "gimpdisplay.h" #include "gimpdisplay-foreach.h" -#include "gimpdisplay-scale.h" -#include "gimpdisplay-scroll.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-scale.h" +#include "gimpdisplayshell-scroll.h" #include "gimprc.h" #include "nav_window.h" @@ -51,17 +51,17 @@ gimp_display_shell_scroll (GimpDisplayShell *shell, g_return_val_if_fail (GIMP_IS_DISPLAY_SHELL (shell), FALSE); - old_x = shell->gdisp->offset_x; - old_y = shell->gdisp->offset_y; + old_x = shell->offset_x; + old_y = shell->offset_y; - shell->gdisp->offset_x += x_offset; - shell->gdisp->offset_y += y_offset; + shell->offset_x += x_offset; + shell->offset_y += y_offset; gimp_display_shell_scroll_clamp_offsets (shell); /* the actual changes in offset */ - x_offset = (shell->gdisp->offset_x - old_x); - y_offset = (shell->gdisp->offset_y - old_y); + x_offset = (shell->offset_x - old_x); + y_offset = (shell->offset_y - old_y); if (x_offset || y_offset) { @@ -75,24 +75,24 @@ gimp_display_shell_scroll (GimpDisplayShell *shell, dest_y = (y_offset < 0) ? -y_offset : 0; /* reset the old values so that the tool can accurately redraw */ - shell->gdisp->offset_x = old_x; - shell->gdisp->offset_y = old_y; + shell->offset_x = old_x; + shell->offset_y = old_y; /* freeze the active tool */ tool_manager_control_active (shell->gdisp->gimage->gimp, PAUSE, shell->gdisp); /* set the offsets back to the new values */ - shell->gdisp->offset_x += x_offset; - shell->gdisp->offset_y += y_offset; + shell->offset_x += x_offset; + shell->offset_y += y_offset; gdk_draw_drawable (shell->canvas->window, shell->scroll_gc, shell->canvas->window, src_x, src_y, dest_x, dest_y, - (shell->gdisp->disp_width - abs (x_offset)), - (shell->gdisp->disp_height - abs (y_offset))); + (shell->disp_width - abs (x_offset)), + (shell->disp_height - abs (y_offset))); /* re-enable the active tool */ tool_manager_control_active (shell->gdisp->gimage->gimp, RESUME, @@ -101,23 +101,23 @@ gimp_display_shell_scroll (GimpDisplayShell *shell, /* scale the image into the exposed regions */ if (x_offset) { - src_x = (x_offset < 0) ? 0 : shell->gdisp->disp_width - x_offset; + src_x = (x_offset < 0) ? 0 : shell->disp_width - x_offset; src_y = 0; gimp_display_shell_add_expose_area (shell, src_x, src_y, abs (x_offset), - shell->gdisp->disp_height); + shell->disp_height); } if (y_offset) { src_x = 0; - src_y = (y_offset < 0) ? 0 : shell->gdisp->disp_height - y_offset; + src_y = (y_offset < 0) ? 0 : shell->disp_height - y_offset; gimp_display_shell_add_expose_area (shell, src_x, src_y, - shell->gdisp->disp_width, + shell->disp_width, abs (y_offset)); } @@ -161,10 +161,10 @@ gimp_display_shell_scroll_clamp_offsets (GimpDisplayShell *shell) sx = SCALEX (shell->gdisp, shell->gdisp->gimage->width); sy = SCALEY (shell->gdisp, shell->gdisp->gimage->height); - shell->gdisp->offset_x = CLAMP (shell->gdisp->offset_x, 0, - MAX (sx - shell->gdisp->disp_width, 0)); + shell->offset_x = CLAMP (shell->offset_x, 0, + MAX (sx - shell->disp_width, 0)); - shell->gdisp->offset_y = CLAMP (shell->gdisp->offset_y, 0, - MAX (sy - shell->gdisp->disp_height, 0)); + shell->offset_y = CLAMP (shell->offset_y, 0, + MAX (sy - shell->disp_height, 0)); } diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c index 83c7c05f51..d3a845e51b 100644 --- a/app/display/gimpdisplayshell.c +++ b/app/display/gimpdisplayshell.c @@ -48,10 +48,10 @@ #include "gimpdisplay.h" #include "gimpdisplay-area.h" -#include "gimpdisplay-callbacks.h" -#include "gimpdisplay-render.h" #include "gimpdisplay-selection.h" #include "gimpdisplayshell.h" +#include "gimpdisplayshell-callbacks.h" +#include "gimpdisplayshell-render.h" #include "gximage.h" #include "colormaps.h" @@ -176,6 +176,14 @@ gimp_display_shell_init (GimpDisplayShell *shell) shell->gdisp = NULL; shell->ifactory = NULL; + shell->offset_x = 0; + shell->offset_y = 0; + + shell->disp_width = 0; + shell->disp_height = 0; + shell->disp_xoffset = 0; + shell->disp_yoffset = 0; + shell->proximity = FALSE; shell->display_areas = NULL; @@ -406,10 +414,10 @@ gimp_display_shell_new (GimpDisplay *gdisp) /* active display callback */ g_signal_connect (G_OBJECT (shell), "button_press_event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); g_signal_connect (G_OBJECT (shell), "key_press_event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); /* dnd stuff */ @@ -420,22 +428,22 @@ gimp_display_shell_new (GimpDisplay *gdisp) GDK_ACTION_COPY); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_LAYER, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_LAYER_MASK, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_CHANNEL, - gdisplay_drop_drawable, + gimp_display_shell_drop_drawable, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_PATTERN, - gdisplay_drop_pattern, + gimp_display_shell_drop_pattern, shell); gimp_dnd_viewable_dest_set (GTK_WIDGET (shell), GIMP_TYPE_BUFFER, - gdisplay_drop_buffer, + gimp_display_shell_drop_buffer, shell); gimp_dnd_color_dest_set (GTK_WIDGET (shell), - gdisplay_drop_color, + gimp_display_shell_drop_color, shell); /* connect the "F1" help key */ @@ -546,7 +554,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK); g_signal_connect (G_OBJECT (shell->origin), "button_press_event", - G_CALLBACK (gdisplay_origin_button_press), + G_CALLBACK (gimp_display_shell_origin_button_press), shell); gimp_help_set_help_data (shell->origin, NULL, "#origin_button"); @@ -565,7 +573,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->hrule)->motion_notify_event), shell->hrule); g_signal_connect (G_OBJECT (shell->hrule), "button_press_event", - G_CALLBACK (gdisplay_hruler_button_press), + G_CALLBACK (gimp_display_shell_hruler_button_press), shell); gimp_help_set_help_data (shell->hrule, NULL, "#ruler"); @@ -579,7 +587,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) G_CALLBACK (GTK_WIDGET_GET_CLASS (shell->vrule)->motion_notify_event), shell->vrule); g_signal_connect (G_OBJECT (shell->vrule), "button_press_event", - G_CALLBACK (gdisplay_vruler_button_press), + G_CALLBACK (gimp_display_shell_vruler_button_press), shell); gimp_help_set_help_data (shell->vrule, NULL, "#ruler"); @@ -588,16 +596,26 @@ gimp_display_shell_new (GimpDisplay *gdisp) shell->canvas = gtk_drawing_area_new (); gtk_widget_set_name (shell->canvas, "gimp-canvas"); gtk_drawing_area_size (GTK_DRAWING_AREA (shell->canvas), n_width, n_height); - gtk_widget_set_events (shell->canvas, CANVAS_EVENT_MASK); + gtk_widget_set_events (shell->canvas, GIMP_DISPLAY_SHELL_CANVAS_EVENT_MASK); gtk_widget_set_extension_events (shell->canvas, GDK_EXTENSION_EVENTS_ALL); GTK_WIDGET_SET_FLAGS (shell->canvas, GTK_CAN_FOCUS); +#if 0 + + FIXME + + g_signal_connect (G_OBJECT (shell->canvas), "realize", + G_CALLBACK (gimp_display_shell_canvas_events), + shell); +#endif + /* set the active display before doing any other canvas event processing */ g_signal_connect (G_OBJECT (shell->canvas), "event", - G_CALLBACK (gdisplay_shell_events), + G_CALLBACK (gimp_display_shell_events), shell); + g_signal_connect (G_OBJECT (shell->canvas), "event", - G_CALLBACK (gdisplay_canvas_events), + G_CALLBACK (gimp_display_shell_canvas_events), shell); /* create the contents of the lower_hbox *********************************/ @@ -651,7 +669,7 @@ gimp_display_shell_new (GimpDisplay *gdisp) /* EEK */ gdisp->shell = GTK_WIDGET (shell); gtk_widget_realize (GTK_WIDGET (shell)); - + /* create the pixmaps ****************************************************/ if (! qmasksel_pixmap) { @@ -1194,10 +1212,10 @@ gimp_display_shell_mask_bounds (GimpDisplayShell *shell, gdisplay_transform_coords (shell->gdisp, *x2, *y2, x2, y2, 0); /* Make sure the extents are within bounds */ - *x1 = CLAMP (*x1, 0, shell->gdisp->disp_width); - *y1 = CLAMP (*y1, 0, shell->gdisp->disp_height); - *x2 = CLAMP (*x2, 0, shell->gdisp->disp_width); - *y2 = CLAMP (*y2, 0, shell->gdisp->disp_height); + *x1 = CLAMP (*x1, 0, shell->disp_width); + *y1 = CLAMP (*y1, 0, shell->disp_height); + *x2 = CLAMP (*x2, 0, shell->disp_width); + *y2 = CLAMP (*y2, 0, shell->disp_height); return TRUE; } @@ -1215,10 +1233,10 @@ gimp_display_shell_add_expose_area (GimpDisplayShell *shell, area = g_new (GimpArea, 1); - area->x1 = CLAMP (x, 0, shell->gdisp->disp_width); - area->y1 = CLAMP (y, 0, shell->gdisp->disp_height); - area->x2 = CLAMP (x + w, 0, shell->gdisp->disp_width); - area->y2 = CLAMP (y + h, 0, shell->gdisp->disp_height); + area->x1 = CLAMP (x, 0, shell->disp_width); + area->y1 = CLAMP (y, 0, shell->disp_height); + area->x2 = CLAMP (x + w, 0, shell->disp_width); + area->y2 = CLAMP (y + h, 0, shell->disp_height); shell->display_areas = gimp_display_area_list_process (shell->display_areas, area); @@ -1246,11 +1264,11 @@ gimp_display_shell_expose_guide (GimpDisplayShell *shell, switch (guide->orientation) { case ORIENTATION_HORIZONTAL: - gimp_display_shell_add_expose_area (shell, 0, y, shell->gdisp->disp_width, 1); + gimp_display_shell_add_expose_area (shell, 0, y, shell->disp_width, 1); break; case ORIENTATION_VERTICAL: - gimp_display_shell_add_expose_area (shell, x, 0, 1, shell->gdisp->disp_height); + gimp_display_shell_add_expose_area (shell, x, 0, 1, shell->disp_height); break; default: @@ -1265,8 +1283,8 @@ gimp_display_shell_expose_full (GimpDisplayShell *shell) gimp_display_shell_add_expose_area (shell, 0, 0, - shell->gdisp->disp_width, - shell->gdisp->disp_height); + shell->disp_width, + shell->disp_height); } void @@ -1431,7 +1449,8 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, gint y) { GimpImage *gimage; - gint new_cursor; + gboolean new_cursor; + gboolean flush = FALSE; gchar buffer[CURSOR_STR_LENGTH]; gint t_x; gint t_y; @@ -1455,10 +1474,19 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, if (! new_cursor) { shell->have_cursor = FALSE; - gdisplay_flush (shell->gdisp); + flush = TRUE; } } + shell->have_cursor = new_cursor; + shell->cursor_x = x; + shell->cursor_y = y; + + if (new_cursor || flush) + { + gdisplay_flush (shell->gdisp); + } + gdisplay_untransform_coords (shell->gdisp, x, y, &t_x, &t_y, FALSE, FALSE); if (t_x < 0 || @@ -1473,29 +1501,23 @@ gimp_display_shell_update_cursor (GimpDisplayShell *shell, { if (shell->gdisp->dot_for_dot) { - g_snprintf (buffer, CURSOR_STR_LENGTH, - shell->cursor_format_str, "", t_x, ", ", t_y); + g_snprintf (buffer, sizeof (buffer), shell->cursor_format_str, + "", t_x, ", ", t_y); } else /* show real world units */ { gdouble unit_factor = gimp_unit_get_factor (gimage->unit); - g_snprintf (buffer, CURSOR_STR_LENGTH, shell->cursor_format_str, + g_snprintf (buffer, sizeof (buffer), shell->cursor_format_str, "", (gdouble) t_x * unit_factor / gimage->xresolution, ", ", (gdouble) t_y * unit_factor / gimage->yresolution); } + gtk_label_set_text (GTK_LABEL (shell->cursor_label), buffer); info_window_update_extended (shell->gdisp, t_x, t_y); } - - shell->have_cursor = new_cursor; - shell->cursor_x = x; - shell->cursor_y = y; - - if (new_cursor) - gdisplay_flush (shell->gdisp); } void @@ -1735,8 +1757,8 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) width = SCALEX (shell->gdisp, shell->gdisp->gimage->width); height = SCALEY (shell->gdisp, shell->gdisp->gimage->height); - disp_width = shell->gdisp->disp_width; - disp_height = shell->gdisp->disp_height; + disp_width = shell->disp_width; + disp_height = shell->disp_height; shell_width = GTK_WIDGET (shell)->allocation.width; shell_height = GTK_WIDGET (shell)->allocation.height; @@ -1789,8 +1811,8 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) border_x, border_y); #endif /* RESIZE_DEBUG */ - shell->gdisp->disp_width = width; - shell->gdisp->disp_height = height; + shell->disp_width = width; + shell->disp_height = height; allocation.width = width + border_x; allocation.height = height + border_y; @@ -1799,10 +1821,10 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) * changes because our caller has to do a full display update anyway */ g_signal_handlers_block_by_func (G_OBJECT (shell->canvas), - gdisplay_shell_events, + gimp_display_shell_events, shell); g_signal_handlers_block_by_func (G_OBJECT (shell->canvas), - gdisplay_canvas_events, + gimp_display_shell_canvas_events, shell); gtk_widget_size_allocate (GTK_WIDGET (shell), &allocation); @@ -1828,21 +1850,21 @@ gimp_display_shell_shrink_wrap (GimpDisplayShell *shell) } g_signal_handlers_unblock_by_func (G_OBJECT (shell->canvas), - gdisplay_shell_events, + gimp_display_shell_events, shell); g_signal_handlers_unblock_by_func (G_OBJECT (shell->canvas), - gdisplay_canvas_events, + gimp_display_shell_canvas_events, shell); } /* If the width or height of the display has changed, recalculate * the display offsets... */ - if (disp_width != shell->gdisp->disp_width || - disp_height != shell->gdisp->disp_height) + if (disp_width != shell->disp_width || + disp_height != shell->disp_height) { - shell->gdisp->offset_x += (disp_width - shell->gdisp->disp_width) / 2; - shell->gdisp->offset_y += (disp_height - shell->gdisp->disp_height) / 2; + shell->offset_x += (disp_width - shell->disp_width) / 2; + shell->offset_y += (disp_height - shell->disp_height) / 2; } } @@ -1889,65 +1911,65 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, sy = SCALEY (shell->gdisp, shell->gdisp->gimage->height); /* Bounds check */ - x1 = CLAMP (x, 0, shell->gdisp->disp_width); - y1 = CLAMP (y, 0, shell->gdisp->disp_height); - x2 = CLAMP (x + w, 0, shell->gdisp->disp_width); - y2 = CLAMP (y + h, 0, shell->gdisp->disp_height); + x1 = CLAMP (x, 0, shell->disp_width); + y1 = CLAMP (y, 0, shell->disp_height); + x2 = CLAMP (x + w, 0, shell->disp_width); + y2 = CLAMP (y + h, 0, shell->disp_height); - if (y1 < shell->gdisp->disp_yoffset) + if (y1 < shell->disp_yoffset) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, x, y, - w, shell->gdisp->disp_yoffset - y); + w, shell->disp_yoffset - y); /* X X X . # . . . . */ - y1 = shell->gdisp->disp_yoffset; + y1 = shell->disp_yoffset; } - if (x1 < shell->gdisp->disp_xoffset) + if (x1 < shell->disp_xoffset) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, x, y1, - shell->gdisp->disp_xoffset - x, h); + shell->disp_xoffset - x, h); /* . . . X # . X . . */ - x1 = shell->gdisp->disp_xoffset; + x1 = shell->disp_xoffset; } - if (x2 > (shell->gdisp->disp_xoffset + sx)) + if (x2 > (shell->disp_xoffset + sx)) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, - shell->gdisp->disp_xoffset + sx, y1, - x2 - (shell->gdisp->disp_xoffset + sx), h - (y1 - y)); + shell->disp_xoffset + sx, y1, + x2 - (shell->disp_xoffset + sx), h - (y1 - y)); /* . . . . # X . . X */ - x2 = shell->gdisp->disp_xoffset + sx; + x2 = shell->disp_xoffset + sx; } - if (y2 > (shell->gdisp->disp_yoffset + sy)) + if (y2 > (shell->disp_yoffset + sy)) { gdk_draw_rectangle (shell->canvas->window, shell->canvas->style->bg_gc[GTK_STATE_NORMAL], TRUE, - x1, shell->gdisp->disp_yoffset + sy, - x2 - x1, y2 - (shell->gdisp->disp_yoffset + sy)); + x1, shell->disp_yoffset + sy, + x2 - x1, y2 - (shell->disp_yoffset + sy)); /* . . . . # . . X . */ - y2 = shell->gdisp->disp_yoffset + sy; + y2 = shell->disp_yoffset + sy; } /* display the image in GXIMAGE_WIDTH x GXIMAGE_HEIGHT sized chunks */ @@ -1959,14 +1981,14 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, dy = MIN (y2 - i, GXIMAGE_HEIGHT); render_image (shell->gdisp, - j - shell->gdisp->disp_xoffset, i - shell->gdisp->disp_yoffset, + j - shell->disp_xoffset, i - shell->disp_yoffset, dx, dy); #if 0 /* Invalidate the projection just after we render it! */ gimp_image_invalidate_without_render (shell->gdisp->gimage, - j - shell->gdisp->disp_xoffset, - i - shell->gdisp->disp_yoffset, + j - shell->disp_xoffset, + i - shell->disp_yoffset, dx, dy, 0, 0, 0, 0); #endif @@ -1982,8 +2004,8 @@ gimp_display_shell_display_area (GimpDisplayShell *shell, gximage_put (shell->canvas->window, j, i, dx, dy, - shell->gdisp->offset_x, - shell->gdisp->offset_y); + shell->offset_x, + shell->offset_y); } } } diff --git a/app/display/gimpdisplayshell.h b/app/display/gimpdisplayshell.h index ec74f71cb0..cac2a147f1 100644 --- a/app/display/gimpdisplayshell.h +++ b/app/display/gimpdisplayshell.h @@ -50,6 +50,14 @@ struct _GimpDisplayShell GtkItemFactory *ifactory; + gint offset_x; /* offset of display image into raw image */ + gint offset_y; + + gint disp_width; /* width of drawing area */ + gint disp_height; /* height of drawing area */ + gint disp_xoffset; + gint disp_yoffset; + gboolean proximity; /* is a device in proximity */ GSList *display_areas; /* display areas list */ diff --git a/app/display/gimpnavigationeditor.c b/app/display/gimpnavigationeditor.c index 94fa5329f4..b6205093be 100644 --- a/app/display/gimpnavigationeditor.c +++ b/app/display/gimpnavigationeditor.c @@ -38,9 +38,9 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-scroll.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scroll.h" +#include "display/gimpdisplayshell-scale.h" #include "widgets/gimpnavigationpreview.h" @@ -175,8 +175,8 @@ nav_dialog_marker_changed (GimpNavigationPreview *nav_preview, xratio = SCALEFACTOR_X (nav_dialog->gdisp); yratio = SCALEFACTOR_Y (nav_dialog->gdisp); - xoffset = x * xratio - shell->gdisp->offset_x; - yoffset = y * yratio - shell->gdisp->offset_y; + xoffset = x * xratio - shell->offset_x; + yoffset = y * yratio - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } @@ -714,17 +714,17 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, gimp_navigation_preview_set_marker (GIMP_NAVIGATION_PREVIEW (nav_dialog->new_preview), - RINT (shell->gdisp->offset_x / xratio), - RINT (shell->gdisp->offset_y / yratio), - RINT (shell->gdisp->disp_width / xratio), - RINT (shell->gdisp->disp_height / yratio)); + RINT (shell->offset_x / xratio), + RINT (shell->offset_y / yratio), + RINT (shell->disp_width / xratio), + RINT (shell->disp_height / yratio)); } - nav_dialog->dispx = shell->gdisp->offset_x * nav_dialog->ratio / xratio + 0.5; - nav_dialog->dispy = shell->gdisp->offset_y * nav_dialog->ratio/yratio + 0.5; + nav_dialog->dispx = shell->offset_x * nav_dialog->ratio / xratio + 0.5; + nav_dialog->dispy = shell->offset_y * nav_dialog->ratio/yratio + 0.5; - nav_dialog->dispwidth = (shell->gdisp->disp_width * nav_dialog->ratio) / xratio + 0.5; - nav_dialog->dispheight = (shell->gdisp->disp_height * nav_dialog->ratio) / yratio + 0.5; + nav_dialog->dispwidth = (shell->disp_width * nav_dialog->ratio) / xratio + 0.5; + nav_dialog->dispheight = (shell->disp_height * nav_dialog->ratio) / yratio + 0.5; newwidth = gimage->width; newheight = gimage->height; @@ -735,12 +735,12 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, (newwidth * gdisp->gimage->yresolution) / gdisp->gimage->xresolution; nav_dialog->dispx = - ((shell->gdisp->offset_x * + ((shell->offset_x * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ nav_dialog->dispwidth = - ((shell->gdisp->disp_width * + ((shell->disp_width * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ } @@ -1222,8 +1222,8 @@ nav_dialog_update_real_view (NavigationDialog *nav_dialog, nav_dialog->gdisp->gimage->xresolution) / nav_dialog->gdisp->gimage->yresolution) + 0.5; - xoffset = xpnt - shell->gdisp->offset_x; - yoffset = ypnt - shell->gdisp->offset_y; + xoffset = xpnt - shell->offset_x; + yoffset = ypnt - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } diff --git a/app/display/gimpnavigationview.c b/app/display/gimpnavigationview.c index 94fa5329f4..b6205093be 100644 --- a/app/display/gimpnavigationview.c +++ b/app/display/gimpnavigationview.c @@ -38,9 +38,9 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-scroll.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scroll.h" +#include "display/gimpdisplayshell-scale.h" #include "widgets/gimpnavigationpreview.h" @@ -175,8 +175,8 @@ nav_dialog_marker_changed (GimpNavigationPreview *nav_preview, xratio = SCALEFACTOR_X (nav_dialog->gdisp); yratio = SCALEFACTOR_Y (nav_dialog->gdisp); - xoffset = x * xratio - shell->gdisp->offset_x; - yoffset = y * yratio - shell->gdisp->offset_y; + xoffset = x * xratio - shell->offset_x; + yoffset = y * yratio - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } @@ -714,17 +714,17 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, gimp_navigation_preview_set_marker (GIMP_NAVIGATION_PREVIEW (nav_dialog->new_preview), - RINT (shell->gdisp->offset_x / xratio), - RINT (shell->gdisp->offset_y / yratio), - RINT (shell->gdisp->disp_width / xratio), - RINT (shell->gdisp->disp_height / yratio)); + RINT (shell->offset_x / xratio), + RINT (shell->offset_y / yratio), + RINT (shell->disp_width / xratio), + RINT (shell->disp_height / yratio)); } - nav_dialog->dispx = shell->gdisp->offset_x * nav_dialog->ratio / xratio + 0.5; - nav_dialog->dispy = shell->gdisp->offset_y * nav_dialog->ratio/yratio + 0.5; + nav_dialog->dispx = shell->offset_x * nav_dialog->ratio / xratio + 0.5; + nav_dialog->dispy = shell->offset_y * nav_dialog->ratio/yratio + 0.5; - nav_dialog->dispwidth = (shell->gdisp->disp_width * nav_dialog->ratio) / xratio + 0.5; - nav_dialog->dispheight = (shell->gdisp->disp_height * nav_dialog->ratio) / yratio + 0.5; + nav_dialog->dispwidth = (shell->disp_width * nav_dialog->ratio) / xratio + 0.5; + nav_dialog->dispheight = (shell->disp_height * nav_dialog->ratio) / yratio + 0.5; newwidth = gimage->width; newheight = gimage->height; @@ -735,12 +735,12 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, (newwidth * gdisp->gimage->yresolution) / gdisp->gimage->xresolution; nav_dialog->dispx = - ((shell->gdisp->offset_x * + ((shell->offset_x * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ nav_dialog->dispwidth = - ((shell->gdisp->disp_width * + ((shell->disp_width * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ } @@ -1222,8 +1222,8 @@ nav_dialog_update_real_view (NavigationDialog *nav_dialog, nav_dialog->gdisp->gimage->xresolution) / nav_dialog->gdisp->gimage->yresolution) + 0.5; - xoffset = xpnt - shell->gdisp->offset_x; - yoffset = ypnt - shell->gdisp->offset_y; + xoffset = xpnt - shell->offset_x; + yoffset = ypnt - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } diff --git a/app/gui/colormap-dialog.c b/app/gui/colormap-dialog.c index db6e684d9d..cbaf616f09 100644 --- a/app/gui/colormap-dialog.c +++ b/app/gui/colormap-dialog.c @@ -34,7 +34,7 @@ #include "core/gimpcontainer.h" #include "core/gimpimage.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "widgets/gimpdnd.h" diff --git a/app/gui/gui.c b/app/gui/gui.c index 6ad4b811a2..a7427fcf84 100644 --- a/app/gui/gui.c +++ b/app/gui/gui.c @@ -35,8 +35,8 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-render.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-render.h" #include "display/gximage.h" #include "widgets/gimpdialogfactory.h" diff --git a/app/gui/menus.c b/app/gui/menus.c index ae91b20b24..829e2b1953 100644 --- a/app/gui/menus.c +++ b/app/gui/menus.c @@ -512,15 +512,20 @@ static GimpItemFactoryEntry image_entries[] = /* /View */ { { N_("/View/Zoom In"), "equal", - view_zoomin_cmd_callback, 0, + view_zoom_in_cmd_callback, 0, "", GTK_STOCK_ZOOM_IN }, NULL, "view/zoom.html", NULL }, { { N_("/View/Zoom Out"), "minus", - view_zoomout_cmd_callback, 0, + view_zoom_out_cmd_callback, 0, "", GTK_STOCK_ZOOM_OUT }, NULL, "view/zoom.html", NULL }, + { { N_("/View/Zoom to Fit Window"), NULL, + view_zoom_fit_cmd_callback, 0, + "", GTK_STOCK_ZOOM_FIT }, + NULL, + "view/zoom.html", NULL }, /* /View/Zoom */ diff --git a/app/gui/preferences-dialog.c b/app/gui/preferences-dialog.c index 3faedd55ed..39b757d00d 100644 --- a/app/gui/preferences-dialog.c +++ b/app/gui/preferences-dialog.c @@ -38,7 +38,7 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "tools/tool_manager.h" diff --git a/app/gui/view-commands.c b/app/gui/view-commands.c index 20c73b4063..3e0e5b7317 100644 --- a/app/gui/view-commands.c +++ b/app/gui/view-commands.c @@ -30,9 +30,9 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplay-selection.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scale.h" #include "info-dialog.h" #include "info-window.h" @@ -49,8 +49,8 @@ void -view_zoomin_cmd_callback (GtkWidget *widget, - gpointer data) +view_zoom_in_cmd_callback (GtkWidget *widget, + gpointer data) { GimpDisplay *gdisp; return_if_no_display (gdisp, data); @@ -59,8 +59,8 @@ view_zoomin_cmd_callback (GtkWidget *widget, } void -view_zoomout_cmd_callback (GtkWidget *widget, - gpointer data) +view_zoom_out_cmd_callback (GtkWidget *widget, + gpointer data) { GimpDisplay *gdisp; return_if_no_display (gdisp, data); @@ -68,6 +68,16 @@ view_zoomout_cmd_callback (GtkWidget *widget, gimp_display_shell_scale (GIMP_DISPLAY_SHELL (gdisp->shell), GIMP_ZOOM_OUT); } +void +view_zoom_fit_cmd_callback (GtkWidget *widget, + gpointer data) +{ + GimpDisplay *gdisp; + return_if_no_display (gdisp, data); + + gimp_display_shell_scale_fit (GIMP_DISPLAY_SHELL (gdisp->shell)); +} + void view_zoom_cmd_callback (GtkWidget *widget, gpointer data, diff --git a/app/gui/view-commands.h b/app/gui/view-commands.h index acef8add06..915fa91fa7 100644 --- a/app/gui/view-commands.h +++ b/app/gui/view-commands.h @@ -20,9 +20,11 @@ #define __VIEW_COMMANDS_H__ -void view_zoomin_cmd_callback (GtkWidget *widget, +void view_zoom_in_cmd_callback (GtkWidget *widget, gpointer data); -void view_zoomout_cmd_callback (GtkWidget *widget, +void view_zoom_out_cmd_callback (GtkWidget *widget, + gpointer data); +void view_zoom_fit_cmd_callback (GtkWidget *widget, gpointer data); void view_zoom_cmd_callback (GtkWidget *widget, gpointer data, diff --git a/app/menus/menus.c b/app/menus/menus.c index ae91b20b24..829e2b1953 100644 --- a/app/menus/menus.c +++ b/app/menus/menus.c @@ -512,15 +512,20 @@ static GimpItemFactoryEntry image_entries[] = /* /View */ { { N_("/View/Zoom In"), "equal", - view_zoomin_cmd_callback, 0, + view_zoom_in_cmd_callback, 0, "", GTK_STOCK_ZOOM_IN }, NULL, "view/zoom.html", NULL }, { { N_("/View/Zoom Out"), "minus", - view_zoomout_cmd_callback, 0, + view_zoom_out_cmd_callback, 0, "", GTK_STOCK_ZOOM_OUT }, NULL, "view/zoom.html", NULL }, + { { N_("/View/Zoom to Fit Window"), NULL, + view_zoom_fit_cmd_callback, 0, + "", GTK_STOCK_ZOOM_FIT }, + NULL, + "view/zoom.html", NULL }, /* /View/Zoom */ diff --git a/app/nav_window.c b/app/nav_window.c index 94fa5329f4..b6205093be 100644 --- a/app/nav_window.c +++ b/app/nav_window.c @@ -38,9 +38,9 @@ #include "display/gimpdisplay.h" #include "display/gimpdisplay-foreach.h" -#include "display/gimpdisplay-scroll.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scroll.h" +#include "display/gimpdisplayshell-scale.h" #include "widgets/gimpnavigationpreview.h" @@ -175,8 +175,8 @@ nav_dialog_marker_changed (GimpNavigationPreview *nav_preview, xratio = SCALEFACTOR_X (nav_dialog->gdisp); yratio = SCALEFACTOR_Y (nav_dialog->gdisp); - xoffset = x * xratio - shell->gdisp->offset_x; - yoffset = y * yratio - shell->gdisp->offset_y; + xoffset = x * xratio - shell->offset_x; + yoffset = y * yratio - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } @@ -714,17 +714,17 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, gimp_navigation_preview_set_marker (GIMP_NAVIGATION_PREVIEW (nav_dialog->new_preview), - RINT (shell->gdisp->offset_x / xratio), - RINT (shell->gdisp->offset_y / yratio), - RINT (shell->gdisp->disp_width / xratio), - RINT (shell->gdisp->disp_height / yratio)); + RINT (shell->offset_x / xratio), + RINT (shell->offset_y / yratio), + RINT (shell->disp_width / xratio), + RINT (shell->disp_height / yratio)); } - nav_dialog->dispx = shell->gdisp->offset_x * nav_dialog->ratio / xratio + 0.5; - nav_dialog->dispy = shell->gdisp->offset_y * nav_dialog->ratio/yratio + 0.5; + nav_dialog->dispx = shell->offset_x * nav_dialog->ratio / xratio + 0.5; + nav_dialog->dispy = shell->offset_y * nav_dialog->ratio/yratio + 0.5; - nav_dialog->dispwidth = (shell->gdisp->disp_width * nav_dialog->ratio) / xratio + 0.5; - nav_dialog->dispheight = (shell->gdisp->disp_height * nav_dialog->ratio) / yratio + 0.5; + nav_dialog->dispwidth = (shell->disp_width * nav_dialog->ratio) / xratio + 0.5; + nav_dialog->dispheight = (shell->disp_height * nav_dialog->ratio) / yratio + 0.5; newwidth = gimage->width; newheight = gimage->height; @@ -735,12 +735,12 @@ nav_dialog_disp_area (NavigationDialog *nav_dialog, (newwidth * gdisp->gimage->yresolution) / gdisp->gimage->xresolution; nav_dialog->dispx = - ((shell->gdisp->offset_x * + ((shell->offset_x * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ nav_dialog->dispwidth = - ((shell->gdisp->disp_width * + ((shell->disp_width * gdisp->gimage->yresolution * nav_dialog->ratio) / (gdisp->gimage->xresolution * xratio)) + 0.5; /*here*/ } @@ -1222,8 +1222,8 @@ nav_dialog_update_real_view (NavigationDialog *nav_dialog, nav_dialog->gdisp->gimage->xresolution) / nav_dialog->gdisp->gimage->yresolution) + 0.5; - xoffset = xpnt - shell->gdisp->offset_x; - yoffset = ypnt - shell->gdisp->offset_y; + xoffset = xpnt - shell->offset_x; + yoffset = ypnt - shell->offset_y; gimp_display_shell_scroll (shell, xoffset, yoffset); } diff --git a/app/tools/gimpcroptool.c b/app/tools/gimpcroptool.c index ef3cd42396..a3b77b069a 100644 --- a/app/tools/gimpcroptool.c +++ b/app/tools/gimpcroptool.c @@ -744,10 +744,10 @@ gimp_crop_tool_draw (GimpDrawTool *draw) gdk_draw_line (draw->win, draw->gc, crop->x1, crop->y1, - tool->gdisp->disp_width, crop->y1); + shell->disp_width, crop->y1); gdk_draw_line (draw->win, draw->gc, crop->x1, crop->y1, - crop->x1, tool->gdisp->disp_height); + crop->x1, shell->disp_height); gdk_draw_line (draw->win, draw->gc, crop->x2, crop->y2, 0, crop->y2); @@ -793,10 +793,6 @@ crop_tool_crop_image (GimpImage *gimage, x1, y1, x2, y2, layer_only, crop_layers); - - gdisplays_shrink_wrap (gimage); - - gdisplays_flush (); } static void diff --git a/app/tools/gimpmagnifytool.c b/app/tools/gimpmagnifytool.c index 21c69a88f6..55f766ede4 100644 --- a/app/tools/gimpmagnifytool.c +++ b/app/tools/gimpmagnifytool.c @@ -28,8 +28,8 @@ #include "tools-types.h" #include "display/gimpdisplay.h" -#include "display/gimpdisplay-scale.h" #include "display/gimpdisplayshell.h" +#include "display/gimpdisplayshell-scale.h" #include "gimpmagnifytool.h" #include "tool_options.h" @@ -353,12 +353,13 @@ gimp_magnify_tool_button_release (GimpTool *tool, y2 = y1 + h; /* these change the user zoom level, so should not be changed to - * the resolution-aware scale macros -- austin */ + * the resolution-aware scale macros -- austin + */ scalesrc = SCALESRC (gdisp); scaledest = SCALEDEST (gdisp); - win_width = gdisp->disp_width; - win_height = gdisp->disp_height; + win_width = shell->disp_width; + win_height = shell->disp_height; width = (win_width * scalesrc) / scaledest; height = (win_height * scalesrc) / scaledest; @@ -381,10 +382,10 @@ gimp_magnify_tool_button_release (GimpTool *tool, gdisp->scale = (scaledest << 8) + scalesrc; - gdisp->offset_x = (scaledest * ((x1 + x2) / 2)) / scalesrc - - (win_width / 2); - gdisp->offset_y = (scaledest * ((y1 + y2) / 2)) / scalesrc - - (win_height / 2); + shell->offset_x = ((scaledest * ((x1 + x2) / 2)) / scalesrc - + (win_width / 2)); + shell->offset_y = ((scaledest * ((y1 + y2) / 2)) / scalesrc - + (win_height / 2)); /* resize the image */ gimp_display_shell_scale_resize (shell, gimprc.allow_resize_windows, TRUE); diff --git a/app/tools/gimpmovetool.c b/app/tools/gimpmovetool.c index 357d0963f7..0f504bab61 100644 --- a/app/tools/gimpmovetool.c +++ b/app/tools/gimpmovetool.c @@ -357,7 +357,7 @@ move_tool_button_release (GimpTool *tool, &x1, &y1, FALSE, FALSE); gdisplay_untransform_coords (gdisp, - gdisp->disp_width, gdisp->disp_height, + shell->disp_width, shell->disp_height, &x2, &y2, FALSE, FALSE); diff --git a/app/tools/gimpselectiontool.c b/app/tools/gimpselectiontool.c index 62aecd0a1e..a0bda9d216 100644 --- a/app/tools/gimpselectiontool.c +++ b/app/tools/gimpselectiontool.c @@ -251,15 +251,13 @@ gimp_selection_tool_update_op_state (GimpSelectionTool *selection_tool, layer = gimp_image_pick_correlate_layer (gdisp->gimage, tx, ty); floating_sel = gimp_image_floating_sel (gdisp->gimage); - if (state & GDK_MOD1_MASK && - !gimage_mask_is_empty (gdisp->gimage)) + if ((state & GDK_MOD1_MASK) && ! gimage_mask_is_empty (gdisp->gimage)) { - selection_tool->op = SELECTION_MOVE_MASK; /* move just the selection mask */ + selection_tool->op = SELECTION_MOVE_MASK; /* move the selection mask */ } - else if (!(state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && - layer && + else if (! (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK)) && layer && (layer == floating_sel || - (gimage_mask_value (gdisp->gimage, x, y) && + (gimage_mask_value (gdisp->gimage, tx, ty) && floating_sel == NULL))) { selection_tool->op = SELECTION_MOVE; /* move the selection */ diff --git a/app/tools/gimptransformtool.c b/app/tools/gimptransformtool.c index f592a4984c..8a4e2d392d 100644 --- a/app/tools/gimptransformtool.c +++ b/app/tools/gimptransformtool.c @@ -602,7 +602,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, TransformUndo *tu; PathUndo *pundo; gboolean new_layer; - gint i, x, y; + gint i; gimp_set_busy (gdisp->gimage->gimp); @@ -683,11 +683,17 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, */ tool->preserve = FALSE; +#ifdef __GNUC__ +#warning FIXME: investigate why display update was done here +#endif +#if 0 /* Flush the gdisplays */ if (gdisp->disp_xoffset || gdisp->disp_yoffset) { - x = shell->canvas->allocation.width; - y = shell->canvas->allocation.height; + gint x, y; + + x = shell->disp_width; + y = shell->disp_height; if (gdisp->disp_yoffset) { @@ -710,6 +716,7 @@ gimp_transform_tool_doit (GimpTransformTool *gt_tool, gdisp->disp_width, gdisp->disp_height); } } +#endif gimp_unset_busy (gdisp->gimage->gimp); diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c index e7b5ca9976..ea0fe06ab0 100644 --- a/app/tools/tool_manager.c +++ b/app/tools/tool_manager.c @@ -234,7 +234,13 @@ tool_manager_select_tool (Gimp *gimp, tool_manager = tool_manager_get (gimp); if (tool_manager->active_tool) - g_object_unref (G_OBJECT (tool_manager->active_tool)); + { + tool_manager_control_active (gimp, + HALT, + tool_manager->active_tool->gdisp); + + g_object_unref (G_OBJECT (tool_manager->active_tool)); + } tool_manager->active_tool = tool; } diff --git a/app/undo.c b/app/undo.c index 46cc7a837b..01b7c2f2a2 100644 --- a/app/undo.c +++ b/app/undo.c @@ -391,13 +391,11 @@ pop_stack (GimpImage *gimage, GSList **unstack_ptr, UndoState state) { - Undo *object; - GSList *stack; - GSList *tmp; - gint status = 0; - gint in_group = 0; - gint x, y; - GimpDisplay *gdisp; + Undo *object; + GSList *stack; + GSList *tmp; + gboolean status = FALSE; + gboolean in_group = FALSE; /* Keep popping until we pop a valid object * or get to the end of a group if we're in one @@ -407,21 +405,26 @@ pop_stack (GimpImage *gimage, stack = *stack_ptr; object = (Undo *) stack->data; + if (object->group_boundary) { - in_group = (in_group) ? 0 : 1; + in_group = ! in_group; + if (in_group) gimage->undo_levels += (state == UNDO) ? -1 : 1; - if (status && !in_group) - status = 1; + if (status && ! in_group) + status = TRUE; else - status = 0; + status = FALSE; } else { TRC (("undo_pop: %s\n", undo_type_to_name (object->type))); - status = (* object->pop_func) (gimage, state, object->type, + + status = (* object->pop_func) (gimage, + state, + object->type, object->data); if (object->dirties_image) @@ -437,19 +440,26 @@ pop_stack (GimpImage *gimage, } } - if (!in_group) + if (! in_group) gimage->undo_levels += (state == UNDO) ? -1 : 1; } - *unstack_ptr = g_slist_prepend (*unstack_ptr, (gpointer) object); + *unstack_ptr = g_slist_prepend (*unstack_ptr, object); tmp = stack; *stack_ptr = g_slist_next (*stack_ptr); tmp->next = NULL; g_slist_free (tmp); - if (status && !in_group) + if (status && ! in_group) { +#ifdef __GNUC__ +#warning FIXME: investigate why display update was done here +#endif +#if 0 + GimpDisplay *gdisp; + gint x, y; + /* Flush any image updates and displays */ gdisp = gimp_context_get_display (gimp_get_user_context (gimage->gimp)); @@ -488,8 +498,7 @@ pop_stack (GimpImage *gimage, } } } - - gdisplays_flush (); +#endif /* If the mode_changed flag was set */ if (mode_changed) @@ -527,6 +536,8 @@ pop_stack (GimpImage *gimage, gimp_image_undo_event (gimage, (state == UNDO)? UNDO_POPPED : UNDO_REDO); + gdisplays_flush (); + return TRUE; } } diff --git a/app/widgets/gimpcolormapeditor.c b/app/widgets/gimpcolormapeditor.c index db6e684d9d..cbaf616f09 100644 --- a/app/widgets/gimpcolormapeditor.c +++ b/app/widgets/gimpcolormapeditor.c @@ -34,7 +34,7 @@ #include "core/gimpcontainer.h" #include "core/gimpimage.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "widgets/gimpdnd.h" diff --git a/app/widgets/gimpitemfactory.c b/app/widgets/gimpitemfactory.c index ae91b20b24..829e2b1953 100644 --- a/app/widgets/gimpitemfactory.c +++ b/app/widgets/gimpitemfactory.c @@ -512,15 +512,20 @@ static GimpItemFactoryEntry image_entries[] = /* /View */ { { N_("/View/Zoom In"), "equal", - view_zoomin_cmd_callback, 0, + view_zoom_in_cmd_callback, 0, "", GTK_STOCK_ZOOM_IN }, NULL, "view/zoom.html", NULL }, { { N_("/View/Zoom Out"), "minus", - view_zoomout_cmd_callback, 0, + view_zoom_out_cmd_callback, 0, "", GTK_STOCK_ZOOM_OUT }, NULL, "view/zoom.html", NULL }, + { { N_("/View/Zoom to Fit Window"), NULL, + view_zoom_fit_cmd_callback, 0, + "", GTK_STOCK_ZOOM_FIT }, + NULL, + "view/zoom.html", NULL }, /* /View/Zoom */ diff --git a/app/widgets/gimppreview.c b/app/widgets/gimppreview.c index b26bf41b71..f6ec6a50ce 100644 --- a/app/widgets/gimppreview.c +++ b/app/widgets/gimppreview.c @@ -44,7 +44,7 @@ #include "core/gimppattern.h" #include "core/gimptoolinfo.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "gimpbrushpreview.h" #include "gimpbufferpreview.h" diff --git a/app/widgets/gimppreviewrenderer.c b/app/widgets/gimppreviewrenderer.c index b26bf41b71..f6ec6a50ce 100644 --- a/app/widgets/gimppreviewrenderer.c +++ b/app/widgets/gimppreviewrenderer.c @@ -44,7 +44,7 @@ #include "core/gimppattern.h" #include "core/gimptoolinfo.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "gimpbrushpreview.h" #include "gimpbufferpreview.h" diff --git a/app/widgets/gimpview.c b/app/widgets/gimpview.c index b26bf41b71..f6ec6a50ce 100644 --- a/app/widgets/gimpview.c +++ b/app/widgets/gimpview.c @@ -44,7 +44,7 @@ #include "core/gimppattern.h" #include "core/gimptoolinfo.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "gimpbrushpreview.h" #include "gimpbufferpreview.h" diff --git a/app/widgets/gimpviewrenderer.c b/app/widgets/gimpviewrenderer.c index b26bf41b71..f6ec6a50ce 100644 --- a/app/widgets/gimpviewrenderer.c +++ b/app/widgets/gimpviewrenderer.c @@ -44,7 +44,7 @@ #include "core/gimppattern.h" #include "core/gimptoolinfo.h" -#include "display/gimpdisplay-render.h" +#include "display/gimpdisplayshell-render.h" #include "gimpbrushpreview.h" #include "gimpbufferpreview.h" diff --git a/po/ChangeLog b/po/ChangeLog index 0b5aaa0e2a..8e50d93f39 100644 --- a/po/ChangeLog +++ b/po/ChangeLog @@ -1,3 +1,7 @@ +2001-11-02 Michael Natterer + + * POTFILES.in: gimpdisplay-callbacks.c -> gimpdisplayshell-callbacks. + 2001-10-31 Michael Natterer * POTFILES.in: updated. diff --git a/po/POTFILES.in b/po/POTFILES.in index 0c9ab24771..8d5cd5252e 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -34,9 +34,9 @@ app/core/gimppalette.c app/core/gimppattern.c app/core/gimpunit.c -app/display/gimpdisplay-callbacks.c app/display/gimpdisplay.c app/display/gimpdisplayshell.c +app/display/gimpdisplayshell-callbacks.c app/file/file-open.c app/file/file-save.c