Beispiel #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);
        }
Beispiel #2
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);
        }