예제 #1
0
        /// <summary>
        /// Draws all of the user interface components.
        /// </summary>
        /// <remarks>Do not call this method. This method will be called automatically</remarks>
        /// <param name="elapsedTime"></param>
        /// <param name="clear"></param>
        /// <param name="renderRightEye"></param>
        public void Draw(float elapsedTime, bool clear, bool renderRightEye)
        {
            State.Device.DepthStencilState = DepthStencilState.None;

            passedTime += elapsedTime;
            if (passedTime >= 1000)
            {
                passedTime  = 0;
                prevCounter = counter;
                counter     = 1;
            }
            else if (elapsedTime != 0)
            {
                counter++;
            }

            float y = 5;
            float x = 5;

            if (State.ShowFPS)
            {
                if (debugFont == null)
                {
                    throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " +
                                              "content directory before you can display debug information");
                }

                UI2DRenderer.WriteText(new Vector2(x, y), prevCounter + " FPS", State.DebugTextColor, debugFont);
                y += 20;
            }

            if (State.ShowTriangleCount)
            {
                if (debugFont == null)
                {
                    throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " +
                                              "content directory before you can display debug information");
                }

                UI2DRenderer.WriteText(new Vector2(x, y), triangleCount + " Triangles", State.DebugTextColor, debugFont);
                y += 20;
            }

            if (State.ShowNotifications)
            {
                if (debugFont == null)
                {
                    throw new GoblinException("You need to add 'DebugFont.spritefont' file to your " +
                                              "content directory before you can display debug information");
                }

                if (Notifier.MessageCount > 0)
                {
                    messages.AddRange(Notifier.GetMessages());
                }

                if (messages.Count > 0)
                {
                    float yGap = Notifier.Font.MeasureString(messages[0].Message).Y;
                    Color color;
                    switch (Notifier.Placement)
                    {
                    case Notifier.NotifierPlacement.TopRight:
                        y = 0;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right,
                                                   GoblinEnums.VerticalAlignment.None);
                            y += yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.TopMiddle:
                        y = 0;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Center,
                                                   GoblinEnums.VerticalAlignment.None);
                            y += yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.TopLeft:
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Left,
                                                   GoblinEnums.VerticalAlignment.None);
                            y += yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.BottomRight:
                        y = State.Height - yGap;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right,
                                                   GoblinEnums.VerticalAlignment.None);
                            y -= yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.BottomMiddle:
                        y = State.Height - yGap;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Center,
                                                   GoblinEnums.VerticalAlignment.None);
                            y -= yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.BottomLeft:
                        y = State.Height - yGap;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(0, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Left,
                                                   GoblinEnums.VerticalAlignment.None);
                            y -= yGap;
                        }
                        break;

                    case Notifier.NotifierPlacement.Custom:
                        x = Notifier.CustomStartLocation.X;
                        y = Notifier.CustomStartLocation.Y;
                        for (int i = messages.Count - 1; i >= 0; i--)
                        {
                            color = Notifier.Color;
                            if (messages[i].StartFadeOut)
                            {
                                color = new Color(color.R, color.G, color.B,
                                                  (byte)messages[i].FadeOutInterpolator.Value);
                            }
                            UI2DRenderer.WriteText(new Vector2(x, y), messages[i].Message, color,
                                                   Notifier.Font, Vector2.One, GoblinEnums.HorizontalAlignment.Right,
                                                   GoblinEnums.VerticalAlignment.None);
                            x -= Notifier.CustomAppearDirection.X;
                            y += Notifier.CustomAppearDirection.Y;
                        }
                        break;
                    }

                    if (Notifier.FadeOutTime > 0)
                    {
                        double currentTime = DateTime.Now.TimeOfDay.TotalMilliseconds;
                        for (int i = 0; i < messages.Count; i++)
                        {
                            if (!messages[i].StartFadeOut)
                            {
                                if ((currentTime - messages[i].StartTime) >= Notifier.FadeOutTime)
                                {
                                    messages[i].StartFadeOut = true;
                                    messages[i].FadeOutInterpolator.Start();
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }

                        int deleteCount = 0;
                        for (int i = 0; i < messages.Count; i++)
                        {
                            if (messages[i].StartFadeOut)
                            {
                                if (messages[i].FadeOutInterpolator.Done)
                                {
                                    deleteCount++;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        messages.RemoveRange(0, deleteCount);
                    }
                }
            }

            foreach (G2DComponent comp2d in comp2Ds)
            {
                comp2d.RenderWidget();
            }

            if (renderRightEye)
            {
                UI2DRenderer.Flush(clear, -globalUIShift / 2);
            }
            else
            {
                UI2DRenderer.Flush(clear, globalUIShift / 2);
            }

            State.Device.DepthStencilState = DepthStencilState.Default;

            UI3DRenderer.Flush(clear);
        }