Example #1
0
        private void Initialize()
        {
            GraphicsContext.ShareContexts = true;

            _window = new OpenTK.GameWindow();
            _window.RenderFrame += OnRenderFrame;
            _window.UpdateFrame += OnUpdateFrame;
            _window.Closing += OpenTkGameWindowClosing;
            _window.Resize += OnResize;
            _window.Keyboard.KeyDown += KeyboardKeyDown;
            _window.Keyboard.KeyUp += KeyboardKeyUp;

            // Set the window icon.
            _window.Icon = Icon.ExtractAssociatedIcon(Assembly.GetEntryAssembly().Location);

            _updateClientBounds = false;
            _clientBounds = new Rectangle(_window.ClientRectangle.X, _window.ClientRectangle.Y, _window.ClientRectangle.Width, _window.ClientRectangle.Height);
            _windowState = _window.WindowState;

            _keys = new List<Keys>();

            #if WINDOWS || LINUX
            Mouse.SetWindow(_window);
            #else
            Mouse.UpdateMouseInfo(window.Mouse);
            #endif

            // Default no resizing
            AllowUserResizing = false;
        }
Example #2
0
        private void OnResize(object sender, EventArgs e)
        {
            var winWidth = _window.ClientRectangle.Width;
            var winHeight = _window.ClientRectangle.Height;
            var winRect = new Rectangle(0, 0, winWidth, winHeight);

            // If window size is zero, leave bounds unchanged
            // OpenTK appears to set the window client size to 1x1 when minimizing
            if (winWidth <= 1 || winHeight <= 1)
                return;

            // If we've already got a pending change, do nothing
            if (_updateClientBounds)
                return;

            // FIXME: This should be really set?
            Game.GraphicsDevice.Viewport = new Viewport(0, 0, winWidth, winHeight);

            ChangeClientBounds(winRect);
            OnClientSizeChanged();
        }
Example #3
0
        internal void ChangeClientBounds(Rectangle clientBounds)
        {
            if (_updateClientBounds)
                return;

            _updateClientBounds = true;
            _clientBounds = clientBounds;
        }