Пример #1
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)parameters;

            userEffect = sect.UserScriptObject;

            if (userEffect != null)
            {
                userEffect.EnvironmentParameters = this.EnvironmentParameters;

                try
                {
                    userEffect.SetRenderInfo(sect.Preview ? sect.PreviewToken : null, dstArgs, srcArgs);
                    fetchDebugMsg = true;
                }
                catch (Exception exc)
                {
                    sect.LastExceptions.Add(exc);
                    dstArgs.Surface.CopySurface(srcArgs.Surface);
                    sect.UserScriptObject = null;
                    userEffect.Dispose();
                    userEffect = null;
                }
            }

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
Пример #2
0
        protected override void InitTokenFromDialog()
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)theEffectToken;

            sect.UserCode         = txtCode.Text;
            sect.UserScriptObject = this.userScriptObject;
            sect.ScriptName       = txtScriptName.Text;
        }
Пример #3
0
        protected override void InitialInitToken()
        {
            CodeLabConfigToken sect = new CodeLabConfigToken();

            sect.UserCode         = "void Render(Surface dst, Surface src, Rectangle rect)\r\n{\r\n    for(int y = rect.Top; y < rect.Bottom; y++)\r\n    {\r\n        for (int x = rect.Left; x < rect.Right; x++)\r\n        {\r\n        }\r\n    }\r\n}";
            sect.UserScriptObject = null;
            sect.ScriptName       = "MyScript";
            theEffectToken        = sect;
        }
Пример #4
0
		public override object Clone()
		{
			CodeLabConfigToken sect = new CodeLabConfigToken();
			sect.UserCode = this.UserCode;
			sect.UserScriptObject = this.UserScriptObject;
            sect.LastExceptions = this.LastExceptions; //Reference copy INTENDED.
			sect.ScriptName = this.ScriptName;
			return sect;
		}
Пример #5
0
        protected override void InitDialogFromToken(EffectConfigToken effectToken)
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)effectToken;

            txtScriptName.Text = sect.ScriptName;
            if (sect != null)
            {
                txtCode.Text = sect.UserCode;
            }
        }
Пример #6
0
        public override object Clone()
        {
            CodeLabConfigToken sect = new CodeLabConfigToken();

            sect.UserCode         = this.UserCode;
            sect.UserScriptObject = this.UserScriptObject;
            sect.LastExceptions   = this.LastExceptions; //Reference copy INTENDED.
            sect.ScriptName       = this.ScriptName;
            return(sect);
        }
Пример #7
0
        private void tmrExceptionCheck_Tick(object sender, System.EventArgs e)
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)theEffectToken;

            if (sect.LastExceptions.Count > 0)
            {
                Exception exc = sect.LastExceptions[0];
                sect.LastExceptions.Clear();
                listErrors.Items.Add(exc.ToString());
            }
        }
Пример #8
0
        protected override void OnSetRenderInfo(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            CodeLabConfigToken sect = (CodeLabConfigToken)parameters;

            userEffect  = sect.UserScriptObject;
            projectType = sect.ProjectType;

            if (projectType == ProjectType.Shape)
            {
                Size      srcSize         = EnvironmentParameters.SourceSurface.Size;
                Rectangle selection       = EnvironmentParameters.SelectionBounds;
                ColorBgra strokeColor     = EnvironmentParameters.PrimaryColor;
                ColorBgra fillColor       = EnvironmentParameters.SecondaryColor;
                double    strokeThickness = EnvironmentParameters.BrushWidth;

                Thread t = new Thread(() =>
                {
                    ShapeBuilder.SetEnviromentParams(srcSize.Width, srcSize.Height, selection.X, selection.Y, selection.Width, selection.Height, strokeColor, fillColor, strokeThickness);
                    ShapeBuilder.RenderShape(sect.UserCode);
                });
                t.SetApartmentState(ApartmentState.STA);
                t.Start();
                t.Join();

                shapeSurface?.Dispose();
                shapeSurface = (ShapeBuilder.Shape != null) ?
                               Surface.CopyFromBitmap(ShapeBuilder.Shape) :
                               null;
            }
            else if (projectType == ProjectType.Effect && userEffect != null)
            {
                userEffect.EnvironmentParameters = this.EnvironmentParameters;

                try
                {
                    userEffect.SetRenderInfo(sect.PreviewToken, dstArgs, srcArgs);
                    fetchDebugMsg = true;
                }
                catch (Exception exc)
                {
                    sect.LastExceptions.Add(exc);
                    dstArgs.Surface.CopySurface(srcArgs.Surface);
                    sect.UserScriptObject = null;
                    userEffect?.Dispose();
                    userEffect = null;
                }
            }

            base.OnSetRenderInfo(parameters, dstArgs, srcArgs);
        }
Пример #9
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            if (projectType == ProjectType.Shape && shapeSurface != null)
            {
                dstArgs.Surface.CopySurface(srcArgs.Surface, rois, startIndex, length);
                normalOp.Apply(dstArgs.Surface, shapeSurface, rois, startIndex, length);
            }
            else if (projectType == ProjectType.Effect && userEffect != null)
            {
                CodeLabConfigToken sect = (CodeLabConfigToken)parameters;
                try
                {
                    userEffect.Render(sect.PreviewToken, dstArgs, srcArgs, rois, startIndex, length);
                }
                catch (Exception exc)
                {
                    sect.LastExceptions.Add(exc);
                    dstArgs.Surface.CopySurface(srcArgs.Surface);
                    sect.UserScriptObject = null;
                    userEffect?.Dispose();
                    userEffect = null;
                }

                if (fetchDebugMsg)
                {
                    fetchDebugMsg = false;
                    try
                    {
                        string output = userEffect?.GetType().GetProperty("__DebugMsgs", typeof(string))?.GetValue(userEffect)?.ToString();
                        if (!output.IsNullOrEmpty())
                        {
                            sect.Output.Add(output);
                        }
                    }
                    catch
                    {
                        // just fail silently
                    }
                }
            }
        }
Пример #10
0
        public override void Render(EffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs, Rectangle[] rois, int startIndex, int length)
        {
            CodeLabConfigToken sect       = (CodeLabConfigToken)parameters;
            Effect             userEffect = sect.UserScriptObject;

            if (userEffect != null)
            {
                userEffect.EnvironmentParameters = this.EnvironmentParameters;

                try
                {
                    userEffect.Render(null, dstArgs, srcArgs, rois, startIndex, length);
                }

                catch (Exception exc)
                {
                    sect.LastExceptions.Add(exc);
                    dstArgs.Surface.CopySurface(srcArgs.Surface);
                    sect.UserScriptObject = null;
                }
            }
        }
Пример #11
0
 protected override void InitialInitToken()
 {
     CodeLabConfigToken sect = new CodeLabConfigToken();
     sect.UserCode = "void Render(Surface dst, Surface src, Rectangle rect)\r\n{\r\n    for(int y = rect.Top; y < rect.Bottom; y++)\r\n    {\r\n        for (int x = rect.Left; x < rect.Right; x++)\r\n        {\r\n        }\r\n    }\r\n}";
     sect.UserScriptObject = null;
     sect.ScriptName = "MyScript";
     theEffectToken = sect;
 }