diff --git a/barraider-sdtools/Tools/GraphicsTools.cs b/barraider-sdtools/Tools/GraphicsTools.cs index bc363e4..50298b1 100644 --- a/barraider-sdtools/Tools/GraphicsTools.cs +++ b/barraider-sdtools/Tools/GraphicsTools.cs @@ -162,6 +162,7 @@ public static Image CreateOpacityImage(Image image, float opacity) /// /// Generates one (or more) images where each one has a few letters drawn on them based on the parameters. You can set number of letters and number of lines per key. /// Use expandToNextImage to decide if you want only one Image returned or multiple if text is too long for one key + /// Will generate a plain background of the provided color. /// /// /// @@ -172,8 +173,55 @@ public static Image CreateOpacityImage(Image image, float opacity) /// /// /// - /// - public static Image[] DrawMultiLinedText(string text, int currentTextPosition, int lettersPerLine, int numberOfLines, Font font, Color backgroundColor, Color textColor, bool expandToNextImage, PointF keyDrawStartingPosition) + /// A list of images generated + public static Image[] DrawMultiLinedText(string text, int currentTextPosition, int lettersPerLine, + int numberOfLines, Font font, Color backgroundColor, Color textColor, bool expandToNextImage, + PointF keyDrawStartingPosition) + { + return DrawMultiLinedTextCommon(text, currentTextPosition, lettersPerLine, numberOfLines, font, backgroundColor, textColor, expandToNextImage, keyDrawStartingPosition); + } + + /// + /// Generates one (or more) images where each one has a few letters drawn on them based on the parameters. You can set number of letters and number of lines per key. + /// Use expandToNextImage to decide if you want only one Image returned or multiple if text is too long for one key + /// Will use the provided background image to generate the text on top of. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// A list of images generated. + public static Image[] DrawMultiLinedTextWithBackground(string text, int currentTextPosition, int lettersPerLine, + int numberOfLines, Font font, String backgroundPath, Color textColor, bool expandToNextImage, + PointF keyDrawStartingPosition) + { + Image myBackground = Image.FromFile(backgroundPath); + return DrawMultiLinedTextCommon(text, currentTextPosition, lettersPerLine, numberOfLines, font, Color.Transparent, textColor, expandToNextImage, keyDrawStartingPosition, myBackground); + } + + /// + /// Centralize the code to generate images with text wrapped: + /// Generates one (or more) images where each one has a few letters drawn on them based on the parameters. You can set number of letters and number of lines per key. + /// Use expandToNextImage to decide if you want only one Image returned or multiple if text is too long for one key + /// Use the background image or generate a plain background of the provided color. + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// + /// A list of images generated. + private static Image[] DrawMultiLinedTextCommon(string text, int currentTextPosition, int lettersPerLine, int numberOfLines, Font font, Color backgroundColor, Color textColor, bool expandToNextImage, PointF keyDrawStartingPosition, Image background = null) { float currentWidth = keyDrawStartingPosition.X; float currentHeight = keyDrawStartingPosition.Y; @@ -182,9 +230,17 @@ public static Image[] DrawMultiLinedText(string text, int currentTextPosition, i Bitmap img = Tools.GenerateGenericKeyImage(out Graphics graphics); images.Add(img); - // Draw Background - var bgBrush = new SolidBrush(backgroundColor); - graphics.FillRectangle(bgBrush, 0, 0, img.Width, img.Height); + if (background != null) + { + // Use the provided background + graphics.DrawImage(background, 0, 0, img.Width, img.Height); + } + else + { + // Draw Background + var bgBrush = new SolidBrush(backgroundColor); + graphics.FillRectangle(bgBrush, 0, 0, img.Width, img.Height); + } float lineHeight = img.Height / numberOfLines; if (numberOfLines == 1) @@ -203,7 +259,7 @@ public static Image[] DrawMultiLinedText(string text, int currentTextPosition, i { if (expandToNextImage) { - images.AddRange(DrawMultiLinedText(text, letter, lettersPerLine, numberOfLines, font, backgroundColor, textColor, expandToNextImage, keyDrawStartingPosition)); + images.AddRange(DrawMultiLinedTextCommon(text, letter, lettersPerLine, numberOfLines, font, backgroundColor, textColor, expandToNextImage, keyDrawStartingPosition, background)); } break; }