Ejemplo n.º 1
0
		/// <summary>
		/// Calculates all the parameters needed for this class to function. It assumes Center, ZoomLevel, ControlSize and Map as given.
		/// </summary>
		private void Calculate()
		{
			// Determine the size of the map first of all
			switch ( m_Map )
			{
				case Maps.Felucca:
				case Maps.Trammel:
					// Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
					m_MapSize = MapSizes.FeluccaML;
					// Issue 13 - End
					break;
				case Maps.Ilshenar:
					// Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
					m_MapSize = MapSizes.Ilshenar;
					// Issue 13- End
					break;
				case Maps.Malas:
					// Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
					m_MapSize = MapSizes.Malas;
					// Issue 13 - End
					break;
				case Maps.Tokuno:
					m_MapSize = MapSizes.Tokuno;
					break;
				default:
					throw new Exception( string.Format( "Map not supported: {0}.", m_Map.ToString() ) );
			}

			m_ControlSize = m_Viewer.Size;

			if ( m_RotateView )
			{
				double d = Math.Sqrt( Math.Pow( m_ControlSize.Width + m_ControlSize.Height, 2 ) / 2 );
				m_ImageSize = new Size( (int) Math.Round( d ), (int) Math.Round( d ) );

				m_Transform = new Matrix( 1, 0, 0, 1, 0, 0 );
				m_Transform.Translate( - ( m_ControlSize.Width - m_Viewer.Width ) / 2, - ( m_ControlSize.Height - m_Viewer.Height ) / 2 );
				m_Transform.RotateAt( 45, new PointF( m_Viewer.Width / 2, m_Viewer.Height / 2 ), MatrixOrder.Append );
				
				m_Transform.Invert();
			}
			else
			{
				m_ImageSize = m_ControlSize;
				m_Transform = null;
			}

			// Calculate the number of cells displayed for each block
			m_CellsPerBlock = 8;

			if ( m_ZoomLevel < 0 )
			{
				m_CellsPerBlock = 8 / ( (int) Math.Pow( 2, Math.Abs( m_ZoomLevel ) ) );

				if ( m_CellsPerBlock < 1 )
					m_CellsPerBlock = 1;
			}

			// Calculate the number of pixels used to display each block
			m_PixelsPerCell = 1;

			if ( m_ZoomLevel > 0 )
				m_PixelsPerCell = (int) Math.Pow( 2, m_ZoomLevel );

			// Calculate the number of cells in each pixel
			m_CellsPerPixel = 1.0 / m_PixelsPerCell;

			// Calculate the center of the control
			m_ControlCenter = new Point( m_Viewer.Width / 2, m_Viewer.Height / 2 );

			// Calculate the BlockInfo
			Point bottomright = InternalControlToMap( new Point( m_ImageSize.Width - 1, m_ImageSize.Height - 1 ) );
			m_End = new BlockInfo( bottomright, m_MapSize );

			Point topleft = InternalControlToMap( new Point( 0, 0 ) );
			m_Start = new BlockInfo( topleft, m_MapSize );

			// Calculate the valid blocks
			BlockInfo start = m_Start;
			BlockInfo end = m_End;

			start.Validate();
			end.Validate();

			m_ValidXBlocks = end.XBlock - start.XBlock + 1;
			m_ValidYBlocks = end.YBlock - start.YBlock + 1;

			// Calculate the number of pixels needed to represent the left and top cells
			if ( m_PixelsPerCell > 1 )
			{
				int yDiff = ( m_ImageSize.Height / 2 ) % m_PixelsPerCell;
				int xDiff = ( m_ImageSize.Width / 2 ) % m_PixelsPerCell;

				if ( yDiff == 0 )
					m_TopPixels = m_PixelsPerCell;
				else
					m_TopPixels = yDiff;

				if ( xDiff == 0 )
					m_LeftPixels = m_PixelsPerCell;
				else
					m_LeftPixels = xDiff;
			}
			else
			{
				m_TopPixels = 1;
				m_LeftPixels = 1;
			}

			// Calculate the bounds
			Point p1 = topleft;
			Point p2 = bottomright;
			m_Bounds = new Rectangle( p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y );
		}
Ejemplo n.º 2
0
		/// <summary>
		/// Initializes the object to provide information for the image drawing
		/// </summary>
		internal void Initialize()
		{
			m_CurrentPoint = new Point( 0,0 );

			m_CurrentXBlock = m_Start.XBlock;
			m_CurrentYBlock = m_Start.YBlock;

			m_CurrentXCell = m_Start.XCell;
			m_CurrentYCell = m_Start.YCell;

			m_ValidStart = m_Start;
			m_ValidEnd = m_End;

			m_ValidStart.Validate();
			m_ValidEnd.Validate();
		}
Ejemplo n.º 3
0
        /// <summary>
        /// Calculates all the parameters needed for this class to function. It assumes Center, ZoomLevel, ControlSize and Map as given.
        /// </summary>
        private void Calculate()
        {
            // Determine the size of the map first of all
            switch (m_Map)
            {
            case Maps.Felucca:
            case Maps.Trammel:
                // Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
                m_MapSize = MapSizes.FeluccaML;
                // Issue 13 - End
                break;

            case Maps.Ilshenar:
                // Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
                m_MapSize = MapSizes.Ilshenar;
                // Issue 13- End
                break;

            case Maps.Malas:
                // Issue 13 - ML map sizes - http://code.google.com/p/pandorasbox3/issues/detail?id=13 - Kons
                m_MapSize = MapSizes.Malas;
                // Issue 13 - End
                break;

            case Maps.Tokuno:
                m_MapSize = MapSizes.Tokuno;
                break;

            default:
                throw new Exception(string.Format("Map not supported: {0}.", m_Map.ToString()));
            }

            m_ControlSize = m_Viewer.Size;

            if (m_RotateView)
            {
                double d = Math.Sqrt(Math.Pow(m_ControlSize.Width + m_ControlSize.Height, 2) / 2);
                m_ImageSize = new Size((int)Math.Round(d), (int)Math.Round(d));

                m_Transform = new Matrix(1, 0, 0, 1, 0, 0);
                m_Transform.Translate(-(m_ControlSize.Width - m_Viewer.Width) / 2, -(m_ControlSize.Height - m_Viewer.Height) / 2);
                m_Transform.RotateAt(45, new PointF(m_Viewer.Width / 2, m_Viewer.Height / 2), MatrixOrder.Append);

                m_Transform.Invert();
            }
            else
            {
                m_ImageSize = m_ControlSize;
                m_Transform = null;
            }

            // Calculate the number of cells displayed for each block
            m_CellsPerBlock = 8;

            if (m_ZoomLevel < 0)
            {
                m_CellsPerBlock = 8 / ((int)Math.Pow(2, Math.Abs(m_ZoomLevel)));

                if (m_CellsPerBlock < 1)
                {
                    m_CellsPerBlock = 1;
                }
            }

            // Calculate the number of pixels used to display each block
            m_PixelsPerCell = 1;

            if (m_ZoomLevel > 0)
            {
                m_PixelsPerCell = (int)Math.Pow(2, m_ZoomLevel);
            }

            // Calculate the number of cells in each pixel
            m_CellsPerPixel = 1.0 / m_PixelsPerCell;

            // Calculate the center of the control
            m_ControlCenter = new Point(m_Viewer.Width / 2, m_Viewer.Height / 2);

            // Calculate the BlockInfo
            Point bottomright = InternalControlToMap(new Point(m_ImageSize.Width - 1, m_ImageSize.Height - 1));

            m_End = new BlockInfo(bottomright, m_MapSize);

            Point topleft = InternalControlToMap(new Point(0, 0));

            m_Start = new BlockInfo(topleft, m_MapSize);

            // Calculate the valid blocks
            BlockInfo start = m_Start;
            BlockInfo end   = m_End;

            start.Validate();
            end.Validate();

            m_ValidXBlocks = end.XBlock - start.XBlock + 1;
            m_ValidYBlocks = end.YBlock - start.YBlock + 1;

            // Calculate the number of pixels needed to represent the left and top cells
            if (m_PixelsPerCell > 1)
            {
                int yDiff = (m_ImageSize.Height / 2) % m_PixelsPerCell;
                int xDiff = (m_ImageSize.Width / 2) % m_PixelsPerCell;

                if (yDiff == 0)
                {
                    m_TopPixels = m_PixelsPerCell;
                }
                else
                {
                    m_TopPixels = yDiff;
                }

                if (xDiff == 0)
                {
                    m_LeftPixels = m_PixelsPerCell;
                }
                else
                {
                    m_LeftPixels = xDiff;
                }
            }
            else
            {
                m_TopPixels  = 1;
                m_LeftPixels = 1;
            }

            // Calculate the bounds
            Point p1 = topleft;
            Point p2 = bottomright;

            m_Bounds = new Rectangle(p1.X, p1.Y, p2.X - p1.X, p2.Y - p1.Y);
        }