// // Component.cs - represents a component in a component designer layout // // Author: // Michael Becker // // Copyright (c) 2011-2020 Mike Becker's Software // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . using System; using MBS.Framework.Drawing; using UniversalEditor.ObjectModels.Multimedia.Picture; using UniversalEditor.Plugins.Multimedia.UserInterface; namespace UniversalEditor.ObjectModels.Designer { /// /// Represents a component in a component designer layout. /// public class Component : ICloneable { public class ComponentCollection : System.Collections.ObjectModel.Collection { public Component this[Guid id] { get { for (int i = 0; i < Count; i++) { if (this[i].ID == id) return this[i]; } return null; } } } public Component(Guid id, string title, Property[] properties = null, Action renderDelegate = null) { ID = id; Title = title; if (properties != null) { for (int i = 0; i < properties.Length; i++) Properties.Add(properties[i]); } if (renderDelegate != null) RenderDelegate += renderDelegate; } /// /// Gets or sets the globally-unique identifier for this . /// /// The globally-unique identifier for this . public Guid ID { get; set; } = Guid.Empty; /// /// Gets or sets the title of this . /// /// The title of this . public string Title { get; set; } = String.Empty; public event Action RenderDelegate = null; public void Render(ComponentInstance instance, MBS.Framework.UserInterface.PaintEventArgs e, Rectangle bounds) { RenderDelegate?.Invoke(instance, e, bounds); } /// /// Gets a collection of instances representing properties associated with this . /// /// The properties associated with this . public Property.PropertyCollection Properties { get; } = new Property.PropertyCollection(); public object Clone() { Component clone = new Component(ID, (Title.Clone() as string)); clone.RenderDelegate = RenderDelegate; return clone; } } }