Exemplo n.º 1
0
        public GraphedItems RunScript(string scriptContent)
        {
            var items       = new GraphedItems();
            var drawMethods = new DrawMethods(items);

            try
            {
                new Engine(cfg => { cfg.AllowClr(typeof(Color).Assembly); })

                // Allow use of the `color` struct, so `color.Red` is accessible
                .Execute(
                    @"var SharpPlotterHelpers = importNamespace('Microsoft.Xna.Framework');var color = SharpPlotterHelpers.Color;")

                // Helper to make defining points easy
                .SetValue("p", new Func <double, double, Point2d>((x, y) => new Point2d((float)x, (float)y)))
                //.SetValue("points", new CallPoints(drawMethods.Points))
                //.SetValue("segments", new Action<object[]>(o => drawMethods.Segments(o)))
                .SetValue("graph", drawMethods)
                .Execute(scriptContent, new ParserOptions {
                });
            }
            catch (JavaScriptException exception)
            {
                throw new ScriptException("Error", false, exception);
            }

            return(items);
        }
Exemplo n.º 2
0
        public App()
        {
            // ReSharper disable once ObjectCreationAsStatement
            new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth  = Width,
                PreferredBackBufferHeight = Height,
                PreferMultiSampling       = true
            };

            IsMouseVisible = true;

            _appSettings = SettingsIo.Load() ?? new AppSettings
            {
                ScriptFolderPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal),
                                                "SharpPlotter"),
                TextEditorExecutable = "code",
            };

            _onScreenLogger = new OnScreenLogger();
            _onScreenLogger.LogMessage(OnLoadText());

            _camera       = new Camera(Width, Height, _onScreenLogger);
            _graphedItems = new GraphedItems();

            // Do a first render to get pixel data from the image for initial byte data allocation
            using var image  = _camera.Render(null, null);
            _rawCanvasPixels = new byte[image.Height * image.PeekPixels().RowBytes];

            _scriptManager = new ScriptManager(_appSettings, _onScreenLogger);
        }
Exemplo n.º 3
0
        public GraphedItems RunScript(string scriptContent)
        {
            var scope       = _scriptEngine.CreateScope();
            var items       = new GraphedItems();
            var drawMethods = new DrawMethods(items);

            scope.SetVariable("graph", drawMethods);

            scriptContent = $"from Microsoft.Xna.Framework import Color{Environment.NewLine}{scriptContent}";
            var script = _scriptEngine.CreateScriptSourceFromString(scriptContent);

            try
            {
                script.Execute(scope);
            }
            catch (Exception exception)
            {
                if (exception is SyntaxErrorException ||
                    exception is AttributeErrorException ||
                    exception is MissingMemberException)
                {
                    throw new ScriptException("Syntax Error", false, exception);
                }

                throw;
            }

            return(items);
        }
Exemplo n.º 4
0
        public GraphedItems RunScript(string scriptContent)
        {
            var items   = new GraphedItems();
            var globals = new ScriptGlobals {
                Graph = new DrawMethods(items)
            };

            try
            {
                CSharpScript.RunAsync(scriptContent, _scriptOptions, globals).GetAwaiter().GetResult();
            }
            catch (CompilationErrorException exception)
            {
                // Since this is a compiler error then we don't need the stack trace shown, as that's just
                // noise that won't help end users
                throw new ScriptException("Compile Error", false, exception);
            }

            return(items);
        }
Exemplo n.º 5
0
        protected override void Update(GameTime gameTime)
        {
            _inputHandler.Update(gameTime);

            if (_resetCameraRequested)
            {
                SetCameraToSizeOfGraphedItems();
                _resetCameraRequested = false;
            }

            if (_camera.CameraHasMoved)
            {
                UpdateToolbarWithCameraProperties();
            }

            var newGraphedItems = _scriptManager.CheckForNewGraphedItems();

            if (newGraphedItems != null)
            {
                _graphedItems = newGraphedItems;
            }

            base.Update(gameTime);
        }
Exemplo n.º 6
0
 public DrawMethods(GraphedItems graphedItems)
 {
     _graphedItems = graphedItems;
 }