private void renderBackbone(DrawArgs drawArgs) { int backboneWidth = 3; int centerHeight = ClientSize.Height / 2; int quarterHeight = ClientSize.Height / 3; int eighthHeight = ClientSize.Height / 4; WidgetUtilities.DrawBox(AbsoluteLocation.X, AbsoluteLocation.Y - backboneWidth + ClientSize.Height, ClientSize.Width, backboneWidth, 0.0f, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - centerHeight; m_vectors[1].X = AbsoluteLocation.X; m_vectors[1].Y = AbsoluteLocation.Y + ClientSize.Height; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + ClientSize.Width / 2; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - centerHeight; m_vectors[1].X = AbsoluteLocation.X + ClientSize.Width / 2; m_vectors[1].Y = AbsoluteLocation.Y + ClientSize.Height; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + ClientSize.Width; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - centerHeight; m_vectors[1].X = AbsoluteLocation.X + ClientSize.Width; m_vectors[1].Y = AbsoluteLocation.Y + ClientSize.Height; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + ClientSize.Width / 4; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - quarterHeight; m_vectors[1].X = AbsoluteLocation.X + ClientSize.Width / 4; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + 3 * ClientSize.Width / 4; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - quarterHeight; m_vectors[1].X = AbsoluteLocation.X + 3 * ClientSize.Width / 4; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + 1 * ClientSize.Width / 8; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - eighthHeight; m_vectors[1].X = AbsoluteLocation.X + 1 * ClientSize.Width / 8; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + 3 * ClientSize.Width / 8; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - eighthHeight; m_vectors[1].X = AbsoluteLocation.X + 3 * ClientSize.Width / 8; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + 5 * ClientSize.Width / 8; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - eighthHeight; m_vectors[1].X = AbsoluteLocation.X + 5 * ClientSize.Width / 8; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); m_vectors[0].X = AbsoluteLocation.X + 7 * ClientSize.Width / 8; m_vectors[0].Y = AbsoluteLocation.Y + ClientSize.Height - eighthHeight; m_vectors[1].X = AbsoluteLocation.X + 7 * ClientSize.Width / 8; WidgetUtilities.DrawLine(m_vectors, m_ForeColor.ToArgb(), drawArgs.device); }
/// <summary> /// Returns a string with this object's position in Degrees Minutes Seconds format /// </summary> /// <returns>Lat and Lon in DMS and Alt in meters</returns> public virtual string DMS() { StringBuilder retStr = new StringBuilder(); retStr.AppendFormat("Lat: {0}", WidgetUtilities.Degrees2DMS(this.Latitude, 'N', 'S')); retStr.AppendFormat(" Lon: {0}", WidgetUtilities.Degrees2DMS(this.Longitude, 'E', 'W')); retStr.AppendFormat(" Alt: {0:F0}", this.Altitude); return(retStr.ToString()); }
public void Render(DrawArgs drawArgs) { if (this.m_Visible) { float percent = 0; if (this.Value < this.Minimum) { percent = 0; } else if (this.Value > this.Maximum) { percent = 1.0f; } else { percent = (float)((this.Value - this.Minimum) / (this.Maximum - this.Minimum)); } if (this.Outline) { this.m_outlinePoints[0].X = this.AbsoluteLocation.X; this.m_outlinePoints[0].Y = this.AbsoluteLocation.Y; this.m_outlinePoints[1].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_outlinePoints[1].Y = this.AbsoluteLocation.Y; this.m_outlinePoints[2].X = this.AbsoluteLocation.X + this.ClientSize.Width; this.m_outlinePoints[2].Y = this.AbsoluteLocation.Y + this.ClientSize.Height; this.m_outlinePoints[3].X = this.AbsoluteLocation.X; this.m_outlinePoints[3].Y = this.AbsoluteLocation.Y + this.ClientSize.Height; this.m_outlinePoints[4].X = this.AbsoluteLocation.X; this.m_outlinePoints[4].Y = this.AbsoluteLocation.Y; WidgetUtilities.DrawLine(this.m_outlinePoints, this.m_ForeColor.ToArgb(), drawArgs.device); } WidgetUtilities.DrawBox(this.AbsoluteLocation.X, this.AbsoluteLocation.Y, (int)(percent * this.ClientSize.Width), this.ClientSize.Height, 0.5f, this.m_ForeColor.ToArgb(), drawArgs.device); } }
public override int Render(DrawArgs drawArgs, int xOffset, int yOffset) { m_ConsumedSize.Height = 0; if (m_textFont == null) { System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, FontStyle.Bold); m_textFont = new Microsoft.DirectX.Direct3D.Font(drawArgs.device, localHeaderFont); } if (m_visible) { if (!m_isInitialized) { this.Initialize(drawArgs); } m_ConsumedSize.Height = NODE_HEIGHT; // This value is dynamic based on the number of expanded nodes above this one m_location.Y = yOffset; // store this value so the mouse events can figure out where the buttons are m_xOffset = xOffset; // compute the color int color = this.Enabled ? m_itemOnColor : m_itemOffColor; // create the bounds of the text draw area Rectangle bounds = new Rectangle(this.AbsoluteLocation, new System.Drawing.Size(this.ClientSize.Width, NODE_HEIGHT)); if (m_isMouseOver) { if (!Enabled) { color = m_mouseOverOffColor; } WidgetUtilities.DrawBox( bounds.X, bounds.Y, bounds.Width, bounds.Height, 0.0f, m_mouseOverColor, drawArgs.device); } #region Draw arrow bounds.X = this.AbsoluteLocation.X + xOffset; bounds.Width = NODE_ARROW_SIZE; // draw arrow if any children if (m_subNodes.Count > 0) { m_worldwinddingsFont.DrawText( null, (this.m_isExpanded ? "L" : "A"), bounds, DrawTextFormat.None, color); } #endregion Draw arrow #region Draw checkbox bounds.Width = NODE_CHECKBOX_SIZE; bounds.X += NODE_ARROW_SIZE; // Normal check symbol string checkSymbol; if (m_isRadioButton) { checkSymbol = this.IsChecked ? "O" : "P"; } else { checkSymbol = this.IsChecked ? "N" : "F"; } m_worldwinddingsFont.DrawText( null, checkSymbol, bounds, DrawTextFormat.NoClip, color); #endregion draw checkbox #region Draw update bounds.X += NODE_CHECKBOX_SIZE; bounds.Width = NODE_UPDATE_SIZE; string updateSymbol = "U"; //m_worldwinddingsFont m_textFont.DrawText(null, updateSymbol, bounds, DrawTextFormat.NoClip, color); #endregion draw update #region Draw name // compute the length based on name length // TODO: Do this only when the name changes Rectangle stringBounds = drawArgs.DefauleFont.MeasureString(null, Name, DrawTextFormat.NoClip, 0); m_size.Width = NODE_ARROW_SIZE + NODE_CHECKBOX_SIZE + NODE_UPDATE_SIZE + 5 + stringBounds.Width; m_ConsumedSize.Width = m_size.Width; bounds.Y += 2; bounds.X += NODE_UPDATE_SIZE + 5; bounds.Width = stringBounds.Width; drawArgs.DefauleFont.DrawText( null, Name, bounds, DrawTextFormat.None, color); #endregion Draw name if (m_isExpanded) { int newXOffset = xOffset + NODE_INDENT; for (int i = 0; i < m_subNodes.Count; i++) { if (m_subNodes[i] is WidgetTreeNode) { m_ConsumedSize.Height += ((WidgetTreeNode)m_subNodes[i]).Render(drawArgs, newXOffset, m_ConsumedSize.Height); } else { System.Drawing.Point newLocation = m_subNodes[i].Location; newLocation.Y = m_ConsumedSize.Height; newLocation.X = newXOffset; m_ConsumedSize.Height += m_subNodes[i].WidgetSize.Height; m_subNodes[i].Location = newLocation; m_subNodes[i].Render(drawArgs); // render normal widgets as a stack of widgets } // if the child width is bigger than my width save it as the consumed width for widget size calculations if (m_subNodes[i].WidgetSize.Width + newXOffset > m_ConsumedSize.Width) { m_ConsumedSize.Width = m_subNodes[i].WidgetSize.Width + newXOffset; } } } } return(m_ConsumedSize.Height); }
public void Render(DrawArgs drawArgs) { if (m_Visible) { string displayText = m_Text; string caretText = "|"; if (m_MouseDownPosition != System.Drawing.Point.Empty) { int startX = (this.m_LastMousePosition.X >= this.m_MouseDownPosition.X ? this.m_MouseDownPosition.X : this.m_LastMousePosition.X); int endX = (this.m_LastMousePosition.X < this.m_MouseDownPosition.X ? this.m_MouseDownPosition.X : this.m_LastMousePosition.X); int prevWidth = 0; bool startXFound = false; bool endXFound = false; for (int i = 1; i <= displayText.Length; i++) { System.Drawing.Rectangle rect = DrawArgs.Instance.DefauleFont.MeasureString( null, displayText.Substring(0, i).Replace(" ", "I"), DrawTextFormat.None, m_ForeColor); if (!startXFound && startX <= rect.Width) { startX = prevWidth; m_SelectionStart = i - 1; startXFound = true; } if (!endXFound && endX <= rect.Width) { endX = prevWidth; m_SelectionEnd = i - 1; endXFound = true; } if (startXFound && endXFound) { break; } prevWidth = rect.Width; } if (!endXFound) { m_SelectionEnd = displayText.Length; endX = prevWidth; } WidgetUtilities.DrawBox( AbsoluteLocation.X + startX, AbsoluteLocation.Y, endX - startX, this.ClientSize.Height, 0.0f, System.Drawing.Color.FromArgb(200, 200, 200, 200).ToArgb(), drawArgs.device); } drawArgs.DefauleFont.DrawText( null, m_Text, new System.Drawing.Rectangle(AbsoluteLocation.X, AbsoluteLocation.Y, m_Size.Width, m_Size.Height), DrawTextFormat.NoClip, m_ForeColor); if (System.DateTime.Now.Millisecond < 500) { string space = " W"; System.Drawing.Rectangle spaceRect = drawArgs.DefauleFont.MeasureString( null, space, DrawTextFormat.None, m_ForeColor); space = "W"; System.Drawing.Rectangle spaceRect1 = drawArgs.DefauleFont.MeasureString( null, space, DrawTextFormat.None, m_ForeColor); int spaceWidth = spaceRect.Width - spaceRect1.Width; if (m_RecalculateCaretPos) { if (m_LastMouseClickPosition == System.Drawing.Point.Empty) { m_CaretPos = displayText.Length; } else if (displayText.Length == 0) { m_CaretPos = 0; } else { for (int i = 1; i < displayText.Length; i++) { System.Drawing.Rectangle rect = drawArgs.DefauleFont.MeasureString( null, displayText.Substring(0, i).Replace(" ", "i"), DrawTextFormat.None, m_ForeColor); if (m_LastMouseClickPosition.X <= rect.Width) { m_CaretPos = i - 1; break; } } m_RecalculateCaretPos = false; } } if (m_CaretPos >= 0) { System.Drawing.Rectangle caretRect = drawArgs.DefauleFont.MeasureString( null, caretText, DrawTextFormat.None, m_ForeColor); System.Drawing.Rectangle textRect = drawArgs.DefauleFont.MeasureString( null, displayText.Substring(0, m_CaretPos), DrawTextFormat.None, m_ForeColor); int caretOffset = 0; if (m_CaretPos != 0 && m_CaretPos == displayText.Length && displayText[displayText.Length - 1] == ' ') { caretOffset = spaceWidth; } else if (m_CaretPos < displayText.Length && m_CaretPos > 0 && displayText[m_CaretPos - 1] == ' ') { caretOffset = spaceWidth; } drawArgs.DefauleFont.DrawText( null, caretText, new System.Drawing.Rectangle( AbsoluteLocation.X + textRect.Width - caretRect.Width / 2 + caretOffset, AbsoluteLocation.Y, m_Size.Width, m_Size.Height), DrawTextFormat.NoClip, System.Drawing.Color.Cyan);//m_ForeColor); } } } }
public void Render(DrawArgs drawArgs) { if (m_sprite == null) { m_sprite = new Sprite(drawArgs.device); } //if (mouseCursor != CursorType.Arrow) // DrawArgs.MouseCursor = mouseCursor; foreach (ControlMenuButton button in m_toolsMenuButtons) { if (button.IsPushed()) { // Does not render the button, but the functionality behind the button button.Render(drawArgs); } } foreach (ControlMenuButton button in m_toolsMenuButtons) { button.Update(drawArgs); } foreach (ControlMenuButton 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.Instance.LastMousePosition.Y < ControlMenuButton.NormalSize) || (m_anchor == MenuAnchor.Bottom && DrawArgs.Instance.LastMousePosition.Y > drawArgs.ScreenHeight - ControlMenuButton.NormalSize) || (m_anchor == MenuAnchor.Right && DrawArgs.Instance.LastMousePosition.X > drawArgs.ScreenWidth - ControlMenuButton.NormalSize)) { this._visibleState = VisibleState.Ascending; this._lastVisibleChange = System.DateTime.Now; } } else if ((m_anchor == MenuAnchor.Top && DrawArgs.Instance.LastMousePosition.Y > 2 * this._outerPadding + ControlMenuButton.NormalSize) || (m_anchor == MenuAnchor.Bottom && DrawArgs.Instance.LastMousePosition.Y < drawArgs.ScreenHeight - 2 * this._outerPadding - ControlMenuButton.NormalSize) || (m_anchor == MenuAnchor.Right && DrawArgs.Instance.LastMousePosition.X < drawArgs.ScreenWidth - ControlMenuButton.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; ControlMenuButton.NormalSize = ControlMenuButton.SelectedSize / 2; _outerPadding = ControlMenuButton.NormalSize * padRatio; float menuWidth = (ControlMenuButton.NormalSize + _outerPadding) * totalNumberButtons + _outerPadding; if (menuWidth > drawArgs.ScreenWidth) { ControlMenuButton.NormalSize = (drawArgs.ScreenWidth) / ((padRatio + 1) * totalNumberButtons + padRatio); _outerPadding = ControlMenuButton.NormalSize * padRatio; // recalc menuWidth if we want to center the toolbar menuWidth = (ControlMenuButton.NormalSize + _outerPadding) * totalNumberButtons + _outerPadding; } if (m_anchor == MenuAnchor.Left) { x = 0; y = (int)ControlMenuButton.NormalSize; } else if (m_anchor == MenuAnchor.Right) { x = (int)(drawArgs.ScreenWidth - 2 * _outerPadding - ControlMenuButton.NormalSize); y = (int)ControlMenuButton.NormalSize; } else if (m_anchor == MenuAnchor.Top) { x = (int)(drawArgs.ScreenWidth / 2 - totalNumberButtons * ControlMenuButton.NormalSize / 2 - _outerPadding); y = 0; } else if (m_anchor == MenuAnchor.Bottom) { x = (int)(drawArgs.ScreenWidth / 2 - totalNumberButtons * ControlMenuButton.NormalSize / 2 - _outerPadding); y = (int)(drawArgs.ScreenHeight - 2 * _outerPadding - ControlMenuButton.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)((ControlMenuButton.NormalSize + 5) - (percent * (ControlMenuButton.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 * (ControlMenuButton.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) { ControlMenuButton selectedButton = null; if (_curSelection >= 0 & _curSelection < totalNumberButtons) { if (_curSelection < m_toolsMenuButtons.Count) { selectedButton = (ControlMenuButton)m_toolsMenuButtons[_curSelection]; } else { selectedButton = (ControlMenuButton)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) { WidgetUtilities.DrawBox(0, 0, drawArgs.ScreenWidth, (int)(ControlMenuButton.NormalSize + 2 * _outerPadding), 0.0f, World.Settings.ToolBarBackColor.ToArgb(), drawArgs.device); } else if (m_anchor == MenuAnchor.Bottom) { WidgetUtilities.DrawBox(0, (int)(y - _outerPadding), drawArgs.ScreenWidth, (int)(ControlMenuButton.NormalSize + 4 * _outerPadding), 0.0f, World.Settings.ToolBarBackColor.ToArgb(), drawArgs.device); } } float total = 0; float extra = 0; for (int i = 0; i < totalNumberButtons; i++) { ControlMenuButton button; if (i < m_toolsMenuButtons.Count) { button = (ControlMenuButton)m_toolsMenuButtons[i]; } else { button = (ControlMenuButton)m_layersMenuButtons[i - m_toolsMenuButtons.Count]; } total += button.CurrentSize; extra += button.CurrentSize - ControlMenuButton.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++) { ControlMenuButton button; if (i < m_toolsMenuButtons.Count) { button = (ControlMenuButton)m_toolsMenuButtons[i]; } else { button = (ControlMenuButton)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(); } }