#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab 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. * * HeuristicLab 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 HeuristicLab. If not, see . */ #endregion using System; using System.Drawing; using System.Windows.Forms; namespace HeuristicLab.Visualization { public abstract class PrimitiveBase : IPrimitive { private readonly IChart chart; public IChart Chart { get { return chart; } } private Pen pen; public virtual Pen Pen { get { return pen; } set { pen = value; OnRedrawRequired(); } } private Brush brush; public virtual Brush Brush { get { return brush; } set { brush = value; OnRedrawRequired(); } } public string ToolTipText { get; set; } public object Tag { get; set; } protected bool SuppressEvents { get; set; } private bool selected; public virtual bool Selected { get { return selected; } set { if (selected == value) return; selected = value; OnRedrawRequired(); } } protected PrimitiveBase(IChart chart) : this(chart, Pens.Black, Brushes.White) { } protected PrimitiveBase(IChart chart, Pen pen, Brush brush) { this.chart = chart; this.pen = pen; this.brush = brush; selected = false; ToolTipText = null; Tag = null; } public abstract void Move(Offset delta); public abstract void Move(PointD point, Offset delta); public abstract void SnapToGrid(IGrid grid); public abstract void SnapToGrid(PointD point, IGrid grid); public abstract bool ContainsPoint(PointD point); public virtual Cursor GetCursor(PointD point) { return null; } public virtual string GetToolTipText(PointD point) { return ToolTipText; } public virtual void PreDraw(Graphics graphics) { } public virtual void Draw(Graphics graphics) { } public virtual void PostDraw(Graphics graphics) { } public event EventHandler RedrawRequired; protected virtual void OnRedrawRequired() { var handler = RedrawRequired; if (!SuppressEvents && handler != null) handler(this, EventArgs.Empty); } } }