示例#1
0
        public bool AreSelectedObjectsBricksWithSameGeometry()
        {
            bool       firstBrick      = true;
            RectangleF threshold       = RectangleF.Empty;
            float      threshold_value = 4.0f;

            LevelEntryCollection objects = GetSelectedObjects();

            foreach (LevelEntry le in objects)
            {
                Brick b = le as Brick;
                if (b == null)
                {
                    return(false);
                }

                PointF cc = b.GetCentrePoint();

                if (firstBrick)
                {
                    threshold  = new RectangleF(cc.X - (threshold_value / 2), cc.Y - (threshold_value / 2), threshold_value, threshold_value);
                    firstBrick = false;
                }
                else
                {
                    if (!threshold.Contains(cc))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
示例#2
0
        public void SendObjectsBackward()
        {
            LevelEntryCollection objs = GetSelectedObjectsInZOrder();

            foreach (LevelEntry obj in objs)
            {
                int index = mLevel.Entries.IndexOf(obj);

                //Top of the list, no change
                if (index == 0)
                {
                    continue;
                }

                //Move up one
                int new_index = index - 1;

                LevelEntry eo = mLevel.Entries[new_index];
                if (objs.Contains(eo))
                {
                    continue;
                }

                mLevel.Entries[index]     = mLevel.Entries[new_index];
                mLevel.Entries[new_index] = obj;
            }

            UpdateRedraw();
        }
示例#3
0
        public void FlipPegsVertically()
        {
            CreateUndoPoint();

            LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());

            if (objects.Count < 2)
            {
                return;
            }

            objects.Sort(new Comparison <LevelEntry>(CompareObjectsByY));

            float startY = objects[0].Y;
            float height = objects[objects.Count - 1].Y - objects[0].Y;

            foreach (LevelEntry o in objects)
            {
                o.Y = (startY + height) - (o.Y - startY);

                if (o is Brick)
                {
                    Brick brick = (Brick)o;
                    brick.Rotation = MathExt.FixAngle(brick.Rotation);
                    brick.Rotation = 360.0f - brick.Rotation;
                }
            }

            UpdateRedraw();
        }
示例#4
0
        public void RotateBricks(float angle)
        {
            LevelEntryCollection objects = GetSelectedObjects();

            if (objects.Count == 0)
            {
                return;
            }

            PointF cc = ((Brick)(objects[0])).GetCentrePoint();

            foreach (Brick b in objects)
            {
                b.Rotation += angle;
                float radius = b.InnerRadius + (b.Width / 2.0f);
                b.X = cc.X + ((float)Math.Cos(MathExt.ToRadians(-b.Rotation)) * radius);
                b.Y = cc.Y + ((float)Math.Sin(MathExt.ToRadians(-b.Rotation)) * radius);
            }


            //Matrix mx = new Matrix();
            //mx.RotateAt(angle, cc);

            //foreach (Brick b in objects) {
            //    PointF[] pnts = new PointF[] { new PointF(b.X, b.Y) };
            //    mx.TransformPoints(pnts);
            //    b.X = pnts[0].X;
            //    b.Y = pnts[0].Y;

            //    b.Angle = FixAngle(b.Angle);
            //    b.Angle -= angle;
            //}

            UpdateRedraw();
        }
示例#5
0
        public void RemoveOffscreenObjects()
        {
            bool firstOne = true;
            LevelEntryCollection removes    = new LevelEntryCollection();
            RectangleF           insideRect = RectangleF.FromLTRB(-Level.DrawAdjustX, -Level.DrawAdjustY, 800 - Level.DrawAdjustX, 600 - Level.DrawAdjustY);

            foreach (LevelEntry o in mLevel.Entries)
            {
                PointF pegPnt = new PointF(o.X, o.Y);

                if (!insideRect.Contains(pegPnt))
                {
                    if (firstOne)
                    {
                        CreateUndoPoint();
                        firstOne = false;
                    }

                    removes.Add((LevelEntry)o);
                }
            }

            foreach (LevelEntry le in removes)
            {
                le.OnDelete();
                mLevel.Entries.Remove(le);
            }

            UpdateRedraw();

            CheckSelectionChanged();
        }
示例#6
0
		public LevelEntryCollection GetSelectedObjects()
		{
			LevelEntryCollection objects = new LevelEntryCollection();
			foreach (LevelEntry le in mSelectedEntries) {
				objects.Add(le);
			}

			return objects;
		}
示例#7
0
        public LevelEntryCollection GetSelectedObjects()
        {
            LevelEntryCollection objects = new LevelEntryCollection();

            foreach (LevelEntry le in mSelectedEntries)
            {
                objects.Add(le);
            }

            return(objects);
        }
示例#8
0
		public LevelEntryCollection GetSelectedObjectsInZOrder()
		{
			LevelEntryCollection objects = new LevelEntryCollection();
			foreach (LevelEntry le in Level.Entries) {
				if (!mSelectedEntries.Contains(le))
					continue;

				objects.Add(le);
			}

			return objects;
		}
示例#9
0
        public LevelEntryCollection GetSelectedObjectsInZOrder()
        {
            LevelEntryCollection objects = new LevelEntryCollection();

            foreach (LevelEntry le in Level.Entries)
            {
                if (!mSelectedEntries.Contains(le))
                {
                    continue;
                }

                objects.Add(le);
            }

            return(objects);
        }
示例#10
0
        public void BringObjectsToFront()
        {
            LevelEntryCollection objs = GetSelectedObjectsInZOrder();

            //objs.Reverse();

            foreach (LevelEntry obj in objs)
            {
                //Remove from list altogether
                mLevel.Entries.Remove(obj);

                //Add again at the bottom of the list
                mLevel.Entries.Add(obj);
            }

            UpdateRedraw();
        }
示例#11
0
        public void SendObjectsToBack()
        {
            //Reverse the order so that selected objects maintain their inner z order
            LevelEntryCollection objs = GetSelectedObjectsInZOrder();

            objs.Reverse();

            foreach (LevelEntry obj in objs)
            {
                //Remove from list altogether
                mLevel.Entries.Remove(obj);

                //Add again at the top of the list
                mLevel.Entries.Insert(0, obj);
            }

            UpdateRedraw();
        }
示例#12
0
        public void AlignObjectYs()
        {
            LevelEntryCollection objects = GetSelectedObjects();

            if (objects.Count < 2)
            {
                return;
            }

            CreateUndoPoint();

            float y = objects[0].Y;

            foreach (LevelEntry o in objects)
            {
                o.Y = y;
            }

            UpdateRedraw();
        }
示例#13
0
		public void CreateUndoPoint()
		{
			LevelEntryCollection copies = new LevelEntryCollection();
			foreach (LevelEntry le in mLevel.Entries) {
				copies.Add((LevelEntry)le.Clone());
			}

			//if (mHistory.Count >= 100) {
			//    Queue<LevelEntry[]> tmpQueue = new Queue<LevelEntry[]>();
			//    while (mHistory.Count > 0) {
			//        tmpQueue.Enqueue(mHistory.Pop());
			//    }

			//    for (int i = 0; i < 99; i++) {
			//        mHistory.Push(tmpQueue.Dequeue());
			//    }
			//}

			mHistory.Push(copies.ToArray());
		}
示例#14
0
        public void CreateUndoPoint()
        {
            LevelEntryCollection copies = new LevelEntryCollection();

            foreach (LevelEntry le in mLevel.Entries)
            {
                copies.Add((LevelEntry)le.Clone());
            }

            //if (mHistory.Count >= 100) {
            //    Queue<LevelEntry[]> tmpQueue = new Queue<LevelEntry[]>();
            //    while (mHistory.Count > 0) {
            //        tmpQueue.Enqueue(mHistory.Pop());
            //    }

            //    for (int i = 0; i < 99; i++) {
            //        mHistory.Push(tmpQueue.Dequeue());
            //    }
            //}

            mHistory.Push(copies.ToArray());
        }
示例#15
0
        public void FlipObjectsHorizontally()
        {
            CreateUndoPoint();

            LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());

            if (objects.Count < 2)
            {
                return;
            }

            objects.Sort(new Comparison <LevelEntry>(CompareObjectsByX));

            float startX = objects[0].X;
            float width  = objects[objects.Count - 1].X - objects[0].X;

            foreach (LevelEntry o in objects)
            {
                o.X = (startX + width) - (o.X - startX);

                if (o is Brick)
                {
                    Brick brick = (Brick)o;
                    brick.Rotation = MathExt.FixAngle(brick.Rotation);

                    if (brick.Rotation < 180.0f)
                    {
                        brick.Rotation = 180.0f - brick.Rotation;
                    }
                    else
                    {
                        brick.Rotation = 540.0f - brick.Rotation;
                    }
                }
            }

            UpdateRedraw();
        }
示例#16
0
        public void SpaceObjectYsEqually()
        {
            LevelEntryCollection objects = GetSelectedObjects();

            if (objects.Count < 3)
            {
                return;
            }

            CreateUndoPoint();

            //Sort list by Y
            objects.Sort(new Comparison <LevelEntry>(CompareObjectsByY));

            //Common spacing
            float ySpacing = objects[1].Y - objects[0].Y;

            for (int i = 2; i < objects.Count; i++)
            {
                objects[i].Y = objects[i - 1].Y + ySpacing;
            }

            UpdateRedraw();
        }
示例#17
0
        public void MoveObjects(float x, float y)
        {
            if (x != 0 || y != 0)
            {
                LevelEntryCollection LevelObjects = GetSelectedObjects();

                if (LevelObjects.Count == 0)
                {
                    return;
                }

                CreateUndoPoint();

                foreach (LevelEntry p in LevelObjects)
                {
                    p.X += x;
                    p.Y += y;
                }

                UpdateRedraw();

                InvokeSelectionChangedEvent();
            }
        }
示例#18
0
		private void duplicateAndPhaseRibbonButton_Click(object sender, EventArgs e)
		{
			if (!IsEditorAvailable())
				return;

			//Check if there is only one peg selected
			LevelEntryCollection objs = LevelEditor.GetSelectedObjects();
			if (objs.Count != 1) {
				MessageBox.Show("You must have only one movement peg selected.");
				return;
			}

			//Check if its a moving peg
			LevelEntry movementPeg = objs[0];
			if (movementPeg == null) {
				MessageBox.Show("You must have only one movement peg selected.");
				return;
			}

			//Check if the peg has moving details
			Movement movement = movementPeg.MovementInfo;
			if (movement == null) {
				MessageBox.Show("The peg must have movement properties.");
				return;
			}

			//Find out how many pegs to duplicate
			string ans = InputForm.Show("How many pegs would you like in this movement cycle, including the selected one?", "Duplicate and Phase", "8");
			int num_pegs;
			if (!Int32.TryParse(ans, out num_pegs) || num_pegs < 0 || num_pegs > 100) {
				MessageBox.Show("Invalid number of pegs.");
				return;
			}

			LevelEntryCollection entries = new LevelEntryCollection();
			entries.Add((LevelEntry)objs[0]);

			//Duplicate the peg
			for (int i = 0; i < num_pegs - 1; i++) {
				LevelEntry entry = (LevelEntry)objs[0].Clone();
				LevelEditor.Level.Entries.Add(entry);
				entries.Add(entry);
			}

			LevelEditor.ClearSelection();
			LevelEditor.SelectedEntries = entries;

			spreadPhaseRibbonButton_Click(sender, e);

			LevelEditor.UpdateRedraw();
			UpdatePropertyGrid();
		}
示例#19
0
        private void duplicateAndPhaseRibbonButton_Click(object sender, EventArgs e)
        {
            if (!IsEditorAvailable())
            {
                return;
            }

            //Check if there is only one peg selected
            LevelEntryCollection objs = LevelEditor.GetSelectedObjects();

            if (objs.Count != 1)
            {
                MessageBox.Show("You must have only one movement peg selected.");
                return;
            }

            //Check if its a moving peg
            LevelEntry movementPeg = objs[0];

            if (movementPeg == null)
            {
                MessageBox.Show("You must have only one movement peg selected.");
                return;
            }

            //Check if the peg has moving details
            Movement movement = movementPeg.MovementInfo;

            if (movement == null)
            {
                MessageBox.Show("The peg must have movement properties.");
                return;
            }

            //Find out how many pegs to duplicate
            string ans = InputForm.Show("How many pegs would you like in this movement cycle, including the selected one?", "Duplicate and Phase", "8");
            int    num_pegs;

            if (!Int32.TryParse(ans, out num_pegs) || num_pegs < 0 || num_pegs > 100)
            {
                MessageBox.Show("Invalid number of pegs.");
                return;
            }

            LevelEntryCollection entries = new LevelEntryCollection();

            entries.Add((LevelEntry)objs[0]);

            //Duplicate the peg
            for (int i = 0; i < num_pegs - 1; i++)
            {
                LevelEntry entry = (LevelEntry)objs[0].Clone();
                LevelEditor.Level.Entries.Add(entry);
                entries.Add(entry);
            }

            LevelEditor.ClearSelection();
            LevelEditor.SelectedEntries = entries;

            spreadPhaseRibbonButton_Click(sender, e);

            LevelEditor.UpdateRedraw();
            UpdatePropertyGrid();
        }
示例#20
0
		public LevelEntry[] GetObjectsIn(RectangleF rect)
		{
			LevelEntryCollection entries = new LevelEntryCollection();
			foreach (LevelEntry le in mEntries) {
				RectangleF pBounds = le.Bounds;
				if (pBounds.IntersectsWith(rect)) {
					entries.Add(le);
				}
			}

			return entries.ToArray();
		}
示例#21
0
		public LevelEntry[] GetPegsIn(RectangleF rect)
		{
			LevelEntryCollection entries = new LevelEntryCollection();
			foreach (LevelEntry le in mEntries) {
				if (le.HasPegInfo) {
					RectangleF pBounds = new RectangleF(le.X - 10, le.Y - 10, 20, 20);
					if (pBounds.IntersectsWith(rect)) {
						entries.Add(le);
					}
				} else if (le is Brick) {
					Brick b = (Brick)le;
					RectangleF bBounds = new RectangleF(b.X - (b.Width / 2), b.Y - (b.Width / 2), b.Width, b.Width);
					if (bBounds.IntersectsWith(rect)) {
						entries.Add(b);
					}
				}
			}

			return entries.ToArray();
		}
示例#22
0
        public void RotateObjects(float angle)
        {
            //Check if all objects are bricks with same geometry
            if (AreSelectedObjectsBricksWithSameGeometry())
            {
                RotateBricks(angle);
                return;
            }

            LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());

            if (objects.Count == 1)
            {
                if (objects[0] is Brick)
                {
                    CreateUndoPoint();

                    ((Brick)objects[0]).Rotation = MathExt.FixAngle(((Brick)objects[0]).Rotation + angle);

                    UpdateRedraw();
                }
                return;
            }

            if (objects.Count < 2)
            {
                return;
            }

            CreateUndoPoint();

            //Get resize rect
            float left   = float.MaxValue;
            float top    = float.MaxValue;
            float right  = float.MinValue;
            float bottom = float.MinValue;

            foreach (LevelEntry obj in objects)
            {
                if (left > obj.X)
                {
                    left = obj.X;
                }
                if (right < obj.X)
                {
                    right = obj.X;
                }
                if (top > obj.Y)
                {
                    top = obj.Y;
                }
                if (bottom < obj.Y)
                {
                    bottom = obj.Y;
                }
            }

            float width  = right - left;
            float height = bottom - top;

            Matrix matrix = new Matrix();

            matrix.RotateAt(angle, new PointF(left + (width / 2.0f), top + (height / 2.0f)));

            foreach (LevelEntry obj in objects)
            {
                PointF[] pnts = new PointF[] { new PointF(obj.X, obj.Y) };
                matrix.TransformPoints(pnts);
                obj.X = pnts[0].X;
                obj.Y = pnts[0].Y;

                if (obj is Brick)
                {
                    Brick brick = (Brick)obj;
                    brick.Rotation  = MathExt.FixAngle(brick.Rotation);
                    brick.Rotation -= angle;
                }
            }

            UpdateRedraw();
        }
示例#23
0
		public void RotateObjects(float angle)
		{
			//Check if all objects are bricks with same geometry
			if (AreSelectedObjectsBricksWithSameGeometry()) {
				RotateBricks(angle);
				return;
			}

			LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());
			if (objects.Count == 1) {
				if (objects[0] is Brick) {
					CreateUndoPoint();

					((Brick)objects[0]).Rotation = MathExt.FixAngle(((Brick)objects[0]).Rotation + angle);

					UpdateRedraw();	
				}
				return;
			}

			if (objects.Count < 2)
				return;

			CreateUndoPoint();

			//Get resize rect
			float left = float.MaxValue;
			float top = float.MaxValue;
			float right = float.MinValue;
			float bottom = float.MinValue;

			foreach (LevelEntry obj in objects) {
				if (left > obj.X)
					left = obj.X;
				if (right < obj.X)
					right = obj.X;
				if (top > obj.Y)
					top = obj.Y;
				if (bottom < obj.Y)
					bottom = obj.Y;
			}

			float width = right - left;
			float height = bottom - top;

			Matrix matrix = new Matrix();
			matrix.RotateAt(angle, new PointF(left + (width / 2.0f), top + (height / 2.0f)));

			foreach (LevelEntry obj in objects) {
				PointF[] pnts = new PointF[] { new PointF(obj.X, obj.Y) };
				matrix.TransformPoints(pnts);
				obj.X = pnts[0].X;
				obj.Y = pnts[0].Y;

				if (obj is Brick) {
					Brick brick = (Brick)obj;
					brick.Rotation = MathExt.FixAngle(brick.Rotation);
					brick.Rotation -= angle;
				}
			}

			UpdateRedraw();
		}
示例#24
0
		public void RemoveOffscreenObjects()
		{
			bool firstOne = true;
			LevelEntryCollection removes = new LevelEntryCollection();
			RectangleF insideRect = RectangleF.FromLTRB(-Level.DrawAdjustX, -Level.DrawAdjustY, 800 - Level.DrawAdjustX, 600 - Level.DrawAdjustY);
			foreach (LevelEntry o in mLevel.Entries) {
				PointF pegPnt = new PointF(o.X, o.Y);

				if (!insideRect.Contains(pegPnt)) {
					if (firstOne) {
						CreateUndoPoint();
						firstOne = false;
					}

					removes.Add((LevelEntry)o);
				}
			}

			foreach (LevelEntry le in removes) {
				le.OnDelete();
				mLevel.Entries.Remove(le);
			}

			UpdateRedraw();

			CheckSelectionChanged();

		}
示例#25
0
		public void FlipObjectsHorizontally()
		{
			CreateUndoPoint();

			LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());
			if (objects.Count < 2)
				return;

			objects.Sort(new Comparison<LevelEntry>(CompareObjectsByX));

			float startX = objects[0].X;
			float width = objects[objects.Count - 1].X - objects[0].X;

			foreach (LevelEntry o in objects) {
				o.X = (startX + width) - (o.X - startX);

				if (o is Brick) {
					Brick brick = (Brick)o;
					brick.Rotation = MathExt.FixAngle(brick.Rotation);

					if (brick.Rotation < 180.0f)
						brick.Rotation = 180.0f - brick.Rotation;
					else
						brick.Rotation = 540.0f - brick.Rotation;
				}
			}

			UpdateRedraw();
		}
示例#26
0
		public void FlipPegsVertically()
		{
			CreateUndoPoint();

			LevelEntryCollection objects = new LevelEntryCollection(GetSelectedObjects());
			if (objects.Count < 2)
				return;

			objects.Sort(new Comparison<LevelEntry>(CompareObjectsByY));

			float startY = objects[0].Y;
			float height = objects[objects.Count - 1].Y - objects[0].Y;

			foreach (LevelEntry o in objects) {
				o.Y = (startY + height) - (o.Y - startY);

				if (o is Brick) {
					Brick brick = (Brick)o;
					brick.Rotation = MathExt.FixAngle(brick.Rotation);
					brick.Rotation = 360.0f - brick.Rotation;
				}
			}

			UpdateRedraw();
		}