//------------------------------------------------------------------------------ private void mUndo_Click(object sender, EventArgs e) { MultiPath mp = GetActivePath(); if (mp.Count == 0) { if (mp.owner.Count == 1) { return; } else { mp.owner.RemoveAt(mp.owner.Count - 1); } } else { MultiPathSegment mps = mp[mp.Count - 1]; if (!mps.RemoveLast()) { mp.RemoveLast(); } } UpdateBtnAndMenuState(); BmpUpdateNeeded(); }
//------------------------------------------------------------------------------ private static void DrawBezierCtrlLines(Graphics graphics, MultiPathSegment mps, uint color) { int cnt = mps.Count; if (cnt < 2) return; Pen pen = new Pen(MakeColor(color)); GraphicsPath gpath = new GraphicsPath(); PointF[] pts = new PointF[2]; pts[0] = PathToPointF(mps[0]); pts[1] = PathToPointF(mps[1]); gpath.StartFigure(); gpath.AddLines(pts); if (mps.IsValid()) if (mps.curvetype == CurveType.CubicBezier) { pts[0] = PathToPointF(mps[2]); pts[1] = PathToPointF(mps[3]); gpath.StartFigure(); gpath.AddLines(pts); } else { pts[0] = PathToPointF(mps[2]); gpath.StartFigure(); gpath.AddLines(pts); } graphics.DrawPath(pen, gpath); pen.Dispose(); gpath.Dispose(); }
//------------------------------------------------------------------------------ private void DisplayPanel_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { mNewPath_Click(sender, e); MovingButtonIdx = -1; } else if (displayPanel.Cursor == Cursors.Hand) { MovingButtonIdx = GetButtonIndex(new IntPoint(e.X * scale, e.Y * scale), out MovingButtonSeg); BmpUpdateNeeded(); } else { //Add a new control point ... CurveType rbPathType = GetRadiobuttonPathType(); MultiPath mp = GetActivePath(); if (mp.Count == 0) { mp.NewMultiPathSegment(rbPathType, new Path()); } else if (rbPathType != GetCurrentPathType(mp)) { if (rbPathType != GetCurrentPathType(mp)) { Path tmp = new Path(); if (!mp.IsValid()) { MultiPathSegment mps = mp[mp.Count - 1]; foreach (IntPoint ip in mps) { tmp.Add(ip); } mp.RemoveLast(); } mp.NewMultiPathSegment(rbPathType, tmp); } } if (!mp[mp.Count - 1].Add(new IntPoint(e.X * scale, e.Y * scale))) { mp.NewMultiPathSegment(rbPathType, new Path()); mp[mp.Count - 1].Add(new IntPoint(e.X * scale, e.Y * scale)); } UpdateBtnAndMenuState(); BmpUpdateNeeded(); MovingButtonIdx = -1; } LeftButtonPressed = (e.Button == MouseButtons.Left); }
//------------------------------------------------------------------------------ private static void DrawBezierCtrlLines(Graphics graphics, MultiPathSegment mps, uint color) { int cnt = mps.Count; if (cnt < 2) { return; } Pen pen = new Pen(MakeColor(color)); GraphicsPath gpath = new GraphicsPath(); PointF[] pts = new PointF[2]; pts[0] = PathToPointF(mps[0]); pts[1] = PathToPointF(mps[1]); gpath.StartFigure(); gpath.AddLines(pts); if (mps.IsValid()) { if (mps.curvetype == CurveType.CubicBezier) { pts[0] = PathToPointF(mps[2]); pts[1] = PathToPointF(mps[3]); gpath.StartFigure(); gpath.AddLines(pts); } else { pts[0] = PathToPointF(mps[2]); gpath.StartFigure(); gpath.AddLines(pts); } } graphics.DrawPath(pen, gpath); pen.Dispose(); gpath.Dispose(); }
//------------------------------------------------------------------------------ private int GetButtonIndex(IntPoint mousePt, out MultiPathSegment mps) { MultiPath mp = GetActivePath(); mps = null; if (mp.Count == 0) { return(-1); } for (int i = 0; i < mp.Count; i++) { for (int j = 0; j < mp[i].Count; j++) { if (Math.Abs(mp[i][j].X - mousePt.X) <= btnRadius && Math.Abs(mp[i][j].Y - mousePt.Y) <= btnRadius) { mps = mp[i]; return(j); } } } return(-1); }
//------------------------------------------------------------------------------ private int GetButtonIndex(IntPoint mousePt, out MultiPathSegment mps) { MultiPath mp = GetActivePath(); mps = null; if (mp.Count == 0) return -1; for (int i = 0; i < mp.Count; i++) for (int j = 0; j < mp[i].Count; j++) if (Math.Abs(mp[i][j].X - mousePt.X) <= btnRadius && Math.Abs(mp[i][j].Y - mousePt.Y) <= btnRadius) { mps = mp[i]; return j; } return -1; }
//------------------------------------------------------------------------------ private static void DrawButtons(Graphics graphics, MultiPath mp, bool small = false) { if (mp == null || mp.Count == 0) { return; } GraphicsPath gpath = new GraphicsPath(FillMode.Alternate); SolidBrush midBrush, startBrush, endBrush; Pen pen; if (small) { midBrush = new SolidBrush(MakeColor(0xFFFFAAAA)); startBrush = new SolidBrush(MakeColor(0xFFFFAAAA)); endBrush = new SolidBrush(MakeColor(0xFFFFAAAA)); pen = new Pen(MakeColor(0xFF660000), 1.0f); } else { midBrush = new SolidBrush(MakeColor(0x20808080)); startBrush = new SolidBrush(MakeColor(0x9980FF80)); endBrush = new SolidBrush(MakeColor(0x99FA8072)); pen = new Pen(Color.Black, 1.0f); } foreach (MultiPathSegment mps in mp) { int len = mps.Count; if (len == 0) { continue; } for (int j = 0; j < len; ++j) { PointF[] btnPts = MakeButton(mps[j], small); gpath.AddPolygon(btnPts); } graphics.FillPath(midBrush, gpath); graphics.DrawPath(pen, gpath); gpath.Reset(); } //draw the start button a shade of green ... if (mp.Count > 0 && mp[0].Count > 0) { gpath.AddPolygon(MakeButton(mp[0][0], small)); graphics.FillPath(startBrush, gpath); MultiPathSegment mps = mp[mp.Count - 1]; //draw the end button a shade of red ... if (mps.index > 0 || mps.Count > 1) { gpath.Reset(); gpath.AddPolygon(MakeButton(mps[mps.Count - 1], small)); graphics.FillPath(endBrush, gpath); } } //clean-up midBrush.Dispose(); startBrush.Dispose(); endBrush.Dispose(); pen.Dispose(); gpath.Dispose(); }