/// <summary>Draws the title and subtitle text. The default implementation places the text within the header if the /// header is horizontal, or to the right of the header if the header is vertical. /// </summary> protected virtual void PaintTitleText(PaintEventArgs e) { using(Brush brush = new SolidBrush(TitleColor)) { int xOffset = HeaderOrientation == Orientation.Horizontal ? 0 : HeaderSize, yOffset = 0; if(!string.IsNullOrEmpty(Title)) { int height = (int)Math.Ceiling(TitleFont.GetHeight(e.Graphics)), shift = height/2; xOffset += shift; yOffset += shift; e.Graphics.DrawString(Title, TitleFont, brush, new Point(xOffset, yOffset)); yOffset += height; } if(!string.IsNullOrEmpty(Subtitle)) { int shift = (int)Math.Ceiling(SubtitleFont.GetHeight(e.Graphics)) / 2; xOffset += shift; yOffset += shift; e.Graphics.DrawString(Subtitle, SubtitleFont, brush, new Rectangle(xOffset, yOffset, Width-xOffset-shift, Height-yOffset)); } } }
/// <summary>Called to create calculate the header height, when the header is horizontally oriented. The default /// implementation measures the height of the title and subtitle text to determine the height of the header. /// </summary> protected virtual int CalculateHeaderHeight() { using(Graphics g = Graphics.FromHwnd(Handle)) { int xOffset = 0, height = 0; if(!string.IsNullOrEmpty(Title)) { int fontHeight = (int)Math.Ceiling(TitleFont.GetHeight(g)), halfHeight = fontHeight/2; xOffset += halfHeight; height += fontHeight + halfHeight; if(string.IsNullOrEmpty(Subtitle)) height += halfHeight; } if(!string.IsNullOrEmpty(Subtitle)) { int fontHeight = (int)Math.Ceiling(SubtitleFont.GetHeight(g)), halfHeight = fontHeight/2; int textHeight = (int)Math.Ceiling(g.MeasureString(Subtitle, SubtitleFont, new Size(Width-xOffset-halfHeight*2, Height-height-halfHeight)).Height); height += textHeight + halfHeight*2; } return Math.Max(60, height); } }
/// <summary> /// Draws the title using the Drawing Context, Origin (x,y) and scale /// </summary> /// <returns> /// The Size required for the title /// </returns> /// TODO: Add a MeasureTitle routine, since can measure TextLayout now /// Size DrawTitle(Context ctx, Point origin, double scale) { ctx.Save(); ctx.SetColor(TitleColor); Font scaled_font; if (AutoScaleTitle) { scaled_font = TitleFont.WithScaledSize(scale); } else { scaled_font = TitleFont; } TextLayout layout = new TextLayout(); layout.Font = scaled_font; layout.Text = Title; Size titleSize = layout.GetSize(); origin.X -= titleSize.Width / 2; ctx.DrawTextLayout(layout, origin); ctx.Restore(); return(titleSize); }
public void PrintToFile(string filePath, string title, string subtitle) { var titleStrings = TitleFont.GetStringRows(title); var subTitleStrings = SubtitleFont.GetStringRows(subtitle); var titleLength = titleStrings[0].Length; var subTitleLength = subTitleStrings[0].Length; var maxWidth = Math.Max(titleLength, subTitleLength); if (titleLength != maxWidth) { foreach (var strBuilder in titleStrings) { strBuilder.Insert(0, " ", (maxWidth - titleLength) / 2); } } else { foreach (var strBuilder in subTitleStrings) { strBuilder.Insert(0, " ", (maxWidth - subTitleLength) / 2); } } using (var fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { using (var streamWriter = new StreamWriter(fileStream)) { foreach (var str in titleStrings) { streamWriter.WriteLine(str.ToString()); } streamWriter.WriteLine(); foreach (var str in subTitleStrings) { streamWriter.WriteLine(str.ToString()); } streamWriter.WriteLine(new String('-', maxWidth)); streamWriter.WriteLine(); streamWriter.WriteLine(); streamWriter.WriteLine(); streamWriter.WriteLine(); streamWriter.WriteLine(); var signString = $"-- Generated by DeafX.Roy {DateTime.Now.ToString("yyyy-MM-dd HH:mm")} "; streamWriter.WriteLine(new String('-', maxWidth)); streamWriter.WriteLine(signString + new String('-', maxWidth - signString.Length)); streamWriter.WriteLine(new String('-', maxWidth)); } } }
/// <summary> /// Draw the minor title under the major title. /// </summary> /// <param name="grfx"></param> /// <param name="fastestTurnRatePlot"></param> private void DrawMinorTitle(Graphics grfx, TurnPerformancePlot fastestTurnRatePlot) { if (plots != null && plots.Count > 0) { string elapsedTimeMinorTitle = string.Format("After {0} elapsed seconds", Math.Round(this.displayTurnDegrees / fastestTurnRatePlot.TurnRateInDegPerSecond, 1)); Point minorTitlePoint = GetTitleLocationPoint(grfx); minorTitlePoint.Y += (int)TitleFont.GetHeight(); minorTitlePoint.X = (int)(this.Width / 2 - grfx.MeasureString(elapsedTimeMinorTitle, MinorTitleFont).Width / 2); grfx.DrawString(elapsedTimeMinorTitle, MinorTitleFont, MinorTitlePen.Brush, minorTitlePoint); } }
private void SetAttributedText(UIAlertController alert, string title, string message) { if (TitleFont != null && !string.IsNullOrEmpty(title)) { var attributedTitle = TitleFont.BuildAttributedString(title); alert.SetValueForKey(attributedTitle, new NSString("attributedTitle")); } if (MessageFont != null && !string.IsNullOrEmpty(message)) { var attributedMessage = MessageFont.BuildAttributedString(message); alert.SetValueForKey(attributedMessage, new NSString("attributedMessage")); } }
public void Paint(float x, float y, float w, float h, string text, string title = null, string hint = null) { if (!Enabled) { return; } if (TextFont == null) { return; } var displaySize = Hud.Window.Size; var screenBorderPadding = 0.0f; if (BorderBrush != null) { screenBorderPadding += BorderBrush.RealStrokeWidth; } var layout = TextFont.GetTextLayout(text); var rect = new RectangleF(x, y, w, h); if (!string.IsNullOrEmpty(hint) && Hud.Window.CursorInsideRect(x, y, w, h)) { Hud.Render.SetHint(hint); } if (BackgroundBrush != null) { BackgroundBrush.DrawRectangle(rect); } var realY = y; if ((TitleFont != null) && (BorderBrush != null) && !string.IsNullOrEmpty(title)) { var titleLayout = TitleFont.GetTextLayout(title); var pad = 3 * Hud.Window.Size.Height / 1200.0f; realY = y + pad + titleLayout.Metrics.Height + pad; BorderBrush.DrawLine(x, realY, x + w, realY); TitleFont.DrawText(titleLayout, x + (w - titleLayout.Metrics.Width) / 2, y + pad); } TextFont.DrawText(layout, x + (w - layout.Metrics.Width) / 2, realY + (h - (realY - y) - layout.Metrics.Height) / 2); if (BorderBrush != null) { BorderBrush.DrawRectangle(rect); } }
public void Draw(SpriteBatch spriteBatch) { LevelText.Text = "Lvl " + GlobalData.Session.CurrentLevel; ScoreText.Text = scene.Player.Score.Value.ToString("N0"); ComboText.Text = "x" + scene.Player.CurrentCombo.ToString(); MaxComboText.Text = "x" + scene.Player.HighestCombo.ToString(); int levelLength = (int)TitleFont.MeasureString(LevelText.Text).X + margin; int comboLength = (int)TitleFont.MeasureString(ComboText.Text).X + margin; int maxComboLength = (int)TitleFont.MeasureString(MaxComboText.Text).X + margin; int maxComboVerticalPos = TitleFont.LineSpacing + margin; Rectangle leftSourceRectangle = new Rectangle(0, 0, background.Width, background.Height); Rectangle leftDestinationRectangle = new Rectangle(0, 0, levelLength, background.Height); Rectangle rightSourceRectangle = new Rectangle( GlobalData.Screen.Width - comboLength, 0, background.Width, background.Height); Rectangle rightDestinationRectangle = new Rectangle( GlobalData.Screen.Width - comboLength, 0, comboLength, background.Height); Rectangle rightBottomSourceRectangle = new Rectangle( GlobalData.Screen.Width - maxComboLength, maxComboVerticalPos, background.Width, background.Height); Rectangle rightBottomDestinationRectangle = new Rectangle( GlobalData.Screen.Width - maxComboLength, maxComboVerticalPos, maxComboLength, background.Height); spriteBatch.Draw(background, leftDestinationRectangle, leftSourceRectangle, Color.White); spriteBatch.Draw(textures["LeftEdge"], new Vector2(levelLength, 0), Color.White); spriteBatch.Draw(background, rightDestinationRectangle, rightSourceRectangle, Color.White); spriteBatch.Draw(textures["RightEdge"], new Vector2(GlobalData.Screen.Width - comboLength - textures["RightEdge"].Width, 0), Color.White); spriteBatch.Draw(textures["GoldenBackground"], rightBottomDestinationRectangle, rightBottomSourceRectangle, Color.White); spriteBatch.Draw(textures["GoldenRightEdge"], new Vector2(GlobalData.Screen.Width - maxComboLength - textures["GoldenRightEdge"].Width, maxComboVerticalPos), Color.White); AlignText(LevelText, Alignment.Left); AlignText(ScoreText, Alignment.Center); AlignText(ComboText, Alignment.Right); AlignText(MaxComboText, Alignment.Right, verticalOffset: maxComboVerticalPos); LevelText.Draw(spriteBatch); ScoreText.Draw(spriteBatch); ComboText.Draw(spriteBatch); MaxComboText.Draw(spriteBatch); }
public void Dispose() { if (TextFont != null) { TextFont.Dispose(); } if (TitleFont != null) { TitleFont.Dispose(); } if (Image != null) { Image.Dispose(); } }
private void ApplyCustomFont(AlertDialog.Builder builder, string title, string message) { var titleView = new TextView(this.Context) { Text = title }; TitleFont.ApplyTo(titleView); var frame = new FrameLayout(this.Context); var layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MatchParent, FrameLayout.LayoutParams.MatchParent); layoutParams.SetMargins(16, 16, 16, 16); frame.AddView(titleView, layoutParams); builder.SetCustomTitle(frame); builder.SetMessage(message); var dialog = builder.Show(); var messageView = (TextView)dialog.FindViewById(Android.Resource.Id.Message); MessageFont.ApplyTo(messageView); }
/// <summary> /// return a hash code /// </summary> /// <returns>hashcode as <see cref="int" /></returns> public override int GetHashCode() { var hashCode = -2087474320; hashCode = hashCode * -1521134295 + HeaderFullWidth.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderFullHeight.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderFocusWidth.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderFocusHeight.GetHashCode(); hashCode = hashCode * -1521134295 + AvatarShape.GetHashCode(); #if NETSTANDARD2_0 hashCode = hashCode * -1521134295 + BackgroundColor.GetHashCode(); #else hashCode = hashCode * -1521134295 + BackgroundColor.GetHashCode(); #endif hashCode = hashCode * -1521134295 + BodyFont.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderBounds.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderImage.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderImageFocused.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderImageScaled.GetHashCode(); hashCode = hashCode * -1521134295 + HeaderStretch.GetHashCode(); #if NETSTANDARD2_0 hashCode = hashCode * -1521134295 + LinkColor.GetHashCode(); #else hashCode = hashCode * -1521134295 + LinkColor.GetHashCode(); #endif hashCode = hashCode * -1521134295 + ShowAvatar.GetHashCode(); hashCode = hashCode * -1521134295 + ShowDescription.GetHashCode(); hashCode = hashCode * -1521134295 + ShowHeaderImage.GetHashCode(); hashCode = hashCode * -1521134295 + ShowTitle.GetHashCode(); #if NETSTANDARD2_0 hashCode = hashCode * -1521134295 + TitleColor.GetHashCode(); #else hashCode = hashCode * -1521134295 + TitleColor.GetHashCode(); #endif hashCode = hashCode * -1521134295 + TitleFont.GetHashCode(); hashCode = hashCode * -1521134295 + TitleFontWeight.GetHashCode(); return(hashCode); }
/// <summary> /// Draws only the text for this bar graph. This will also calculate some critical /// font measurements to help size the internal part of the graph. /// </summary> /// <param name="g">The graphics object used for drawing.</param> public void DrawText(Graphics g) { _titleHeight = (int)Math.Ceiling(g.MeasureString("My", TitleFont.GetFont()).Height); Font fnt = Font.GetFont(); string min = Format(Minimum); SizeF minSize = g.MeasureString(min, fnt); string max = Format(Maximum); SizeF maxSize = g.MeasureString(max, fnt); string mid = Format((Maximum + Minimum) / 2); SizeF midSize = g.MeasureString(mid, fnt); _axisTextHeight = (int)Math.Ceiling(Math.Max(Math.Max(minSize.Height, maxSize.Height), midSize.Height)); _axisTextHeight += 10; const string One = "1"; SizeF oneSize = g.MeasureString(One, fnt); string count = Format(MaxBinCount); SizeF countSize = g.MeasureString(count, fnt); SizeF halfSize = new SizeF(0, 0); string halfCount = string.Empty; if (MaxBinCount > 1) { halfCount = Format(MaxBinCount / 2f); if (LogY) { halfCount = Format(Math.Exp(Math.Log(MaxBinCount) / 2)); } halfSize = g.MeasureString(halfCount, fnt); } _countTextWidth = (int)Math.Ceiling(Math.Max(Math.Max(oneSize.Width, countSize.Width), halfSize.Width)); _countTextWidth += 20; Rectangle gb = GetGraphBounds(); Font.Draw(g, min, gb.X, gb.Bottom + 15); g.DrawLine(Pens.Black, gb.Left, gb.Bottom, gb.Left, gb.Bottom + 10); Font.Draw(g, max, gb.Right - maxSize.Width, gb.Bottom + 15); g.DrawLine(Pens.Black, gb.Left + (gb.Width / 2), gb.Bottom, gb.Left + (gb.Width / 2), gb.Bottom + 10); Font.Draw(g, mid, gb.X + (gb.Width / 2) - (midSize.Width / 2), gb.Bottom + 15); g.DrawLine(Pens.Black, gb.Right, gb.Bottom, gb.Right, gb.Bottom + 10); float dY; if (MaxBinCount == 0) { dY = MinHeight; } else { dY = gb.Height / (float)MaxBinCount; } float oneH = Math.Max(dY, MinHeight); Font.Draw(g, One, gb.Left - oneSize.Width - 15, gb.Bottom - (oneSize.Height / 2) - oneH); g.DrawLine(Pens.Black, gb.Left - 10, gb.Bottom - oneH, gb.Left, gb.Bottom - oneH); if (MaxBinCount > 1) { Font.Draw(g, count, gb.Left - countSize.Width - 15, gb.Top); g.DrawLine(Pens.Black, gb.Left - 20, gb.Top, gb.Left, gb.Top); Font.Draw(g, halfCount, gb.Left - halfSize.Width - 15, gb.Top + (gb.Height / 2) - (halfSize.Height / 2)); g.DrawLine(Pens.Black, gb.Left - 10, gb.Top + (gb.Height / 2), gb.Left, gb.Top + (gb.Height / 2)); } SizeF titleSize = g.MeasureString(Title, TitleFont.GetFont()); TitleFont.Draw(g, Title, gb.X + (gb.Width / 2) - (titleSize.Width / 2), 2.5f); }
/// <summary> /// Disposes the font and titlefont /// </summary> public void Dispose() { Font.Dispose(); TitleFont.Dispose(); }
public void Dispose() { TextFont?.Dispose(); TitleFont?.Dispose(); Image?.Dispose(); }
void DeterminePhysicalAxesToDraw(Rectangle bounds, Axis XAxis1, Axis XAxis2, Axis YAxis1, Axis YAxis2, out PhysicalAxis pXAxis1, out PhysicalAxis pXAxis2, out PhysicalAxis pYAxis1, out PhysicalAxis pYAxis2) { Rectangle cb = bounds; pXAxis1 = new PhysicalAxis(XAxis1, new Point(cb.Left, cb.Bottom), new Point(cb.Right, cb.Bottom)); pYAxis1 = new PhysicalAxis(YAxis1, new Point(cb.Left, cb.Bottom), new Point(cb.Left, cb.Top)); pXAxis2 = new PhysicalAxis(XAxis2, new Point(cb.Left, cb.Top), new Point(cb.Right, cb.Top)); pYAxis2 = new PhysicalAxis(YAxis2, new Point(cb.Right, cb.Bottom), new Point(cb.Right, cb.Top)); double bottomIndent = Padding; if (!pXAxis1.Axis.Hidden) { // evaluate its bounding box Rectangle bb = pXAxis1.GetBoundingBox(); // finally determine its indentation from the bottom bottomIndent = bottomIndent + bb.Bottom - cb.Bottom; } double leftIndent = Padding; if (!pYAxis1.Axis.Hidden) { // evaluate its bounding box Rectangle bb = pYAxis1.GetBoundingBox(); // finally determine its indentation from the left leftIndent = leftIndent - bb.Left + cb.Left; } // determine title size double scale = DetermineScaleFactor(bounds.Width, bounds.Height); Font scaled_font; if (AutoScaleTitle) { scaled_font = TitleFont.WithScaledSize(scale); } else { scaled_font = TitleFont; } Size titleSize; using (TextLayout layout = new TextLayout()) { layout.Font = scaled_font; layout.Text = Title; titleSize = layout.GetSize(); }; double topIndent = Padding; if (!pXAxis2.Axis.Hidden) { // evaluate its bounding box Rectangle bb = pXAxis2.GetBoundingBox(); topIndent = topIndent - bb.Top + cb.Top; // finally determine its indentation from the top // correct top indendation to take into account plot title if (Title != "") { topIndent += titleSize.Height * 1.3; } } double rightIndent = Padding; if (!pYAxis2.Axis.Hidden) { // evaluate its bounding box Rectangle bb = pYAxis2.GetBoundingBox(); // finally determine its indentation from the right rightIndent += (bb.Right - cb.Right); } // now we have all the default calculated positions and we can proceed to // "move" the axes to their right places // primary axes (bottom, left) pXAxis1.PhysicalMin = new Point(cb.Left + leftIndent, cb.Bottom - bottomIndent); pXAxis1.PhysicalMax = new Point(cb.Right - rightIndent, cb.Bottom - bottomIndent); pYAxis1.PhysicalMin = new Point(cb.Left + leftIndent, cb.Bottom - bottomIndent); pYAxis1.PhysicalMax = new Point(cb.Left + leftIndent, cb.Top + topIndent); // secondary axes (top, right) pXAxis2.PhysicalMin = new Point(cb.Left + leftIndent, cb.Top + topIndent); pXAxis2.PhysicalMax = new Point(cb.Right - rightIndent, cb.Top + topIndent); pYAxis2.PhysicalMin = new Point(cb.Right - rightIndent, cb.Bottom - bottomIndent); pYAxis2.PhysicalMax = new Point(cb.Right - rightIndent, cb.Top + topIndent); }