void SetTouchRectangle (Rectangle? touchRectangle, Vector2 position, BitmapFont font, string text, float scale) { if (touchRectangle == null) { var measurements = font.MeasureString (text) * scale; _touchRectangle = new Rectangle ((int)position.X, (int)position.Y, (int)measurements.X, (int)measurements.Y); } else { _touchRectangle = touchRectangle.Value; } _center = new Vector2(_touchRectangle.Center.X, _touchRectangle.Center.Y); }
public TextToggleButton (Vector2 position, BitmapFont font, string text, Color textColor, float textScale, Vector2 buttonSize, Texture2D buttonTexture) { Position = position; _toggleButton = new ToggleButton (position, buttonSize, buttonTexture); var textMeasurements = font.MeasureString (text) * textScale; var sizeDifferenceY = buttonSize.Y - textMeasurements.Y; var textTouchArea = new Rectangle ( (int)(position.X + buttonSize.X * (1f + MarginPercentage)), (int)(position.Y + buttonSize.Y / 2 - sizeDifferenceY), (int)textMeasurements.X, (int)textMeasurements.Y); _textButton = new TextButton (new Vector2(textTouchArea.X, textTouchArea.Y), font, textColor, text, textTouchArea, textScale); _center = _textButton.Center; }