using System; using System.Collections.Generic; using System.Drawing; using System.Text.Json; using System.Xml; namespace CoreUnit.Control.UserControl.Canvas { public class BackgroundLayer : ICanvasLayer, ISerialize { int m_no = 0; SolidBrush m_backgroundBrush; SolidBrush m_fieldBrush; Color m_color = Color.Black; Color m_backgroundColor = Color.White; Color m_fieldColor = Color.Black; public Color Color { get { return m_color; } set { m_color = value; m_backgroundBrush = new SolidBrush(m_color); } } public BackgroundLayer() { m_backgroundBrush = new SolidBrush(m_color); } public Color BackgroundColor { get { return m_backgroundColor; } set { m_color = value; m_backgroundColor = value; m_backgroundBrush = new SolidBrush(m_backgroundColor); } } public Color FieldColor { get { return m_fieldColor; } set { m_fieldColor = value; m_fieldBrush = new SolidBrush(m_fieldColor); } } #region ICanvasLayer Members public void Draw(ICanvas canvas, RectangleF unitrect) { //// 백그라운드 그림 RectangleF r = ScreenUtils.ToScreenNormalized(canvas, unitrect); BackgroundColor = m_backgroundColor; canvas.Graphics.FillRectangle(m_backgroundBrush, r); //// 특정 영역 선택 unitrect = SetSpecificRange(unitrect, canvas.BackgroundSize); //// 필드 그림 r = ScreenUtils.ToScreenNormalized(canvas, unitrect); FieldColor = m_fieldColor; canvas.Graphics.FillRectangle(m_fieldBrush, r); } public PointF SnapPoint(PointF unitmousepoint) { return PointF.Empty; } public int No { get { return m_no; } set { m_no = value; } } ISnapPoint ICanvasLayer.SnapPoint(ICanvas canvas, UnitPoint point, List otherobj) { throw new Exception("The method or operation is not implemented."); } public List Objects { get { return null; } } public bool Enabled { get { return false; } set {; } } public bool Visible { get { return true; } set {; } } public SizeF Spacing { get { return new SizeF(10, 10); } set { } } #endregion #region ISerialize Interface public void GetObjectData(XmlWriter wr) { wr.WriteStartElement("backgroundlayer"); Common.XmlUtil.WriteProperties(this, wr); wr.WriteEndElement(); } public virtual string GetObjectData() { string jsonString = string.Empty; var options = new JsonSerializerOptions { WriteIndented = true }; try { jsonString += JsonSerializer.Serialize(this, options); } catch { } return jsonString; } public void AfterSerializedIn() { } #endregion public RectangleF SetSpecificRange(RectangleF Unitrect, float range) { RectangleF unitrect = Unitrect; //// 우리가 정한 구역은 흰색으로 float maxValue = range / 2, minValue = -range / 2; if (unitrect.X + unitrect.Width > maxValue && unitrect.X < minValue) { unitrect.X = minValue; unitrect.Width = maxValue - minValue; } else if (unitrect.X + unitrect.Width > maxValue) { unitrect.Width = maxValue - unitrect.X; } else if (unitrect.X < minValue) { unitrect.Width = unitrect.X + unitrect.Width - minValue; unitrect.X = minValue; } //else; if (unitrect.Y + unitrect.Height > maxValue && unitrect.Y < minValue) { unitrect.Y = minValue; unitrect.Height = maxValue - minValue; } else if (unitrect.Y + unitrect.Height > maxValue) unitrect.Height = maxValue - unitrect.Y; else if (unitrect.Y < minValue) { unitrect.Height = unitrect.Y + unitrect.Height - minValue; unitrect.Y = minValue; } //else; return unitrect; } public void Copy(BackgroundLayer org) { FieldColor = org.FieldColor; BackgroundColor = org.BackgroundColor; Enabled = org.Enabled; Color = org.Color; No = org.No; Spacing = org.Spacing; Visible = org.Visible; } } }