using Newtonsoft.Json; namespace Pilz.UI; public class PaintingObjectLayering { // private readonly PaintingObject _PaintingObject; [JsonIgnore] public PaintingObject PaintingObject { get { return _PaintingObject; } } /// /// Get the current object list from the painting object. /// /// Returns the current object list from the painting object. [JsonIgnore] public PaintingObjectList ObjectList { get { return PaintingObject.Parent.PaintingObjects; } } /// /// Create a new instance of object layer managing. /// /// public PaintingObjectLayering(PaintingObject obj) { _PaintingObject = obj; } /// /// Moves the object by the given number of indicies. /// /// The number how many objects it should be moved. public void MoveObject(int count) { int oldIndex = ObjectList.IndexOf(PaintingObject); int newIndex = oldIndex + count; MoveObjectTo(newIndex); } /// /// Moves the object to the new index. /// /// public void MoveObjectTo(int newIndex) { var list = ObjectList; // Check & make index valid if (newIndex >= ObjectList.Count) newIndex = ObjectList.Count - 1; else if (newIndex < 0) { newIndex = 0; } // Remove object list.Remove(PaintingObject); // Insert object at new index list.Insert(newIndex, PaintingObject); // Order all objects again list.Layering.OrderAll(); } /// /// Moves the object to the front. /// public void BringToTop() { MoveObjectTo(ObjectList.Count - 1); } /// /// Moves the object to the back. /// public void SendToBack() { MoveObjectTo(0); } /// /// Moves the object fordward by one /// public void OneToTop() { MoveObject(+1); } /// /// Moves the object backward by one /// public void OneToBack() { MoveObject(-1); } }