public void DoInvalidate(bool dostatic, RectangleF rect) { if (dostatic) { m_staticDirty = true; } Invalidate(ScreenUtils.ConvertRect(rect)); }
public RectangleF Selection(ICanvas canvas) { Rectangle screenRect = ScreenRect(); if (screenRect.IsEmpty) { return(RectangleF.Empty); } return(ScreenUtils.ToUnitNormalized(canvas, screenRect)); }
public static RectangleF LineBoundingRect(UnitPoint linepoint1, UnitPoint linepoint2, float halflinewidth) { double x = Math.Min(linepoint1.X, linepoint2.X); double y = Math.Min(linepoint1.Y, linepoint2.Y); double w = Math.Abs(linepoint1.X - linepoint2.X); double h = Math.Abs(linepoint1.Y - linepoint2.Y); RectangleF boundingrect = ScreenUtils.GetRect(x, y, w, h); boundingrect.Inflate(halflinewidth, halflinewidth); return(boundingrect); }
public static RectangleF GetRect(UnitPoint p1, UnitPoint p2, double width) { double x = Math.Min(p1.X, p2.X); double y = Math.Min(p1.Y, p2.Y); double w = Math.Abs(p1.X - p2.X); double h = Math.Abs(p1.Y - p2.Y); RectangleF rect = ScreenUtils.GetRect(x, y, w, h); rect.Inflate((float)width, (float)width); return(rect); }
/* * public void DoInvalidate(bool dostatic, RectangleF rect) * { * if (dostatic) * m_staticDirty = true; * Invalidate(ScreenUtils.ConvertRect(rect)); * }*/ void RepaintObject(IDrawObject obj) { if (obj == null) { return; } CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle); RectangleF invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(dc, obj.GetBoundingRect(dc))); obj.Draw(dc, invalidaterect); dc.Graphics.Dispose(); dc.Dispose(); }
//djl public void Draw(CanvasWrapper canvas, RectangleF unitrect, int start, int end, int line, int strong) { if (Enabled == false) { return; } float gridX = m_spacing.Width; float gridY = m_spacing.Height; //Console.WriteLine("gridX=" + gridX + " ; Y=" + gridY); float gridscreensizeX = canvas.ToScreen(gridX); float gridscreensizeY = canvas.ToScreen(gridY); //Console.WriteLine("gridscreensizeX=" + gridscreensizeX + " ; Y=" + gridscreensizeY); if (gridscreensizeX < m_minSize || gridscreensizeY < m_minSize) { return; } PointF leftpoint = unitrect.Location; PointF rightpoint = ScreenUtils.RightPoint(canvas, unitrect); float left = (float)Math.Round(leftpoint.X / gridX) * gridX; float top = unitrect.Height + unitrect.Y; float right = rightpoint.X; float bottom = (float)Math.Round(leftpoint.Y / gridY) * gridY; GraphicsPath path = new GraphicsPath(); PointF p1; PointF p2; if (true) { Console.WriteLine("left=" + left + " ; top=" + top + " ; right=" + right + " ; bottom=" + bottom + "; start=" + start + ";end=" + end + ";line=" + line); p1 = canvas.ToScreen(new UnitPoint(leftpoint.X + start, top - line * gridY)); p2 = canvas.ToScreen(new UnitPoint(leftpoint.X + end, top - line * gridY)); } try { Line l = new Line(p1, p2, strong); CanvasCtrl.M_canvas.List.Add(l); canvas.Graphics.DrawLine(new Pen(l.Color, 2), p1, p2); } catch (Exception e) { Console.Write(e.Message); } }
public void Draw(ICanvas canvas, RectangleF unitrect) { RectangleF r = ScreenUtils.ToScreenNormalized(canvas, unitrect); canvas.Graphics.FillRectangle(m_backgroundBrush, r); StringFormat f = new StringFormat(); f.Alignment = StringAlignment.Center; PointF centerpoint = new PointF(r.Width / 2, r.Height / 2); canvas.Graphics.TranslateTransform(centerpoint.X, centerpoint.Y); canvas.Graphics.RotateTransform(-15); canvas.Graphics.DrawString("NineLineNotation Canvas Test", m_font, m_brush, 0, 0, f); canvas.Graphics.ResetTransform(); }
public void Draw(CanvasWrapper canvas, RectangleF unitrect, int start, int end, int time, int strong) { if (Enabled == false) { return; } float gridX = Spacing.Width; float gridY = Spacing.Height; //Console.WriteLine("gridX=" + gridX + " ; Y=" + gridY); float gridscreensizeX = canvas.ToScreen(gridX); float gridscreensizeY = canvas.ToScreen(gridY); //Console.WriteLine("gridscreensizeX=" + gridscreensizeX + " ; Y=" + gridscreensizeY); if (gridscreensizeX < MinSize || gridscreensizeY < MinSize) { return; } PointF leftpoint = unitrect.Location; PointF rightpoint = ScreenUtils.RightPoint(canvas, unitrect); float left = (float)Math.Round(leftpoint.X / gridX) * gridX; float top = unitrect.Height + unitrect.Y; float right = rightpoint.X; float bottom = (float)Math.Round(leftpoint.Y / gridY) * gridY; //Console.WriteLine("left=" + left + " ; top=" + top + " ; right=" + right + " ; bottom=" + bottom); Pen pen = new Pen(d_color); GraphicsPath path = new GraphicsPath(); while (bottom < top) { PointF p1 = canvas.ToScreen(new UnitPoint(leftpoint.X, bottom)); PointF p2 = canvas.ToScreen(new UnitPoint(rightpoint.X, bottom)); path.AddLine(p1, p2); path.CloseFigure(); bottom += gridY; } if (canvas.Graphics != null) { canvas.Graphics.DrawPath(pen, path); } }
protected override void OnPaint(PaintEventArgs e) { //CommonTools.Tracing.StartTrack(Program.TracePaint); //ClearPens(); e.Graphics.SmoothingMode = m_smoothingMode; CanvasWrapper dc = new CanvasWrapper(this, e.Graphics, ClientRectangle); Rectangle cliprectangle = e.ClipRectangle; if (m_staticImage == null) { cliprectangle = ClientRectangle; m_staticImage = new Bitmap(ClientRectangle.Width, ClientRectangle.Height); m_staticDirty = true; } RectangleF r = ScreenUtils.ToUnitNormalized(dc, cliprectangle); if (float.IsNaN(r.Width) || float.IsInfinity(r.Width)) { r = ScreenUtils.ToUnitNormalized(dc, cliprectangle); } if (m_staticDirty) { m_staticDirty = false; CanvasWrapper dcStatic = new CanvasWrapper(this, Graphics.FromImage(m_staticImage), ClientRectangle); dcStatic.Graphics.SmoothingMode = m_smoothingMode; m_model.BackgroundLayer.Draw(dcStatic, r); //九线谱底谱 if (m_model.GridLayer.Enabled) { m_model.GridLayer.Draw(dcStatic, r); } //djl dcanvaswrapper = dcStatic; drf = r; /* * PointF nullPoint = ToScreen(new UnitPoint(0, 0)); * dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X - 10, nullPoint.Y, nullPoint.X + 10, nullPoint.Y); * dcStatic.Graphics.DrawLine(Pens.Blue, nullPoint.X, nullPoint.Y - 10, nullPoint.X, nullPoint.Y + 10); */ ICanvasLayer[] layers = m_model.Layers; for (int layerindex = layers.Length - 1; layerindex >= 0; layerindex--) { if (layers[layerindex] != m_model.ActiveLayer && layers[layerindex].Visible) { layers[layerindex].Draw(dcStatic, r); } } if (m_model.ActiveLayer != null) { m_model.ActiveLayer.Draw(dcStatic, r); } dcStatic.Dispose(); } e.Graphics.DrawImage(m_staticImage, cliprectangle, cliprectangle, GraphicsUnit.Pixel); /* * foreach (IDrawObject drawobject in m_model.SelectedObjects) * drawobject.Draw(dc, r); * * if (m_newObject != null) * m_newObject.Draw(dc, r); * * if (m_snappoint != null) * m_snappoint.Draw(dc); * * if (m_selection != null) * { * m_selection.Reset(); * m_selection.SetMousePoint(e.Graphics, this.PointToClient(Control.MousePosition)); * } * if (m_moveHelper.IsEmpty == false) * m_moveHelper.DrawObjects(dc, r); * * if (m_nodeMoveHelper.IsEmpty == false) * m_nodeMoveHelper.DrawObjects(dc, r); * dc.Dispose(); * ClearPens(); * CommonTools.Tracing.EndTrack(Program.TracePaint, "OnPaint complete");*/ //重绘线 if (CanvasCtrl.M_canvas.List.Count != 0) { List <Line> l = CanvasCtrl.M_canvas.List; for (int i = 0; i < l.Count; i++) { e.Graphics.DrawLine(new Pen(l[i].Color, 2), l[i].P1, l[i].P2); } } //重绘小节线和拍线 if (CanvasCtrl.M_canvas.OrList.Count != 0) { List <Line> l = CanvasCtrl.M_canvas.OrList; for (int i = 0; i < l.Count; i++) { e.Graphics.DrawLine(new Pen(l[i].Color2, l[i].S), l[i].P1, l[i].P2); } } //绘制移动中的选定区域 if (moving) { mr.drawRegion(e.Graphics); } if (ispaste) { if (pr != null) { pr.drawRegion(e.Graphics); } } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (m_selection != null) { Graphics dc = Graphics.FromHwnd(Handle); m_selection.SetMousePoint(dc, new PointF(e.X, e.Y)); dc.Dispose(); return; } if (moving) //如果有选中的区域正在移动 { Invalidate(); mr.moving(e.X - lastX, e.Y - lastY); lastX = e.X; lastY = e.Y; } if (ispaste) //如果有选中的区域正在移动 { Invalidate(); pr.moving(e.X - lastX, e.Y - lastY); lastX = e.X; lastY = e.Y; } UnitPoint mousepoint; if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false) { Rectangle invalidaterect = Rectangle.Empty; ISnapPoint newsnap = null; mousepoint = GetMousePoint(); if (RunningSnapsEnabled) { newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null); } if (newsnap == null) { newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null); } if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType())) { invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect)); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); // remove old snappoint m_snappoint = newsnap; } //if (m_commandType == eCommandType.move) // Invalidate(invalidaterect); if (m_snappoint == null) { m_snappoint = newsnap; } } ////////////////////////////////////////////////////////////////////////// //UnitPoint mousepoint; if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } else { mousepoint = GetMousePoint(); } if (m_newObject != null) { Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper))); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); m_newObject.OnMouseMove(m_canvaswrapper, mousepoint); RepaintObject(m_newObject); } if (m_snappoint != null) { RepaintSnappoint(m_snappoint); } /* * if (m_moveHelper.HandleMouseMoveForMove(mousepoint)) * Refresh(); //Invalidate(); * * RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint); * * if (rNoderect != RectangleF.Empty) * { * * Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect)); * RepaintStatic(invalidaterect); * * CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle); * dc.Graphics.Clip = new Region(ClientRectangle); * //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect); * m_nodeMoveHelper.DrawObjects(dc, rNoderect); * if (m_snappoint != null) * RepaintSnappoint(m_snappoint); * * dc.Graphics.Dispose(); * dc.Dispose(); * } */ }
public void Draw(ICanvas canvas, RectangleF unitrect) { if (Enabled == false) { return; } float gridX = Spacing.Width; float gridY = Spacing.Height; //Console.WriteLine("gridX=" + gridX + " ; Y=" + gridY); float gridscreensizeX = canvas.ToScreen(gridX); float gridscreensizeY = canvas.ToScreen(gridY); //Console.WriteLine("gridscreensizeX=" + gridscreensizeX + " ; Y=" + gridscreensizeY); if (gridscreensizeX < MinSize || gridscreensizeY < MinSize) { return; } PointF leftpoint = unitrect.Location; PointF rightpoint = ScreenUtils.RightPoint(canvas, unitrect); float left = (float)Math.Round(leftpoint.X / gridX) * gridX; float top = unitrect.Height + unitrect.Y; float right = rightpoint.X; float bottom = (float)Math.Round(leftpoint.Y / gridY) * gridY; // Console.WriteLine("left=" + left + " ; top=" + top + " ; right=" + right + " ; bottom=" + bottom); Pen pen = new Pen(m_color); GraphicsPath path = new GraphicsPath(); // 蓝色底格 /* * * * while (bottom < top) * { * PointF p1 = canvas.ToScreen(new UnitPoint(-20, bottom)); * PointF p2 = canvas.ToScreen(new UnitPoint(180, bottom)); * path.AddLine(p1, p2); * path.CloseFigure(); * bottom += gridY; * } * canvas.Graphics.DrawPath(pen, path); * */ //画基架括号 // Image newImage = Image.FromFile("d:\\CSARP\\1.jpg");//建立要绘制的Image图像 right = 174; pen = new Pen(l_color); path.Reset(); left = 10; int pailine = 14; top = (float)Math.Round(top); while (left < right) { bottom = 10; while (bottom < top) { PointF p1 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p2 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 1; path.AddLine(p1, p2); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p3 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p4 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 1 + 3 * i, top - bottom)); path.AddLine(p3, p4); path.CloseFigure(); } bottom += 2; PointF p5 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p6 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p5, p6); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p7 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p8 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 1 + 3 * i, top - bottom)); path.AddLine(p7, p8); path.CloseFigure(); } bottom += 1; PointF p9 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p10 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p9, p10); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p11 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p12 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p11, p12); path.CloseFigure(); } bottom += 2; PointF p13 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p14 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p13, p14); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p15 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p16 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p15, p16); path.CloseFigure(); } bottom += 1; PointF p17 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p18 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 7; path.AddLine(p17, p18); path.CloseFigure(); PointF p19 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p20 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p19, p20); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p21 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p22 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p21, p22); path.CloseFigure(); } bottom += 2; PointF p23 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p24 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 1; path.AddLine(p23, p24); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p25 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p26 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p25, p26); path.CloseFigure(); } bottom += 2; PointF p27 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p28 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p27, p28); path.CloseFigure(); for (int i = 0; i < 5; i++) { PointF p29 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p30 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p29, p30); path.CloseFigure(); } bottom += 1; PointF p31 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p32 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); bottom += 2; path.AddLine(p31, p32); for (int i = 0; i < 5; i++) { path.CloseFigure(); PointF p33 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i, top - bottom)); PointF p34 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + 3 * i + 1, top - bottom)); path.AddLine(p33, p34); path.CloseFigure(); } bottom += 2; PointF p35 = canvas.ToScreen(new UnitPoint(leftpoint.X + left, top - bottom)); PointF p36 = canvas.ToScreen(new UnitPoint(leftpoint.X + left + pailine, top - bottom)); path.AddLine(p35, p36); path.CloseFigure(); bottom += 20; } left += 14; } canvas.Graphics.DrawPath(pen, path); Image newImage = Image.FromFile("..//..//Resources//fower.png"); canvas.Graphics.DrawImage(newImage, 10, 42, 23, 138); canvas.Graphics.DrawImage(newImage, 10, 255, 23, 138); canvas.Graphics.DrawImage(newImage, 10, 470, 23, 138); canvas.Graphics.DrawImage(newImage, 10, 686, 23, 138); }