コード例 #1
0
        public void Render(DrawArgs drawArgs)
        {
            if ((DrawArgs.WorldWindow != null) && (DrawArgs.WorldWindow.MenuBar.Anchor == MenuAnchor.Bottom))
            {
                this.Top    = 0;
                this.Bottom = drawArgs.screenHeight - 120;
            }
            else
            {
                this.Top    = 120;
                this.Bottom = drawArgs.screenHeight - 1;
            }

            MenuUtils.DrawBox(Left, Top, Right - Left, Bottom - Top, 0.0f,
                              World.Settings.menuBackColor, drawArgs.device);

            RenderContents(drawArgs);

            outlineVerts[0].X = Left;
            outlineVerts[0].Y = Top;

            outlineVerts[1].X = Right;
            outlineVerts[1].Y = Top;

            outlineVerts[2].X = Right;
            outlineVerts[2].Y = Bottom;

            outlineVerts[3].X = Left;
            outlineVerts[3].Y = Bottom;

            outlineVerts[4].X = Left;
            outlineVerts[4].Y = Top;

            MenuUtils.DrawLine(outlineVerts, World.Settings.menuOutlineColor, drawArgs.device);
        }
コード例 #2
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);
            }
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: MenuBar.cs プロジェクト: Fav/testww
        public void Render(DrawArgs drawArgs)
        {
            if (m_sprite == null)
            {
                m_sprite = new Sprite(drawArgs.device);
            }

            if (mouseCursor != CursorType.Arrow)
            {
                DrawArgs.MouseCursor = mouseCursor;
            }


            foreach (MenuButton button in m_toolsMenuButtons)
            {
                if (button.IsPushed())
                {
                    // Does not render the button, but the functionality behind the button
                    button.Render(drawArgs);
                }
            }

            foreach (MenuButton button in m_toolsMenuButtons)
            {
                button.Update(drawArgs);
            }

            foreach (MenuButton button in m_layersMenuButtons)
            {
                button.Update(drawArgs);
            }

            if (!World.Settings.showToolbar)
            {
                return;
            }

            if (this._isHideable)
            {
                if (this._visibleState == VisibleState.NotVisible)
                {
                    if (
                        (m_anchor == MenuAnchor.Top && DrawArgs.LastMousePosition.Y < MenuButton.NormalSize) ||
                        (m_anchor == MenuAnchor.Bottom && DrawArgs.LastMousePosition.Y > drawArgs.screenHeight - MenuButton.NormalSize) ||
                        (m_anchor == MenuAnchor.Right && DrawArgs.LastMousePosition.X > drawArgs.screenWidth - MenuButton.NormalSize)
                        )
                    {
                        this._visibleState      = VisibleState.Ascending;
                        this._lastVisibleChange = System.DateTime.Now;
                    }
                }
                else if (
                    (m_anchor == MenuAnchor.Top && DrawArgs.LastMousePosition.Y > 2 * this._outerPadding + MenuButton.NormalSize) ||
                    (m_anchor == MenuAnchor.Bottom && DrawArgs.LastMousePosition.Y < drawArgs.screenHeight - 2 * this._outerPadding - MenuButton.NormalSize) ||
                    (m_anchor == MenuAnchor.Right && DrawArgs.LastMousePosition.X < drawArgs.screenWidth - MenuButton.NormalSize)
                    )
                {
                    if (this._visibleState == VisibleState.Visible)
                    {
                        this._visibleState      = VisibleState.Descending;
                        this._lastVisibleChange = System.DateTime.Now;
                    }
                    else if (this._visibleState == VisibleState.Descending)
                    {
                        if (System.DateTime.Now.Subtract(this._lastVisibleChange) > System.TimeSpan.FromMilliseconds(hideTimeMilliseconds))
                        {
                            this._visibleState      = VisibleState.NotVisible;
                            this._lastVisibleChange = System.DateTime.Now;
                        }
                    }
                }
                else if (this._visibleState == VisibleState.Ascending)
                {
                    if (System.DateTime.Now.Subtract(this._lastVisibleChange) > System.TimeSpan.FromMilliseconds(hideTimeMilliseconds))
                    {
                        this._visibleState      = VisibleState.Visible;
                        this._lastVisibleChange = System.DateTime.Now;
                    }
                }
                else if (this._visibleState == VisibleState.Descending)
                {
                    if (System.DateTime.Now.Subtract(this._lastVisibleChange) > System.TimeSpan.FromMilliseconds(hideTimeMilliseconds))
                    {
                        this._visibleState      = VisibleState.NotVisible;
                        this._lastVisibleChange = System.DateTime.Now;
                    }
                }
            }
            else
            {
                this._visibleState = VisibleState.Visible;
            }

            int totalNumberButtons = m_toolsMenuButtons.Count + m_layersMenuButtons.Count;

            MenuButton.NormalSize = MenuButton.SelectedSize / 2;
            _outerPadding         = MenuButton.NormalSize * padRatio;

            float menuWidth = (MenuButton.NormalSize + _outerPadding) * totalNumberButtons + _outerPadding;

            if (menuWidth > drawArgs.screenWidth)
            {
                MenuButton.NormalSize = (drawArgs.screenWidth) / ((padRatio + 1) * totalNumberButtons + padRatio);
                _outerPadding         = MenuButton.NormalSize * padRatio;

                // recalc menuWidth if we want to center the toolbar
                menuWidth = (MenuButton.NormalSize + _outerPadding) * totalNumberButtons + _outerPadding;
            }

            if (m_anchor == MenuAnchor.Left)
            {
                x = 0;
                y = (int)MenuButton.NormalSize;
            }
            else if (m_anchor == MenuAnchor.Right)
            {
                x = (int)(drawArgs.screenWidth - 2 * _outerPadding - MenuButton.NormalSize);
                y = (int)MenuButton.NormalSize;
            }
            else if (m_anchor == MenuAnchor.Top)
            {
                x = (int)(drawArgs.screenWidth / 2 - totalNumberButtons * MenuButton.NormalSize / 2 - _outerPadding);
                y = 0;
            }
            else if (m_anchor == MenuAnchor.Bottom)
            {
                x = (int)(drawArgs.screenWidth / 2 - totalNumberButtons * MenuButton.NormalSize / 2 - _outerPadding);
                y = (int)(drawArgs.screenHeight - 2 * _outerPadding - MenuButton.NormalSize);
            }

            if (this._visibleState == VisibleState.Ascending)
            {
                TimeSpan t = System.DateTime.Now.Subtract(this._lastVisibleChange);
                if (t.Milliseconds < hideTimeMilliseconds)
                {
                    double percent = (double)t.Milliseconds / hideTimeMilliseconds;
                    int    dx      = (int)((MenuButton.NormalSize + 5) - (percent * (MenuButton.NormalSize + 5)));

                    if (m_anchor == MenuAnchor.Left)
                    {
                        x -= dx;
                    }
                    else if (m_anchor == MenuAnchor.Right)
                    {
                        x += dx;
                    }
                    else if (m_anchor == MenuAnchor.Top)
                    {
                        y -= dx;
                    }
                    else if (m_anchor == MenuAnchor.Bottom)
                    {
                        y += dx;
                    }
                }
            }
            else if (this._visibleState == VisibleState.Descending)
            {
                TimeSpan t = System.DateTime.Now.Subtract(this._lastVisibleChange);
                if (t.Milliseconds < hideTimeMilliseconds)
                {
                    double percent = (double)t.Milliseconds / hideTimeMilliseconds;
                    int    dx      = (int)((percent * (MenuButton.NormalSize + 5)));

                    if (m_anchor == MenuAnchor.Left)
                    {
                        x -= dx;
                    }
                    else if (m_anchor == MenuAnchor.Right)
                    {
                        x += dx;
                    }
                    else if (m_anchor == MenuAnchor.Top)
                    {
                        y -= dx;
                    }
                    else if (m_anchor == MenuAnchor.Bottom)
                    {
                        y += dx;
                    }
                }
            }

            lock (m_toolsMenuButtons.SyncRoot)
            {
                MenuButton selectedButton = null;
                if (_curSelection >= 0 & _curSelection < totalNumberButtons)
                {
                    if (_curSelection < m_toolsMenuButtons.Count)
                    {
                        selectedButton = (MenuButton)m_toolsMenuButtons[_curSelection];
                    }
                    else
                    {
                        selectedButton = (MenuButton)m_layersMenuButtons[_curSelection - m_toolsMenuButtons.Count];
                    }
                }

                //_outerPadding = MenuButton.NormalSize*padRatio;
                //float menuWidth = (MenuButton.NormalSize+_outerPadding)*totalNumberButtons+_outerPadding;
                //if(menuWidth>drawArgs.screenWidth)
                //{
                //    //MessageBox.Show(drawArgs.screenWidth.ToString());
                //    MenuButton.NormalSize = (drawArgs.screenWidth)/((padRatio+1)*totalNumberButtons+padRatio);
                //    //MessageBox.Show(MenuButton.NormalSize.ToString());
                //    _outerPadding = MenuButton.NormalSize*padRatio;
                //}

                if (this._visibleState != VisibleState.NotVisible)
                {
                    if (m_anchor == MenuAnchor.Top)
                    {
                        MenuUtils.DrawBox(0, 0, drawArgs.screenWidth, (int)(MenuButton.NormalSize + 2 * _outerPadding), 0.0f,
                                          World.Settings.toolBarBackColor, drawArgs.device);
                    }
                    else if (m_anchor == MenuAnchor.Bottom)
                    {
                        MenuUtils.DrawBox(0, (int)(y - _outerPadding), drawArgs.screenWidth, (int)(MenuButton.NormalSize + 4 * _outerPadding), 0.0f,
                                          World.Settings.toolBarBackColor, drawArgs.device);
                    }
                }

                float total = 0;
                float extra = 0;
                for (int i = 0; i < totalNumberButtons; i++)
                {
                    MenuButton button;
                    if (i < m_toolsMenuButtons.Count)
                    {
                        button = (MenuButton)m_toolsMenuButtons[i];
                    }
                    else
                    {
                        button = (MenuButton)m_layersMenuButtons[i - m_toolsMenuButtons.Count];
                    }
                    total += button.CurrentSize;
                    extra += button.CurrentSize - MenuButton.NormalSize;
                }

                float pad     = ((float)_outerPadding * (totalNumberButtons + 1) - extra) / (totalNumberButtons + 1);
                float buttonX = pad;

                // TODO - to center the menubar set the buttonX to center-half toolbar width
                // float buttonX = (drawArgs.screenWidth - menuWidth) / 2;

                m_sprite.Begin(SpriteFlags.AlphaBlend);
                for (int i = 0; i < totalNumberButtons; i++)
                {
                    MenuButton button;
                    if (i < m_toolsMenuButtons.Count)
                    {
                        button = (MenuButton)m_toolsMenuButtons[i];
                    }
                    else
                    {
                        button = (MenuButton)m_layersMenuButtons[i - m_toolsMenuButtons.Count];
                    }

                    if (button.IconTexture == null)
                    {
                        button.InitializeTexture(drawArgs.device);
                    }

                    if (this._visibleState != VisibleState.NotVisible)
                    {
                        int centerX = (int)(buttonX + button.CurrentSize * 0.5f);
                        buttonX += button.CurrentSize + pad;
                        float buttonTopY = y + _outerPadding;

                        if (m_anchor == MenuAnchor.Bottom)
                        {
                            buttonTopY = (int)(drawArgs.screenHeight - _outerPadding - button.CurrentSize);
                        }

                        if (button.IsPushed())
                        {
                            // Draw the chevron
                            float chevronSize = button.CurrentSize * padRatio;

                            enabledChevron[0].Color = chevronColor;
                            enabledChevron[1].Color = chevronColor;
                            enabledChevron[2].Color = chevronColor;

                            if (m_anchor == MenuAnchor.Bottom)
                            {
                                enabledChevron[2].X = centerX - chevronSize;
                                enabledChevron[2].Y = y - 2;
                                enabledChevron[2].Z = 0.0f;

                                enabledChevron[0].X = centerX;
                                enabledChevron[0].Y = y - 2 + chevronSize;
                                enabledChevron[0].Z = 0.0f;

                                enabledChevron[1].X = centerX + chevronSize;
                                enabledChevron[1].Y = y - 2;
                                enabledChevron[1].Z = 0.0f;
                            }
                            else
                            {
                                enabledChevron[2].X = centerX - chevronSize;
                                enabledChevron[2].Y = y + 2;
                                enabledChevron[2].Z = 0.0f;

                                enabledChevron[0].X = centerX;
                                enabledChevron[0].Y = y + 2 + chevronSize;
                                enabledChevron[0].Z = 0.0f;

                                enabledChevron[1].X = centerX + chevronSize;
                                enabledChevron[1].Y = y + 2;
                                enabledChevron[1].Z = 0.0f;
                            }

                            drawArgs.device.VertexFormat = CustomVertex.TransformedColored.Format;
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.Disable;
                            drawArgs.device.DrawUserPrimitives(PrimitiveType.TriangleList, 1, enabledChevron);
                            drawArgs.device.TextureState[0].ColorOperation = TextureOperation.SelectArg1;
                        }

                        button.RenderEnabledIcon(
                            m_sprite,
                            drawArgs,
                            centerX,
                            buttonTopY,
                            i == this._curSelection,
                            m_anchor);
                    }
                }
                m_sprite.End();
            }
        }