/// <summary> /// Test whether label collides. /// </summary> /// <param name="newLabel"></param> /// <returns>true if label collided with another (more important or earlier) label</returns> public Boolean SimpleCollisionTest(Label2D newLabel) { if (labelList.Contains(newLabel)) { return false; } Size2D newSize = TextRenderer.MeasureString(newLabel.Text, newLabel.Font); newSize = new Size2D(newSize.Width + 2 * newLabel.CollisionBuffer.Width, newSize.Height + 2 * newLabel.CollisionBuffer.Height); Rectangle2D newRect = new Rectangle2D(new Point2D(newLabel.Location.X - newLabel.CollisionBuffer.Width, newLabel.Location.Y - newLabel.CollisionBuffer.Height), newSize); foreach (Label2D label in labelList) { Size2D size = TextRenderer.MeasureString(label.Text, label.Font); size = new Size2D(size.Width + 2*label.CollisionBuffer.Width, size.Height + 2*label.CollisionBuffer.Height); Rectangle2D rect = new Rectangle2D( new Point2D(label.Location.X - newLabel.CollisionBuffer.Width, label.Location.Y - label.CollisionBuffer.Height), size); if (newRect.Intersects(rect)) { return true; } } labelList.Add(newLabel); return false; }
/// <summary> /// Shows a label in the specified position. or changes a label position. /// </summary> public void ShowLabel(String name, Vector2 position) { Label2D label; if (!persistent2DLabels.TryGetValue(name, out label)) { label = new Label2D(name, position, name, Config.DefaultColor); persistent2DLabels.Add(name, label); } else { label.Position = position; } }
/// <summary> /// Creates a label or changes its values /// </summary> public void ShowLabel(String name, Vector2 position, String text, Color color) { Label2D label; if (!persistent2DLabels.TryGetValue(name, out label)) { label = new Label2D(name, position, text, color); persistent2DLabels.Add(name, label); } else { label.Text = text; label.Position = position; label.Color = color; } }
private Switch setupPosViewLables(PosViewReader pos) { _labels = new Switch(); if (!pos.HasLables) { return(_labels); } for (int i = 0; i < pos.Labels.Length; i++) { Label2D l = new Label2D(); l.setText(pos.Labels[i]); l.setLocation(-0.9f, 0.9f); l.setFontSize(20); _labels.addChild(l); } return(_labels); }
/// <summary> /// Shows a label in the specified position. or changes a label position. /// </summary> public void ShowLabel(String name, Vector2 position) { Label2D label; if (!_persistent2DLabels.TryGetValue(name, out label)) { label = new Label2D(name, position, name, Config.DefaultColor); _persistent2DLabels.Add(name, label); } else { label.Position = position; } }
/// <summary> /// Creates a label or changes its values /// </summary> public void ShowLabel(String name, Vector2 position, String text, Color color) { Label2D label; if (!_persistent2DLabels.TryGetValue(name, out label)) { label = new Label2D(name, position, text, color); _persistent2DLabels.Add(name, label); } else { label.Text = text; label.Position = position; label.Color = color; } }
private Boolean AdvancedCollisionTest(Label2D newLabel, Int32 depth) { //newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1); Size2D newSize = TextRenderer.MeasureString(newLabel.Text, newLabel.Font); newSize = new Size2D(newSize.Width + 2 * newLabel.CollisionBuffer.Width, newSize.Height + 2 * newLabel.CollisionBuffer.Height); Rectangle2D newRect = new Rectangle2D(new Point2D(newLabel.Location.X - newLabel.CollisionBuffer.Width, newLabel.Location.Y - newLabel.CollisionBuffer.Height), newSize); foreach (Label2D label in labelList) { Size2D size = TextRenderer.MeasureString(label.Text, label.Font); size = new Size2D(size.Width + 2 * label.CollisionBuffer.Width, size.Height + 2 * label.CollisionBuffer.Height); Rectangle2D rect = new Rectangle2D(new Point2D(label.Location.X - newLabel.CollisionBuffer.Width, label.Location.Y - label.CollisionBuffer.Height), size); if(newRect.Intersects(rect)) { if (label.Text == newLabel.Text) return true; if (depth == 5) { /* * StyleFont font = newLabel.Font; newLabel.Style.Foreground = new SolidStyleBrush(StyleColor.Yellow); newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1); newLabel.Font = new StyleFont(font.FontFamily, new Size2D(font.Size.Width / 3.0, font.Size.Height / 3.0), font.Style); newLabel.Text = newLabel.Text + ":" + label.Text; labelList.Add(newLabel); /*/ // give up on this label after 5 tries at moving it return true; /* */ } else { if(newRect.Location.Y > (rect.Location.Y + rect.Height/2.0)) { newLabel.Location = new Point2D(newLabel.Location.X, rect.Location.Y + rect.Height + 3); } else { newLabel.Location = new Point2D(newLabel.Location.X, rect.Location.Y - newRect.Height - 3); } //newLabel.Style.Foreground = new SolidStyleBrush(StyleColor.Blue); ////StyleFont font = newLabel.Font; ////newLabel.Font = new StyleFont(font.FontFamily, new Size2D(font.Size.Width / depth, font.Size.Height / depth), font.Style); //newLabel.Style.Halo = new StylePen(newLabel.Style.Foreground, 1); return AdvancedCollisionTest(newLabel, depth + 1); } } //else //{ // newLabel.Style.Halo = new StylePen(new SolidStyleBrush(StyleColor.Purple), 1); //} } labelList.Add(newLabel); return false; }
/// <summary> /// Test whether label collides. /// </summary> /// <param name="newLabel"></param> /// <returns>true if label collided with another (more important or earlier) label</returns> public Boolean AdvancedCollisionTest(Label2D newLabel) { if (labelList.Contains(newLabel)) { return false; } return AdvancedCollisionTest(newLabel, 0); }