Exemplo n.º 1
0
        public void Highlight()
        {
            var context = _canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            context.FillStyle = Theme.HighlightColor;
            context.FillRect((int)_cell.X, (int)_cell.Y, (int)_cell.Width, (int)_cell.Width);
            context.FillStyle = Theme.DefaultFill;
        }
Exemplo n.º 2
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.º 3
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.º 4
0
 public Sprite()
 {
     spriteBuffer   = new HTMLCanvasElement();
     spriteGraphics = spriteBuffer.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
     spriteGraphics.ImageSmoothingEnabled = false;
     Position = new Vector2();
 }
Exemplo n.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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//+mm3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rUmOQNpJFa/r+sa4e/pBlAABoAAAAA3CUgShLdGIxsY7AUABPRrgCABdDuQ5GC7DqPQCgbbJUAoRSUj+NIEig0YfyWUho1VBBBA//uQZB4ABZx5zfMakeAAAAmwAAAAF5F3P0w9GtAAACfAAAAAwLhMDmAYWMgVEG1U0FIGCBgXBXAtfMH10000EEEEEECUBYln03TTTdNBDZopopYvrTTdNa325mImNg3TTPV9q3pmY0xoO6bv3r00y+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.º 10
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.º 11
0
        public static void Main()
        {
            getContainerProperties();

            setupCanvas();

            Sky sky = new Sky(container.ClientWidth, container.ClientHeight, timLimitScale, gScale, newPlanetSpeedScale, timeScale);

            //Add a bunch of new planets at random places
            sky.addRandomPlanets(startPlanets);

            //Register resize listener

            /*
             * Window.OnResize = (e) =>
             * {
             *      canvas.Width = container.ClientWidth;
             *      canvas.Height = container.ClientHeight;
             *      sky.xSize = canvas.Width;
             *      sky.ySize = canvas.Height;
             * };
             */

            //Capture the rendering context for the sky
            CanvasRenderingContext2D ctx = (CanvasRenderingContext2D)canvas.GetContext("2d");

            double timestamp = Global.Performance.Now();

            Window.RequestAnimationFrame((t) => {
                renderFrame(sky, ctx, t, timestamp, true);
            });
        }
Exemplo n.º 12
0
        public void Draw()
        {
            var context = Canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            context.ClearRect(0, 0, Canvas.Width, Canvas.Height);
            foreach (var child in Children)
            {
                if (child is DrawnGameObject)
                {
                    var drawObject = child.As <DrawnGameObject>();
#pragma warning disable CS0184 // 'is' expression's given expression is never of the provided type
                    if (drawObject.Image is string)
#pragma warning restore CS0184 // 'is' expression's given expression is never of the provided type
                    {
                        context.FillStyle = drawObject.Image.As <string>();
                        context.FillRect((int)drawObject.X, (int)drawObject.Y, (int)drawObject.Width, (int)drawObject.Height);
                    }
                    else
                    {
                        context.DrawImage(drawObject.Image.As <HTMLImageElement>(), drawObject.X, drawObject.Y, drawObject.Width, drawObject.Height);
                    }
                    if (drawObject.Selected)
                    {
                        context.StrokeStyle = "#4286f4";
                        context.StrokeRect((int)drawObject.X - 1, (int)drawObject.Y - 1, (int)drawObject.Width + 2, (int)drawObject.Height + 2);
                    }
                }
            }
        }
Exemplo n.º 13
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.º 14
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.º 15
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";
 }
Exemplo n.º 16
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.º 17
0
        private void ImageLoad(HTMLImageElement image)
        {
            var canvas = new HTMLCanvasElement
            {
                Width  = image.Width,
                Height = image.Height
            };
            var context = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            context.DrawImage(image, 0, 0);
            _data = context.GetImageData(0, 0, canvas.Width, canvas.Height);
            Load?.Invoke();
        }
Exemplo n.º 18
0
        /// <summary>
        /// Sets up the CanvasElement and its context
        /// <param name="UseDefaults">Set to true to have the canvas take up the entire screen; the background color will also be turned black to make sure it worked and all that.</param>
        /// </summary>
        public static void Create(bool UseDefaults = false)
        {
            if (!Created)
            {
                // If using default layout, set the CSS, width and height
                if (UseDefaults)
                {
                    Position        = Position.Absolute;
                    Left            = "0px";
                    Top             = "0px";
                    Width           = Window.InnerWidth;
                    Height          = Window.InnerHeight;
                    BackgroundColor = "black";
                }

                Window.AddEventListener("resize", () =>
                {
                    if (Orientation == Orientation.PORTRAIT)
                    {
                        if (Window.InnerWidth > Window.InnerHeight)
                        {
                            // Left off here
                        }
                        else
                        {
                        }
                    }
                    if (Orientation == Orientation.LANDSCAPE)
                    {
                        if (Window.InnerWidth > Window.InnerHeight)
                        {
                        }
                        else
                        {
                        }
                    }
                });

                // Add the CanvasElement element to the page
                Document.Body.AppendChild(CanvasElement);

                // Try to get its "context"
                Context = CanvasElement.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
                if (Context.Equals(null))
                {
                    throw new KissException("CanvasElementError: HTML5 CanvasElement not supported.");
                }
                Created = true;     // So it won't bug out if someone calls Create twice
            }
        }
Exemplo n.º 19
0
        public virtual BitmapData clone()
        {
            var bitmapData = new BitmapData();
            var canvas     = new HTMLCanvasElement();

            canvas.Width  = this.width;
            canvas.Height = this.height;
            var context2d = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            var ctx       = new RenderingContext2D(context2d);

            this.drawSelf(context2d, 0, 0, this.width, this.height);
            bitmapData.internalImage = context2d;
            return(bitmapData);
        }
Exemplo n.º 20
0
        static void ApplyImage(HTMLCanvasElement tmpImg)
        {
            ImageEncoding.ImageType imgType     = ImageEncoding.ImageTypesByID[t.NameToImageID(ImageInputSenderID)];
            HTMLCanvasElement       FinalCanvas = new HTMLCanvasElement();

            FinalCanvas.Width  = imgType.s.x;
            FinalCanvas.Height = imgType.s.y;

            if (tmpImg == null)
            {
                t.GetTexture(ImageInputSenderID).tex = null;
                var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d"));
                context.FillRect(0, 0, imgType.s.x, imgType.s.y);
            }
            else if (tmpImg.Width == imgType.ActualSize.x && tmpImg.Height == imgType.ActualSize.y)
            {
                var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d"));
                context.FillRect(0, 0, imgType.s.x, imgType.s.y);
                context.DrawImage(tmpImg, 0, 0);
            }
            else if (tmpImg.Width == imgType.s.x && tmpImg.Height == imgType.s.y)
            {
                FinalCanvas = tmpImg;
            }
            else
            {
                var context = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d"));
                context.FillRect(0, 0, imgType.s.x, imgType.s.y);
                context.DrawImage(tmpImg, 0, 0, imgType.ActualSize.x, imgType.ActualSize.y);
            }

            var img = ((CanvasRenderingContext2D)FinalCanvas.GetContext("2d")).GetImageData(0, 0, imgType.s.x, imgType.s.y);

            t.GetTexture(ImageInputSenderID).tex = tmpImg == null ? null : img;

            UpdateShownImg(imgType, ImageInputSenderID, img);
        }
Exemplo n.º 21
0
        public Pong()
        {
            canvas = Document.GetElementById("pong") as HTMLCanvasElement;
            ctx    = canvas.GetContext("2d").As <CanvasRenderingContext2D>();

            gameInfo = Document.GetElementById("gameInfo") as HTMLParagraphElement;

            try
            {
                highscore = ulong.Parse(Window.LocalStorage["highscore"].ToString());
            }
            catch { }

            pong = this;

            canvas.OnClick = (ev) => { if (!ingame)
                                       {
                                           Achievement.achievements[(int)Achievement.eAchievs.Upgrade].isSpecial = false; Achievement.Check(); pWidth = 200; pX = ev.ClientX - 250; ingame = true; score = 0; ball = new Ball {
                                               x = canvas.OffsetWidth / 2, y = canvas.OffsetHeight / 2, vx = new double[] { -0.5, -0.4, -0.3, -0.2, -0.1, 0.1, 0.2, 0.3, 0.4, 0.5 }[new Random().Next(10)], vy = 5
                                           }; ball.Move();
                                       }
            };
            Document.Body.OnMouseMove = (ev) =>
            {
                pX = ev.ClientX - 90 - canvas.OffsetLeft;
                if (pX < 0)
                {
                    pX = 0;
                }
                if (pX + pWidth > canvas.OffsetWidth)
                {
                    pX = canvas.OffsetWidth - pWidth;
                }
            };
            // Mobile devices

            /*
             * canvas.OnTouchMove = (ev) =>
             * {
             *  pX = ev.PageX - 250;
             *  Console.WriteLine(ev.PageX - 250);
             *  if (pX < 0)
             *      pX = 0;
             *  if (pX + pWidth > canvas.OffsetWidth)
             *      pX = canvas.OffsetWidth - pWidth;
             * };*/

            gameInfo.InnerHTML = $"Score: {score}<br />Highscore: {highscore}";
        }
Exemplo n.º 22
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);
 }
        private static HTMLCanvasElement UpscaleImage(HTMLImageElement img, double scale)
        {
            var nWidth  = (int)Math.Round(img.Width * scale);
            var nHeight = (int)Math.Round(img.Height * scale);

            var imgCV = new HTMLCanvasElement();

            imgCV.Width  = nWidth;
            imgCV.Height = nHeight;
            var imgCtx = imgCV.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            imgCtx.DrawImage(img, 0, 0, nWidth, nHeight);

            return(imgCV);
        }
        public static CanvasInformation Create(HTMLCanvasElement canvas, int w, int h)
        {
            if (w == 0)
            {
                w = 1;
            }
            if (h == 0)
            {
                h = 1;
            }
            canvas.Width  = w;
            canvas.Height = h;

            var ctx = (CanvasRenderingContext2D)canvas.GetContext("2d");

            return(new CanvasInformation(ctx, canvas));
        }
Exemplo n.º 25
0
        public Camera(HTMLCanvasElement canvas, double resolution, double focalLength)
        {
            Ctx = canvas.GetContext(CanvasContext2DType.CanvasRenderingContext2D);

            canvas.Width = (int)(Window.InnerWidth * 0.5);
            Width        = canvas.Width;

            canvas.Height = (int)(Window.InnerHeight * 0.5);
            Height        = canvas.Height;

            Resolution  = resolution;
            Spacing     = Width / Resolution;
            FocalLength = focalLength > 0 ? focalLength : 0.8;
            Range       = 14;
            LightRange  = 5;
            Scale       = (Width + Height) / 1200;
        }
        private static HTMLCanvasElement DownscaleImage(HTMLImageElement img, double scale)
        {
            var nWidth  = (int)Math.Round(img.Width * scale);
            var nHeight = (int)Math.Round(img.Height * scale);

            var imgCV = new HTMLCanvasElement();

            imgCV.Width  = img.Width;
            imgCV.Height = img.Height;
            var imgCtx = imgCV.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);

            imgCtx.DrawImage(img, 0, 0);

            Script.Write <HTMLCanvasElement>("resample_single(imgCV,nWidth,nHeight,true);");

            return(imgCV);
        }
Exemplo n.º 27
0
        public Bitmap(int width, int height)
        {
            if (width < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(width));
            }
            if (height < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(height));
            }

            _canvas        = Document.CreateElement <HTMLCanvasElement>("canvas");
            _canvas.Width  = width;
            _canvas.Height = height;
            _context       = _canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            _disposed      = false;
        }
Exemplo n.º 28
0
        public App(HTMLCanvasElement screen)
        {
            this.canvasScreen = screen;
            ctx = screen.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            ctx.ImageSmoothingEnabled = true;

            bgImage = new HTMLImageElement()
            {
                Src = "img/bg.png"
            };
            toad = new HTMLImageElement()
            {
                Src = "img/toad.png"
            };

            screen.AddEventListener(EventType.Click, Clicked);
            panelViewModel.FocusBestPosition();
        }
Exemplo n.º 29
0
        public Bitmap(Bitmap source, Size resizeTo)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }
            if ((resizeTo.Width < 0) || (resizeTo.Height < 0))
            {
                throw new ArgumentOutOfRangeException(nameof(resizeTo));
            }

            _canvas        = Document.CreateElement <HTMLCanvasElement>("canvas");
            _canvas.Width  = resizeTo.Width;
            _canvas.Height = resizeTo.Height;
            _context       = _canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            _context.DrawImage(source._canvas, 0, 0, resizeTo.Width, resizeTo.Height);
            _disposed = false;
        }
Exemplo n.º 30
0
        public App(HTMLCanvasElement screen)
        {
            this.canvasScreen = screen;
            ctx = screen.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            ctx.ImageSmoothingEnabled = true;
            LastMousePos             = new Vec2i();
            LastPinchGestureDistance = 0.0;

            Window.AddEventListener(EventType.Resize, OnSizeChanged);
            screen.AddEventListener(EventType.Wheel, OnMouseWheel);
            screen.AddEventListener(EventType.MouseDown, OnMouseDown);
            screen.AddEventListener(EventType.MouseUp, OnMouseUp);
            screen.AddEventListener(EventType.MouseMove, OnMouseMove);
            screen.AddEventListener(EventType.TouchStart, OnTouchStart);
            screen.AddEventListener(EventType.TouchEnd, OnTouchEnd);
            screen.AddEventListener(EventType.TouchMove, OnTouchMove);

            ReadLayerInfos();
        }
Exemplo n.º 31
0
        /// <summary>
        /// This is called when the game should draw itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected void Draw()
        {
            if (!needsRedraw)
            {
                return;
            }

            needsRedraw = false;

            context      = canvas.GetContext(CanvasTypes.CanvasContext2DType.CanvasRenderingContext2D);
            context.Font = "9px arial";
            DrawRectangle(new Rectangle(0, 0, 1024, 720), new Color(94, 54, 54));

            DrawCube(showingCube, showingPosition.B16, showingPosition, new Vector2(30, 30), blockSize);

            DrawString("Current color: ", new Vector2(850, 20), Color.Black);
            IGifValue currentValue = gifScriptState.current;

            DrawGifValue(currentValue, new Vector2(850, 40), blockSize);

            DrawString("Registers: ", new Vector2(850, 100), Color.Black);
            DrawString("Name", new Vector2(850, 120), Color.Black);
            DrawString("Pos", new Vector2(900, 120), Color.Black);
            DrawString("Value", new Vector2(950, 120), Color.Black);
            Vector2 registerDrawPos = registersScreenPos;

            foreach (ColorRGB register in interestingRegisters)
            {
                DrawColorBlock(register, registerDrawPos, blockSize);

                ColorRGB registerPos = gifScriptState.GetRegisterPosition(register);
                DrawColorBlock(registerPos, new Vector2(registerDrawPos.X + blockSize.X + 1, registerDrawPos.Y), blockSize);
                DrawCell(gifScriptState.GetRegisterTarget(register), registerPos.R16, registerPos.G16, registerPos.B16, new Vector2(registerDrawPos.X + blockSize.X * 2 + 2, registerDrawPos.Y), blockSize);

                if (gifScriptState.runningRegister == register)
                {
                    DrawImage(runningTexture, new Vector2(registerDrawPos.X + 17, registerDrawPos.Y + 18));
                }

                registerDrawPos.Y += registersScreenSpacing;
            }
            Global.RequestAnimationFrame(e => Draw());
        }
Exemplo n.º 32
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);
 }
Exemplo n.º 33
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);
                //    }
                //}
            }
        }