Exemplo n.º 1
0
        static void DrawTest()
        {
            CanvasElement canvas = (CanvasElement)Document.GetElementById("canvas");

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

            ctx.FillStyle = "rgb(80,0,0)";
            ctx.FillRect(120, 120, 165, 160);

            ctx.FillStyle = "rgba(0, 0, 160, 0.5)";
            ctx.FillRect(140, 140, 165, 160);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
        public void Clear()
        {
            if (gl != null)
            {
                gl.viewport(0, 0, (int)Width, (int)Height);
                gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
                //gl.clearColor(1, 0, 0, 1);
            }
            else
            {
                Device.Save();
                Device.FillStyle = "black";
                Device.FillRect(0, 0, Width, Height);

                Device.Restore();
            }
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        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);
        }
Exemplo n.º 6
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;
                }
            }
        }