gimp/app/scale.c

278 lines
7.1 KiB
C
Raw Normal View History

1997-11-25 06:05:25 +08:00
/* 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.
1997-11-25 06:05:25 +08:00
*/
#include "config.h"
1997-11-25 06:05:25 +08:00
#include <stdlib.h>
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#include <gtk/gtk.h>
#include "apptypes.h"
#include "tools/gimptool.h"
Made the tool system work again and integrated it back with the 2001-02-21 Michael Natterer <mitch@gimp.org> Made the tool system work again and integrated it back with the GimpContext. It's a hack between old, new and freshly hacked stuff. There are still lots of warnings but at least we can switch tools again. * app/tools/Makefile.am * app/tools/gimptoolinfo.[ch]: resurrected as real object. The GimpToolInfo objects are derived from GimpData, which gives us the tool icon stuff for free. Also, we need a list of _objects_ which is allocated all the time. All tools are required to have a "register" function which registers themselves with the list of GimpToolInfo objects which is maintained by the tool manager. * app/tools/tool.[ch]: made a real GtkObject with properly named functions out of it. The former "active_tool_control" is of course not the default implementation of the tool's "control" method but a hack _around_ it, so it went to the tool manager. * app/tools/color_picker.[ch] * app/tools/measure.[ch]: ditto. Added "register" functions and "destroy" implementations so the tools go away after use. * app/tools/tool_manager.[ch]: badly hacked at the moment to keep both the list of class structures _and_ the tool info list. * app/tools/tools.c: call the tools' register functions. * app/gimpcontext.[ch]: store a pointer to a GimpToolInfo object as "active_tool" in the context, so we're independent of tools being allocated or not. It's treated just like a brush or pattern now. * app/gimpdnd.[ch]: made tool DND work like all other DND types. * app/devices.[ch]: also here: the tool is just a normal data object now, resulting in removal of lots of code. * app/commands.c * app/context_manager.c: updated the tool select and context stuff to work again. * app/toolbox.c: removed the old pixmap buttons and put GimpPreviews inside the tool buttons. Still needs an own preview type to look nice. * app/disp_callbacks.c * app/about_dialog.c * app/app_procs.c * app/appenums.h * app/apptypes.h * app/gimage.c * app/gimppalette.c * app/gimppreview.c * app/gimprc.c * app/info_window.c * app/menus.c * app/palette_select.h * app/scale.c * app/scroll.c: lots of changes to make it work again.
2001-02-21 20:18:09 +08:00
#include "tools/tool_manager.h"
1997-11-25 06:05:25 +08:00
#include "gdisplay.h"
#include "gdisplay_ops.h"
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
#include "gimpimage.h"
1997-11-25 06:05:25 +08:00
#include "gimprc.h"
#include "nav_window.h"
1997-11-25 06:05:25 +08:00
#include "scale.h"
app/Makefile.am app/channel_pvt.h app/drawable_pvt.h app/gdisplayF.h 2000-12-29 Michael Natterer <mitch@gimp.org> * app/Makefile.am * app/channel_pvt.h * app/drawable_pvt.h * app/gdisplayF.h * app/gimpdrawableP.h * app/gimpimageP.h * app/layer_pvt.h * app/toolsF.h: removed these files. * app/apptypes.h * tools/pdbgen/enums.pl: added tons of opaque typedefs and enums. * tools/pdbgen/pdb/brush_select.pdb * tools/pdbgen/pdb/brushes.pdb * tools/pdbgen/pdb/channel.pdb * tools/pdbgen/pdb/color.pdb * tools/pdbgen/pdb/convert.pdb * tools/pdbgen/pdb/display.pdb * tools/pdbgen/pdb/drawable.pdb * tools/pdbgen/pdb/fileops.pdb * tools/pdbgen/pdb/gradient_select.pdb * tools/pdbgen/pdb/gradients.pdb * tools/pdbgen/pdb/help.pdb * tools/pdbgen/pdb/image.pdb * tools/pdbgen/pdb/layer.pdb * tools/pdbgen/pdb/pattern_select.pdb * tools/pdbgen/pdb/patterns.pdb * tools/pdbgen/pdb/selection.pdb * tools/pdbgen/pdb/tools.pdb * app/*: chainsaw #include cleanup: - Never (never!!) include stuff in header files except where we need access to structures' contents (like derived objects). - Added prototypes and proper formating in many files. - The #include order in *all* *.c files is as follows: #include "config.h" #include <system stuff> #include <gtk/gtk.h> #include "apptypes.h" #include "gimp stuff" #include "libgimp stuff" #include "libgimp/gimpintl.h" By following this scheme we can easily see a file's dependencies from it's #include's and can grep for the inclusion to find out where a file is used. * tools/pdbgen/app.pl: changed to follow the include scheme above. * libgimp/Makefile.am * libgimp/gimpuitypes.h: new file, included from libgimp/gimpui.h and from app/apptypes.h. * libgimp/gimpcolorbutton.[ch] * libgimp/gimpdialog.[ch] * libgimp/gimphelpui.[ch] * libgimp/gimpparasite.[ch] * libgimp/gimppatheditor.[ch] * libgimp/gimpprotocol.c * libgimp/gimpquerybox.[ch] * libgimp/gimpsizeentry.[ch] * libgimp/gimptypes.h * libgimp/gimpui.h * libgimp/gimpunit.h * libgimp/gimpunitmenu.[ch] * libgimp/gimpwidgets.[ch]: changed accordingly. * plug-ins/FractalExplorer/Dialogs.c * plug-ins/gdyntext/message_window.c * plug-ins/imagemap/imap_default_dialog.c * plug-ins/imagemap/imap_file.c: these files used to include "libgimp/gimpui.h" without including "libgimp/gimp.h". This is no longer possible because the libgimpui headers don't inlcude "libgimp/gimpunit.h" any more.
2000-12-29 23:22:01 +08:00
1997-11-25 06:05:25 +08:00
void
bounds_checking (GDisplay *gdisp)
{
gint sx, sy;
1997-11-25 06:05:25 +08:00
sx = SCALEX (gdisp, gdisp->gimage->width);
sy = SCALEY (gdisp, gdisp->gimage->height);
1997-11-25 06:05:25 +08:00
gdisp->offset_x = CLAMP (gdisp->offset_x, 0,
LOWPASS (sx - gdisp->disp_width));
1997-11-25 06:05:25 +08:00
gdisp->offset_y = CLAMP (gdisp->offset_y, 0,
LOWPASS (sy - gdisp->disp_height));
1997-11-25 06:05:25 +08:00
}
void
resize_display (GDisplay *gdisp,
gboolean resize_window,
gboolean redisplay)
1997-11-25 06:05:25 +08:00
{
/* freeze the active tool */
tool_manager_control_active (PAUSE, gdisp);
1997-11-25 06:05:25 +08:00
if (resize_window)
gdisplay_shrink_wrap (gdisp);
bounds_checking (gdisp);
setup_scale (gdisp);
if (resize_window || redisplay)
1997-11-25 06:05:25 +08:00
{
gdisplay_expose_full (gdisp);
gdisplays_flush ();
/* title may have changed if it includes the zoom ratio */
gdisplay_update_title (gdisp);
1997-11-25 06:05:25 +08:00
}
/* re-enable the active tool */
tool_manager_control_active (RESUME, gdisp);
1997-11-25 06:05:25 +08:00
}
void
shrink_wrap_display (GDisplay *gdisp)
{
/* freeze the active tool */
tool_manager_control_active (PAUSE, gdisp);
1997-11-25 06:05:25 +08:00
gdisplay_shrink_wrap (gdisp);
bounds_checking (gdisp);
setup_scale (gdisp);
gdisplay_expose_full (gdisp);
gdisplays_flush ();
/* re-enable the active tool */
tool_manager_control_active (RESUME, gdisp);
1997-11-25 06:05:25 +08:00
}
void
change_scale (GDisplay *gdisp,
GimpZoomType zoom_type)
1997-11-25 06:05:25 +08:00
{
guchar scalesrc, scaledest;
gdouble offset_x, offset_y;
glong sx, sy;
1997-11-25 06:05:25 +08:00
/* user zoom control, so resolution versions not needed -- austin */
scalesrc = SCALESRC (gdisp);
scaledest = SCALEDEST (gdisp);
1997-11-25 06:05:25 +08:00
offset_x = gdisp->offset_x + (gdisp->disp_width / 2.0);
offset_y = gdisp->offset_y + (gdisp->disp_height / 2.0);
1997-11-25 06:05:25 +08:00
offset_x *= ((double) scalesrc / (double) scaledest);
offset_y *= ((double) scalesrc / (double) scaledest);
switch (zoom_type)
1997-11-25 06:05:25 +08:00
{
case GIMP_ZOOM_IN:
1997-11-25 06:05:25 +08:00
if (scalesrc > 1)
scalesrc--;
else
if (scaledest < 0x10)
scaledest++;
else
return;
1997-11-25 06:05:25 +08:00
break;
case GIMP_ZOOM_OUT:
1997-11-25 06:05:25 +08:00
if (scaledest > 1)
scaledest--;
else
if (scalesrc < 0x10)
scalesrc++;
else
return;
1997-11-25 06:05:25 +08:00
break;
default:
scalesrc = zoom_type % 100;
1997-11-25 06:05:25 +08:00
if (scalesrc < 1)
scalesrc = 1;
else if (scalesrc > 0x10)
scalesrc = 0x10;
scaledest = zoom_type / 100;
1997-11-25 06:05:25 +08:00
if (scaledest < 1)
scaledest = 1;
else if (scaledest > 0x10)
scaledest = 0x10;
break;
}
sx = (gdisp->gimage->width * scaledest) / scalesrc;
sy = (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)
{
gdisp->scale = (scaledest << 8) + scalesrc;
/* set the offsets */
offset_x *= ((double) scaledest / (double) scalesrc);
offset_y *= ((double) scaledest / (double) scalesrc);
gdisp->offset_x = (int) (offset_x - (gdisp->disp_width / 2));
gdisp->offset_y = (int) (offset_y - (gdisp->disp_height / 2));
/* resize the image */
resize_display (gdisp, allow_resize_windows, TRUE);
}
}
/* 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 (GDisplay *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;
}
1997-11-25 06:05:25 +08:00
void
setup_scale (GDisplay *gdisp)
{
GtkRuler *hruler;
GtkRuler *vruler;
gfloat sx, sy;
gfloat stepx, stepy;
1997-11-25 06:05:25 +08:00
sx = SCALEX (gdisp, gdisp->gimage->width);
sy = SCALEY (gdisp, gdisp->gimage->height);
stepx = SCALEFACTOR_X (gdisp);
stepy = SCALEFACTOR_Y (gdisp);
1997-11-25 06:05:25 +08:00
gdisp->hsbdata->value = gdisp->offset_x;
gdisp->hsbdata->upper = sx;
gdisp->hsbdata->page_size = MIN (sx, gdisp->disp_width);
gdisp->hsbdata->page_increment = (gdisp->disp_width / 2);
gdisp->hsbdata->step_increment = stepx;
1997-11-25 06:05:25 +08:00
gdisp->vsbdata->value = gdisp->offset_y;
gdisp->vsbdata->upper = sy;
gdisp->vsbdata->page_size = MIN (sy, gdisp->disp_height);
gdisp->vsbdata->page_increment = (gdisp->disp_height / 2);
gdisp->vsbdata->step_increment = stepy;
1997-11-25 06:05:25 +08:00
gtk_signal_emit_by_name (GTK_OBJECT (gdisp->hsbdata), "changed");
gtk_signal_emit_by_name (GTK_OBJECT (gdisp->vsbdata), "changed");
hruler = GTK_RULER (gdisp->hrule);
vruler = GTK_RULER (gdisp->vrule);
hruler->lower = 0;
hruler->upper = img2real (gdisp, TRUE, FUNSCALEX (gdisp, gdisp->disp_width));
hruler->max_size = img2real (gdisp, TRUE, MAX (gdisp->gimage->width,
gdisp->gimage->height));
1997-11-25 06:05:25 +08:00
vruler->lower = 0;
vruler->upper = img2real(gdisp, FALSE, FUNSCALEY(gdisp, gdisp->disp_height));
vruler->max_size = img2real (gdisp, FALSE, MAX (gdisp->gimage->width,
gdisp->gimage->height));
1997-11-25 06:05:25 +08:00
if (sx < gdisp->disp_width)
{
gdisp->disp_xoffset = (gdisp->disp_width - sx) / 2;
hruler->lower -= img2real(gdisp, TRUE,
FUNSCALEX (gdisp, (double) gdisp->disp_xoffset));
hruler->upper -= img2real(gdisp, TRUE,
FUNSCALEX (gdisp, (double) gdisp->disp_xoffset));
1997-11-25 06:05:25 +08:00
}
else
{
gdisp->disp_xoffset = 0;
hruler->lower += img2real (gdisp, TRUE,
FUNSCALEX (gdisp, (double) gdisp->offset_x));
hruler->upper += img2real (gdisp, TRUE,
FUNSCALEX (gdisp, (double) gdisp->offset_x));
1997-11-25 06:05:25 +08:00
}
if (sy < gdisp->disp_height)
{
gdisp->disp_yoffset = (gdisp->disp_height - sy) / 2;
vruler->lower -= img2real(gdisp, FALSE,
FUNSCALEY (gdisp, (double) gdisp->disp_yoffset));
vruler->upper -= img2real(gdisp, FALSE,
FUNSCALEY (gdisp, (double) gdisp->disp_yoffset));
1997-11-25 06:05:25 +08:00
}
else
{
gdisp->disp_yoffset = 0;
vruler->lower += img2real (gdisp, FALSE,
FUNSCALEY (gdisp, (double) gdisp->offset_y));
vruler->upper += img2real (gdisp, FALSE,
FUNSCALEY (gdisp, (double) gdisp->offset_y));
1997-11-25 06:05:25 +08:00
}
gtk_widget_queue_draw (GTK_WIDGET (hruler));
gtk_widget_queue_draw (GTK_WIDGET (vruler));
nav_window_update_window_marker (gdisp->window_nav_dialog);
1997-11-25 06:05:25 +08:00
}