Exemplo n.º 1
0
        /// <summary>
        /// The render method to draw this widget on the screen.
        ///
        /// Called on the GUI thread.
        /// </summary>
        /// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
        public void Render(DrawArgs drawArgs)
        {
            if (!this.m_isInitialized)
            {
                this.Initialize(drawArgs);
            }

            if ((m_visible) && (m_enabled))
            {
                // Draw the interior background
                WidgetUtilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y,
                    m_size.Width,
                    m_size.Height,
                    0.0f,
                    m_BackgroundColor.ToArgb(),
                    drawArgs.device);

                m_sprite.Begin(SpriteFlags.AlphaBlend);
                m_sprite.Transform  = Matrix.Scaling(this.XScale, this.YScale, 0);
                m_sprite.Transform *= Matrix.Translation(AbsoluteLocation.X + m_size.Width / 2, AbsoluteLocation.Y + m_size.Height / 2, 0);
                m_sprite.Draw(m_iconTexture.Texture,
                              new Vector3(m_iconTexture.Width >> 1, m_iconTexture.Height >> 1, 0),
                              Vector3.Empty,
                              m_normalColor);
                m_sprite.Transform = Matrix.Identity;
                m_sprite.End();

                UpdateCrosshair(drawArgs);
            }
        }
Exemplo n.º 2
0
        public void Render(DrawArgs drawArgs)
        {
            if (m_Visible)
            {
                float percent = 0;
                if (Value < Minimum)
                {
                    percent = 0;
                }
                else if (Value > Maximum)
                {
                    percent = 1.0f;
                }
                else
                {
                    percent = (float)((Value - Minimum) / (Maximum - Minimum));
                }

                if (Outline)
                {
                    m_outlinePoints[0].X = AbsoluteLocation.X;
                    m_outlinePoints[0].Y = AbsoluteLocation.Y;

                    m_outlinePoints[1].X = AbsoluteLocation.X + ClientSize.Width;
                    m_outlinePoints[1].Y = AbsoluteLocation.Y;

                    m_outlinePoints[2].X = AbsoluteLocation.X + ClientSize.Width;
                    m_outlinePoints[2].Y = AbsoluteLocation.Y + ClientSize.Height;

                    m_outlinePoints[3].X = AbsoluteLocation.X;
                    m_outlinePoints[3].Y = AbsoluteLocation.Y + ClientSize.Height;

                    m_outlinePoints[4].X = AbsoluteLocation.X;
                    m_outlinePoints[4].Y = AbsoluteLocation.Y;

                    WidgetUtilities.DrawLine(m_outlinePoints, m_ForeColor.ToArgb(), drawArgs.device);
                }

                WidgetUtilities.DrawBox(
                    AbsoluteLocation.X,
                    AbsoluteLocation.Y,
                    (int)(percent * ClientSize.Width),
                    ClientSize.Height,
                    0.5f,
                    m_ForeColor.ToArgb(),
                    drawArgs.device);
            }
        }
Exemplo n.º 3
0
        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.defaultDrawingFont.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.defaultDrawingFont.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.defaultDrawingFont.MeasureString(
                        null,
                        space,
                        DrawTextFormat.None,
                        m_ForeColor);

                    space = "W";

                    System.Drawing.Rectangle spaceRect1 = drawArgs.defaultDrawingFont.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.defaultDrawingFont.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.defaultDrawingFont.MeasureString(
                            null,
                            caretText,
                            DrawTextFormat.None,
                            m_ForeColor);

                        System.Drawing.Rectangle textRect = drawArgs.defaultDrawingFont.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.defaultDrawingFont.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);
                    }
                }
            }
        }
Exemplo n.º 4
0
        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.defaultDrawingFont.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.defaultDrawingFont.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 TreeNodeWidget)
                        {
                            m_ConsumedSize.Height += ((TreeNodeWidget)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);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The render method to draw this widget on the screen.
        ///
        /// Called on the GUI thread.
        /// </summary>
        /// <param name="drawArgs">The drawing arguments passed from the WW GUI thread.</param>
        public void Render(DrawArgs drawArgs)
        {
            if ((!m_visible) || (!m_enabled))
            {
                return;
            }

            if (!m_isInitialized)
            {
                Initialize(drawArgs);
            }

            int widgetTop    = this.Top;
            int widgetBottom = this.Bottom;
            int widgetLeft   = this.Left;
            int widgetRight  = this.Right;

            m_currHeaderHeight = 0;

            #region Header Rendering

            // If we should render the header
            if (HeaderEnabled)
            {
                m_currHeaderHeight = m_headerHeight;

                WidgetUtilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y,
                    m_size.Width,
                    m_currHeaderHeight,
                    0.0f,
                    m_HeaderColor.ToArgb(),
                    drawArgs.device);

                Rectangle nameBounds = m_TitleFont.MeasureString(
                    null,
                    m_name,
                    DrawTextFormat.None,
                    0);

                int widthLeft = m_size.Width;

                m_TitleFont.DrawText(
                    null,
                    m_name,
                    new System.Drawing.Rectangle(this.AbsoluteLocation.X + 2, this.AbsoluteLocation.Y + 2, widthLeft, m_currHeaderHeight),
                    DrawTextFormat.None,
                    m_TextColor.ToArgb());


                // if we don't render the body add whatever is in the text field as annotation
                if (!m_renderBody)
                {
                    widthLeft -= nameBounds.Width + 10;
                    if (widthLeft > 20)
                    {
                        m_TextFont.DrawText(
                            null,
                            Text,
                            new System.Drawing.Rectangle(this.AbsoluteLocation.X + 10 + nameBounds.Width, this.AbsoluteLocation.Y + 3, widthLeft, m_currHeaderHeight),
                            DrawTextFormat.None,
                            m_TextColor.ToArgb());
                    }
                }

                // Render border
                m_OutlineVertsHeader[0].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[0].Y = AbsoluteLocation.Y;

                m_OutlineVertsHeader[1].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVertsHeader[1].Y = AbsoluteLocation.Y;

                m_OutlineVertsHeader[2].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVertsHeader[2].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVertsHeader[3].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[3].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVertsHeader[4].X = AbsoluteLocation.X;
                m_OutlineVertsHeader[4].Y = AbsoluteLocation.Y;

                WidgetUtilities.DrawLine(m_OutlineVertsHeader, m_BorderColor.ToArgb(), drawArgs.device);
            }

            #endregion

            #region Body Rendering

            if (m_renderBody)
            {
                // Draw the interior background
                WidgetUtilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y + m_currHeaderHeight,
                    m_size.Width,
                    m_size.Height - m_currHeaderHeight,
                    0.0f,
                    m_BackgroundColor.ToArgb(),
                    drawArgs.device);

                int childrenHeight = 0;
                int childrenWidth  = 0;

                int bodyHeight = m_size.Height - m_currHeaderHeight;
                int bodyWidth  = m_size.Width;

                getChildrenSize(out childrenHeight, out childrenWidth);

                // Render each child widget

                int bodyLeft    = this.BodyLocation.X;
                int bodyRight   = this.BodyLocation.X + this.ClientSize.Width;
                int bodyTop     = this.BodyLocation.Y;
                int bodyBottom  = this.BodyLocation.Y + this.ClientSize.Height;
                int childLeft   = 0;
                int childRight  = 0;
                int childTop    = 0;
                int childBottom = 0;

                for (int index = m_ChildWidgets.Count - 1; index >= 0; index--)
                {
                    IWidget currentChildWidget = m_ChildWidgets[index] as IWidget;
                    if (currentChildWidget != null)
                    {
                        if (currentChildWidget.ParentWidget == null || currentChildWidget.ParentWidget != this)
                        {
                            currentChildWidget.ParentWidget = this;
                        }
                        System.Drawing.Point childLocation = currentChildWidget.AbsoluteLocation;

                        // if any portion is visible try to render
                        childLeft   = childLocation.X;
                        childRight  = childLocation.X + currentChildWidget.WidgetSize.Width;
                        childTop    = childLocation.Y;
                        childBottom = childLocation.Y + currentChildWidget.WidgetSize.Height;

                        if ((((childLeft >= bodyLeft) && (childLeft <= bodyRight)) ||
                             ((childRight >= bodyLeft) && (childRight <= bodyRight)) ||
                             ((childLeft <= bodyLeft) && (childRight >= bodyRight)))
                            &&
                            (((childTop >= bodyTop) && (childTop <= bodyBottom)) ||
                             ((childBottom >= bodyTop) && (childBottom <= bodyBottom)) ||
                             ((childTop <= bodyTop) && (childBottom >= bodyBottom)))
                            )
                        {
                            currentChildWidget.Visible = true;
                            currentChildWidget.Render(drawArgs);
                        }
                        else
                        {
                            currentChildWidget.Visible = false;
                        }
                    }
                }

                m_OutlineVerts[0].X = AbsoluteLocation.X;
                m_OutlineVerts[0].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVerts[1].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVerts[1].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                m_OutlineVerts[2].X = AbsoluteLocation.X + m_size.Width;
                m_OutlineVerts[2].Y = AbsoluteLocation.Y + m_size.Height;

                m_OutlineVerts[3].X = AbsoluteLocation.X;
                m_OutlineVerts[3].Y = AbsoluteLocation.Y + m_size.Height;

                m_OutlineVerts[4].X = AbsoluteLocation.X;
                m_OutlineVerts[4].Y = AbsoluteLocation.Y + m_currHeaderHeight;

                WidgetUtilities.DrawLine(m_OutlineVerts, m_BorderColor.ToArgb(), drawArgs.device);
            }

            #endregion
        }