/// <summary> /// Adds a new layer control for a given frame layer /// </summary> /// <param name="layer">The layer to create the layer control out of</param> /// <param name="arrangeAfter">Whether to call the ArrangeControls method after adding the control</param> private void AddLayerControl(IFrameLayer layer, bool arrangeAfter = true) { var control = new LayerControl(layer); control.LayerClicked += OnLayerControlClicked; control.LayerStatusChanged += OnLayerStatusChanged; control.DuplicateLayerSelected += OnDuplicateLayerSelected; control.RemoveLayerSelected += OnRemoveLayerSelected; control.LayerControlDragged += OnLayerControlDragged; control.LayerNameEdited += OnLayerNameEdited; control.LayerCollapeChanged += OnLayerCollapseChanged; control.LayerImagePressed += OnLayerImagePressed; control.LayerImageReleased += OnLayerImageReleased; _layerControls.Insert(layer.Index, control); pnl_container.Controls.Add(control); if (arrangeAfter) { ArrangeControls(); } ClearSelection(); }
public ApplicationLayer(ApiTypes apiType, ISessionLayer sessionLayer, IFrameLayer frameLayer, ITransportLayer transportLayer) { ApiType = apiType; SessionLayer = sessionLayer; FrameLayer = frameLayer; TransportLayer = transportLayer; }
/// <summary> /// Adds the specified layer at a specified index /// </summary> /// <param name="layer">The layer to add</param> /// <param name="index">The index to add the layer at</param> public void AddLayer(IFrameLayer layer, int index = -1) { BeforeLayerCreated?.Invoke(this, new EventArgs()); _frame.AddLayer(layer, index); LayerCreated?.Invoke(this, new LayerControllerLayerCreatedEventArgs(layer)); }
/// <summary> /// Saves the contents of a layer to a stream /// </summary> /// <param name="layer">The layer to save</param> /// <param name="stream">The stream to save the layer to</param> private void SaveLayerToStream(IFrameLayer layer, Stream stream) { // Save the layer's name BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8); writer.Write(layer.Name); PersistenceHelper.SaveImageToStream(layer.LayerBitmap, stream); }
/// <summary> /// Adds a layer with a specified bitmap at the specified index /// </summary> /// <param name="bitmap">The bitmap to use as a layer</param> /// <param name="index">The index to add the layer at</param> /// <returns>The layer that was created</returns> public IFrameLayer AddLayer(Bitmap bitmap, int index = -1) { BeforeLayerCreated?.Invoke(this, new EventArgs()); IFrameLayer layer = _frame.AddLayer(bitmap, index); LayerCreated?.Invoke(this, new LayerControllerLayerCreatedEventArgs(layer)); return(layer); }
/// <summary> /// Creates a layer at the specified index /// </summary> /// <param name="layerIndex">The index at which to create the layer</param> public IFrameLayer CreateLayer(int layerIndex = -1) { BeforeLayerCreated?.Invoke(this, new EventArgs()); IFrameLayer layer = _frame.CreateLayer(layerIndex); LayerCreated?.Invoke(this, new LayerControllerLayerCreatedEventArgs(layer)); return(layer); }
/// <summary> /// Initializes a new instance of the LayerControl class /// </summary> /// <param name="layer">The layer this control will bind to</param> public LayerControl(IFrameLayer layer) { InitializeComponent(); _layer = layer; // Update startup values _layerVisible = true; _layerLocked = false; _transparency = 1.0f; UpdateDisplay(); }
public void TestLayerReinserting() { Frame frame1 = FrameGenerator.GenerateRandomFrame(64, 64, 10); Frame frame2 = frame1.Clone(); IFrameLayer layer = frame2.GetLayerAt(0); frame2.RemoveLayerAt(0, false); frame2.AddLayer(layer, 0); Assert.AreEqual(frame1, frame2, "After removing and readding a layer back to its original place, the frame structure must be considered unchanged"); }
/// <summary> /// Removes a layer that is at the specified index /// </summary> /// <param name="layerIndex">The index of the layer to remove</param> /// <param name="dispose">Whether to dispose of the layer that was removed</param> public void RemoveLayer(int layerIndex, bool dispose = true) { IFrameLayer layer = _frame.GetLayerAt(layerIndex); BeforeLayerRemoved?.Invoke(this, new LayerControllerLayerRemovedEventArgs(layer)); _frame.RemoveLayerAt(layerIndex, dispose); // Normalize active layer _activeLayerIndex = ActiveLayerIndex; LayerRemoved?.Invoke(this, new LayerControllerLayerRemovedEventArgs(layer)); }
public void TestLayerIndexing() { Frame frame = FrameGenerator.GenerateRandomFrame(64, 64, 5, 1); frame.AddLayer(FrameGenerator.GenerateRandomBitmap(64, 64, 2)); IFrameLayer layer = frame.CreateLayer(); Assert.AreEqual(0, frame.GetLayerAt(0).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(1, frame.GetLayerAt(1).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, frame.GetLayerAt(2).Index, "Layers fetched with GetLayerAt() must have an index that match the parameter passed"); Assert.AreEqual(2, layer.Index, "Layers returned by calls to AddLayer() and CreateLayer() must have an index that match the 'index' parameter passed"); }
public void TestLayerRemoval() { // Create a frame Frame frame = new Frame(null, 64, 64); Bitmap bitmap = FrameGenerator.GenerateRandomBitmap(64, 64, 10); frame.CreateLayer(); // Swap the layers frame.SetLayerBitmap(1, bitmap); IFrameLayer layer = frame.GetLayerAt(0); frame.RemoveLayerAt(0); // Test layer swapping by comparing the bitmaps Assert.AreEqual(null, layer.Frame, "After removing a layer from a frame, its Frame reference must be null"); Assert.IsTrue(ImageUtilities.ImagesAreIdentical(bitmap, frame.GetLayerAt(0).LayerBitmap), "The layer does not appear to have been correctly removed"); }
/// <summary> /// Loads a single layer from a specified stream /// </summary> /// <param name="frame">The frame to load the layer into</param> /// <param name="stream">The stream to load the layer from</param> private void LoadLayerFromStream(Frame frame, Stream stream) { // Load the layer's name string name = null; if (blockVersion >= 2) { BinaryReader reader = new BinaryReader(stream, Encoding.UTF8); name = reader.ReadString(); } Bitmap layerBitmap = PersistenceHelper.LoadImageFromStream(stream); IFrameLayer layer = frame.AddLayer(layerBitmap); // Add the attributes that were loaded earlier if (name != null) { layer.Name = name; } }
/// <summary> /// Duplicates the specified layer index /// </summary> /// <param name="layerIndex">The layer to duplicate</param> /// <returns>An IFrameLayer for the newly duplicated layer</returns> public IFrameLayer DuplicateLayer(int layerIndex) { BeforeLayerDuplicated?.Invoke(this, new LayerControllerLayerDuplicatedEventArgs(layerIndex)); // Duplicate the layer up IFrameLayer layer = _frame.GetLayerAt(layerIndex).Clone(); // Use the class' AddLayer method to take advantage of the event firing if (layerIndex == _frame.LayerCount - 1) { AddLayer(layer); } else { AddLayer(layer, layerIndex + 1); } LayerDuplicated?.Invoke(this, new LayerControllerLayerDuplicatedEventArgs(layerIndex)); return(layer); }
/// <summary> /// Adds the specified layer to this Frame object. /// If the layer's size does not match this frame's dimensions, an exception is raised. /// If the layer's type does not match the internal layer type (or, the layer does not originates from a CreateLayer/AddLayer/GetLayerAt from this object), an exception is raised /// </summary> /// <param name="layer">The layer to add to this frame</param> /// <param name="layerIndex">The index at which to add the layer</param> /// <exception cref="ArgumentException"> /// The provided layers's dimensions does not match this Frame's dimensions, or the provided layers's type /// is not compatible with this Frame object, or the provided layer is already stored in a Frame object /// </exception> public void AddLayer(IFrameLayer layer, int layerIndex = -1) { if (!_initialized) { throw new InvalidOperationException("The frame was not initialized prior to this action"); } if (layer.Width != _width || layer.Height != _height) { throw new ArgumentException(@"The provided layer's dimensions must match the size of this frame", nameof(layer)); } if (layer.Frame != null) { throw new ArgumentException("The specified layer is already stored in a Frame object"); } var frameLayer = layer as FrameLayer; if (frameLayer == null) { throw new ArgumentException("The provided layers's type is not compatible with this Frame object"); } if (layerIndex == -1 || layerIndex == _layers.Count) { _layers.Add(frameLayer); } else { _layers.Insert(layerIndex, frameLayer); } frameLayer.Frame = this; UpdateLayerIndices(); }
public TextApplicationLayer(ISessionLayer sessionLayer, IFrameLayer frameLayer, ITransportLayer transportLayer) : base(ApiTypes.Text, sessionLayer, frameLayer, transportLayer) { }
/// <summary> /// Initializes a new instance of the LayerControllerLayerNameUpdatedEventArgs class /// </summary> /// <param name="frameLayer">The layer that was updated</param> /// <param name="oldLayerName">Gets the old name before the layer name was updated</param> public LayerControllerLayerNameUpdatedEventArgs(IFrameLayer frameLayer, string oldLayerName) { FrameLayer = frameLayer; OldLayerName = oldLayerName; }
/// <summary> /// Initializes a new instance of the LayerControllerLayerImageUpdatedEventArgs class /// </summary> /// <param name="frameLayer">The layer that was updated</param> /// <param name="oldLayerBitmap">The old layer bitmap before the layer image was updated</param> public LayerControllerLayerImageUpdatedEventArgs(IFrameLayer frameLayer, Bitmap oldLayerBitmap) { FrameLayer = frameLayer; OldLayerBitmap = oldLayerBitmap; }
/// <summary> /// Initializes a new instance of the LayerControllerLayerRemovedEventArgs class /// </summary> /// <param name="frameLayer">The layer that was removed</param> public LayerControllerLayerRemovedEventArgs(IFrameLayer frameLayer) { FrameLayer = frameLayer; }
/// <summary> /// Initializes a new instance of the LayerControllerLayerCreatedEventArgs class /// </summary> /// <param name="frameLayer">The frame layer that was created</param> public LayerControllerLayerCreatedEventArgs(IFrameLayer frameLayer) { FrameLayer = frameLayer; }
/// <summary> /// Gets the layer control for the specified layer, or null, if none was found /// </summary> /// <param name="layer">A valid IFrameLayer that is currently registered on this layer control panel</param> /// <returns>The layer control for the specified layer, or null, if none was found</returns> private LayerControl GetLayerControlForLayer(IFrameLayer layer) { return(_layerControls.FirstOrDefault(control => ReferenceEquals(control.Layer, layer))); }
public XModemApplicationLayer(ISessionLayer sessionLayer, IFrameLayer frameLayer, ITransportLayer transportLayer) : base(ApiTypes.XModem, sessionLayer, frameLayer, transportLayer) { }
public BasicApplicationLayer(ISessionLayer sessionLayer, IFrameLayer frameLayer, ITransportLayer transportLayer) : base(ApiTypes.Basic, sessionLayer, frameLayer, transportLayer) { }