xod

Unfinished plugins

Recommended Posts

Thought I'd share my WiP. It turns images into an array of isometric tiles that fit into a mesh. Sooo, it's not great. But... it's a start, I guess.

 

i9cXOOr.png

becomes

image.png.40ff97b02afbc9ef23e9aa56caaf0f50.png

becomes

Lzp8mv8.png

Edited by Mallaboro

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
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"
                }

 

 

Share this post


Link to post
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);

Share this post


Link to post
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...

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
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,
	

	...
}

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

 

FgQrdAu.png

Share this post


Link to post
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()
    {

    }

}

 

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now