示例#1
0
        public static void Initialize(ECSWorld world)
        {
            if (initialized)
            {
                return;
            }
            if (world == null)
            {
                throw  new ArgumentNullException(nameof(world), "The ECSWorld provided can not be null.");
            }
            if (!world.IsMainWorld)
            {
                throw new ArgumentException("The ECSWorld of the window needs to be the mainWorld", nameof(world));
            }

            WindowInstance     = Process.GetCurrentProcess().SafeHandle.DangerousGetHandle();
            window             = new Sdl2Window("ECS", 50, 50, 1280, 720, SDL_WindowFlags.Resizable, threadedProcessing: false);
            window.X           = 50;
            window.Y           = 50;
            window.Visible     = true;
            window.MouseWheel += (x) => OnMouseWheel?.Invoke(x);
            window.MouseMove  += (x) => OnMouseMove?.Invoke(x);
            window.MouseDown  += (x) => OnMouseDown?.Invoke(x);
            window.KeyDown    += (x) => OnKeyDown?.Invoke(x);
            window.Closed     += () => OnWindowClose?.Invoke();
            window.Resized    += () => OnWindowResize?.Invoke(window.Width, window.Height);

            world.EarlyUpdate += PumpEvents;

            initialized = true;
            GraphicsContext.Initialize(world);
        }
 void LateUpdate()
 {
     //Check if window was resized
     if (PreviousResolution.x != Screen.width || PreviousResolution.y != Screen.height || RequestedInvoke)
     {
         PreviousResolution.x = Screen.width;
         PreviousResolution.y = Screen.height;
         //Event callback
         OnWindowResize?.Invoke();
         RequestedInvoke = false;
     }
 }
示例#3
0
 //Can't figure out a way to prevent the user from changing the window size.
 //If we don't allow resize, just reset the size back where we want it.
 private void CheckForResize()
 {
     if (Console.WindowWidth != CurrentSettings.WindowWidth || Console.WindowHeight != CurrentSettings.WindowHeight)
     {
         if (CurrentSettings.AllowResize)
         {
             CurrentSettings.WindowWidth  = Console.WindowWidth;
             CurrentSettings.WindowHeight = Console.WindowHeight;
             CurrentSettings.Apply();
             OnWindowResize?.Invoke(this, new WindowResizedEvent());
         }
         else
         {
             CurrentSettings.Apply();
         }
         DrawEngine.InitializeScreen();
     }
 }
示例#4
0
        /// <summary>
        /// Sets the window size.
        /// </summary>
        /// <param name="newSize">New size.</param>
        private void SetSize(Point newSize)
        {
            if (currentWindowState == WindowStates.FULLSCREEN)
            {
                Resources.GraphicsDeviceManager.IsFullScreen              = true;
                Resources.GraphicsDeviceManager.PreferredBackBufferWidth  = currentWindowFullscreenSize.X;
                Resources.GraphicsDeviceManager.PreferredBackBufferHeight = currentWindowFullscreenSize.Y;
            }
            else
            {
                Resources.GraphicsDeviceManager.IsFullScreen              = false;
                Resources.GraphicsDeviceManager.PreferredBackBufferWidth  = newSize.X;
                Resources.GraphicsDeviceManager.PreferredBackBufferHeight = newSize.Y;
                currentWindowSize = newSize;
            }

            Resources.GraphicsDeviceManager.ApplyChanges();

            OnWindowResize?.Invoke(newSize);
        }
示例#5
0
        private void RefreshViewMode(ResizeMode resizeMode, float pixelScale)
        {
            WindowSize   = new Size(XNAGameWrapper.Window.ClientBounds.Width, XNAGameWrapper.Window.ClientBounds.Height);
            WindowCenter = (WindowSize / 2f).ToVector2();
            _pixelScale  = pixelScale;

            switch (resizeMode)
            {
            case ResizeMode.KeepProportions:
                Size = new Size(_nextInternalWidth, _nextInternalHeight);
                KeepProportionsScale = WindowHeight / (Height * _pixelScale);

                // width correction
                float internalGameWidth = Math.Round(Width * _pixelScale * KeepProportionsScale);

                _gameCanvasPosition = Math.Round(new Vector2((WindowWidth - internalGameWidth) / 2f, 0f));
                break;

            case ResizeMode.ExpandView:
                KeepProportionsScale = 1f;
                _gameCanvasPosition  = Vector2.Zero;

                Size = WindowSize / _pixelScale;
                break;

            default:
                break;
            }

            ResizeMode = resizeMode;
            Center     = (Size / 2f).ToVector2();

            // renderers
            foreach (Renderer renderer in Renderers)
            {
                renderer.RecalculateProjection();
            }

            // canvas
            RenderTargetStack.Clear();

            // game renderers projection
            if (MainCanvas != null)
            {
                MainCanvas.Resize(Size);
                MainCanvas.ClippingRegion = MainCanvas.SourceRegion;
            }

#if DEBUG
            if (DebugCanvas != null)
            {
                DebugCanvas.Resize((int)Math.Floor(Size.Width * KeepProportionsScale * PixelScale), (int)Math.Floor(Size.Height * KeepProportionsScale * PixelScale));
                DebugCanvas.ClippingRegion = DebugCanvas.SourceRegion;
            }
#endif

            ScreenRenderer.RecalculateProjection();

            // window callback
            OnWindowResize?.Invoke();
        }
示例#6
0
 internal void InvokeWindowResize(int w, int h)
 {
     OnWindowResize?.Invoke(w, h);
     WindowResize(w, h);
 }
示例#7
0
 public void OnSizeChanged(float width, float height)
 {
     OnWindowResize?.Invoke(new SizeF(width, height));
 }