Exemple #1
0
        private void Draw()
        {
            if (_width < FishTank.BackgroundImageWidth)
            {
                // Show just a portion of the background image, since the window is
                // smaller than the background
                _tankCanvasContext.DrawImage(_backgroundImageElement, 0, 0, FishTank.BackgroundImageWidth, _height);
            }
            else
            {
                // Tile the background image horizontally if the window is wider than
                // the background

                int    tileCount = (int)(_width / FishTank.BackgroundImageWidth);
                double flip      = 1;

                for (int i = 0; i <= tileCount; i++)
                {
                    _tankCanvasContext.Save();
                    _tankCanvasContext.Transform(flip, 0, 0, 1, 0, 0);
                    _tankCanvasContext.DrawImage(_backgroundImageElement,
                                                 (flip - 1) * FishTank.BackgroundImageWidth / 2 + flip * FishTank.BackgroundImageWidth * i,
                                                 0, FishTank.BackgroundImageWidth, _height);
                    _tankCanvasContext.Restore();
                    flip = -flip;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Performs pixel level collision between two masks
        /// </summary>
        /// <param name="mask1">The mask1.</param>
        /// <param name="mask2">The mask2.</param>
        /// <param name="x">The x.</param>
        /// <param name="y">The y.</param>
        /// <returns></returns>
        public static bool Collision(string mask1, string mask2, float x, float y)
        {
            CanvasElement canvas1 = _masks[mask1];

            if (x > canvas1.Width || y > canvas1.Height)
            {
                return(false);
            }

            CanvasElement canvas2 = _masks[mask2];

            if (canvas2.Width + x < 0 || canvas2.Height + y < 0)
            {
                return(false);
            }

            int top    = Math.Round(Math.Max(0, y));
            int height = Math.Round(Math.Min(canvas1.Height, y + canvas2.Height) - top);
            int left   = Math.Round(Math.Max(0, x));
            int width  = Math.Round(Math.Min(canvas1.Width, x + canvas2.Width) - left);

            if (width <= 0 || height <= 0)
            {
                return(false);
            }

            CanvasElement checkCanvas = (CanvasElement)Document.CreateElement("Canvas");

            checkCanvas.Width  = width;
            checkCanvas.Height = height;

            CanvasContext2D context = (CanvasContext2D)checkCanvas.GetContext(Rendering.Render2D);

            context.FillStyle = "white";
            context.FillRect(0, 0, checkCanvas.Width, checkCanvas.Height);
            context.CompositeOperation = CompositeOperation.Xor;

            context.DrawImage(canvas1, left, top, width, height, 0, 0, width, height);
            context.DrawImage(canvas2, Math.Round(left - x), Math.Round(top - y), width, height, 0, 0, width, height);

            PixelArray data = context.GetImageData(0, 0, width, height).Data;

            for (int i = 0; i < data.Length; i += 4)
            {
                if ((int)data[i] > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Exemple #3
0
        private void UpdateFlak(CanvasContext2D context, float speed)
        {
            if (Math.Random() * 100 < 2)
            {
                float x          = Math.Random() * 800;
                float startAngle = Math.Random() * 2 - 3;
                float interval   = 0.08f - Math.Random() / 100;

                for (int i = 0; i < 5 + Math.Floor(Math.Random() * 8); i++)
                {
                    _flakObjects.Add(new FlakObject(startAngle + i * interval, x, i * 400));
                }
            }

            List <FlakObject> toRemove = new List <FlakObject>();

            foreach (FlakObject flakObject in _flakObjects)
            {
                if (flakObject.Update())
                {
                    toRemove.Add(flakObject);
                }
                flakObject.X += 0.3f * speed;
                context.DrawImage(_flakImage, flakObject.X, flakObject.Y);
            }

            foreach (FlakObject flakObject in toRemove)
            {
                _flakObjects.Remove(flakObject);
            }
        }
Exemple #4
0
        private void UpdateExplosions(CanvasContext2D context, float speed)
        {
            if (Math.Random() * 100 < 2)
            {
                Explosion explosion = new Explosion();
                explosion.X     = Math.Random() * 800;
                explosion.start = DateTime.Now;
                _explosions.Add(explosion);
            }

            Explosion toDelete = null;

            foreach (Explosion explosion in _explosions)
            {
                explosion.X = explosion.X - (0.3f * speed);
                double y = 240 + (DateTime.Now - explosion.start) * 0.5;
                context.DrawImage(_explosionImage, explosion.X - 133, y);
                if (y >= 319)
                {
                    toDelete = explosion;
                }
            }

            if (toDelete != null)
            {
                _explosions.Remove(toDelete);
            }
        }
Exemple #5
0
        public virtual void MakeTexture()
        {
            if (PrepDevice != null)
            {
                //     PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);

                try
                {
                    texture2d = PrepDevice.createTexture();

                    if (dataset.Extension == ".fits" && RenderContext.UseGlVersion2)
                    {
                        PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);

                        PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.R32F, (int)fitsImage.SizeX, (int)fitsImage.SizeY, 0, GL.RED, GL.FLOAT, fitsImage.dataUnit);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.NEAREST);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MAG_FILTER, GL.NEAREST);
                    }
                    else
                    {
                        ImageElement image = texture;

                        // Before we bind resize to a power of two if nessesary so we can MIPMAP
                        if (!Texture.IsPowerOfTwo(texture.Height) | !Texture.IsPowerOfTwo(texture.Width))
                        {
                            CanvasElement temp = (CanvasElement)Document.CreateElement("canvas");
                            temp.Height = Texture.FitPowerOfTwo(image.Height);
                            temp.Width  = Texture.FitPowerOfTwo(image.Width);
                            CanvasContext2D ctx = (CanvasContext2D)temp.GetContext(Rendering.Render2D);
                            ctx.DrawImage(image, 0, 0, temp.Width, temp.Height);
                            //Substitute the resized image
                            image = (ImageElement)(Element)temp;
                        }

                        PrepDevice.bindTexture(GL.TEXTURE_2D, texture2d);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
                        PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image);
                        PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
                        PrepDevice.generateMipmap(GL.TEXTURE_2D);
                    }



                    PrepDevice.bindTexture(GL.TEXTURE_2D, null);
                }
                catch
                {
                    errored = true;
                }
            }
        }
Exemple #6
0
        public void Draw(CanvasContext2D context)
        {
            if (!Visible || Script.IsNullOrUndefined(CurrentAnimation))
            {
                return;
            }

            Sprite sprite = AnimationSequences[CurrentAnimation].Sprites[CurrentFrame];

            if (Scale == 1)
            {
                context.DrawImage(sprite.Image, Location.X - sprite.HandleX, Location.Y - sprite.HandleY);
            }
            else
            {
                context.DrawImage(sprite.Image,
                                  Location.X - sprite.HandleX * Scale,
                                  Location.Y - sprite.HandleY * Scale,
                                  sprite.Image.NaturalWidth * Scale,
                                  sprite.Image.NaturalHeight * Scale);
            }
        }
Exemple #7
0
        void DrawPlayerControls(RenderContext renderContext)
        {
            LoadImages();

            if (!imagesLoaded)
            {
                return;
            }

            if (PlayerState.State)
            {
                int span = Date.Now - lastHit;

                if (span > 7000)
                {
                    PlayerState.TargetState = false;
                }


                CanvasContext2D ctx = renderContext.Device;

                ctx.Save();
                ctx.Alpha = PlayerState.Opacity;
                top       = renderContext.Height - 60;
                center    = renderContext.Width / 2;

                ImageElement left   = leftDown ? buttonPreviousPressed : (leftHover ? buttonPreviousHover : buttonPreviousNormal);
                ImageElement middle = Playing ? (middleDown ? buttonPausePressed : (middleHover ? buttonPauseHover : buttonPauseNormal)) :
                                      (middleDown ? buttonPlayPressed : (middleHover ? buttonPlayHover : buttonPlayNormal));
                ImageElement right = rightDown ? buttonNextPressed : (rightHover ? buttonNextHover : buttonNextNormal);

                ctx.DrawImage(left, center - 110, top);
                ctx.DrawImage(right, center, top);
                ctx.DrawImage(middle, center - 32, top - 4);

                ctx.Restore();
            }
        }
Exemple #8
0
        public override void Update(CanvasContext2D context)
        {
            RoadEvent roadEvent  = null;
            int       trackIndex = 0;

            while (trackIndex < _events.Length && _events[trackIndex].Distance <= _level.Position)
            {
                roadEvent = _events[trackIndex];
                trackIndex++;
            }

            float shift = 0;
            float curve = 0;

            for (int i = 0; i < RaceLevel.Lines; i++)
            {
                float distance = _level.Position + _level.DistanceTable[i];
                while ((trackIndex < _events.Length) && (_events[trackIndex].Distance <= distance))
                {
                    roadEvent = _events[trackIndex];
                    trackIndex++;
                }

                if (trackIndex < _events.Length)
                {
                    RoadEvent nextEvent = _events[trackIndex];

                    curve = (nextEvent.Curve - roadEvent.Curve) * (distance - roadEvent.Distance) / (nextEvent.Distance - roadEvent.Distance) + roadEvent.Curve;
                }

                long index = Math.Round(distance / 2000) % 2;

                if (i > 0)
                {
                    shift += curve * (_level.DistanceTable[i + 1] - _level.DistanceTable[i]);
                }

                _level.Curves[i] = curve;
                _level.Shifts[i] = Math.Round(((299 - i) * _level.Shift) / RaceLevel.Lines) - 25 + shift;

                context.DrawImage(_road[index], 0, 299 - i, 850, 1, _level.Shifts[i], 599 - i, 850, 1);

                if (i == 0)
                {
                    _level.Curve = curve;
                }
            }
        }
Exemple #9
0
        private void MaskedResourceLoaded(ElementEvent e)
        {
            CanvasElement canvas = (CanvasElement)Document.CreateElement("CANVAS");
            ImageElement  image  = (ImageElement)e.Target;

            canvas.Width  = image.NaturalWidth;
            canvas.Height = image.NaturalHeight;

            CanvasContext2D context = (CanvasContext2D)canvas.GetContext(Rendering.Render2D);

            context.FillStyle = "black";
            context.FillRect(0, 0, image.NaturalWidth, image.NaturalHeight);
            context.CompositeOperation = CompositeOperation.Xor;
            context.DrawImage(image, 0, 0);
            _masks[image.Src] = canvas;

            ResourceLoaded(e);
        }
Exemple #10
0
        public void Draw(RenderContext renderContext)
        {
            if (!imageReady)
            {
                return;
            }

            renderContext.Device.Save();

            renderContext.WVP.ProjectArrayToScreen(worldList, transformedList);
            CanvasContext2D ctx = renderContext.Device;

            ctx.Alpha = .4;

            double width  = renderContext.Width;
            double height = renderContext.Height;

            Vector3d viewPoint = Vector3d.MakeCopy(renderContext.ViewPoint);

            double scaleFactor = renderContext.FovScale / 100;

            foreach (DataItem item in items)
            {
                // if (Vector3d.Dot(viewPoint, item.Location) < 0)
                if (item.Tranformed.Z < 1)
                {
                    double x    = item.Tranformed.X;
                    double y    = item.Tranformed.Y;
                    double size = 4 * item.Size / scaleFactor;
                    double half = size / 2;
                    if (x > -half && x < width + half && y > -half && y < height + half)
                    {
                        ctx.DrawImage(starProfile, x - size / 2, y - size / 2, size, size);

                        //ctx.BeginPath();
                        //ctx.FillStyle = "rgb(200,0,0)";
                        //ctx.Arc(x, y, size, 0, Math.PI * 2, true);
                        //ctx.Fill();
                    }
                }
            }

            renderContext.Device.Restore();
        }
Exemple #11
0
        public Color GetColorFromClick(ElementEvent e)
        {
            ImageElement image = Document.GetElementById <ImageElement>("colorhex");

            CanvasElement canvas = (CanvasElement)Document.CreateElement("canvas");

            canvas.Width  = image.Width;
            canvas.Height = image.Height;

            CanvasContext2D ctx = (CanvasContext2D)canvas.GetContext(Rendering.Render2D);

            ctx.DrawImage(image, 0, 0);

            PixelArray pixels = ctx.GetImageData(e.OffsetX, e.OffsetY, 1, 1).Data;

            Color = Color.FromArgb((float)pixels[3], (float)pixels[0], (float)pixels[1], (float)pixels[2]);

            return(Color);
        }
Exemple #12
0
        public void MakeTexture()
        {
            if (Tile.PrepDevice != null)
            {
                //     PrepDevice.pixelStorei(GL.UNPACK_FLIP_Y_WEBGL, 1);

                try
                {
                    Texture2d = Tile.PrepDevice.createTexture();

                    Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, Texture2d);

                    ImageElement image = ImageElement;

                    // Before we bind resize to a power of two if nessesary so we can MIPMAP
                    if (!IsPowerOfTwo(ImageElement.Height) | !IsPowerOfTwo(ImageElement.Width))
                    {
                        CanvasElement temp = (CanvasElement)Document.CreateElement("canvas");
                        temp.Height = FitPowerOfTwo(image.Height);
                        temp.Width  = FitPowerOfTwo(image.Width);
                        CanvasContext2D ctx = (CanvasContext2D)temp.GetContext(Rendering.Render2D);
                        ctx.DrawImage(image, 0, 0, temp.Width, temp.Height);
                        //Substitute the resized image
                        image = (ImageElement)(Element)temp;
                    }


                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_S, GL.CLAMP_TO_EDGE);
                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_WRAP_T, GL.CLAMP_TO_EDGE);
                    Tile.PrepDevice.texImage2D(GL.TEXTURE_2D, 0, GL.RGBA, GL.RGBA, GL.UNSIGNED_BYTE, image);
                    Tile.PrepDevice.texParameteri(GL.TEXTURE_2D, GL.TEXTURE_MIN_FILTER, GL.LINEAR_MIPMAP_NEAREST);
                    Tile.PrepDevice.generateMipmap(GL.TEXTURE_2D);

                    Tile.PrepDevice.bindTexture(GL.TEXTURE_2D, null);
                }
                catch
                {
                    Errored = true;
                }
            }
        }
Exemple #13
0
        public override void Draw3D(RenderContext renderContext, bool designTime)
        {
            if (texture == null)
            {
                InitializeTexture();
            }

            if (!textureReady)
            {
                return;
            }
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();

            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.Alpha = Opacity;
            ctx.DrawImage(texture, -Width / 2, -Height / 2, Width, Height);
            ctx.Restore();
        }
Exemple #14
0
        public override void Update(CanvasContext2D context)
        {
            context.Save();
            context.BeginPath();
            context.Rect(0, 0, 800, 320);
            context.ClosePath();
            context.Clip();

            float speed = -(_level.Curve * _level.Speed * 50);

            if (_level.Left && _level.Speed > 0)
            {
                speed += 1;
            }
            if (_level.Right && _level.Speed > 0)
            {
                speed -= 1;
            }

            UpdateExplosions(context, speed);

            UpdateFlak(context, speed);

            foreach (Cloud cloud in _clouds)
            {
                float scale = (400 - cloud.Y) / 400;

                cloud.X = (cloud.X - (0.3f - speed) * scale + 2400) % 2400;

                context.DrawImage(
                    _cloudImage,
                    cloud.X - 1200,
                    cloud.Y - (_cloudImage.NaturalHeight / 2) * scale,
                    _cloudImage.NaturalWidth * scale,
                    _cloudImage.NaturalHeight * scale);
            }
            context.Restore();
        }
        public void PickColor(ElementEvent e)
        {
            DivElement picker = Document.GetElementById <DivElement>("colorpicker");

            ImageElement image = Document.GetElementById <ImageElement>("colorhex");

            CanvasElement canvas = (CanvasElement)Document.CreateElement("canvas");

            canvas.Width  = image.Width;
            canvas.Height = image.Height;

            CanvasContext2D ctx = (CanvasContext2D)canvas.GetContext(Rendering.Render2D);

            ctx.DrawImage(image, 0, 0);

            PixelArray pixels = ctx.GetImageData(e.OffsetX, e.OffsetY, 1, 1).Data;

            Color = Color.FromArgb((float)pixels[3], (float)pixels[0], (float)pixels[1], (float)pixels[2]);

            if (CallBack != null)
            {
                CallBack(Color);
            }
        }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            bool inside;

            if (factor == 1.0)
            {
                inside = Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2);
            }
            else
            {
                hw     = Width / 2;
                qw     = hw * factor;
                hh     = Height / 2;
                qh     = hh * factor;
                inside = Intersects(hw - qw, hw + qw, hh - qh, hh + qh, x0, y0, x1, y1, x2, y2);
            }

            if (!inside)
            {
                return(false);
            }

            double   edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), edgeOffset);
            Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), edgeOffset);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            ctx.BeginPath();
            ctx.MoveTo(x0, y0);
            ctx.LineTo(x1, y1);
            ctx.LineTo(x2, y2);
            ctx.ClosePath();
            ctx.Clip();

            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;

            if (denom == 0)
            {
                ctx.Restore();
                return(false);
            }
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            ctx.DrawImage(im, 0, 0);

            ctx.Restore();

            if (factor != 1.0)
            {
                ctx.BeginPath();
                ctx.MoveTo(hw - qw, hh - qh);
                ctx.LineTo(hw + qw, hh - qh);
                ctx.LineTo(hw + qw, hh + qh);
                ctx.LineTo(hw - qw, hh + qh);
                ctx.ClosePath();
                ctx.StrokeStyle = "yellow";
                ctx.Stroke();
            }

            return(true);
        }
 protected override void PreUpdate(CanvasContext2D context)
 {
     context.DrawImage(_backgroundImage, 0, 0);
     Position += BaseSpeed * DeltaTime;
 }
        private bool DrawTriangle(CanvasContext2D ctx, ImageElement im, double x0, double y0, double x1, double y1, double x2, double y2,
                                  double sx0, double sy0, double sx1, double sy1, double sx2, double sy2)
        {
            if (!Intersects(0, Width, 0, Height, x0, y0, x1, y1, x2, y2))
            {
                return(false);
            }

            //double edgeOffset = isOutlined ? ContractionInPixels : ExpansionInPixels;
            //Vector2d expandedS0 = GetMiterPoint(Vector2d.Create(x0, y0), Vector2d.Create(x1, y1), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS1 = GetMiterPoint(Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), Vector2d.Create(x2, y2), ExpansionInPixels);
            //Vector2d expandedS2 = GetMiterPoint(Vector2d.Create(x2, y2), Vector2d.Create(x1, y1), Vector2d.Create(x0, y0), ExpansionInPixels);

            //Vector2d expandedS0 = MiterPoint(x0, y0, x1, y1, x2, y2);
            //Vector2d expandedS1 = MiterPoint(x1, y1, x0, y0, x2, y2);
            //Vector2d expandedS2 = MiterPoint(x2, y2, x1, y1, x0, y0);
            MiterPointOut(expandedS0, x0, y0, x1, y1, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS1, x1, y1, x0, y0, x2, y2, ExpansionInPixels);
            MiterPointOut(expandedS2, x2, y2, x1, y1, x0, y0, ExpansionInPixels);

            x0 = expandedS0.X;
            y0 = expandedS0.Y;
            x1 = expandedS1.X;
            y1 = expandedS1.Y;
            x2 = expandedS2.X;
            y2 = expandedS2.Y;


            ctx.Save();
            if (RenderingOn)
            {
                ctx.BeginPath();
                ctx.MoveTo(x0, y0);
                ctx.LineTo(x1, y1);
                ctx.LineTo(x2, y2);
                ctx.ClosePath();
                ctx.Clip();
            }
            double denom = sx0 * (sy2 - sy1) - sx1 * sy2 + sx2 * sy1 + (sx1 - sx2) * sy0;
            //if (denom == 0)
            //{
            //    ctx.Restore();
            //    return false;
            //}
            double m11 = -(sy0 * (x2 - x1) - sy1 * x2 + sy2 * x1 + (sy1 - sy2) * x0) / denom;
            double m12 = (sy1 * y2 + sy0 * (y1 - y2) - sy2 * y1 + (sy2 - sy1) * y0) / denom;
            double m21 = (sx0 * (x2 - x1) - sx1 * x2 + sx2 * x1 + (sx1 - sx2) * x0) / denom;
            double m22 = -(sx1 * y2 + sx0 * (y1 - y2) - sx2 * y1 + (sx2 - sx1) * y0) / denom;
            double dx  = (sx0 * (sy2 * x1 - sy1 * x2) + sy0 * (sx1 * x2 - sx2 * x1) + (sx2 * sy1 - sx1 * sy2) * x0) / denom;
            double dy  = (sx0 * (sy2 * y1 - sy1 * y2) + sy0 * (sx1 * y2 - sx2 * y1) + (sx2 * sy1 - sx1 * sy2) * y0) / denom;


            ctx.Transform(m11, m12, m21, m22, dx, dy);

            if (RenderingOn)
            {
                ctx.Alpha = Opacity;

                if (lighting < 1.0)
                {
                    ctx.Alpha     = 1;
                    ctx.FillStyle = "Black";
                    ctx.FillRect(0, 0, Width, Height);
                    ctx.Alpha = lighting * Opacity;
                }

                ctx.DrawImage(im, 0, 0);
            }



            ctx.Restore();
            return(true);
        }
Exemple #19
0
 public override void Update(CanvasContext2D context)
 {
     context.DrawImage(_backgroundImage, 0, 0);
 }
Exemple #20
0
        public void Paint()
        {
            CanvasContext2D g = (CanvasContext2D)Canvas.GetContext(Rendering.Render2D);

            g.FillStyle = "rgb(20, 22, 31)";
            g.FillRect(0, 0, Width, Height);
            if (!ImagesLoaded)
            {
                return;
            }
            int netHeight = (Height - buffer * 2);
            int netWidth  = (Width - buffer * 2);

            RowCount = Math.Round(Math.Max(netHeight / ThumbHeight, 1));
            ColCount = Math.Round(Math.Max(netWidth / HorzSpacing, 1));

            horzMultiple = ((float)netWidth + 13) / (float)ColCount;

            startIndex = Math.Round((startIndex / ItemsPerPage) * ItemsPerPage);

            Rectangle rectf;
            int       index = startIndex;

            for (int y = 0; y < rowCount; y++)
            {
                for (int x = 0; x < colCount; x++)
                {
                    if (index >= items.Count)
                    {
                        if (items.Count == 0 || showAddButton)
                        {
                            rectf = Rectangle.Create(Left + x * horzMultiple + 3f + startOffset, Top + y * VertSpacing, ThumbWidth - 10, 60);
                            g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, (int)((float)x * horzMultiple) + startOffset, y * VertSpacing);


                            //g.FillText(emptyText, rectf.X,rectf,Y, rectf.Width);
                            //g.DrawString(showAddButton ? addText : emptyText, UiTools.StandardRegular, (addButtonHover && showAddButton) ? UiTools.YellowTextBrush : UiTools.StadardTextBrush, rectf, UiTools.StringFormatCenterCenter);
                        }
                        break;
                    }



                    rectf = Rectangle.Create(Left + x * horzMultiple + 3 + startOffset, Top + y * VertSpacing, ThumbWidth - 14, 60);
                    //Brush textBrush = UiTools.StadardTextBrush;
                    string textBrush = "white";

                    if (index == hoverItem || (index == selectedItem && hoverItem == -1))
                    {
                        g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWideHover : bmpBackgroundHover, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing);
                        textBrush = "yellow";
                    }
                    else
                    {
                        g.DrawImage(thumbnailSize == ThumbnailSize.Big ? bmpBackgroundWide : bmpBackground, Left + (int)((float)x * horzMultiple) + startOffset, Top + y * VertSpacing);
                    }

                    (items[index]).Bounds = Rectangle.Create((int)(Left + x * horzMultiple) + startOffset, Top + (int)(y * VertSpacing), (int)horzMultiple, (int)VertSpacing);
                    try
                    {
                        ImageElement bmpThumb = items[index].Thumbnail;
                        if (bmpThumb != null)
                        {
                            g.DrawImage(bmpThumb, Left + (int)(x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3);

                            g.StrokeStyle = "rgb(0,0,0)";
                            g.Rect(Left + (int)((float)x * horzMultiple) + 2 + startOffset, Top + y * VertSpacing + 3, items[index].Thumbnail.Width, items[index].Thumbnail.Height);
                        }
                        else
                        {
                            items[index].Thumbnail     = (ImageElement)Document.CreateElement("img");
                            items[index].Thumbnail.Src = items[index].ThumbnailUrl;
                            items[index].Thumbnail.AddEventListener("load", delegate(ElementEvent e) { Refresh(); }, false);
                        }
                    }
                    // TODO FIX this!
                    catch
                    {
                    }

                    //if (((IThumbnail)items[index]).IsImage)
                    //{
                    //    g.DrawImage(Properties.Resources.InsertPictureHS, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1);
                    //}
                    //if (((IThumbnail)items[index]).IsTour)
                    //{
                    //    g.DrawImage(Properties.Resources.TourIcon, (int)((float)x * horzMultiple) + 79, y * VertSpacing + 1);
                    //}
                    //g.DrawString(((IThumbnail), UiTools.StandardRegular, textBrush, rectf, UiTools.StringFormatThumbnails);
                    g.FillStyle   = textBrush;
                    g.StrokeStyle = textBrush;
                    g.LineWidth   = 1;
                    g.Font        = "normal 8pt Arial";
                    g.FillText(items[index].Name, rectf.X, rectf.Y + rectf.Height, rectf.Width);
                    //g.FillText(items[index].Name, 10, 10);
                    index++;
                }
                if (index >= items.Count)
                {
                    break;
                }
            }
        }
Exemple #21
0
 protected override void Update(CanvasContext2D context)
 {
     context.DrawImage(_titleImage, (800 - _titleImage.NaturalWidth) / 2, 90 + Math.Cos(Ticks / 1000) * 20);
 }
Exemple #22
0
        public void Update()
        {
            // Calculate next position of fish
            double fps = FishTank.FramesPerSecond;

            _velocity = Math.Max(Math.Floor(fps * fps * .5 / 3), 1);

            double nextX     = _x + _xAngle * _velocity * FishTank.TimeDelta;
            double nextY     = _y + _yAngle * _velocity * FishTank.TimeDelta;
            double nextZ     = _z + _zAngle * .1 * _velocity * FishTank.TimeDelta;
            double nextScale = Math.Abs(nextZ) / (FishTank.ZFar - FishTank.ZNear);

            // If fish is going to move off right side of screen
            if (nextX + FishTank.FishWidth / 2 * _scale > _tank.Width)
            {
                // If angle is between 3 o'clock and 6 o'clock
                if ((_angle >= 0 && _angle < Math.PI / 2))
                {
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI / 2 * 3)
                {
                    // If angle is between 12 o'clock and 3 o'clock
                    _angle  = _angle - (_angle - Math.PI / 2 * 3) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off left side of screen
            if (nextX - FishTank.FishWidth / 2 * _scale < 0)
            {
                if ((_angle > Math.PI / 2 && _angle < Math.PI))
                {
                    // If angle is between 6 o'clock and 9 o'clock
                    _angle  = Math.PI - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
                else if (_angle > Math.PI && _angle < Math.PI / 2 * 3)
                {
                    // If angle is between 9 o'clock and 12 o'clock
                    _angle  = _angle + (Math.PI / 2 * 3 - _angle) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                    _flip   = -_flip;
                }
            }

            // If fish is going to move off bottom side of screen
            if (nextY + FishTank.FishHeight / 2 * _scale > _tank.Height)
            {
                // If angle is between 3 o'clock and 9 o'clock
                if ((_angle > 0 && _angle < Math.PI))
                {
                    _angle  = Math.PI * 2 - _angle;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle) * Math.Random();
                }
            }

            // If fish is going to move off top side of screen
            if (nextY - FishTank.FishHeight / 2 * _scale < 0)
            {
                // If angle is between 9 o'clock and 3 o'clock
                if ((_angle > Math.PI && _angle < Math.PI * 2))
                {
                    _angle  = _angle - (_angle - Math.PI) * 2;
                    _xAngle = Math.Cos(_angle);
                    _yAngle = Math.Sin(_angle);
                }
            }

            // If fish is going too far (getting too small)
            if (nextZ <= FishTank.ZNear && _zAngle < 0)
            {
                _zAngle = -_zAngle;
            }

            // If fish is getting to close (getting too large)
            if (((_tank.Width / FishTank.FishWidth) * 10) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .3;
            }
            else if (((_tank.Width / FishTank.FishWidth) * 2) < ((FishTank.FishWidth * FishTank.FishCount) / _tank.Width))
            {
                _zFactor = .5;
            }
            else
            {
                _zFactor = 1;
            }

            if (nextZ >= FishTank.ZFar * _zFactor && _zAngle > 0)
            {
                _zAngle = -_zAngle;
            }

            if (_scale < .1)
            {
                // Don't let fish get too tiny
                _scale = .1;
            }

            // Draw the fish
            _context.Save();

            // Move the fish to where it is within the fish tank
            _context.Translate(_x, _y);

            // Make the fish bigger or smaller depending on how far away it is.
            _context.Scale(_scale, _scale);

            // Make the fish face the way it is swimming.
            _context.Transform(_flip, 0, 0, 1, 0, 0);

            _context.DrawImage(_fishStrip,
                               FishTank.FishWidth * _cellIndex, FishTank.FishHeight * _species,
                               FishTank.FishWidth, FishTank.FishHeight,
                               -FishTank.FishWidth / 2, -FishTank.FishHeight / 2,
                               FishTank.FishWidth, FishTank.FishHeight);
            _context.Restore();

            // Increment to next state
            _x     = nextX;
            _y     = nextY;
            _z     = nextZ;
            _scale = nextScale;

            if ((_cellIndex >= FishTank.CellsInFishStrip - 1) || (_cellIndex <= 0))
            {
                // Go through each cell in the animation
                _cellReverse = -_cellReverse;
            }

            // Go back down once we hit the end of the animation
            _cellIndex = _cellIndex + _cellReverse;
        }
Exemple #23
0
        protected override void Update(CanvasContext2D context)
        {
            if (Status != RaceStatus.Fail && Status != RaceStatus.Win)
            {
                context.DrawImage(_timeLeftFrame, 308, 10);

                Type.SetField(context, "textAlign", "right");
                context.FillStyle = "#00AD11";

                if (TimeLeft > 10000 || Math.Floor((TimeLeft / 300) % 2) != 0)
                {
                    if (TimeLeft < 0)
                    {
                        TimeLeft = 0;
                    }
                    context.Font = "110px Digital";
                    context.FillText(Math.Floor(TimeLeft / 1000).ToString(), 475, 105);
                }

                if (Speed > 0)
                {
                    context.Save();
                    context.Scale(-1, 1);
                    long width = Math.Floor((10 * Speed) / MaxSpeed) * 22;
                    if (width > 0)
                    {
                        context.DrawImage(_meterImage, 220 - width, 0, width, 102, -561 - width, 20, width, 102);
                    }
                    context.Restore();
                }

                context.Font = "30px Digital";
                context.FillText(Math.Floor(Speed * 5) + " Km/h", 780, 120);

                int rpmWidth = Math.Floor(_rpm / 500) * 22 + 22;

                context.DrawImage(_meterImage, 220 - rpmWidth, 0, rpmWidth, 102, 240 - rpmWidth, 20, rpmWidth, 102);
                context.FillText(Math.Floor(_rpm) + " RPM", 130, 120);

                context.BeginPath();
                context.LineWidth   = 3;
                context.StrokeStyle = "#00AD11";
                context.MoveTo(5, 150);
                float x = 5 + Math.Min(Position * 735 / RoadLength, 735);
                context.LineTo(x, 150);
                context.Stroke();
                context.ClosePath();

                context.BeginPath();
                context.StrokeStyle = "#006808";
                context.MoveTo(x, 150);
                context.LineTo(790, 150);
                context.Stroke();
                context.ClosePath();
                context.DrawImage(_markerImage, x, 142);
            }

            if (Status == RaceStatus.Running)
            {
                TimeLeft -= DeltaTime;

                if (TimeLeft < 0)
                {
                    _music.Pause();
                    CarSystem.CarObject.CurrentAnimation = "Forward";
                    Status = RaceStatus.Fail;
                    ShowMessage(_failMessage);
                    RemoveSystem(_engineSoundSystem);
                    RemoveSystem(_npcSystem);
                    pendingTimers.Add(Window.SetTimeout(delegate()
                    {
                        UpdateMessage("<p>Press a key to continue.</p>");
                    }, 3000));
                }
            }
        }
Exemple #24
0
        protected override void PreUpdate(CanvasContext2D context)
        {
            // Draw background
            context.DrawImage(_backgroundImage, 0, 0);

            switch (Status)
            {
            case RaceStatus.Running:
                // Handle left and right turns
                if (Speed > 0)
                {
                    float increment = (60 - Math.Max(Speed, 20)) / 80;

                    if (Left)
                    {
                        Shift += increment * DeltaTime;
                        CarSystem.CarObject.CurrentAnimation = Down ? "b-Left" : "Left";
                    }
                    if (Right)
                    {
                        Shift -= increment * DeltaTime;
                        CarSystem.CarObject.CurrentAnimation = Down ? "b-Right" : "Right";
                    }
                }

                if (!(Left ^ Right))
                {
                    CarSystem.CarObject.CurrentAnimation = Down ? "b-Forward" : "Forward";
                }

                // Handle acceleration, braking and inertia
                if (Down)
                {
                    Speed -= 0.4f;
                }
                else if (Up)
                {
                    Speed += 0.3f;
                }
                else
                {
                    Speed -= 0.1f;
                }

                if (Up)
                {
                    _rpm += 40;
                }
                else
                {
                    _rpm -= 40;
                }
                if (_rpm > 4500)
                {
                    _rpm = 4500;
                }
                else if (_rpm < 200)
                {
                    _rpm = 200;
                }

                // When driving off the road
                if (Math.Abs(Shift) > 350)
                {
                    Speed *= 0.95f;

                    if (Math.Abs(Shift) > 450)
                    {
                        Shift = (Shift / Math.Abs(Shift)) * 450;
                    }
                }
                break;

            case RaceStatus.Win:
            case RaceStatus.Fail:
                Speed -= 1;
                _rpm  -= 40;
                break;

            case RaceStatus.Crashing:
                Speed -= 0.3f;
                Shift -= Shift * DeltaTime / 1000;
                break;
            }

            // Speed capping
            if (Speed > MaxSpeed)
            {
                Speed = MaxSpeed;
            }
            if (Speed < 0)
            {
                Speed = 0;
            }

            // Calculating new position
            Position += Speed * DeltaTime;

            // Drift in turns
            Shift += Curve * Speed * 150;

            if (Position >= RoadLength && Status == RaceStatus.Running)
            {
                _music.Pause();
                Status = RaceStatus.Win;
                CarSystem.CarObject.StartAnimation("Skid");
                ShowMessage(_winMessage);
                RemoveSystem(_engineSoundSystem);
                RemoveSystem(_npcSystem);

                int timeLeft = Math.Floor(TimeLeft / 1000);
                CurrentGame.Score += 1000 + timeLeft * 500;

                //if (!_practice)
                //{
                //    pendingTimers.Add(
                //    Window.SetTimeout(delegate()
                //    {
                //        UpdateMessage("<p>Time Left: " + timeLeft + "</p>");
                //    }, 1500));

                //    pendingTimers.Add(
                //    Window.SetTimeout(delegate()
                //    {
                //        UpdateMessage("<p>Score: " + CurrentGame.Score + "</p>");
                //    }, 2500));
                //}

                pendingTimers.Add(
                    Window.SetTimeout(delegate()
                {
                    UpdateMessage("<p>Press a key to continue.</p>");
                }, 3000));
            }
        }