Пример #1
0
        ////////////////

        /// <summary>
        /// Gets the screen-space coordinates of the given world coordinates.
        /// </summary>
        /// <param name="worldCoords"></param>
        /// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <returns></returns>
        public static Vector2 ConvertToScreenPosition(Vector2 worldCoords, bool?uiZoomState, bool?gameZoomState)
        {
            var wldScrFrame = UIZoomLibraries.GetWorldFrameOfScreen(uiZoomState, gameZoomState);
            var wldScrPos   = new Vector2(wldScrFrame.X, wldScrFrame.Y);

            return(worldCoords - wldScrPos);
        }
Пример #2
0
        /// <summary>
        /// Gets the current screen size according to the given scales.
        /// </summary>
        /// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <returns></returns>
        public static (float Width, float Height) GetScreenSize(bool?uiZoomState, bool?gameZoomState)
        {
            float width  = UIZoomLibraries.ApplyZoom(Main.screenWidth, uiZoomState, gameZoomState);
            float height = UIZoomLibraries.ApplyZoom(Main.screenHeight, uiZoomState, gameZoomState);

            return(width, height);
        }
Пример #3
0
        /// <summary>
        /// Gets the world position and range of the screen, according to the given zoom parameters.
        /// </summary>
        /// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <returns></returns>
        public static Rectangle GetWorldFrameOfScreen(bool?uiZoomState, bool?gameZoomState)
        {
            float width  = UIZoomLibraries.ApplyZoom(Main.screenWidth, uiZoomState, gameZoomState);
            float height = UIZoomLibraries.ApplyZoom(Main.screenHeight, uiZoomState, gameZoomState);

            int scrX = (int)Main.screenPosition.X;

            scrX += (int)(((float)Main.screenWidth - width) * 0.5f);
            int scrY = (int)Main.screenPosition.Y;

            scrY += (int)(((float)Main.screenHeight - height) * 0.5f);

            return(new Rectangle(scrX, scrY, (int)width, (int)height));
        }
Пример #4
0
        /// <summary>
        /// Applies the given zoom parameters to the given Vector2.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="uiZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <param name="gameZoomState">If `true`, assumes zoom is applied, and removes it. `false` assumes it has been
        /// removed, and applies it.</param>
        /// <param name="uiZoomStateForCenterOffset"></param>
        /// <param name="gameZoomStateForCenterOffset"></param>
        /// <returns></returns>
        public static Vector2 ApplyZoomFromScreenCenter(
            Vector2 value,
            bool?uiZoomState,
            bool?gameZoomState,
            bool?uiZoomStateForCenterOffset,
            bool?gameZoomStateForCenterOffset)
        {
            var scrMid = new Vector2(Main.screenWidth, Main.screenHeight) * 0.5f;

            value -= UIZoomLibraries.ApplyZoom(scrMid, uiZoomStateForCenterOffset, gameZoomStateForCenterOffset);
            value  = UIZoomLibraries.ApplyZoom(value, uiZoomState, gameZoomState);
            value += scrMid;

            return(value);
        }