Exemple #1
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                //todo draw in WebGL
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
Exemple #2
0
        private void CreateCircleGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Scale(1, Width / Height);
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();
            ctx.Alpha     = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
Exemple #3
0
        private void CreateStarGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();

            double centerX = 0;
            double centerY = 0;
            double radius  = Width / 2;

            double radiansPerSegment = ((double)Math.PI * 2) / 5;

            bool first = true;

            for (int i = 0; i < 5; i++)
            {
                double rads = i * radiansPerSegment - (Math.PI / 2);
                if (first)
                {
                    first = false;
                    ctx.MoveTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }
                else
                {
                    ctx.LineTo(centerX + Math.Cos(rads) * (Width / 2), centerY + Math.Sin(rads) * (Height / 2));
                }

                double rads2 = i * radiansPerSegment + (radiansPerSegment / 2) - (Math.PI / 2);
                ctx.LineTo(centerX + Math.Cos(rads2) * (Width / 5.3), centerY + Math.Sin(rads2) * (Height / 5.3));
            }

            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();


            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
Exemple #4
0
        private void CreateDonutGeometry(RenderContext renderContext)
        {
            //todo move to dashed lines in future
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Scale(1, Height / Width);
            ctx.Rotate(RotationAngle * RC);
            ctx.BeginPath();
            ctx.Arc(0, 0, Width / 2, 0, Math.PI * 2, false);

            ctx.ClosePath();
            ctx.LineWidth   = 9;
            ctx.StrokeStyle = Color.ToString();
            ctx.Alpha       = Opacity;
            ctx.Stroke();
            ctx.Restore();
        }
Exemple #5
0
        private void CreateRectGeometry(RenderContext renderContext)
        {
            CanvasContext2D ctx = renderContext.Device;

            ctx.Save();
            ctx.Translate(X, Y);
            ctx.Rotate(RotationAngle * RC);

            ctx.BeginPath();
            ctx.MoveTo(-Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, -Height / 2);
            ctx.LineTo(Width / 2, +Height / 2);
            ctx.LineTo(-Width / 2, +Height / 2);
            ctx.ClosePath();
            ctx.LineWidth = 0;
            ctx.FillStyle = Color.ToString();

            ctx.Alpha = Opacity;
            ctx.Fill();
            ctx.Restore();
        }
Exemple #6
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();
        }
        //protected Vector3d RaDecTo3d(double lat, double lng)
        //{
        //    return Vector3d.Create((Math.Cos(lng * RC) * Math.Cos(lat * RC) * radius), (Math.Sin(lat * RC) * radius), (Math.Sin(lng * RC) * Math.Cos(lat * RC) * radius));

        //}
        private void DrawSingleConstellationOld(RenderContext renderContext, Lineset ls)
        {
            bool reverse = false;
            // todo get this working
            Place centroid = ConstellationCentroids[ls.Name];

            if (centroid != null)
            {
                Vector3d pos = Coordinates.RADecTo3d(reverse ? -centroid.RA - 6 : centroid.RA, reverse ? centroid.Dec : centroid.Dec);

                if (Vector3d.Dot(renderContext.ViewPoint, pos) < maxSeperation)
                {
                    return;
                }
            }

            drawCount++;
            string col;

            if (boundry)
            {
                if (constToDraw != ls.Name)
                {
                    col = Settings.GlobalSettings.ConstellationBoundryColor;
                }
                else
                {
                    col = Settings.GlobalSettings.ConstellationSelectionColor;
                }
            }
            else
            {
                col = Settings.GlobalSettings.ConstellationFigureColor;
            }

            if (renderContext.gl == null)
            {
                CanvasContext2D ctx = renderContext.Device;

                int count = ls.Points.Count;

                Vector3d lastPoint = new Vector3d();
                ctx.Save();
                bool linePending = false;
                ctx.BeginPath();
                ctx.StrokeStyle = col;
                ctx.LineWidth   = 2;
                ctx.Alpha       = .25;
                for (int i = 0; i < count; i++)
                {
                    if (ls.Points[i].PointType == PointType.Move || i == 0)
                    {
                        if (linePending)
                        {
                            ctx.Stroke();
                        }
                        lastPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        ctx.MoveTo(lastPoint.X, lastPoint.Y);
                    }
                    else
                    {
                        Vector3d newPoint = renderContext.WVP.Transform(Coordinates.RADecTo3d(ls.Points[i].RA, ls.Points[i].Dec));

                        //            if (lastPoint.Z > 0 && newPoint.Z > 0)
                        {
                            ctx.LineTo(newPoint.X, newPoint.Y);
                            linePending = true;
                        }
                    }
                }

                if (boundry)
                {
                    ctx.ClosePath();
                }

                ctx.Stroke();
                ctx.Restore();
            }
            else
            {
                //todo add webgl method of drawing
            }
        }
Exemple #8
0
        //bool hitTestInit = false;

        //void InitHitTest(RenderContext renderContext)
        //{
        //    Vector2d center = new Vector2d();
        //    double radius = 0;
        //    Vector2d[] screenPoints = new Vector2d[points.Count];
        //    int index = 0;
        //    foreach (Vector3d pnt in points)
        //    {
        //        Vector3d screenSpacePnt = renderContext.ViewMatrix.Transform(pnt);
        //        if (screenSpacePnt.Z < 0)
        //        {
        //            return;
        //        }
        //        if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .55)
        //        {
        //            return;
        //        }
        //        screenPoints[index] = new Vector2d(screenSpacePnt.X, screenSpacePnt.Y);
        //        index++;
        //    }

        //    ConvexHull.FindEnclosingCircle(screenPoints, out center, out radius);
        //}

        public override void Draw(RenderContext renderContext)
        {
            if (renderContext.gl != null)
            {
                if (Annotation.BatchDirty || AnnotationDirty)
                {
                    //todo can we save this work for later?
                    List <Vector3d> vertexList = points;


                    if (strokeWidth > 0 && points.Count > 1)
                    {
                        for (int i = 0; i < (points.Count - 1); i++)
                        {
                            LineList.AddLine(vertexList[i], vertexList[i + 1], lineColor, new Dates(0, 1));
                        }
                        LineList.AddLine(vertexList[points.Count - 1], vertexList[0], lineColor, new Dates(0, 1));
                    }
                    if (fill)
                    {
                        List <int> indexes = Tessellator.TesselateSimplePoly(vertexList);

                        for (int i = 0; i < indexes.Count; i += 3)
                        {
                            TriangleList.AddSubdividedTriangles(vertexList[indexes[i]], vertexList[indexes[i + 1]], vertexList[indexes[i + 2]], fillColor, new Dates(0, 1), 2);
                        }
                    }
                    AnnotationDirty = false;
                }
            }
            else
            {
                CanvasContext2D ctx = renderContext.Device;
                ctx.Save();
                ctx.Alpha = Opacity;

                ctx.BeginPath();

                bool first = true;
                foreach (Vector3d pnt in points)
                {
                    Vector3d screenSpacePnt = renderContext.WVP.Transform(pnt);
                    if (screenSpacePnt.Z < 0)
                    {
                        ctx.Restore();

                        return;
                    }

                    if (Vector3d.Dot(renderContext.ViewPoint, pnt) < .75)
                    {
                        ctx.Restore();
                        return;
                    }

                    if (first)
                    {
                        first = false;
                        ctx.MoveTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                    else
                    {
                        ctx.LineTo(screenSpacePnt.X, screenSpacePnt.Y);
                    }
                }
                ctx.ClosePath();

                ctx.LineWidth = strokeWidth;
                if (fill)
                {
                    ctx.FillStyle = fillColor.ToString();
                    ctx.Fill();
                }

                ctx.StrokeStyle = lineColor.ToString();
                ctx.Alpha       = 1;
                ctx.Stroke();

                ctx.Restore();
            }
        }
        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 #10
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 #11
0
        public void Draw()
        {
            CanvasElement   canvas = Document.GetElementById <CanvasElement>("graph");
            CanvasContext2D ctx    = (CanvasContext2D)canvas.GetContext(Rendering.Render2D);

            if (image != null)
            {
                image.DrawHistogram(ctx);
            }

            string red   = "rgba(255,0,0,255)";
            string green = "rgba(0,255,0,255)";
            string blue  = "rgba(0,0,255,255)";

            ctx.StrokeStyle = red;
            ctx.BeginPath();
            ctx.MoveTo(lowPosition, 0);
            ctx.LineTo(lowPosition, 150);

            ctx.Stroke();

            ctx.StrokeStyle = green;
            ctx.BeginPath();
            ctx.MoveTo(highPosition, 0);
            ctx.LineTo(highPosition, 150);
            ctx.Stroke();

            ctx.StrokeStyle = blue;
            ctx.BeginPath();
            ctx.Arc(center, 75, 10, 0, Math.PI * 2, false);
            ctx.ClosePath();
            ctx.Stroke();


            List <Vector2d> Curve = new List <Vector2d>();

            //todo get from combo box

            switch (SelectedCurveStyle)
            {
            case 0:     // Linear
            {
                Curve.Clear();
                Curve.Add(Vector2d.Create(lowPosition, 150));
                Curve.Add(Vector2d.Create(highPosition, 0));
                break;
            }

            case 1:     // Log
            {
                Curve.Clear();
                double factor = 150 / Math.Log(255);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Log(val) * factor))));
                    val += step;
                }
            }
            break;

            case 2:     // Power 2
            {
                Curve.Clear();
                double factor = 150 / Math.Pow(255, 2);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Pow(val, 2) * factor))));
                    val += step;
                }
            }

            break;

            case 3:     // Square Root
            {
                Curve.Clear();
                double factor = 150 / Math.Sqrt(255);
                double diff   = (highPosition - lowPosition);
                int    jump   = diff < 0 ? -1 : 1;
                double step   = Math.Abs(256.0 / (diff == 0 ? .000001 : diff));
                double val    = .000001;
                for (int i = lowPosition; i != highPosition; i += jump)
                {
                    Curve.Add(Vector2d.Create((float)i, (float)(150 - (Math.Sqrt(val) * factor))));
                    val += step;
                }
            }

            break;
            }

            if (Curve.Count > 1)
            {
                ctx.BeginPath();
                ctx.StrokeStyle = blue;
                ctx.MoveTo(Curve[0].X, Curve[0].Y);

                for (int i = 1; i < Curve.Count; i++)
                {
                    ctx.LineTo(Curve[i].X, Curve[i].Y);
                }
                ctx.Stroke();
            }
        }
        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);
        }