private void INTERNAL_TextInputIn(Keys key) { if (key == Keys.Back) { INTERNAL_TextInputControlDown[0] = true; INTERNAL_TextInputControlRepeat[0] = Environment.TickCount + 400; TextInputEXT.OnTextInput((char)8); // Backspace } else if (key == Keys.Tab) { INTERNAL_TextInputControlDown[1] = true; INTERNAL_TextInputControlRepeat[1] = Environment.TickCount + 400; TextInputEXT.OnTextInput((char)9); // Tab } else if (key == Keys.Enter) { INTERNAL_TextInputControlDown[2] = true; INTERNAL_TextInputControlRepeat[2] = Environment.TickCount + 400; TextInputEXT.OnTextInput((char)13); // Enter } else if (keys.Contains(Keys.LeftControl) && key == Keys.V) { INTERNAL_TextInputControlDown[3] = true; INTERNAL_TextInputControlRepeat[3] = Environment.TickCount + 400; TextInputEXT.OnTextInput((char)22); // Control-V (Paste) INTERNAL_TextInputSuppress = true; } }
public override void OnDeselected(MenuElement nextElement) { base.OnDeselected(nextElement); TextInputEXT.StopTextInput(); TextInputEXT.TextInput -= OnTextInput; Page.Parent.Parent.Game.OnStateChange -= OnStateChange; }
public override void OnSelected(MenuElement lastElement) { base.OnSelected(lastElement); TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); Page.Parent.Parent.Game.OnStateChange += OnStateChange; }
public StateMachine() { Content.RootDirectory = "Content"; ScratchContent = new ContentManager(Services, "Content"); // for big things to be unloaded graphicsDeviceManager = new GraphicsDeviceManager(this); #if SDL2 TextInputEXT.TextInput += TextInputEXT_TextInput; TextInputEXT.StartTextInput(); #else EventInput.EventInput.Initialize(this.Window); EventInput.EventInput.CharEntered += new EventInput.CharEnteredHandler(EventInput_CharEntered); EventInput.EventInput.KeyDown += new EventInput.KeyEventHandler(EventInput_KeyDown); EventInput.EventInput.KeyUp += new EventInput.KeyEventHandler(EventInput_KeyUp); #endif }
public void SetTextInputState(bool enabled) { if (!enabled) { TextInputEXT.StopTextInput(); return; } if (!IsTextInputRegistered) { IsTextInputRegistered = true; TextInputEXT.TextInput += TextInputEXT_TextInput; TextInputEXT.TextEditing += TextInputEXT_TextEditing; } TextInputEXT.StartTextInput(); }
private void INTERNAL_TextInputUpdate() { if (INTERNAL_TextInputControlDown[0] && INTERNAL_TextInputControlRepeat[0] <= Environment.TickCount) { TextInputEXT.OnTextInput((char)8); } if (INTERNAL_TextInputControlDown[1] && INTERNAL_TextInputControlRepeat[1] <= Environment.TickCount) { TextInputEXT.OnTextInput((char)9); } if (INTERNAL_TextInputControlDown[2] && INTERNAL_TextInputControlRepeat[2] <= Environment.TickCount) { TextInputEXT.OnTextInput((char)13); } if (INTERNAL_TextInputControlDown[3] && INTERNAL_TextInputControlRepeat[3] <= Environment.TickCount) { TextInputEXT.OnTextInput((char)22); } }
public void Update(Game game) { if (_first) { TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); game.OnStateChange += OnStateChange; _first = false; } if (game.Input.MousePressed(MouseButton.Left)) { bool oldFocused = Focused; Focused = Rectangle.Contains(game.Input.MousePosition); if (Focused != oldFocused && FocusChanged != null) { FocusChanged(this, Focused); } } }
private void OnStateChange(object sender, Game.ChangeStateEventArgs e) { TextInputEXT.TextInput -= OnTextInput; TextInputEXT.StopTextInput(); ((Game)sender).OnStateChange -= OnStateChange; }
public override void RunLoop() { SDL.SDL_ShowWindow(Window.Handle); SDL.SDL_Event evt; while (INTERNAL_runApplication) { #if !THREADED_GL Threading.Run(); #endif while (SDL.SDL_PollEvent(out evt) == 1) { // Keyboard if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN) { Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); if (!keys.Contains(key)) { keys.Add(key); INTERNAL_TextInputIn(key); } } else if (evt.type == SDL.SDL_EventType.SDL_KEYUP) { Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); if (keys.Remove(key)) { INTERNAL_TextInputOut(key); } } // Mouse Input else if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION) { Mouse.INTERNAL_IsWarped = false; } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL) { // 120 units per notch. Because reasons. Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120; } // Touch Input else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Pressed, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Released, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Moved, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } // Various Window Events... else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT) { // Window Focus if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED) { IsActive = true; if (!INTERNAL_useFullscreenSpaces) { // If we alt-tab away, we lose the 'fullscreen desktop' flag on some WMs SDL.SDL_SetWindowFullscreen( Window.Handle, Game.GraphicsDevice.PresentationParameters.IsFullScreen ? (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0 ); } // Disable the screensaver when we're back. SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST) { IsActive = false; if (!INTERNAL_useFullscreenSpaces) { SDL.SDL_SetWindowFullscreen(Window.Handle, 0); } // Give the screensaver back, we're not that important now. SDL.SDL_EnableScreenSaver(); } // Window Resize else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Should be called on user resize only, NOT ApplyChanges! ((SDL2_GameWindow)Window).INTERNAL_ClientSizeChanged(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Need to reset the graphics device any time the window size changes if (Game.graphicsDeviceManager.IsFullScreen) { GraphicsDevice device = Game.GraphicsDevice; Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice( device.GLDevice.Backbuffer.Width, device.GLDevice.Backbuffer.Height ); } else { Game.graphicsDeviceManager.INTERNAL_ResizeGraphicsDevice( evt.window.data1, evt.window.data2 ); } } // Window Move else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED) { /* Apparently if you move the window to a new * display, a GraphicsDevice Reset occurs. * -flibit */ int newIndex = SDL.SDL_GetWindowDisplayIndex( Window.Handle ); if (newIndex != displayIndex) { displayIndex = newIndex; INTERNAL_GenerateDisplayModes(); Game.GraphicsDevice.Reset(); } } // Mouse Focus else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER) { SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE) { SDL.SDL_EnableScreenSaver(); } } // Controller device management else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEADDED) { GamePad.INTERNAL_AddInstance(evt.jdevice.which); } else if (evt.type == SDL.SDL_EventType.SDL_JOYDEVICEREMOVED) { GamePad.INTERNAL_RemoveInstance(evt.jdevice.which); } // Text Input else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT && !INTERNAL_TextInputSuppress) { string text; unsafe { text = new string((char *)evt.text.text); } if (text.Length > 0) { TextInputEXT.OnTextInput(text[0]); } } // Quit else if (evt.type == SDL.SDL_EventType.SDL_QUIT) { INTERNAL_runApplication = false; break; } } // Text Input Controls Key Handling INTERNAL_TextInputUpdate(); Keyboard.SetKeys(keys); Game.Tick(); } // We out. Game.Exit(); }
public void Draw(Engine.Game game) { game.Batch.Scissor = Rectangle; if (!_isSearching) { game.Batch.Rectangle(Rectangle, Color.Black * 0.85f); } if (_screenFade != 1.0f) { game.Batch.Text(SpriteBatch.FontStyle.Bold, 15, SelectedTile.Name(null, _environment), new Vector2(Rectangle.Value.X + 8, Rectangle.Value.Y + 4), Color.White * (1.0f - _screenFade) * (Disabled ? 0.3f : 0.6f)); Rectangle tileRect = new Rectangle(Rectangle.Value.X + Rectangle.Value.Width - 4 - 16 - 2, Rectangle.Value.Y + 6, 16, 16); if (game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)).Height > game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)).Width) { tileRect.Width /= 2; tileRect.X += 8; } game.Batch.Outline(tileRect, Color.White * (1.0f - _screenFade) * 0.6f, 1, false); game.Batch.Texture(tileRect, game.Assets.Get <Texture2D>(SelectedTile.TextureName(null, _environment)), Color.White * (1.0f - _screenFade)); } if (_screenFade != 0.0f) { Matrix oldTransform = game.Batch.Transform; game.Batch.Transform = Matrix.CreateTranslation( Rectangle.Value.X + 8 + 18 + 10, (int)-Scroll + Rectangle.Value.Y + 6, 0); int y = 0; foreach (Category category in Categories) { DrawCategory(game, category, true, ref y); } game.Batch.Transform = oldTransform; int cY = 8; int categoryTop = 8 - (int)Scroll; foreach (Category category in Categories) { Rectangle rectC = new Rectangle( Rectangle.Value.X + 8, Rectangle.Value.Y + cY /* - (categoryTop < cY ? cY - categoryTop : 0) */, 18, 18); bool hoverC = rectC.Contains(game.Input.MousePosition); game.Batch.Texture(rectC, game.Assets.Get <Texture2D>(category.Icon), Color.White * _screenFade * (hoverC ? 1.0f : 0.6f)); if (game.Input.MousePressed(Engine.MouseButton.Left) && hoverC && CanInteractWith) { _scrollTarget = Math.Min(ScrollableAmount, categoryTop + (int)Scroll - 8); } /*if(categoryTop < cY) * cY -= Math.Min(cY - categoryTop, 24); */ cY += 24; categoryTop += CalculateCategorySize(category, true).Y; } if (ScrollableAmount > 0) { float scrollBarHeight = 1000 / ScrollableAmount; if (scrollBarHeight > Rectangle.Value.Height - 16) { scrollBarHeight = Rectangle.Value.Height - 16; } if (scrollBarHeight < 20) { scrollBarHeight = 20; } Rectangle fullScrollRectangle = new Rectangle(Rectangle.TargetValue.Right - 18, Rectangle.TargetValue.Y + 8, 20, Rectangle.TargetValue.Height - 16); if ((fullScrollRectangle.Contains(game.Input.MousePosition) || _isScrolling) && CanInteractWith) { fullScrollRectangle.X = Rectangle.TargetValue.Right - 10; fullScrollRectangle.Width = 2; game.Batch.Rectangle(fullScrollRectangle, Color.White * 0.4f * _screenFade); if (game.Input.MousePressed(Engine.MouseButton.Left) && !_isScrolling && CanInteractWith) { _isScrolling = true; } } game.Batch.Rectangle(new Rectangle( Rectangle.TargetValue.Right - 10, (int)(MathHelper.Lerp(Rectangle.TargetValue.Y + 8, Rectangle.TargetValue.Bottom - 8 - scrollBarHeight, Scroll / ScrollableAmount)), 2, (int)scrollBarHeight), Color.White * 0.5f * _screenFade); } Rectangle rect = new Rectangle( Rectangle.Value.X + 8, Rectangle.TargetValue.Bottom - 8 - 18, 18, 18); bool hover = rect.Contains(game.Input.MousePosition); game.Batch.Texture(rect, game.Assets.Get <Texture2D>("editor/tilemenu/search.png"), Color.White * _screenFade * (hover ? 1.0f : 0.6f)); if (game.Input.MousePressed(Engine.MouseButton.Left) && hover && CanInteractWith) { _isSearching = true; _quitQueued = true; TextInputEXT.TextInput += OnSearchInput; TextInputEXT.StartTextInput(); game.OnStateChange += RemoveSearchInput; } } if (_isSearching) { game.Batch.Rectangle(Rectangle, Color.Black * 0.85f); string text = _searchTerm; Vector2 measure = game.DefaultFonts.MonoBold.Measure(14, text + "|"); text += ((int)((game.Time * 4) % 2) == 0 ? "|" : ""); game.Batch.Text(SpriteBatch.FontStyle.MonoBold, 14, text, Rectangle.Value.Center.ToVector2() - measure / 2, Color.White); } game.Batch.Scissor = null; }
public void Update(Game game) { if (_first) { TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); game.OnStateChange += OnStateChange; _first = false; RecalculateTotalArea(); } if (game.Input.MousePressed(MouseButton.Left) || _defocusQueued) { if (_isScrollingX || _isScrollingY) { if (!_defocusQueued) { _defocusQueued = true; } } else { _defocusQueued = false; bool oldFocused = Focused; Focused = Area.Value.Contains(game.Input.MousePosition); if (Focused != oldFocused && FocusChanged != null) { FocusChanged(this, Focused); } } } if (Area.Value.Contains(game.Input.MousePosition)) { if ((game.Input.MouseScroll < 0 && Scroll.Y < ScrollableAmount.Y) || (game.Input.MouseScroll > 0 && Scroll.Y > 0)) { Scroll.Y -= game.Input.MouseScroll / 4f; } if (game.Input.Key(Keys.Up) && Scroll.Y > 0) { Scroll.Y = Math.Max(0, Scroll.Y - ((float)game.DeltaTime * 140f)); } if (game.Input.Key(Keys.Down) && Scroll.Y < ScrollableAmount.Y) { Scroll.Y = Math.Min(ScrollableAmount.Y, Scroll.Y + ((float)game.DeltaTime * 140f)); } } if (_isScrollingX) { float at = game.Input.MousePosition.X - (Area.Value.Left + 8); float percentage = at / (Area.Value.Width - 16); Scroll.X = percentage * ScrollableAmount.X; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrollingX = false; } } if (_isScrollingY) { float at = game.Input.MousePosition.Y - (Area.Value.Top + 8); float percentage = at / (Area.Value.Height - 16); Scroll.Y = percentage * ScrollableAmount.Y; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrollingY = false; } } Scroll = Vector2.Clamp(Scroll, Vector2.Zero, ScrollableAmount); }
private void RemoveSearchInput(object sender, Game.ChangeStateEventArgs e) { TextInputEXT.TextInput -= OnSearchInput; TextInputEXT.StopTextInput(); Game.OnStateChange -= RemoveSearchInput; }
public override void OnLeave(GameState nextState) { TextInputEXT.TextInput -= OnTextInput; TextInputEXT.StopTextInput(); }
public override void OnEnter(GameState previousState) { _lastState = previousState; TextInputEXT.TextInput += OnTextInput; TextInputEXT.StartTextInput(); }
private void OnStateChange(object sender, Engine.Game.ChangeStateEventArgs e) { TextInputEXT.StopTextInput(); TextInputEXT.TextInput -= OnTextInput; }
public void Update(Game game) { if (!Disabled && ((Rectangle.Value.Contains(game.Input.MousePosition) && !Rectangle.Value.Contains(game.Input.PreviousMousePosition)) || (Game.Input.KeyPressed(Keys.S) && !_isSearching))) { Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, Math.Min((int)TotalArea.Y, MaxHeight)), TweenEaseType.EaseOutQuad, 0.1f); _screenFade.TweenTo(1, TweenEaseType.EaseOutQuad, 0.1f); if (Game.Input.KeyPressed(Keys.S)) { _isSearching = true; _quitQueued = true; TextInputEXT.TextInput += OnSearchInput; TextInputEXT.StartTextInput(); game.OnStateChange += RemoveSearchInput; } } else if (_quitQueued || (!Rectangle.Value.Contains(game.Input.MousePosition) && Rectangle.Value.Contains(game.Input.PreviousMousePosition))) { if (_isScrolling || _isSearching) { _quitQueued = true; } else { if (!Rectangle.Value.Contains(game.Input.MousePosition)) { Rectangle.TweenTo(new Rectangle(Rectangle.TargetValue.X, Rectangle.TargetValue.Y, (int)TotalArea.X, 28), TweenEaseType.EaseOutQuad, 0.1f); _screenFade.TweenTo(0, TweenEaseType.EaseOutQuad, 0.1f); } _quitQueued = false; } } if (_isSearching && game.Input.KeyPressed(Keys.Tab)) { string s = _searchTerm.ToLowerInvariant().Trim().Replace(" ", ""); foreach (Category category in Categories) { Tile searched = Search(s, category); if (searched != null) { _searchTerm = searched.Name(null, _environment); break; } } } if (_isSearching && game.Input.KeyPressed(Keys.Enter)) { _searchTerm = _searchTerm.ToLowerInvariant().Trim().Replace(" ", ""); foreach (Category category in Categories) { Tile searched = Search(_searchTerm, category); if (searched != null) { SelectedTile = searched; if (SelectionChanged != null) { SelectionChanged(this, SelectedTile); } } } _isSearching = false; _searchTerm = ""; TextInputEXT.TextInput -= OnSearchInput; TextInputEXT.StopTextInput(); game.OnStateChange -= RemoveSearchInput; } else if (_isSearching && game.Input.KeyPressed(Keys.Escape)) { _isSearching = false; _searchTerm = ""; TextInputEXT.TextInput -= OnSearchInput; TextInputEXT.StopTextInput(); game.OnStateChange -= RemoveSearchInput; } if (IsHovered && CanInteractWith) { float changed = _scrollTarget; if (game.Input.KeyPressed(Keys.Home)) { _scrollTarget = 0; } if (game.Input.KeyPressed(Keys.PageUp)) { _scrollTarget = Scroll - 180; } if (game.Input.KeyPressed(Keys.PageDown)) { _scrollTarget = Scroll + 180; } if (game.Input.KeyPressed(Keys.End)) { _scrollTarget = ScrollableAmount; } if (changed != _scrollTarget) { if (_scrollTarget < 0) { _scrollTarget = 0; } if (_scrollTarget > ScrollableAmount) { _scrollTarget = ScrollableAmount; } } } if (CanInteractWith) { if (_scrollTarget != -1) { Scroll = MathHelper.Lerp(Scroll, _scrollTarget, (float)Game.DeltaTime * 14f); if (Math.Abs(Scroll - _scrollTarget) <= 0.75f) { _scrollTarget = -1; } } else if (Rectangle.Value.Contains(game.Input.MousePosition)) { if ((game.Input.MouseScroll < 0 && Scroll < ScrollableAmount) || (game.Input.MouseScroll > 0 && Scroll > 0)) { Scroll -= game.Input.MouseScroll / 4f; } if (game.Input.Key(Keys.Up) && Scroll > 0) { Scroll = Math.Max(0, Scroll - ((float)game.DeltaTime * 140f)); } if (game.Input.Key(Keys.Down) && Scroll < ScrollableAmount) { Scroll = Math.Min(ScrollableAmount, Scroll + ((float)game.DeltaTime * 140f)); } } if (_isScrolling) { float at = game.Input.MousePosition.Y - (Rectangle.Value.Top + 8); float percentage = at / (Rectangle.Value.Height - 16); Scroll = percentage * ScrollableAmount; if (game.Input.MouseReleased(Engine.MouseButton.Left)) { _isScrolling = false; } } Scroll = MathHelper.Clamp(Scroll, 0, ScrollableAmount); } }
public override void RunLoop() { SDL.SDL_ShowWindow(Window.Handle); if (Window.IsBorderlessEXT) { /* FIXME: SDL2/X11 bug! * See SDL2_GameWindow.IsBorderlessEXT. * -flibit */ SDL.SDL_SetWindowBordered( Window.Handle, SDL.SDL_bool.SDL_FALSE ); } SDL.SDL_Event evt; while (INTERNAL_runApplication) { while (SDL.SDL_PollEvent(out evt) == 1) { // Keyboard if (evt.type == SDL.SDL_EventType.SDL_KEYDOWN) { #if USE_SCANCODES Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); #else Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym); #endif if (!keys.Contains(key)) { keys.Add(key); INTERNAL_TextInputIn(key); } } else if (evt.type == SDL.SDL_EventType.SDL_KEYUP) { #if USE_SCANCODES Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.scancode); #else Keys key = SDL2_KeyboardUtil.ToXNA(evt.key.keysym.sym); #endif if (keys.Remove(key)) { INTERNAL_TextInputOut(key); } } // Mouse Input else if (evt.type == SDL.SDL_EventType.SDL_MOUSEMOTION) { Mouse.INTERNAL_IsWarped = false; } else if (evt.type == SDL.SDL_EventType.SDL_MOUSEWHEEL) { // 120 units per notch. Because reasons. Mouse.INTERNAL_MouseWheel += evt.wheel.y * 120; } // Touch Input else if (evt.type == SDL.SDL_EventType.SDL_FINGERDOWN) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Pressed, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERUP) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Released, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } else if (evt.type == SDL.SDL_EventType.SDL_FINGERMOTION) { TouchPanel.AddEvent( (int)evt.tfinger.touchId, TouchLocationState.Moved, new Vector2( evt.tfinger.x, evt.tfinger.y ) ); } // Various Window Events... else if (evt.type == SDL.SDL_EventType.SDL_WINDOWEVENT) { // Window Focus if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_GAINED) { IsActive = true; if (!INTERNAL_useFullscreenSpaces) { // If we alt-tab away, we lose the 'fullscreen desktop' flag on some WMs SDL.SDL_SetWindowFullscreen( Window.Handle, Game.GraphicsDevice.PresentationParameters.IsFullScreen ? (uint)SDL.SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0 ); } // Disable the screensaver when we're back. SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_FOCUS_LOST) { IsActive = false; if (!INTERNAL_useFullscreenSpaces) { SDL.SDL_SetWindowFullscreen(Window.Handle, 0); } // Give the screensaver back, we're not that important now. SDL.SDL_EnableScreenSaver(); } // Window Resize else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_RESIZED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Should be called on user resize only, NOT ApplyChanges! ((SDL2_GameWindow)Window).INTERNAL_ClientSizeChanged(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED) { Mouse.INTERNAL_WindowWidth = evt.window.data1; Mouse.INTERNAL_WindowHeight = evt.window.data2; // Need to reset the graphics device any time the window size changes GraphicsDeviceManager gdm = Game.Services.GetService( typeof(IGraphicsDeviceService) ) as GraphicsDeviceManager; // FIXME: gdm == null? -flibit if (gdm.IsFullScreen) { GraphicsDevice device = Game.GraphicsDevice; gdm.INTERNAL_ResizeGraphicsDevice( device.GLDevice.Backbuffer.Width, device.GLDevice.Backbuffer.Height ); } else { gdm.INTERNAL_ResizeGraphicsDevice( evt.window.data1, evt.window.data2 ); } } // Window Move else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_MOVED) { /* Apparently if you move the window to a new * display, a GraphicsDevice Reset occurs. * -flibit */ int newIndex = SDL.SDL_GetWindowDisplayIndex( Window.Handle ); if (newIndex != displayIndex) { displayIndex = newIndex; INTERNAL_GenerateDisplayModes(); Game.GraphicsDevice.Reset(); } } // Mouse Focus else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_ENTER) { SDL.SDL_DisableScreenSaver(); } else if (evt.window.windowEvent == SDL.SDL_WindowEventID.SDL_WINDOWEVENT_LEAVE) { SDL.SDL_EnableScreenSaver(); } } // Controller device management else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEADDED) { GamePad.INTERNAL_AddInstance(evt.cdevice.which); } else if (evt.type == SDL.SDL_EventType.SDL_CONTROLLERDEVICEREMOVED) { GamePad.INTERNAL_RemoveInstance(evt.cdevice.which); } // Text Input else if (evt.type == SDL.SDL_EventType.SDL_TEXTINPUT && !INTERNAL_TextInputSuppress) { string text; // Based on the SDL2# LPUtf8StrMarshaler unsafe { byte *endPtr = evt.text.text; while (*endPtr != 0) { endPtr++; } byte[] bytes = new byte[endPtr - evt.text.text]; Marshal.Copy((IntPtr)evt.text.text, bytes, 0, bytes.Length); text = System.Text.Encoding.UTF8.GetString(bytes); } if (text.Length > 0) { TextInputEXT.OnTextInput(text[0]); } } // Quit else if (evt.type == SDL.SDL_EventType.SDL_QUIT) { INTERNAL_runApplication = false; break; } } // Text Input Controls Key Handling INTERNAL_TextInputUpdate(); Keyboard.SetKeys(keys); Game.Tick(); } // We out. Game.Exit(); }