public Vector2i ToPixelPosition(Vector2f canvasPosition)
        {
            Vector2f v = Vector2f.ComponentDivision(canvasPosition, root.unitSize);

            v = Vector2f.ComponentMultiply(v, new Vector2f(root.viewport.Dimensions.X, root.viewport.Dimensions.Y));
            return(new Vector2i((int)(v.X + 0.5f), (int)(v.Y + 0.5f)));
        }
Exemple #2
0
        /// <summary>
        /// Converts pixel coordinates to canvas coordinates.
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="pixel"></param>
        /// <returns></returns>
        public static Vector2f PixelToCanvas(ICanvas canvas, Vector2f pixel)
        {
            Vector2i ps = canvas.CanvasPixelSize;

            return(Vector2f.ComponentDivision(
                       Vector2f.ComponentMultiply(pixel, canvas.CanvasUnitSize),
                       new Vector2f(ps.X, ps.Y)));
        }
        public Vector2f ToCanvasPosition(Vector2i pixelPosition)
        {
            Vector2f v = Vector2f.ComponentDivision(
                new Vector2f((float)pixelPosition.X, (float)pixelPosition.Y),
                new Vector2f((float)root.viewport.Width, (float)root.viewport.Height));

            return(Vector2f.ComponentMultiply(v, root.unitSize));
        }
Exemple #4
0
        /// <summary>
        /// Calculates mouse sensitivity.
        /// </summary>
        /// <param name="canvas"></param>
        /// <returns></returns>
        public Vector2f CalcMouseSensitivity(ICanvas canvas)
        {
            Vector2i ps = canvas.CanvasPixelSize;

            return(mouseSensitivity.CanvasCoordinates +
                   Vector2f.ComponentDivision(Vector2f.ComponentMultiply(mouseSensitivity.PixelCoordinates,
                                                                         canvas.CanvasUnitSize), new Vector2f(ps.X, ps.Y)));
        }
Exemple #5
0
        public Vector2f ToConvasPosition(ICanvas canvas, IPositionable parentElement)
        {
            Vector2f leftBottom, rightTop;

            parentElement.GetBoundingBox(out leftBottom, out rightTop);

            // We now construct canvas position.
            return(leftBottom + Vector2f.ComponentMultiply(parentCoordinates, (rightTop - leftBottom)) +
                   canvasCoordinates + PixelToCanvas(canvas, pixelCoordinates));
        }