Пример #1
0
        /// <summary>
        /// Button add roof piece
        /// </summary>
        private void bAdd_Click(object sender, System.EventArgs e)
        {
            RoofRect rect = CurrentRect;

            if (m_Roof.AddRectangle(rect))
            {
                pctImage.Image = m_Roof.Image;
            }

            EnableButtons();
        }
Пример #2
0
        /// <summary>
        ///     Adds a rectangle to the roof
        /// </summary>
        /// <param name="rect">The new rectangle being added</param>
        /// <returns>True if the rectangle has been succesfully added, false otherwise</returns>
        public bool AddRectangle(RoofRect rect)
        {
            if (rect.Rectangle.Height > 0 && rect.Rectangle.Width > 0)
            {
                if ((!rect.Sloped && !rect.GoesUp && (rect.Rectangle.Height % 2 > 0)) ||
                    (!rect.Sloped && rect.GoesUp && (rect.Rectangle.Width % 2 > 0)))
                {
                    // This rectangle isn't odd wide and itsn't sloped
                    if (MessageBox.Show(
                            Pandora.Localization.TextProvider["Roofing.NotOddWide"],
                            "",
                            MessageBoxButtons.YesNo,
                            MessageBoxIcon.Question) == DialogResult.No)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                MessageBox.Show(Pandora.Localization.TextProvider["Roofing.EmptyRoof"]);
                return(false);
            }

            foreach (var rr in m_Edges)
            {
                if (rr.Rectangle.Equals(rect.Rectangle) && rect.GoesUp == rr.GoesUp && rect.Sloped && rr.Sloped)
                {
                    MessageBox.Show(Pandora.Localization.TextProvider["Roofing.AlreadyAdded"]);
                    return(false);
                }
            }

            m_Edges.Add(rect);

            if (!Calculate())
            {
                MessageBox.Show(Pandora.Localization.TextProvider["Roofing.CantAdd"]);
                m_Edges.Remove(rect);
                Calculate();

                return(false);
            }
            m_RoofImage.CreateImage();
            return(true);
        }
Пример #3
0
		/// <summary>
		/// Adds a rectangle to the roof
		/// </summary>
		/// <param name="rect">The new rectangle being added</param>
		/// <returns>True if the rectangle has been succesfully added, false otherwise</returns>
		public bool AddRectangle( RoofRect rect )
		{
			if ( rect.Rectangle.Height > 0 && rect.Rectangle.Width > 0 )
			{
				if ( ( !rect.Sloped && !rect.GoesUp && ( rect.Rectangle.Height % 2 > 0 ) ) || 
					( !rect.Sloped && rect.GoesUp && ( rect.Rectangle.Width % 2 > 0 ) ) )
				{
					// This rectangle isn't odd wide and itsn't sloped
					if ( MessageBox.Show( Pandora.Localization.TextProvider[ "Roofing.NotOddWide" ], "", MessageBoxButtons.YesNo, MessageBoxIcon.Question )
						== DialogResult.No )
					{
						return false;
					}
				}
			}
			else
			{
				MessageBox.Show( Pandora.Localization.TextProvider[ "Roofing.EmptyRoof" ] );
				return false;
			}
			
			foreach( RoofRect rr in m_Edges )
			{
				if ( rr.Rectangle.Equals( rect.Rectangle ) && rect.GoesUp == rr.GoesUp && rect.Sloped && rr.Sloped )
				{
					MessageBox.Show( Pandora.Localization.TextProvider[ "Roofing.AlreadyAdded"  ] );
					return false;
				}
			}

			m_Edges.Add( rect );

			if ( ! Calculate() )
			{
				MessageBox.Show( Pandora.Localization.TextProvider[ "Roofing.CantAdd" ] );
				m_Edges.Remove( rect );
				Calculate();

				return false;
			}
			else
			{
				m_RoofImage.CreateImage();
				return true;
			}
		}
Пример #4
0
        /// <summary>
        /// Calculates the roof
        /// </summary>
        /// <returns>True if a valid roof can be generated from the current set of rectangles</returns>
        private bool Calculate()
        {
            // Clear the roofimage data if needed
            if (m_RoofImage.Data.Count > 0)
            {
                m_RoofImage.Data.Clear();
            }

            // Empty roof is a valid roof
            if (m_Edges.Count == 0)
            {
                return(true);
            }

            Rectangle bounds = RoofBounds;

            // Maximum supported roof size is 300 x 300
            if (bounds.Width > 300 || bounds.Height > 300)
            {
                return(false);
            }

            m_RoofImage.Width  = bounds.Width + 3;
            m_RoofImage.Height = bounds.Height + 3;

            // Create the data array
            // Issue 10 - Update the code to Net Framework 3.5 - http://code.google.com/p/pandorasbox3/issues/detail?id=10 - Smjert
            m_RoofImage.Data = new List <int>(m_RoofImage.Width * m_RoofImage.Height);
            // Issue 10 - End

            for (int i = 0; i < m_RoofImage.Width * m_RoofImage.Height; i++)
            {
                m_RoofImage.Data.Add(0);
            }

            m_BasePoint = new Point(bounds.X - 1, bounds.Y - 1);

            bounds.X -= m_BasePoint.X;
            bounds.Y -= m_BasePoint.Y;

            foreach (RoofRect roofrect in m_Edges)
            {
                RoofRect rect = roofrect.Clone() as RoofRect;

                // Shift the rect to our relative coordinates
                Rectangle r = rect.Rectangle;

                r.X -= m_BasePoint.X;
                r.Y -= m_BasePoint.Y;

                rect.Rectangle = r;

                if (rect.GoesUp)
                {
                    for (int i = 0; i < rect.Rectangle.Height + 1; i++)
                    {
                        AddVertexX(rect.Rectangle.Left,
                                   rect.Rectangle.Right,
                                   rect.Rectangle.Top + i,
                                   rect.Tent ? Math.Min(i + 1, rect.Rectangle.Height + 1 - i) : 1000,
                                   rect.Sloped ? rect.Slope : Slope.None);
                    }
                }
                else
                {
                    for (int i = 0; i < rect.Rectangle.Width + 1; i++)
                    {
                        AddVertexY(
                            rect.Rectangle.Top,
                            rect.Rectangle.Bottom,
                            rect.Rectangle.Left + i,
                            rect.Tent ? Math.Min(i + 1, rect.Rectangle.Width + 1 - i) : 1000,
                            rect.Sloped ? rect.Slope : Slope.None);
                    }
                }
            }

            return(true);
        }