示例#1
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);
            }
        }
示例#2
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
        }