using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SCJMapper_V2.Layout { /// /// Controller Input /// contains a text to display at a position within a rectangle /// class ShapeItem : IShape { /// /// The Text Shown in the Map /// public string DispText { get; set; } /// /// Location Left /// public int X { get; set; } = 0; /// /// Location Top /// public int Y { get; set; } = 0; /// /// Width /// public int Width { get; set; } = 0; /// /// Height /// public int Height { get; set; } = 0; public Point Location { get { return new Point( X, Y ); } set { X = value.X; Y = value.Y; } } public Size Size { get { return new Size( Width, Height ); } set { Width = value.Width; Height = value.Height; } } public Rectangle Rectangle { get { return new Rectangle( X, Y, Width, Height ); } set { X = value.X; Y = value.Y; Width = value.Width; Height = value.Height; } } public bool IsValid { get => !string.IsNullOrEmpty( DispText ); } private Brush m_textBrush = Brushes.Black; private Color m_textColor = Color.DarkBlue; private Brush m_backBrush = Brushes.White; private Color m_backColor = Color.White; /// /// Set the Textcolor /// public Color TextColor { get => m_textColor; set { m_textColor = value; m_textBrush.Dispose( ); m_textBrush = new SolidBrush( m_textColor ); // set the text brush as well } } /// /// Set the Textcolor /// public Color BackColor { get => m_backColor; set { m_backColor = value; m_backBrush.Dispose( ); m_backBrush = new SolidBrush( m_backColor ); // set the text brush as well } } /// /// Returns the drawn text size for this item /// /// /// public SizeF MeasureShape( Graphics g ) { return g.MeasureString( DispText, MapProps.MapFont ); } #region IShape Implementation /// /// Draws the shape /// public void DrawShape( Graphics g ) { if ( IsValid ) { if ( m_backColor!= Color.White ) { g.FillRectangle( m_backBrush, Rectangle ); } g.DrawString( DispText, MapProps.MapFont, m_textBrush, Rectangle ); // write into the rectangle } } /// /// Sets X,Y from Mouse location - shape is centered /// /// public void SetMouseLocation( Point loc ) { } /// /// Returns true if the item contains the location /// /// A location point /// True if the location is with the item area public bool HitTest( Point location ) { return new Rectangle( X, Y, Width, Height ).Contains( location ); } /// /// Offset of click location vs. middle of the rectangle /// to move it seamlessly /// /// Click location /// Movement offset public Point ClickOffset( Point location ) { return new Point( -( location.X - X - Width / 2 ), -( location.Y - Y - Height / 2 ) ); } #endregion } }