Ref #331: Overimposed custom composition rule lines
authorColin Clark <colin.clark@cclark.uk>
Sat, 14 Jul 2018 13:23:55 +0000 (14:23 +0100)
committerColin Clark <colin.clark@cclark.uk>
Sat, 14 Jul 2018 13:23:55 +0000 (14:23 +0100)
"Rule of thirds" guidelines are included as an additional item in the
overlay screen display feature.

src/icons/Makefile.am
src/icons/icon_guidelines.png [new file with mode: 0644]
src/image-overlay.c
src/image-overlay.h
src/layout_util.c
src/options.h
src/pixbuf_util.c
src/pixbuf_util.h
src/rcfile.c
src/toolbar.c

index 9bc0c03..bb47ecc 100644 (file)
@@ -21,7 +21,8 @@ ICONS_INLINE = \
        icon_book.png           \
        icon_config.png         \
        icon_tools.png          \
-       icon_view.png
+       icon_view.png           \
+       icon_guidelines.png
 
 ICONS_INLINE_PAIRS = \
        folder_closed           $(srcdir)/folder_closed.png     \
@@ -41,7 +42,8 @@ ICONS_INLINE_PAIRS = \
        icon_book               $(srcdir)/icon_book.png         \
        icon_config             $(srcdir)/icon_config.png       \
        icon_tools              $(srcdir)/icon_tools.png        \
-       icon_view               $(srcdir)/icon_view.png
+       icon_view               $(srcdir)/icon_view.png         \
+       icon_guidelines $(srcdir)/icon_guidelines.png
 
 icons_inline.h: $(ICONS_INLINE) Makefile.in
        @sh -ec "echo '/* Auto generated file, do not edit */'; echo; \
diff --git a/src/icons/icon_guidelines.png b/src/icons/icon_guidelines.png
new file mode 100644 (file)
index 0000000..1fb81fa
Binary files /dev/null and b/src/icons/icon_guidelines.png differ
index cb272f0..b0585f6 100644 (file)
@@ -52,6 +52,7 @@ struct _OverlayStateData {
        Histogram *histogram;
 
        OsdShowFlags show;
+       OverlayRendererFlags origin;
 
        gint ovl_info;
 
@@ -215,10 +216,15 @@ void image_osd_toggle(ImageWindow *imd)
                }
        else
                {
-               if (show & OSD_SHOW_HISTOGRAM)
+               if (show & OSD_SHOW_GUIDELINES)
                        {
                        image_osd_set(imd, OSD_SHOW_NOTHING);
                        }
+               else if (show & OSD_SHOW_HISTOGRAM)
+                       {
+                       image_osd_set(imd, OSD_SHOW_GUIDELINES);
+                       image_osd_set(imd, show | ~OSD_SHOW_HISTOGRAM);
+                       }
                else
                        {
                        image_osd_set(imd, show | OSD_SHOW_HISTOGRAM);
@@ -793,6 +799,40 @@ static GdkPixbuf *image_osd_icon_pixbuf(ImageOSDFlag flag)
        return icon;
 }
 
+static GdkPixbuf *image_osd_guidelines_render(OverlayStateData *osd)
+{
+       gint width, height;
+       GdkPixbuf *rectangles;
+       ImageWindow *imd = osd->imd;
+
+       pixbuf_renderer_get_scaled_size((PixbufRenderer *)imd->pr, &width, &height);
+
+       if (width && height)
+               {
+               rectangles = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height);
+               if (rectangles)
+                       {
+                       pixbuf_set_rect_fill(rectangles, 0, 0, width, height, 255, 255, 255, 0);
+                       pixbuf_set_rect(rectangles, 0, 0 + (height / 3), width, height / 3,
+                                                               0, 0, 0, 255,
+                                                               1, 1, 1, 1);
+                       pixbuf_set_rect(rectangles, 0, 0 + (height / 3 + 1), width, height / 3 - 2,
+                                                               255, 255, 255, 255,
+                                                               1, 1, 1, 1);
+
+                       pixbuf_set_rect(rectangles, 0 + width / 3, 0 , width / 3, height,
+                                                               0, 0, 0, 255,
+                                                               1, 1, 1, 1);
+                       pixbuf_set_rect(rectangles, 0 + width / 3 + 1, 0, width / 3 - 2, height,
+                                                               255, 255, 255, 255,
+                                                               1, 1, 1, 1);
+                       return rectangles;
+                       }
+               }
+
+       return NULL;
+}
+
 static gint image_overlay_add(ImageWindow *imd, GdkPixbuf *pixbuf, gint x, gint y,
                              OverlayRendererFlags flags)
 {
@@ -876,7 +916,7 @@ static void image_osd_info_show(OverlayStateData *osd, GdkPixbuf *pixbuf)
 {
        if (osd->ovl_info == 0)
                {
-               osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, OVL_RELATIVE);
+               osd->ovl_info = image_overlay_add(osd->imd, pixbuf, osd->x, osd->y, osd->origin);
                }
        else
                {
@@ -902,19 +942,41 @@ static gboolean image_osd_update_cb(gpointer data)
                   with histogram we have to redraw also when loading is finished */
                if (osd->changed_states & IMAGE_STATE_IMAGE ||
                    (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_HISTOGRAM) ||
+                   (osd->changed_states & IMAGE_STATE_LOADING && osd->show & OSD_SHOW_GUIDELINES) ||
                    osd->notify & NOTIFY_HISTMAP)
                        {
                        GdkPixbuf *pixbuf;
 
-                       pixbuf = image_osd_info_render(osd);
-                       if (pixbuf)
+                       if (osd->show & OSD_SHOW_GUIDELINES)
                                {
-                               image_osd_info_show(osd, pixbuf);
-                               g_object_unref(pixbuf);
+                               ImageWindow *imd = osd->imd;
+                               osd->x = ((PixbufRenderer *)imd->pr)->x_offset;
+                               osd->y = ((PixbufRenderer *)imd->pr)->y_offset;
+                               osd->origin = OVL_NORMAL;
+
+                               pixbuf = image_osd_guidelines_render(osd);
+                               if (pixbuf)
+                                       {
+                                       image_osd_info_show(osd, pixbuf);
+                                       g_object_unref(pixbuf);
+                                       }
+
+                               osd->x = options->image_overlay.x;
+                               osd->y = options->image_overlay.y;
+                               osd->origin = OVL_RELATIVE;
                                }
                        else
                                {
-                               image_osd_info_hide(osd);
+                               pixbuf = image_osd_info_render(osd);
+                               if (pixbuf)
+                                       {
+                                       image_osd_info_show(osd, pixbuf);
+                                       g_object_unref(pixbuf);
+                                       }
+                               else
+                                       {
+                                       image_osd_info_hide(osd);
+                                       }
                                }
                        }
                }
@@ -1088,6 +1150,7 @@ static void image_osd_enable(ImageWindow *imd, OsdShowFlags show)
                osd->show = OSD_SHOW_NOTHING;
                osd->x = options->image_overlay.x;
                osd->y = options->image_overlay.y;
+               osd->origin = OVL_RELATIVE;
 
                osd->histogram = histogram_new();
 
index ae72dca..9792f4f 100644 (file)
@@ -37,7 +37,8 @@ typedef enum {
        OSD_SHOW_NOTHING        = 0,
        OSD_SHOW_INFO           = 1 << 0,
        OSD_SHOW_STATUS         = 1 << 1,
-       OSD_SHOW_HISTOGRAM      = 1 << 2
+       OSD_SHOW_HISTOGRAM      = 1 << 2,
+       OSD_SHOW_GUIDELINES     = 1 << 3
 } OsdShowFlags;
 
 void set_image_overlay_template_string(gchar **template_string, const gchar *value);
index 7c9d013..52e99b0 100644 (file)
@@ -928,6 +928,24 @@ static void layout_menu_histogram_cb(GtkToggleAction *action, gpointer data)
                }
 }
 
+static void layout_menu_guidelines_cb(GtkToggleAction *action, gpointer data)
+{
+       LayoutWindow *lw = data;
+
+       if (gtk_toggle_action_get_active(action))
+               {
+               OsdShowFlags flags = image_osd_get(lw->image);
+               image_osd_set(lw->image, OSD_SHOW_INFO | OSD_SHOW_STATUS | OSD_SHOW_GUIDELINES);
+               layout_util_sync_views(lw);
+               }
+       else
+               {
+               OsdShowFlags flags = image_osd_get(lw->image);
+               if (flags & OSD_SHOW_GUIDELINES)
+                       image_osd_set(lw->image, OSD_SHOW_NOTHING);
+               }
+}
+
 static void layout_menu_animate_cb(GtkToggleAction *action, gpointer data)
 {
        LayoutWindow *lw = data;
@@ -1927,6 +1945,7 @@ static GtkToggleActionEntry menu_toggle_entries[] = {
   { "Grayscale",       NULL,                   N_("Toggle _grayscale"),                "<shift>G",             N_("Toggle grayscale"),                 CB(layout_menu_alter_desaturate_cb), FALSE},
   { "ImageOverlay",    NULL,                   N_("Image _Overlay"),                   NULL,                   N_("Image Overlay"),                    CB(layout_menu_overlay_cb),      FALSE },
   { "ImageHistogram",  NULL,                   N_("_Show Histogram"),                  NULL,                   N_("Show Histogram"),                   CB(layout_menu_histogram_cb),    FALSE },
+  { "ImageGuidelines", PIXBUF_INLINE_ICON_GUIDELINES,          N_("_Show Guidelines"),                 NULL,           N_("Show Guidelines"),                  CB(layout_menu_guidelines_cb),   FALSE },
   { "RectangularSelection",    NULL,                   N_("Rectangular Selection"),                    "<alt>R",                       N_("Rectangular Selection"),                    CB(layout_menu_rectangular_selection_cb),        FALSE },
   { "Animate", NULL,   N_("GIF _animation"),           "A",                    N_("Toggle GIF animation"),                     CB(layout_menu_animate_cb),      FALSE  },
   { "ExifRotate",      GTK_STOCK_ORIENTATION_PORTRAIT,                 N_("_Exif rotate"),             "<alt>X",               N_("Exif rotate"),                      CB(layout_menu_exif_rotate_cb), FALSE },
@@ -2162,6 +2181,7 @@ static const gchar *menu_ui_description =
 "      </menu>"
 "      <menu action='OverlayMenu'>"
 "        <menuitem action='ImageOverlay'/>"
+"        <menuitem action='ImageGuidelines'/>"
 "        <menuitem action='ImageHistogram'/>"
 "        <menuitem action='ImageOverlayCycle'/>"
 "        <separator/>"
@@ -3018,6 +3038,9 @@ static void layout_util_sync_views(LayoutWindow *lw)
        action = gtk_action_group_get_action(lw->action_group, "ImageHistogram");
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_HISTOGRAM);
 
+       action = gtk_action_group_get_action(lw->action_group, "ImageGuidelines");
+       gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), osd_flags & OSD_SHOW_GUIDELINES);
+
        action = gtk_action_group_get_action(lw->action_group, "ExifRotate");
        gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), options->image.exif_rotate_enable);
 
index 95181c1..4bc52dd 100644 (file)
@@ -35,6 +35,7 @@ struct _ConfOptions
        gchar *image_l_click_video_editor;
        gboolean show_icon_names;
        gboolean show_star_rating;
+       gboolean show_guidelines;
 
        /* various */
        gboolean tree_descend_subdirs;
index bb2469c..ba82181 100644 (file)
@@ -120,6 +120,7 @@ static PixbufInline inline_pixbuf_data[] = {
        { PIXBUF_INLINE_ICON_CONFIG,    icon_config },
        { PIXBUF_INLINE_ICON_TOOLS,     icon_tools },
        { PIXBUF_INLINE_ICON_VIEW,      icon_view },
+       { PIXBUF_INLINE_ICON_GUIDELINES,        icon_guidelines },
        { NULL, NULL }
 };
 
index b4a61d7..74ddf21 100644 (file)
@@ -54,6 +54,7 @@ gboolean pixbuf_scale_aspect(gint req_w, gint req_h, gint old_w, gint old_h, gin
 #define PIXBUF_INLINE_ICON_CONFIG      "icon_config"
 #define PIXBUF_INLINE_ICON_TOOLS       "icon_tools"
 #define PIXBUF_INLINE_ICON_VIEW                "icon_view"
+#define PIXBUF_INLINE_ICON_GUIDELINES  "icon_guidelines"
 
 
 GdkPixbuf *pixbuf_copy_rotate_90(GdkPixbuf *src, gboolean counter_clockwise);
index a68ab47..2f6a28c 100644 (file)
@@ -307,6 +307,7 @@ static void write_global_attributes(GString *outstr, gint indent)
        /* General Options */
        WRITE_NL(); WRITE_BOOL(*options, show_icon_names);
        WRITE_NL(); WRITE_BOOL(*options, show_star_rating);
+       WRITE_NL(); WRITE_BOOL(*options, show_guidelines);
        WRITE_SEPARATOR();
 
        WRITE_NL(); WRITE_BOOL(*options, tree_descend_subdirs);
@@ -644,6 +645,7 @@ static gboolean load_global_params(const gchar **attribute_names, const gchar **
                /* General options */
                if (READ_BOOL(*options, show_icon_names)) continue;
                if (READ_BOOL(*options, show_star_rating)) continue;
+               if (READ_BOOL(*options, show_guidelines)) continue;
 
                if (READ_BOOL(*options, tree_descend_subdirs)) continue;
                if (READ_BOOL(*options, view_dir_list_single_click_enter)) continue;
index 25cba76..fdd2c8e 100644 (file)
@@ -111,6 +111,7 @@ static const UseableToolbarItems useable_toolbar_items[] = {
        {"ExifWin",     N_("Exif window"), GTK_STOCK_FILE},
        {"Thumbnails",  N_("Show thumbnails"), PIXBUF_INLINE_ICON_THUMB},
        {"ShowMarks",   N_("Show marks"), GTK_STOCK_FILE},
+       {"ImageGuidelines",     N_("Show guidelines"), PIXBUF_INLINE_ICON_GUIDELINES},
        {"FloatTools",  N_("Float file list"), PIXBUF_INLINE_ICON_FLOAT},
        {"SBar",        N_("Info sidebar"), GTK_STOCK_FILE},
        {"SBarSort",    N_("Sort manager"), GTK_STOCK_FILE},