private void Renderer_Destroyed(object sender, EventArgs e) { ConfigurationState.Instance.HideCursorOnIdle.Event -= HideCursorStateChanged; NpadManager.Dispose(); Dispose(); }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } NpadManager.Update(); // Touchscreen bool hasTouch = false; // Get screen touch position if (!_enableMouse) { hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as SDL2MouseDriver).IsButtonPressed(MouseButton.Button1), _aspectRatio.ToFloat()); } if (!hasTouch) { TouchScreenManager.Update(false); } Device.Hid.DebugPad.Update(); return(true); }
public RendererWidgetBase(InputManager inputManager, GraphicsDebugLevel glLogLevel) { _inputManager = inputManager; NpadManager = _inputManager.CreateNpadManager(); _keyboardInterface = (IKeyboard)_inputManager.KeyboardDriver.GetGamepad("0"); NpadManager.ReloadConfiguration(ConfigurationState.Instance.Hid.InputConfig.Value.ToList()); WaitEvent = new ManualResetEvent(false); _glLogLevel = glLogLevel; Destroyed += Renderer_Destroyed; _chrono = new Stopwatch(); _ticksPerFrame = Stopwatch.Frequency / TargetFps; AddEvents((int)(EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask)); Shown += Renderer_Shown; _exitEvent = new ManualResetEvent(false); _hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle; _lastCursorMoveTime = Stopwatch.GetTimestamp(); ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged; }
public void Initialize(Switch device) { Device = device; Renderer = Device.Gpu.Renderer; Renderer?.Window.SetSize(_windowWidth, _windowHeight); NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard); }
public void Initialize(Switch device, List <InputConfig> inputConfigs, bool enableKeyboard, bool enableMouse) { Device = device; Renderer = Device.Gpu.Renderer; NpadManager.Initialize(device, inputConfigs, enableKeyboard, enableMouse); TouchScreenManager.Initialize(device); }
public Client(NpadManager npadManager) { _npadManager = npadManager; _hosts = new Dictionary <int, IPEndPoint>(); _motionData = new Dictionary <int, Dictionary <int, MotionInput> >(); _clients = new Dictionary <int, UdpClient>(); CloseClients(); }
public void Initialize(Switch device) { Device = device; Renderer = Device.Gpu.Renderer; Renderer.Window?.SetSize(_windowWidth, _windowHeight); if (Renderer != null) { Renderer.ScreenCaptured += Renderer_ScreenCaptured; } NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); TouchScreenManager.Initialize(device); }
protected virtual void Dispose(bool disposing) { if (disposing) { _isActive = false; TouchScreenManager?.Dispose(); NpadManager.Dispose(); SDL2Driver.Instance.UnregisterWindow(_windowId); SDL_DestroyWindow(WindowHandle); SDL2Driver.Instance.Dispose(); } }
public void Exit() { NpadManager?.Dispose(); if (_isStopped) { return; } _isStopped = true; _isActive = false; _exitEvent.WaitOne(); _exitEvent.Dispose(); }
public void Initialize(Switch device, List <InputConfig> inputConfigs, bool enableKeyboard, bool enableMouse) { Device = device; IRenderer renderer = Device.Gpu.Renderer; if (renderer is ThreadedRenderer tr) { renderer = tr.BaseRenderer; } Renderer = renderer; NpadManager.Initialize(device, inputConfigs, enableKeyboard, enableMouse); TouchScreenManager.Initialize(device); }
public void Exit() { TouchScreenManager?.Dispose(); NpadManager?.Dispose(); if (_isStopped) { return; } _gpuCancellationTokenSource.Cancel(); _isStopped = true; _isActive = false; _exitEvent.WaitOne(); _exitEvent.Dispose(); }
public GlRenderer(Switch device, InputManager inputManager, GraphicsDebugLevel glLogLevel) : base(GetGraphicsMode(), 3, 3, glLogLevel == GraphicsDebugLevel.None ? OpenGLContextFlags.Compat : OpenGLContextFlags.Compat | OpenGLContextFlags.Debug) { _inputManager = inputManager; NpadManager = _inputManager.CreateNpadManager(); _keyboardInterface = (IKeyboard)_inputManager.KeyboardDriver.GetGamepad("0"); NpadManager.ReloadConfiguration(ConfigurationState.Instance.Hid.InputConfig.Value.ToList()); WaitEvent = new ManualResetEvent(false); _device = device; Initialized += GLRenderer_Initialized; Destroyed += GLRenderer_Destroyed; ShuttingDown += GLRenderer_ShuttingDown; Initialize(); _chrono = new Stopwatch(); _ticksPerFrame = Stopwatch.Frequency / TargetFps; AddEvents((int)(EventMask.ButtonPressMask | EventMask.ButtonReleaseMask | EventMask.PointerMotionMask | EventMask.KeyPressMask | EventMask.KeyReleaseMask)); Shown += Renderer_Shown; _glLogLevel = glLogLevel; _exitEvent = new ManualResetEvent(false); _hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle; _lastCursorMoveTime = Stopwatch.GetTimestamp(); ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged; }
protected override void Dispose(bool disposing) { // Try to bind the OpenGL context before calling the shutdown event try { _openGLContext?.MakeCurrent(_nativeWindow); } catch (Exception) { } Device.DisposeGpu(); NpadManager.Dispose(); // Unbind context and destroy everything try { _openGLContext?.MakeCurrent(null); } catch (Exception) { } _openGLContext.Dispose(); }
public void Initialize(Switch device) { Device = device; IRenderer renderer = Device.Gpu.Renderer; if (renderer is ThreadedRenderer tr) { renderer = tr.BaseRenderer; } Renderer = renderer; Renderer?.Window?.SetSize(WindowWidth, WindowHeight); if (Renderer != null) { Renderer.ScreenCaptured += Renderer_ScreenCaptured; } NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse); TouchScreenManager.Initialize(device); }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } if (_isFocused) { Gtk.Application.Invoke(delegate { KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot(); HandleScreenState(keyboard); if (keyboard.IsPressed(Key.Delete)) { if (!ParentWindow.State.HasFlag(WindowState.Fullscreen)) { Ptc.Continue(); } } }); } NpadManager.Update(Device.Hid, Device.TamperMachine); if (_isFocused) { KeyboardHotkeyState currentHotkeyState = GetHotkeyState(); if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync)) { Device.EnableDeviceVsync = !Device.EnableDeviceVsync; } _prevHotkeyState = currentHotkeyState; } // Touchscreen bool hasTouch = false; // Get screen touch position from left mouse click // OpenTK always captures mouse events, even if out of focus, so check if window is focused. if (_isFocused && _mousePressed) { float aspectWidth = SwitchPanelHeight * ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat(); int screenWidth = AllocatedWidth; int screenHeight = AllocatedHeight; if (AllocatedWidth > AllocatedHeight * aspectWidth / SwitchPanelHeight) { screenWidth = (int)(AllocatedHeight * aspectWidth) / SwitchPanelHeight; } else { screenHeight = (AllocatedWidth * SwitchPanelHeight) / (int)aspectWidth; } int startX = (AllocatedWidth - screenWidth) >> 1; int startY = (AllocatedHeight - screenHeight) >> 1; int endX = startX + screenWidth; int endY = startY + screenHeight; if (_mouseX >= startX && _mouseY >= startY && _mouseX < endX && _mouseY < endY) { int screenMouseX = (int)_mouseX - startX; int screenMouseY = (int)_mouseY - startY; int mX = (screenMouseX * (int)aspectWidth) / screenWidth; int mY = (screenMouseY * SwitchPanelHeight) / screenHeight; TouchPoint currentPoint = new TouchPoint { X = (uint)mX, Y = (uint)mY, // Placeholder values till more data is acquired DiameterX = 10, DiameterY = 10, Angle = 90 }; hasTouch = true; Device.Hid.Touchscreen.Update(currentPoint); } } if (!hasTouch) { Device.Hid.Touchscreen.Update(); } Device.Hid.DebugPad.Update(); return(true); }
protected override void Dispose(bool disposing) { Device.DisposeGpu(); NpadManager.Dispose(); }
private bool UpdateFrame() { if (!_isActive) { return(true); } if (_isStopped) { return(false); } if ((Toplevel as MainWindow).IsFocused) { Application.Invoke(delegate { KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot(); HandleScreenState(keyboard); if (keyboard.IsPressed(Key.Delete)) { if (!ParentWindow.State.HasFlag(WindowState.Fullscreen)) { Ptc.Continue(); } } }); } NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); if ((Toplevel as MainWindow).IsFocused) { KeyboardHotkeyState currentHotkeyState = GetHotkeyState(); if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync)) { Device.EnableDeviceVsync = !Device.EnableDeviceVsync; } if ((currentHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot) && !_prevHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot)) || ScreenshotRequested) { ScreenshotRequested = false; Renderer.Screenshot(); } _prevHotkeyState = currentHotkeyState; } // Touchscreen bool hasTouch = false; // Get screen touch position if ((Toplevel as MainWindow).IsFocused && !ConfigurationState.Instance.Hid.EnableMouse) { hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as GTK3MouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat()); } if (!hasTouch) { TouchScreenManager.Update(false); } Device.Hid.DebugPad.Update(); return(true); }