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(); } }
private void updateList() { if (this.isExpanded) { RenderableObjectList rol = (RenderableObjectList)this.m_renderableObject; for (int i = 0; i < rol.ChildObjects.Count; i++) { RenderableObject childObject = (RenderableObject)rol.ChildObjects[i]; if (i >= this.m_subItems.Count) { LayerMenuItem newItem = new LayerMenuItem(this.m_parent, childObject); this.m_subItems.Add(newItem); } else { LayerMenuItem curItem = (LayerMenuItem)this.m_subItems[i]; if (curItem != null && curItem.RenderableObject != null && childObject != null && !curItem.RenderableObject.Name.Equals(childObject.Name)) { this.m_subItems.Insert(i, new LayerMenuItem(this.m_parent, childObject)); } } } int extraItems = this.m_subItems.Count - rol.ChildObjects.Count; if (extraItems > 0) { this.m_subItems.RemoveRange(rol.ChildObjects.Count, extraItems); } } }
/// <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 (this.ContextMenu != null) { this.ContextMenu.Dispose(); this.ContextMenu = null; } this.ContextMenu = new ContextMenu(); item.RenderableObject.BuildContextMenu(this.ContextMenu); this.ContextMenu.Show(item.ParentControl, new Point(x, y)); }
public override bool OnMouseMove(MouseEventArgs e) { // Reset mouse over effect since mouse moved. this.MouseOverItem = null; if (this.isResizing) { if (e.X > 140 && e.X < 800) { this.Width = e.X; } return(true); } if (this.isScrolling) { int totalHeight = this.GetItemsHeight(this.m_DrawArgs); //GetNumberOfUncollapsedItems() * ItemHeight; double percent = (double)totalHeight / this.ClientHeight; this.scrollBarPosition = (int)((e.Y - this.scrollGrabPositionY - this.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 > this.ClientRight) { return(true); } foreach (LayerMenuItem lmi in this._itemList) { if (lmi.OnMouseMove(e)) { return(true); } } // Handled return(true); }
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); } }
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); }