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) { 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); }
/// <summary> /// Updates the opacity of the item's highlight. /// </summary> private void UpdateHighlightOpacity() { var isHighlit = false; if (!isHighlit && HighlightOnSelect && IsSelected) { isHighlit = true; } if (!isHighlit && HighlightOnMouseOver && IsMouseOver) { isHighlit = true; } if (!isHighlit && HighlightOnTouchOver && AreAnyTouchesOver) { var touchDevice = Ultraviolet.GetInput().GetFirstRegisteredTouchDevice(); if (touchDevice != null) { foreach (var touch in TouchesOver) { if (touchDevice.IsFirstTouchInGesture(touch)) { isHighlit = true; break; } } } } HighlightOpacity = isHighlit ? 1.0 : 0.0; }
/// <inheritdoc/> public void RegisterImportersAndProcessors(IEnumerable <Assembly> additionalAssemblies) { Contract.EnsureNot(registered, UltravioletStrings.ContentHandlersAlreadyRegistered); var asmUltravioletCore = typeof(UltravioletContext).Assembly; var asmUltravioletImpl = Ultraviolet.GetType().Assembly; var asmUltravioletPlatform = Ultraviolet.GetPlatform().GetType().Assembly; var asmUltravioletContent = Ultraviolet.GetContent().GetType().Assembly; var asmUltravioletGraphics = Ultraviolet.GetGraphics().GetType().Assembly; var asmUltravioletAudio = Ultraviolet.GetAudio().GetType().Assembly; var asmUltravioletInput = Ultraviolet.GetInput().GetType().Assembly; var asmUltravioletUI = Ultraviolet.GetUI().GetType().Assembly; var assemblies = new[] { asmUltravioletCore, asmUltravioletImpl, asmUltravioletPlatform, asmUltravioletContent, asmUltravioletGraphics, asmUltravioletAudio, asmUltravioletInput, asmUltravioletUI }.Union(additionalAssemblies ?? Enumerable.Empty <Assembly>()).Where(x => x != null).Distinct(); foreach (var asm in assemblies) { importers.RegisterAssembly(asm); processors.RegisterAssembly(asm); } registered = true; }
protected override void OnUpdating(UltravioletTime time) { // ACTION: Save Image if (Ultraviolet.GetInput().GetActions().SaveImage.IsPressed() || (Ultraviolet.GetInput().GetPrimaryTouchDevice()?.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); }
/// <summary> /// Updates the combo box's input capture state. /// </summary> private void UpdateInputCapture(Boolean captured) { if (captured) { if (Ultraviolet.GetInput().IsMouseCursorAvailable) { Mouse.Capture(View, this, CaptureMode.SubTree); } else { Touch.CaptureNew(View, this, CaptureMode.SubTree); } } else { if (Ultraviolet.GetInput().IsMouseCursorAvailable) { if (IsMouseCaptured) { Mouse.Capture(View, null, CaptureMode.None); } } else { if (AreNewTouchesCaptured) { Touch.CaptureNew(View, null, CaptureMode.None); } } } }
/// <summary> /// Handles SDL2's MOUSEBUTTONUP event. /// </summary> private void OnMouseButtonUp(ref SDL_MouseButtonEvent evt) { if (!Ultraviolet.GetInput().EmulateMouseWithTouchInput&& evt.which == SDL_TOUCH_MOUSEID) { return; } var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID); var button = GetUltravioletButton(evt.button); this.states[(int)button].OnUp(); if (evt.clicks == 1) { buttonStateClicks |= (uint)SDL_BUTTON(evt.button); OnClick(window, button); } if (evt.clicks == 2) { buttonStateDoubleClicks |= (uint)SDL_BUTTON(evt.button); OnDoubleClick(window, button); } OnButtonReleased(window, button); }
/// <inheritdoc/> protected override void OnGenericInteraction(UltravioletResource device, ref RoutedEventData data) { Ultraviolet.GetInput().ShowSoftwareKeyboard(KeyboardMode); data.Handled = true; base.OnGenericInteraction(device, ref data); }
protected override void OnLoadingContent() { //TODO: Attach & Detach Window & Apply changes var gfx = Ultraviolet.GetGraphics(); Ultraviolet.GetPlatform().Windows.GetPrimary().Caption = "Project Spark Test"; Ultraviolet.GetPlatform().Windows.GetPrimary().ClientSize = new Size2(1280, 720); camera = new Camera(); _content = ContentManager.Create("Content"); Resources.ContentManager = _content; LoadInputBindings(); Resources.Input = Ultraviolet.GetInput(); Resources.gfx = Ultraviolet.GetGraphics(); tr = new TextRenderer(); tr.RegisterGlyphShader("shaky", new Shaky()); tr.RegisterGlyphShader("wavy", new Wavy()); spriteBatch = SpriteBatch.Create(); LoadContentManifests(); base.OnLoadingContent(); Anonymous = _content.Load <SpriteFont>(GlobalFontID.Anonymous16); Rabelo = _content.Load <SpriteFont>(GlobalFontID.Rabelo16); Trebuchet = _content.Load <SpriteFont>(GlobalFontID.TrebuchetMS16); States.Push(new MainMenuState()); }
protected override void OnUpdating(UltravioletTime time) { if (Ultraviolet.GetInput().GetKeyboard().IsKeyPressed(Key.Escape)) { Exit(); } base.OnUpdating(time); }
/// <summary> /// Called when the application state is being updated. /// </summary> /// <param name="time">Time elapsed since the last call to Update.</param> protected override void OnUpdating(UltravioletTime time) { if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } base.OnUpdating(time); }
/// <summary> /// Flags the device as registered. /// </summary> private void Register() { var input = (SDL2UltravioletInput)Ultraviolet.GetInput(); if (input.RegisterTouchDevice(this)) { isRegistered = true; } }
protected override void OnUpdating(UltravioletTime time) { foreach (var soundEffectPlayer in soundEffectPlayers) { soundEffectPlayer.Update(time); } var touch = Ultraviolet.GetInput().GetPrimaryTouchDevice(); 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> /// Flags the device as registered. /// </summary> private void Register(UInt32 windowID) { var input = (SDL2UltravioletInput)Ultraviolet.GetInput(); if (input.RegisterMouseDevice(this)) { isRegistered = true; } }
public Game() : base("FaustVX", "My Test1") { _gravityThread = new Thread(CalculateGravityField); void CalculateGravityField() { var size = 8; var window = Ultraviolet.GetPlatform().Windows.GetPrimary(); while (true) { if (_ship is Ship ship && _movers?.ToArray() is CelestialBody[] movers && SelectedMover is var selectedMover) { var windowSize = new Vector2(window.ClientSize.Width, window.ClientSize.Height); var centerWindow = windowSize / 2; var width = (window.ClientSize.Width / size) + 1; var height = (window.ClientSize.Height / size) + 1; var field = new (Rectangle rect, Color color)[width, height]; var half = size / 2f; #if DEBUG var mouse = Ultraviolet.GetInput().GetMouse().Position; #endif var offset = TotalOffset - centerWindow; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var position = new Vector2(x * size + half, y * size + half) + offset; var force = Vector2.Zero; for (int i = 0; i < movers.Length; i++) { var mover = movers[i]; if ((mover.Position - position).LengthSquared() >= mover.CalculateGravityRadiusSquared(1, Globals.MinimumGravityForCalculation)) { continue; } mover.CalculateGravity(position, 1, out _, out var force2); force += force2; } var magnitude = force.Length(); #if DEBUG var rect = new RectangleF(position.X, position.Y, size, size); if (rect.Contains(mouse.X + offset.X, mouse.Y + offset.Y)) { Ultraviolet.GetPlatform().Windows.GetPrimary().Caption += $" -- pointed gravity: {magnitude:0.00000}m/s/s"; } #endif magnitude *= Globals.G / 2; var color = magnitude <= 1 ? Color.Green.Interpolate(Color.Blue, EasingFunction(magnitude, 3)) : Color.Red.Interpolate(Color.Blue, 1 / (magnitude)); field[x, y] = (new Rectangle(x * size, y * size, size, size), color);
/// <summary> /// Releases resources associated with the input devices. /// </summary> private void QuitInput() { var input = Ultraviolet.GetInput(); var keyboard = input.GetKeyboard(); if (keyboard != null) { keyboard.TextInput -= this.Keyboard_TextInput; } }
/// <summary> /// Handles SDL2's MOUSEMOTION event. /// </summary> private void OnMouseMotion(ref SDL_MouseMotionEvent evt) { if (!Ultraviolet.GetInput().EmulateMouseWithTouchInput&& evt.which == SDL_TOUCH_MOUSEID) { return; } SetMousePosition(evt.windowID, evt.x, evt.y); OnMoved(window, evt.x, evt.y, evt.xrel, evt.yrel); }
/// <inheritdoc/> protected override void OnLostKeyboardFocus(KeyboardDevice device, IInputElement oldFocus, IInputElement newFocus, ref RoutedEventData data) { Ultraviolet.GetInput().HideSoftwareKeyboard(); if (TextEditor != null) { TextEditor.HandleLostKeyboardFocus(); } base.OnLostKeyboardFocus(device, oldFocus, newFocus, ref data); }
/// <inheritdoc/> protected override void OnTouchLeave(TouchDevice device, Int64 id, RoutedEventData data) { if (!Ultraviolet.GetInput().IsMouseCursorAvailable) { if (device.IsFirstTouchInGesture(id)) { IsPressed = false; } } base.OnTouchLeave(device, id, data); }
protected override void OnLoadingContent() { this.content = ContentManager.Create("Content"); spriteBatch = SpriteBatch.Create(); Keyboard = Ultraviolet.GetInput().GetKeyboard(); Keyboard.ButtonReleased += Keyboard_ButtonReleased; // TODO: Load content here base.OnLoadingContent(); }
protected override void OnDrawing(UltravioletTime time) { var window = Ultraviolet.GetPlatform().Windows.GetCurrent(); var input = Ultraviolet.GetInput(); if (input.GetKeyboard().IsKeyDown(Key.Backslash)) { window.Position = new Point2(0, 40); } this.spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend); _colorList = new List <Color>(); cpu._Halted = false; cpu.Loop(); for (int y = 0; y < _height; y++) { for (int yScale = 0; yScale < _scale; yScale++) { for (int x = 0; x < _width; x++) { for (int xScale = 0; xScale < _scale; xScale++) { switch (cpu._PPU._frameData[y, x]) { case 0: _colorList.Add(_white); break; case 1: _colorList.Add(_dark); break; case 2: _colorList.Add(_light); break; case 3: _colorList.Add(_black); break; } } } } } _canvas.Clear(_black); _canvas.SetData(_colorList.ToArray()); _canvas.Flip(SurfaceFlipDirection.Vertical); _frameBuffer.SetData(_canvas); this.spriteBatch.Flush(); this.spriteBatch.Draw(_frameBuffer, new Vector2(0, 0), null, Color.White, 0f, new Vector2(0, 0), 1, SpriteEffects.None, 0f); this.spriteBatch.End(); _canvas.Clear(_black); base.OnDrawing(time); }
/// <inheritdoc/> protected override void OnGotKeyboardFocus(KeyboardDevice device, IInputElement oldFocus, IInputElement newFocus, RoutedEventData data) { UpdateTextInputRegion(); Ultraviolet.GetInput().ShowSoftwareKeyboard(KeyboardMode); if (TextEditor != null) { TextEditor.HandleGotKeyboardFocus(); } base.OnGotKeyboardFocus(device, oldFocus, newFocus, data); }
/// <inheritdoc/> protected override void OnTouchEnter(TouchDevice device, Int64 id, RoutedEventData data) { if (!Ultraviolet.GetInput().IsMouseCursorAvailable) { if (device.IsFirstTouchInGesture(id) && ClickMode == ClickMode.Hover) { OnClick(); OnClickByUser(); } } base.OnTouchEnter(device, id, data); }
/// <inheritdoc/> protected override void OnTouchTap(TouchDevice device, Int64 id, Double x, Double y, RoutedEventData data) { if (!Ultraviolet.GetInput().IsMouseCursorAvailable) { if (device.IsFirstTouchInGesture(id)) { HandleReleased(checkMousePosition: false); data.Handled = true; } } base.OnTouchTap(device, id, x, y, data); }
/// <inheritdoc/> protected override void OnTouchDown(TouchDevice device, Int64 id, Double x, Double y, Single pressure, RoutedEventData data) { if (!Ultraviolet.GetInput().IsMouseCursorAvailable) { if (device.IsFirstTouchInGesture(id)) { HandlePressed(); data.Handled = true; } } base.OnTouchDown(device, id, x, y, pressure, data); }
/// <summary> /// Called when the application state is being updated. /// </summary> /// <param name="uv">The Ultraviolet context.</param> /// <param name="time">Time elapsed since the last call to Update.</param> protected override void OnUpdating(UltravioletTime time) { if (Ultraviolet.GetInput().GetActions().MoveLeft.IsPressed() || Ultraviolet.GetInput().GetActions().MoveLeft.IsDown()) { MoveGameObject(new Vec2(-30, 0), playerObj); } if (Ultraviolet.GetInput().GetActions().MoveRight.IsPressed() || Ultraviolet.GetInput().GetActions().MoveRight.IsDown()) { MoveGameObject(new Vec2(+30, 0), playerObj); } if (Ultraviolet.GetInput().GetActions().Shoot.IsPressed()) { //retrieve projectiles from shooting Projectile[] temp = playerObj.playerWeapon.pattern.ShootWeapon(playerObj.position, new Vector2(mouse.X, mouse.Y)); //add returned projectiles to the queue for (int i = 0; i < temp.Length; i++) { gameProjectiles.Enqueue(temp[i]); } } if (Ultraviolet.GetInput().GetActions().ExitApplication.IsPressed()) { Exit(); } if (Ultraviolet.GetInput().GetActions().Jump.IsPressed()) { //physicsTestObject.body2D.ApplyImpulse(new Vec2(0F, -20F), new Vec2(0F, 0F)); } //FIRE THE BULLETS (just 1) (and apply sprites as they appear) if (gameProjectiles.Count >= 1) { firedBullet = gameProjectiles.Dequeue(); firedBullet.sprite = content.Load <Sprite>(GlobalSpriteID.Brown_Kernel); firedBullet.animationIndex = 0; firedBullet.animations = new SpriteAnimationController[] { sprite["Brown_Kernel"].Controller }; firedBullet.SetupBodyFromSprite(physicsWorld); firedBullet.body2D.ApplyForce(firedBullet.fireDirection.ToWorldVector(), firedBullet.position.ToWorldVector()); firingBullet = true; } else { firingBullet = false; } physicsWorld.Step(1F / 60F, 10, 10); playerObj.position = playerObj.body2D.GetPosition().ToScreenVector(); base.OnUpdating(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 files. We can pass a render target directly to the SaveAsPng() or SaveAsJpg() methods. var saver = SurfaceSaver.Create(); var filename = $"output-{DateTime.Now:yyyyMMdd-HHmmss}.png"; var path = filename; #if ANDROID var dir = Android.OS.Environment.GetExternalStoragePublicDirectory( Android.OS.Environment.DirectoryPictures).AbsolutePath; path = Path.Combine(dir, filename); #endif using (var stream = File.OpenWrite(path)) saver.SaveAsPng(rtarget, stream); #if ANDROID Android.Media.MediaScannerConnection.ScanFile(ApplicationContext, new String[] { path }, new String[] { Android.Webkit.MimeTypeMap.Singleton.GetMimeTypeFromExtension("png") }, null); confirmMsgText = $"Image saved to photo gallery"; confirmMsgOpacity = 1; #else confirmMsgText = $"Image saved to {filename}"; confirmMsgOpacity = 1; #endif // 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); }
/// <inheritdoc/> protected override void OnGotKeyboardFocus(KeyboardDevice device, IInputElement oldFocus, IInputElement newFocus, ref RoutedEventData data) { Ultraviolet.GetInput().ShowSoftwareKeyboard(KeyboardMode.Text); if (PART_Editor != null) { PART_Editor.HandleGotKeyboardFocus(); } UpdateIsSelectionActive(); base.OnGotKeyboardFocus(device, oldFocus, newFocus, ref data); }
/// <summary> /// Handles SDL2's MOUSEWHEEL event. /// </summary> private void OnMouseWheel(ref SDL_MouseWheelEvent evt) { if (!Ultraviolet.GetInput().EmulateMouseWithTouchInput&& evt.which == SDL_TOUCH_MOUSEID) { return; } var window = Ultraviolet.GetPlatform().Windows.GetByID((int)evt.windowID); wheelDeltaX = evt.x; wheelDeltaY = evt.y; OnWheelScrolled(window, evt.x, evt.y); }
/// <inheritdoc/> protected override void OnLostKeyboardFocus(KeyboardDevice device, IInputElement oldFocus, IInputElement newFocus, RoutedEventData data) { Ultraviolet.GetInput().HideSoftwareKeyboard(); if (PART_Editor != null) { PART_Editor.HandleLostKeyboardFocus(); } UpdateIsSelectionActive(); base.OnLostKeyboardFocus(device, oldFocus, newFocus, data); }