Ejemplo n.º 1
0
        /// <summary>
        /// 更新列表
        /// </summary>
        private void updateList()
        {
            if (this._parentWorld != null && this._parentWorld.RenderableObjects != null)
            {
                for (int i = 0; i < this._parentWorld.RenderableObjects.ChildObjects.Count; i++)
                {
                    RenderableObject curObject = (RenderableObject)this._parentWorld.RenderableObjects.ChildObjects[i];

                    if (i >= this._itemList.Count)
                    {
                        LayerMenuItem newItem = new LayerMenuItem(this, curObject);
                        this._itemList.Add(newItem);
                    }
                    else
                    {
                        LayerMenuItem curItem = (LayerMenuItem)this._itemList[i];
                        if (!curItem.RenderableObject.Name.Equals(curObject.Name))
                        {
                            this._itemList.Insert(i, new LayerMenuItem(this, curObject));
                        }
                    }
                }

                int extraItems = this._itemList.Count - this._parentWorld.RenderableObjects.ChildObjects.Count;
                this._itemList.RemoveRange(this._parentWorld.RenderableObjects.ChildObjects.Count, extraItems);
            }
            else
            {
                this._itemList.Clear();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 更新列表
        /// </summary>
        private void updateList()
        {
            if (this.isExpanded)
            {
                RenderableObjectList rol = (RenderableObjectList)m_renderableObject;
                for (int i = 0; i < rol.ChildObjects.Count; i++)
                {
                    RenderableObject childObject = (RenderableObject)rol.ChildObjects[i];
                    if (i >= m_subItems.Count)
                    {
                        LayerMenuItem newItem = new LayerMenuItem(m_parent, childObject);
                        m_subItems.Add(newItem);
                    }
                    else
                    {
                        LayerMenuItem curItem = (LayerMenuItem)m_subItems[i];

                        if (curItem != null && curItem.RenderableObject != null &&
                            childObject != null &&
                            !curItem.RenderableObject.Name.Equals(childObject.Name))
                        {
                            m_subItems.Insert(i, new LayerMenuItem(m_parent, childObject));
                        }
                    }
                }

                int extraItems = m_subItems.Count - rol.ChildObjects.Count;
                if (extraItems > 0)
                {
                    m_subItems.RemoveRange(rol.ChildObjects.Count, extraItems);
                }
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 显示右键菜单
 /// </summary>
 /// <param name="x">右键菜单起始X位置</param>
 /// <param name="y">右键菜单起始Y位置</param>
 /// <param name="item">图层菜单项</param>
 public void ShowContextMenu(int x, int y, LayerMenuItem item)
 {
     if (ContextMenu != null)
     {
         ContextMenu.Dispose();
         ContextMenu = null;
     }
     ContextMenu = new ContextMenu();
     item.RenderableObject.BuildContextMenu(ContextMenu);
     ContextMenu.Show(item.ParentControl, new System.Drawing.Point(x, y));
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 渲染菜单内容
        /// </summary>
        /// <param name="drawArgs">绘制参数</param>
        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.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);

                    string fontFile = Path.Combine(World.Settings.DataDirectory, "Earth\\World Wind Dings 1.04.ttf");
                    AddFontResource(fontFile);
                    System.Drawing.Text.PrivateFontCollection fpc = new System.Drawing.Text.PrivateFontCollection();
                    fpc.AddFontFile(fontFile);
                    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, "图层管理",
                    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)
            {
                MessageBox.Show(caught.ToString());
                Log.Write(caught);
            }
        }
Ejemplo n.º 5
0
        public override bool OnMouseMove(MouseEventArgs e)
        {
            // Reset mouse over effect since mouse moved.
            MouseOverItem = null;

            if (this.isResizing)
            {
                if (Anchor == SideBarMenuAnchor.Left)
                {
                    if (e.X > 100 && e.X < m_DrawArgs.ScreenWidth)
                    {
                        this.Width = e.X - this.Left;
                    }
                }
                else
                {
                    if (e.X < m_DrawArgs.ScreenWidth - 100)
                    {
                        this.Width = this.Right - e.X;
                    }
                }

                DrawArgs.MouseCursor = CursorType.SizeWE;
                return(true);
            }

            if (this.isScrolling)
            {
                int    totalHeight = GetItemsHeight(m_DrawArgs);//GetNumberOfUncollapsedItems() * ItemHeight;
                double percent     = (double)totalHeight / ClientHeight;
                scrollBarPosition = (int)((e.Y - scrollGrabPositionY - ClientTop) * percent);
                return(true);
            }

            if (e.X > this.Right || e.X < this.Left || e.Y < this.Top || e.Y > this.Bottom)
            {
                // Outside
                return(false);
            }

            if ((Anchor == SideBarMenuAnchor.Left && Math.Abs(e.X - this.Right) < 5) ||
                (Anchor == SideBarMenuAnchor.Right && Math.Abs(e.X - this.Left) < 5))
            {
                DrawArgs.MouseCursor = CursorType.SizeWE;
                return(true);
            }

            if (e.X > ClientRight)
            {
                return(true);
            }

            foreach (LayerMenuItem lmi in this._itemList)
            {
                if (lmi.OnMouseMove(e))
                {
                    return(true);
                }
            }

            // Handled
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 渲染当前菜单项
        /// </summary>
        /// <param name="drawArgs">绘制参数</param>
        /// <param name="x">菜单项X位置</param>
        /// <param name="y">菜单项Y位置</param>
        /// <param name="yOffset">菜单项Y偏移</param>
        /// <param name="width">菜单项宽度</param>
        /// <param name="height">菜单项高度</param>
        /// <param name="drawingFont">绘制字体</param>
        /// <param name="wingdingsFont"></param>
        /// <param name="worldwinddingsFont"></param>
        /// <param name="mouseOverItem">鼠标覆盖的菜单项</param>
        /// <returns>返回本次渲染消耗的高度</returns>
        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 QRST.WorldGlobeTool.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 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.IsShowOnlyOneLayer)
                {
                    // 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 QRST.WorldGlobeTool.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);
        }