GetContext() public method

public GetContext ( CanvasContextId contextId ) : CanvasRenderingContext
contextId CanvasContextId
return System.Html.Media.Graphics.CanvasRenderingContext
Esempio n. 1
0
        public void Run()
        {
            _backgroundImageElement = Document.GetElementById("backgroundImage").As<ImageElement>();
            _imageStripElement = Document.GetElementById("imageStrip").As<ImageElement>();
            _tankCanvas = Document.GetElementById("fishTankCanvas").As<CanvasElement>();
            _fishesCanvas = Document.GetElementById("fishesCanvas").As<CanvasElement>();

            Debug.Assert(_backgroundImageElement != null);
            Debug.Assert(_imageStripElement != null);
            Debug.Assert(_tankCanvas != null);
            Debug.Assert(_fishesCanvas != null);

            _tankCanvasContext = (CanvasContext2D)_tankCanvas.GetContext(Rendering.Render2D);
            _fishesCanvasContext = (CanvasContext2D)_fishesCanvas.GetContext(Rendering.Render2D);

            _fishes = new List<Fish>();
            for (int i = 0; i < FishTank.FishCount; i++) {
                double x = Math.Floor(Math.Random() * (_width - FishTank.FishWidth) + FishTank.FishWidth / 2);
                double y = Math.Floor(Math.Random() * (_height - FishTank.FishHeight) + FishTank.FishHeight / 2);
                double z = Math.Floor(Math.Random() * (FishTank.ZFar - FishTank.ZNear));

                _fishes.Add(new Fish(this, x, y, z, _imageStripElement, _fishesCanvasContext));
            }

            OnWindowResize(null);
            Window.AddEventListener("resize", OnWindowResize, false);

            _tickHandler = OnTick;
            QueueUpdate();
        }
       public Bitmap(int w, int h)
       {
           width = w;
           height = h;

           canvas = (CanvasElement) Document.GetElementById("canvas");
           context = (CanvasRenderingContext2D) canvas.GetContext(CanvasContextId.Render2D); // "2d"    
           context.GlobalCompositeOperation = CompositeOperation.Copy;  // ### it was: CompositeOperation         
           imagedata = context.CreateImageData(w,1);  // w,h
       }
Esempio n. 3
0
        public static CanvasInformation Create(CanvasElement 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, jQuery.FromElement(canvas));
        } 
        public static CanvasInformation Create(CanvasElement canvas, int w, int h,bool pixelated)
        {
            if (w == 0) w = 1;
            if (h == 0) h = 1;
            canvas.Width = w;
            canvas.Height = h;

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

        
            if (pixelated)
            {
                ctx.Me().webkitImageSmoothingEnabled = false;
                ctx.Me().mozImageSmoothingEnabled = false;
                ctx.Me().imageSmoothingEnabled = false;
            }
            return new CanvasInformation(ctx, jQuery.FromElement(canvas));
        }
Esempio n. 5
0
        private static void start()
        {
            canvas = (CanvasElement)Document.GetElementById("canvas");
            context = (CanvasRenderingContext2D)canvas.GetContext(CanvasContextId.Render2D);

            Offset = new Vector2(0, 0);

            Vector2 draggingPos = null;
            canvas.OnMousedown = @event =>
            {
                int mouseX = ((dynamic)@event).pageX;
                int mouseY = ((dynamic)@event).pageY;
                draggingPos = new Vector2(mouseX, mouseY);
            };
            canvas.OnMouseup = @event =>
            {
                /*
                                if (draggingPos == null) return;

                                int mouseX = ((dynamic)@event).pageX;
                                int mouseY = ((dynamic)@event).pageY;

                                draggingPos = new Vector2(draggingPos.X - mouseX, draggingPos.Y - mouseY);

                                Offset = new Vector2(Offset.X + draggingPos.X, Offset.Y + draggingPos.Y);
                                draw();


                */
                draggingPos = null;
            };
            Document.OnMousemove = @event =>
            {
                if (draggingPos == null) return;

                int mouseX = ((dynamic)@event).pageX;
                int mouseY = ((dynamic)@event).pageY;

                Offset = new Vector2(Offset.X + (draggingPos.X - mouseX) * 6, Offset.Y + (draggingPos.Y - mouseY) * 6);

                draggingPos = new Vector2(mouseX, mouseY);
                Draw();
            };



            canvas.Width = Document.Body.ClientWidth - 100;
            canvas.Height = Document.Body.ClientHeight - 100;
            context.Save();
            context.Font = "50px Arial";
            context.FillText("Loading...", canvas.Width / 2, canvas.Height / 2);
            context.Restore();


            Window.OnKeydown = @event =>
            {
                if (((dynamic)@event).keyCode == 17)
                {
                    drawLines = !drawLines;
                }
                Draw();
            };


        
             


            Window.SetTimeout(() =>
            {
                Console.WriteLine("Started");
                Console.Profile();

                Stopwatch sw = new Stopwatch();
                sw.Start();
                tree = new RTree<Player>();
                players = new List<Player>();
                for (int j = 0; j < numberOfPlayers; j++)
                {
                    var player = new Player(nextId());
                    player.X = rand.Next(0, gameSize);
                    player.Y = rand.Next(0, gameSize);
                    players.Add(player);
                    tree.Add(new Rectangle(player.X, player.Y), player);
                }

                buildClusters(viewRadius);

                sw.Stop();
                Console.ProfileEnd();
                Console.WriteLine(string.Format("Time {0}", sw.ElapsedMilliseconds));
                Console.WriteLine("Done");
                Draw();
            });
        }
Esempio n. 6
0
        public void Setup(CanvasElement canvas)
        {
            canvas.AddEventListener("dblclick", OnDoubleClick, false);
            //canvas.AddEventListener("mousemove", OnMouseMove, false);
            //canvas.AddEventListener("mouseup", OnMouseUp, false);
            //canvas.AddEventListener("pointerdown", OnPointerDown, false);
            canvas.AddEventListener("mousedown", OnMouseDown, false);
            canvas.AddEventListener("mousewheel", OnMouseWheel, false);
            canvas.AddEventListener("DOMMouseScroll", OnMouseWheel, false);  // this is for firefox as it does not support mousewheel
            canvas.AddEventListener("touchstart", OnTouchStart, false);
            canvas.AddEventListener("touchmove", OnTouchMove, false);
            canvas.AddEventListener("touchend", OnTouchEnd, false);
            canvas.AddEventListener("gesturechange", OnGestureChange, false);
            canvas.AddEventListener("gesturestart", OnGestureStart, false);
            canvas.AddEventListener("gestureend", OnGestureEnd, false);
            Document.Body.AddEventListener("keydown", OnKeyDown, false);
            //canvas.AddEventListener("MSGestureChange", OnGestureChange, false);
            //canvas.AddEventListener("mouseout", OnMouseUp, false);

            // MS Touch code
            canvas.AddEventListener("pointerdown", OnPointerDown, false);

            canvas.AddEventListener("pointermove", OnPointerMove, false);

            canvas.AddEventListener("pointerup", OnPointerUp, false);

            // End MS touch code

            RenderContext.ViewCamera.Lat = StartLat;
            RenderContext.ViewCamera.Lng = StartLng;
            RenderContext.ViewCamera.Zoom = StartZoom;

            RenderContext.TargetCamera = RenderContext.ViewCamera.Copy();

            if (RenderContext.gl == null)
            {

                foregroundCanvas = (CanvasElement)Document.CreateElement("canvas");
                foregroundCanvas.Width = canvas.Width;
                foregroundCanvas.Height = canvas.Height;
                fgDevice = (CanvasContext2D)foregroundCanvas.GetContext(Rendering.Render2D);
            }
            webFolder = new Folder();
            webFolder.LoadFromUrl("http://www.worldwidetelescope.org/wwtweb/catalog.aspx?X=ImageSets5", SetupComplete);

            WebFile webFile = new WebFile("http://www.worldwidetelescope.org/wwtweb/weblogin.aspx?user=12345678-03D2-4935-8D0F-DCE54C9113E5&Version=HTML5&webkey=AX2011Gqqu&platform=web");
            webFile.Send();
        }