public void AddComponent(BaseComponent.ComponentType type, Point?location) { _selectorMode = false; ClearComponent(); _currentComponent = BaseComponent.Create(type, _canvas); _currentComponent.OnComponentActionCompleted = OnComponentActionCompleted; _currentComponent.OnComponentActionUpdated = OnComponentActionUpdated; // now try and see what the last component of this type has for options and copy it over var lastComponent = FindLastComponent(type); _currentComponent.CopyOptions(lastComponent); _currentComponent.Color = ActiveColor; if (location != null) { _currentComponent.SetLocation((float)location.Value.X, (float)location.Value.Y); } var currrentHighestDisplayPriority = _components?.OrderByDescending(c => c.DisplayOrder).FirstOrDefault()?.DisplayOrder; _currentComponent.DisplayOrder = (currrentHighestDisplayPriority ?? 0) + 1; ComponentSelected?.Invoke(); _canvas.Invalidate(); }
private BaseComponent FindLastComponent(BaseComponent.ComponentType type) { for (var i = _components.Count - 1; i >= 0; i--) { var c = _components[i]; if (c.Type == type) { return(c); } } return(null); }