[gegl] bin: draw bezier control points in path ui



commit b2aef8f2e9d2f6bc78c4a4dde7c6dc4e4c029343
Author: Øyvind Kolås <pippin gimp org>
Date:   Mon Feb 18 15:04:24 2019 +0100

    bin: draw bezier control points in path ui

 bin/lua/gegl_fill-path.lua     |   1 +
 bin/lua/gegl_rectangle.lua     |  40 ++++++++++++++
 bin/lua/gegl_vector-stroke.lua | 121 ++++++++++++++++++++++++++++++++++-------
 bin/ui.c                       |   5 +-
 4 files changed, 144 insertions(+), 23 deletions(-)
---
diff --git a/bin/lua/gegl_fill-path.lua b/bin/lua/gegl_fill-path.lua
new file mode 120000
index 000000000..88427ca57
--- /dev/null
+++ b/bin/lua/gegl_fill-path.lua
@@ -0,0 +1 @@
+gegl_vector-stroke.lua
\ No newline at end of file
diff --git a/bin/lua/gegl_rectangle.lua b/bin/lua/gegl_rectangle.lua
new file mode 100644
index 000000000..c428f9d0d
--- /dev/null
+++ b/bin/lua/gegl_rectangle.lua
@@ -0,0 +1,40 @@
+local x = active:get_property("x").value
+local y = active:get_property("y").value
+
+cr:new_path()
+cr:arc(x, y, dim/2, 0, 3.1415 * 2)
+
+mrg:listen(Mrg.DRAG, function(ev)
+  if ev.type == Mrg.DRAG_MOTION then
+    local x = active:get_property("x").value
+    local y = active:get_property("y").value
+    x = x + ev.delta_x
+    y = y + ev.delta_y
+    active:set_property("y", GObject.Value(GObject.Type.DOUBLE, y))
+    active:set_property("x", GObject.Value(GObject.Type.DOUBLE, x))
+    ev:stop_propagate();
+  end
+end)
+
+cr:set_source_rgba(1,0,0,0.5)
+cr:fill()
+
+local w = active:get_property("width").value
+local h = active:get_property("height").value
+
+cr:new_path()
+cr:arc(x + w, y + h, dim/2, 0, 3.1415 * 2)
+mrg:listen(Mrg.DRAG, function(ev)
+  if ev.type == Mrg.DRAG_MOTION then
+    local w = active:get_property("width").value
+    local h = active:get_property("height").value
+    w = w + ev.delta_x
+    h = h + ev.delta_y
+    active:set_property("width", GObject.Value(GObject.Type.DOUBLE, w))
+    active:set_property("height", GObject.Value(GObject.Type.DOUBLE, h))
+    ev:stop_propagate();
+  end
+end)
+cr:set_source_rgba(1,0,0,0.5)
+cr:fill()
+
diff --git a/bin/lua/gegl_vector-stroke.lua b/bin/lua/gegl_vector-stroke.lua
index 44842797a..82629006b 100644
--- a/bin/lua/gegl_vector-stroke.lua
+++ b/bin/lua/gegl_vector-stroke.lua
@@ -1,26 +1,109 @@
 local path = active:get_property("d").value
 
-path:foreach( function(el)
-  local x = el.point[1].x
-  local y = el.point[1].y
-
-  cr:new_path()
-  cr:arc(x, y, dim/15, 0, 3.1415 * 2)
-
-mrg:listen(Mrg.DRAG, function(ev)
-  if ev.type == Mrg.DRAG_MOTION then
-    local x = el.point[1].x
-    local y = el.point[1].y
-    x = x + ev.delta_x
-    y = y + ev.delta_y
-    el.point[1].x = x
-    el.point[1].y = y
-    path:dirty()
-    ev:stop_propagate();
+-- there seem to be enough exposed through gobject introspection
+-- to build a full bezier editor, for now placeholder.
+
+--print ('\n nodes:' .. path:get_n_nodes())
+--print ('length:' .. path:get_length())
+--local a = path:get_node(0)
+--print ('a:' .. a.type)
+
+
+
+
+local no = 0
+
+path:foreach_flat( function(el)
+  if el.type == 77 then
+    cr:move_to(el.point[1].x, el.point[1].y)
+  elseif el.type == 76 then
+    cr:line_to(el.point[1].x, el.point[1].y)
+  elseif el.type == 122 then
   end
 end)
 
-  cr:set_source_rgb(0,1,0)
-  cr:fill()
+cr:set_line_width(dim/20)
+cr:stroke()
+
+-- 67 : C
+-- 76 : L
+-- 77 : M
+-- 99 : c
+-- 108 : l
+-- 109 : m
+-- 122 : z
+
+local cur_x = 0
+local cur_y = 0
+
+path:foreach( function(el)
+
+  local coord_no = 1
+
+  if el.type == 67 then -- 'C'
+
+    for coord_no = 1, 3 do
+    local x = el.point[coord_no].x
+    local y = el.point[coord_no].y
+
+    cr:new_path()
+    cr:move_to (el.point[3].x, el.point[3].y)
+    cr:line_to (el.point[2].x, el.point[2].y)
+    cr:stroke()
+
+
+    cr:new_path()
+    cr:move_to (el.point[1].x, el.point[1].y)
+    cr:line_to (cur_x, cur_y)
+    cr:stroke()
+
+
+    cr:new_path()
+    cr:arc(x, y, dim/15, 0, 3.1415 * 2)
+    mrg:listen(Mrg.DRAG, function(ev)
+      if ev.type == Mrg.DRAG_MOTION then
+        local x = el.point[coord_no].x
+        local y = el.point[coord_no].y
+        x = x + ev.delta_x
+        y = y + ev.delta_y
+        el.point[coord_no].x = x
+        el.point[coord_no].y = y
+        path:dirty()
+        ev:stop_propagate();
+      end
+    end)
+    cr:set_source_rgb(1,0,0)
+    cr:fill()
+    end
+
+    coord_no = 3
+  elseif el.type == 122 then
+  else
+    coord_no = 1
+    local x = el.point[coord_no].x
+    local y = el.point[coord_no].y
+    cr:new_path()
+    cr:arc(x, y, dim/15, 0, 3.1415 * 2)
+    mrg:listen(Mrg.DRAG, function(ev)
+      if ev.type == Mrg.DRAG_MOTION then
+        local x = el.point[coord_no].x
+        local y = el.point[coord_no].y
+        x = x + ev.delta_x
+        y = y + ev.delta_y
+        el.point[coord_no].x = x
+        el.point[coord_no].y = y
+        path:dirty()
+        ev:stop_propagate();
+      end
+    end)
+    cr:set_source_rgb(1,0,0)
+    cr:fill()
+  end
+
+
+  cur_x = el.point[coord_no].x
+  cur_y = el.point[coord_no].y
+ --print ('' .. no .. ' - ' .. el.type )
 
+  no = no + 1
 end)
diff --git a/bin/ui.c b/bin/ui.c
index 81558963f..7ddcf5fc1 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -7660,15 +7660,12 @@ int cmd_todo (COMMAND_ARGS);/* "todo", -1, "", ""*/
 int
 cmd_todo (COMMAND_ARGS)
 {
+  printf ("tab-completion for cd command\n");
   printf ("visual color picker\n");
   printf ("make axis constrained vertical drag up/down adjust linear small increments on double\n");
-  printf ("crop ui\n");
-  printf ("tab-completion for cd command\n");
   printf ("units in commandline\n");
-  printf ("polyline/bezier on canvas display/editing\n");
   printf ("interpret GUM\n");
   printf ("star/comment/title storage\n");
-  printf ("loadable lua modules\n");
   printf ("rewrite of core in lua?\n");
   printf ("keep track of \"orphaned\" nodes as free-floating new columns\n");
   printf ("video/audio playback time controls\n");


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