Commit ca493e0d authored by Dave Neary's avatar Dave Neary Committed by David Neary

Added the GimpImageScaleCheckType enum and used it in



2003-12-08  Dave Neary  <bolsh@gimp.org>

        * app/core/core-enums.h:
        * app/core/gimpimage-scale.[ch]: Added the GimpImageScaleCheckType
        enum and used it in gimp_image_scale_check() which used to be
        gimp_image_check_scaling().

        * app/gui/image_commands.c: Used the above when checking
        scaling parameters to display a message if the image is too big
        or too small after scaling. Closes bug #21028.
parent a0469696
2003-12-08 Dave Neary <bolsh@gimp.org>
* app/core/core-enums.h:
* app/core/gimpimage-scale.[ch]: Added the GimpImageScaleCheckType
enum and used it in gimp_image_scale_check() which used to be
gimp_image_check_scaling().
* app/gui/image_commands.c: Used the above when checking
scaling parameters to display a message if the image is too big
or too small after scaling. Closes bug #21028.
2003-12-08 Michael Natterer <mitch@gimp.org>
* tools/pdbgen/pdb/image.pdb: renamed PDB function
......@@ -20,10 +20,14 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimputils.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "config/gimpguiconfig.h"
#include "core/core-enums.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
......@@ -83,14 +87,17 @@ typedef struct
/* local functions */
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data);
static void image_scale_implement (ImageResize *image_scale);
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data);
static void image_scale_implement (ImageResize *image_scale);
static void image_scale_warn (ImageResize *image_scale,
const gchar *warning_title,
const gchar *warning_message);
/* public functions */
......@@ -483,40 +490,62 @@ image_scale_callback (GtkWidget *widget,
gpointer data)
{
ImageResize *image_scale = data;
gchar *warning_message;
g_assert (image_scale != NULL);
g_assert (image_scale->gimage != NULL);
gtk_widget_set_sensitive (image_scale->resize->resize_shell, FALSE);
if (gimp_image_check_scaling (image_scale->gimage,
image_scale->resize->width,
image_scale->resize->height))
GimpImageScaleCheckType scale_check =
gimp_image_scale_check (image_scale->gimage,
image_scale->resize->width,
image_scale->resize->height);
switch (scale_check)
{
image_scale_implement (image_scale);
gtk_widget_destroy (image_scale->resize->resize_shell);
}
else
{
GtkWidget *dialog;
dialog =
gimp_query_boolean_box (_("Layer Too Small"),
image_scale->resize->resize_shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_DIALOG_QUESTION,
_("The chosen image size will shrink "
"some layers completely away. "
"Is this what you want?"),
GTK_STOCK_OK, GTK_STOCK_CANCEL,
G_OBJECT (image_scale->resize->resize_shell),
"destroy",
image_scale_warn_callback,
image_scale);
gtk_widget_show (dialog);
case GIMP_SCALE_TOO_BIG:
{
gchar *size_str;
gchar *max_size_str;
size_str = gimp_memsize_to_string (gimp_object_get_memsize
(GIMP_OBJECT (image_scale->gimage), NULL)
* image_scale->resize->ratio_x
* image_scale->resize->ratio_y);
max_size_str = gimp_memsize_to_string
(GIMP_GUI_CONFIG (image_scale->gimage->gimp->config)
->max_new_image_size);
warning_message = g_strdup_printf (
_("You are trying to create an image with "
"a size of %s.\n\n"
"Choose OK to create this image anyway.\n"
"Choose Cancel if you did not intend to "
"create such a large image.\n\n"
"To prevent this dialog from appearing, "
"increase the \"Maximum Image Size\" "
"setting (currently %s) in the "
"Preferences dialog."),
size_str, max_size_str);
image_scale_warn (image_scale,
_("Image exceeds maximum image size"),
warning_message);
break;
}
case GIMP_SCALE_TOO_SMALL:
warning_message = _("The chosen image size will shrink "
"some layers completely away. "
"Is this what you want?");
image_scale_warn (image_scale,
_("Layer Too Small"),
warning_message);
break;
case GIMP_SCALE_OK:
/* If all is well, return directly after scaling image. */
image_scale_implement (image_scale);
gtk_widget_destroy (image_scale->resize->resize_shell);
break;
}
}
static void
......@@ -526,7 +555,8 @@ image_scale_warn_callback (GtkWidget *widget,
{
ImageResize *image_scale = data;
if (do_scale) /* User doesn't mind losing layers... */
if (do_scale) /* User doesn't mind losing layers or
* creating huge image... */
{
image_scale_implement (image_scale);
......@@ -538,6 +568,27 @@ image_scale_warn_callback (GtkWidget *widget,
}
}
static void image_scale_warn (ImageResize *image_scale,
const gchar *warning_title,
const gchar *warning_message)
{
GtkWidget *dialog;
dialog =
gimp_query_boolean_box (warning_title,
image_scale->resize->resize_shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_DIALOG_QUESTION,
warning_message,
GTK_STOCK_OK, GTK_STOCK_CANCEL,
G_OBJECT (image_scale->resize->resize_shell),
"destroy",
image_scale_warn_callback,
image_scale);
gtk_widget_show (dialog);
}
static void
image_scale_implement (ImageResize *image_scale)
{
......
......@@ -581,5 +581,11 @@ typedef enum /*< skip >*/
GIMP_OFFSET_TRANSPARENT
} GimpOffsetType;
typedef enum /*< pdb-skip, skip >*/
{
GIMP_SCALE_OK,
GIMP_SCALE_TOO_SMALL,
GIMP_SCALE_TOO_BIG
} GimpImageScaleCheckType;
#endif /* __CORE_ENUMS_H__ */
......@@ -32,6 +32,8 @@
#include "gimplayer-floating-sel.h"
#include "gimplist.h"
#include "config/gimpguiconfig.h"
#include "gimp-intl.h"
......@@ -190,25 +192,42 @@ gimp_image_scale (GimpImage *gimage,
}
/**
* gimp_image_check_scaling:
* gimp_image_scale_check:
* @gimage: A #GimpImage.
* @new_width: The new width.
* @new_height: The new height.
* Returns: #GimpImageScaleCheckType
*
* Inventory the layer list in gimage and return #TRUE if, after
* scaling, they all retain positive x and y pixel dimensions.
* Inventory the layer list in gimage and check that it may be
* scaled to @new_height and @new_width without problems.
*
* Return value: #TRUE if scaling the image will shrink none of it's
* layers completely away.
* Return value: #GIMP_SCALE_OK if scaling the image will shrink none
* of its layers completely away, and the new image size
* is smaller than the maximum specified in the
* preferences.
* #GIMP_SCALE_TOO_SMALL if scaling would remove some
* existing layers.
* #GIMP_SCALE_TOO_BIG if the new image size would
* exceed the maximum specified in the preferences.
**/
gboolean
gimp_image_check_scaling (const GimpImage *gimage,
gint new_width,
gint new_height)
GimpImageScaleCheckType
gimp_image_scale_check (const GimpImage *gimage,
gint new_width,
gint new_height)
{
GList *list;
glong new_size;
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), GIMP_SCALE_TOO_SMALL);
new_size = gimp_object_get_memsize
(GIMP_OBJECT (gimage), NULL)
* (gdouble) new_width / gimp_image_get_width (gimage)
* (gdouble) new_height / gimp_image_get_height (gimage);
g_return_val_if_fail (GIMP_IS_IMAGE (gimage), FALSE);
if (new_size >
GIMP_GUI_CONFIG (gimage->gimp->config)->max_new_image_size)
return GIMP_SCALE_TOO_BIG;
for (list = GIMP_LIST (gimage->layers)->list;
list;
......@@ -217,8 +236,8 @@ gimp_image_check_scaling (const GimpImage *gimage,
GimpItem *item = list->data;
if (! gimp_item_check_scaling (item, new_width, new_height))
return FALSE;
return GIMP_SCALE_TOO_SMALL;
}
return TRUE;
return GIMP_SCALE_OK;
}
......@@ -20,16 +20,17 @@
#define __GIMP_IMAGE_SCALE_H__
void gimp_image_scale (GimpImage *gimage,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type,
GimpProgressFunc progress_func,
gpointer progress_data);
void gimp_image_scale (GimpImage *gimage,
gint new_width,
gint new_height,
GimpInterpolationType interpolation_type,
GimpProgressFunc progress_func,
gpointer progress_data);
gboolean gimp_image_check_scaling (const GimpImage *gimage,
gint new_width,
gint new_height);
GimpImageScaleCheckType
gimp_image_scale_check (const GimpImage *gimage,
gint new_width,
gint new_height);
#endif /* __GIMP_IMAGE_SCALE_H__ */
......@@ -20,10 +20,14 @@
#include <gtk/gtk.h>
#include "libgimpbase/gimputils.h"
#include "libgimpwidgets/gimpwidgets.h"
#include "gui-types.h"
#include "config/gimpguiconfig.h"
#include "core/core-enums.h"
#include "core/gimp.h"
#include "core/gimpchannel.h"
#include "core/gimpcontext.h"
......@@ -83,14 +87,17 @@ typedef struct
/* local functions */
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data);
static void image_scale_implement (ImageResize *image_scale);
static void image_resize_callback (GtkWidget *widget,
gpointer data);
static void image_scale_callback (GtkWidget *widget,
gpointer data);
static void image_scale_warn_callback (GtkWidget *widget,
gboolean do_scale,
gpointer data);
static void image_scale_implement (ImageResize *image_scale);
static void image_scale_warn (ImageResize *image_scale,
const gchar *warning_title,
const gchar *warning_message);
/* public functions */
......@@ -483,40 +490,62 @@ image_scale_callback (GtkWidget *widget,
gpointer data)
{
ImageResize *image_scale = data;
gchar *warning_message;
g_assert (image_scale != NULL);
g_assert (image_scale->gimage != NULL);
gtk_widget_set_sensitive (image_scale->resize->resize_shell, FALSE);
if (gimp_image_check_scaling (image_scale->gimage,
image_scale->resize->width,
image_scale->resize->height))
GimpImageScaleCheckType scale_check =
gimp_image_scale_check (image_scale->gimage,
image_scale->resize->width,
image_scale->resize->height);
switch (scale_check)
{
image_scale_implement (image_scale);
gtk_widget_destroy (image_scale->resize->resize_shell);
}
else
{
GtkWidget *dialog;
dialog =
gimp_query_boolean_box (_("Layer Too Small"),
image_scale->resize->resize_shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_DIALOG_QUESTION,
_("The chosen image size will shrink "
"some layers completely away. "
"Is this what you want?"),
GTK_STOCK_OK, GTK_STOCK_CANCEL,
G_OBJECT (image_scale->resize->resize_shell),
"destroy",
image_scale_warn_callback,
image_scale);
gtk_widget_show (dialog);
case GIMP_SCALE_TOO_BIG:
{
gchar *size_str;
gchar *max_size_str;
size_str = gimp_memsize_to_string (gimp_object_get_memsize
(GIMP_OBJECT (image_scale->gimage), NULL)
* image_scale->resize->ratio_x
* image_scale->resize->ratio_y);
max_size_str = gimp_memsize_to_string
(GIMP_GUI_CONFIG (image_scale->gimage->gimp->config)
->max_new_image_size);
warning_message = g_strdup_printf (
_("You are trying to create an image with "
"a size of %s.\n\n"
"Choose OK to create this image anyway.\n"
"Choose Cancel if you did not intend to "
"create such a large image.\n\n"
"To prevent this dialog from appearing, "
"increase the \"Maximum Image Size\" "
"setting (currently %s) in the "
"Preferences dialog."),
size_str, max_size_str);
image_scale_warn (image_scale,
_("Image exceeds maximum image size"),
warning_message);
break;
}
case GIMP_SCALE_TOO_SMALL:
warning_message = _("The chosen image size will shrink "
"some layers completely away. "
"Is this what you want?");
image_scale_warn (image_scale,
_("Layer Too Small"),
warning_message);
break;
case GIMP_SCALE_OK:
/* If all is well, return directly after scaling image. */
image_scale_implement (image_scale);
gtk_widget_destroy (image_scale->resize->resize_shell);
break;
}
}
static void
......@@ -526,7 +555,8 @@ image_scale_warn_callback (GtkWidget *widget,
{
ImageResize *image_scale = data;
if (do_scale) /* User doesn't mind losing layers... */
if (do_scale) /* User doesn't mind losing layers or
* creating huge image... */
{
image_scale_implement (image_scale);
......@@ -538,6 +568,27 @@ image_scale_warn_callback (GtkWidget *widget,
}
}
static void image_scale_warn (ImageResize *image_scale,
const gchar *warning_title,
const gchar *warning_message)
{
GtkWidget *dialog;
dialog =
gimp_query_boolean_box (warning_title,
image_scale->resize->resize_shell,
gimp_standard_help_func,
GIMP_HELP_IMAGE_SCALE_WARNING,
GTK_STOCK_DIALOG_QUESTION,
warning_message,
GTK_STOCK_OK, GTK_STOCK_CANCEL,
G_OBJECT (image_scale->resize->resize_shell),
"destroy",
image_scale_warn_callback,
image_scale);
gtk_widget_show (dialog);
}
static void
image_scale_implement (ImageResize *image_scale)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment