public PointDisplayObject(string name, string label, Color color, ControlPointStyle style, ContentAlignment labelAlignment) { this.name = name; this.label = label; this.color = color; this.style = style; this.labelAlignment = labelAlignment; }
/// <summary> /// Gets bounding box to make object show correctly in viewer /// </summary> /// <param name="loc"></param> /// <param name="style"></param> /// <param name="wt"></param> /// <returns></returns> public static RectangleF GetBoundingBox(Coordinates loc, ControlPointStyle style, WorldTransform wt) { // figure out the size the control box needs to be in world coordinates to make it // show up as appropriate in view coordinates // invert the scale float scaled_offset = 1 / wt.Scale; float scaled_size = 0; if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) { scaled_size = cp_large_size / wt.Scale; } else { scaled_size = cp_small_size / wt.Scale; } // assume that the world transform is currently applied correctly to the graphics RectangleF rect = new RectangleF((float)loc.X - scaled_size / 2, (float)loc.Y - scaled_size / 2, scaled_size, scaled_size); return(rect); }
/// <summary> /// Draw a point in the world /// </summary> /// <param name="loc"></param> /// <param name="color"></param> /// <param name="label"></param> /// <param name="align"></param> /// <param name="style"></param> /// <param name="g"></param> /// <param name="wt"></param> public static void DrawControlPoint(Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, Graphics g, WorldTransform wt) { // Determine size of bounding box RectangleF rect = GetBoundingBox(loc, style, wt); #region Draw the object float scaled_offset = 1 / wt.Scale; // draw a small circle if (style == ControlPointStyle.SmallCircle) { using (SolidBrush b = new SolidBrush(color)) { g.FillEllipse(b, rect); } } else if (style == ControlPointStyle.SmallX) { using (Pen p = new Pen(color, 3 / wt.Scale)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } } else if (style == ControlPointStyle.LargeX) { using (Pen p = new Pen(Color.White, 3 / wt.Scale)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } using (Pen p = new Pen(color, scaled_offset)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } } if (label != null) { SizeF strSize = g.MeasureString(label, labelFont); float x = 0, y = 0; if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) { x = (float)loc.X + cp_label_space / wt.Scale; } else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) { x = (float)loc.X - strSize.Width / (2 * wt.Scale); } else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) { x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale; } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { y = (float)loc.Y - cp_label_space / wt.Scale; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { y = (float)loc.Y + strSize.Height / (2 * wt.Scale); } else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) { y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale; } PointF[] pts = new PointF[] { new PointF(x, y) }; g.Transform.TransformPoints(pts); PointF text_loc = pts[0]; Matrix t = g.Transform.Clone(); g.ResetTransform(); using (SolidBrush b = new SolidBrush(color)) { g.DrawString(label, labelFont, b, text_loc); } g.Transform = t; } #endregion }
/// <summary> /// Draw a point in the world /// </summary> /// <param name="loc"></param> /// <param name="color"></param> /// <param name="label"></param> /// <param name="align"></param> /// <param name="style"></param> /// <param name="g"></param> /// <param name="wt"></param> public static void DrawControlLabel(Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, Graphics g, WorldTransform wt) { // Determine size of bounding box //RectangleF rect = GetBoundingBox(loc, style, wt); float scaled_offset = 1 / wt.Scale; if (label != null) { SizeF strSize = g.MeasureString(label, labelFont); float x = 0, y = 0; if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) { x = (float)loc.X + cp_label_space / wt.Scale; } else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) { x = (float)loc.X - strSize.Width / (2 * wt.Scale); } else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) { x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale; } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { y = (float)loc.Y - cp_label_space / wt.Scale; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { y = (float)loc.Y + strSize.Height / (2 * wt.Scale); } else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) { y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale; } PointF[] pts = new PointF[] { new PointF(x, y) }; g.Transform.TransformPoints(pts); PointF text_loc = pts[0]; Matrix t = g.Transform.Clone(); g.ResetTransform(); using (SolidBrush b = new SolidBrush(color)) { g.DrawString(label, labelFont, b, text_loc); } g.Transform = t; } }
public PointsDisplayObject(string name, Color color, ControlPointStyle style) { this.name = name; this.color = color; this.style = style; }
public static void DrawControlPoint(IGraphics g, Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, bool drawTextBox, WorldTransform wt) { // figure out the size the control box needs to be in world coordinates to make it // show up as appropriate in view coordinates // invert the scale float scaled_size = 0; if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) { scaled_size = cp_large_size / wt.Scale; } else { scaled_size = cp_small_size / wt.Scale; } float scaled_offset = 1 / wt.Scale; // assume that the world transform is currently applied correctly to the graphics RectangleF rect = new RectangleF(-scaled_size / 2, -scaled_size / 2, scaled_size, scaled_size); rect.Offset(Utility.ToPointF(loc)); if (style == ControlPointStyle.LargeBox) { g.FillRectangle(Color.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); g.FillRectangle(color, rect); } else if (style == ControlPointStyle.LargeCircle) { g.FillEllipse(Color.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); g.FillEllipse(color, rect); } else if (style == ControlPointStyle.LargeX) { using (IPen p = g.CreatePen()) { p.Width = 3/wt.Scale; p.Color = Color.White; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); p.Width = scaled_offset; p.Color = color; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); } } else if (style == ControlPointStyle.SmallBox) { g.FillRectangle(color, rect); } else if (style == ControlPointStyle.SmallCircle) { g.FillEllipse(color, rect); } else if (style == ControlPointStyle.SmallX) { using (IPen p = g.CreatePen()) { p.Width = 3/wt.Scale; p.Color = color; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); } } if (!string.IsNullOrEmpty(label)) { SizeF strSize = g.MeasureString(label, label_font); float x = 0, y = 0; if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) { x = (float)loc.X + cp_label_space / wt.Scale; } else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) { x = (float)loc.X - strSize.Width / (2 * wt.Scale); } else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) { x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale; } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { y = (float)loc.Y - cp_label_space / wt.Scale; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { y = (float)loc.Y + strSize.Height / (2 * wt.Scale); } else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) { y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale; } PointF text_loc = new PointF(x, y); if (drawTextBox) { RectangleF text_rect = new RectangleF(text_loc.X - 4/wt.Scale, text_loc.Y - 4/wt.Scale, strSize.Width/wt.Scale, strSize.Height/wt.Scale); g.FillRectangle(Color.FromArgb(127, Color.White), text_rect); } g.DrawString(label, label_font, color, text_loc); } }
/// <summary> /// Draw a point in the world /// </summary> /// <param name="loc"></param> /// <param name="color"></param> /// <param name="label"></param> /// <param name="align"></param> /// <param name="style"></param> /// <param name="g"></param> /// <param name="wt"></param> public static void DrawControlPoint(Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, Graphics g, WorldTransform wt) { // Determine size of bounding box //RectangleF rect = GetBoundingBox(loc, style, wt); float scaled_offset = 1 / wt.Scale; // invert the scale float scaled_size = 0; if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) { scaled_size = cp_large_size / wt.Scale; } else { scaled_size = cp_small_size / wt.Scale; } // assume that the world transform is currently applied correctly to the graphics RectangleF rect = new RectangleF((float)loc.X - scaled_size / 2, (float)loc.Y - scaled_size / 2, scaled_size, scaled_size); if (style == ControlPointStyle.LargeBox) { g.FillRectangle(Brushes.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); using (SolidBrush b = new SolidBrush(color)) { g.FillRectangle(b, rect); } } else if (style == ControlPointStyle.LargeCircle) { g.FillEllipse(Brushes.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); using (SolidBrush b = new SolidBrush(color)) { g.FillEllipse(b, rect); } } else if (style == ControlPointStyle.LargeX) { using (Pen p = new Pen(Color.White, 3 / wt.Scale)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } using (Pen p = new Pen(color, scaled_offset)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } } else if (style == ControlPointStyle.SmallBox) { using (SolidBrush b = new SolidBrush(color)) { g.FillRectangle(b, rect); } } else if (style == ControlPointStyle.SmallCircle) { using (SolidBrush b = new SolidBrush(color)) { g.FillEllipse(b, rect); } } else if (style == ControlPointStyle.SmallX) { using (Pen p = new Pen(color, 3 / wt.Scale)) { p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); } } #region Draw the object // draw a small circle /*if (style == ControlPointStyle.SmallCircle) * { * using (SolidBrush b = new SolidBrush(color)) * { * g.FillEllipse(b, rect); * } * } * else if (style == ControlPointStyle.LargeX) * { * using (Pen p = new Pen(Color.White, 3 / wt.Scale)) * { * p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; * g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); * g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); * } * * using (Pen p = new Pen(color, scaled_offset)) * { * p.Alignment = System.Drawing.Drawing2D.PenAlignment.Center; * g.DrawLine(p, rect.Left, rect.Top, rect.Right, rect.Bottom); * g.DrawLine(p, rect.Left, rect.Bottom, rect.Right, rect.Top); * } * }*/ if (label != null) { SizeF strSize = g.MeasureString(label, labelFont); float x = 0, y = 0; if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) { x = (float)loc.X + cp_label_space / wt.Scale; } else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) { x = (float)loc.X - strSize.Width / (2 * wt.Scale); } else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) { x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale; } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { y = (float)loc.Y - cp_label_space / wt.Scale; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { y = (float)loc.Y + strSize.Height / (2 * wt.Scale); } else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) { y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale; } PointF[] pts = new PointF[] { new PointF(x, y) }; g.Transform.TransformPoints(pts); PointF text_loc = pts[0]; Matrix t = g.Transform.Clone(); g.ResetTransform(); using (SolidBrush b = new SolidBrush(color)) { g.DrawString(label, labelFont, b, text_loc); } g.Transform = t; } #endregion }
public static void DrawControlPoint(IGraphics g, Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, WorldTransform wt) { DrawControlPoint(g, loc, color, label, align, style, true, wt); }
public static void DrawControlPoint(IGraphics g, Coordinates loc, Color color, string label, ContentAlignment align, ControlPointStyle style, bool drawTextBox, WorldTransform wt) { // figure out the size the control box needs to be in world coordinates to make it // show up as appropriate in view coordinates // invert the scale float scaled_size = 0; if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) { scaled_size = cp_large_size / wt.Scale; } else { scaled_size = cp_small_size / wt.Scale; } float scaled_offset = 1 / wt.Scale; // assume that the world transform is currently applied correctly to the graphics RectangleF rect = new RectangleF(-scaled_size / 2, -scaled_size / 2, scaled_size, scaled_size); rect.Offset(Utility.ToPointF(loc)); if (style == ControlPointStyle.LargeBox) { g.FillRectangle(Color.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); g.FillRectangle(color, rect); } else if (style == ControlPointStyle.LargeCircle) { g.FillEllipse(Color.White, rect); // shrink the rect down a little (nominally 1 pixel) rect.Inflate(-scaled_offset, -scaled_offset); g.FillEllipse(color, rect); } else if (style == ControlPointStyle.LargeX) { using (IPen p = g.CreatePen()) { p.Width = 3 / wt.Scale; p.Color = Color.White; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); p.Width = scaled_offset; p.Color = color; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); } } else if (style == ControlPointStyle.SmallBox) { g.FillRectangle(color, rect); } else if (style == ControlPointStyle.SmallCircle) { g.FillEllipse(color, rect); } else if (style == ControlPointStyle.SmallX) { using (IPen p = g.CreatePen()) { p.Width = 3 / wt.Scale; p.Color = color; g.DrawLine(p, new PointF(rect.Left, rect.Top), new PointF(rect.Right, rect.Bottom)); g.DrawLine(p, new PointF(rect.Left, rect.Bottom), new PointF(rect.Right, rect.Top)); } } if (!string.IsNullOrEmpty(label)) { SizeF strSize = g.MeasureString(label, label_font); float x = 0, y = 0; if (align == ContentAlignment.BottomRight || align == ContentAlignment.MiddleRight || align == ContentAlignment.TopRight) { x = (float)loc.X + cp_label_space / wt.Scale; } else if (align == ContentAlignment.BottomCenter || align == ContentAlignment.MiddleCenter || align == ContentAlignment.TopCenter) { x = (float)loc.X - strSize.Width / (2 * wt.Scale); } else if (align == ContentAlignment.BottomLeft || align == ContentAlignment.MiddleLeft || align == ContentAlignment.TopLeft) { x = (float)loc.X - (strSize.Width + cp_label_space) / wt.Scale; } if (align == ContentAlignment.BottomCenter || align == ContentAlignment.BottomLeft || align == ContentAlignment.BottomRight) { y = (float)loc.Y - cp_label_space / wt.Scale; } else if (align == ContentAlignment.MiddleCenter || align == ContentAlignment.MiddleLeft || align == ContentAlignment.MiddleRight) { y = (float)loc.Y + strSize.Height / (2 * wt.Scale); } else if (align == ContentAlignment.TopCenter || align == ContentAlignment.TopLeft || align == ContentAlignment.TopRight) { y = (float)loc.Y + (strSize.Height + cp_label_space) / wt.Scale; } PointF text_loc = new PointF(x, y); if (drawTextBox) { RectangleF text_rect = new RectangleF(text_loc.X - 4 / wt.Scale, text_loc.Y - 4 / wt.Scale, strSize.Width / wt.Scale, strSize.Height / wt.Scale); g.FillRectangle(Color.FromArgb(127, Color.White), text_rect); } g.DrawString(label, label_font, color, text_loc); } }
/// <summary> /// Gets bounding box to make object show correctly in viewer /// </summary> /// <param name="loc"></param> /// <param name="style"></param> /// <param name="wt"></param> /// <returns></returns> public static RectangleF GetBoundingBox(Coordinates loc, ControlPointStyle style, WorldTransform wt) { // figure out the size the control box needs to be in world coordinates to make it // show up as appropriate in view coordinates // invert the scale float scaled_offset = 1 / wt.Scale; float scaled_size = 0; if (style == ControlPointStyle.LargeBox || style == ControlPointStyle.LargeCircle || style == ControlPointStyle.LargeX) { scaled_size = cp_large_size / wt.Scale; } else { scaled_size = cp_small_size / wt.Scale; } // assume that the world transform is currently applied correctly to the graphics RectangleF rect = new RectangleF((float)loc.X - scaled_size / 2, (float)loc.Y - scaled_size / 2, scaled_size, scaled_size); return rect; }