public Rectangle[] MakeHandles(Overlay overlay)
        {
            double x = ((int)(overlay.X - (overlay.Width / 2))) + .5f;
            double y = ((int)overlay.Y - (overlay.Height / 2)) + .5f;

            centerX = overlay.X;
            centerY = overlay.Y;

            double width      = overlay.Width;
            double height     = overlay.Height;
            double handleSize = 12 * ratio;

            Rectangle[] handles = new Rectangle[9];

            handles[0] = Rectangle.Create(x - handleSize, y - handleSize, handleSize, handleSize);
            handles[1] = Rectangle.Create((x + (width / 2)) - (handleSize / 2), y - handleSize, handleSize, handleSize);
            handles[2] = Rectangle.Create(x + width, y - handleSize, handleSize, handleSize);
            handles[3] = Rectangle.Create(x + width, (y + (height / 2)) - (handleSize / 2), handleSize, handleSize);
            handles[4] = Rectangle.Create(x + width, (y + height), handleSize, handleSize);
            handles[5] = Rectangle.Create((x + (width / 2)) - (handleSize / 2), (y + height), handleSize, handleSize);
            handles[6] = Rectangle.Create(x - handleSize, (y + height), handleSize, handleSize);
            handles[7] = Rectangle.Create(x - handleSize, (y + (height / 2)) - (handleSize / 2), handleSize, handleSize);
            handles[8] = Rectangle.Create((x + (width / 2)) - (handleSize / 2), y - 30f * ratio, handleSize, handleSize);
            return(handles);
        }
Example #2
0
        internal static GlyphItem FromXML(XmlNode node)
        {
            string glyph = node.Attributes.GetNamedItem("Glyph").Value;

            GlyphItem item = new GlyphItem(glyph);

            item.UVRect = Rectangle.Create(
                double.Parse(node.Attributes.GetNamedItem("UVLeft").Value),
                double.Parse(node.Attributes.GetNamedItem("UVTop").Value),
                double.Parse(node.Attributes.GetNamedItem("UVWidth").Value),
                double.Parse(node.Attributes.GetNamedItem("UVHeight").Value)
                );

            item.Size = Vector2d.Create(
                double.Parse(node.Attributes.GetNamedItem("SizeWidth").Value),
                double.Parse(node.Attributes.GetNamedItem("SizeHeight").Value));

            item.Extents = Vector2d.Create(
                double.Parse(node.Attributes.GetNamedItem("ExtentsWidth").Value),
                double.Parse(node.Attributes.GetNamedItem("ExtentsHeight").Value));

            return(item);
        }
Example #3
0
        public void PrepareBatch()
        {
            if (glyphCache == null)
            {
                glyphCache = GlyphCache.GetCache(Height);
            }

            if (glyphCache.Ready == false)
            {
                return;
            }

            // Add All Glyphs

            //foreach (Text3d t3d in Items)
            //{
            //    foreach (char c in t3d.Text)
            //    {
            //        glyphCache.AddGlyph(c);
            //    }
            //}

            //// Calculate Metrics

            TextObject.Text     = "";
            TextObject.FontSize = (float)Height * .50f;

            //System.Drawing.Font font = TextObject.Font;
            //StringFormat sf = new StringFormat();
            //sf.Alignment = StringAlignment.Near;

            //Bitmap bmp = new Bitmap(20, 20);
            //Graphics g = Graphics.FromImage(bmp);
            //// Create Index Buffers

            List <PositionTexture> verts = new List <PositionTexture>();

            foreach (Text3d t3d in Items)
            {
                String text      = t3d.Text;
                float  left      = 0;
                float  top       = 0;
                float  fntAdjust = TextObject.FontSize / 128f;
                float  factor    = .6666f;
                float  width     = 0;
                float  height    = 0;
                for (int i = 0; i < text.Length; i++)
                {
                    GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1));
                    if (item != null)
                    {
                        width += (float)(item.Extents.X);
                        height = Math.Max(item.Extents.Y, height);
                    }
                }

                Vector2d size = Vector2d.Create(width, height);

                t3d.width  = size.X * (float)t3d.scale * factor * fntAdjust;
                t3d.height = size.Y * (float)t3d.scale * factor * fntAdjust;


                int charsLeft = text.Length;

                for (int i = 0; i < charsLeft; i++)
                {
                    GlyphItem item = glyphCache.GetGlyphItem(text.Substr(i, 1));
                    if (item != null)
                    {
                        Rectangle position = Rectangle.Create(left * (float)t3d.scale * factor, 0 * (float)t3d.scale * factor, item.Extents.X * fntAdjust * (float)t3d.scale * factor, item.Extents.Y * fntAdjust * (float)t3d.scale * factor);
                        left += (float)(item.Extents.X * fntAdjust);

                        //System.Diagnostics.Debug.WriteLine((position.Width/position1.Width).ToString() + ", " + (position.Height / position1.Height).ToString());

                        t3d.AddGlyphPoints(verts, item.Size, position, item.UVRect);
                    }
                }
            }


            vertCount    = verts.Count;
            vertexBuffer = new PositionTextureVertexBuffer(vertCount);

            PositionTexture[] vertBuf = (PositionTexture[])vertexBuffer.Lock(); // Lock the buffer (which will return our structs)

            for (int i = 0; i < vertCount; i++)
            {
                vertBuf[i] = verts[i];
            }

            vertexBuffer.Unlock();

            glyphVersion = glyphCache.Version;
        }
Example #4
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;
                }
            }
        }