/// <summary> /// Fired by the Activated event. /// </summary> /// <param name="sender">Sender object.</param> /// <param name="e">Event arguments.</param> protected virtual void OnActivated(object sender, EventArgs e) { Activated?.Invoke(this, null); AudioManager.Instance.PlaySound("Interface/click"); }
static void Form_Activated(object sender, EventArgs e) { Activated?.Invoke((Form)sender); }
protected void OnActivated(object sender, EventArgs args) { Activated?.Invoke(this, EventArgs.Empty); }
internal virtual void ItemActivate(UIMenu sender) { Activated?.Invoke(sender, this); }
private void OnActivated() { this.LatestActiveTime = CurrentTimeRough; Activated?.Invoke(this); }
protected void OnActivated() { Activated?.Invoke(this, EventArgs.Empty); }
public void Activate() { Dispatcher.UIThread.Post(() => Activated?.Invoke(), DispatcherPriority.Input); }
protected void OnActivated(object source, EventArgs e) { Activated?.Invoke(this, e); }
public void OnActivated() { Activated?.Invoke(this, EventArgs.Empty); }
public void Activate() { Activated.Raise(this, EventArgs.Empty); }
void OnDisplayActivated(Display display) { _view?.Activate(); Activated?.Invoke(this, System.EventArgs.Empty); }
protected void RaiseActivated() { using (Context.Activate().Scoped()) { Activated?.Invoke(); } }
/// <summary> /// Raises the <see cref="Activated"/> event. /// Override this method to add code to handle when the application gains focus. /// </summary> /// <param name="sender">The application.</param> protected virtual void OnActivated(Game sender) { Activated?.Invoke(sender); }
/// <summary> /// Called when mode gets activated. /// </summary> public virtual void OnActivated() { Activated?.Invoke(); }
private void OnActivated() { Activated?.Invoke(this, new EventArgs()); }
public DecisionOptionsHistory(IEnumerable <DecisionOption> matched, IEnumerable <DecisionOption> activated) : base() { Matched.AddRange(matched); Activated.AddRange(activated); }
public override void OnGripped(HandGrip gripper, Vector3 velocity) { Activated?.Invoke(this); }
private void OnActivated(EventArgs e) { Activated?.Invoke(this, e); }
protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd); const double wheelDelta = 120.0; uint timestamp = unchecked ((uint)UnmanagedMethods.GetMessageTime()); RawInputEventArgs e = null; WindowsMouseDevice.Instance.CurrentWindow = this; switch ((UnmanagedMethods.WindowsMessage)msg) { case UnmanagedMethods.WindowsMessage.WM_ACTIVATE: var wa = (UnmanagedMethods.WindowActivate)(ToInt32(wParam) & 0xffff); switch (wa) { case UnmanagedMethods.WindowActivate.WA_ACTIVE: case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE: Activated?.Invoke(); break; case UnmanagedMethods.WindowActivate.WA_INACTIVE: Deactivated?.Invoke(); break; } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_CLOSE: bool?preventClosing = Closing?.Invoke(); if (preventClosing == true) { return(IntPtr.Zero); } break; case UnmanagedMethods.WindowsMessage.WM_DESTROY: //Window doesn't exist anymore _hwnd = IntPtr.Zero; //Remove root reference to this class, so unmanaged delegate can be collected s_instances.Remove(this); Closed?.Invoke(); //Free other resources Dispose(); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DPICHANGED: var dpi = ToInt32(wParam) & 0xffff; var newDisplayRect = Marshal.PtrToStructure <UnmanagedMethods.RECT>(lParam); Position = new Point(newDisplayRect.left, newDisplayRect.top); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_KEYDOWN: case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_KEYUP: case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_CHAR: // Ignore control chars if (ToInt32(wParam) >= 32) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, new string((char)ToInt32(wParam), 1)); } break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN ? RawMouseEventType.LeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN ? RawMouseEventType.RightButtonDown : RawMouseEventType.MiddleButtonDown, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP ? RawMouseEventType.LeftButtonUp : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP ? RawMouseEventType.RightButtonUp : RawMouseEventType.MiddleButtonUp, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: if (!_trackingMouse) { var tm = new UnmanagedMethods.TRACKMOUSEEVENT { cbSize = Marshal.SizeOf <UnmanagedMethods.TRACKMOUSEEVENT>(), dwFlags = 2, hwndTrack = _hwnd, dwHoverTime = 0, }; UnmanagedMethods.TrackMouseEvent(ref tm); } e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawMouseEventType.Move, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL: e = new RawMouseWheelEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, PointToClient(PointFromLParam(lParam)), new Vector(0, (ToInt32(wParam) >> 16) / wheelDelta), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL: e = new RawMouseWheelEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, PointToClient(PointFromLParam(lParam)), new Vector(-(ToInt32(wParam) >> 16) / wheelDelta, 0), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE: _trackingMouse = false; e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawMouseEventType.LeaveWindow, new Point(), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN ? RawMouseEventType.NonClientLeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN ? RawMouseEventType.RightButtonDown : RawMouseEventType.MiddleButtonDown, new Point(0, 0), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_PAINT: UnmanagedMethods.PAINTSTRUCT ps; if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero) { var f = Scaling; var r = ps.rcPaint; Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f)); UnmanagedMethods.EndPaint(_hwnd, ref ps); } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_SIZE: if (Resized != null && (wParam == (IntPtr)UnmanagedMethods.SizeCommand.Restored || wParam == (IntPtr)UnmanagedMethods.SizeCommand.Maximized)) { var clientSize = new Size(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16); Resized(clientSize / Scaling); } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_MOVE: PositionChanged?.Invoke(new Point((short)(ToInt32(lParam) & 0xffff), (short)(ToInt32(lParam) >> 16))); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_GETMINMAXINFO: MINMAXINFO mmi = Marshal.PtrToStructure <UnmanagedMethods.MINMAXINFO>(lParam); if (_minSize.Width > 0) { mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); } if (_minSize.Height > 0) { mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); } if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0) { mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); } if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0) { mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); } Marshal.StructureToPtr(mmi, lParam, true); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DISPLAYCHANGE: (Screen as ScreenImpl)?.InvalidateScreensCache(); return(IntPtr.Zero); } #if USE_MANAGED_DRAG if (_managedDrag.PreprocessInputEvent(ref e)) { return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam)); } #endif if (e != null && Input != null) { Input(e); if (e.Handled) { return(IntPtr.Zero); } } return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam)); }
protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { const double wheelDelta = 120.0; const long UiaRootObjectId = -25; uint timestamp = unchecked ((uint)GetMessageTime()); RawInputEventArgs e = null; var shouldTakeFocus = false; var message = (WindowsMessage)msg; switch (message) { case WindowsMessage.WM_ACTIVATE: { var wa = (WindowActivate)(ToInt32(wParam) & 0xffff); switch (wa) { case WindowActivate.WA_ACTIVE: case WindowActivate.WA_CLICKACTIVE: { Activated?.Invoke(); UpdateInputMethod(GetKeyboardLayout(0)); break; } case WindowActivate.WA_INACTIVE: { Deactivated?.Invoke(); break; } } return(IntPtr.Zero); } case WindowsMessage.WM_NCCALCSIZE: { if (ToInt32(wParam) == 1 && !HasFullDecorations || _isClientAreaExtended) { return(IntPtr.Zero); } break; } case WindowsMessage.WM_CLOSE: { bool?preventClosing = Closing?.Invoke(); if (preventClosing == true) { return(IntPtr.Zero); } BeforeCloseCleanup(false); // Used to distinguish between programmatic and regular close requests. _isCloseRequested = true; break; } case WindowsMessage.WM_DESTROY: { UiaCoreProviderApi.UiaReturnRawElementProvider(_hwnd, IntPtr.Zero, IntPtr.Zero, null); // We need to release IMM context and state to avoid leaks. if (Imm32InputMethod.Current.HWND == _hwnd) { Imm32InputMethod.Current.ClearLanguageAndWindow(); } //Window doesn't exist anymore _hwnd = IntPtr.Zero; //Remove root reference to this class, so unmanaged delegate can be collected s_instances.Remove(this); Closed?.Invoke(); _mouseDevice.Dispose(); _touchDevice?.Dispose(); //Free other resources Dispose(); return(IntPtr.Zero); } case WindowsMessage.WM_DPICHANGED: { var dpi = ToInt32(wParam) & 0xffff; var newDisplayRect = Marshal.PtrToStructure <RECT>(lParam); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); using (SetResizeReason(PlatformResizeReason.DpiChange)) { SetWindowPos(hWnd, IntPtr.Zero, newDisplayRect.left, newDisplayRect.top, newDisplayRect.right - newDisplayRect.left, newDisplayRect.bottom - newDisplayRect.top, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE); } return(IntPtr.Zero); } case WindowsMessage.WM_KEYDOWN: case WindowsMessage.WM_SYSKEYDOWN: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_SYSCOMMAND: // Disable system handling of Alt/F10 menu keys. if ((SysCommands)wParam == SysCommands.SC_KEYMENU && HighWord(ToInt32(lParam)) <= 0) { return(IntPtr.Zero); } break; case WindowsMessage.WM_MENUCHAR: { // mute the system beep return((IntPtr)((int)MenuCharParam.MNC_CLOSE << 16)); } case WindowsMessage.WM_KEYUP: case WindowsMessage.WM_SYSKEYUP: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_CHAR: { // Ignore control chars and chars that were handled in WM_KEYDOWN. if (ToInt32(wParam) >= 32 && !_ignoreWmChar) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner, new string((char)ToInt32(wParam), 1)); } break; } case WindowsMessage.WM_LBUTTONDOWN: case WindowsMessage.WM_RBUTTONDOWN: case WindowsMessage.WM_MBUTTONDOWN: case WindowsMessage.WM_XBUTTONDOWN: { if (IsMouseInPointerEnabled) { break; } shouldTakeFocus = ShouldTakeFocusOnClick; if (ShouldIgnoreTouchEmulatedMessage()) { break; } e = new RawPointerEventArgs( _mouseDevice, timestamp, _owner, message switch { WindowsMessage.WM_LBUTTONDOWN => RawPointerEventType.LeftButtonDown, WindowsMessage.WM_RBUTTONDOWN => RawPointerEventType.RightButtonDown, WindowsMessage.WM_MBUTTONDOWN => RawPointerEventType.MiddleButtonDown, WindowsMessage.WM_XBUTTONDOWN => HighWord(ToInt32(wParam)) == 1 ? RawPointerEventType.XButton1Down : RawPointerEventType.XButton2Down }, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; }
/// <summary> /// /// </summary> internal void UpdateInternal() { /*if (skipFirstFrame) { * skipFirstFrame = false; * Thread.Sleep(1); * return; * } */ if (IsDisposed) { throw new ObjectDisposedException("Game"); } if (!IsInitialized) { throw new InvalidOperationException("Game is not initialized"); } bool isActive = IsActive; // to reduce access to winforms. if (isActive != isActiveLastFrame) { isActiveLastFrame = isActive; if (isActive) { Activated?.Invoke(this, EventArgs.Empty); } else { Deactivated?.Invoke(this, EventArgs.Empty); } } if (Enabled) { if (requestFullscreenOnStartup) { graphicsDevice.FullScreen = requestFullscreenOnStartup; requestFullscreenOnStartup = false; } if (requestReload) { Reloading?.Invoke(this, EventArgs.Empty); requestReload = false; } graphicsDevice.Prepare(); graphicsDevice.Display.Prepare(); // pre update : gameTimeInternal.Update(); InputDevice.UpdateInput(); Frames.Update(gameTimeInternal); Console.Update(gameTimeInternal); //GIS.Update(gameTimeInternal); UpdateClientServerGame(gameTimeInternal); // // Sound : // SoundSystem.Update(gameTimeInternal); // // Render : // var eyeList = graphicsDevice.Display.StereoEyeList; foreach (var eye in eyeList) { GraphicsDevice.ResetStates(); GraphicsDevice.Display.TargetEye = eye; GraphicsDevice.RestoreBackbuffer(); GraphicsDevice.ClearBackbuffer(Color.Zero); this.Draw(gameTimeInternal, eye); } GraphicsDevice.Present(RenderSystem.VSyncInterval); InputDevice.EndUpdateInput(); } try { invoker.ExecuteQueue(gameTimeInternal, CommandAffinity.Default); } catch (Exception e) { Log.Error(e.Message); } CheckExitInternal(); }
protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd); const double wheelDelta = 120.0; uint timestamp = unchecked ((uint)UnmanagedMethods.GetMessageTime()); RawInputEventArgs e = null; WindowsMouseDevice.Instance.CurrentWindow = this; switch ((UnmanagedMethods.WindowsMessage)msg) { case UnmanagedMethods.WindowsMessage.WM_ACTIVATE: var wa = (UnmanagedMethods.WindowActivate)((int)wParam & 0xffff); switch (wa) { case UnmanagedMethods.WindowActivate.WA_ACTIVE: case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE: _isActive = true; Activated?.Invoke(); break; case UnmanagedMethods.WindowActivate.WA_INACTIVE: _isActive = false; Deactivated?.Invoke(); break; } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DESTROY: if (Closed != null) { UnmanagedMethods.UnregisterClass(_className, Marshal.GetHINSTANCE(GetType().Module)); Closed(); } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DPICHANGED: var dpi = (int)wParam & 0xffff; var newDisplayRect = (UnmanagedMethods.RECT)Marshal.PtrToStructure(lParam, typeof(UnmanagedMethods.RECT)); Position = new Point(newDisplayRect.left, newDisplayRect.top); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_KEYDOWN: case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey((int)wParam), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_KEYUP: case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey((int)wParam), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_CHAR: // Ignore control chars if (wParam.ToInt32() >= 32) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, new string((char)wParam.ToInt32(), 1)); } break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN ? RawMouseEventType.LeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN ? RawMouseEventType.RightButtonDown : RawMouseEventType.MiddleButtonDown, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP ? RawMouseEventType.LeftButtonUp : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP ? RawMouseEventType.RightButtonUp : RawMouseEventType.MiddleButtonUp, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: if (!_trackingMouse) { var tm = new UnmanagedMethods.TRACKMOUSEEVENT { cbSize = Marshal.SizeOf(typeof(UnmanagedMethods.TRACKMOUSEEVENT)), dwFlags = 2, hwndTrack = _hwnd, dwHoverTime = 0, }; UnmanagedMethods.TrackMouseEvent(ref tm); } e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawMouseEventType.Move, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL: e = new RawMouseWheelEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, ScreenToClient(DipFromLParam(lParam)), new Vector(0, ((int)wParam >> 16) / wheelDelta), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE: _trackingMouse = false; e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawMouseEventType.LeaveWindow, new Point(), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN: e = new RawMouseEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN ? RawMouseEventType.NonClientLeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN ? RawMouseEventType.RightButtonDown : RawMouseEventType.MiddleButtonDown, new Point(0, 0), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_PAINT: if (Paint != null) { UnmanagedMethods.PAINTSTRUCT ps; if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero) { UnmanagedMethods.RECT r; UnmanagedMethods.GetUpdateRect(_hwnd, out r, false); var f = Scaling; Paint(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f)); UnmanagedMethods.EndPaint(_hwnd, ref ps); } } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_SIZE: if (Resized != null) { var clientSize = new Size((int)lParam & 0xffff, (int)lParam >> 16); Resized(clientSize / Scaling); } return(IntPtr.Zero); } if (e != null && Input != null) { Input(e); if (e.Handled) { return(IntPtr.Zero); } } return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam)); }
public virtual void Activate() { Activated?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Raises the <see cref="Activated"/> event. /// </summary> /// <param name="eventArgs"> /// <see cref="ActivationEventArgs"/> object that provides the arguments for the event. /// </param> /// <remarks> /// <strong>Notes to Inheritors:</strong> When overriding <see cref="OnActivated"/> in a /// derived class, be sure to call the base class's <see cref="OnActivated"/> method so that /// registered delegates receive the event. /// </remarks> protected virtual void OnActivated(ActivationEventArgs eventArgs) { Activated?.Invoke(this, eventArgs); }
/// <summary> /// Raises the Activated event. Override this method to add code to handle when the game gains focus. /// </summary> /// <param name="sender">The Game.</param> /// <param name="args">Arguments for the Activated event.</param> protected virtual void OnActivated(object sender, EventArgs args) { Activated?.Invoke(this, args); }
protected virtual unsafe IntPtr AppWndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { const double wheelDelta = 120.0; uint timestamp = unchecked ((uint)GetMessageTime()); RawInputEventArgs e = null; var shouldTakeFocus = false; switch ((WindowsMessage)msg) { case WindowsMessage.WM_ACTIVATE: { var wa = (WindowActivate)(ToInt32(wParam) & 0xffff); switch (wa) { case WindowActivate.WA_ACTIVE: case WindowActivate.WA_CLICKACTIVE: { Activated?.Invoke(); break; } case WindowActivate.WA_INACTIVE: { Deactivated?.Invoke(); break; } } return(IntPtr.Zero); } case WindowsMessage.WM_NCCALCSIZE: { if (ToInt32(wParam) == 1 && !HasFullDecorations || _isClientAreaExtended) { return(IntPtr.Zero); } break; } case WindowsMessage.WM_CLOSE: { bool?preventClosing = Closing?.Invoke(); if (preventClosing == true) { return(IntPtr.Zero); } BeforeCloseCleanup(false); // Used to distinguish between programmatic and regular close requests. _isCloseRequested = true; break; } case WindowsMessage.WM_DESTROY: { //Window doesn't exist anymore _hwnd = IntPtr.Zero; //Remove root reference to this class, so unmanaged delegate can be collected s_instances.Remove(this); Closed?.Invoke(); _mouseDevice.Dispose(); _touchDevice?.Dispose(); //Free other resources Dispose(); return(IntPtr.Zero); } case WindowsMessage.WM_DPICHANGED: { var dpi = ToInt32(wParam) & 0xffff; var newDisplayRect = Marshal.PtrToStructure <RECT>(lParam); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); SetWindowPos(hWnd, IntPtr.Zero, newDisplayRect.left, newDisplayRect.top, newDisplayRect.right - newDisplayRect.left, newDisplayRect.bottom - newDisplayRect.top, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE); return(IntPtr.Zero); } case WindowsMessage.WM_KEYDOWN: case WindowsMessage.WM_SYSKEYDOWN: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_MENUCHAR: { // mute the system beep return((IntPtr)((int)MenuCharParam.MNC_CLOSE << 16)); } case WindowsMessage.WM_KEYUP: case WindowsMessage.WM_SYSKEYUP: { e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, _owner, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), WindowsKeyboardDevice.Instance.Modifiers); break; } case WindowsMessage.WM_CHAR: { // Ignore control chars if (ToInt32(wParam) >= 32) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, _owner, new string((char)ToInt32(wParam), 1)); } break; } case WindowsMessage.WM_LBUTTONDOWN: case WindowsMessage.WM_RBUTTONDOWN: case WindowsMessage.WM_MBUTTONDOWN: case WindowsMessage.WM_XBUTTONDOWN: { shouldTakeFocus = ShouldTakeFocusOnClick; if (ShouldIgnoreTouchEmulatedMessage()) { break; } e = new RawPointerEventArgs( _mouseDevice, timestamp, _owner, (WindowsMessage)msg switch { WindowsMessage.WM_LBUTTONDOWN => RawPointerEventType.LeftButtonDown, WindowsMessage.WM_RBUTTONDOWN => RawPointerEventType.RightButtonDown, WindowsMessage.WM_MBUTTONDOWN => RawPointerEventType.MiddleButtonDown, WindowsMessage.WM_XBUTTONDOWN => HighWord(ToInt32(wParam)) == 1 ? RawPointerEventType.XButton1Down : RawPointerEventType.XButton2Down }, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; }
protected void OnActivated(EventArgs e) { Activated?.Invoke(this, e); }
protected virtual IntPtr WndProc(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) { bool unicode = UnmanagedMethods.IsWindowUnicode(hWnd); const double wheelDelta = 120.0; uint timestamp = unchecked ((uint)UnmanagedMethods.GetMessageTime()); RawInputEventArgs e = null; WindowsMouseDevice.Instance.CurrentWindow = this; switch ((UnmanagedMethods.WindowsMessage)msg) { case UnmanagedMethods.WindowsMessage.WM_ACTIVATE: var wa = (UnmanagedMethods.WindowActivate)(ToInt32(wParam) & 0xffff); switch (wa) { case UnmanagedMethods.WindowActivate.WA_ACTIVE: case UnmanagedMethods.WindowActivate.WA_CLICKACTIVE: Activated?.Invoke(); break; case UnmanagedMethods.WindowActivate.WA_INACTIVE: Deactivated?.Invoke(); break; } return(IntPtr.Zero); case WindowsMessage.WM_NCCALCSIZE: if (ToInt32(wParam) == 1 && !_decorated) { return(IntPtr.Zero); } break; case UnmanagedMethods.WindowsMessage.WM_CLOSE: bool?preventClosing = Closing?.Invoke(); if (preventClosing == true) { return(IntPtr.Zero); } break; case UnmanagedMethods.WindowsMessage.WM_DESTROY: //Window doesn't exist anymore _hwnd = IntPtr.Zero; //Remove root reference to this class, so unmanaged delegate can be collected s_instances.Remove(this); Closed?.Invoke(); if (_parent != null) { _parent._disabledBy.Remove(this); _parent.UpdateEnabled(); } //Free other resources Dispose(); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DPICHANGED: var dpi = ToInt32(wParam) & 0xffff; var newDisplayRect = Marshal.PtrToStructure <UnmanagedMethods.RECT>(lParam); _scaling = dpi / 96.0; ScalingChanged?.Invoke(_scaling); SetWindowPos(hWnd, IntPtr.Zero, newDisplayRect.left, newDisplayRect.top, newDisplayRect.right - newDisplayRect.left, newDisplayRect.bottom - newDisplayRect.top, SetWindowPosFlags.SWP_NOZORDER | SetWindowPosFlags.SWP_NOACTIVATE); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_KEYDOWN: case UnmanagedMethods.WindowsMessage.WM_SYSKEYDOWN: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyDown, KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_MENUCHAR: // mute the system beep return((IntPtr)((Int32)UnmanagedMethods.MenuCharParam.MNC_CLOSE << 16)); case UnmanagedMethods.WindowsMessage.WM_KEYUP: case UnmanagedMethods.WindowsMessage.WM_SYSKEYUP: e = new RawKeyEventArgs( WindowsKeyboardDevice.Instance, timestamp, RawKeyEventType.KeyUp, KeyInterop.KeyFromVirtualKey(ToInt32(wParam)), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_CHAR: // Ignore control chars if (ToInt32(wParam) >= 32) { e = new RawTextInputEventArgs(WindowsKeyboardDevice.Instance, timestamp, new string((char)ToInt32(wParam), 1)); } break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_MBUTTONDOWN: if (ShouldIgnoreTouchEmulatedMessage()) { break; } e = new RawPointerEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONDOWN ? RawPointerEventType.LeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONDOWN ? RawPointerEventType.RightButtonDown : RawPointerEventType.MiddleButtonDown, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_LBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_RBUTTONUP: case UnmanagedMethods.WindowsMessage.WM_MBUTTONUP: if (ShouldIgnoreTouchEmulatedMessage()) { break; } e = new RawPointerEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_LBUTTONUP ? RawPointerEventType.LeftButtonUp : msg == (int)UnmanagedMethods.WindowsMessage.WM_RBUTTONUP ? RawPointerEventType.RightButtonUp : RawPointerEventType.MiddleButtonUp, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEMOVE: if (ShouldIgnoreTouchEmulatedMessage()) { break; } if (!_trackingMouse) { var tm = new UnmanagedMethods.TRACKMOUSEEVENT { cbSize = Marshal.SizeOf <UnmanagedMethods.TRACKMOUSEEVENT>(), dwFlags = 2, hwndTrack = _hwnd, dwHoverTime = 0, }; UnmanagedMethods.TrackMouseEvent(ref tm); } e = new RawPointerEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawPointerEventType.Move, DipFromLParam(lParam), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEWHEEL: e = new RawMouseWheelEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, PointToClient(PointFromLParam(lParam)), new Vector(0, (ToInt32(wParam) >> 16) / wheelDelta), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSEHWHEEL: e = new RawMouseWheelEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, PointToClient(PointFromLParam(lParam)), new Vector(-(ToInt32(wParam) >> 16) / wheelDelta, 0), GetMouseModifiers(wParam)); break; case UnmanagedMethods.WindowsMessage.WM_MOUSELEAVE: _trackingMouse = false; e = new RawPointerEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, RawPointerEventType.LeaveWindow, new Point(), WindowsKeyboardDevice.Instance.Modifiers); break; case UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN: case UnmanagedMethods.WindowsMessage.WM_NCMBUTTONDOWN: e = new RawPointerEventArgs( WindowsMouseDevice.Instance, timestamp, _owner, msg == (int)UnmanagedMethods.WindowsMessage.WM_NCLBUTTONDOWN ? RawPointerEventType.NonClientLeftButtonDown : msg == (int)UnmanagedMethods.WindowsMessage.WM_NCRBUTTONDOWN ? RawPointerEventType.RightButtonDown : RawPointerEventType.MiddleButtonDown, new Point(0, 0), GetMouseModifiers(wParam)); break; case WindowsMessage.WM_TOUCH: var touchInputs = new TOUCHINPUT[wParam.ToInt32()]; if (GetTouchInputInfo(lParam, (uint)wParam.ToInt32(), touchInputs, Marshal.SizeOf <TOUCHINPUT>())) { foreach (var touchInput in touchInputs) { Input?.Invoke(new RawTouchEventArgs(_touchDevice, touchInput.Time, _owner, touchInput.Flags.HasFlag(TouchInputFlags.TOUCHEVENTF_UP) ? RawPointerEventType.TouchEnd : touchInput.Flags.HasFlag(TouchInputFlags.TOUCHEVENTF_DOWN) ? RawPointerEventType.TouchBegin : RawPointerEventType.TouchUpdate, PointToClient(new PixelPoint(touchInput.X / 100, touchInput.Y / 100)), WindowsKeyboardDevice.Instance.Modifiers, touchInput.Id)); } CloseTouchInputHandle(lParam); return(IntPtr.Zero); } break; case WindowsMessage.WM_NCPAINT: if (!_decorated) { return(IntPtr.Zero); } break; case WindowsMessage.WM_NCACTIVATE: if (!_decorated) { return(new IntPtr(1)); } break; case UnmanagedMethods.WindowsMessage.WM_PAINT: using (_rendererLock.Lock()) { UnmanagedMethods.PAINTSTRUCT ps; if (UnmanagedMethods.BeginPaint(_hwnd, out ps) != IntPtr.Zero) { var f = Scaling; var r = ps.rcPaint; Paint?.Invoke(new Rect(r.left / f, r.top / f, (r.right - r.left) / f, (r.bottom - r.top) / f)); UnmanagedMethods.EndPaint(_hwnd, ref ps); } } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_SIZE: using (_rendererLock.Lock()) { // Do nothing here, just block until the pending frame render is completed on the render thread } var size = (UnmanagedMethods.SizeCommand)wParam; if (Resized != null && (size == UnmanagedMethods.SizeCommand.Restored || size == UnmanagedMethods.SizeCommand.Maximized)) { var clientSize = new Size(ToInt32(lParam) & 0xffff, ToInt32(lParam) >> 16); Resized(clientSize / Scaling); } var windowState = size == SizeCommand.Maximized ? WindowState.Maximized : (size == SizeCommand.Minimized ? WindowState.Minimized : WindowState.Normal); if (windowState != _lastWindowState) { _lastWindowState = windowState; WindowStateChanged?.Invoke(windowState); } return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_MOVE: PositionChanged?.Invoke(new PixelPoint((short)(ToInt32(lParam) & 0xffff), (short)(ToInt32(lParam) >> 16))); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_GETMINMAXINFO: MINMAXINFO mmi = Marshal.PtrToStructure <UnmanagedMethods.MINMAXINFO>(lParam); if (_minSize.Width > 0) { mmi.ptMinTrackSize.X = (int)((_minSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); } if (_minSize.Height > 0) { mmi.ptMinTrackSize.Y = (int)((_minSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); } if (!Double.IsInfinity(_maxSize.Width) && _maxSize.Width > 0) { mmi.ptMaxTrackSize.X = (int)((_maxSize.Width * Scaling) + BorderThickness.Left + BorderThickness.Right); } if (!Double.IsInfinity(_maxSize.Height) && _maxSize.Height > 0) { mmi.ptMaxTrackSize.Y = (int)((_maxSize.Height * Scaling) + BorderThickness.Top + BorderThickness.Bottom); } Marshal.StructureToPtr(mmi, lParam, true); return(IntPtr.Zero); case UnmanagedMethods.WindowsMessage.WM_DISPLAYCHANGE: (Screen as ScreenImpl)?.InvalidateScreensCache(); return(IntPtr.Zero); } #if USE_MANAGED_DRAG if (_managedDrag.PreprocessInputEvent(ref e)) { return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam)); } #endif if (e != null && Input != null) { Input(e); if (e.Handled) { return(IntPtr.Zero); } } using (_rendererLock.Lock()) return(UnmanagedMethods.DefWindowProc(hWnd, msg, wParam, lParam)); }
protected virtual void OnGotFocus(object sender, EventArgs e) { Activated?.Invoke(this, EventArgs.Empty); Enter?.Invoke(this, EventArgs.Empty); }
void Start() { activatedScript = gameObject.GetComponent<Activated>(); }
protected virtual void OnActivated() => m_updateQueue.Enqueue(() => Activated?.Invoke());