/// <summary> /// Given some text we want to draw (which may not already be set into a PreparedPagedText object), /// draw it to the screen at the given logical position. /// </summary> public static void DrawPreparedText(BaseGameModel model, Position logicalPosition, String fullText, Graphics g, Font font, Boolean drawBorder, Pen penBorder, Int32 edgeBuffer, ref PreparedPagedText prepText) { Position displayPos = model.Camera.MapLogicalToDisplay(logicalPosition, true); if (drawBorder) { Drawing2D.DrawRectBorder(g, penBorder, displayPos); } if (prepText == null) { prepText = DrawText.PrepareTextForDisplayInBox(fullText, g, font, (Int32)displayPos.Width, (Int32)displayPos.Height, (Int32)(edgeBuffer * model.Camera.CurrentScale)); } List <String> preparedOutputText = prepText.GetCurrentPageText(); Int32 currentLineY = 0; for (Int32 currentLine = 0; currentLine < preparedOutputText.Count; currentLine++) { String textToDraw = preparedOutputText[currentLine]; Position displayTextPos = model.Camera.TopLeftAlignTextWithinRect(logicalPosition, textToDraw, font, g, ignoreCameraPosition: true); g.DrawString(textToDraw, font, Brushes.White, (Single)displayTextPos.UpperLeftX, (Single)displayTextPos.UpperLeftY + currentLineY); currentLineY += prepText.LineHeight; } }
/// <summary> /// Given some offset rectangle, and some logical position, draw a solid color rectangle and text over it. /// </summary> public static void DrawTextOnRectangle(BaseGameModel model, Position logPosOffsetRect, Position logPosRect, SolidBrush sbBaseRect, SolidBrush sbText, Graphics g, Font f, String text) { logPosRect = logPosRect.AddPositionUpperLeft(logPosOffsetRect); Position disPosRect = model.Camera.MapLogicalToDisplay(logPosRect, true); Drawing2D.DrawRect(g, sbBaseRect, disPosRect); Position disPosText = model.Camera.BottomLeftAlignTextWithinRect(logPosRect, text, f, g, true); g.DrawString(text, f, sbText, (Single)disPosText.UpperLeftX, (Single)disPosText.UpperLeftY); }
/// <summary> /// Draws a rectangle with a border. Basically draws a larger rectangle with the border color, and then draws a small /// rectangle inside with the fill color. /// Returns the display position for the inner rectangle. /// If the fill color is semi-transparent, realize that due to the implementation of this method, the border color will appear through /// the fill color. /// </summary> public static void FillRectWithBorder(BaseGameModel model, Graphics g, Position rectDisplay, Brush borderColor, Brush fillColor, Double borderSizeLogical, Boolean ignoreCameraPos, out Position rectInnerDisplay) { Position p = rectDisplay; Drawing2D.DrawRect(g, borderColor, p); rectInnerDisplay = new Position(p); Double scale = model.Camera.GetScale(ignoreCameraPos); rectInnerDisplay.TransformByPixels(-borderSizeLogical * scale); Drawing2D.DrawRect(g, fillColor, rectInnerDisplay); }
/// <summary> /// Draws a solid/filled rectangle. Maps this rectangle to the display window based on the camera. /// </summary> public static void DrawRect(BaseGameModel model, Graphics g, Brush b, Position rect) { Position rectAdjusted = model.Camera.MapLogicalToDisplay(rect, true); Drawing2D.DrawRect(g, b, rectAdjusted); }