예제 #1
0
        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();
            }
        }
예제 #2
0
        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);
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Displays the layer manager context menu for an item.
 /// </summary>
 /// <param name="x"></param>
 /// <param name="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();
     ContextMenu.Show(item.ParentControl, new System.Drawing.Point(x, y));
 }
예제 #4
0
        public override bool OnMouseMove(MouseEventArgs e)
        {
            // Reset mouse over effect since mouse moved.
            MouseOverItem = null;

            if (this.isResizing)
            {
                if (e.X > 140 && e.X < 800)
                {
                    this.Width = e.X;
                }

                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 (Math.Abs(e.X - this.Right) < 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);
        }
예제 #5
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);
            }
        }
예제 #6
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 MFW3D.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 MFW3D.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 MFW3D.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);
        }