コード例 #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 ((this.m_visible) && (this.m_enabled))
            {
                // Draw the interior background
                WidgetUtilities.DrawBox(
                    this.AbsoluteLocation.X,
                    this.AbsoluteLocation.Y, this.m_size.Width, this.m_size.Height,
                    0.0f, this.m_BackgroundColor.ToArgb(),
                    drawArgs.device);

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

                this.UpdateCrosshair(drawArgs);
            }
        }
コード例 #2
0
        public void Render(DrawArgs drawArgs)
        {
            if (this.m_Visible)
            {
                string displayText = this.m_Text;
                string caretText   = "|";

                if (this.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, this.m_ForeColor);

                        if (!startXFound && startX <= rect.Width)
                        {
                            startX = prevWidth;
                            this.m_SelectionStart = i - 1;
                            startXFound           = true;
                        }

                        if (!endXFound && endX <= rect.Width)
                        {
                            endX = prevWidth;
                            this.m_SelectionEnd = i - 1;
                            endXFound           = true;
                        }

                        if (startXFound && endXFound)
                        {
                            break;
                        }

                        prevWidth = rect.Width;
                    }

                    if (!endXFound)
                    {
                        this.m_SelectionEnd = displayText.Length;
                        endX = prevWidth;
                    }

                    WidgetUtilities.DrawBox(this.AbsoluteLocation.X + startX, this.AbsoluteLocation.Y,
                                            endX - startX,
                                            this.ClientSize.Height, 0.0f, System.Drawing.Color.FromArgb(200, 200, 200, 200).ToArgb(),
                                            drawArgs.device);
                }

                drawArgs.defaultDrawingFont.DrawText(
                    null, this.m_Text,
                    new System.Drawing.Rectangle(this.AbsoluteLocation.X, this.AbsoluteLocation.Y, this.m_Size.Width, this.m_Size.Height),
                    DrawTextFormat.NoClip, this.m_ForeColor);

                if (DateTime.Now.Millisecond < 500)
                {
                    string space = " W";

                    System.Drawing.Rectangle spaceRect = drawArgs.defaultDrawingFont.MeasureString(
                        null,
                        space,
                        DrawTextFormat.None, this.m_ForeColor);

                    space = "W";

                    System.Drawing.Rectangle spaceRect1 = drawArgs.defaultDrawingFont.MeasureString(
                        null,
                        space,
                        DrawTextFormat.None, this.m_ForeColor);

                    int spaceWidth = spaceRect.Width - spaceRect1.Width;

                    if (this.m_RecalculateCaretPos)
                    {
                        if (this.m_LastMouseClickPosition == System.Drawing.Point.Empty)
                        {
                            this.m_CaretPos = displayText.Length;
                        }
                        else if (displayText.Length == 0)
                        {
                            this.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, this.m_ForeColor);

                                if (this.m_LastMouseClickPosition.X <= rect.Width)
                                {
                                    this.m_CaretPos = i - 1;
                                    break;
                                }
                            }

                            this.m_RecalculateCaretPos = false;
                        }
                    }


                    if (this.m_CaretPos >= 0)
                    {
                        System.Drawing.Rectangle caretRect = drawArgs.defaultDrawingFont.MeasureString(
                            null,
                            caretText,
                            DrawTextFormat.None, this.m_ForeColor);

                        System.Drawing.Rectangle textRect = drawArgs.defaultDrawingFont.MeasureString(
                            null,
                            displayText.Substring(0, this.m_CaretPos),
                            DrawTextFormat.None, this.m_ForeColor);

                        int caretOffset = 0;
                        if (this.m_CaretPos != 0 && this.m_CaretPos == displayText.Length && displayText[displayText.Length - 1] == ' ')
                        {
                            caretOffset = spaceWidth;
                        }
                        else if (this.m_CaretPos < displayText.Length && this.m_CaretPos > 0 && displayText[this.m_CaretPos - 1] == ' ')
                        {
                            caretOffset = spaceWidth;
                        }

                        drawArgs.defaultDrawingFont.DrawText(
                            null,
                            caretText,
                            new System.Drawing.Rectangle(this.AbsoluteLocation.X + textRect.Width - caretRect.Width / 2 + caretOffset, this.AbsoluteLocation.Y, this.m_Size.Width, this.m_Size.Height),
                            DrawTextFormat.NoClip,
                            System.Drawing.Color.Cyan);                            //m_ForeColor);
                    }
                }
            }
        }
コード例 #3
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_visible) || (!this.m_enabled))
            {
                return;
            }

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

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

            this.m_currHeaderHeight = 0;

            #region Header Rendering

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

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

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

                int widthLeft = this.m_size.Width;

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


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

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

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

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

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

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

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

            #endregion

            #region Body Rendering

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

                int childrenHeight = 0;
                int childrenWidth  = 0;

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

                this.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 = this.m_ChildWidgets.Count - 1; index >= 0; index--)
                {
                    IWidget currentChildWidget = this.m_ChildWidgets[index] as IWidget;
                    if (currentChildWidget != null)
                    {
                        if (currentChildWidget.ParentWidget == null || currentChildWidget.ParentWidget != this)
                        {
                            currentChildWidget.ParentWidget = this;
                        }
                        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;
                        }
                    }
                }

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

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

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

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

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

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

            #endregion
        }
コード例 #4
0
        public override int Render(DrawArgs drawArgs, int xOffset, int yOffset)
        {
            this.m_ConsumedSize.Height = 0;
            if (m_textFont == null)
            {
                Font localHeaderFont = new Font("Arial", 12.0f, FontStyle.Bold);
                m_textFont = new SharpDX.Direct3D9.Font(drawArgs.device, localHeaderFont);
            }
            if (this.m_visible)
            {
                if (!this.m_isInitialized)
                {
                    this.Initialize(drawArgs);
                }

                this.m_ConsumedSize.Height = NODE_HEIGHT;

                // This value is dynamic based on the number of expanded nodes above this one
                this.m_location.Y = yOffset;

                // store this value so the mouse events can figure out where the buttons are
                this.m_xOffset = xOffset;

                // compute the color
                int color = this.Enabled ? this.m_itemOnColor : this.m_itemOffColor;

                // create the bounds of the text draw area
                Rectangle bounds = new Rectangle(this.AbsoluteLocation, new Size(this.ClientSize.Width, NODE_HEIGHT));

                if (this.m_isMouseOver)
                {
                    if (!this.Enabled)
                    {
                        color = this.m_mouseOverOffColor;
                    }

                    WidgetUtilities.DrawBox(
                        bounds.X,
                        bounds.Y,
                        bounds.Width,
                        bounds.Height,
                        0.0f, this.m_mouseOverColor,
                        drawArgs.device);
                }

                #region Draw arrow

                bounds.X     = this.AbsoluteLocation.X + xOffset;
                bounds.Width = NODE_ARROW_SIZE;
                // draw arrow if any children
                if (this.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 (this.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, this.Name, DrawTextFormat.NoClip, 0);
                this.m_size.Width         = NODE_ARROW_SIZE + NODE_CHECKBOX_SIZE + NODE_UPDATE_SIZE + 5 + stringBounds.Width;
                this.m_ConsumedSize.Width = this.m_size.Width;

                bounds.Y    += 2;
                bounds.X    += NODE_UPDATE_SIZE + 5;
                bounds.Width = stringBounds.Width;

                drawArgs.defaultDrawingFont.DrawText(
                    null, this.Name,
                    bounds,
                    DrawTextFormat.None,
                    color);

                #endregion Draw name

                if (this.m_isExpanded)
                {
                    int newXOffset = xOffset + NODE_INDENT;

                    for (int i = 0; i < this.m_subNodes.Count; i++)
                    {
                        if (this.m_subNodes[i] is TreeNodeWidget)
                        {
                            this.m_ConsumedSize.Height += ((TreeNodeWidget)this.m_subNodes[i]).Render(drawArgs, newXOffset, this.m_ConsumedSize.Height);
                        }
                        else
                        {
                            Point newLocation = this.m_subNodes[i].Location;
                            newLocation.Y = this.m_ConsumedSize.Height;
                            newLocation.X = newXOffset;
                            this.m_ConsumedSize.Height += this.m_subNodes[i].WidgetSize.Height;
                            this.m_subNodes[i].Location = newLocation;
                            this.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 (this.m_subNodes[i].WidgetSize.Width + newXOffset > this.m_ConsumedSize.Width)
                        {
                            this.m_ConsumedSize.Width = this.m_subNodes[i].WidgetSize.Width + newXOffset;
                        }
                    }
                }
            }
            return(this.m_ConsumedSize.Height);
        }