[gegl] bin: add .lui extension



commit f617778fbe1ec9fb7bb88d457b112c3496fea19d
Author: Øyvind Kolås <pippin gimp org>
Date:   Wed Feb 27 16:16:04 2019 +0100

    bin: add .lui extension
    
    Files with a .lui extension get executed as lua code similar to the
    on-canvas ui. For now, such files get only black thumbnails.

 bin/gegl.c       |  1 +
 bin/lua/init.lua | 17 ++++++++++--
 bin/ui.c         | 85 +++++++++++++++++++++++++++++++-------------------------
 bin/ui.h         |  4 ++-
 4 files changed, 66 insertions(+), 41 deletions(-)
---
diff --git a/bin/gegl.c b/bin/gegl.c
index 010b13324..e48fcdc02 100644
--- a/bin/gegl.c
+++ b/bin/gegl.c
@@ -423,6 +423,7 @@ int gegl_str_has_image_suffix (char *path)
          g_str_has_suffix (path, ".JPEG") ||
          g_str_has_suffix (path, ".CR2") ||
          g_str_has_suffix (path, ".cr2") ||
+         g_str_has_suffix (path, ".lui") ||
          g_str_has_suffix (path, ".exr");
 }
 
diff --git a/bin/lua/init.lua b/bin/lua/init.lua
index 5834d29b7..fb6ee498d 100644
--- a/bin/lua/init.lua
+++ b/bin/lua/init.lua
@@ -16,7 +16,7 @@ typedef void* GeglProcessor;
 typedef void* GThread;
 typedef void* GHashTable;
 
-struct State {
+struct _GeState {
   int64_t   pad_for_gobject[3];
 
   void      (*ui) (Mrg *mrg, void *state);
@@ -111,14 +111,27 @@ struct State {
   GHashTable  *ui_consumer;
 };
 
+typedef struct _GeState GeState;
+
+const char *ge_state_get_path (GeState *state, int no);
+int         ge_state_get_n_paths (GeState *state);
+
 float hypotf (float a, float b);
-struct State *app_state(void);
+GeState *app_state(void);
 int argvs_eval (const char *str);
+
 ]]
 
 o = ffi.C.app_state()
 mrg = o.mrg
 
+ffi.metatype('GeState', {__index = {
+   get_path = function(...) local ret = ffi.C.ge_state_get_path(...)
+                              if ret ~= nil then return ffi.string(ret) end
+                              return nil
+                            end;
+   get_n_paths = function(...) return ffi.C.get_state_get_n_paths(...) end;
+ }})
 
 function touch_point(x, y)
   cr:new_path()
diff --git a/bin/ui.c b/bin/ui.c
index a114b4626..298d13d54 100644
--- a/bin/ui.c
+++ b/bin/ui.c
@@ -5327,33 +5327,6 @@ jump:
   cairo_restore (cr);
 }
 
-static void vector_op_ui (GeState *o, GeglNode *node)
-{
-  Mrg *mrg = o->mrg;
-  GeglPath *path;
-  cairo_t  *cr = mrg_cr (mrg);
-  double linewidth = 2.0f;
-  double linewidth_shadow = 2.5f;
-  double foo ;
-
-  cairo_device_to_user_distance (cr, &linewidth, &foo);
-  cairo_device_to_user_distance (cr, &linewidth_shadow, &foo);
-
-  return;
-
-  gegl_node_get (node, "d", &path, NULL);
-
-
-  cairo_move_to (cr, 0, 0);
-  cairo_line_to (cr, 1100,1100);
-
-  cairo_set_source_rgba (cr, 0,0,0, .5);
-  cairo_set_line_width (cr, linewidth_shadow);
-  cairo_set_source_rgba (cr, 1,0,0, 1.0);
-  cairo_stroke (cr);
-}
-
-
 static cairo_matrix_t node_get_relative_transform (GeglNode *node_view,
                                                    GeglNode *source);
 
@@ -5387,17 +5360,7 @@ static int per_op_canvas_ui (GeState *o)
      luaname[i] = '_';
   }
 
-if (0)
-{
-  if (!strcmp (opname, "gegl:vector-stroke"))
-  {
-    vector_op_ui (o, o->active);
-  }
-}
-
-  {
-    run_lua_file (luaname);
-  }
+  run_lua_file (luaname);
 
   cairo_restore (cr);
 
@@ -5685,6 +5648,35 @@ static void gegl_ui (Mrg *mrg, void *data)
       else
         {
 
+  if (g_str_has_suffix (o->path, ".lui"))
+  {
+  int result;
+  int status = luaL_loadfile(L, o->path);
+  if (status)
+  {
+    fprintf(stderr, "Couldn't load file: %s\n", lua_tostring(L, -1));
+  }
+  else
+  {
+    result = lua_pcall(L, 0, LUA_MULTRET, 0);
+    if (result){
+      fprintf (stderr, "lua exec problem %s\n", lua_tostring(L, -1));
+    } else
+    {
+    }
+  }
+  }
+
+
+
+
+
+
+
+
+
+
+
 #if HAVE_LUA
   if (run_lua_file ("viewer.lua"))
   {
@@ -5999,6 +5991,15 @@ static void load_path_inner (GeState *o,
          "operation", "gegl:pdf-load", "path", path, NULL);
     gegl_node_link_many (o->source, o->sink, NULL);
   }
+  else if (g_str_has_suffix (path, ".lui"))
+  {
+    o->gegl = gegl_node_new ();
+    o->sink = gegl_node_new_child (o->gegl,
+                       "operation", "gegl:nop", NULL);
+    o->source = gegl_node_new_child (o->gegl,
+         "operation", "gegl:rectangle", "color", gegl_color_new ("black"), "width", 1024.0, "height", 768.0, 
NULL);
+    gegl_node_link_many (o->source, o->sink, NULL);
+  }
   else if (g_str_has_suffix (path, ".gif"))
   {
     o->gegl = gegl_node_new ();
@@ -8106,5 +8107,13 @@ cmd_todo (COMMAND_ARGS)
   return 0;
 }
 
+const char *ge_state_get_path (GeState *state, int no)
+{
+  return g_list_nth_data (state->paths, no);
+}
 
+int ge_state_get_n_paths (GeState *state)
+{
+  return g_list_length (state->paths);
+}
 #endif
diff --git a/bin/ui.h b/bin/ui.h
index b9775c9e0..b36112412 100644
--- a/bin/ui.h
+++ b/bin/ui.h
@@ -29,6 +29,7 @@ typedef struct _GeStateClass         GeStateClass;
  *
  */
 
+
 struct _GeState {
   GObject   parent;
   void      (*ui) (Mrg *mrg, void *state);
@@ -128,7 +129,8 @@ struct _GeStateClass {
 
 GType        ge_state_get_type    (void) G_GNUC_CONST;
 GeState*     ge_state_new         (void);
-void         ge_state_greet       (GeState *state);
 
+const char *ge_state_get_path (GeState *state, int no);
+int         ge_state_get_n_paths (GeState *state);
 
 #endif


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