Exemplo n.º 1
0
        public Menu(Device device, Point location, Orientation orientation, params MenuItem[] items)
        {
            Log.Trace("Menu()");
            this.Device       = device;
            Items             = new List <MenuItem>(items);
            Location          = location;
            Orientation       = orientation;
            ForeColor         = Color.White;
            SelectedForeColor = Color.Red;
            Font        = new Font("Arial", 12, FontStyle.Bold);
            ItemPadding = 15;

            DrawingFont = new SharpDX.Direct3D9.Font(device, Font);

            IncrementMenuKey  = new Key(Keys.OemCloseBrackets);
            DecrementMenuKey  = new Key(Keys.OemOpenBrackets);
            IncrementValueKey = new Key(Keys.PageUp);
            DecrementValueKey = new Key(Keys.PageDown);
            ResetToZeroKey    = new Key(Keys.End);

            IncrementMenuKey.OnJustPressed += (sender, args) => { SelectedIndex = (SelectedIndex + 1).Clamp(SelectedIndex, Items.Count - 1); };
            DecrementMenuKey.OnJustPressed += (sender, args) => { SelectedIndex = (SelectedIndex - 1).Clamp(0, SelectedIndex); };
            IncrementValueKey.OnHold       += (sender, args) => Items[SelectedIndex].IncrementValue(2);
            DecrementValueKey.OnHold       += (sender, args) => Items[SelectedIndex].DecrementValue(2);
            ResetToZeroKey.OnJustPressed   += (sender, args) => { Items[SelectedIndex].Value = 0; };
        }
Exemplo n.º 2
0
        public Menu(Device device, Point location, Orientation orientation, params MenuItem[] items)
        {
            Log.Trace("Menu()");
            this.Device = device;
            Items = new List <MenuItem>(items);
            Location = location;
            Orientation = orientation;
            ForeColor = Color.White;
            SelectedForeColor = Color.Red;
            Font = new Font ("Arial", 12, FontStyle.Bold);
            ItemPadding = 15;

            DrawingFont = new SharpDX.Direct3D9.Font (device, Font);

            IncrementMenuKey = new Key (Keys.OemCloseBrackets);
            DecrementMenuKey = new Key (Keys.OemOpenBrackets);
            IncrementValueKey = new Key (Keys.PageUp);
            DecrementValueKey = new Key (Keys.PageDown);
            ResetToZeroKey = new Key (Keys.End);

            IncrementMenuKey.OnJustPressed += (sender, args) => { SelectedIndex = (SelectedIndex + 1).Clamp(SelectedIndex, Items.Count - 1); };
            DecrementMenuKey.OnJustPressed += (sender, args) => { SelectedIndex = (SelectedIndex - 1).Clamp(0, SelectedIndex); };
            IncrementValueKey.OnHold += (sender, args) => Items[SelectedIndex].IncrementValue(2);
            DecrementValueKey.OnHold += (sender, args) => Items[SelectedIndex].DecrementValue(2);
            ResetToZeroKey.OnJustPressed += (sender, args) => { Items[SelectedIndex].Value = 0; };
        }
Exemplo n.º 3
0
        public override void RenderContents(DrawArgs drawArgs)
        {
            this.m_DrawArgs = drawArgs;
            try
            {
                if (this.itemFont == null)
                {
                    this.itemFont = drawArgs.CreateFont(World.Settings.LayerManagerFontName,
                                                        World.Settings.LayerManagerFontSize, World.Settings.LayerManagerFontStyle);

                    // TODO: Fix wingdings menu problems
                    Font localHeaderFont = new Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
                    this.headerFont = new SharpDX.Direct3D9.Font(drawArgs.device, localHeaderFont);

                    Font wingdings = new Font("Wingdings", 12.0f);
                    this.wingdingsFont = new SharpDX.Direct3D9.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"));
                    Font worldwinddings = new Font(fpc.Families[0], 12.0f);
                    this.worldwinddingsFont = new SharpDX.Direct3D9.Font(drawArgs.device, worldwinddings);
                }

                this.updateList();

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

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

                    int maxScroll = totalHeight - this.ClientHeight;

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

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

                    this.scrollSmoothPosition += smoothScrollDelta;

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

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

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

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

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

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

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

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

                int runningItemHeight = 0;
                if (this.showScrollbar)
                {
                    runningItemHeight = -(int)Math.Round(this.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      = this.ClientLeft;
                lmClientAreaViewPort.Y      = this.ClientTop;
                lmClientAreaViewPort.Width  = this.ClientWidth;
                lmClientAreaViewPort.Height = this.ClientHeight;
                Viewport defaultViewPort = drawArgs.device.Viewport;
                drawArgs.device.Viewport = lmClientAreaViewPort;
                for (int i = 0; i < this._itemList.Count; i++)
                {
                    if (runningItemHeight > this.ClientHeight)
                    {
                        // No more space for items
                        break;
                    }
                    LayerMenuItem lmi = (LayerMenuItem)this._itemList[i];
                    runningItemHeight += lmi.Render(
                        drawArgs, this.ClientLeft, this.ClientTop,
                        runningItemHeight, this.ClientWidth, this.ClientBottom, this.itemFont, this.wingdingsFont, this.worldwinddingsFont, this.MouseOverItem);
                }
                drawArgs.device.Viewport = defaultViewPort;
            }
            catch (Exception caught)
            {
                Log.Write(caught);
            }
        }
Exemplo n.º 4
0
        public int Render(DrawArgs drawArgs, int x, int y, int yOffset, int width, int height,
                          SharpDX.Direct3D9.Font drawingFont,
                          SharpDX.Direct3D9.Font wingdingsFont,
                          SharpDX.Direct3D9.Font worldwinddingsFont,
                          LayerMenuItem mouseOverItem)
        {
            if (this.ParentControl == null)
            {
                this.ParentControl = drawArgs.parentControl;
            }

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

            int consumedHeight = 20;

            Rectangle textRect = drawingFont.MeasureString(null, this.m_renderableObject.Name,
                                                           FontDrawFlags.SingleLine,
                                                           Color.White.ToArgb());

            consumedHeight = textRect.Height;

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

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

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

            this.updateList();

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

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

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

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


                drawingFont.DrawText(
                    null, this.m_renderableObject.Name,
                    new Rectangle(
                        x + this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset, this._y,
                        width - (this._itemXOffset + this._expandArrowXSize + this._checkBoxXOffset),
                        height),
                    FontDrawFlags.SingleLine,
                    color);

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

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

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

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

            return(consumedHeight);
        }