public void AddItem(string text, MenuItem.OnClick click) { _items.Add(new MenuItem(text, new Rectangle(_x, _y + (int)(_items.Count * _font.MeasureString(text).Y), (int)_font.MeasureString(text).X, (int)_font.MeasureString(text).Y), click)); if (OnAdd != null) { OnAdd(); } }
public void AddItem(string text, MenuItem.OnClick click) { float x, y1, y2; Texture2D texture = null; if (_font != null) { x = _font.MeasureString(text).X; y2 = _font.MeasureString(text).Y; y1 = _items.Count * (y2 + Padding); } else { texture = Textures.Get(text); x = texture.Width; y1 = 0; foreach (MenuItem m in _items) { y1 += m.Texture.Height + Padding; } y2 = texture.Height; if (texture.Width > _width) { _width = texture.Width; } } Rectangle rect = new Rectangle(_x, _y + (int)y1, (int)x, (int)y2); MenuItem mi; if (_font != null) { mi = new MenuItem(text, rect, click); } else { mi = new MenuItem(texture, rect, click); } _items.Add(mi); if (OnAdd != null) { OnAdd(); } }