Esempio n. 1
0
        public virtual void Render(DrawArgs drawArgs)
        {
            if (!Visible)
            {
                return;
            }

            if (m_TextFont == null)
            {
                System.Drawing.Font localHeaderFont = new System.Drawing.Font("Arial", 12.0f, FontStyle.Italic | FontStyle.Bold);
                m_TextFont = new Font(drawArgs.Device, localHeaderFont);
            }

            if (m_WorldWindDingsFont == null)
            {
                AddFontResource(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                PrivateFontCollection fpc = new PrivateFontCollection();
                fpc.AddFontFile(Path.Combine(Application.StartupPath, "World Wind Dings 1.04.ttf"));
                System.Drawing.Font worldwinddings = new System.Drawing.Font(fpc.Families[0], 12.0f);

                m_WorldWindDingsFont = new Font(drawArgs.Device, worldwinddings);
            }

            if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer &&
                DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer)
            {
                DrawArgs.MouseCursor = CursorType.SizeNWSE;
            }
            else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer &&
                     DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer)
            {
                DrawArgs.MouseCursor = CursorType.SizeNESW;
            }
            else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height &&
                     DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height)
            {
                DrawArgs.MouseCursor = CursorType.SizeNESW;
            }
            else if (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height &&
                     DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height)
            {
                DrawArgs.MouseCursor = CursorType.SizeNWSE;
            }
            else if ((DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height) ||
                     (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height))
            {
                DrawArgs.MouseCursor = CursorType.SizeWE;
            }
            else if ((DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer) ||
                     (DrawArgs.LastMousePosition.X > AbsoluteLocation.X - resizeBuffer && DrawArgs.LastMousePosition.X < AbsoluteLocation.X + resizeBuffer + ClientSize.Width && DrawArgs.LastMousePosition.Y > AbsoluteLocation.Y - resizeBuffer + ClientSize.Height && DrawArgs.LastMousePosition.Y < AbsoluteLocation.Y + resizeBuffer + ClientSize.Height))
            {
                DrawArgs.MouseCursor = CursorType.SizeNS;
            }

            if (ClientSize.Height
                > drawArgs.ParentControl.Height)
            {
                ClientSize = new Size(ClientSize.Width, drawArgs.ParentControl.Height);
            }

            if (ClientSize.Width
                > drawArgs.ParentControl.Width)
            {
                ClientSize = new Size(drawArgs.ParentControl.Width, ClientSize.Height);
            }

            if (!m_AutoHideHeader ||
                (DrawArgs.LastMousePosition.X >= m_Location.X && DrawArgs.LastMousePosition.X <= m_Location.X + m_Size.Width && DrawArgs.LastMousePosition.Y >= m_Location.Y && DrawArgs.LastMousePosition.Y <= m_Location.Y + m_Size.Height))
            {
                WidgetUtil.DrawBox(m_Location.X, m_Location.Y, m_Size.Width, m_HeaderHeight, 0.0f, m_HeaderColor.ToArgb(), drawArgs.Device);

                m_TextFont.DrawText(null, m_Text, new Rectangle(m_Location.X + 2, m_Location.Y, m_Size.Width, m_HeaderHeight), DrawTextFormat.None, m_TextColor.ToArgb());

                m_WorldWindDingsFont.DrawText(null, "E", new Rectangle(m_Location.X + m_Size.Width - 15, m_Location.Y + 2, m_Size.Width, m_Size.Height), DrawTextFormat.NoClip, Color.White.ToArgb());

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

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

                m_OutlineVertsHeader[2].X = AbsoluteLocation.X + ClientSize.Width;
                m_OutlineVertsHeader[2].Y = AbsoluteLocation.Y + m_HeaderHeight;

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

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

                if (!m_HideBorder)
                {
                    WidgetUtil.DrawLine(m_OutlineVertsHeader, m_BorderColor.ToArgb(), drawArgs.Device);
                }
            }

            WidgetUtil.DrawBox(m_Location.X, m_Location.Y + m_HeaderHeight, m_Size.Width, m_Size.Height - m_HeaderHeight, 0.0f, m_BackgroundColor.ToArgb(), drawArgs.Device);

            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;
                    }
                    currentChildWidget.Render(drawArgs);
                }
            }

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

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

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

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

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

            if (!m_HideBorder)
            {
                WidgetUtil.DrawLine(m_OutlineVerts, m_BorderColor.ToArgb(), drawArgs.Device);
            }
        }
Esempio n. 2
0
        public void Render(DrawArgs drawArgs)
        {
            if (m_Visible)
            {
                string displayText = m_Text;
                string caretText   = "|";

                if (m_MouseDownPosition != 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++)
                    {
                        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;
                    }

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

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

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

                    Rectangle spaceRect = drawArgs.DefaultDrawingFont.MeasureString(null, space, DrawTextFormat.None, m_ForeColor);

                    space = "W";

                    Rectangle spaceRect1 = drawArgs.DefaultDrawingFont.MeasureString(null, space, DrawTextFormat.None, m_ForeColor);

                    int spaceWidth = spaceRect.Width - spaceRect1.Width;

                    if (m_RecalculateCaretPos)
                    {
                        if (m_LastMouseClickPosition == Point.Empty)
                        {
                            m_CaretPos = displayText.Length;
                        }
                        else if (displayText.Length == 0)
                        {
                            m_CaretPos = 0;
                        }
                        else
                        {
                            for (int i = 1; i < displayText.Length; i++)
                            {
                                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)
                    {
                        Rectangle caretRect = drawArgs.DefaultDrawingFont.MeasureString(null, caretText, DrawTextFormat.None, m_ForeColor);

                        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 Rectangle(AbsoluteLocation.X + textRect.Width - caretRect.Width / 2 + caretOffset, AbsoluteLocation.Y, m_Size.Width, m_Size.Height), DrawTextFormat.NoClip, Color.Cyan);                       //m_ForeColor);
                    }
                }
            }
        }