Пример #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.Dungeon:  m_MapSize = MapSizes.Dungeon;   break;
                case Maps.Sosaria:  m_MapSize = MapSizes.Sosaria;   break;
                //case Maps.Felucca:  m_MapSize = MapSizes.FeluccaML; break;
                //case Maps.Trammel:  m_MapSize = MapSizes.TrammelML; break;
                case Maps.Ilshenar: m_MapSize = MapSizes.Ilshenar;  break;
                case Maps.Malas:    m_MapSize = MapSizes.Malas;     break;
                case Maps.Tokuno:   m_MapSize = MapSizes.Tokuno;    break;
                case Maps.TerMur:   m_MapSize = MapSizes.TerMur;    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 );
        }
Пример #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();
        }