Exemplo n.º 1
0
        public WebGameWindow(Game game)
        {
            _game = game;
            _keys = new List <Keys>();

            Keyboard.SetKeys(_keys);

            _canvas          = document.getElementById("monogamecanvas") as HTMLCanvasElement;
            _canvas.tabIndex = 1000;

            // Disable selection
            _canvas.style.userSelect       = "none";
            _canvas.style.webkitUserSelect = "none";
            _canvas.style.msUserSelect     = "none";

            // TODO: Move "GL context" creation outside the game window
            var possiblecontexts = new[] { "webgl", "experimental-webgl", "webkit-3d", "moz-webgl" };

            foreach (var context in possiblecontexts)
            {
                try
                {
                    WebHelper.gl = _canvas.getContext(context).As <WebGLRenderingContext>();
                    if (WebHelper.gl != null)
                    {
                        break;
                    }
                }
                catch { }
            }

            if (WebHelper.gl == null)
            {
                var d2d = _canvas.getContext("2d").As <CanvasRenderingContext2D>();
                d2d.fillStyle = "#6495ED";
                d2d.fillRect(0, 0, _canvas.width, _canvas.height);
                d2d.fillStyle = "#000000";
                d2d.font      = "30px Arial";
                d2d.textAlign = "center";
                d2d.fillText("This device does not support WebGL  :(", _canvas.width / 2, _canvas.height / 2);

                throw new Exception("Failed to get WebGL context :|");
            }

            // Block context menu on the canvas element
            _canvas.oncontextmenu += (e) => e.preventDefault();

            // Connect events
            _canvas.onmousemove  += (e) => Canvas_MouseMove(e);
            _canvas.onmousedown  += (e) => Canvas_MouseDown(e);
            _canvas.onmouseup    += (e) => Canvas_MouseUp(e);
            _canvas.onmousewheel += (e) => Canvas_MouseWheel(e);
            _canvas.onkeydown    += (e) => Canvas_KeyDown(e);
            _canvas.onkeyup      += (e) => Canvas_KeyUp(e);

            document.addEventListener("webkitfullscreenchange", Document_FullscreenChange);
            document.addEventListener("mozfullscreenchange", Document_FullscreenChange);
            document.addEventListener("fullscreenchange", Document_FullscreenChange);
            document.addEventListener("MSFullscreenChange", Document_FullscreenChange);
        }
Exemplo n.º 2
0
        private void _SpriteFont(HTMLImageElement image, int glyphWidth, int glyphHeight, bool xtrim)
        {
            HTMLCanvasElement canvas = new HTMLCanvasElement();

            canvas.width  = (uint)glyphWidth;
            canvas.height = (uint)glyphHeight;
            CanvasRenderingContext2D context = canvas.getContext(Literals._2d);

            for (int i = start; i <= end; i++)
            {
                context.clearRect(0, 0, canvas.width, canvas.height);
                context.drawImage(image, glyphWidth * (i - start), 0, glyphWidth, glyphHeight, 0, 0, glyphWidth, glyphHeight);

                // Make sure loaded image is large enough
                // If image is not large enough, generate error glyphs
                if (image.width >= glyphWidth * (i - start) + glyphWidth)
                {
                    glyphs[i] = SpriteSheet.AddSpriteFontGlyph(canvas, context, xtrim);
                }
                else
                {
                    glyphs[i] = SpriteSheet.AddSpriteFontGlyph(canvas, context, false);
                }
            }

            canvas.remove();

            loaded = true;
        }
Exemplo n.º 3
0
        public static void Main()
        {
            document.body.setAttribute("style", "margin: 0; overflow: hidden;");

            var div = new HTMLDivElement();

            div.setAttribute("style", "width: 960px; height: 540px;");

            var button = new HTMLButtonElement();

            button.innerHTML = "Run Game";
            button.setAttribute("style", "width: 100%; height: 100%; background-color: rgb(100, 149, 237); color: rgb(255, 255, 255); font-size: 20px; border: 0;");

            document.body.appendChild(div);
            div.appendChild(button);

            button.onclick = (ev) =>
            {
                var canvas = new HTMLCanvasElement();
                canvas.width  = 960;
                canvas.height = 540;
                canvas.id     = "monogamecanvas";

                div.removeChild(button);
                div.appendChild(canvas);

                _game = new Game1();
                _game.Run();

                canvas.focus();
            };
        }
Exemplo n.º 4
0
 public Sprite()
 {
     spriteBuffer   = new HTMLCanvasElement();
     spriteGraphics = spriteBuffer.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
     spriteGraphics.ImageSmoothingEnabled = false;
     Position = new Vector2();
 }
Exemplo n.º 5
0
        private string CreateImage(string message, double size)
        {
            var col       = size * 0.575;
            var row       = size;
            var lineArray = message.Split('\n');

            var width  = (lineArray.Select(_ => _.Length).Max() * col);
            var height = lineArray.Length * row;

            var bufferCanvas = new HTMLCanvasElement()
            {
                Width = _resolution.Clamp(width), Height = _resolution.Clamp(height)
            };
            var bufferContext = bufferCanvas.GetContext(CanvasContext2DType.CanvasRenderingContext2D);

            double colAmount = 0;
            double rowAmount = 0;

            foreach (var line in lineArray)
            {
                foreach (var letter in line)
                {
                    DrawLetter(letter, size, colAmount, rowAmount, bufferContext);
                    colAmount += col;
                }
                rowAmount += row;
                colAmount  = 0;
            }

            return(bufferCanvas.ToDataURL());
        }
Exemplo n.º 6
0
        public static void Main()
        {
            var divdata = new HTMLDivElement();

            divdata.innerHTML = "This is an example web game that uses MonoGame, it just uses a prototype that @Jjagg and me made in like 3h for a gamejam, and than didn't have the time to finish it...<br><br>Once in game press space to spawn enemies.<br><br>Green screen means that the game is loading, I didn't want to bother implementing a custom loading screen.<br><br>";
            document.body.appendChild(divdata);

            var button = new HTMLButtonElement();

            button.innerHTML = "Run Game";
            divdata.appendChild(button);

            var brelem = new HTMLBRElement();

            document.body.appendChild(brelem);

            var canvas = new HTMLCanvasElement();

            canvas.width  = 1024;
            canvas.height = 576;
            canvas.id     = "monogamecanvas";
            document.body.appendChild(canvas);

            button.onclick = (ev) =>
            {
                game = new Game1();
                game.Run();

                document.body.removeChild(divdata);
                document.body.removeChild(brelem);
            };
        }
Exemplo n.º 7
0
        public static void Main()
        {
            var canvasSize = new IntSize(400, 800);

            var div = new HTMLDivElement();

            div.style.width  = $"{canvasSize.Width}px";
            div.style.height = $"{canvasSize.Height}px";
            document.body.appendChild(div);

            var button = new HTMLButtonElement();

            button.innerHTML             = "Click on game area to start it!";
            button.style.width           = "100%";
            button.style.height          = "100%";
            button.style.backgroundColor = "#6495ED";
            button.style.color           = "#ffffff";
            button.style.fontSize        = "20px";
            div.appendChild(button);

            button.onclick = (ev) =>
            {
                div.removeChild(button);

                var canvas = new HTMLCanvasElement();
                canvas.style.width  = "100%";
                canvas.style.height = "100%";
                canvas.id           = "monogamecanvas";
                div.appendChild(canvas);

                game = new TheGame(canvasSize, Platform.Desktop);
                game.Run();
            };
        }
Exemplo n.º 8
0
        public static void Main()
        {
            var canvas = new HTMLCanvasElement();

            canvas.width  = 800;
            canvas.height = 480;
            canvas.id     = "monogamecanvas";

            var button = new HTMLButtonElement();

            button.innerHTML = "Run Game";

            document.body.appendChild(canvas);
            document.body.appendChild(button);

            document.body.style.background = "#121212";

            button.onclick = (ev) =>
            {
                //window.setTimeout((e) =>
                //{
                _game = new Game1();
                _game.Run();
                //}, 1f);
            };
        }
Exemplo n.º 9
0
        private void SetupHtml()
        {
            string gameId  = "game";
            var    scoreId = "score";

            HTMLCanvasElement canvas = (HTMLCanvasElement)Document.GetElementById(boardId);

            Canvas = canvas;
            var score = Document.GetElementById(scoreId);

            score.InnerHTML = "Score: ";

            SetupCanvas(canvas, score);


            var reset = Document.GetElementById("reset");
            var flag  = Document.GetElementById("flag");
            var text  = Document.GetElementById("flagtext");

            flag.OnClick = click =>
            {
                _flag          = !_flag;
                text.InnerHTML = "Flag: " + _flag;
            };
            reset.OnClick = click =>
            {
                GameSetup();
                Show();
                Result.TextContent = "";
            };
            canvas.Width  = (int)Width;
            canvas.Height = (int)Height;
        }
Exemplo n.º 10
0
        public static WebGLRenderingContext GetWebGLRenderingContext(HTMLCanvasElement canvas)
        {
            var contextNames = new string[]
            {
                "webgl",
                "experimental-webgl",
                "webkit-3d",
                "moz-webgl"
            };

            WebGLRenderingContext context = null;

            foreach (var name in contextNames)
            {
                try
                {
                    context = canvas.GetContext(name).As <WebGLRenderingContext>();
                }
                catch (Exception) { }

                if (context != null)
                {
                    break;
                }
            }

            return(context);
        }
Exemplo n.º 11
0
        static void Main()
        {
            var div = new HTMLDivElement();

            div.style.width  = "800px";
            div.style.height = "480px";
            document.body.appendChild(div);

            var button = new HTMLButtonElement();

            button.innerHTML             = "Click on game area to start it!";
            button.style.width           = "100%";
            button.style.height          = "100%";
            button.style.backgroundColor = "#000000";
            button.style.color           = "#ffffff";
            button.style.fontSize        = "20px";
            div.appendChild(button);

            button.onclick = (ev) =>
            {
                div.removeChild(button);

                var canvas = new HTMLCanvasElement();
                canvas.style.width  = "100%";
                canvas.style.height = "100%";
                canvas.id           = "monogamecanvas";
                div.appendChild(canvas);

                game = new GameProject.Game1();
                game.Run();
            };
        }
Exemplo n.º 12
0
        public static void StartGame()
        {
            debug = Document.GetElementById <HTMLDivElement>("debug");

            // Set up canvas rendering.
            screen             = Document.GetElementById <HTMLCanvasElement>("screen");
            screenContext      = screen.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            lightPixel         = screenContext.CreateImageData(1, 1);
            lightPixel.Data[1] = 0x64;            // Set green part (#006400)
            lightPixel.Data[3] = 255;             // Alpha

            // Set up touch events for canvas so we can play on mobile.
            screen.OnTouchStart += SetTouchDown;
            screen.OnTouchEnd   += SetTouchUp;

            // Set up audio.
            // http://stackoverflow.com/a/23395136/25124
            beep = new HTMLAudioElement("data:audio/wav;base64,//uQRAAAAWMSLwUIYAAsYkXgoQwAEaYLWfkWgAI0wWs/ItAAAGDgYtAgAyN+QWaAAihwMWm4G8QQRDiMcCBcH3Cc+CDv/7xA4Tvh9Rz/y8QADBwMWgQAZG/ILNAARQ4GLTcDeIIIhxGOBAuD7hOfBB3/94gcJ3w+o5/5eIAIAAAVwWgQAVQ2ORaIQwEMAJiDg95G4nQL7mQVWI6GwRcfsZAcsKkJvxgxEjzFUgfHoSQ9Qq7KNwqHwuB13MA4a1q/DmBrHgPcmjiGoh//EwC5nGPEmS4RcfkVKOhJf+WOgoxJclFz3kgn//dBA+ya1GhurNn8zb//9NNutNuhz31f////9vt///z+IdAEAAAK4LQIAKobHItEIYCGAExBwe8jcToF9zIKrEdDYIuP2MgOWFSE34wYiR5iqQPj0JIeoVdlG4VD4XA67mAcNa1fhzA1jwHuTRxDUQ//iYBczjHiTJcIuPyKlHQkv/LHQUYkuSi57yQT//uggfZNajQ3Vmz+Zt//+mm3Wm3Q576v////+32///5/EOgAAADVghQAAAAA//uQZAUAB1WI0PZugAAAAAoQwAAAEk3nRd2qAAAAACiDgAAAAAAABCqEEQRLCgwpBGMlJkIz8jK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4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+IDGid/9aaaZTGMuj9mpu9Mpio1dXrr5HERTZSmqU36A3CumzN/9Robv/Xx4v9ijkSRSNLQhAWumap82WRSBUqXStV/YcS+XVLnSS+WLDroqArFkMEsAS+eWmrUzrO0oEmE40RlMZ5+ODIkAyKAGUwZ3mVKmcamcJnMW26MRPgUw6j+LkhyHGVGYjSUUKNpuJUQoOIAyDvEyG8S5yfK6dhZc0Tx1KI/gviKL6qvvFs1+bWtaz58uUNnryq6kt5RzOCkPWlVqVX2a/EEBUdU1KrXLf40GoiiFXK///qpoiDXrOgqDR38JB0bw7SoL+ZB9o1RCkQjQ2CBYZKd/+VJxZRRZlqSkKiws0WFxUyCwsKiMy7hUVFhIaCrNQsKkTIsLivwKKigsj8XYlwt/WKi2N4d//uQRCSAAjURNIHpMZBGYiaQPSYyAAABLAAAAAAAACWAAAAApUF/Mg+0aohSIRobBAsMlO//Kk4soosy1JSFRYWaLC4qZBYWFRGZdwqKiwkNBVmoWFSJkWFxX4FFRQWR+LsS4W/rFRb/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////VEFHAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAU291bmRib3kuZGUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMjAwNGh0dHA6Ly93d3cuc291bmRib3kuZGUAAAAAAAAAACU=");

            // Create the interpreter.
            chip8 = new Chip8(Draw, Beep);

            // Pass keypresses over to the interpreter.
            Document.OnKeyDown += SetKeyDown;
            Document.OnKeyUp   += SetKeyUp;

            // Kick off async loading of ROM.
            BeginLoadRom(ROM);
        }
Exemplo n.º 13
0
        public Game(HTMLCanvasElement canvas)
        {
            _mainCanvas         = canvas;
            _mainCanvasRenderer = _mainCanvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            _shadowCanvas = new Bridge.Html5.HTMLCanvasElement()
            {
                Width  = _mainCanvas.Width,
                Height = _mainCanvas.Height
            };
            _shadowCanvas2D = _shadowCanvas.GetContext(Bridge.Html5.CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);


            Resize();

            _player = new Player();

            _lastDraw = DateTime.Now;

            _world         = new World(_player, "map1.json");
            _world.Loaded += () => {
                Window.SetTimeout(GameTick, 1000 / TickRate);
                Window.RequestAnimationFrame(GameFrame);
                _player.X = 500;
                _player.Y = 500;
            };
        }
Exemplo n.º 14
0
        static void AddImageToPage(ImageData tex, string Id)
        {
            HTMLDivElement div = new HTMLDivElement();

            div.ClassName     = "col";
            div.Style.Padding = "5px";
            HTMLCanvasElement c = new HTMLCanvasElement();

            c.Id                    = Id;
            c.ClassName             = "CustomCanvas";
            c.Style.BackgroundColor = "#FAFAFA";
            ImageEncoding.ImageType imgType = ImageEncoding.ImageTypesByID[t.NameToImageID(Id)];
            c.Height       = imgType.s.y;
            c.Width        = imgType.s.x;
            c.OnClick      = ImageCanvasClick;
            c.Style.Margin = "auto";
            c.Style.Border = "black 3px solid";
            div.AppendChild(MakeImageLabel(Id, imgType.s.x.ToString() + "x" + imgType.s.y.ToString()));
            if (Id != Theme.Name_TopScr && Id != Theme.Name_BotScr)
            {
                div.AppendChild(MakeImageEnableCheckBox(Id, tex != null));
            }
            else
            {
                HtmlCanvasFitSize(c, imgType.s);
            }
            div.AppendChild(c);
            ImagesDiv.AppendChild(div);
            if (tex != null)
            {
                ((CanvasRenderingContext2D)c.GetContext("2d")).PutImageData(tex, 0, 0);
            }
        }
Exemplo n.º 15
0
        public static void Main()
        {
            var canvas = new HTMLCanvasElement();

            canvas.width  = 800;
            canvas.height = 480;
            canvas.id     = "monogamecanvas";

            var divdata = new HTMLDivElement();

            divdata.id = "testoutput";

            var button = new HTMLButtonElement();

            button.innerHTML = "Run Game";

            document.body.appendChild(canvas);
            document.body.appendChild(button);
            document.body.appendChild(divdata);

            button.onclick = (ev) =>
            {
                game = new Game1();
                // game = new PrimitivesSample.PrimitivesSampleGame();
                game.Run();
            };
        }
Exemplo n.º 16
0
        public TileMap(Game game, int Seed = -1)
        {
            RND = new Random();
            //position = new Vector2(-576);
            ///position = new Vector2(-128);
            position = new Vector2();
            //tilesize = 48;
            tilesize = 16;
            //rows = 16;
            /*columns = 52;*/
            rows      = (int)Math.Ceiling(((-position.Y * 2) + game.stageBounds.bottom) / tilesize);
            columns   = (int)Math.Ceiling(((-position.X * 2) + game.stageBounds.right) / tilesize);
            data      = new TileData[columns, rows];
            tiles     = AnimationLoader.Get("images/land/brick");
            cracks    = AnimationLoader.Get("images/land/cracks");
            this.game = game;

            buffer = new HTMLCanvasElement();
            bg     = buffer.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            if (Seed < 0)
            {
                this.Seed = RND.Next();
            }
            else
            {
                this.Seed = Seed;
            }
            //Randomize();
            Generate();
        }
Exemplo n.º 17
0
        public static WebGLRenderingContext Create3DContext(HTMLCanvasElement canvas)
        {
            string[] names = new string[]
            {
                "webgl",
                "experimental-webgl",
                "webkit-3d",
                "moz-webgl"
            };

            WebGLRenderingContext context = null;

            foreach (string name in names)
            {
                try
                {
                    context = canvas.GetContext(name).As <WebGLRenderingContext>();
                }
                catch { }

                if (context != null)
                {
                    break;
                }
            }

            return(context);
        }
Exemplo n.º 18
0
        private void GetImageData(HTMLCanvasElement canvas)
        {
            int height = canvas.Height;
            int width  = canvas.Width;

            if (CanvasRenderingContext == null)
            {
                CanvasRenderingContext = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            }

            if (Image == null)
            {
                // the data to manipulate
                Image = CanvasRenderingContext.CreateImageData(width, height);
            }
            else
            {
                //var color = new Color() { Red = 0, Green = 0, Blue = 0 };

                //for (int y = 0; y < height; y++)
                //{
                //    for (int x = 0; x < width; x++)
                //    {
                //        Image.SetPixel(x, y, color);
                //    }
                //}
            }
        }
Exemplo n.º 19
0
        static void UpdateShownImg(ImageEncoding.ImageType imgType, string ID, ImageData img)
        {
            HTMLCanvasElement ShownImg = Document.GetElementById <HTMLCanvasElement>(ID);

            ShownImg.Width  = imgType.s.x;
            ShownImg.Height = imgType.s.y;
            ((CanvasRenderingContext2D)ShownImg.GetContext("2d")).PutImageData(img, 0, 0);
        }
Exemplo n.º 20
0
        private static void LoadCanvasContext()
        {
            // FIXME: Shouldn't it allow returning HTMLCanvasElement without a cast??
            BridgeTetris.Tetris.canvas = Get("canvas").As <HTMLCanvasElement>();
            BridgeTetris.Tetris.upcomingPieceCanvas = Get("upcoming").As <HTMLCanvasElement>();

            BridgeTetris.Tetris.canvasContext = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            BridgeTetris.Tetris.upcomingPieceCanvasContext = upcomingPieceCanvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
        }
Exemplo n.º 21
0
        public void GetMousePosition(HTMLCanvasElement c, Event e)
        {
            var rect  = (ClientRect)c.GetBoundingClientRect();
            var mouse = (MouseEvent)e;
            var px    = (int)(mouse.ClientX - rect.Left);
            var py    = (int)(mouse.ClientY - rect.Top);

            OnClick((MouseEvent)e, px, py);
        }
Exemplo n.º 22
0
 static void AttachTouchEvents(HTMLCanvasElement canvas)
 {
     canvas.OnTouchCancel += OnTouchCancel;
     canvas.OnTouchEnd    += OnTouchEnd;
     canvas.OnTouchEnter  += OnTouchEnter;
     canvas.OnTouchLeave  += OnTouchLeave;
     canvas.OnTouchMove   += OnTouchMove;
     canvas.OnTouchStart  += OnTouchStart;
 }
Exemplo n.º 23
0
 /*protected string Font
  * {
  *  get
  *  {
  *      return TextGraphic.Font;
  *  }
  *  set
  *  {
  *      if (TextGraphic.Font != value)
  *      {
  *          TextGraphic.Font = value;
  *          textInvallidated = true;
  *          imageInvallidated = true;
  *      }
  *
  *  }
  * }*/
 public TextSprite()
 {
     TextImage   = new HTMLCanvasElement();
     TextGraphic = TextImage.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
     TextGraphic.ImageSmoothingEnabled = false;
     //TextGraphic.Font.
     TextImage.Style.ImageRendering = ImageRendering.Pixelated;
     TextGraphic.FillStyle          = "#FFFFFF";
 }
 public static void ToBlob(HTMLCanvasElement canvas, ActionCallback <Blob> successCallback, string mimeType = null)
 {
     EventHorizonBlazorInterop.Func <CachedEntity>(
         new object[]
     {
         new string[] { "BABYLON", "Tools", "ToBlob" }, canvas, successCallback, mimeType
     }
         );
 }
Exemplo n.º 25
0
 public void texImage2D(
     int target,
     int level,
     int internalformat,
     int format,
     int type,
     HTMLCanvasElement canvas)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 public void DrawFull(CanvasRenderingContext2D context, HTMLCanvasElement canvas)
 {
     context.DrawImage(
         _image,
         0,
         0,
         canvas.Width,
         canvas.Height
         );
 }
Exemplo n.º 27
0
        public static void Main()
        {
            Window.OnLoad              += OnLoad;
            Window.OnResize            += OnResize;
            Window.OnDeviceOrientation += OnDeviceOrientation;

            _canvas = Document.CreateElement <HTMLCanvasElement>("canvas");

            Document.Body.AppendChild(_canvas);
        }
Exemplo n.º 28
0
 public void texSubImage2D(
     int target,
     int level,
     double xoffset,
     double yoffset,
     int format,
     int type,
     HTMLCanvasElement canvas)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 29
0
        /// <summary>
        /// Returns Text Metrics for a given string
        /// </summary>
        /// <param name="t">the string</param>
        /// <param name="f">the font used</param>
        /// <returns>TextMetrics</returns>
        public static TextMetrics GetTextMetrics(string t, string f)
        {
            if (f == "")
            {
                f = "8.25pt Tahoma";
            }
            var c = (cva ?? (cva = new HTMLCanvasElement())).getContext("2d").As <CanvasRenderingContext2D>();

            c.font = f;
            return(c.measureText(t));
        }
Exemplo n.º 30
0
        public static HTMLCanvasElement CloneCanvas(HTMLCanvasElement C)
        {
            HTMLCanvasElement ret = new HTMLCanvasElement();

            ret.Width  = C.Width;
            ret.Height = C.Height;
            CanvasRenderingContext2D g = ret.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            g.DrawImage(C, 0f, 0f);
            return(ret);
        }
Exemplo n.º 31
0
 public TinyPlotter(PlotSettings settings)
 {
     Settings = settings;
     Canvas = new HTMLCanvasElement();
     Canvas.Height = Settings.Height;
     Canvas.Width = Settings.Width;
     Canvas.Style.Border = "1px solid black";
     var ctx = Canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
     var image = ctx.CreateImageData(Canvas.Width, Canvas.Height);
     if (Settings.DrawXAxis)
         DrawXAxis(image);
     if (Settings.DrawXAxis)
         DrawYAxis(image);
     ctx.PutImageData(image, 0, 0);
 }
Exemplo n.º 32
0
        private void GetImageData(HTMLCanvasElement canvas)
        {
            int height = canvas.Height;
            int width = canvas.Width;

            if (CanvasRenderingContext == null)
            {
                CanvasRenderingContext = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            }

            if (Image == null)
            {
                // the data to manipulate
                Image = CanvasRenderingContext.CreateImageData(width, height);
            }
            else
            {
                //var color = new Color() { Red = 0, Green = 0, Blue = 0 };

                //for (int y = 0; y < height; y++)
                //{
                //    for (int x = 0; x < width; x++)
                //    {
                //        Image.SetPixel(x, y, color);
                //    }
                //}
            }
        }
Exemplo n.º 33
0
        public Drawer(Options settings, Mandelbrot calculator)
        {
            this.Settings = settings;
            this.Calculator = calculator;

            // the actual canvas element
            var canvas = new HTMLCanvasElement();
            canvas.Width = 900;
            canvas.Height = 500;

            DrawButton = new HTMLButtonElement
            {
                InnerHTML = "Draw the Mandelbrot fractal",
                OnClick = (ev) =>
                {
                    StartDraw(canvas);
                }
            };

            DrawButton.SetAttribute("style", "font-size:18px;height: 60px;  width:95%; border: 2px solid black; cursor: pointer");

            // Iteration controls
            RadiusElement = GetInputNumberElement(null, this.Settings.MaxRadius, 3, 0.5);
            IterationCountElement = GetInputNumberElement(null, this.Settings.MaxIterations, 4, 100, 0, 100000);
            // Color controls
            ColorMapCheckbox = GetCheckboxElement(this.Settings.UseColorMap);
            ColorScaleElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorScale, 5, 1000);
            ColorOffsetElement = GetInputNumberElement(ColorMapCheckbox, this.Settings.ColorOffset, 4, 10);

            // Julia sets
            JuliaSetCheckbox = GetCheckboxElement(this.Settings.UseJuliaSet);
            JuliaImElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Im, 5, 0.005, null);
            JuliaReElement = GetInputNumberElement(JuliaSetCheckbox, this.Settings.JuliaSetParameter.Re, 5,  0.005, null);

            // Viewport controls
            XMinElement = GetInputNumberElement(null, this.Settings.XMin, 5, 0.005, -5.0);
            XMaxElement = GetInputNumberElement(null, this.Settings.XMax, 5, 0.005, 0.0);
            YMinElement = GetInputNumberElement(null, this.Settings.YMin, 5, 0.005, -5.0);
            YMaxElement = GetInputNumberElement(null, this.Settings.YMax, 5, 0.005, 0.0);

            var paramsColumn = new HTMLTableDataCellElement();
            var canvasColumn = new HTMLTableDataCellElement();
            paramsColumn.SetAttribute("valign", "top");
            canvasColumn.SetAttribute("valign", "top");
            canvasColumn.AppendChild(canvas);

            var layoutRow = new HTMLTableRowElement();
            layoutRow.AppendChildren(paramsColumn, canvasColumn);

            var layout = new HTMLTableElement();

            var paramsTable = new HTMLTableElement();
            paramsTable.AppendChildren(
                Row(Label("XMin: "), XMinElement),
                Row(Label("XMax: "), XMaxElement),
                Row(Label("YMin: "), YMinElement),
                Row(Label("YMax: "), YMaxElement),
                Row(Label("Escape radius: "), RadiusElement),
                Row(Label("Iteration count: "), IterationCountElement),
                Row(Label("Use color map: "), ColorMapCheckbox),
                Row(Label("Color scale: "), ColorScaleElement),
                Row(Label("Color offset: "), ColorOffsetElement),
                Row(Label("Use Julia set: "), JuliaSetCheckbox),
                Row(Label("Im: "), JuliaImElement),
                Row(Label("Re: "), JuliaReElement),
                Row(new HTMLHRElement(), 2),
                Row(DrawButton, 2)
            );

            paramsColumn.AppendChild(paramsTable);

            layout.AppendChild(layoutRow);
            Document.Body.AppendChild(layout);
        }
Exemplo n.º 34
0
        private void StartDraw(HTMLCanvasElement canvas)
        {
            if (!GetInputValue(IterationCountElement, out this.Settings.MaxIterations))
            {
                Window.Alert("Iteration count should be positive integer");
                return;
            }

            if (!GetInputValue(RadiusElement, out this.Settings.MaxRadius))
            {
                Window.Alert("Escape radius should be positive integer");
                return;
            }

            if (!GetInputValue(XMinElement, out this.Settings.XMin))
            {
                Window.Alert("XMin should be a number");
                return;
            }

            if (!GetInputValue(XMaxElement, out this.Settings.XMax))
            {
                Window.Alert("XMax should be a number");
                return;
            }

            if (!GetInputValue(YMinElement, out this.Settings.YMin))
            {
                Window.Alert("YMin should be a number");
                return;
            }

            if (!GetInputValue(YMaxElement, out this.Settings.YMax))
            {
                Window.Alert("YMax should be a number");
                return;
            }

            this.Settings.UseColorMap = ColorMapCheckbox.Checked;
            if (this.Settings.UseColorMap)
            {
                if (!GetInputValue(ColorScaleElement, out this.Settings.ColorScale))
                {
                    Window.Alert("Color scale should be positive integer");
                    return;
                }

                if (!GetInputValue(ColorOffsetElement, out this.Settings.ColorOffset))
                {
                    Window.Alert("Color offset should be positive integer");
                    return;
                }
            }

            this.Settings.UseJuliaSet = JuliaSetCheckbox.Checked;
            if (this.Settings.UseJuliaSet)
            {
                if (!GetInputValue(JuliaImElement, out this.Settings.JuliaSetParameter.Im))
                {
                    Window.Alert("Julia Im should be a number");
                    return;
                }

                if (!GetInputValue(JuliaReElement, out this.Settings.JuliaSetParameter.Re))
                {
                    Window.Alert("Julia Re should be a number");
                    return;
                }
            }

            GetImageData(canvas);

            CurrentY = 0;
            DrawPart();
        }
Exemplo n.º 35
0
 private void InitializePlot()
 {
     Canvas = new HTMLCanvasElement();
     Canvas.Height = Settings.Height;
     Canvas.Width = Settings.Width;
     if (Settings.DrawBorder)
         Canvas.Style.Border = "1px solid black";
     var ctx = Canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
     var image = ctx.CreateImageData(Canvas.Width, Canvas.Height);
     if (Settings.DrawXAxis)
         DrawXAxis(image);
     if (Settings.DrawXAxis)
         DrawYAxis(image);
     ctx.PutImageData(image, 0, 0);
 }