added a GimpSizeBox as a replacement for the InfoDialog widgets. Needs

2006-04-03  Sven Neumann  <sven@gimp.org>

	* app/tools/gimpscaletool.c: added a GimpSizeBox as a replacement
	for the InfoDialog widgets. Needs more work ...
This commit is contained in:
Sven Neumann 2006-04-03 07:50:06 +00:00 committed by Sven Neumann
parent 5666cd6bcc
commit 4a8ee7f392
3 changed files with 49 additions and 262 deletions

View File

@ -1,3 +1,8 @@
2006-04-03 Sven Neumann <sven@gimp.org>
* app/tools/gimpscaletool.c: added a GimpSizeBox as a replacement
for the InfoDialog widgets. Needs more work ...
2006-04-03 Sven Neumann <sven@gimp.org>
* desktop/Makefile.am: added an install hook that touches the

View File

@ -33,6 +33,7 @@
#include "core/gimpunit.h"
#include "widgets/gimphelp-ids.h"
#include "widgets/gimpsizebox.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
@ -46,21 +47,18 @@
/* local function prototypes */
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_dialog (GimpTransformTool *tr_tool);
static void gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool);
static void gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_motion (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
GimpDisplay *display);
static void gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_unit_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_aspect_changed (GtkWidget *widget,
GimpTransformTool *tr_tool);
static void gimp_scale_tool_size_notify (GtkWidget *box,
GParamSpec *pspec,
GimpTransformTool *tr_tool);
G_DEFINE_TYPE (GimpScaleTool, gimp_scale_tool, GIMP_TYPE_TRANSFORM_TOOL);
@ -113,157 +111,28 @@ static void
gimp_scale_tool_dialog (GimpTransformTool *tr_tool)
{
GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
GtkWidget *table;
table = gtk_table_new (5, 2, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (table), 6);
gtk_table_set_row_spacings (GTK_TABLE (table), 2);
gtk_table_set_col_spacings (GTK_TABLE (table), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (tr_tool->dialog)->vbox), table,
scale->box = g_object_new (GIMP_TYPE_SIZE_BOX, NULL);
gtk_container_set_border_width (GTK_CONTAINER (scale->box), 6);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG (tr_tool->dialog)->vbox), scale->box,
FALSE, FALSE, 0);
gtk_widget_show (table);
gtk_widget_show (scale->box);
#if 0
GtkWidget *spinbutton;
info_dialog_add_label (tr_tool->info_dialog,
_("Original Width:"),
scale->orig_width_buf);
info_dialog_add_label (tr_tool->info_dialog,
_("Height:"),
scale->orig_height_buf);
spinbutton = info_dialog_add_spinbutton (tr_tool->info_dialog,
_("Current width:"),
NULL, -1, 1, 1, 10, 1, 1, 2,
NULL, NULL);
scale->sizeentry = info_dialog_add_sizeentry (tr_tool->info_dialog,
_("Current height:"),
scale->size_vals, 1,
GIMP_UNIT_PIXEL, "%a",
TRUE, TRUE, FALSE,
GIMP_SIZE_ENTRY_UPDATE_SIZE,
G_CALLBACK (gimp_scale_tool_size_changed),
tr_tool);
g_signal_connect (scale->sizeentry, "unit-changed",
G_CALLBACK (gimp_scale_tool_unit_changed),
g_signal_connect (scale->box, "notify",
G_CALLBACK (gimp_scale_tool_size_notify),
tr_tool);
gimp_size_entry_add_field (GIMP_SIZE_ENTRY (scale->sizeentry),
GTK_SPIN_BUTTON (spinbutton), NULL);
info_dialog_add_label (tr_tool->info_dialog,
_("Scale ratio X:"),
scale->x_ratio_buf);
info_dialog_add_label (tr_tool->info_dialog,
_("Scale ratio Y:"),
scale->y_ratio_buf);
spinbutton = info_dialog_add_spinbutton (tr_tool->info_dialog,
_("Aspect Ratio:"),
&scale->aspect_ratio_val,
0, 65536, 0.01, 0.1, 1, 0.5, 2,
G_CALLBACK (gimp_scale_tool_aspect_changed),
tr_tool);
gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
1, 4);
gtk_table_set_row_spacing (GTK_TABLE (tr_tool->info_dialog->info_table),
2, 0);
#endif
}
static void
gimp_scale_tool_dialog_update (GimpTransformTool *tr_tool)
{
#if 0
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
GimpTransformOptions *options;
Gimp *gimp;
gdouble ratio_x, ratio_y;
gint x1, y1, x2, y2, x3, y3, x4, y4;
GimpUnit unit;
gdouble unit_factor;
gchar format_buf[16];
gint width = (gint) tr_tool->trans_info[X1] - (gint) tr_tool->trans_info[X0];
gint height = (gint) tr_tool->trans_info[Y1] - (gint) tr_tool->trans_info[Y0];
static GimpUnit label_unit = GIMP_UNIT_PIXEL;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
unit = gimp_size_entry_get_unit (GIMP_SIZE_ENTRY (scale->sizeentry));
/* Find original sizes */
x1 = tr_tool->x1;
y1 = tr_tool->y1;
x2 = tr_tool->x2;
y2 = tr_tool->y2;
if (unit != GIMP_UNIT_PERCENT)
label_unit = unit;
gimp = tool->tool_info->gimp;
unit_factor = _gimp_unit_get_factor (gimp, label_unit);
if (label_unit) /* unit != GIMP_UNIT_PIXEL */
{
g_snprintf (format_buf, sizeof (format_buf), "%%.%df %s",
_gimp_unit_get_digits (gimp, label_unit) + 1,
_gimp_unit_get_symbol (gimp, label_unit));
g_snprintf (scale->orig_width_buf, MAX_INFO_BUF, format_buf,
(x2 - x1) * unit_factor / tool->display->image->xresolution);
g_snprintf (scale->orig_height_buf, MAX_INFO_BUF, format_buf,
(y2 - y1) * unit_factor / tool->display->image->yresolution);
}
else /* unit == GIMP_UNIT_PIXEL */
{
g_snprintf (scale->orig_width_buf, MAX_INFO_BUF, "%d", x2 - x1);
g_snprintf (scale->orig_height_buf, MAX_INFO_BUF, "%d", y2 - y1);
}
/* Find current sizes */
x3 = (gint) tr_tool->trans_info[X0];
y3 = (gint) tr_tool->trans_info[Y0];
x4 = (gint) tr_tool->trans_info[X1];
y4 = (gint) tr_tool->trans_info[Y1];
scale->size_vals[0] = x4 - x3;
scale->size_vals[1] = y4 - y3;
ratio_x = ratio_y = 0.0;
if (x2 - x1)
ratio_x = (double) (x4 - x3) / (double) (x2 - x1);
if (y2 - y1)
ratio_y = (double) (y4 - y3) / (double) (y2 - y1);
/* Detecting initial update, aspect_ratio reset */
if (ratio_x == 1 && ratio_y == 1)
scale->aspect_ratio_val = 0.0;
/* Only when one or the two options are disabled, is necessary to
* update the value Taking care of the initial update too
*/
if (! options->constrain_1 ||
! options->constrain_2 ||
scale->aspect_ratio_val == 0 )
{
scale->aspect_ratio_val =
((tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
(tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0]));
}
g_snprintf (scale->x_ratio_buf, sizeof (scale->x_ratio_buf),
"%0.2f", ratio_x);
g_snprintf (scale->y_ratio_buf, sizeof (scale->y_ratio_buf),
"%0.2f", ratio_y);
info_dialog_update (tr_tool->info_dialog);
#endif
g_object_set (GIMP_SCALE_TOOL (tr_tool)->box,
"width", width,
"height", height,
NULL);
gtk_widget_show (tr_tool->dialog);
}
@ -274,55 +143,18 @@ gimp_scale_tool_prepare (GimpTransformTool *tr_tool,
{
GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
scale->size_vals[0] = tr_tool->x2 - tr_tool->x1;
scale->size_vals[1] = tr_tool->y2 - tr_tool->y1;
#if 0
g_signal_handlers_block_by_func (scale->sizeentry,
gimp_scale_tool_size_changed,
tr_tool);
g_signal_handlers_block_by_func (scale->sizeentry,
gimp_scale_tool_unit_changed,
tr_tool);
gimp_size_entry_set_unit (GIMP_SIZE_ENTRY (scale->sizeentry),
GIMP_DISPLAY_SHELL (display->shell)->unit);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
display->image->xresolution, FALSE);
gimp_size_entry_set_resolution (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
display->image->yresolution, FALSE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_refval_boundaries (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
GIMP_MIN_IMAGE_SIZE,
GIMP_MAX_IMAGE_SIZE);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
0, scale->size_vals[0]);
gimp_size_entry_set_size (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
0, scale->size_vals[1]);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (scale->sizeentry), 0,
scale->size_vals[0]);
gimp_size_entry_set_refval (GIMP_SIZE_ENTRY (scale->sizeentry), 1,
scale->size_vals[1]);
g_signal_handlers_unblock_by_func (scale->sizeentry,
gimp_scale_tool_size_changed,
tr_tool);
g_signal_handlers_unblock_by_func (scale->sizeentry,
gimp_scale_tool_unit_changed,
tr_tool);
#endif
tr_tool->trans_info[X0] = (gdouble) tr_tool->x1;
tr_tool->trans_info[Y0] = (gdouble) tr_tool->y1;
tr_tool->trans_info[X1] = (gdouble) tr_tool->x2;
tr_tool->trans_info[Y1] = (gdouble) tr_tool->y2;
g_object_set (scale->box,
"width", tr_tool->x2 - tr_tool->x1,
"height", tr_tool->y2 - tr_tool->y1,
"unit", GIMP_DISPLAY_SHELL (display->shell)->unit,
"xresolution", display->image->xresolution,
"yresolution", display->image->yresolution,
NULL);
}
static void
@ -465,38 +297,23 @@ gimp_scale_tool_recalc (GimpTransformTool *tr_tool,
}
static void
gimp_scale_tool_size_changed (GtkWidget *widget,
GimpTransformTool *tr_tool)
gimp_scale_tool_size_notify (GtkWidget *box,
GParamSpec *pspec,
GimpTransformTool *tr_tool)
{
GimpTool *tool = GIMP_TOOL (tr_tool);
GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
GimpTransformOptions *options;
gint width;
gint height;
gint width;
gint height;
options = GIMP_TRANSFORM_OPTIONS (tool->tool_info->tool_options);
g_object_get (box,
"width", &width,
"height", &height,
NULL);
width = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 0));
height = RINT (gimp_size_entry_get_refval (GIMP_SIZE_ENTRY (widget), 1));
if ((width != (tr_tool->trans_info[X1] -
tr_tool->trans_info[X0])) ||
(height != (tr_tool->trans_info[Y1] -
tr_tool->trans_info[Y0])))
if ((width != (tr_tool->trans_info[X1] - tr_tool->trans_info[X0])) ||
(height != (tr_tool->trans_info[Y1] - tr_tool->trans_info[Y0])))
{
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
if (options->constrain_1 && options->constrain_2)
{
gdouble ratio = scale->aspect_ratio_val;
/* Calculating height and width taking into account the aspect ratio*/
if (width != (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]))
height = width / ratio;
else
width = height * ratio;
}
tr_tool->trans_info[X1] = tr_tool->trans_info[X0] + width;
tr_tool->trans_info[Y1] = tr_tool->trans_info[Y0] + height;
@ -507,30 +324,3 @@ gimp_scale_tool_size_changed (GtkWidget *widget,
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
}
}
static void
gimp_scale_tool_unit_changed (GtkWidget *widget,
GimpTransformTool *tr_tool)
{
gimp_scale_tool_dialog_update (tr_tool);
}
static void
gimp_scale_tool_aspect_changed (GtkWidget *widget,
GimpTransformTool *tr_tool)
{
GimpScaleTool *scale = GIMP_SCALE_TOOL (tr_tool);
scale->aspect_ratio_val = GTK_ADJUSTMENT (widget)->value;
gimp_draw_tool_pause (GIMP_DRAW_TOOL (tr_tool));
tr_tool->trans_info[Y1] =
((gdouble) (tr_tool->trans_info[X1] - tr_tool->trans_info[X0]) /
scale->aspect_ratio_val) +
tr_tool->trans_info[Y0];
gimp_transform_tool_recalc (tr_tool, GIMP_TOOL (tr_tool)->display);
gimp_draw_tool_resume (GIMP_DRAW_TOOL (tr_tool));
}

View File

@ -37,15 +37,7 @@ struct _GimpScaleTool
{
GimpTransformTool parent_instance;
/* scale dialog */
gchar orig_width_buf[MAX_INFO_BUF];
gchar orig_height_buf[MAX_INFO_BUF];
gdouble size_vals[2];
gchar x_ratio_buf[MAX_INFO_BUF];
gchar y_ratio_buf[MAX_INFO_BUF];
gdouble aspect_ratio_val;
GtkWidget *sizeentry;
GtkWidget *box;
};
struct _GimpScaleToolClass