[gimp] Implements Title bar codes for Layer dimensions



commit bb172b52c82385236a155d1e88b811005d651327
Author: João S. O. Bueno <gwidion gmail com>
Date:   Mon Apr 21 00:30:49 2014 -0300

    Implements Title bar codes for Layer dimensions
    
    Implements codes %x, %y and %X, %Y to display
    a layer's size in title and status bars
    for image windows.
    Addresses request at bug #728493

 app/dialogs/preferences-dialog.c     |    6 ++-
 app/display/gimpdisplayshell-title.c |   78 +++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/app/dialogs/preferences-dialog.c b/app/dialogs/preferences-dialog.c
index 300fae3..5965a8d 100644
--- a/app/dialogs/preferences-dialog.c
+++ b/app/dialogs/preferences-dialog.c
@@ -2008,7 +2008,8 @@ prefs_dialog_new (Gimp       *gimp,
       NULL,
       "%f-%p.%i (%t) %z%%",
       "%f-%p.%i (%t) %d:%s",
-      "%f-%p.%i (%t) %wx%h"
+      "%f-%p.%i (%t) %wx%h",
+      "%f-%p-%i (%t) %wx%h (%xx%y)"
     };
 
     const gchar *format_names[] =
@@ -2017,7 +2018,8 @@ prefs_dialog_new (Gimp       *gimp,
       N_("Default format"),
       N_("Show zoom percentage"),
       N_("Show zoom ratio"),
-      N_("Show image size")
+      N_("Show image size"),
+      N_("Show drawable size")
     };
 
     struct
diff --git a/app/display/gimpdisplayshell-title.c b/app/display/gimpdisplayshell-title.c
index b1bbc8f..3006399 100644
--- a/app/display/gimpdisplayshell-title.c
+++ b/app/display/gimpdisplayshell-title.c
@@ -410,11 +410,87 @@ gimp_display_shell_format_title (GimpDisplayShell *shell,
                           gimp_unit_get_abbreviation (shell->unit));
               break;
 
+            case 'X': /* drawable width in real world units */
+              if (shell->unit != GIMP_UNIT_PIXEL)
+                {
+                  gdouble xres;
+                  gdouble yres;
+                  gchar   unit_format[8];
+                  GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+
+                  gimp_image_get_resolution (image, &xres, &yres);
+
+                  g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
+                              gimp_unit_get_digits (shell->unit) + 1);
+                  i += print (title, title_len, i, unit_format,
+                              gimp_pixels_to_units (gimp_item_get_width
+                                                     (GIMP_ITEM (drawable)),
+                                                    shell->unit, yres));
+                  break;
+                }
+              /* else fallthru */
+            case 'x': /* drawable width in pixels */
+              {
+                GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+                i += print (title, title_len, i, "%d",
+                            gimp_item_get_width (GIMP_ITEM (drawable)));
+              }
+              break;
+
+            case 'Y': /* drawable height in real world units */
+              if (shell->unit != GIMP_UNIT_PIXEL)
+                {
+                  gdouble xres;
+                  gdouble yres;
+                  gchar   unit_format[8];
+                  GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+
+                  gimp_image_get_resolution (image, &xres, &yres);
+
+                  g_snprintf (unit_format, sizeof (unit_format), "%%.%df",
+                              gimp_unit_get_digits (shell->unit) + 1);
+                  i += print (title, title_len, i, unit_format,
+                              gimp_pixels_to_units (gimp_item_get_height
+                                                     (GIMP_ITEM (drawable)),
+                                                    shell->unit, yres));
+                  break;
+                }
+              /* else fallthru */
+            case 'y': /* drawable height in pixels */
+              {
+                GimpDrawable *drawable = gimp_image_get_active_drawable (image);
+                i += print (title, title_len, i, "%d",
+                            gimp_item_get_height (GIMP_ITEM (drawable)));
+              }
+              break;
+
+            case '\xc3': /* utf-8 extended char */
+              {
+                format ++;
+                switch (*format)
+                  {
+                  case '\xbe':
+                      {
+                        /* line actually written at 23:55 on an Easter Sunday */
+                        i+= print(title, title_len, i, "42");
+                      }
+                      break;
+
+                  default:
+                    /* in the case of an unhandled utf-8 extended char format
+                     * leave the format string parsing as it was
+                    */
+                    format --;
+                    break;
+                  }
+              }
+              break;
+
               /* Other cool things to be added:
                * %r = xresolution
                * %R = yresolution
                * %� = image's fractal dimension
-               * %� = the answer to everything
+               * # %� = the answer to everything - (implemented)
                */
 
             default:


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]