Browse Source

scripts sub menus

johann 5 years ago
parent
commit
0f018aa878

+ 44 - 9
lazpaint/umenu.pas

@@ -240,6 +240,47 @@ begin
 end;
 
 procedure TMainFormMenu.AddInstalledScripts(AMenu: TMenuItem; AIndex: integer);
+
+  procedure AddScriptRec(AMenu: TMenuItem; var AIndex: integer; AItem: TMenuItem);
+  var
+    posSub, j, subIndex: integer;
+    sectionName: String;
+    sectionItem: TMenuItem;
+  begin
+    posSub := pos('>', AItem.Caption);
+    if posSub > 0 then
+    begin
+      sectionName := copy(AItem.Caption, 1, posSub-1);
+      AItem.Caption := copy(AItem.Caption, posSub+1, length(AItem.Caption) - posSub);
+      subIndex := -1;
+      for j := 0 to AMenu.Count-1 do
+        if AMenu.Items[j].Caption = sectionName then
+        begin
+          AddScriptRec(AMenu.Items[j], subIndex, AItem);
+          exit;
+        end;
+      sectionItem := TMenuItem.Create(AMenu);
+      sectionItem.Caption := sectionName;
+      if AIndex = -1 then
+        AMenu.Add(sectionItem)
+      else
+      begin
+        AMenu.Insert(AIndex, sectionItem);
+        inc(AIndex);
+      end;
+      AddScriptRec(sectionItem, subIndex, AItem);
+      exit;
+    end;
+
+    if AIndex = -1 then
+      AMenu.Add(AItem)
+    else
+    begin
+      AMenu.Insert(AIndex, AItem);
+      inc(AIndex);
+    end;
+  end;
+
 var
   path, fullname, header, title: String;
   searchRec: TSearchRec;
@@ -266,6 +307,8 @@ begin
           if header.StartsWith('#') then
           begin
             title := header.Substring(1).Trim;
+            title := StringReplace(title, ' >', '>', [rfReplaceAll]);
+            title := StringReplace(title, '> ', '>', [rfReplaceAll]);
             item := TMenuItem.Create(AMenu);
             item.Caption := title;
             item.Tag := FInstalledScripts.Add(fullname);
@@ -277,15 +320,7 @@ begin
     finally
       FindCloseUTF8(searchRec);
       for i := 0 to items.Count-1 do
-      begin
-        if AIndex = -1 then
-          AMenu.Add(TMenuItem(items.Objects[i]))
-        else
-        begin
-          AMenu.Insert(AIndex, TMenuItem(items.Objects[i]));
-          inc(AIndex);
-        end;
-      end;
+        AddScriptRec(AMenu, AIndex, TMenuItem(items.Objects[i]));
       items.Free;
     end;
   end;

+ 1 - 1
scripts/merge_channels.py → scripts/channels_merge.py

@@ -1,4 +1,4 @@
-# Merge channels
+# Channels > Merge
 from lazpaint import image, dialog, layer
 
 channels_id = None

+ 1 - 1
scripts/split_hsl_native.py → scripts/channels_split_hsl.py

@@ -1,4 +1,4 @@
-# Split HSL channels
+# Channels > Split HSL
 from lazpaint import image, dialog, layer, filters
 
 # check if it is a channel

+ 1 - 1
scripts/split_rgb_native.py → scripts/channels_split_rgb.py

@@ -1,4 +1,4 @@
-# Split RGB channels
+# Channels > Split RGB
 from lazpaint import image, dialog, layer, filters
 
 # check if it is a channel

+ 1 - 1
scripts/color_overlay.py → scripts/layerfx_color_overlay.py

@@ -1,4 +1,4 @@
-# Color overlay
+# Layer effect > Color overlay
 from lazpaint import image, colors, layer, filters
 
 color = colors.show_dialog(layer.get_registry("overlay-color"))

+ 1 - 1
scripts/layer_shadow.py → scripts/layerfx_shadow.py

@@ -1,4 +1,4 @@
-# Layer shadow
+# Layer effect > Drop shadow
 from lazpaint import dialog
 
 try:

+ 1 - 1
scripts/layer_stroke.py → scripts/layerfx_stroke.py

@@ -1,4 +1,4 @@
-# Layer stroke
+# Layer effect > Stroke
 from lazpaint import dialog
 
 try:

+ 12 - 0
scripts/mask_from_alpha.py

@@ -0,0 +1,12 @@
+# Mask > Mask from alpha channel
+from lazpaint import image, layer, filters, selection
+
+image.do_begin()
+
+selection.deselect()
+layer.duplicate()
+layer.set_name("Mask")
+filters.filter_function(red="alpha", green="alpha", blue="alpha", alpha=255, gamma_correction=False)
+layer.set_blend_op(layer.BLEND_MASK)
+
+image.do_end()

+ 1 - 1
scripts/new_mask.py → scripts/mask_new.py

@@ -1,4 +1,4 @@
-# New mask
+# Mask > New mask
 from lazpaint import image, layer, tools, colors, selection
 
 image.do_begin()

+ 1 - 1
scripts/fractal_tree.py → scripts/render_fractal_tree.py

@@ -1,4 +1,4 @@
-# Render fractal tree
+# Render > Fractal tree
 from lazpaint import tools, image, layer, dialog
 import math, random
 

+ 1 - 1
scripts/render_lava.py

@@ -1,4 +1,4 @@
-# Render Lava
+# Render > Lava
 from lazpaint import image, layer, filters, colors
 
 image.do_begin()