Jump to content

Unfinished plugins


xod

Recommended Posts

Nice start! Feel free to post your code if you want help.

Link to comment
Share on other sites

  • 2 weeks later...

I try to use OptionBasedLibrary but i can't figure out how to get the parameter Bold or Italic or both.

enum OptionNames
        {
            myFontStyle,
        ...
        }



enum FontStyleEnum
        {
            Bold,
            Italic
        }


protected override OptionControlList OnSetupOptions(OptionContext optContext)
        {
            return new OptionControlList
            {

new OptionEnumCheckBoxes<FontStyleEnum>(OptionNames.myFontStyle, optContext)
                { },
...


protected override void OnSetRenderInfo(OptionBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {

FontStyle myStyle = OptionEnumCheckBoxes<FontStyleEnum>.GetOptionChecked(OptionNames.myFontStyle, newToken.Items);

...

Error:
There is no argument given to corresponds to the required formal parameter 'values' of ...

Link to comment
Share on other sites

33 minutes ago, xod said:

I try to use OptionBasedLibrary but i can't figure out how to get the parameter Bold or Italic or both.

 

Replace FontStyle with FontStyleEnum.

FontStyleEnum myStyle = OptionEnumCheckBoxes<FontStyleEnum>.GetOptionChecked(OptionNames.myFontStyle, newToken.Items);

 

  • Upvote 2

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

Is there a way to make the VectorPan control background to have the color of the canvas?(OptionBasedLibrary)

 

ItTbkwj.png

 

Spoiler

new OptionDoubleVectorPan(OptionNames.VectorPan, optContext, 0, -1, 1, 0, -1, 1, false)//true = deactivate control
                {
                    DisplayName = "Position",//the control name displayed on the UI
                    StaticBitmapUnderlay = new Bitmap(80,60),//an image can be used here: new Bitmap(Image,80,60),
                    Indent = 0,//Indenting to the left of the window
                    //NumericUnitX = new NumericUnit("%"),
                    //NumericUnitY = new NumericUnit("%"),
                    UpDownIncrementX = 0.01,
                    UpDownIncrementY = 0.01,
                    ShowLineToCenter = true,
                    ViewOffset = 0,
                    ViewFactor = 1,
                    DecimalPlaces = 3,
                    ShowResetButton = true,
                    SliderShowTickMarks = false,
                    SliderSmallChangeX = 0.01,
                    SliderSmallChangeY = 0.01,
                    SliderLargeChangeX = 0.25,
                    SliderLargeChangeY = 0.25,
                    //Description = "Control Description",
                    GadgetScale = 1.5,
                    //Label = "Label:\nsome text\nhere"
                }

 

 

Link to comment
Share on other sites

52 minutes ago, xod said:

Is there a way to make the VectorPan control background to have the color of the canvas?(OptionBasedLibrary)

 

StaticBitmapUnderlay = this.EnvironmentParameters.SourceSurface.CreateAliasedBitmap(selection);

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

How to add list of installed font in a drop down?

new OptionEnumDropDown<FontFamily>(OptionNames.Test, optContext)

This does not work:   The type 'FontFamily' must be a non-nullabe value...

Link to comment
Share on other sites

Top effort! I'm impressed.

  • Like 2
Link to comment
Share on other sites

On 9/9/2018 at 6:59 PM, xod said:

How to add list of installed font in a drop down?

 

An OptionBasedEffect requires the DropDown items to be defined in an enum. However, you can't dynamically create an enum from a list of fonts.

 

IndirectUI is more flexible in this regard, since the items can be defined in an array of any type, or an enum.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

1 minute ago, xod said:

So there is no simple solution?

 

Correct.

 

Midora (Martin Osieka) hasn't been around for more than 18 months, but you could try to send him a PM with the feature request.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

3 hours ago, toe_head2001 said:

IndirectUI is more flexible in this regard, since the items can be defined in an array of any type, or an enum.

 

Perhaps I'm missing something, having never used the OptionBased library,  but that doesn't really seem like much of a limitation. Can't the integer returned by the control be used to index into an array of fonts? Returning anything but an index from a list control never struck me as that great of an advantage. It may save a few steps, but they're pretty simple steps.

  • Like 1
Link to comment
Share on other sites

1 minute ago, MJW said:

Perhaps I'm missing something, having never used the OptionBased library,  but that doesn't really seem like much of a limitation. Can't the integer returned by the control be used to index into an array of fonts? Returning anything but an index from a list control never struck me as that much of an advantage

 

The issue is not about the return value, but simply populating the DropDown.

You have to have an enum with all the DropDown items.

 

ie.

enum Fonts
{
	Arial,
	Consolas,
	Times New Roman,
	

	...
}

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

I see the problem. If the OptionBased library accepts only enums for the list values, that seems like a rather poor design choice, since it doesn't easily allow for any variable-length lists. There's no option to simply return the integer index of the selection? If the length of the list can be specified independently of the number of enum entries, then the  problem can be solved (simply, if not elegantly) by using an enum with the maximum number of entries. I expect it can't, though.

Link to comment
Share on other sites

34 minutes ago, xod said:

I looked at the PrintIt effect and it seems that OptionBased can display the list of installed fonts, but I don't know how ...

 

The implementation for the OptionFontName control is within PrintIt itself, and therefore can't be used by other plugins.

 

You could try to recreate it though. An OptionControl works like a UserControl.  ie: A control that houses a group of child controls.

 

Create a class that derives from OptionControl, and add the controls you need.

class MyCustomOptionControl : OptionControl
{
    ComboBox myDropDown = new ComboBox();
    TextBox myTextBox = new TextBox();
    CheckBox myCheckBox = new TextBox();


    MyCustomOptionControl()
    {

    }

}

 

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

36 minutes ago, xod said:

I looked at the PrintIt effect and it seems that OptionBased can display the list of installed fonts, but I don't know how ...

 

That control is part of PrintIt, not the OptionBased  library.

  • Like 1

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

@xod, I got a proof-of-concept working:

 

Spoiler

Add this class to your project.

 


    internal class OptionFontDropDown : OptionControl
    {
        private readonly ComboBox fontDropDown;
        private readonly int defaultIndex;

        internal OptionFontDropDown(Enum optId, OptionContext optContext)
            : this(optId, optContext, "Arial")
        {
        }

        internal OptionFontDropDown(Enum optId, OptionContext optContext, string defaultFont)
            : base(optId, optContext)
        {
            this.fontDropDown = new ComboBox();
            this.defaultIndex = FontUtil.FindFontIndex(defaultFont);

            this.fontDropDown.Items.AddRange(FontUtil.FontNames);
            this.fontDropDown.SelectedIndex = this.defaultIndex;
            this.fontDropDown.SelectedIndexChanged += (sender, e) => OnValueChanged();

            this.Controls.Add(fontDropDown);
        }

        public override void OptionDefaultToValues(OptionDictionary values)
        {
            values[this.Id] = FontUtil.FontNames[this.defaultIndex];
        }

        public override void OptionToValues(OptionDictionary values)
        {
            values[this.Id] = FontUtil.FontNames[this.fontDropDown.SelectedIndex];
        }

        public override void ValuesToOption(OptionDictionary values)
        {
            string fontName = (string)values[this.Id];
            fontDropDown.SelectedIndex = FontUtil.FindFontIndex(fontName);
        }

        protected override void OnReset()
        {
            fontDropDown.SelectedIndex = this.defaultIndex;
        }

        public static string GetOptionValue(Enum optId, OptionDictionary values)
        {
            return (string)values[optId.ToString()];
        }

        protected override void OnLayout(LayoutEventArgs e)
        {
            this.SetBounds(
                0,
                0,
                this.Parent?.Width ?? this.fontDropDown.Width + this.fontDropDown.Margin.Horizontal,
                this.fontDropDown.Height + this.fontDropDown.Margin.Vertical);

            base.OnLayout(e);
        }

        private static class FontUtil
        {
            internal static readonly string[] FontNames;

            internal static int FindFontIndex(string familyName)
            {
                for (int i = 0; i < FontNames.Length; i++)
                {
                    if (FontNames[i].Equals(familyName, StringComparison.OrdinalIgnoreCase))
                    {
                        return i;
                    }
                }

                return 0;
            }

            static FontUtil()
            {
                List<string> usableFonts = new List<string>();
                using (InstalledFontCollection intstalledFonts = new InstalledFontCollection())
                {
                    foreach (FontFamily font in intstalledFonts.Families)
                    {
                        usableFonts.Add(font.Name);
                    }
                }
                FontNames = usableFonts.ToArray();
            }
        }
    }

 

 

fontDropDown.png

Edited by toe_head2001
  • Like 1
  • Upvote 2

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

It is the same plugin made with the OptionBased library.

 

1. I can't figure out how to disable 'Inner circle', 'Outer circle' and 'Pen width' when I uncheck  'Draw the circles'.
2. If I modify the Alpha channel for any Colors tab and then run the Pan or Rotator controls (not the sliders) the canvas is not updated with the chosen color.

 

Download

Edited by xod
  • Like 1
Link to comment
Share on other sites

16 minutes ago, xod said:

1. I can't figure out how to disable 'Inner circle', 'Outer circle' and 'Pen width' when I uncheck 'Draw the circles'.

 

Did you take a look at the example in my 'Graph Paper' plugin?

https://github.com/toehead2001/pdn-graph-paper/blob/master/GraphPaper/GraphPaper.cs#L204

 

19 minutes ago, xod said:

2. If I modify the Alpha channel for any Colors tab and then run the Pan or Rotator controls (not the sliders) the canvas is not updated with the chosen color.

I'm guessing the Effect Token only gets updated when Focus leaves the Alpha textbox.  When you click on the Pan or the Rotator, the Focus remains in the textbox (as evidenced by the blinking text caret).

You might be able to create a work-around, but I'd have to take a close look at it to be sure.

(September 25th, 2023)  Sorry about any broken images in my posts. I am aware of the issue.

bp-sig.png
My Gallery  |  My Plugin Pack

Layman's Guide to CodeLab

Link to comment
Share on other sites

  • 2 weeks later...

I'm trying to translate my plugins into my language and everything goes right except for the title in the

window that remains unchanged. Is there a trick I should know?

Spoiler

public string DisplayName => LangStrings.EffectName;

using System.Globalization;

namespace TestEffect
{
    internal static class LangStrings
    {
        private static readonly string UICulture = CultureInfo.CurrentUICulture.Name;

        internal static string EffectName
        {
            get
            {
                switch (UICulture)
                {
                    case "ro":
                        return "The effect name in my language";
                    default:
                        return "The effect name in english";
                }
            }
        }
...

 

 

Link to comment
Share on other sites

Try

 

Spoiler

using System.Globalization;

namespace TestEffect
{
    public class PluginSupportInfo : IPluginSupportInfo
    {
        public string DisplayName => LangStrings.EffectName;
    }

    internal static class LangStrings
    {
        private static readonly string UICulture = CultureInfo.CurrentUICulture.Name;

        internal static string EffectName
        {
            get
            {
                switch (UICulture)
                {
                    case "ro":
                        return "The effect name in my language";
                    default:
                        return "The effect name in english";
                }
            }
        }
...

 

 

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...