using System; using System.Data; using System.Drawing; using System.Drawing.Drawing2D; using Projects; using System.Windows.Forms; using Data.BusinessService; using Data.DataModel; namespace ControlLibrary { public partial class LayerControl : UserControl { //Check radius for begin drag n drop public bool AllowDrag { get; set; } private bool _isDragging = false; private int _DDradius = 40; private int _mX = 0; private int _mY = 0; private int _StatusBarColorIndex = 0; private string _LayerName = "Default"; private ILayerService layerService; private Layer _layerObj; private LayerModel layerModel; public delegate void ArrowUpClicked(LayerControl sender, EventArgs e); public delegate void ArrowDownClicked(LayerControl sender, EventArgs e); public delegate void DoubleClicked(LayerControl sender, EventArgs e); public delegate void CancelClicked(LayerControl sender, EventArgs e); public event ArrowUpClicked OnArrowUpClicked; public event ArrowDownClicked OnArrowDownClicked; public event DoubleClicked OnDoubleClicked; public event CancelClicked OnCancelClicked; public LayerControl() { InitializeComponent(); UpdateTitleBar(); UpdateStatusBar(); UpdateLeftSideBar(); UpdateRightSideBar(); UpdateBtnCancel(); UpdateToggleSwitchButton(); UpdateArrowUp(); UpdateArrowDown(); this.layerService = new LayerService(); AllowDrag = true; } #region properties /// /// ColorIndex. [0 - Treko] [1 - Diamond] [2 - ...] [3 - ...]. /// public int StatusBarColor { get { return _StatusBarColorIndex; } set { switch (value) { case 0: // Raw active leftSideBarPanel.BackColor = Color.OliveDrab; break; case 1: // Raw inactive leftSideBarPanel.BackColor = Color.Goldenrod; break; case 2: // Dry active leftSideBarPanel.BackColor = Color.DimGray; break; case 3: // Dry inactive leftSideBarPanel.BackColor = Color.DimGray; break; default: leftSideBarPanel.BackColor = Color.DimGray; break; } } } public string LayerName { get { return _LayerName; } set { _LayerName = value; this.lblLayerName.Text = _LayerName; } } public Layer LayerObj { get { return _layerObj; } set { _layerObj = value; } } public ILayerService LayerService { get { return layerService; } set { layerService = value; } } public LayerModel LayerModel { get { return layerModel; } set { layerModel = value; } } #endregion private void RefreshControl(LayerModel layerModel) { _layerObj.Id = layerModel.Id; LayerName = _layerObj.LayerName = layerModel.LayerName; _layerObj.OpticalSchema = layerModel.OpticalSchema; _layerObj.Order = layerModel.Order; _layerObj.ProjectId = layerModel.ProjectId; _layerObj.TechnologyName = layerModel.TechnologyName; _layerObj.TraceProfile = layerModel.TraceProfile; _layerObj.LayerLeft = layerModel.LayerLeft; _layerObj.LayerTop = layerModel.LayerTop; _layerObj.LayerWidth = layerModel.LayerWidth; _layerObj.LayerHeight = layerModel.LayerHeight; _layerObj.ArcWidth = layerModel.ArcWidth; _layerObj.RadiusMax = layerModel.RadiusMax; _layerObj.Step = layerModel.Step; _layerObj.SourceFilePath = layerModel.SourceFilePath; _layerObj.AnglesFilePath = layerModel.AnglesFilePath; } public void ReloadControl() { int layerId = 0; if (_layerObj != null && _layerObj.Id != 0) layerId = _layerObj.Id; else if (layerModel != null && layerModel.Id != 0) layerId = layerModel.Id; if (layerId == 0) return; DataRow row = layerService.GetLayerById(layerId); layerModel.Id = Convert.ToInt16(row["Id"]); layerModel.Order = Convert.ToInt16(row["Order"]); layerModel.LayerName = row["LayerName"].ToString(); layerModel.OpticalSchema = row["OpticalSchema"].ToString(); layerModel.ProjectId = Convert.ToInt16(row["ProjectId"]); layerModel.TechnologyName = row["TechnologyName"].ToString(); layerModel.LayerLeft = Convert.ToSingle(row["LayerLeft"]); layerModel.LayerTop = Convert.ToSingle(row["LayerTop"]); layerModel.LayerWidth = Convert.ToSingle(row["LayerWidth"]); layerModel.LayerHeight = Convert.ToSingle(row["LayerHeight"]); layerModel.ArcWidth = Convert.ToInt16(row["ArcWidth"]); layerModel.RadiusMax = Convert.ToSingle(row["RadiusMax"]); layerModel.Step = Convert.ToSingle(row["Step"]); layerModel.SourceFilePath = row["SourceFilePath"].ToString(); layerModel.AnglesFilePath = row["AnglesFilePath"].ToString(); RefreshControl(layerModel); } #region events protected override void OnGotFocus(EventArgs e) { //this.BackColor = Color.SandyBrown; this.BackColor = Color.Transparent; base.OnGotFocus(e); } protected override void OnLostFocus(EventArgs e) { this.BackColor = Color.Transparent; base.OnLostFocus(e); } protected override void OnClick(EventArgs e) { this.Focus(); base.OnClick(e); } protected override void OnMouseDown(MouseEventArgs e) { this.Focus(); base.OnMouseDown(e); _mX = e.X; _mY = e.Y; this._isDragging = false; } protected override void OnMouseMove(MouseEventArgs e) { if (!_isDragging) { // This is a check to see if the mouse is moving while pressed. // Without this, the DragDrop is fired directly when the control is clicked, now you have to drag a few pixels first. if (e.Button == MouseButtons.Left && _DDradius > 0 && this.AllowDrag) { int num1 = _mX - e.X; int num2 = _mY - e.Y; if (((num1 * num1) + (num2 * num2)) > _DDradius) { DoDragDrop(this, DragDropEffects.All); _isDragging = true; return; } } base.OnMouseMove(e); } } protected override void OnMouseUp(MouseEventArgs e) { _isDragging = false; base.OnMouseUp(e); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); paintThisShit(e.Graphics); } private void btnCancel_Click(object sender, EventArgs e) { FlowLayoutPanel flp = (FlowLayoutPanel)this.Parent; OnCancelClicked?.Invoke(this, EventArgs.Empty); flp.Invalidate(); } private void btnArrowUp_Click(object sender, EventArgs e) { FlowLayoutPanel flp = (FlowLayoutPanel)this.Parent; ControlCollection innerList = flp.Controls; int index = innerList.GetChildIndex(this, false); index = 0; innerList.SetChildIndex(this, index); //if (OnArrowUpClicked != null) OnArrowUpClicked?.Invoke(this, EventArgs.Empty); flp.Invalidate(); //MessageBox.Show("Up"); } private void btnArrowDown_Click(object sender, EventArgs e) { FlowLayoutPanel flp = (FlowLayoutPanel)this.Parent; ControlCollection innerList = flp.Controls; int index = innerList.GetChildIndex(this, false); index = innerList.Count - 1; innerList.SetChildIndex(this, index); OnArrowDownClicked?.Invoke(this, EventArgs.Empty); flp.Invalidate(); // MessageBox.Show("Down"); } private void LayerControl_DoubleClick(object sender, EventArgs e) { //FlowLayoutPanel flp = (FlowLayoutPanel)this.Parent; //SplitterPanel splitterPanel = (SplitterPanel)flp.Parent.Parent; //SplitContainer splitContainer = (SplitContainer)splitterPanel.Parent; LayerControl layerControl = (LayerControl)sender; //layerControl.RefreshControl(layerModel); //string layerName = layerControl.LayerName; OnDoubleClicked?.Invoke(this, EventArgs.Empty); //Control[] cnt = this.ParentForm.Controls.Find("splitContainer1", true); //SplitContainer splitContainer = (SplitContainer)cnt[0]; //if (splitContainer.Panel1Collapsed == true) // splitContainer.Panel1Collapsed = false; //else // splitContainer.Panel1Collapsed = true; } #endregion public void paintThisShit(Graphics _graphics) { } private void UpdateTitleBar() { Point[] pts = { new Point(0, 0), new Point(217, 0), new Point(202, 15), new Point(15, 15), new Point(0, 0) }; //g.FillPath(lgb,XButtonBox); // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); titleBarPanel.Region = polygon_region; // Make the button big enough to hold the whole region. titleBarPanel.SetBounds( titleBarPanel.Location.X, titleBarPanel.Location.Y, 217, 15); } private void UpdateStatusBar() { Point[] pts = { new Point(15, 0), new Point(202, 0), new Point(217, 15), new Point(0, 15), new Point(15, 0) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); statusBarPanel.Region = polygon_region; // Make the button big enough to hold the whole region. statusBarPanel.SetBounds( statusBarPanel.Location.X, statusBarPanel.Location.Y + 1, 217, 15); } private void UpdateLeftSideBar() { Point[] pts = { new Point(0, 0), new Point(15, 15), new Point(15, 53), new Point(0, 68), new Point(0, 0) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); leftSideBarPanel.Region = polygon_region; // Make the button big enough to hold the whole region. leftSideBarPanel.SetBounds( leftSideBarPanel.Location.X, leftSideBarPanel.Location.Y, 15, 83); } private void UpdateRightSideBar() { Point[] pts = { new Point(0, 15), new Point(15, 0), new Point(15, 83), new Point(0, 68), new Point(0, 15) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //rightSideBarPanel.Region = polygon_region; // Make the button big enough to hold the whole region. rightSideBarPanel.SetBounds( rightSideBarPanel.Location.X, rightSideBarPanel.Location.Y, 15, 83); } private void UpdateBtnCancel() { Point[] pts = { new Point(13, 0), new Point(31, 0), new Point(16, 15), new Point(0, 15), new Point(13, 0) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnCancel.Region = polygon_region; // Make the button big enough to hold the whole region. btnCancel.SetBounds( btnCancel.Location.X, btnCancel.Location.Y, 30, 15); } private void UpdateToggleSwitchButton() { Point[] pts = { new Point(14, 0), new Point(45, 0), new Point(30, 17), new Point(0, 17), new Point(14, 0) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd toggleBlockBtn.Region = polygon_region; // Make the button big enough to hold the whole region. toggleBlockBtn.SetBounds( toggleBlockBtn.Location.X, toggleBlockBtn.Location.Y, 45, 17); } private void UpdateArrowUp() { Point[] pts = { new Point(0, 10), new Point(5, 0), new Point(10, 10), new Point(7, 10), new Point(7, 20), new Point(3, 20), new Point(3, 10), new Point(0, 10) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnArrowUp.Region = polygon_region; // Make the button big enough to hold the whole region. btnArrowUp.SetBounds( btnArrowUp.Location.X, btnArrowUp.Location.Y, 15, 25); } private void UpdateArrowDown() { Point[] pts = { new Point(3, 0), new Point(7, 0), new Point(7, 10), new Point(10, 10), new Point(5, 20), new Point(0, 10), new Point(3, 10), new Point(3, 0) }; // Make the GraphicsPath. GraphicsPath polygon_path = new GraphicsPath(FillMode.Winding); polygon_path.AddPolygon(pts); // Convert the GraphicsPath into a Region. Region polygon_region = new Region(polygon_path); //fineprint //stereograd btnArrowDown.Region = polygon_region; // Make the button big enough to hold the whole region. btnArrowDown.SetBounds( btnArrowDown.Location.X, btnArrowDown.Location.Y, 15, 25); } private void LayerControl_MouseClick(object sender, MouseEventArgs e) //!!!!Nick { LayerControl layerControl = (LayerControl)sender; OnDoubleClicked?.Invoke(this, EventArgs.Empty); } } }