Пример #1
0
        public override void RenderContents(DrawArgs drawArgs)
        {
            m_DrawArgs = drawArgs;
            try
            {
                if (itemFont == null)
                {
                    itemFont = drawArgs.CreateFont(World.Settings.LayerManagerFontName,
                                                   World.Settings.LayerManagerFontSize, World.Settings.LayerManagerFontStyle);

                    // TODO: Fix wingdings menu problems
                    System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
                    headerFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, localHeaderFont);

                    System.Drawing.Font wingdings = new System.Drawing.Font("Wingdings", 12.0f);
                    wingdingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, wingdings);

                    AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                    System.Drawing.Text.PrivateFontCollection fpc = new System.Drawing.Text.PrivateFontCollection();
                    fpc.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                    System.Drawing.Font worldwinddings = new System.Drawing.Font(fpc.Families[0], 12.0f);
                    worldwinddingsFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, worldwinddings);
                }

                this.updateList();

                this.worldwinddingsFont.DrawText(
                    null,
                    "E",
                    new System.Drawing.Rectangle(this.Right - 16, this.Top + 2, 20, topBorder),
                    DrawTextFormat.None,
                    TextColor);

                int numItems    = GetNumberOfUncollapsedItems();
                int totalHeight = GetItemsHeight(drawArgs);                //numItems * ItemHeight;
                showScrollbar = totalHeight > ClientHeight;
                if (showScrollbar)
                {
                    double percentHeight   = (double)ClientHeight / totalHeight;
                    int    scrollbarHeight = (int)(ClientHeight * percentHeight);

                    int maxScroll = totalHeight - ClientHeight;

                    if (scrollBarPosition < 0)
                    {
                        scrollBarPosition = 0;
                    }
                    else if (scrollBarPosition > maxScroll)
                    {
                        scrollBarPosition = maxScroll;
                    }

                    // Smooth scroll
                    const float scrollSpeed       = 0.3f;
                    float       smoothScrollDelta = (scrollBarPosition - scrollSmoothPosition) * scrollSpeed;
                    float       absDelta          = Math.Abs(smoothScrollDelta);
                    if (absDelta > 100f || absDelta < 3f)
                    {
                        // Scroll > 100 pixels and < 1.5 pixels faster
                        smoothScrollDelta = (scrollBarPosition - scrollSmoothPosition) * (float)Math.Sqrt(scrollSpeed);
                    }

                    scrollSmoothPosition += smoothScrollDelta;

                    if (scrollSmoothPosition > maxScroll)
                    {
                        scrollSmoothPosition = maxScroll;
                    }

                    int scrollPos = (int)((float)percentHeight * scrollBarPosition);

                    int color = isScrolling ? World.Settings.scrollbarHotColor : World.Settings.scrollbarColor;
                    MenuUtils.DrawBox(
                        Right - ScrollBarSize + 2,
                        ClientTop + scrollPos,
                        ScrollBarSize - 3,
                        scrollbarHeight + 1,
                        0.0f,
                        color,
                        drawArgs.device);

                    scrollbarLine[0].X = this.Right - ScrollBarSize;
                    scrollbarLine[0].Y = this.ClientTop;
                    scrollbarLine[1].X = this.Right - ScrollBarSize;
                    scrollbarLine[1].Y = this.Bottom;
                    MenuUtils.DrawLine(scrollbarLine,
                                       DialogColor,
                                       drawArgs.device);
                }

                this.headerFont.DrawText(
                    null, "Layer Manager",
                    new System.Drawing.Rectangle(Left + 5, Top + 1, Width, topBorder - 2),
                    DrawTextFormat.VerticalCenter, TextColor);

                Microsoft.DirectX.Vector2[] headerLinePoints = new Microsoft.DirectX.Vector2[2];
                headerLinePoints[0].X = this.Left;
                headerLinePoints[0].Y = this.Top + topBorder - 1;

                headerLinePoints[1].X = this.Right;
                headerLinePoints[1].Y = this.Top + topBorder - 1;

                MenuUtils.DrawLine(headerLinePoints, DialogColor, drawArgs.device);

                int runningItemHeight = 0;
                if (showScrollbar)
                {
                    runningItemHeight = -(int)Math.Round(scrollSmoothPosition);
                }

                // Set the Direct3D viewport to match the layer manager client area
                // to clip the text to the window when scrolling
                Viewport lmClientAreaViewPort = new Viewport();
                lmClientAreaViewPort.X      = ClientLeft;
                lmClientAreaViewPort.Y      = ClientTop;
                lmClientAreaViewPort.Width  = ClientWidth;
                lmClientAreaViewPort.Height = ClientHeight;
                Viewport defaultViewPort = drawArgs.device.Viewport;
                drawArgs.device.Viewport = lmClientAreaViewPort;
                for (int i = 0; i < _itemList.Count; i++)
                {
                    if (runningItemHeight > ClientHeight)
                    {
                        // No more space for items
                        break;
                    }
                    LayerMenuItem lmi = (LayerMenuItem)_itemList[i];
                    runningItemHeight += lmi.Render(
                        drawArgs,
                        ClientLeft,
                        ClientTop,
                        runningItemHeight,
                        ClientWidth,
                        ClientBottom,
                        itemFont,
                        wingdingsFont,
                        worldwinddingsFont,
                        MouseOverItem);
                }
                drawArgs.device.Viewport = defaultViewPort;
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
Пример #2
0
        public int Render(DrawArgs drawArgs, int x, int y, int yOffset, int width, int height,
                          Microsoft.DirectX.Direct3D.Font drawingFont,
                          Microsoft.DirectX.Direct3D.Font wingdingsFont,
                          Microsoft.DirectX.Direct3D.Font worldwinddingsFont,
                          LayerMenuItem mouseOverItem)
        {
            if (ParentControl == null)
            {
                ParentControl = drawArgs.parentControl;
            }

            this._x     = x;
            this._y     = y + yOffset;
            this._width = width;

            int consumedHeight = 20;

            System.Drawing.Rectangle textRect = drawingFont.MeasureString(null,
                                                                          m_renderableObject.Name,
                                                                          DrawTextFormat.None,
                                                                          System.Drawing.Color.White.ToArgb());

            consumedHeight = textRect.Height;

            if (m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is WorldWind.Renderable.Icon))
            {
                System.Drawing.SizeF rectF = DrawArgs.Graphics.MeasureString(
                    m_renderableObject.Description,
                    drawArgs.defaultSubTitleFont,
                    width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset)
                    );

                consumedHeight += (int)rectF.Height + 15;
            }

            lastConsumedHeight = consumedHeight;
            // Layer manager client area height
            int totalHeight = height - y;

            updateList();

            if (yOffset >= -consumedHeight)
            {
                // Part of item or whole item visible
                int color = m_renderableObject.IsOn ? itemOnColor : itemOffColor;
                if (mouseOverItem == this)
                {
                    if (!m_renderableObject.IsOn)
                    {
                        // mouseover + inactive color (black)
                        color = 0xff << 24;
                    }
                    MenuUtils.DrawBox(m_parent.ClientLeft, _y, m_parent.ClientWidth, consumedHeight, 0,
                                      World.Settings.menuOutlineColor, drawArgs.device);
                }

                if (m_renderableObject is WorldWind.Renderable.RenderableObjectList)
                {
                    RenderableObjectList rol = (RenderableObjectList)m_renderableObject;
                    if (!rol.DisableExpansion)
                    {
                        worldwinddingsFont.DrawText(
                            null,
                            (this.isExpanded ? "L" : "A"),
                            new System.Drawing.Rectangle(x + this._itemXOffset, _y, this._expandArrowXSize, height),
                            DrawTextFormat.None,
                            color);
                    }
                }

                string checkSymbol = null;
                if (m_renderableObject.ParentList != null && m_renderableObject.ParentList.ShowOnlyOneLayer)
                {
                    // Radio check
                    checkSymbol = m_renderableObject.IsOn ? "O" : "P";
                }
                else
                {
                    // Normal check
                    checkSymbol = m_renderableObject.IsOn ? "N" : "F";
                }

                worldwinddingsFont.DrawText(
                    null,
                    checkSymbol,
                    new System.Drawing.Rectangle(
                        x + this._itemXOffset + this._expandArrowXSize,
                        _y,
                        this._checkBoxXOffset,
                        height),
                    DrawTextFormat.NoClip,
                    color);


                drawingFont.DrawText(
                    null,
                    m_renderableObject.Name,
                    new System.Drawing.Rectangle(
                        x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset,
                        _y,
                        width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset),
                        height),
                    DrawTextFormat.None,
                    color);

                if (m_renderableObject.Description != null && m_renderableObject.Description.Length > 0 && !(m_renderableObject is WorldWind.Renderable.Icon))
                {
                    drawArgs.defaultSubTitleDrawingFont.DrawText(
                        null,
                        m_renderableObject.Description,
                        new System.Drawing.Rectangle(
                            x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset,
                            _y + textRect.Height,
                            width - (_itemXOffset + _expandArrowXSize + _checkBoxXOffset),
                            height),
                        DrawTextFormat.WordBreak,
                        System.Drawing.Color.Gray.ToArgb());
                }

                if (m_renderableObject.MetaData.Contains("InfoUri"))
                {
                    Vector2[] underlineVerts = new Vector2[2];
                    underlineVerts[0].X = x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset;
                    underlineVerts[0].Y = _y + textRect.Height;
                    underlineVerts[1].X = underlineVerts[0].X + textRect.Width;
                    underlineVerts[1].Y = _y + textRect.Height;

                    MenuUtils.DrawLine(underlineVerts, color, drawArgs.device);
                }
            }

            if (isExpanded)
            {
                for (int i = 0; i < m_subItems.Count; i++)
                {
                    int yRealOffset = yOffset + consumedHeight;
                    if (yRealOffset > totalHeight)
                    {
                        // No more space for items
                        break;
                    }
                    LayerMenuItem lmi = (LayerMenuItem)m_subItems[i];
                    consumedHeight += lmi.Render(
                        drawArgs,
                        x + _subItemXIndent,
                        y,
                        yRealOffset,
                        width - _subItemXIndent,
                        height,
                        drawingFont,
                        wingdingsFont,
                        worldwinddingsFont,
                        mouseOverItem);
                }
            }

            return(consumedHeight);
        }