/// <summary>Set the text. Int numbers mean color in RGB format /// </summary> public void SetText(string text, float fontsize, int a = 0, int b = 0, int c = 0) { _easyDraw.Clear(Color.Transparent); _easyDraw.TextSize(fontsize); _easyDraw.Text(text, _easyDraw.width / 2, _easyDraw.height / 2); _easyDraw.Fill(a, b, c); }
void Update() { _easy.Clear(Color.Transparent); _easy.Fill(_bgColor); _easy.Stroke(_borderColor); _easy.StrokeWeight(_borderWeight); _easy.ShapeAlign(CenterMode.Min, CenterMode.Min); _easy.Rect(0, 0, _easy.width - _borderWeight, _easy.height - _borderWeight); _easy.Fill(_textColor); _easy.TextAlign(CenterMode.Min, CenterMode.Min); _easy.Text(_textToShow, _paddingX, _paddingY); if (_pressAnyKeyMsg != null) { _pressAnyKeyMsg.visible = _showPressAnyKeyToNext; } }
//-------------------------------------------------------------------------------------------- // REGION: public static utility methods, related to creating and placing GXPEngine objects // based on data from Tiled Objects. //-------------------------------------------------------------------------------------------- /// <summary> /// Creates an EasyDraw for displaying text, based on the configuration parameters of a /// Tiled object. (Including font, text alignment, color) /// </summary> /// <param name="obj">The Tiled (text) object</param> /// <returns></returns> public static EasyDraw CreateTextField(TiledObject obj, bool addCollider = true, bool highQualityText = true) { float scaleMultiplier = highQualityText ? 2 : 1; // 1=as is. 2=better antialiasing, but 4 x size EasyDraw message = new EasyDraw((int)Mathf.Ceiling(obj.Width * scaleMultiplier), (int)Mathf.Ceiling(obj.Height * scaleMultiplier), addCollider); // TODO: Cache fonts? // Set Font: FontStyle f = FontStyle.Regular; if (obj.textField.bold == 1 && obj.textField.italic == 1) { f = FontStyle.Bold | FontStyle.Italic; } else if (obj.textField.bold == 0 && obj.textField.italic == 1) { f = FontStyle.Italic; } else if (obj.textField.bold == 1 && obj.textField.italic == 0) { f = FontStyle.Bold; } message.TextFont(new Font(obj.textField.font, Mathf.Round(obj.textField.fontSize * scaleMultiplier), f, GraphicsUnit.Pixel)); message.graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; //AntiAlias; // Set text alignment: message.TextAlign( obj.textField.horizontalAlign == "left" ? CenterMode.Min : (obj.textField.horizontalAlign == "right" ? CenterMode.Max : CenterMode.Center), obj.textField.verticalAlign == "top" ? CenterMode.Min : (obj.textField.verticalAlign == "bottom" ? CenterMode.Max : CenterMode.Center) ); // Set color: uint col = obj.textField.Color; message.Fill(Color.FromArgb((int)(col & 255), (int)((col >> 24) & 255), (int)((col >> 16) & 255), (int)((col >> 8) & 255)), (int)(col & 255)); return(message); }