コード例 #1
0
ファイル: GLFW3_Wrapper.cs プロジェクト: masums/GLFW3.NET
 /// <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>((__, _) => { });
 }
コード例 #2
0
 private void InvokeSizeChanged()
 {
     if (SizeChanged != null)
     {
         SizeChanged.Invoke(this, EventArgs.Empty);
     }
 }
コード例 #3
0
        protected virtual void OnSizeChanged()
        {
            TextureValid = false;

            if (SizeChanged != null)
            {
                SizeChanged.Invoke(this, EventArgs.Empty);
            }
        }
コード例 #4
0
 void OnSizeChanged()
 {
     SizeChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #5
0
        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);
        }
コード例 #6
0
ファイル: Shape.cs プロジェクト: NC5324/graphic-editor
 public void OnSizeChanged(SizeEventArgs e)
 {
     SizeChanged?.Invoke(this, e);
 }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
 public void OnSizeChanged(int Width, int Height)
 {
     SizeChanged?.Invoke(this, Width, Height);
 }
コード例 #9
0
 public static Task <bool> UpdateWindowSize(int width, int height)
 {
     SizeChanged?.Invoke(null, new Rectangle(0, 0, width, height));
     return(Task.FromResult(true));
 }
コード例 #10
0
        /// <summary>
        /// To be called by view
        /// </summary>
        public async Task SetSize(TerminalSize size)
        {
            await _trayProcessCommunicationService.ResizeTerminal(Id, size);

            SizeChanged?.Invoke(this, size);
        }
コード例 #11
0
 protected void OnSizeChanged()
 {
     SizeChanged?.Invoke(this, _EventCache);
 }
コード例 #12
0
 private void Provider_SizeChanged(object sender, SizeChangedEventArgs e)
 => SizeChanged?.Invoke(this, e);
コード例 #13
0
 private void OnSizeChanged()
 => SizeChanged?.Invoke(this, EventArgs.Empty);
コード例 #14
0
 public override void Show()
 {
     SizeChanged?.Invoke(this, ClientWidth, ClientHeight);
     LocationChanged?.Invoke(this, 0, 0);
     Window.MakeKeyAndVisible();
 }
コード例 #15
0
ファイル: Window.cs プロジェクト: masums/tcdfx
 /// <summary>
 /// Raises the <see cref="SizeChanged"/> event.
 /// </summary>
 protected virtual void OnSizeChanged(Window sender) => SizeChanged?.Invoke(sender);
コード例 #16
0
 protected void RecalculateRelativeSize()
 {
     relativeSize    = new Vector2(NonScaledSize.X, NonScaledSize.Y) / new Vector2(NonScaledParentRect.Width, NonScaledParentRect.Height);
     recalculateRect = true;
     SizeChanged?.Invoke();
 }
コード例 #17
0
 protected void RecalculateAbsoluteSize()
 {
     nonScaledSize   = NonScaledParentRect.Size.Multiply(RelativeSize).Clamp(MinSize, MaxSize);
     recalculateRect = true;
     SizeChanged?.Invoke();
 }
コード例 #18
0
 internal void RaiseSizeChanged(SizeChangedEventArgs args)
 {
     SizeChanged?.Invoke(this, args);
     _renderTransform?.UpdateSize(args.NewSize);
 }
コード例 #19
0
        protected override void OnResized(Vector2D <int> size)
        {
            graphicsDevice.SetViewport(0, 0, (uint)size.X, (uint)size.Y);

            SizeChanged?.Invoke(this, EventArgs.Empty);
        }
コード例 #20
0
 private void FireSizeChanged()
 {
     SizeChanged.Invoke(this);
 }
コード例 #21
0
        /// <summary>
        /// To be called by view
        /// </summary>
        public async Task SetSizeAsync(TerminalSize size)
        {
            await _trayProcessCommunicationService.ResizeTerminalAsync(Id, size).ConfigureAwait(false);

            SizeChanged?.Invoke(this, size);
        }
コード例 #22
0
ファイル: PhysicalObject.cs プロジェクト: piRepos/pEngine-del
        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;
            }
        }
コード例 #23
0
ファイル: Widget.cs プロジェクト: communityus-branch/Myra
 private void FireSizeChanged()
 {
     SizeChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #24
0
 /// <summary>
 /// Occurs when size changed
 /// </summary>
 /// <param name="size"></param>
 protected virtual void OnSizeChanged(Size size)
 {
     SizeChanged?.Invoke(this, size);
     OnLookChanged(new EventArgs());
 }
コード例 #25
0
 internal void RaiseSizeChanged(SizeChangedEventArgs args)
 {
     SizeChanged?.Invoke(this, args);
 }
コード例 #26
0
 public override void SetFrameSize(CGSize newSize)
 {
     base.SetFrameSize(newSize);
     NeedsNewContext = true;
     SizeChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #27
0
        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));
        }
コード例 #28
0
 private void SizeChangedCommand_Execute()
 {
     SizeChanged?.Invoke();
 }
コード例 #29
0
 protected virtual void OnSizeChanged()
 {
     SizeChanged?.Invoke(this, EventArgs.Empty);
 }
コード例 #30
0
 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();
 }