[gegl] bin: add pdf specific page-up/page-down key bindings



commit b5da4cdbc6af409c74fb176b8da425e17c0a47fa
Author: Øyvind Kolås <pippin gimp org>
Date:   Sat Feb 23 00:45:42 2019 +0100

    bin: add pdf specific page-up/page-down key bindings

 bin/lua/viewer.lua | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++--
 bin/ui.c           |  8 ++++++
 2 files changed, 87 insertions(+), 3 deletions(-)
---
diff --git a/bin/lua/viewer.lua b/bin/lua/viewer.lua
index 47acfc52a..1f911a844 100644
--- a/bin/lua/viewer.lua
+++ b/bin/lua/viewer.lua
@@ -133,6 +133,20 @@ function draw_back(x,y,w,h)
   cr:line_to (x+0.1*w, y+0.5*h);
 end
 
+function draw_up (x,y,w,h)
+  cr:new_path ();
+  cr:move_to (x+0.1*w, y+0.9*h);
+  cr:line_to (x+0.5*w, y+0.1*h);
+  cr:line_to (x+0.9*w, y+0.9*h);
+end
+
+function draw_down (x,y,w,h)
+  cr:new_path ();
+  cr:move_to (x+0.1*w, y+0.1*h);
+  cr:line_to (x+0.5*w, y+0.9*h);
+  cr:line_to (x+0.9*w, y+0.1*h);
+end
+
 function draw_forward(x,y,w,h)
   cr:new_path ();
   cr:move_to (x+0.1*w, y+0.1*h);
@@ -143,7 +157,7 @@ end
 function draw_pause (x,y,w,h)
   local margin = w * .1
   local bar = w * .3
-  local gap = w * .15
+  local gap = w * .16
   cr:new_path ();
   cr:rectangle (x + margin, y, bar, h)
   cr:rectangle (x + margin + bar + gap, y, bar, h)
@@ -304,16 +318,78 @@ if o.is_video ~= 0 then
   end)
   cr:new_path()
 
+  
+
+
+
+
 end
 
+local path = GObject.Object(STATE).path
+local source = GObject.Object(STATE).source
 
+function pdf_next_page()
+  local pages = source:get_property('pages').value
+  local page = source:get_property('page').value
+  source:set_property('page', GObject.Value(GObject.Type.INT, page + 1))
+end
 
+function pdf_prev_page()
+  local pages = source:get_property('pages').value
+  local page = source:get_property('page').value
+  source:set_property('page', GObject.Value(GObject.Type.INT, page - 1))
+end
 
 mrg:add_binding("page-up", NULL, "previous image",
-  function() ffi.C.argvs_val ("prev") end)
+  function() ffi.C.argvs_eval ("prev") end)
 
 mrg:add_binding("page-down", NULL, "next image",
-  function() ffi.C.argvs_val ("next") end)
+  function() ffi.C.argvs_eval ("next") end)
+
+if path:find(".pdf$") or path:find('.PDF$') then
+  local pages = source:get_property('pages').value
+  local page = source:get_property('page').value
+
+  mrg:set_style("background:transparent;color:white")
+  mrg:set_xy(width - height * .12, height - height * .15)
+  if o.show_controls ~= 0 then
+    mrg:print(' ' .. page .. '/' .. pages)
+  end
+
+  draw_up (width - height * .12, height * .71, height * .1, height *.1);
+  cr:close_path ();
+  mrg:listen(Mrg.PRESS, function(event)
+    pdf_prev_page()
+    event:stop_propagate()
+  end)
+  if o.show_controls ~= 0 then
+    contrasty_stroke ()
+  else
+    cr:new_path()
+  end
+
+  draw_down (width - height * .12, height * .87, height * .1, height *.1);
+  cr:close_path ();
+  mrg:listen(Mrg.PRESS, function(event)
+    pdf_next_page()
+    event:stop_propagate()
+  end)
+  if o.show_controls ~= 0 then
+    contrasty_stroke ()
+  else
+    cr:new_path()
+  end
+
+  -- override default page-up / page-down bindings
+  mrg:add_binding("page-up", NULL, "previous page",
+    function(e) pdf_prev_page() e:stop_propagate() end)
+
+  mrg:add_binding("page-down", NULL, "next page",
+    function(e) pdf_next_page() e:stop_propagate() end)
+
+end
+
+
 
 mrg:add_binding("alt-right", NULL, "next image",
   function() ffi.C.argvs_val ("next") end)
diff --git a/bin/ui.c b/bin/ui.c
index 411ffa510..6984ef563 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -127,6 +127,7 @@ enum
     PROP_SOURCE,
     PROP_ACTIVE,
     PROP_SINK,
+    PROP_PATH,
     N_PROPERTIES
 };
 
@@ -220,6 +221,9 @@ ge_state_get_property (GObject    *object,
     case PROP_SINK:
         g_value_set_object (value, state->sink);
         break;
+    case PROP_PATH:
+        g_value_set_string (value, state->path);
+        break;
 
     default:
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -270,6 +274,10 @@ ge_state_class_init (GeStateClass *klass)
         g_param_spec_object ("active", "Active", "Active node",
                              GEGL_TYPE_NODE,
                              G_PARAM_READWRITE);
+    obj_properties[PROP_PATH] =
+        g_param_spec_string ("path", "Path", "Path of active image",
+                             NULL,
+                             G_PARAM_READABLE);
 
     g_object_class_install_properties (object_class,
                                        N_PROPERTIES,


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