protected override void OnDrawing(UltravioletTime time) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); var settings = new TextLayoutSettings(spriteFont, null, null, TextFlags.Standard); if (Ultraviolet.Platform == UltravioletPlatform.Android || Ultraviolet.Platform == UltravioletPlatform.iOS) { textRenderer.Draw(spriteBatch, "Tap the screen to reset the scrolling text.", Vector2.One * 8f, Color.White, settings); } else { textRenderer.Draw(spriteBatch, $"Press {Ultraviolet.GetInput().GetActions().ResetScrollingText.Primary} to reset the scrolling text.", Vector2.One * 8f, Color.White, settings); } var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); var x = (window.DrawableSize.Width - textBlock.Width.Value) / 2; var y = (window.DrawableSize.Height - textBlock.Height.Value) / 2; textBlock.Draw(time, spriteBatch, new Vector2(x, y), Color.White); spriteBatch.End(); base.OnDrawing(time); }
protected override void OnUpdating(UltravioletTime time) { this.sprite.Update(time); if (time.TotalTime.TotalMilliseconds > 250 && !controller1.IsPlaying) { controller1.PlayAnimation(sprite["Explosion"]); } if (time.TotalTime.TotalMilliseconds > 500 && !controller2.IsPlaying) { controller2.PlayAnimation(sprite["Explosion"]); } if (time.TotalTime.TotalMilliseconds > 750 && !controller3.IsPlaying) { controller3.PlayAnimation(sprite["Explosion"]); } if (time.TotalTime.TotalMilliseconds > 1000 && !controller4.IsPlaying) { controller4.PlayAnimation(sprite["Explosion"]); } controller1.Update(time); controller2.Update(time); controller3.Update(time); controller4.Update(time); if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } base.OnUpdating(time); }
protected override void OnDrawing(UltravioletTime time) { var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width; var height = window.ClientSize.Height; stringFormatter.Reset(); stringFormatter.AddArgument(songPlayer.Position.Minutes); stringFormatter.AddArgument(songPlayer.Position.Seconds); stringFormatter.AddArgument(songPlayer.Duration.Minutes); stringFormatter.AddArgument(songPlayer.Duration.Seconds); stringFormatter.Format("{0:pad:2}:{1:pad:2} / {2:pad:2}:{3:pad:2}", stringBuffer); spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); var attribution = "|c:FFFFFF00|Now Playing|c|\n\n" + "\"|c:FFFFFF00|Deep Haze|c|\" by Kevin MacLeod (incompetech.com)\n" + "Licensed under Creative Commons: By Attribution 3.0\n" + "|c:FF808080|http://creativecommons.org/licenses/by/3.0/|c|\n\n\n"; var settings = new TextLayoutSettings(spriteFont, width, height, TextFlags.AlignMiddle | TextFlags.AlignCenter); textRenderer.CalculateLayout(attribution, textLayoutCommands, settings); textRenderer.Draw(spriteBatch, textLayoutCommands, Vector2.Zero, Color.White); var timerSize = spriteFont.Regular.MeasureString(stringBuffer); var timerPosition = new Vector2( (Int32)(textLayoutCommands.Bounds.Left + ((textLayoutCommands.Bounds.Width - timerSize.Width) / 2f)), (Int32)(textLayoutCommands.Bounds.Bottom - timerSize.Height)); spriteBatch.DrawString(spriteFont.Regular, stringBuffer, timerPosition, Color.White); spriteBatch.End(); base.OnDrawing(time); }
/// <inheritdoc/> protected override void OnUpdating(UltravioletTime time) { // ACTION: Save Image if (Ultraviolet.GetInput().GetActions().SaveImage.IsPressed() || (Ultraviolet.GetInput().GetTouchDevice()?.WasTapped() ?? false)) { content.Load<SoundEffect>(GlobalSoundEffectID.Shutter).Play(); // The SurfaceSaver class contains platform-specific functionality needed to write image // data to streams. We can pass a render target directly to the SaveAsPng() or SaveAsJpg() methods. var saver = SurfaceSaver.Create(); // The Android and iOS platforms have restrictions on where you can save files, so we'll just // save to the photo gallery on those devices. We'll use a partial method to implement // this platform-specific behavior. SaveImage(saver, rtarget); // Alternatively, we could populate an array with the target's data using the GetData() method... // var data = new Color[rtarget.Width * rtarget.Height]; // rtarget.GetData(data); } // ACTION: Exit Application if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } // Fade out save confirmation message if (confirmMsgOpacity > 0) confirmMsgOpacity -= (1.0 / 4.0) * time.ElapsedTime.TotalSeconds; base.OnUpdating(time); }
protected override void OnUpdating(UltravioletTime time) { if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } base.OnUpdating(time); }
protected override void OnDrawingForeground(UltravioletTime time, SpriteBatch spriteBatch) { spriteBatch.Draw(blankTexture, new RectangleF(64, 64, Width - 128, Height - 128), Color.Black * 0.75f * TransitionPosition); var settings = new TextLayoutSettings(font, Width, Height, TextFlags.AlignCenter | TextFlags.AlignMiddle); textRenderer.Draw(spriteBatch, "Welcome to the game!", Vector2.Zero, Color.White * TransitionPosition, settings); base.OnDrawingForeground(time, spriteBatch); }
/// <inheritdoc/> public void Update(UltravioletTime time) { Contract.EnsureNotDisposed(this, Disposed); var temp = Updating; if (temp != null) { temp(this, time); } }
/// <inheritdoc/> public override void Update(UltravioletTime time) { var vm = View.GetViewModel<GamePlayViewModel>(); if (vm != null && vm.IsTriangleSpinning) { var rotMax = (Single)(Math.PI * 2.0); var rotDelta = (Single)(rotMax * time.ElapsedTime.TotalSeconds); vm.TriangleRotation = (vm.TriangleRotation + rotDelta) % rotMax; } base.Update(time); }
protected override void OnDrawing(UltravioletTime time) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); DrawAlignedText(); DrawColoredAndStyledText(); spriteBatch.End(); base.OnDrawing(time); }
protected override void OnUpdating(UltravioletTime time) { spinnerSprite.Update(time); if (loader.IsLoaded) { var screen = uiScreenService.Get<GameplayScreen>(); Screens.OpenBelow(screen, this); Screens.Close(this); } base.OnUpdating(time); }
protected override void OnDrawing(UltravioletTime time) { spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); spriteBatch.DrawSprite(this.sprite["Explosion"].Controller, new Vector2(32, 32)); spriteBatch.DrawSprite(controller1, new Vector2(132, 32)); spriteBatch.DrawSprite(controller2, new Vector2(232, 32)); spriteBatch.DrawSprite(controller3, new Vector2(332, 32)); spriteBatch.DrawSprite(controller4, new Vector2(432, 32)); spriteBatch.End(); base.OnDrawing(time); }
protected override void OnDrawingForeground(UltravioletTime time, SpriteBatch spriteBatch) { spriteBatch.Draw(blankTexture, new RectangleF(0, 0, Width, Height), new Color(180, 0, 0)); #if ANDROID || IOS var text = "This is SampleScreen1\nTap to open SampleScreen2"; #else var text = "This is SampleScreen1\nPress right arrow key to open SampleScreen2"; #endif var settings = new TextLayoutSettings(font, Width, Height, TextFlags.AlignCenter | TextFlags.AlignMiddle); textRenderer.Draw(spriteBatch, text, Vector2.Zero, Color.White * TransitionPosition, settings); base.OnDrawingForeground(time, spriteBatch); }
protected override void OnUpdating(UltravioletTime time) { if (IsReadyForInput) { var input = Ultraviolet.GetInput(); var keyboard = input.GetKeyboard(); var touch = input.GetTouchDevice(); if (keyboard.IsKeyPressed(Key.Left) || (touch != null && touch.WasTapped())) { Screens.Close(this); } } base.OnUpdating(time); }
protected override void OnDrawingForeground(UltravioletTime time, SpriteBatch spriteBatch) { var offset = GetScreenOffset(); spriteBatch.Draw(blankTexture, new RectangleF(offset, 0, Width, Height), new Color(0, 0, 180)); #if ANDROID var text = "This is SampleScreen2\nTap to open SampleScreen1"; #else var text = "This is SampleScreen2\nPress left arrow key to open SampleScreen1"; #endif var settings = new TextLayoutSettings(font, Width, Height, TextFlags.AlignCenter | TextFlags.AlignMiddle); textRenderer.Draw(spriteBatch, text, new Vector2(offset, 0), Color.White, settings); base.OnDrawingForeground(time, spriteBatch); }
protected override void OnUpdating(UltravioletTime time) { if (IsReadyForInput) { var input = Ultraviolet.GetInput(); var keyboard = input.GetKeyboard(); var touch = input.GetTouchDevice(); if (keyboard.IsKeyPressed(Key.Right) || (touch != null && touch.WasTapped())) { var screen = uiScreenService.Get<SampleScreen2>(); Screens.Open(screen); } } base.OnUpdating(time); }
protected override void OnDrawing(UltravioletTime time) { var winSize = Ultraviolet.GetPlatform().Windows.GetPrimary().DrawableSize; var x = 0; var y = 0; var width = winSize.Width / 4; var height = winSize.Height; for (int i = 0; i < 4; i++) { DrawGamePadState(i, new Rectangle(x, y, width, height)); x += width; } base.OnDrawing(time); }
protected override void OnUpdating(UltravioletTime time) { var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); if (window != null) { this.textBlock.ChangeSize( window.DrawableSize.Width / 2, window.DrawableSize.Height / 2); this.textBlock.Update(time); } if (Ultraviolet.GetInput().GetActions().ResetScrollingText.IsPressed() || (Ultraviolet.GetInput().GetTouchDevice()?.WasTapped() ?? false)) textBlock.Reset(); if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) Exit(); base.OnUpdating(time); }
/// <inheritdoc/> protected override void OnDrawing(UltravioletTime time) { // We've loaded our surface data into the 'data' array, and we'll use it now to draw an image to the screen. // We'll draw each pixel as a string of text representing that pixel's color. spriteBatch.Begin(SpriteSortMode.Deferred, null); const Int32 CellWidth = 64; const Int32 CellHeight = 24; var totalWidth = surface.Width * CellWidth; var totalHeight = surface.Height * CellHeight; var compositor = Ultraviolet.GetPlatform().Windows.GetPrimary().Compositor; var origX = (compositor.Width - totalWidth) / 2; var origY = (compositor.Height - totalHeight) / 2; var cx = origX; var cy = origY; var font = content.Load<SpriteFont>(GlobalFontID.SegoeUI); for (int y = 0; y < surface.Width; y++) { for (int x = 0; x < surface.Height; x++) { var cellColor = data[(y * surface.Width) + x]; var cellText = $"{cellColor:x}"; var cellPosition = new Vector2(cx, cy); spriteBatch.DrawString(font, cellText, cellPosition, cellColor); cx = cx + CellWidth; } cx = origX; cy = cy + CellHeight; } spriteBatch.End(); base.OnDrawing(time); }
protected override void OnDrawing(UltravioletTime time) { var gfx = Ultraviolet.GetGraphics(); var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); var aspectRatio = window.DrawableSize.Width / (float)window.DrawableSize.Height; effect.World = Matrix.CreateRotationY((float)(2.0 * Math.PI * time.TotalTime.TotalSeconds)); effect.View = Matrix.CreateLookAt(new Vector3(0, 0, 5), Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView((float)Math.PI / 4f, aspectRatio, 1f, 1000f); effect.VertexColorEnabled = true; foreach (var pass in this.effect.CurrentTechnique.Passes) { pass.Apply(); gfx.SetRasterizerState(RasterizerState.CullNone); gfx.SetGeometryStream(geometryStream); gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1); } base.OnDrawing(time); }
protected override void OnUpdating(UltravioletTime time) { foreach (var soundEffectPlayer in soundEffectPlayers) soundEffectPlayer.Update(time); var touch = Ultraviolet.GetInput().GetTouchDevice(); if (touch != null && touch.WasTapped()) { soundEffectPlayers[nextPlayerInSequence].Play(soundEffect); nextPlayerInSequence = (nextPlayerInSequence + 1) % soundEffectPlayers.Length; } var keyboard = Ultraviolet.GetInput().GetKeyboard(); if (keyboard.IsKeyPressed(Key.D1)) soundEffectPlayers[0].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D2)) soundEffectPlayers[1].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D3)) soundEffectPlayers[2].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D4)) soundEffectPlayers[3].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D5)) soundEffectPlayers[4].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D6)) soundEffectPlayers[5].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D7)) soundEffectPlayers[6].Play(soundEffect); if (keyboard.IsKeyPressed(Key.D8)) soundEffectPlayers[7].Play(soundEffect); if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } base.OnUpdating(time); }
/// <summary> /// Updates the scrolling text block's state. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Update(UltravioletTime)"/>.</param> public void Update(UltravioletTime time) { if (ProcessDelay(time)) return; var fullCharsVisible = (Int32)charsVisible; charsVisible = Math.Min(Text.Length, charsVisible + (time.ElapsedTime.TotalSeconds * charsPerSecond)); var fullCharsRevealed = (Int32)charsVisible - fullCharsVisible; if (fullCharsRevealed == 0) return; textLayoutCommands.GetCustomCommands(fullCharsVisible, fullCharsRevealed, this, (state, position, command) => { if (command.ID == DelayCommandID) return ((ScrollingTextBlock)state).HandleDelayCommand(command); if (command.ID == SpeedCommandID) return ((ScrollingTextBlock)state).HandleSpeedCommand(command); return true; }); }
/// <summary> /// Updates the current delay, if there is one, and returns a value indicating whether /// the block should be prevented from scrolling. /// </summary> private Boolean ProcessDelay(UltravioletTime time) { if (delay > 0) delay = Math.Max(0, delay - time.ElapsedTime.TotalMilliseconds); return delay > 0; }
protected override void OnDrawing(UltravioletTime time) { base.OnDrawing(time); }
/// <summary> /// Called when the scene is being rendered. /// </summary> /// <param name="time">Time elapsed since the last call to Draw.</param> protected override void OnDrawing(UltravioletTime time) { spriteBatch.Begin(); textFormatter.Reset(); textFormatter.AddArgument(Ultraviolet.GetGraphics().FrameRate); textFormatter.AddArgument(GC.GetTotalMemory(false) / 1024); textFormatter.AddArgument(Environment.Is64BitProcess ? "64-bit" : "32-bit"); textFormatter.Format("{0:decimals:2} FPS\nAllocated: {1:decimals:2} kb\n{2}", textBuffer); spriteBatch.DrawString(spriteFont, textBuffer, Vector2.One * 8f, Color.White); var size = Ultraviolet.GetPlatform().Windows.GetCurrent().Compositor.Size; var settings = new TextLayoutSettings(spriteFont, size.Width, size.Height, TextFlags.AlignCenter | TextFlags.AlignMiddle); textRenderer.Draw(spriteBatch, "Welcome to the |c:FFFF00C0|Ultraviolet Framework|c|!", Vector2.Zero, Color.White, settings); spriteBatch.End(); base.OnDrawing(time); }
/// <summary> /// Handles the Ultraviolet context's <see cref="UltravioletContext.WindowDrawn"/> event. /// </summary> private void uv_WindowDrawn(UltravioletContext uv, UltravioletTime time, IUltravioletWindow window) { OnWindowDrawn(time, window); }
protected override void OnDrawingBackground(UltravioletTime time, SpriteBatch spriteBatch) { spriteBatch.Draw(photograph, new RectangleF(0, 0, Width, Height), Color.White * TransitionPosition); base.OnDrawingBackground(time, spriteBatch); }
/// <summary> /// Handles the Ultraviolet window's Drawing event. /// </summary> /// <param name="window">The window being drawn.</param> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> private void uv_Drawing(IUltravioletWindow window, UltravioletTime time) { OnDrawing(time); }
/// <summary> /// Called after one of the application's windows has been drawn. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> /// <param name="window">The window that was just drawn.</param> protected virtual void OnWindowDrawn(UltravioletTime time, IUltravioletWindow window) { }
/// <summary> /// Called when the scene is being drawn. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> protected virtual void OnDrawing(UltravioletTime time) { }
/// <summary> /// Called when the application state is being updated. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Update(UltravioletTime)"/>.</param> protected virtual void OnUpdating(UltravioletTime time) { }
/// <inheritdoc/> public void Update(UltravioletTime time) { Contract.EnsureNotDisposed(this, Disposed); Updating?.Invoke(this, time); }
/// <summary> /// Draws the scrolling text block. /// </summary> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Draw(UltravioletTime)"/>.</param> /// <param name="spriteBatch">The sprite batch with which to draw the text block.</param> /// <param name="position">The position at which to draw the text block.</param> /// <param name="defaultColor">The default color with which to draw the text block.</param> public void Draw(UltravioletTime time, SpriteBatch spriteBatch, Vector2 position, Color defaultColor) { TextRenderer.Draw(spriteBatch, textLayoutCommands, position, defaultColor, 0, (Int32)charsVisible); }
/// <inheritdoc/> protected override void DrawOverride(UltravioletTime time, DrawingContext dc) { DrawBlank(dc, Color.Black * 0.5f); var viewport = AdjustViewportFor3D(dc); var triangleRotation = TriangleRotation; var triangleDistance = 5f - (TriangleZoom * 2.5f); var triangleAspectRatio = (Single)(ActualWidth / ActualHeight); var gfx = Ultraviolet.GetGraphics(); var effect = EnsureEffect(); effect.World = Matrix.CreateRotationY(TriangleRotation); effect.View = Matrix.CreateLookAt(new Vector3(0, 0, triangleDistance), Vector3.Zero, Vector3.Up); effect.Projection = Matrix.CreatePerspectiveFieldOfView((Single)(Math.PI / 4.0), triangleAspectRatio, 1f, 1000f); effect.VertexColorEnabled = true; foreach (var pass in effect.CurrentTechnique.Passes) { pass.Apply(); gfx.SetRasterizerState(RasterizerState.CullNone); gfx.SetGeometryStream(EnsureGeometryStream()); gfx.DrawPrimitives(PrimitiveType.TriangleList, 0, 1); } gfx.SetViewport(viewport); base.DrawOverride(time, dc); }
/// <summary> /// Handles the Ultraviolet context's Updating event. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="time">Time elapsed since the last call to <see cref="UltravioletContext.Update(UltravioletTime)"/>.</param> private void uv_Updating(UltravioletContext uv, UltravioletTime time) { OnUpdating(time); }
protected override void OnDrawing(UltravioletTime time) { var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); var width = window.ClientSize.Width; var height = window.ClientSize.Height; spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); var attribution = #if ANDROID "|c:FFFFFF00|Tap the screen|c| to activate one of the sound effect players.\n\n" + #else "Press the |c:FFFFFF00|1-8 number keys|c| to activate one of the sound effect players.\n\n" + #endif "\"|c:FFFFFF00|grenade.wav|c|\" by ljudman (http://freesound.org/people/ljudman)\n" + "Licensed under Creative Commons: Sampling+\n" + "|c:FF808080|http://creativecommons.org/licenses/sampling+/1.0/|c|"; var settings = new TextLayoutSettings(spriteFont, width, height, TextFlags.AlignMiddle | TextFlags.AlignCenter); textRenderer.CalculateLayout(attribution, textLayoutCommands, settings); textRenderer.Draw(spriteBatch, textLayoutCommands, Vector2.Zero, Color.White); spriteBatch.End(); base.OnDrawing(time); }
/// <summary> /// Updates the specified context. /// </summary> /// <param name="uv">The Ultraviolet context to update.</param> /// <param name="time">Time elapsed since the last update.</param> /// <returns><see langword="true"/> if the host should continue processing; otherwise, <see langword="false"/>.</returns> private Boolean UpdateContext(UltravioletContext uv, UltravioletTime time) { using (UltravioletProfiler.Section(UltravioletProfilerSections.Update)) { uv.Update(time); } return !uv.Disposed; }