Generalize the default Fixed: Aspect ratio option setting code so that it
2007-09-01 Martin Nordholts <martinn@svn.gnome.org> * app/tools/gimpcroptool.c (gimp_crop_tool_update_default_fixed_ratio_options): Generalize the default Fixed: Aspect ratio option setting code so that it can later be used for Fixed: Size as well, and move it to * app/tools/gimprectangletool.[ch] (gimp_rectangle_tool_pending_size_set) (gimp_rectangle_tool_constraint_size_set): and use these two new functions instead. svn path=/trunk/; revision=23435
This commit is contained in:

committed by
Martin Nordholts

parent
8624241dd7
commit
63fbdc2600
13
ChangeLog
13
ChangeLog
@ -1,3 +1,16 @@
|
||||
2007-09-01 Martin Nordholts <martinn@svn.gnome.org>
|
||||
|
||||
* app/tools/gimpcroptool.c
|
||||
(gimp_crop_tool_update_default_fixed_ratio_options):
|
||||
Generalize the default Fixed: Aspect ratio option setting code
|
||||
so that it can later be used for Fixed: Size as well, and move
|
||||
it to
|
||||
|
||||
* app/tools/gimprectangletool.[ch]
|
||||
(gimp_rectangle_tool_pending_size_set)
|
||||
(gimp_rectangle_tool_constraint_size_set): and use these two new
|
||||
functions instead.
|
||||
|
||||
2007-08-31 Simon Budig <simon@gimp.org>
|
||||
|
||||
* plug-ins/script-fu/tinyscheme/scheme.[ch]
|
||||
|
@ -342,14 +342,13 @@ gimp_crop_tool_execute (GimpRectangleTool *rectangle,
|
||||
* Sets the default aspect numerator/denominator to that of the current
|
||||
* layer/image/pending crop rectangle.
|
||||
*/
|
||||
static void gimp_crop_tool_update_default_fixed_ratio_options (GimpCropTool *crop_tool,
|
||||
gboolean ignore_pending)
|
||||
static void
|
||||
gimp_crop_tool_update_default_fixed_ratio_options (GimpCropTool *crop_tool,
|
||||
gboolean ignore_pending)
|
||||
{
|
||||
GimpTool *tool;
|
||||
GimpRectangleTool *rectangle_tool;
|
||||
GimpRectangleOptions *rectangle_options;
|
||||
gdouble default_numerator;
|
||||
gdouble default_denominator;
|
||||
|
||||
tool = GIMP_TOOL (crop_tool);
|
||||
rectangle_tool = GIMP_RECTANGLE_TOOL (tool);
|
||||
@ -357,74 +356,18 @@ static void gimp_crop_tool_update_default_fixed_ratio_options (GimpCropTool *cro
|
||||
|
||||
if (tool->display != NULL && !ignore_pending)
|
||||
{
|
||||
gint crop_rectangle_width;
|
||||
gint crop_rectangle_height;
|
||||
|
||||
/* There exists a pending crop rectangle, set default aspect ratio to the
|
||||
* same aspect ratio of the rectangle.
|
||||
*/
|
||||
|
||||
gimp_rectangle_tool_get_rectangle_size (rectangle_tool,
|
||||
&crop_rectangle_width,
|
||||
&crop_rectangle_height);
|
||||
|
||||
default_numerator = MAX (crop_rectangle_width, 1.0);
|
||||
default_denominator = MAX (crop_rectangle_height, 1.0);
|
||||
gimp_rectangle_tool_pending_size_set (rectangle_tool,
|
||||
G_OBJECT (rectangle_options),
|
||||
"default-aspect-numerator",
|
||||
"default-aspect-denominator");
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpRectangleConstraint constraint;
|
||||
GimpContext *gimp_context;
|
||||
GimpImage *image;
|
||||
|
||||
/* There exist no rectangle, set defaults */
|
||||
|
||||
gimp_context = gimp_get_user_context (tool->tool_info->gimp);
|
||||
image = gimp_context_get_image (gimp_context);
|
||||
|
||||
if (image == NULL)
|
||||
{
|
||||
default_numerator = 1.0;
|
||||
default_denominator = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
constraint = gimp_rectangle_tool_get_constraint (rectangle_tool);
|
||||
|
||||
switch (constraint)
|
||||
{
|
||||
case GIMP_RECTANGLE_CONSTRAIN_DRAWABLE:
|
||||
{
|
||||
GimpItem *item = GIMP_ITEM (gimp_image_get_active_layer (image));
|
||||
|
||||
if (item == NULL)
|
||||
{
|
||||
default_numerator = 1.0;
|
||||
default_denominator = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
default_numerator = gimp_item_width (item);
|
||||
default_denominator = gimp_item_height (item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RECTANGLE_CONSTRAIN_IMAGE:
|
||||
default:
|
||||
{
|
||||
default_numerator = image->width;
|
||||
default_denominator = image->height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
gimp_rectangle_tool_constraint_size_set (rectangle_tool,
|
||||
G_OBJECT (rectangle_options),
|
||||
"default-aspect-numerator",
|
||||
"default-aspect-denominator");
|
||||
}
|
||||
|
||||
g_object_set (rectangle_options,
|
||||
"default-aspect-numerator", default_numerator,
|
||||
"default-aspect-denominator", default_denominator,
|
||||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -29,11 +29,14 @@
|
||||
|
||||
#include "tools-types.h"
|
||||
|
||||
#include "core/gimp.h"
|
||||
#include "core/gimpchannel.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpcontext.h"
|
||||
#include "core/gimpimage-crop.h"
|
||||
#include "core/gimppickable.h"
|
||||
#include "core/gimpimage.h"
|
||||
#include "core/gimpmarshal.h"
|
||||
#include "core/gimppickable.h"
|
||||
#include "core/gimptoolinfo.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
#include "display/gimpdisplayshell.h"
|
||||
@ -455,6 +458,104 @@ gimp_rectangle_tool_get_press_coords (GimpRectangleTool *rectangle,
|
||||
*pressy_ptr = private->pressy;
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_rectangle_tool_pending_size_set_option:
|
||||
* @width_property: Option property to set to pending rectangle width.
|
||||
* @height_property: Option property to set to pending rectangle height.
|
||||
*
|
||||
* Sets specified rectangle tool options properties to the width and
|
||||
* height of the current pending rectangle.
|
||||
*/
|
||||
void
|
||||
gimp_rectangle_tool_pending_size_set (GimpRectangleTool *rectangle_tool,
|
||||
GObject *object,
|
||||
const gchar *width_property,
|
||||
const gchar *height_property)
|
||||
{
|
||||
GimpRectangleToolPrivate *private;
|
||||
|
||||
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rectangle_tool));
|
||||
g_return_if_fail (width_property != NULL);
|
||||
g_return_if_fail (height_property != NULL);
|
||||
|
||||
private = gimp_rectangle_tool_get_private (rectangle_tool);
|
||||
|
||||
g_object_set (object,
|
||||
width_property, MAX ((double)(private->x2 - private->x1), 1.0),
|
||||
height_property, MAX ((double)(private->y2 - private->y1), 1.0),
|
||||
NULL);
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_rectangle_tool_constraint_size_set_option:
|
||||
* @width_property: Option property to set to current constraint width.
|
||||
* @height_property: Option property to set to current constraint height.
|
||||
*
|
||||
* Sets specified rectangle tool options properties to the width and
|
||||
* height of the current contraint size.
|
||||
*/
|
||||
void
|
||||
gimp_rectangle_tool_constraint_size_set (GimpRectangleTool *rectangle_tool,
|
||||
GObject *object,
|
||||
const gchar *width_property,
|
||||
const gchar *height_property)
|
||||
{
|
||||
GimpContext *gimp_context;
|
||||
GimpImage *image;
|
||||
GimpTool *tool;
|
||||
gdouble width;
|
||||
gdouble height;
|
||||
|
||||
tool = GIMP_TOOL (rectangle_tool);
|
||||
gimp_context = gimp_get_user_context (tool->tool_info->gimp);
|
||||
image = gimp_context_get_image (gimp_context);
|
||||
|
||||
if (image == NULL)
|
||||
{
|
||||
width = 1.0;
|
||||
height = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
GimpRectangleConstraint constraint;
|
||||
|
||||
constraint = gimp_rectangle_tool_get_constraint (rectangle_tool);
|
||||
|
||||
switch (constraint)
|
||||
{
|
||||
case GIMP_RECTANGLE_CONSTRAIN_DRAWABLE:
|
||||
{
|
||||
GimpItem *item = GIMP_ITEM (gimp_image_get_active_layer (image));
|
||||
|
||||
if (item == NULL)
|
||||
{
|
||||
width = 1.0;
|
||||
height = 1.0;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = gimp_item_width (item);
|
||||
height = gimp_item_height (item);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GIMP_RECTANGLE_CONSTRAIN_IMAGE:
|
||||
default:
|
||||
{
|
||||
width = image->width;
|
||||
height = image->height;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
g_object_set (object,
|
||||
width_property, width,
|
||||
height_property, height,
|
||||
NULL);
|
||||
}
|
||||
|
||||
void
|
||||
gimp_rectangle_tool_set_property (GObject *object,
|
||||
guint property_id,
|
||||
@ -2148,24 +2249,6 @@ gimp_rectangle_tool_set_function (GimpRectangleTool *rectangle,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gimp_rectangle_tool_get_rectangle_size (GimpRectangleTool *rectangle,
|
||||
gint *width,
|
||||
gint *height)
|
||||
{
|
||||
GimpRectangleToolPrivate *private;
|
||||
|
||||
g_return_if_fail (GIMP_IS_RECTANGLE_TOOL (rectangle));
|
||||
|
||||
private = GIMP_RECTANGLE_TOOL_GET_PRIVATE (rectangle);
|
||||
|
||||
if (width != NULL)
|
||||
*width = private->x2 - private->x1;
|
||||
|
||||
if (height != NULL)
|
||||
*height = private->y2 - private->y1;
|
||||
}
|
||||
|
||||
static void
|
||||
gimp_rectangle_tool_rectangle_changed (GimpRectangleTool *rectangle)
|
||||
{
|
||||
|
@ -129,12 +129,17 @@ GimpRectangleConstraint gimp_rectangle_tool_get_constraint
|
||||
GimpRectangleFunction gimp_rectangle_tool_get_function (GimpRectangleTool *rectangle);
|
||||
void gimp_rectangle_tool_set_function (GimpRectangleTool *rectangle,
|
||||
GimpRectangleFunction function);
|
||||
void gimp_rectangle_tool_get_rectangle_size (GimpRectangleTool *rectangle,
|
||||
gint *width,
|
||||
gint *height);
|
||||
void gimp_rectangle_tool_get_press_coords (GimpRectangleTool *rectangle,
|
||||
gint *pressx_ptr,
|
||||
gint *pressy_ptr);
|
||||
void gimp_rectangle_tool_pending_size_set (GimpRectangleTool *rectangle,
|
||||
GObject *object,
|
||||
const gchar *width_property,
|
||||
const gchar *height_property);
|
||||
void gimp_rectangle_tool_constraint_size_set (GimpRectangleTool *rectangle,
|
||||
GObject *object,
|
||||
const gchar *width_property,
|
||||
const gchar *height_property);
|
||||
|
||||
|
||||
/* convenience functions */
|
||||
|
Reference in New Issue
Block a user