/// <summary> /// Initializes the MessageBoxPhase. Sets its bounds and creates its buttons. /// </summary> protected internal override void Initialize(Game game) { Root.ReturnedMessageBoxResult = MessageBoxResult.Awaiting; // Total width and height and X and Y Rectangle bounds = Primitives.GetMultiLineTextBounds(Text, new Rectangle(0, 0, 700, 400), FontFamily.Normal); Height = bounds.Height + 106; Width = bounds.Width + 65; TopLeftX = Root.ScreenWidth / 2 - Width / 2; TopLeftY = Root.ScreenHeight / 2 - Height / 2; // Arranging buttons int numbuttons = 0; bool doOKButton = false; bool doYesButton = false; bool doNoButton = false; bool doCancelButton = false; if (ButtonsType == MessageBoxButtons.OK) { numbuttons = 1; doOKButton = true; } if (ButtonsType == MessageBoxButtons.OKCancel) { numbuttons = 2; doOKButton = true; doCancelButton = true; } if (ButtonsType == MessageBoxButtons.YesNo) { numbuttons = 2; doYesButton = true; doNoButton = true; } if (ButtonsType == MessageBoxButtons.YesNoCancel) { numbuttons = 3; doYesButton = true; doNoButton = true; doCancelButton = true; } const int buttonwidth = 140; const int buttonspace = 20; if (Width < numbuttons * (buttonwidth + buttonspace) + 100) { Width = numbuttons * (buttonwidth + buttonspace) + 100; } const int buttonheight = 40; int buttony = TopLeftY + Height - 10 - buttonheight; int x = TopLeftX + Width / 2 - (((buttonwidth + buttonspace) * (numbuttons)) - buttonspace) / 2; if (doOKButton) { Button b = new Button("OK", new Rectangle(x, buttony, buttonwidth, buttonheight)); b.Click += button_Click; buttons.Add(b); x += buttonwidth + buttonspace; } if (doYesButton) { Button b = new Button("Yes", new Rectangle(x, buttony, buttonwidth, buttonheight)); b.Click += button_Click; buttons.Add(b); x += buttonwidth + buttonspace; } if (doNoButton) { Button b = new Button("No", new Rectangle(x, buttony, buttonwidth, buttonheight)); b.Click += button_Click; buttons.Add(b); x += buttonwidth + buttonspace; } if (doCancelButton) { Button b = new Button("Cancel", new Rectangle(x, buttony, buttonwidth, buttonheight)); b.Click += button_Click; buttons.Add(b); } base.Initialize(game); }
/// <summary> /// Draws the video player. /// </summary> /// <param name="sb">Spritebatch to use.</param> /// <param name="rect">Rectangle to fill.</param> /// <param name="alreadyFullscreen">Is the video player part of the FullscreenVideoGamePhase?</param> public void Draw(SpriteBatch sb, Rectangle rect, bool alreadyFullscreen = false) { mouseOverFullscreenButton = false; mouseOverPlayPauseButton = false; mouseOverStopButton = false; mouseOverThisElement = false; if (State == MediaState.Playing || State == MediaState.Paused) { Texture2D tex = this.GetTexture(); if (tex != null) { Primitives.DrawImage(tex, rect, Color.White, scale: PerformScaling, scaleUp: false, scaleBgColor: Color.Black); } else { Primitives.FillRectangle(rect, Color.DarkGreen); } } else { if (stoppedTexture != null) { Primitives.DrawImage(stoppedTexture, rect, Color.White, scale: PerformScaling, scaleUp: false, scaleBgColor: Color.Black); } else { Primitives.FillRectangle(rect, Color.Black); } } if (Root.IsMouseOver(rect)) { mouseOverThisElement = true; Color clrSemitransparent = Color.FromNonPremultiplied(255, 255, 255, 150); Rectangle rectBottom = new Rectangle(rect.X, rect.Bottom - 5, rect.Width, 5); Primitives.FillRectangle(rectBottom, Color.Gray); double percent = videoPlayer.PlayPosition.TotalSeconds / videoPlayer.Video.Duration.TotalSeconds; Primitives.FillRectangle(new Rectangle(rectBottom.X, rectBottom.Y, (int)(rectBottom.Width * percent), rectBottom.Height), Color.White); const int ICONSIZE = 30; Rectangle rectPlayPause = new Rectangle(rectBottom.X + 1, rectBottom.Bottom - 1 - ICONSIZE, ICONSIZE, ICONSIZE); Rectangle rectStop = new Rectangle(rectBottom.X + ICONSIZE + 1, rectBottom.Bottom - 1 - ICONSIZE, ICONSIZE, ICONSIZE); Rectangle rectFullscreen = new Rectangle(rectBottom.Right - ICONSIZE - 1, rectBottom.Bottom - 1 - ICONSIZE, ICONSIZE, ICONSIZE); if (hasPlayPauseButton) { Texture2D icon = videoPlayer.State == MediaState.Playing ? Library.IconPause : Library.IconPlay; mouseOverPlayPauseButton = Root.IsMouseOver(rectPlayPause); sb.Draw(icon, rectPlayPause, mouseOverPlayPauseButton ? Color.White : clrSemitransparent); if (State == MediaState.Playing || State == MediaState.Paused) { mouseOverStopButton = Root.IsMouseOver(rectStop); sb.Draw(Library.IconStop, rectStop, mouseOverStopButton ? Color.White : clrSemitransparent); } } if (hasExtendToFullscreenButton && !alreadyFullscreen) { mouseOverFullscreenButton = Root.IsMouseOver(rectFullscreen); sb.Draw(Library.IconFullscreen, rectFullscreen, mouseOverFullscreenButton ? Color.White : clrSemitransparent); } if (onClickPlayPause) { sb.Draw(videoPlayer.State == MediaState.Playing ? Library.IconPause : Library.IconPlay, new Rectangle(rect.X + rect.Width / 2 - 30, rect.Y + rect.Height / 2 - 30, 60, 60), clrSemitransparent); } if (onClickExtendToFullscreen && !alreadyFullscreen) { sb.Draw(Library.IconFullscreen, new Rectangle(rect.X + rect.Width / 2 - 30, rect.Y + rect.Height / 2 - 30, 60, 60), clrSemitransparent); } } }