diff --git a/ChangeLog b/ChangeLog index 179f943df0..a664d337ef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +Sat Feb 27 18:07:53 GMT 1999 Austin Donnelly + + * app/scale.c: use image's units, not the ruler units, when + dimentioning the rulers. Gimprc ruler-units syntax has no + use anymore. + + * app/gdisplay.[ch]: applied statusbar unit display patch from + Michael Natterer. + Sat Feb 27 16:54:51 GMT 1999 Adam D. Moss * app/gimage_cmds.c: When a gimage's colourmap is changed, diff --git a/app/core/gimpprojection.c b/app/core/gimpprojection.c index 45a4f91db0..d3477977b5 100644 --- a/app/core/gimpprojection.c +++ b/app/core/gimpprojection.c @@ -77,7 +77,7 @@ static GHashTable *display_ht = NULL; GDisplay* -gdisplay_new (GimpImage *gimage, +gdisplay_new (GimpImage *gimage, unsigned int scale) { GDisplay *gdisp; @@ -173,8 +173,8 @@ print (char *buf, int len, int start, const char *fmt, ...) static void gdisplay_format_title (GDisplay *gdisp, - char *title, - int title_len) + char *title, + int title_len) { GimpImage *gimage; char *image_type_str; @@ -1012,7 +1012,21 @@ gdisplay_update_cursor (GDisplay *gdisp, int x, int y) } else { - g_snprintf (buffer, CURSOR_STR_LENGTH, "%d, %d", t_x, t_y); + if (gdisp->dot_for_dot) + { + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, t_x, t_y); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, + (float)t_x * unit_factor / gdisp->gimage->xresolution, + (float)t_y * unit_factor / gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } gtk_label_set (GTK_LABEL (gdisp->cursor_label), buffer); } } @@ -1033,6 +1047,7 @@ gdisplay_set_dot_for_dot (GDisplay *gdisp, int value) { gdisp->dot_for_dot = value; + gdisplay_resize_cursor_label (gdisp); resize_display (gdisp, allow_resize_windows, TRUE); } } @@ -1044,11 +1059,44 @@ gdisplay_resize_cursor_label (GDisplay *gdisp) /* Set a proper size for the coordinates display in the statusbar. */ char buffer[CURSOR_STR_LENGTH]; int cursor_label_width; - - g_snprintf (buffer, sizeof(buffer),"%d, %d", gdisp->gimage->width, gdisp->gimage->height); + int label_frame_size_difference; + + if (gdisp->dot_for_dot) + { + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%d, %%d"); + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + gdisp->gimage->width, gdisp->gimage->height); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%.%df, %%.%df %%s", + gimp_unit_get_digits (gdisp->gimage->unit), + gimp_unit_get_digits (gdisp->gimage->unit)); + + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + (float)gdisp->gimage->width * unit_factor / + gdisp->gimage->xresolution, + (float)gdisp->gimage->height * unit_factor / + gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } cursor_label_width = gdk_string_width ( gtk_widget_get_style(gdisp->cursor_label)->font, buffer ); + + /* find out how many pixels the label's parent frame is bigger than + * the label itself */ + label_frame_size_difference = + gdisp->cursor_label->parent->allocation.width - + gdisp->cursor_label->allocation.width; + gtk_widget_set_usize (gdisp->cursor_label, cursor_label_width, -1); + if (label_frame_size_difference) /* don't resize if this is a new display */ + gtk_widget_set_usize (gdisp->cursor_label->parent, + cursor_label_width + label_frame_size_difference, -1); } void diff --git a/app/core/gimpprojection.h b/app/core/gimpprojection.h index 790327e35f..c23c708b12 100644 --- a/app/core/gimpprojection.h +++ b/app/core/gimpprojection.h @@ -67,6 +67,9 @@ the status line */ #define CURSOR_STR_LENGTH 256 +/* maximal length of the format string for the cursor-coordinates */ +#define CURSOR_FORMAT_LENGTH 16 + typedef struct _IdleRenderStruct { int width; @@ -97,6 +100,10 @@ struct _GDisplay GtkWidget *statusbar; /* widget for statusbar */ GtkWidget *progressbar; /* widget for progressbar */ GtkWidget *cursor_label; /* widget for cursor position */ + char cursor_format_str [CURSOR_FORMAT_LENGTH]; /* we need a variable format + * string because different + * units have different number + * of decimals */ GtkWidget *cancelbutton; /* widget for cancel button */ guint progressid; /* id of statusbar message for progress */ diff --git a/app/display/gimpdisplay-scale.c b/app/display/gimpdisplay-scale.c index b70521d7d2..cbe72d6cdb 100644 --- a/app/display/gimpdisplay-scale.c +++ b/app/display/gimpdisplay-scale.c @@ -161,10 +161,12 @@ change_scale (GDisplay *gdisp, /* 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) { - float res; + float res; if (gdisp->dot_for_dot) return a; @@ -174,20 +176,7 @@ img2real (GDisplay *gdisp, gboolean xdir, gdouble a) else res = gdisp->gimage->yresolution; - switch (ruler_units) { - case GTK_PIXELS: - return a; - - case GTK_INCHES: - return a / res; - - case GTK_CENTIMETERS: - return a * 2.54 / res; - - default: - g_warning ("unknown ruler_units %d, can't happen", ruler_units); - return a; - } + return a * gimp_unit_get_factor (gdisp->gimage->unit) / res; } diff --git a/app/display/gimpdisplay.c b/app/display/gimpdisplay.c index 45a4f91db0..d3477977b5 100644 --- a/app/display/gimpdisplay.c +++ b/app/display/gimpdisplay.c @@ -77,7 +77,7 @@ static GHashTable *display_ht = NULL; GDisplay* -gdisplay_new (GimpImage *gimage, +gdisplay_new (GimpImage *gimage, unsigned int scale) { GDisplay *gdisp; @@ -173,8 +173,8 @@ print (char *buf, int len, int start, const char *fmt, ...) static void gdisplay_format_title (GDisplay *gdisp, - char *title, - int title_len) + char *title, + int title_len) { GimpImage *gimage; char *image_type_str; @@ -1012,7 +1012,21 @@ gdisplay_update_cursor (GDisplay *gdisp, int x, int y) } else { - g_snprintf (buffer, CURSOR_STR_LENGTH, "%d, %d", t_x, t_y); + if (gdisp->dot_for_dot) + { + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, t_x, t_y); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, + (float)t_x * unit_factor / gdisp->gimage->xresolution, + (float)t_y * unit_factor / gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } gtk_label_set (GTK_LABEL (gdisp->cursor_label), buffer); } } @@ -1033,6 +1047,7 @@ gdisplay_set_dot_for_dot (GDisplay *gdisp, int value) { gdisp->dot_for_dot = value; + gdisplay_resize_cursor_label (gdisp); resize_display (gdisp, allow_resize_windows, TRUE); } } @@ -1044,11 +1059,44 @@ gdisplay_resize_cursor_label (GDisplay *gdisp) /* Set a proper size for the coordinates display in the statusbar. */ char buffer[CURSOR_STR_LENGTH]; int cursor_label_width; - - g_snprintf (buffer, sizeof(buffer),"%d, %d", gdisp->gimage->width, gdisp->gimage->height); + int label_frame_size_difference; + + if (gdisp->dot_for_dot) + { + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%d, %%d"); + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + gdisp->gimage->width, gdisp->gimage->height); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%.%df, %%.%df %%s", + gimp_unit_get_digits (gdisp->gimage->unit), + gimp_unit_get_digits (gdisp->gimage->unit)); + + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + (float)gdisp->gimage->width * unit_factor / + gdisp->gimage->xresolution, + (float)gdisp->gimage->height * unit_factor / + gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } cursor_label_width = gdk_string_width ( gtk_widget_get_style(gdisp->cursor_label)->font, buffer ); + + /* find out how many pixels the label's parent frame is bigger than + * the label itself */ + label_frame_size_difference = + gdisp->cursor_label->parent->allocation.width - + gdisp->cursor_label->allocation.width; + gtk_widget_set_usize (gdisp->cursor_label, cursor_label_width, -1); + if (label_frame_size_difference) /* don't resize if this is a new display */ + gtk_widget_set_usize (gdisp->cursor_label->parent, + cursor_label_width + label_frame_size_difference, -1); } void diff --git a/app/display/gimpdisplay.h b/app/display/gimpdisplay.h index 790327e35f..c23c708b12 100644 --- a/app/display/gimpdisplay.h +++ b/app/display/gimpdisplay.h @@ -67,6 +67,9 @@ the status line */ #define CURSOR_STR_LENGTH 256 +/* maximal length of the format string for the cursor-coordinates */ +#define CURSOR_FORMAT_LENGTH 16 + typedef struct _IdleRenderStruct { int width; @@ -97,6 +100,10 @@ struct _GDisplay GtkWidget *statusbar; /* widget for statusbar */ GtkWidget *progressbar; /* widget for progressbar */ GtkWidget *cursor_label; /* widget for cursor position */ + char cursor_format_str [CURSOR_FORMAT_LENGTH]; /* we need a variable format + * string because different + * units have different number + * of decimals */ GtkWidget *cancelbutton; /* widget for cancel button */ guint progressid; /* id of statusbar message for progress */ diff --git a/app/display/gimpdisplayshell-scale.c b/app/display/gimpdisplayshell-scale.c index b70521d7d2..cbe72d6cdb 100644 --- a/app/display/gimpdisplayshell-scale.c +++ b/app/display/gimpdisplayshell-scale.c @@ -161,10 +161,12 @@ change_scale (GDisplay *gdisp, /* 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) { - float res; + float res; if (gdisp->dot_for_dot) return a; @@ -174,20 +176,7 @@ img2real (GDisplay *gdisp, gboolean xdir, gdouble a) else res = gdisp->gimage->yresolution; - switch (ruler_units) { - case GTK_PIXELS: - return a; - - case GTK_INCHES: - return a / res; - - case GTK_CENTIMETERS: - return a * 2.54 / res; - - default: - g_warning ("unknown ruler_units %d, can't happen", ruler_units); - return a; - } + return a * gimp_unit_get_factor (gdisp->gimage->unit) / res; } diff --git a/app/gdisplay.c b/app/gdisplay.c index 45a4f91db0..d3477977b5 100644 --- a/app/gdisplay.c +++ b/app/gdisplay.c @@ -77,7 +77,7 @@ static GHashTable *display_ht = NULL; GDisplay* -gdisplay_new (GimpImage *gimage, +gdisplay_new (GimpImage *gimage, unsigned int scale) { GDisplay *gdisp; @@ -173,8 +173,8 @@ print (char *buf, int len, int start, const char *fmt, ...) static void gdisplay_format_title (GDisplay *gdisp, - char *title, - int title_len) + char *title, + int title_len) { GimpImage *gimage; char *image_type_str; @@ -1012,7 +1012,21 @@ gdisplay_update_cursor (GDisplay *gdisp, int x, int y) } else { - g_snprintf (buffer, CURSOR_STR_LENGTH, "%d, %d", t_x, t_y); + if (gdisp->dot_for_dot) + { + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, t_x, t_y); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (buffer, CURSOR_STR_LENGTH, + gdisp->cursor_format_str, + (float)t_x * unit_factor / gdisp->gimage->xresolution, + (float)t_y * unit_factor / gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } gtk_label_set (GTK_LABEL (gdisp->cursor_label), buffer); } } @@ -1033,6 +1047,7 @@ gdisplay_set_dot_for_dot (GDisplay *gdisp, int value) { gdisp->dot_for_dot = value; + gdisplay_resize_cursor_label (gdisp); resize_display (gdisp, allow_resize_windows, TRUE); } } @@ -1044,11 +1059,44 @@ gdisplay_resize_cursor_label (GDisplay *gdisp) /* Set a proper size for the coordinates display in the statusbar. */ char buffer[CURSOR_STR_LENGTH]; int cursor_label_width; - - g_snprintf (buffer, sizeof(buffer),"%d, %d", gdisp->gimage->width, gdisp->gimage->height); + int label_frame_size_difference; + + if (gdisp->dot_for_dot) + { + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%d, %%d"); + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + gdisp->gimage->width, gdisp->gimage->height); + } + else /* show real world units */ + { + float unit_factor = gimp_unit_get_factor (gdisp->gimage->unit); + + g_snprintf (gdisp->cursor_format_str, sizeof(gdisp->cursor_format_str), + "%%.%df, %%.%df %%s", + gimp_unit_get_digits (gdisp->gimage->unit), + gimp_unit_get_digits (gdisp->gimage->unit)); + + g_snprintf (buffer, sizeof(buffer), gdisp->cursor_format_str, + (float)gdisp->gimage->width * unit_factor / + gdisp->gimage->xresolution, + (float)gdisp->gimage->height * unit_factor / + gdisp->gimage->yresolution, + gimp_unit_get_symbol (gdisp->gimage->unit)); + } cursor_label_width = gdk_string_width ( gtk_widget_get_style(gdisp->cursor_label)->font, buffer ); + + /* find out how many pixels the label's parent frame is bigger than + * the label itself */ + label_frame_size_difference = + gdisp->cursor_label->parent->allocation.width - + gdisp->cursor_label->allocation.width; + gtk_widget_set_usize (gdisp->cursor_label, cursor_label_width, -1); + if (label_frame_size_difference) /* don't resize if this is a new display */ + gtk_widget_set_usize (gdisp->cursor_label->parent, + cursor_label_width + label_frame_size_difference, -1); } void diff --git a/app/gdisplay.h b/app/gdisplay.h index 790327e35f..c23c708b12 100644 --- a/app/gdisplay.h +++ b/app/gdisplay.h @@ -67,6 +67,9 @@ the status line */ #define CURSOR_STR_LENGTH 256 +/* maximal length of the format string for the cursor-coordinates */ +#define CURSOR_FORMAT_LENGTH 16 + typedef struct _IdleRenderStruct { int width; @@ -97,6 +100,10 @@ struct _GDisplay GtkWidget *statusbar; /* widget for statusbar */ GtkWidget *progressbar; /* widget for progressbar */ GtkWidget *cursor_label; /* widget for cursor position */ + char cursor_format_str [CURSOR_FORMAT_LENGTH]; /* we need a variable format + * string because different + * units have different number + * of decimals */ GtkWidget *cancelbutton; /* widget for cancel button */ guint progressid; /* id of statusbar message for progress */ diff --git a/app/scale.c b/app/scale.c index b70521d7d2..cbe72d6cdb 100644 --- a/app/scale.c +++ b/app/scale.c @@ -161,10 +161,12 @@ change_scale (GDisplay *gdisp, /* 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) { - float res; + float res; if (gdisp->dot_for_dot) return a; @@ -174,20 +176,7 @@ img2real (GDisplay *gdisp, gboolean xdir, gdouble a) else res = gdisp->gimage->yresolution; - switch (ruler_units) { - case GTK_PIXELS: - return a; - - case GTK_INCHES: - return a / res; - - case GTK_CENTIMETERS: - return a * 2.54 / res; - - default: - g_warning ("unknown ruler_units %d, can't happen", ruler_units); - return a; - } + return a * gimp_unit_get_factor (gdisp->gimage->unit) / res; }