Jump to content

New to Visual Studio Editing


Recommended Posts

Hi, I'm not exactly sure if I know what I'm doing and I'm working from GmicSharpPDNExample.

 

First, what do I do with CreateForEnum as it gives me a error?

Spoiler


        protected override PropertyCollection OnCreatePropertyCollection()
        {
            Property[] props = new Property[]
            {
                new StaticListChoiceProperty.CreateForEnum<color_spaceOptions>(PropertyNames.color_space,0,false),
                new StaticListChoiceProperty.CreateForEnum<tiled_formOptions>(PropertyNames.tiled_form,0,false),
                new BooleanProperty(PropertyNames.use_clipboard_as_tile, false),
                new Int32Property(PropertyNames.shape_w, 30, 0, 100),
                new Int32Property(PropertyNames.shape_h, 30, 0, 100),
                new DoubleProperty(PropertyNames.shape_ratio, 100, .1, 100),
                new DoubleProperty(PropertyNames.shape_rotation, 45.0, -180, 180),
                new StaticListChoiceProperty.CreateForEnum<shape_mirror_axisOptions>(PropertyNames.shape_mirror_axis,0,false),
                new DoubleProperty(PropertyNames.sublevel, 1, .5, 2),
                new StaticListChoiceProperty.CreateForEnum<interpolationOptions>(PropertyNames.interpolation,0,false),
                new StaticListChoiceProperty.CreateForEnum<preprocessOptions>(PropertyNames.tile_boundary,0,false),
                new StaticListChoiceProperty.CreateForEnum<preprocessOptions>(PropertyNames.preprocess,0,false),
                new BooleanProperty(PropertyNames.fit_tile, true)
            };

            return new PropertyCollection(props);
        }

 

 

Second, what do I do with #if #endif statements found within all of the codes here.

 

Spoiler



#define USE_CLIPBOARD

using GmicSharpPdn;
using PaintDotNet;
using PaintDotNet.AppModel;
using PaintDotNet.Effects;
using PaintDotNet.IndirectUI;
using PaintDotNet.PropertySystem;
using System.Drawing;
using System.Globalization;
using System.Reflection;

#if USE_CLIPBOARD
using PaintDotNet.Clipboard;
#endif

namespace Tiled_Form
{
    [PluginSupportInfo(typeof(PluginSupportInfo))]
    public sealed class TiledFormGmicPdnPlugin : PropertyBasedEffect
    {
        public TiledFormGmicPdnPlugin()
            : base("Tiled Form", null, SubmenuNames.Artistic, new EffectOptions { Flags = EffectFlags.Configurable })
        {
        }

        private enum PropertyNames
        {
            color_space,
            tiled_form,
            use_clipboard_as_tile,
            shape_w,
            shape_h,
            shape_ratio,
            shape_rotation,
            shape_mirror_axis,
            sublevel,
            interpolation,
            tile_boundary,
            preprocess,
            fit_tile          
        }

        public enum color_spaceOptions
        {
            color_spaceOption1,
            color_spaceOption2,
            color_spaceOption3,
            color_spaceOption4,
            color_spaceOption5,
            color_spaceOption6,
            color_spaceOption7,
            color_spaceOption8,
            color_spaceOption9
        }

        public enum tiled_formOptions
        {
            tiled_formOption1,
            tiled_formOption2,
            tiled_formOption3,
            tiled_formOption4,
            tiled_formOption5,
            tiled_formOption6,
            tiled_formOption7,
            tiled_formOption8,
            tiled_formOption9,
            tiled_formOption10,
            tiled_formOption11,
            tiled_formOption12,
            tiled_formOption13,
            tiled_formOption14,
            tiled_formOption15,
            tiled_formOption16,
            tiled_formOption17,
            tiled_formOption18,
            tiled_formOption19,
            tiled_formOption20,
            tiled_formOption21
        }
        public enum shape_mirror_axisOptions
        {
            shape_mirror_axisOption1,
            shape_mirror_axisOption2,
            shape_mirror_axisOption3
        }
        public enum interpolationOptions
        {
            interpolationOption1,
            interpolationOption2,
            interpolationOption3,
            interpolationOption4,
            interpolationOption5,
            interpolationOption6
        }
        public enum tile_boundaryOptions
        {
            tile_boundaryOption1,
            tile_boundaryOption2,
            tile_boundaryOption3,
            tile_boundaryOption4
        }
        public enum preprocessOptions
        {
            preprocessOption1,
            preprocessOption2,
            preprocessOption3
        }

        protected override PropertyCollection OnCreatePropertyCollection()
        {
            Property[] props = new Property[]
            {
                new StaticListChoiceProperty.CreateForEnum<color_spaceOptions>(PropertyNames.color_space,0,false),
                new StaticListChoiceProperty.CreateForEnum<tiled_formOptions>(PropertyNames.tiled_form,0,false),
                new BooleanProperty(PropertyNames.use_clipboard_as_tile, false),
                new Int32Property(PropertyNames.shape_w, 30, 0, 100),
                new Int32Property(PropertyNames.shape_h, 30, 0, 100),
                new DoubleProperty(PropertyNames.shape_ratio, 100, .1, 100),
                new DoubleProperty(PropertyNames.shape_rotation, 45.0, -180, 180),
                new StaticListChoiceProperty.CreateForEnum<shape_mirror_axisOptions>(PropertyNames.shape_mirror_axis,0,false),
                new DoubleProperty(PropertyNames.sublevel, 1, .5, 2),
                new StaticListChoiceProperty.CreateForEnum<interpolationOptions>(PropertyNames.interpolation,0,false),
                new StaticListChoiceProperty.CreateForEnum<preprocessOptions>(PropertyNames.tile_boundary,0,false),
                new StaticListChoiceProperty.CreateForEnum<preprocessOptions>(PropertyNames.preprocess,0,false),
                new BooleanProperty(PropertyNames.fit_tile, true)
            };

            return new PropertyCollection(props);
        }

        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);
            configUI.SetPropertyControlValue(PropertyNames.color_space, ControlInfoPropertyNames.DisplayName, "Color Space");
            PropertyControlInfo cs_choice = configUI.FindControlForPropertyName(PropertyNames.color_space);
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption1, "RGB");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption2, "RYB");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption3, "CMYK");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption4, "HCY");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption5, "HSI");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption6, "HSL");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption7, "HSV");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption8, "LAB");
            cs_choice.SetValueDisplayName(color_spaceOptions.color_spaceOption9, "LCH");
            configUI.SetPropertyControlValue(PropertyNames.tiled_form, ControlInfoPropertyNames.DisplayName, "Tiled Form");
            PropertyControlInfo tile_choice= configUI.FindControlForPropertyName(PropertyNames.tiled_form);
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption1, "Australia");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption2, "Barbed Wire");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption3, "Circle");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption4, "Cupid");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption5, "Diamond");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption6, "Dragonfly");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption7, "Flip");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption8, "Gumleaf");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption9, "Heart");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption10, "Information");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption11, "Kookaburra");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption12, "Mail");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption13, "Mapleleaf");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption14, "Paint Splat");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption15, "Paw");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption16, "Phone");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption17, "Polygon-[D]");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption18, "Rooster");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption19, "Shopping Cart");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption20, "Snowflake-[D]");
            tile_choice.SetValueDisplayName(tiled_formOptions.tiled_formOption21, "Star-[D]");
            configUI.SetPropertyControlValue(PropertyNames.use_clipboard_as_tile, ControlInfoPropertyNames.Description, "Use Clipboard as Tile");
            configUI.SetPropertyControlValue(PropertyNames.shape_w, ControlInfoPropertyNames.DisplayName, "Shape Width");
            configUI.SetPropertyControlValue(PropertyNames.shape_h, ControlInfoPropertyNames.DisplayName, "Shape Height");
            configUI.SetPropertyControlValue(PropertyNames.shape_ratio, ControlInfoPropertyNames.DisplayName, "Shape Ratio (%)");
            configUI.SetPropertyControlValue(PropertyNames.shape_ratio, ControlInfoPropertyNames.SliderLargeChange, 10);
            configUI.SetPropertyControlValue(PropertyNames.shape_ratio, ControlInfoPropertyNames.SliderSmallChange, 1);
            configUI.SetPropertyControlValue(PropertyNames.shape_ratio, ControlInfoPropertyNames.UpDownIncrement, 1);
            configUI.SetPropertyControlValue(PropertyNames.shape_ratio, ControlInfoPropertyNames.DecimalPlaces, 1);
            configUI.SetPropertyControlValue(PropertyNames.shape_mirror_axis, ControlInfoPropertyNames.DisplayName, "Color Space");
            PropertyControlInfo mirror_axis = configUI.FindControlForPropertyName(PropertyNames.shape_mirror_axis);
            mirror_axis.SetValueDisplayName(shape_mirror_axisOptions.shape_mirror_axisOption1, "None");
            mirror_axis.SetValueDisplayName(shape_mirror_axisOptions.shape_mirror_axisOption2, "X");
            mirror_axis.SetValueDisplayName(shape_mirror_axisOptions.shape_mirror_axisOption3, "Y");
            configUI.SetPropertyControlValue(PropertyNames.sublevel, ControlInfoPropertyNames.DisplayName, "Sublevel");
            configUI.SetPropertyControlValue(PropertyNames.sublevel, ControlInfoPropertyNames.SliderLargeChange, .1);
            configUI.SetPropertyControlValue(PropertyNames.sublevel, ControlInfoPropertyNames.SliderSmallChange, .01);
            configUI.SetPropertyControlValue(PropertyNames.sublevel, ControlInfoPropertyNames.UpDownIncrement, 1);
            configUI.SetPropertyControlValue(PropertyNames.sublevel, ControlInfoPropertyNames.DecimalPlaces, 2);
            PropertyControlInfo interp_choice = configUI.FindControlForPropertyName(PropertyNames.interpolation);
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Nearest");
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Average");
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Linear");
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Grid");
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Bicubic");
            interp_choice.SetValueDisplayName(interpolationOptions.interpolationOption1, "Lanczos");
            PropertyControlInfo tile_boundary_choice = configUI.FindControlForPropertyName(PropertyNames.tile_boundary);
            tile_boundary_choice.SetValueDisplayName(tile_boundaryOptions.tile_boundaryOption1, "Periodic");
            tile_boundary_choice.SetValueDisplayName(tile_boundaryOptions.tile_boundaryOption2, "Mirror - X");
            tile_boundary_choice.SetValueDisplayName(tile_boundaryOptions.tile_boundaryOption3, "Mirror - Y");
            tile_boundary_choice.SetValueDisplayName(tile_boundaryOptions.tile_boundaryOption4, "Mirror - XY");
            PropertyControlInfo preprocess_choice = configUI.FindControlForPropertyName(PropertyNames.preprocess);
            preprocess_choice.SetValueDisplayName(preprocessOptions.preprocessOption1, "Neumann");
            preprocess_choice.SetValueDisplayName(preprocessOptions.preprocessOption2, "Periodic");
            preprocess_choice.SetValueDisplayName(preprocessOptions.preprocessOption3, "Mirror");
            configUI.SetPropertyControlValue(PropertyNames.fit_tile, ControlInfoPropertyNames.Description, "Fit Tile");

            return configUI;
        }

        protected override void OnCustomizeConfigUIWindowProperties(PropertyCollection props)
        {
            // Add help button to effect UI
            props[ControlInfoPropertyNames.WindowTitle].Value = "Tiled Form - G'MIC-QT";
            props[ControlInfoPropertyNames.WindowHelpContentType].Value = WindowHelpContentType.PlainText;

            Assembly assembly = typeof(TiledFormGmicPdnPlugin).Assembly;

            string fileVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
            string copyright = assembly.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;

            props[ControlInfoPropertyNames.WindowHelpContent].Value = $"Tiled_Form v{ fileVersion }\n\n{ copyright }\nAll rights reserved.";

            base.OnCustomizeConfigUIWindowProperties(props);
        }

        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int color_space_id = newToken.GetProperty<Int32Property>(PropertyNames.color_space).Value;
            double tile_id = newToken.GetProperty<Int32Property>(PropertyNames.tiled_form).Value;
            bool use_clipboard = newToken.GetProperty<BooleanProperty>(PropertyNames.use_clipboard_as_tile).Value;
            int tile_w = newToken.GetProperty<Int32Property>(PropertyNames.shape_w).Value;
            int tile_h = newToken.GetProperty<Int32Property>(PropertyNames.shape_h).Value;
            double ratio = newToken.GetProperty<DoubleProperty>(PropertyNames.shape_ratio).Value;
            double rotation = newToken.GetProperty<DoubleProperty>(PropertyNames.shape_rotation).Value;
            int shape_mirror_axis_mode = newToken.GetProperty<Int32Property>(PropertyNames.shape_mirror_axis).Value;
            double subpixel_process = newToken.GetProperty<DoubleProperty>(PropertyNames.sublevel).Value;
            int interp = newToken.GetProperty<Int32Property>(PropertyNames.interpolation).Value;
            int tile_bound_id = newToken.GetProperty<Int32Property>(PropertyNames.tile_boundary).Value;
            int preprocess_id = newToken.GetProperty<Int32Property>(PropertyNames.preprocess).Value;
            bool ftmode = newToken.GetProperty<BooleanProperty>(PropertyNames.fit_tile).Value;

            using (PdnGmicSharp gmic = new PdnGmicSharp())
            {
                // Add the source surface as the first input image.
                using (PdnGmicBitmap source = new PdnGmicBitmap(srcArgs.Surface))
                {
                    gmic.AddInputImage(source);
                }

                // The following code demonstrates adding an image
                // from the clipboard as a second G'MIC surface.
#if USE_CLIPBOARD
                IClipboardService clipboard = this.Services.GetService<IClipboardService>();

                Surface clipboardSurface = clipboard.TryGetSurface();

                try
                {
                    if (clipboardSurface != null)
                    {
                        using (PdnGmicBitmap clipboardBitmap = new PdnGmicBitmap(clipboardSurface, true))
                        {
                            // The PdnGmicBitmap takes ownership of the clipboard surface.
                            clipboardSurface = null;

                            gmic.AddInputImage(clipboardBitmap);
                        }
                    }
                }
                finally
                {
                    clipboardSurface?.Dispose();
                }
#endif

                string command = string.Format(CultureInfo.InvariantCulture,
                                               "rep_test_pdn");

                // Run the G'MIC command and allow it to receive cancellation info from Paint.NET.
                gmic.RunGmic(command, () => this.IsCancelRequested);

                if (gmic.Error != null)
                {
                    this.Services.GetService<IExceptionDialogService>().ShowErrorDialog(null, gmic.Error);
                }
                else if (!gmic.Canceled)
                {
                    Surface output = gmic.OutputImages?[0]?.Surface;

                    if (output != null)
                    {
                        // Copy the rendered G'MIC image to the destination surface,
                        // and restrict the copied portions to the user's selection.
                        dstArgs.Surface.CopySurface(output, this.EnvironmentParameters.GetSelectionAsPdnRegion());
                    }
                }
            }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }

        protected override void OnRender(Rectangle[] renderRects, int startIndex, int length)
        {
            // All work is performed in OnSetRenderInfo.
        }
    }
}

 

 

Third, is there more to point out here? I'm not exactly sure if I'm on the right route as I don't know what to question other than those.

 

EDIT: After removing the new from StaticCast, it finally can build. However, it crash pdn because cast is invalid. What to do from here?

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

Never mind, I succeeded in getting it to run. Now, I can make a GMIC-C# PDN plugin! Though one question remainss.

 

How come I'm not getting RGB,RYB under first dropdown option?

 

Spoiler




#define USE_CLIPBOARD

using GmicSharpPdn;
using PaintDotNet;
using PaintDotNet.AppModel;
using PaintDotNet.Effects;
using PaintDotNet.IndirectUI;
using PaintDotNet.PropertySystem;
using System.Drawing;
using System.Globalization;
using System.Reflection;

#if USE_CLIPBOARD
using PaintDotNet.Clipboard;
#endif

namespace Tiled_Form
{
    [PluginSupportInfo(typeof(PluginSupportInfo))]
    public sealed class TiledFormGmicPdnPlugin : PropertyBasedEffect
    {
        public TiledFormGmicPdnPlugin()
            : base("Tiled Form", null, SubmenuNames.Artistic, new EffectOptions { Flags = EffectFlags.Configurable })
        {
        }

        private enum PropertyNames
        {
            Cs_mode,
            Pretile_mode,
            Use_clipboard_as_tile,
            Shape_w,
            Shape_h,
            Shape_ratio,
            Shape_ang,
            Shape_axis,
            Sub,
            Interp,
            Tile_b,
            Preprocess,
            Fit_tile
        }

        public enum color_spaceOptions
        {
            color_spaceOption1,
            color_spaceOption2,
            color_spaceOption3,
            color_spaceOption4,
            color_spaceOption5,
            color_spaceOption6,
            color_spaceOption7,
            color_spaceOption8,
            color_spaceOption9
        }

        public enum Cs_modeOptions
        {
            Cs_modeOption1,
            Cs_modeOption2,
            Cs_modeOption3,
            Cs_modeOption4,
            Cs_modeOption5,
            Cs_modeOption6,
            Cs_modeOption7,
            Cs_modeOption8,
            Cs_modeOption9
        }

        public enum Pretile_modeOptions
        {
            Pretile_modeOption1,
            Pretile_modeOption2,
            Pretile_modeOption3,
            Pretile_modeOption4,
            Pretile_modeOption5,
            Pretile_modeOption6,
            Pretile_modeOption7,
            Pretile_modeOption8,
            Pretile_modeOption9,
            Pretile_modeOption10,
            Pretile_modeOption11,
            Pretile_modeOption12,
            Pretile_modeOption13,
            Pretile_modeOption14,
            Pretile_modeOption15,
            Pretile_modeOption16,
            Pretile_modeOption17,
            Pretile_modeOption18,
            Pretile_modeOption19,
            Pretile_modeOption20,
            Pretile_modeOption21,
            Pretile_modeOption22,
            Pretile_modeOption23
        }

        public enum Shape_axisOptions
        {
            Shape_axisOption1,
            Shape_axisOption2,
            Shape_axisOption3
        }

        public enum InterpOptions
        {
            InterpOption1,
            InterpOption2,
            InterpOption3,
            InterpOption4,
            InterpOption5
        }

        public enum Tile_bOptions
        {
            Tile_bOption1,
            Tile_bOption2,
            Tile_bOption3,
            Tile_bOption4
        }

        public enum PreprocessOptions
        {
            PreprocessOption1,
            PreprocessOption2,
            PreprocessOption3
        }

        protected override PropertyCollection OnCreatePropertyCollection()
        {
            Property[] props = new Property[]
            {
                StaticListChoiceProperty.CreateForEnum<color_spaceOptions>(PropertyNames.Cs_mode,0,false),
                StaticListChoiceProperty.CreateForEnum<Pretile_modeOptions>(PropertyNames.Pretile_mode,0,false),
                new BooleanProperty(PropertyNames.Use_clipboard_as_tile, false),
                new Int32Property(PropertyNames.Shape_w, 30, 0, 100),
                new Int32Property(PropertyNames.Shape_h, 30, 0, 100),
                new DoubleProperty(PropertyNames.Shape_ratio, 100, .1, 100),
                new DoubleProperty(PropertyNames.Shape_ang, 0, -180, 180),
                StaticListChoiceProperty.CreateForEnum<Shape_axisOptions>(PropertyNames.Shape_axis,0,false),
                new DoubleProperty(PropertyNames.Sub, 1, .5, 2),
                StaticListChoiceProperty.CreateForEnum<InterpOptions>(PropertyNames.Interp,0,false),
                StaticListChoiceProperty.CreateForEnum<Tile_bOptions>(PropertyNames.Tile_b,0,false),
                StaticListChoiceProperty.CreateForEnum<PreprocessOptions>(PropertyNames.Preprocess,0,false),
                new BooleanProperty(PropertyNames.Fit_tile, true)
            };

            return new PropertyCollection(props);
        }

        protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
        {
            ControlInfo configUI = CreateDefaultConfigUI(props);
            configUI.SetPropertyControlValue(PropertyNames.Cs_mode, ControlInfoPropertyNames.DisplayName, "Color Space");
            PropertyControlInfo Cs_modeControl = configUI.FindControlForPropertyName(PropertyNames.Cs_mode);
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption1, "RGB");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption2, "RYB");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption3, "CMYK");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption4, "HCY");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption5, "HSI");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption6, "HSL");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption7, "HSV");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption8, "LAB");
            Cs_modeControl.SetValueDisplayName(Cs_modeOptions.Cs_modeOption9, "LCH");
            configUI.SetPropertyControlValue(PropertyNames.Pretile_mode, ControlInfoPropertyNames.DisplayName, "Tiled Form");
            PropertyControlInfo Pretile_modeControl = configUI.FindControlForPropertyName(PropertyNames.Pretile_mode);
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption1, "Australia");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption2, "Barbed Wire");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption3, "Circle");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption4, "Crosshair");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption5, "Cupid");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption6, "Diamond");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption7, "Dragonfly");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption8, "Flip");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption9, "Gear");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption10, "Gumleaf");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption11, "Heart");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption12, "Information");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption13, "Kookaburra");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption14, "Mail");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption15, "Mapleleaf");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption16, "Paint Splat");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption17, "Paw");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption18, "Phone");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption19, "Polygon (Dynamic)");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption20, "Rooster");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption21, "Shopping Cart");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption22, "Snowflake (Dynamic)");
            Pretile_modeControl.SetValueDisplayName(Pretile_modeOptions.Pretile_modeOption23, "Star (Dynamic)");
            configUI.SetPropertyControlValue(PropertyNames.Use_clipboard_as_tile, ControlInfoPropertyNames.DisplayName, string.Empty);
            configUI.SetPropertyControlValue(PropertyNames.Use_clipboard_as_tile, ControlInfoPropertyNames.Description, "Use Clipboard as Tile?");
            configUI.SetPropertyControlValue(PropertyNames.Shape_w, ControlInfoPropertyNames.DisplayName, "Shape Width");
            configUI.SetPropertyControlValue(PropertyNames.Shape_h, ControlInfoPropertyNames.DisplayName, "Shape Height");
            configUI.SetPropertyControlValue(PropertyNames.Shape_ratio, ControlInfoPropertyNames.DisplayName, "Shape Ratio (%)");
            configUI.SetPropertyControlValue(PropertyNames.Shape_ratio, ControlInfoPropertyNames.SliderLargeChange, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Shape_ratio, ControlInfoPropertyNames.SliderSmallChange, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Shape_ratio, ControlInfoPropertyNames.UpDownIncrement, 0.01);
            configUI.SetPropertyControlValue(PropertyNames.Shape_ratio, ControlInfoPropertyNames.DecimalPlaces, 3);
            configUI.SetPropertyControlValue(PropertyNames.Shape_ang, ControlInfoPropertyNames.DisplayName, "Shape Rotation");
            configUI.SetPropertyControlType(PropertyNames.Shape_ang, PropertyControlType.AngleChooser);
            configUI.SetPropertyControlValue(PropertyNames.Shape_ang, ControlInfoPropertyNames.DecimalPlaces, 3);
            configUI.SetPropertyControlValue(PropertyNames.Shape_axis, ControlInfoPropertyNames.DisplayName, "Shape Mirror Axis");
            PropertyControlInfo Shape_axisControl = configUI.FindControlForPropertyName(PropertyNames.Shape_axis);
            Shape_axisControl.SetValueDisplayName(Shape_axisOptions.Shape_axisOption1, "None");
            Shape_axisControl.SetValueDisplayName(Shape_axisOptions.Shape_axisOption2, "X");
            Shape_axisControl.SetValueDisplayName(Shape_axisOptions.Shape_axisOption3, "Y");
            configUI.SetPropertyControlValue(PropertyNames.Sub, ControlInfoPropertyNames.DisplayName, "Subpixel Level");
            configUI.SetPropertyControlValue(PropertyNames.Sub, ControlInfoPropertyNames.SliderLargeChange, 0.25);
            configUI.SetPropertyControlValue(PropertyNames.Sub, ControlInfoPropertyNames.SliderSmallChange, 0.05);
            configUI.SetPropertyControlValue(PropertyNames.Sub, ControlInfoPropertyNames.UpDownIncrement, 0.01);
            configUI.SetPropertyControlValue(PropertyNames.Sub, ControlInfoPropertyNames.DecimalPlaces, 3);
            configUI.SetPropertyControlValue(PropertyNames.Interp, ControlInfoPropertyNames.DisplayName, "Interpolation");
            PropertyControlInfo InterpControl = configUI.FindControlForPropertyName(PropertyNames.Interp);
            InterpControl.SetValueDisplayName(InterpOptions.InterpOption1, "Nearest");
            InterpControl.SetValueDisplayName(InterpOptions.InterpOption2, "Average");
            InterpControl.SetValueDisplayName(InterpOptions.InterpOption3, "Linear");
            InterpControl.SetValueDisplayName(InterpOptions.InterpOption4, "Grid");
            InterpControl.SetValueDisplayName(InterpOptions.InterpOption5, "Bicubic");
            configUI.SetPropertyControlValue(PropertyNames.Tile_b, ControlInfoPropertyNames.DisplayName, "Tile Boundary");
            PropertyControlInfo Tile_bControl = configUI.FindControlForPropertyName(PropertyNames.Tile_b);
            Tile_bControl.SetValueDisplayName(Tile_bOptions.Tile_bOption1, "Periodic");
            Tile_bControl.SetValueDisplayName(Tile_bOptions.Tile_bOption2, "Mirror X");
            Tile_bControl.SetValueDisplayName(Tile_bOptions.Tile_bOption3, "Mirror Y");
            Tile_bControl.SetValueDisplayName(Tile_bOptions.Tile_bOption4, "Mirror XY");
            configUI.SetPropertyControlValue(PropertyNames.Preprocess, ControlInfoPropertyNames.DisplayName, "Preprocess");
            PropertyControlInfo PreprocessControl = configUI.FindControlForPropertyName(PropertyNames.Preprocess);
            PreprocessControl.SetValueDisplayName(PreprocessOptions.PreprocessOption1, "Neumann");
            PreprocessControl.SetValueDisplayName(PreprocessOptions.PreprocessOption2, "Periodic");
            PreprocessControl.SetValueDisplayName(PreprocessOptions.PreprocessOption3, "Mirror");
            configUI.SetPropertyControlValue(PropertyNames.Fit_tile, ControlInfoPropertyNames.DisplayName, string.Empty);
            configUI.SetPropertyControlValue(PropertyNames.Fit_tile, ControlInfoPropertyNames.Description, "Fit Tile");

            return configUI;
        }

        protected override void OnCustomizeConfigUIWindowProperties(PropertyCollection props)
        {
            // Add help button to effect UI
            props[ControlInfoPropertyNames.WindowTitle].Value = "Tiled Form - G'MIC-QT";
            props[ControlInfoPropertyNames.WindowHelpContentType].Value = WindowHelpContentType.PlainText;

            Assembly assembly = typeof(TiledFormGmicPdnPlugin).Assembly;

            string fileVersion = assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
            string copyright = assembly.GetCustomAttribute<AssemblyCopyrightAttribute>().Copyright;

            props[ControlInfoPropertyNames.WindowHelpContent].Value = $"Tiled_Form v{ fileVersion }\n\n{ copyright }\nAll rights reserved.";

            base.OnCustomizeConfigUIWindowProperties(props);
        }

        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int color_space_id = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Cs_mode).Value; ;
            double tile_id = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Pretile_mode).Value;
            bool use_clipboard = newToken.GetProperty<BooleanProperty>(PropertyNames.Use_clipboard_as_tile).Value;
            int tile_w = newToken.GetProperty<Int32Property>(PropertyNames.Shape_w).Value;
            int tile_h = newToken.GetProperty<Int32Property>(PropertyNames.Shape_h).Value;
            double ratio = newToken.GetProperty<DoubleProperty>(PropertyNames.Shape_ratio).Value;
            double rotation = newToken.GetProperty<DoubleProperty>(PropertyNames.Shape_ang).Value;
            int shape_mirror_axis_mode = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Shape_axis).Value;
            double subpixel_process = newToken.GetProperty<DoubleProperty>(PropertyNames.Sub).Value;
            int interp = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Interp).Value;
            int tile_bound_id = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Tile_b).Value;
            int preprocess_id = (byte)(int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Preprocess).Value;
            bool ftmode = newToken.GetProperty<BooleanProperty>(PropertyNames.Fit_tile).Value;

            using (PdnGmicSharp gmic = new PdnGmicSharp())
            {
                // Add the source surface as the first input image.
                using (PdnGmicBitmap source = new PdnGmicBitmap(srcArgs.Surface))
                {
                    gmic.AddInputImage(source);
                }

                // The following code demonstrates adding an image
                // from the clipboard as a second G'MIC surface.
#if USE_CLIPBOARD
                IClipboardService clipboard = this.Services.GetService<IClipboardService>();

                Surface clipboardSurface = clipboard.TryGetSurface();

                try
                {
                    if (clipboardSurface != null)
                    {
                        using (PdnGmicBitmap clipboardBitmap = new PdnGmicBitmap(clipboardSurface, true))
                        {
                            // The PdnGmicBitmap takes ownership of the clipboard surface.
                            clipboardSurface = null;

                            gmic.AddInputImage(clipboardBitmap);
                        }
                    }
                }
                finally
                {
                    clipboardSurface?.Dispose();
                }
#endif

                string command = string.Format(CultureInfo.InvariantCulture,
                                               "f i%64");

                // Run the G'MIC command and allow it to receive cancellation info from Paint.NET.
                gmic.RunGmic(command, () => this.IsCancelRequested);

                if (gmic.Error != null)
                {
                    this.Services.GetService<IExceptionDialogService>().ShowErrorDialog(null, gmic.Error);
                }
                else if (!gmic.Canceled)
                {
                    Surface output = gmic.OutputImages?[0]?.Surface;

                    if (output != null)
                    {
                        // Copy the rendered G'MIC image to the destination surface,
                        // and restrict the copied portions to the user's selection.
                        dstArgs.Surface.CopySurface(output, this.EnvironmentParameters.GetSelectionAsPdnRegion());
                    }
                }
            }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }

        protected override void OnRender(Rectangle[] renderRects, int startIndex, int length)
        {
            // All work is performed in OnSetRenderInfo.
        }
    }
}

 

 

EDIT: I solved that now. Also, it's great that I am able to use user.gmic scripts file rather than prebuilt gmic script, so that I can make appropriate changes in context of pdn plugins. Though I did found that the script aren't done internally. I have to ask @null54. Do I need gmicxxxx.gmic files to make the pdn dll work?

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

25 minutes ago, Reptillian said:

Do I need gmicxxxx.gmic files to make the pdn dll work?

 

I do not think so.

It should use the files in %APPDATA%\gmic.

PdnSig.png

Plugin Pack | PSFilterPdn | Content Aware Fill | G'MICPaint Shop Pro Filetype | RAW Filetype | WebP Filetype

The small increase in performance you get coding in C++ over C# is hardly enough to offset the headache of coding in the C++ language. ~BoltBait

 

Link to comment
Share on other sites

34 minutes ago, null54 said:

 

I do not think so.

It should use the files in %APPDATA%\gmic.

 

So, users will need to download updatexxx.gmic files and drop it into a new folder called gmic inside %appdata% if they didn't install gmic?

 

EDIT: I found out that by deleting updatexxx inside %appdata%, you don't need to install gmic to be able to use the built dll. So, now I know what to do.

Edited by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...