public LabelMono(int x, int y, int width, int height, string text, LabelAlignment align) : base(x, y, width, height) { Text = text; Align = align; Color = Color.White; }
/// <summary> /// Constructor /// </summary> /// <param name="color"></param> /// <param name="alignment"></param> public AbstractLabel(Color color, LabelAlignment alignment) { this.RenderColor = color; this.DefaultColor = color; this.Alignment = alignment; this._labelState = LabelState.Visible; }
public wLabel(LabelPosition NewPosition, LabelAlignment NewAlignment, wGraphic NewGraphic) { Enabled = true; Position = NewPosition; Alignment = NewAlignment; Graphics = NewGraphic; }
/// <summary> /// Returns string format for the text to draw based upon label alignment option /// </summary> /// <param name="alignment">MapWinGIS to convert</param> /// <returns>Net string format</returns> private StringFormat StringFormatByAlignment(LabelAlignment alignment) { StringFormat fmt = new StringFormat(); switch (alignment) { case LabelAlignment.Center: fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Center; break; case LabelAlignment.CenterLeft: fmt.Alignment = StringAlignment.Near; fmt.LineAlignment = StringAlignment.Center; break; case LabelAlignment.CenterRight: fmt.Alignment = StringAlignment.Far; fmt.LineAlignment = StringAlignment.Center; break; case LabelAlignment.BottomCenter: fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Far; break; case LabelAlignment.BottomLeft: fmt.Alignment = StringAlignment.Near; fmt.LineAlignment = StringAlignment.Far; break; case LabelAlignment.BottomRight: fmt.Alignment = StringAlignment.Far; fmt.LineAlignment = StringAlignment.Far; break; case LabelAlignment.TopCenter: fmt.Alignment = StringAlignment.Center; fmt.LineAlignment = StringAlignment.Near; break; case LabelAlignment.TopLeft: fmt.Alignment = StringAlignment.Near; fmt.LineAlignment = StringAlignment.Near; break; case LabelAlignment.TopRight: fmt.Alignment = StringAlignment.Far; fmt.LineAlignment = StringAlignment.Near; break; } return(fmt); }
public void SetAlignment(LabelAlignment alignment) { switch (alignment) { case LabelAlignment.LEFT: m_Anchor = TextAnchor.UpperLeft; return; case LabelAlignment.CENTER: m_Anchor = TextAnchor.UpperCenter; return; case LabelAlignment.RIGHT: m_Anchor = TextAnchor.UpperRight; return; } }
// Constructor public TextLabel(string text, SpriteFont spriteFont, Vector2 position, LabelAlignment alignment, Color color) : base(color, alignment) { this.Text = text; this.Font = spriteFont; // From base class this.Origin = GetOrigin(text); this.Size = spriteFont.MeasureString(text); this.TopLeftPosition = alignment == LabelAlignment.TopLeft ? position : alignment == LabelAlignment.Center ? position - this.Origin : Vector2.Zero; }
/// <summary> /// Aligning the label rectangle around the point of origin /// </summary> /// <param name="r">Rectangle to align</param> /// <param name="alignment">Alignment option to apply</param> private void AlignRectangle(ref Rectangle r, LabelAlignment alignment) { switch (alignment) { case LabelAlignment.TopLeft: r.X -= r.Width; r.Y -= r.Height; break; case LabelAlignment.TopCenter: r.X -= r.Width / 2; r.Y -= r.Height; break; case LabelAlignment.TopRight: r.X += 0; r.Y -= r.Height; break; case LabelAlignment.CenterLeft: r.X -= r.Width; r.Y -= r.Height / 2; break; case LabelAlignment.Center: r.X -= r.Width / 2; r.Y -= r.Height / 2; break; case LabelAlignment.CenterRight: r.X += 0; r.Y -= r.Height / 2; break; case LabelAlignment.BottomLeft: r.X -= r.Width; r.Y += 0; break; case LabelAlignment.BottomCenter: r.X -= r.Width / 2; r.Y += 0; break; case LabelAlignment.BottomRight: // rect.MoveToXY(0, 0); break; } }
private RectangleF CalculateMaxColorBarBounds(MapGraphics g, RectangleF bounds, float endCaptionWidth, int colorsNumber, SwatchLabelType currentLabelType) { if (this.LabelInterval == 0) { return(bounds); } LabelAlignment labelAlignment2 = this.LabelAlignment; float num = endCaptionWidth; if (currentLabelType == SwatchLabelType.ShowMiddleValue) { num = ((this.Colors.Count != 1) ? (((float)this.Colors.Count * endCaptionWidth - bounds.Width) / (float)(this.Colors.Count - 1)) : (num - bounds.Width / (float)colorsNumber)); num = (float)((num < 0.0) ? 0.0 : num); } bounds.Inflate((float)((0.0 - num) / 2.0), 0f); return(bounds); }
/// <summary>Initialisation for screen space labels.</summary> public void Init( float x, float y, ref Color color, LabelPivot pivot, LabelAlignment alignment, IMDrawGUICommandFlag flags, string label, float duration) { m_Text.text = label; m_Position.x = x; m_Position.y = y; m_Color = color; m_Flags = flags; SetAlignment(alignment); SetPivot(pivot); m_T = duration; }
/// <summary>\copydoc Label2D(float3,string,float,LabelAlignment)</summary> /// <param name="color">Color of the object</param> public void Label2D(float3 position, string text, float sizeInPixels, LabelAlignment alignment, Color color) { AssertBufferExists(); var g = gizmos.Target as DrawingData; Reserve <Color32, TextData>(); Add(Command.Text | Command.PushColorInline); Add((Color32)color); Add(new TextData { center = position, numCharacters = text.Length, sizeInPixels = sizeInPixels, alignment = alignment }); Reserve(UnsafeUtility.SizeOf <System.UInt16>() * text.Length); for (int i = 0; i < text.Length; i++) { char c = text[i]; System.UInt16 index = (System.UInt16)g.fontData.GetIndex(c); Add(index); } }
private Vector2 CalculateStringPosition(LabelAlignment alignment) { Vector2 pos = Vector2.Zero; if (alignment == LabelAlignment.middle) { pos = Position; pos -= Font.MeasureString(Text) / 2; } if (alignment == LabelAlignment.left) { pos = Position; } if (alignment == LabelAlignment.right) { pos = Position; pos -= Font.MeasureString(Text); } return(pos); }
/// <summary>Initialisation for world space labels.</summary> public void Init( Vector3 position, ref Color color, LabelPivot pivot, LabelAlignment alignment, IMDrawGUICommandFlag flags, string label, float duration) { m_Text.text = label; m_Position = position; m_OffsetX = 0f; m_OffsetY = 0f; m_Color = color; m_BaseAlpha = color.a; m_Flags = flags; SetAlignment(alignment); SetPivot(pivot); m_T = duration; }
public LabelMono(int width, int height, string text, LabelAlignment align) : this(0, 0, width, height, text, align) { }
/// <summary> /// Generates labels with specified positions /// </summary> private void btnOk_Click(object sender, EventArgs e) { // callback and wait cursor Enabled = false; Cursor = Cursors.WaitCursor; var lb = _shapefile.Labels; var positioning = get_LabelPositioning(); lb.Style.Orientation = (LabelOrientation)cboLineOrientation.SelectedIndex; try { // generation _shapefile.GenerateEmptyLabels(positioning, !chkLabelEveryPart.Checked); _shapefile.Labels.SavingMode = PersistenceType.XmlOverwrite; // .lbl file should be updated if (_shapefile.PointOrMultiPoint) { if (optAlignBottomCenter.Checked) { _alignment = LabelAlignment.BottomCenter; } if (optAlignBottomLeft.Checked) { _alignment = LabelAlignment.BottomLeft; } if (optAlignBottomRight.Checked) { _alignment = LabelAlignment.BottomRight; } if (optAlignCenter.Checked) { _alignment = LabelAlignment.Center; } if (optAlignCenterLeft.Checked) { _alignment = LabelAlignment.CenterLeft; } if (optAlignCenterRight.Checked) { _alignment = LabelAlignment.CenterRight; } if (optAlignTopCenter.Checked) { _alignment = LabelAlignment.TopCenter; } if (optAlignTopLeft.Checked) { _alignment = LabelAlignment.TopLeft; } if (optAlignTopRight.Checked) { _alignment = LabelAlignment.TopRight; } } // updating references to categories //if (lb.NumCategories > 0) //{ // for (int i = 0; i < lb.Count; i++) // { // MapWinGIS.Label label = lb.get_Label(i, 0); // label.Category = m_shapefile.get_ShapeCategory(i); // } //} } finally { Enabled = true; Cursor = Cursors.Default; } }
/// <summary> /// Creates a new instance of the AddLabelsForm /// </summary> public AddLabelsForm(IFeatureSet sf, LabelAlignment alignment) { InitializeComponent(); if (sf == null) { throw new Exception("AddLabelsForm: Unexpected null parameter"); } _alignment = alignment; _shapefile = sf; cboLineOrientation.Enabled = false; panel1.Visible = false; if (_shapefile.IsPolygon) { optPosition1.Text = "Center"; optPosition2.Text = "Centroid"; optPosition3.Text = "Interior point"; optPosition4.Visible = false; optPosition1.Tag = LabelPosition.Center; optPosition2.Tag = LabelPosition.Centroid; optPosition3.Tag = LabelPosition.InteriorPoint; groupBox5.Height -= 30; groupBox4.Top -= 30; Height -= 30; optPosition2.Checked = true; // TODO: choose according Labels.Positioning } else if (_shapefile.IsPolyline) { optPosition1.Text = "First segment"; optPosition2.Text = "Last segment"; optPosition3.Text = "Middle segment"; optPosition4.Text = "The longest segment"; optPosition1.Tag = LabelPosition.FirstSegment; optPosition2.Tag = LabelPosition.LastSegment; optPosition3.Tag = LabelPosition.MiddleSegment; optPosition4.Tag = LabelPosition.LongestSegement; optPosition4.Checked = true; // TODO: choose according Labels.Positioning cboLineOrientation.Enabled = true; } else { panel1.Visible = true; optPosition1.Visible = false; optPosition2.Visible = false; optPosition3.Visible = false; optPosition4.Visible = false; Height -= 100; groupBox4.Visible = false; optAlignBottomCenter.Checked = (_alignment == LabelAlignment.BottomCenter); optAlignBottomLeft.Checked = (_alignment == LabelAlignment.BottomLeft); optAlignBottomRight.Checked = (_alignment == LabelAlignment.BottomRight); optAlignCenterLeft.Checked = (_alignment == LabelAlignment.CenterLeft); optAlignCenterRight.Checked = (_alignment == LabelAlignment.CenterRight || _alignment == LabelAlignment.Center); optAlignTopCenter.Checked = (_alignment == LabelAlignment.TopCenter); optAlignTopLeft.Checked = (_alignment == LabelAlignment.TopLeft); optAlignTopRight.Checked = (_alignment == LabelAlignment.TopRight); // Applicable for polyline and polygon shapefiles //throw new Exception("AddLabelsForm: invalid shapefile type"); } // line orientation cboLineOrientation.Items.Clear(); cboLineOrientation.Items.Add("Horizontal"); cboLineOrientation.Items.Add("Parallel"); cboLineOrientation.Items.Add("Perpendicular"); cboLineOrientation.SelectedIndex = 1; }
void Draw(SpriteBatch spriteBatch, Point position, float rotation, int width, string text, LabelAlignment align, Color color, Color outline) { EnsureCharacterData(text); var characters = Characters; var chIndexes = new int[text.Length]; for (var i = 0; i < text.Length; i++) { chIndexes[i] = characters.IndexOfCharacter(text[i]); } var rotationScale = Matrix.CreateRotationZ(rotation) * Matrix.CreateTranslation(position.X - OutlineSize, position.Y - OutlineSize, 0); var current = Vector2.Zero; if (align != LabelAlignment.Left) { for (var i = 0; i < text.Length; i++) { current.X += characters.AbcWidths[chIndexes[i]].X; current.X += characters.AbcWidths[chIndexes[i]].Y; current.X += characters.AbcWidths[chIndexes[i]].Z; } if (align == LabelAlignment.Center) { current.X = (int)((width - current.X) / 2); } else { current.X = width - current.X; } } var start = current; var texture = characters.Texture; if (texture == null) { return; } if (OutlineSize > 0) { var outlineOffset = characters.BoxesMaxBottom; current = start; for (var i = 0; i < text.Length; i++) { var box = characters.Boxes[chIndexes[i]]; box.Y += outlineOffset; if (text[i] > ' ') { spriteBatch.Draw(texture, Vector2.Transform(current, rotationScale), box, outline, rotation, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); } current.X += characters.AbcWidths[chIndexes[i]].X; current.X += characters.AbcWidths[chIndexes[i]].Y; current.X += characters.AbcWidths[chIndexes[i]].Z; if (text[i] == '\n') { current.X = start.X; current.Y += Height; } } } current = start; for (var i = 0; i < text.Length; i++) { if (text[i] > ' ') { spriteBatch.Draw(texture, Vector2.Transform(current, rotationScale), characters.Boxes[chIndexes[i]], color, rotation, Vector2.Zero, Vector2.One, SpriteEffects.None, 0); } current.X += characters.AbcWidths[chIndexes[i]].X; current.X += characters.AbcWidths[chIndexes[i]].Y; current.X += characters.AbcWidths[chIndexes[i]].Z; if (text[i] == '\n') { current.X = start.X; current.Y += Height; } } }
public DrawData PrepareFrame(GraphicsDevice graphicsDevice, float width, float height, string text, LabelAlignment align) { // We'll crash creating 0-byte buffers below and there's nothing to be done with an empty string anyway. if (String.IsNullOrEmpty(text)) { return(null); } EnsureCharacterData(text); var chIndexes = new int[text.Length]; for (var i = 0; i < text.Length; i++) { chIndexes[i] = Characters.IndexOfCharacter(text[i]); } var x = 0f; var y = 0f; if (align != LabelAlignment.Left) { for (var i = 0; i < text.Length; i++) { x += Characters.AbcWidths[chIndexes[i]].X; x += Characters.AbcWidths[chIndexes[i]].Y; x += Characters.AbcWidths[chIndexes[i]].Z; } if (align == LabelAlignment.Center) { x = (width - x) / 2; } else { x = width - x; } } var vertexData = new VertexPositionTexture[text.Length * 4]; var indexData = new short[text.Length * 6]; for (var i = 0; i < text.Length; i++) { vertexData[i * 4 + 0] = new VertexPositionTexture(new Vector3(x + 0, y + 0, 0), new Vector2((float)Characters.Boxes[chIndexes[i]].Left / Characters.Texture.Width, (float)Characters.Boxes[chIndexes[i]].Top / Characters.Texture.Height)); vertexData[i * 4 + 1] = new VertexPositionTexture(new Vector3(x + Characters.Boxes[chIndexes[i]].Width, y + 0, 0), new Vector2((float)Characters.Boxes[chIndexes[i]].Right / Characters.Texture.Width, (float)Characters.Boxes[chIndexes[i]].Top / Characters.Texture.Height)); vertexData[i * 4 + 2] = new VertexPositionTexture(new Vector3(x + 0, y + Characters.Boxes[chIndexes[i]].Height, 0), new Vector2((float)Characters.Boxes[chIndexes[i]].Left / Characters.Texture.Width, (float)Characters.Boxes[chIndexes[i]].Bottom / Characters.Texture.Height)); vertexData[i * 4 + 3] = new VertexPositionTexture(new Vector3(x + Characters.Boxes[chIndexes[i]].Width, y + Characters.Boxes[chIndexes[i]].Height, 0), new Vector2((float)Characters.Boxes[chIndexes[i]].Right / Characters.Texture.Width, (float)Characters.Boxes[chIndexes[i]].Bottom / Characters.Texture.Height)); x += Characters.AbcWidths[chIndexes[i]].X; x += Characters.AbcWidths[chIndexes[i]].Y; x += Characters.AbcWidths[chIndexes[i]].Z; indexData[i * 6 + 0] = (short)(i * 4 + 0); indexData[i * 6 + 1] = (short)(i * 4 + 1); indexData[i * 6 + 2] = (short)(i * 4 + 2); indexData[i * 6 + 3] = (short)(i * 4 + 1); indexData[i * 6 + 4] = (short)(i * 4 + 3); indexData[i * 6 + 5] = (short)(i * 4 + 2); } var vertexBuffer = new VertexBuffer(graphicsDevice, typeof(VertexPositionTexture), vertexData.Length, BufferUsage.WriteOnly); vertexBuffer.SetData(vertexData); var indexBuffer = new IndexBuffer(graphicsDevice, typeof(short), indexData.Length, BufferUsage.WriteOnly); indexBuffer.SetData(indexData); return(new DrawData(Characters, vertexBuffer, vertexData.Length, indexBuffer, text.Length * 2)); }
public void Draw(SpriteBatch spriteBatch, Rectangle position, Point offset, string text, LabelAlignment align, Color color, float rotation) { Draw(spriteBatch, position, offset, text, align, color, Color.Black, rotation); }
public void Draw(SpriteBatch spriteBatch, Rectangle position, Point offset, string text, LabelAlignment align, Color color, Color outline, float rotation) { offset.X += position.Location.X; offset.Y += position.Location.Y; Draw(spriteBatch, offset, rotation, position.Width, text, align, color, outline); }
public TrainOperationsLabel(int x, int y, Viewer viewer, TrainCar car, int carPosition, LabelAlignment alignment) : base(x, y, "", alignment) { Viewer = viewer; CarPosition = carPosition; Text = car.CarID; Click += new Action <Control, Point>(TrainOperationsLabel_Click); }
internal static void UpdateLabelPosition(PlotElement pe, FrameworkElement lbl) { if ((pe != null) && (lbl != null)) { Size labelSize = Utils.GetSize(lbl); Rect labelRect = pe.LabelRect; double left = Canvas.GetLeft(pe); double top = Canvas.GetTop(pe); if (!double.IsNaN(left)) { labelRect.X += left; } if (!double.IsNaN(top)) { labelRect.Y += top; } double naN = double.NaN; double length = double.NaN; LabelAlignment labelAlignment = GetLabelAlignment(lbl); Point labelOffset = GetLabelOffset(lbl); Point hot = new Point(); if (labelAlignment == LabelAlignment.Auto) { labelAlignment = pe.AutoPosition(ref hot, ref labelOffset); } switch (labelAlignment) { case LabelAlignment.BottomCenter: naN = (labelRect.X + (labelRect.Width * 0.5)) - (labelSize.Width * 0.5); length = labelRect.Bottom; hot = new Point(labelRect.X + (labelRect.Width * 0.5), labelRect.Bottom); break; case LabelAlignment.BottomLeft: naN = labelRect.X - labelSize.Width; length = labelRect.Bottom; hot = new Point(labelRect.Left, labelRect.Bottom); break; case LabelAlignment.BottomRight: naN = labelRect.Right; length = labelRect.Bottom; hot = new Point(labelRect.Right, labelRect.Bottom); break; case LabelAlignment.MiddleCenter: naN = (labelRect.X + (labelRect.Width * 0.5)) - (labelSize.Width * 0.5); length = (labelRect.Y + (labelRect.Height * 0.5)) - (labelSize.Height * 0.5); hot = new Point(labelRect.X + (labelRect.Width * 0.5), labelRect.Y + (labelRect.Height * 0.5)); break; case LabelAlignment.MiddleLeft: naN = labelRect.X - labelSize.Width; length = (labelRect.Y + (labelRect.Height * 0.5)) - (labelSize.Height * 0.5); hot = new Point(labelRect.X, labelRect.Y + (labelRect.Height * 0.5)); break; case LabelAlignment.MiddleRight: naN = labelRect.Right; length = (labelRect.Y + (labelRect.Height * 0.5)) - (labelSize.Height * 0.5); hot = new Point(labelRect.Right, labelRect.Y + (labelRect.Height * 0.5)); break; case LabelAlignment.TopCenter: naN = (labelRect.X + (labelRect.Width * 0.5)) - (labelSize.Width * 0.5); length = labelRect.Top - labelSize.Height; hot = new Point(labelRect.X + (labelRect.Width * 0.5), labelRect.Top); break; case LabelAlignment.TopLeft: naN = labelRect.X - labelSize.Width; length = labelRect.Top - labelSize.Height; hot = new Point(labelRect.Left, labelRect.Top); break; case LabelAlignment.TopRight: naN = labelRect.Right; length = labelRect.Top - labelSize.Height; hot = new Point(labelRect.Right, labelRect.Top); break; } if ((labelOffset.X != 0.0) || (labelOffset.Y != 0.0)) { Line labelLine = GetLabelLine(lbl); if (labelLine != null) { labelLine.X1 = hot.X; labelLine.Y1 = hot.Y; } naN += labelOffset.X; length += labelOffset.Y; if (labelLine != null) { labelLine.X2 = hot.X + labelOffset.X; labelLine.Y2 = hot.Y + labelOffset.Y; } } Canvas.SetLeft(lbl, naN); Canvas.SetTop(lbl, length); } }
public static void SetLabelAlignment(DependencyObject obj, LabelAlignment value) { obj.SetValue(LabelAlignmentProperty, value); }
public EOTLabel(int width, int height, Viewer viewer, string eotType, String eotString, LabelAlignment alignment) : base(width, height, eotString, alignment) { Viewer = viewer; PickedEOTTypeFromList = eotType; Click += new Action <Control, Point>(EOTListLabel_Click); }
public TrainLabel(int width, int height, Viewer viewer, Train train, String trainName, LabelAlignment alignment) : base(width, height, trainName, alignment) { Viewer = viewer; PickedTrainFromList = train; Click += new Action <Control, Point>(TrainListLabel_Click); }