/// <summary> /// Init this instance. /// Callbacks are here initialized for the events. /// </summary> private void Init() { SizeChangedCallback = (IntPtr _handle, int width, int height) => { SizeChanged.Invoke(this, new SizeChangedEventArgs { source = this, width = width, height = height }); }; Glfw.SetWindowSizeCallback(this, SizeChangedCallback); KeyPressedCallback = (IntPtr _handle, int key, int scancode, int action, int mods) => { var args = new KeyEventArgs { source = this, key = (Key)System.Enum.Parse(typeof(Key), key.ToString()), action = (State)System.Enum.Parse(typeof(State), action.ToString()), scancode = scancode, mods = mods }; KeyChanged.Invoke(this, args); }; Glfw.SetKeyCallback(this, KeyPressedCallback); // Add dummy handlers to prevent any null reference exceptions SizeChanged = new EventHandler <SizeChangedEventArgs>((__, _) => { }); KeyChanged = new EventHandler <KeyEventArgs>((__, _) => { }); }
private void InvokeSizeChanged() { if (SizeChanged != null) { SizeChanged.Invoke(this, EventArgs.Empty); } }
protected virtual void OnSizeChanged() { TextureValid = false; if (SizeChanged != null) { SizeChanged.Invoke(this, EventArgs.Empty); } }
void OnSizeChanged() { SizeChanged?.Invoke(this, EventArgs.Empty); }
public override void EnterMessageLoop(bool runInBackground) { IntPtr e = System.Runtime.InteropServices.Marshal.AllocHGlobal(24 * sizeof(long)); bool running = true; while (running) { while (XPending(_display) != 0) { XNextEvent(_display, e); if (XFilterEvent(e, IntPtr.Zero)) { continue; } XAnyEvent anyEvent = (XAnyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XAnyEvent)); switch ((Event)anyEvent.type) { case Event.ClientMessage: { running = false; break; } case Event.ConfigureNotify: { XConfigureEvent configureEvent = (XConfigureEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XConfigureEvent)); LocationChanged?.Invoke(this, configureEvent.x, configureEvent.y); SizeChanged?.Invoke(this, configureEvent.width, configureEvent.height); break; } case Event.FocusIn: { Activated?.Invoke(this); break; } case Event.FocusOut: { Deactivated?.Invoke(this); break; } case Event.MotionNotify: { XMotionEvent motionEvent = (XMotionEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XMotionEvent)); MouseMove?.Invoke(this, motionEvent.x, motionEvent.y); break; } case Event.ButtonPress: { XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent)); switch ((Button)buttonEvent.button) { case Button.Button1: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left); break; } case Button.Button2: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle); break; } case Button.Button3: { MouseButtonDown?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right); break; } case Button.Button4: { MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, 120); break; } case Button.Button5: { MouseWheel?.Invoke(this, buttonEvent.x, buttonEvent.y, -120); break; } } break; } case Event.ButtonRelease: { XButtonEvent buttonEvent = (XButtonEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XButtonEvent)); switch ((Button)buttonEvent.button) { case Button.Button1: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Left); break; } case Button.Button2: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Middle); break; } case Button.Button3: { MouseButtonUp?.Invoke(this, buttonEvent.x, buttonEvent.y, MouseButton.Right); break; } } break; } case Event.KeyPress: { XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent)); KeySym ks = XLookupKeysym(ref keyEvent, 0); Key key = NoesisKey(ks); if (key != Key.None) { KeyDown?.Invoke(this, key); } if (_xic != IntPtr.Zero) { Status status = 0; byte[] buffer = new byte[256]; KeySym ret_ks = (KeySym)0; int size = Xutf8LookupString(_xic, e, buffer, 255, ref ret_ks, ref status); if (size > 0 && ((int)status == XLookupChars || (int)status == XLookupBoth)) { buffer[size] = 0; Decoder decoder = _utf8.GetDecoder(); char[] text = new char[256]; int bytesUsed = 0; int charsUsed = 0; bool completed = false; decoder.Convert(buffer, 0, size, text, 0, 255, true, out bytesUsed, out charsUsed, out completed); for (int i = 0; i < charsUsed; ++i) { Char?.Invoke(this, text[i]); } } } break; } case Event.KeyRelease: { XKeyEvent keyEvent = (XKeyEvent)System.Runtime.InteropServices.Marshal.PtrToStructure(e, typeof(XKeyEvent)); KeySym ks = XLookupKeysym(ref keyEvent, 0); Key key = NoesisKey(ks); if (key != Key.None) { KeyUp?.Invoke(this, key); } break; } } } Render?.Invoke(this); } System.Runtime.InteropServices.Marshal.FreeHGlobal(e); }
public void OnSizeChanged(SizeEventArgs e) { SizeChanged?.Invoke(this, e); }
protected override void OnLayoutCore(bool changed, int left, int top, int right, int bottom) { base.OnLayoutCore(changed, left, top, right, bottom); Size newSize; if (ArrangeLogicalSize is Rect als) { // If the parent element is from managed code, // we can recover the "Arrange" with double accuracy. // We use that because the conversion to android's "int" is loosing too much precision. newSize = new Size(als.Width, als.Height); } else { // Here the "arrange" is coming from a native element, // so we convert those measurements to logical ones. newSize = new Size(right - left, bottom - top).PhysicalToLogicalPixels(); } if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().DebugFormat( "[{0}/{1}] OnLayoutCore({2}, {3}, {4}, {5}) (parent: {5},{6})", GetType(), Name, left, top, right, bottom, MeasuredWidth, MeasuredHeight ); } var previousSize = _actualSize; _actualSize = newSize; if ( // If the layout has changed, but the final size has not, this is just a translation. // So unless there was a layout requested, we can skip arranging the children. (changed && _lastLayoutSize != newSize) // Even if nothing changed, but a layout was requested, arrange the children. || IsLayoutRequested ) { _lastLayoutSize = newSize; var finalRect = new Rect(0, 0, newSize.Width, newSize.Height); OnBeforeArrange(); _layouter.Arrange(finalRect); OnAfterArrange(); } if (previousSize != newSize) { SizeChanged?.Invoke(this, new SizeChangedEventArgs(this, previousSize, newSize)); _renderTransform?.UpdateSize(newSize); } }
public void OnSizeChanged(int Width, int Height) { SizeChanged?.Invoke(this, Width, Height); }
public static Task <bool> UpdateWindowSize(int width, int height) { SizeChanged?.Invoke(null, new Rectangle(0, 0, width, height)); return(Task.FromResult(true)); }
/// <summary> /// To be called by view /// </summary> public async Task SetSize(TerminalSize size) { await _trayProcessCommunicationService.ResizeTerminal(Id, size); SizeChanged?.Invoke(this, size); }
protected void OnSizeChanged() { SizeChanged?.Invoke(this, _EventCache); }
private void Provider_SizeChanged(object sender, SizeChangedEventArgs e) => SizeChanged?.Invoke(this, e);
private void OnSizeChanged() => SizeChanged?.Invoke(this, EventArgs.Empty);
public override void Show() { SizeChanged?.Invoke(this, ClientWidth, ClientHeight); LocationChanged?.Invoke(this, 0, 0); Window.MakeKeyAndVisible(); }
/// <summary> /// Raises the <see cref="SizeChanged"/> event. /// </summary> protected virtual void OnSizeChanged(Window sender) => SizeChanged?.Invoke(sender);
protected void RecalculateRelativeSize() { relativeSize = new Vector2(NonScaledSize.X, NonScaledSize.Y) / new Vector2(NonScaledParentRect.Width, NonScaledParentRect.Height); recalculateRect = true; SizeChanged?.Invoke(); }
protected void RecalculateAbsoluteSize() { nonScaledSize = NonScaledParentRect.Size.Multiply(RelativeSize).Clamp(MinSize, MaxSize); recalculateRect = true; SizeChanged?.Invoke(); }
internal void RaiseSizeChanged(SizeChangedEventArgs args) { SizeChanged?.Invoke(this, args); _renderTransform?.UpdateSize(args.NewSize); }
protected override void OnResized(Vector2D <int> size) { graphicsDevice.SetViewport(0, 0, (uint)size.X, (uint)size.Y); SizeChanged?.Invoke(this, EventArgs.Empty); }
private void FireSizeChanged() { SizeChanged.Invoke(this); }
/// <summary> /// To be called by view /// </summary> public async Task SetSizeAsync(TerminalSize size) { await _trayProcessCommunicationService.ResizeTerminalAsync(Id, size).ConfigureAwait(false); SizeChanged?.Invoke(this, size); }
private void PositionChange(object sender, System.ComponentModel.PropertyChangedEventArgs e) { switch (e.PropertyName) { case "Size": if (ScaleReference == Vector2i.Zero) { ScaleReference = Size; } SizeChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "ScaleWithParent": case "ScaleSize": SizeChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "ScalePosition": case "Origin": case "Anchor": case "Position": PositionChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "RotationCenter": case "Rotation": RotationChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "CustomOrigin": if (Origin != Anchor.Custom) { return; } PositionChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "CustomAnchor": if (Anchor != Anchor.Custom) { return; } PositionChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "RotationCustomCenter": if (RotationCenter != Anchor.Custom) { return; } RotationChanged?.Invoke(this, EventArgs.Empty); goto case "InvalidateMatrix"; case "InvalidateMatrix": if (State == ResourceState.NotLoaded) { return; } Invalidate("Transformation", InvalidationDirection.Children); Invalidate("Graphics", InvalidationDirection.Both); break; } }
private void FireSizeChanged() { SizeChanged?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Occurs when size changed /// </summary> /// <param name="size"></param> protected virtual void OnSizeChanged(Size size) { SizeChanged?.Invoke(this, size); OnLookChanged(new EventArgs()); }
internal void RaiseSizeChanged(SizeChangedEventArgs args) { SizeChanged?.Invoke(this, args); }
public override void SetFrameSize(CGSize newSize) { base.SetFrameSize(newSize); NeedsNewContext = true; SizeChanged?.Invoke(this, EventArgs.Empty); }
protected virtual IntPtr WndProc(IntPtr hWnd, uint message, IntPtr wParam, IntPtr lParam) { WM msg = (WM)message; switch (msg) { case WM.HOTKEY: { if (wParam == (IntPtr)1) { PostMessage(_handle, (uint)WM.CLOSE, IntPtr.Zero, IntPtr.Zero); return(IntPtr.Zero); } break; } case WM.SYSKEYDOWN: { if (_options.KioskMode && (wParam == (IntPtr)Keyboard.VirtualKeyStates.VK_F4)) { return(IntPtr.Zero); } break; } case WM.CREATE: { NativeInstance = this; _handle = hWnd; var createdEvent = new CreatedEventArgs(IntPtr.Zero, _handle, _handle); Created?.Invoke(this, createdEvent); _isInitialized = true; break; } case WM.ERASEBKGND: return(new IntPtr(1)); case WM.NCHITTEST: if (_options.WindowFrameless) { return((IntPtr)HT_CAPTION); } break; case WM.MOVING: case WM.MOVE: { Moving?.Invoke(this, new MovingEventArgs()); return(IntPtr.Zero); } case WM.SIZE: { var size = GetClientSize(); SizeChanged?.Invoke(this, new SizeChangedEventArgs(size.Width, size.Height)); break; } case WM.CLOSE: { if (_handle != IntPtr.Zero && _isInitialized) { Close?.Invoke(this, new CloseEventArgs()); } PostQuitMessage(0); Environment.Exit(0); break; } } return(DefWindowProc(hWnd, message, wParam, lParam)); }
private void SizeChangedCommand_Execute() { SizeChanged?.Invoke(); }
protected virtual void OnSizeChanged() { SizeChanged?.Invoke(this, EventArgs.Empty); }
public WindowsNativeConsoleProvider() { _threadToken = new CancellationTokenSource(); _buffer = (CHAR_INFO *)Marshal.AllocHGlobal(BufferSize * BufferSize * CHAR_INFO.SizeOf).ToPointer(); _buffer2 = (CHAR_INFO *)Marshal.AllocHGlobal(BufferSize * BufferSize * CHAR_INFO.SizeOf).ToPointer(); _stdin = GetStdHandle(-10); _stdout = GetStdHandle(-11); { var info = new CONSOLE_SCREEN_BUFFER_INFO(); GetConsoleScreenBufferInfo(_stdout, ref info); WindowWidth = info.Window.Right - info.Window.Left + 1; WindowHeight = info.Window.Bottom - info.Window.Top + 1; _prevBuf = info.Size; SetConsoleScreenBufferSize(_stdout, new COORD { X = (short)WindowWidth, Y = (short)WindowHeight }); } new Thread(() => // window size monitor { while (!_threadToken.IsCancellationRequested) { Thread.Sleep(16); var info = new CONSOLE_SCREEN_BUFFER_INFO(); GetConsoleScreenBufferInfo(_stdout, ref info); int nw = info.Window.Right - info.Window.Left + 1, nh = info.Window.Bottom - info.Window.Top + 1; if (nw < 0) { nw = WindowWidth; } if (nh < 0) { nh = WindowHeight; // fukken winapi bugs } if (nw == WindowWidth && nh == WindowHeight) { continue; } var pw = WindowWidth; var ph = WindowHeight; _resizeFlag = true; WindowWidth = nw; WindowHeight = nh; SetConsoleScreenBufferSize(_stdout, new COORD { X = (short)WindowWidth, Y = (short)WindowHeight }); try { SizeChanged?.Invoke(this, new SizeChangedEventArgs(new Size(pw, ph), new Size(nw, nh))); } catch { /* Do not care if subscriber f****d up */ } //Refresh(); } }) { Priority = ThreadPriority.Lowest }.Start(); _keyboardThread = new Thread(() => // keyboard monitor { INPUT_RECORD *charBuf = stackalloc INPUT_RECORD[1]; var ptr = new IntPtr(charBuf); var sizeOf = Marshal.SizeOf(typeof(INPUT_RECORD)); while (!_threadToken.IsCancellationRequested) { try { uint nchars = 0; Memset(ptr, 0, sizeOf); ReadConsoleInputW(_stdin, ptr, 1, ref nchars); if (charBuf->EventType == 1 && nchars == 1 && charBuf->KeyEvent.KeyDown) { KeyPressed?.Invoke( this, new KeyPressedEventArgs(new ConsoleKeyInfo( charBuf->KeyEvent.Char, (ConsoleKey)charBuf->KeyEvent.KeyCode, (charBuf->KeyEvent.ControlKeyState & 0x10) > 0, (charBuf->KeyEvent.ControlKeyState & 0x03) > 0, (charBuf->KeyEvent.ControlKeyState & 0x0c) > 0 ))); } } catch { } } }); _keyboardThread.Start(); }