Jump to content

problems with IndirectUI, I think?


goatie
 Share

Recommended Posts

(using VS C# 2010 express)

Having cleaned up the VS c# template and got it building successfully, I suddenly hit 'no suitable method to override' with

protected override PropertyCollection OnCreatePropertyCollection()

protected override ControlInfo OnCreateConfigUI(PropertyCollection props)

protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)

and 'the name 'CreateDefaultConfigUI' does not exist in the current context' with

ControlInfo configUI = CreateDefaultConfigUI(props);

using System;

using System.Collections;

using System.Drawing;

using System.Drawing.Text;

using System.Collections.Generic;

using System.Reflection;

using System.Windows;

using System.Windows.Forms;

using System.Runtime.CompilerServices;

using System.Runtime.InteropServices;

using PaintDotNet;

using PaintDotNet.Effects;

using PaintDotNet.IndirectUI;

using PaintDotNet.PropertySystem;

are the dlls I'm including.

any ideas?

Link to comment
Share on other sites

No worries. I was just making sure my interpretation of what you described was what you intended (it was).

Can you show us more of the code?

You won't have methods like OnCreatePropertyCollection if you're deriving from Effect instead of PropertyBasedEffect, for instance.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

I started from the VS template, updated it to work with the current PDN, and am using Stuart Radforth's Rotate plugin to understand how everything fits together.

I've moved part of the code to another class file.

This is EffectPlugin.cs

using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Text;
using System.Collections.Generic;
using System.Reflection;
using System.Windows;
using System.Windows.Forms;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using PaintDotNet;
using PaintDotNet.Effects;
using PaintDotNet.IndirectUI;
using PaintDotNet.PropertySystem;
//using PaintDotNet.Rendering;
//using BlankEffect.pixelInterpolate;
namespace BlankEffect
{
   public class PictureRotatePlugin
    : PaintDotNet.Effects.Effect
   {
    public static string StaticName
    {
	    get
	    {
		    return "Effect Plugin";
	    }
    }

    public double Amount1 = 45; // [-180,180] Rotation
    public bool Amount3 = false; // [0,1] Disable Interpolation
    public byte Amount2 = 0; // [1] Limit Type|Clamp|Wrap|Mirror|Primary Colour|Secondary Colour|Untouch
    public static Bitmap StaticIcon
    {
	    get
	    {
		    return new Bitmap(typeof(PictureRotatePlugin), "EffectPluginIcon.png");
	    }
    }
    public static string StaticSubMenuName
    {
	    get
	    {
		    return null; // Use for no submenu
		    // return "My SubMenu"; // Use for custom submenu
	    }
    }
    public PictureRotatePlugin()
	    : base(PictureRotatePlugin.StaticName, PictureRotatePlugin.StaticIcon, PictureRotatePlugin.StaticSubMenuName, EffectFlags.Configurable)
    {
    }
    public enum PropertyNames
    {
	    Amount1,
	    Amount2,
	    Amount3
    }
    public enum Amount2Options
    {
	    Amount2Option1,
	    Amount2Option2,
	    Amount2Option3,
	    Amount2Option4,
	    Amount2Option5,
	    Amount2Option6
    }

    protected override PropertyCollection OnCreatePropertyCollection()
    {
	    List<Property> props = new List<Property>();
	    props.Add(new DoubleProperty(PropertyNames.Amount1, 45, -180, +180));
	    props.Add(StaticListChoiceProperty.CreateForEnum<Amount2Options>(PropertyNames.Amount2, 0, false));
	    props.Add(new BooleanProperty(PropertyNames.Amount3, false));
	    return new PropertyCollection(props);
    }
    protected override ControlInfo OnCreateConfigUI(PropertyCollection props)
    {
	    ControlInfo configUI = CreateDefaultConfigUI(props);
	    configUI.SetPropertyControlValue(PropertyNames.Amount1, ControlInfoPropertyNames.DisplayName, "Rotation");
	    configUI.SetPropertyControlType(PropertyNames.Amount1, PropertyControlType.AngleChooser);
	    configUI.SetPropertyControlValue(PropertyNames.Amount2, ControlInfoPropertyNames.DisplayName, "Limit Type");
	    configUI.SetPropertyControlType(PropertyNames.Amount2, PropertyControlType.RadioButton);
	    PropertyControlInfo Amount2Control = configUI.FindControlForPropertyName(PropertyNames.Amount2);
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option1, "Clamp");
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option2, "Wrap");
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option3, "Mirror");
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option4, "Primary Colour");
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option5, "Secondary Colour");
	    Amount2Control.SetValueDisplayName(Amount2Options.Amount2Option6, "Untouch");
	    configUI.SetPropertyControlValue(PropertyNames.Amount3, ControlInfoPropertyNames.DisplayName, string.Empty);
	    configUI.SetPropertyControlValue(PropertyNames.Amount3, ControlInfoPropertyNames.Description, "Disable Interpolation");
	    return configUI;
    }
    protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
    {
	    this.Amount1 = newToken.GetProperty<DoubleProperty>(PropertyNames.Amount1).Value;
	    this.Amount2 = (byte)((int)newToken.GetProperty<StaticListChoiceProperty>(PropertyNames.Amount2).Value);
	    this.Amount3 = newToken.GetProperty<BooleanProperty>(PropertyNames.Amount3).Value;
	    base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
    }

    public override EffectConfigDialog CreateConfigDialog()
    {

	    return new EffectPluginConfigDialog();
    }
    /// <summary>
    ///
    /// </summary>
    /// <param name="parameters"></param>
    /// <param name="dstArgs">Destination canvas</param>
    /// <param name="srcArgs">Source canvas</param>
    /// <param name="rois">Region of Interest</param>
    /// <param name="startIndex"></param>
    /// <param name="length"></param>

    public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
    {
	    Surface src = srcArgs.Surface;
	    Surface dst = dstArgs.Surface;
	    PdnRegion selectionRegion = EnvironmentParameters.GetSelection(srcArgs.Bounds);
	    // Delete any of these lines you don't need
	    Rectangle selection = this.EnvironmentParameters.GetSelection(src.Bounds).GetBoundsInt();
	    long CenterX = (long)(((selection.Right - selection.Left) / 2) + selection.Left);
	    long CenterY = (long)(((selection.Bottom - selection.Top) / 2) + selection.Top);
	    ColorBgra PrimaryColor = (ColorBgra)EnvironmentParameters.PrimaryColor;
	    ColorBgra SecondaryColor = (ColorBgra)EnvironmentParameters.SecondaryColor;
	    int BrushWidth = (int)EnvironmentParameters.BrushWidth;
	    ColorBgra CurrentPixel;
	    double tempX;
	    double tempY;
	    bool bError;
	    double dAngle;
	    double dCos, dSin;
	    dAngle = Amount1 * 6.283 / 360.0;
	    dCos = Math.Cos(dAngle);
	    dSin = Math.Sin(dAngle);

	    pixelInterpolate Interpolate = new pixelInterpolate();
	    for (int i = startIndex; i < startIndex + length; ++i)
	    {
		    Rectangle rect = rois[i];
		    for (int y = rect.Top; y < rect.Bottom; ++y)
		    {
			    for (int x = rect.Left; x < rect.Right; ++x)
			    {
				    // Render Code Here
				    //CurrentPixel = src[x, y];
				    tempX = ((double)(x - CenterX)) * dCos + (((double)(y - CenterY)) * dSin) + CenterX;
				    tempY = ((double)(y - CenterY)) * dCos + (((double)(x - CenterX)) * -1 * dSin) + CenterY;
				    CurrentPixel = src[x, y];
				    bError = false;
				    XCompareTo(ref selection, tempX, ref bError);
				    YCompareTo(ref selection, tempY, ref bError);

				    // Copy the background colour if an error is encountered
				    if (bError)
				    {
					    CopyBackgroundColour(src, ref selection, ref PrimaryColor, ref SecondaryColor, ref CurrentPixel, ref tempX, ref tempY, Amount2, Interpolate);
				    }
				    else
				    {
					    CurrentPixel = Interpolate.Interpolate(src, selection, tempX, tempY);
				    }
				    dst[x, y] = CurrentPixel;
			    }
		    }
	    }
    }
    private static void CopyBackgroundColour(Surface src, ref Rectangle selection, ref ColorBgra PrimaryColor, ref ColorBgra SecondaryColor, ref ColorBgra CurrentPixel, ref double tempX, ref double tempY, byte Amount2, pixelInterpolate Interpolate)
    {
	    switch (Amount2)
	    {
		    // Clamp
		    case 0:
			    if (tempX >= selection.Right)
			    {
				    tempX = selection.Right - 1;
			    }
			    else if (tempX < selection.Left)
			    {
				    tempX = selection.Left;
			    }
			    if (tempY >= selection.Bottom)
			    {
				    tempY = selection.Bottom - 1;
			    }
			    else if (tempY < selection.Top)
			    {
				    tempY = selection.Top;
			    }
			    CurrentPixel = Interpolate.Interpolate(src, selection, tempX, tempY);
			    break;
		    // Wrap
		    case 1:
			    tempX = (((int)tempX + (selection.Right - selection.Left)) % (selection.Right - selection.Left)) + selection.Left;
			    tempY = (((int)tempY + (selection.Bottom - selection.Top)) % (selection.Bottom - selection.Top)) + selection.Top;
			    tempX = ((int)tempX) % selection.Right;
			    tempY = ((int)tempY) % selection.Bottom;
			    CurrentPixel = Interpolate.Interpolate(src, selection, tempX, tempY);
			    break;
		    // Mirror
		    case 2:
			    double dSelectionWidth;
			    double dSelectionHeight;
			    dSelectionWidth = (selection.Right - selection.Left);
			    dSelectionHeight = (selection.Bottom - selection.Top);
			    double dOffsetX = (tempX - selection.Left) + (dSelectionWidth * 10000.0);
			    double dOffsetY = (tempY - selection.Top) + (dSelectionHeight * 10000.0);
			    dOffsetX %= (2.0 * dSelectionWidth);
			    dOffsetY %= (2.0 * dSelectionHeight);
			    if (dOffsetX > (dSelectionWidth))
			    {
				    dOffsetX = (dSelectionWidth * 2.0) - dOffsetX;
			    }
			    if (dOffsetY > (dSelectionHeight))
			    {
				    dOffsetY = (dSelectionHeight * 2.0) - dOffsetY;
			    }

			    tempX = dOffsetX + selection.Left;
			    tempY = dOffsetY + selection.Top;
			    CurrentPixel = Interpolate.Interpolate(src, selection, tempX, tempY);
			    break;
		    // Set with primary colour
		    case 3:
			    CurrentPixel.R = (byte)PrimaryColor.R;
			    CurrentPixel.G = (byte)PrimaryColor.G;
			    CurrentPixel.B = (byte)PrimaryColor.B;
			    CurrentPixel.A = (byte)PrimaryColor.A;
			    break;
		    // Set with secondary colour
		    case 4:
			    CurrentPixel.R = (byte)SecondaryColor.R;
			    CurrentPixel.G = (byte)SecondaryColor.G;
			    CurrentPixel.B = (byte)SecondaryColor.B;
			    CurrentPixel.A = (byte)SecondaryColor.A;
			    break;
		    // Untouch Leave src pixels
		    case 5:
		    default:
			    break;
	    };
    }
    private static void YCompareTo(ref Rectangle selection, double tempY, ref bool bError)
    {
	    if (tempY >= selection.Bottom)
	    {
		    bError = true;
	    }
	    else if (tempY < selection.Top)
	    {
		    bError = true;
	    }
    }
    private static void XCompareTo(ref Rectangle selection, double tempX, ref bool bError)
    {
	    if (tempX >= selection.Right)
	    {
		    bError = true;
	    }
	    else if (tempX < selection.Left)
	    {
		    bError = true;
	    }
    }
   }
}

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.

 Share

×
×
  • Create New...