Exemple #1
0
		/// <summary>
		/// Returns a point which should be subtracted from the interpreted
		/// point to get the top-left position.
		/// </summary>
		/// <param name="origin"></param>
		/// <param name="size"></param>
		/// <returns></returns>
		public static Point Calc(OriginAlignment origin, Size size)
		{
			Point result = new Point();
			int tb = ((int)origin) & 0xf0;
			int lr = ((int)origin) & 0x0f;
			int width = Math.Abs(size.Width);
			int height = Math.Abs(size.Height);

			if (lr == 0x01)
				result.X = 0;
			else if (lr == 0x02)
				result.X = width / 2;
			else if (lr == 0x03)
			{
				result.X = width;

			}

			if (tb == 0x10)
				result.Y = 0;
			else if (tb == 0x20)
				result.Y = height / 2;
			else if (tb == 0x30)
			{
				result.Y = height;
			}

			return result;
		}
Exemple #2
0
        /// <summary>
        /// Returns a point which should be subtracted from the interpreted
        /// point to get the top-left position.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="size"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        public static void Calc(OriginAlignment origin, Size size, out int x, out int y)
        {
            Point ret = Calc(origin, size);

            x = ret.X;
            y = ret.Y;
        }
Exemple #3
0
        /// <summary>
        /// Returns a point which should be subtracted from the interpreted
        /// point to get the top-left position.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static PointF CalcF(OriginAlignment origin, SizeF size)
        {
            PointF retval = new PointF();
            int    tb     = ((int)origin) & 0xf0;
            int    lr     = ((int)origin) & 0x0f;

            if (lr == 0x01)
            {
                retval.X = 0;
            }
            else if (lr == 0x02)
            {
                retval.X = size.Width / 2;
            }
            else if (lr == 0x03)
            {
                retval.X = size.Width;
            }

            if (tb == 0x10)
            {
                retval.Y = 0;
            }
            else if (tb == 0x20)
            {
                retval.Y = size.Height / 2;
            }
            else if (tb == 0x30)
            {
                retval.Y = size.Height;
            }

            return(retval);
        }
Exemple #4
0
        /// <summary>
        /// Return the point on the rectangle that corresponds to the specified alignemtn.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="rect"></param>
        /// <returns></returns>
        public static Point OnRect(this OriginAlignment origin, Rectangle rect)
        {
            var calcPoint = Calc(origin, rect.Size);

            return(new Point(calcPoint.X + rect.X,
                             calcPoint.Y + rect.Y));
        }
Exemple #5
0
        /// <summary>
        /// Returns a point which should be subtracted from the interpreted
        /// point to get the top-left position.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static Vector2 CalcF(this OriginAlignment origin, SizeF size)
        {
            Vector2 result = new Vector2();
            int     tb     = ((int)origin) & 0xf0;
            int     lr     = ((int)origin) & 0x0f;

            if (lr == 0x01)
            {
                result.X = 0;
            }
            else if (lr == 0x02)
            {
                result.X = size.Width / 2;
            }
            else if (lr == 0x03)
            {
                result.X = size.Width;
            }

            if (tb == 0x10)
            {
                result.Y = 0;
            }
            else if (tb == 0x20)
            {
                result.Y = size.Height / 2;
            }
            else if (tb == 0x30)
            {
                result.Y = size.Height;
            }

            return(result);
        }
Exemple #6
0
		/// <summary>
		/// Modifies the rectangle by taking its Location and converting it
		/// using Calc so that the rectangle outlines the actual destination.
		/// </summary>
		/// <param name="origin"></param>
		/// <param name="rect"></param>
		/// <param name="effectiveSize"></param>
		/// <returns></returns>
		public static Rectangle CalcRect(OriginAlignment origin, Rectangle rect, Size effectiveSize)
		{
			Point pt = Origin.Calc(origin, effectiveSize);
			Rectangle result = new Rectangle(rect.X, rect.Y, rect.Width, rect.Height);

			result.X -= pt.X;
			result.Y -= pt.Y;

			return result;
		}
        private void SetVertsPosition(PositionTextureColor[] verts, int index,
                                      RectangleF dest, float rotationCenterX, float rotationCenterY,
                                      OriginAlignment DisplayAlignment,
                                      float mRotationCos, float mRotationSin)
        {
            float destX      = dest.X - 0.5f;
            float destY      = dest.Y - 0.5f;
            float destWidth  = dest.Width;
            float destHeight = dest.Height;

            mCenterPoint = Origin.CalcF(DisplayAlignment, dest.Size);

            destX += rotationCenterX - mCenterPoint.X;
            destY += rotationCenterY - mCenterPoint.Y;

            // Point at (0, 0) local coordinates
            verts[index].X = mRotationCos * (-rotationCenterX) +
                             mRotationSin * (-rotationCenterY) + destX;

            verts[index].Y = -mRotationSin * (-rotationCenterX) +
                             mRotationCos * (-rotationCenterY) + destY;

            // Point at (DisplayWidth, 0) local coordinates
            verts[index + 1].X = mRotationCos * (-rotationCenterX + destWidth) +
                                 mRotationSin * (-rotationCenterY) + destX;

            verts[index + 1].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                                 mRotationCos * (-rotationCenterY) + destY;

            // Point at (0, DisplayHeight) local coordinates
            verts[index + 2].X = mRotationCos * (-rotationCenterX) +
                                 mRotationSin * (-rotationCenterY + destHeight) + destX;

            verts[index + 2].Y = (-mRotationSin * (-rotationCenterX) +
                                  mRotationCos * (-rotationCenterY + destHeight)) + destY;

            // Point at (DisplayWidth, DisplayHeight) local coordinates
            verts[index + 3].X = mRotationCos * (-rotationCenterX + destWidth) +
                                 mRotationSin * (-rotationCenterY + destHeight) + destX;

            verts[index + 3].Y = -mRotationSin * (-rotationCenterX + destWidth) +
                                 mRotationCos * (-rotationCenterY + destHeight) + destY;
        }
Exemple #8
0
        /// <summary>
        /// For function use, see documentation of Surface.
        ///
        /// Info for developers:
        /// This method should Draw the surface to the screen, ignoring
        /// all scaling, rotation and alignment state data.
        /// Color and Alpha are still to be used.
        ///
        /// It is recommended to override this method, as the base class
        /// implementation saves the state, draws, then restores the state.
        /// </summary>
        /// <param name="destRect"></param>
        public virtual void Draw(Rectangle destRect)
        {
            // save the state
            Size            displaySize      = DisplaySize;
            OriginAlignment displayAlignment = DisplayAlignment;
            double          angle            = RotationAngle;

            // reset the state
            DisplaySize      = destRect.Size;
            DisplayAlignment = OriginAlignment.TopLeft;
            RotationAngle    = 0;

            // draw with no state values
            Draw(destRect.Location);

            // restore the state.
            RotationAngle    = angle;
            DisplayAlignment = displayAlignment;
            DisplaySize      = displaySize;
        }
Exemple #9
0
		/// <summary>
		/// Returns a point which should be subtracted from the interpreted
		/// point to get the top-left position.
		/// </summary>
		/// <param name="origin"></param>
		/// <param name="size"></param>
		/// <returns></returns>
		public static Vector2 CalcF(OriginAlignment origin, SizeF size)
		{
			Vector2 result = new Vector2();
			int tb = ((int)origin) & 0xf0;
			int lr = ((int)origin) & 0x0f;

			if (lr == 0x01)
				result.X = 0;
			else if (lr == 0x02)
				result.X = size.Width / 2;
			else if (lr == 0x03)
				result.X = size.Width;

			if (tb == 0x10)
				result.Y = 0;
			else if (tb == 0x20)
				result.Y = size.Height / 2;
			else if (tb == 0x30)
				result.Y = size.Height;

			return result;
		}
Exemple #10
0
		/// <summary>
		/// Returns a point which should be subtracted from the interpreted
		/// point to get the top-left position.
		/// </summary>
		/// <param name="origin"></param>
		/// <param name="size"></param>
		/// <returns></returns>
		public static Vector2 CalcF(OriginAlignment origin, Size size)
		{
			Point result = Calc(origin, size);

			return new Vector2(result.X, result.Y);
		}
Exemple #11
0
		/// <summary>
		/// Modifies the rectangle by taking its Location and converting it
		/// using Calc so that the rectangle outlines the actual destination.
		/// </summary>
		/// <param name="origin"></param>
		/// <param name="rect"></param>
		/// <returns></returns>
		public static Rectangle CalcRect(OriginAlignment origin, Rectangle rect)
		{
			return CalcRect(origin, rect, rect.Size);
		}
Exemple #12
0
        /// <summary>
        /// Returns a point which should be subtracted from the interpreted
        /// point to get the top-left position.
        /// </summary>
        /// <param name="origin"></param>
        /// <param name="size"></param>
        /// <returns></returns>
        public static PointF CalcF(OriginAlignment origin, Size size)
        {
            Point retval = Calc(origin, size);

            return(new PointF(retval.X, retval.Y));
        }