public override void OnDraw(Graphics2D graphics2D) { graphics2D.PushTransform(); int numLines = Text.Split('\n').Length - 1; if(Text.Contains("\r")) { throw new Exception("These should have be converted to \n."); } double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines; double xOffsetForText = 0; switch (printer.Justification) { case Justification.Left: break; case Justification.Center: xOffsetForText = (Width - Printer.LocalBounds.Width) / 2; break; case Justification.Right: xOffsetForText = Width - Printer.LocalBounds.Width; break; default: throw new NotImplementedException(); } graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText)); RGBA_Bytes currentColor = this.textColor; if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width) // only do this if it's static text { TypeFacePrinter shortTextPrinter = Printer; while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4) { shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer); } shortTextPrinter.Render(graphics2D, currentColor); } else { // it all fits or it's editable (if editable it will need to be offset/scrolled sometimes). Printer.Render(graphics2D, currentColor); } if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Blue); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Blue); } graphics2D.PopTransform(); if (debugIt) { graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Red); graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Red); } base.OnDraw(graphics2D); }
public void DrawCard(Graphics2D DestGraphics, int CardX, int CardY) { double StartX = CardX * CARD_WIDTH + m_BoardX; double StartY = CardY * CARD_HEIGHT + m_BoardY; RectangleDouble CardBounds = new RectangleDouble(StartX + 1.5, StartY + 1.5, StartX + CARD_WIDTH - 1.5, StartY + CARD_HEIGHT - 1.5); RoundedRect CardFiledRoundedRect = new RoundedRect(CardBounds.Left, CardBounds.Bottom, CardBounds.Right, CardBounds.Top, 5); Stroke CardRectBounds = new Stroke(CardFiledRoundedRect); CardRectBounds.width(1); CCard Card = MomsGame.GetCard(CardX, CardY); int CardValue = Card.GetValue(); int CardSuit = Card.GetSuit(); String ValueString = "Uninitialized "; if (CardValue > (int)CCard.CARD_VALUE.VALUE_ACE) { DestGraphics.SetTransform(Affine.NewIdentity()); DestGraphics.Render(CardRectBounds, new RGBA_Bytes(0, 0, 0)); if (CardValue > 10) { switch (CardValue) { case 11: ValueString = "J"; break; case 12: ValueString = "Q"; break; case 13: ValueString = "K"; break; default: throw new Exception(); } } else { ValueString = CardValue.ToString(); } TextWidget stringToDraw = new TextWidget(ValueString, 10); RectangleDouble textBounds = stringToDraw.Printer.LocalBounds; DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 2, CardBounds.Top - 8 - textBounds.Height / 2)); DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0)); DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 4 - textBounds.Width, CardBounds.Bottom + 9 - textBounds.Height / 2)); DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0)); RGBA_Bytes SuitColor = new RGBA_Bytes(0, 0, 0); IVertexSource suitPath = new PathStorage(); switch (CardSuit) { case (int)CCard.CARD_SUIT.SUIT_DIAMOND: { SuitColor = new RGBA_Bytes(0xFF, 0x11, 0x11); suitPath = m_DiamondShape; } break; case (int)CCard.CARD_SUIT.SUIT_CLUB: { SuitColor = new RGBA_Bytes(0x22, 0x22, 0x66); suitPath = new FlattenCurves(m_ClubShape); } break; case (int)CCard.CARD_SUIT.SUIT_HEART: { SuitColor = new RGBA_Bytes(0xBB, 0x00, 0x00); suitPath = new FlattenCurves(m_HeartShape); } break; case (int)CCard.CARD_SUIT.SUIT_SPADE: { SuitColor = new RGBA_Bytes(0x00, 0x00, 0x00); suitPath = new FlattenCurves(m_SpadeShape); } break; default: break; } textBounds = stringToDraw.Printer.LocalBounds; if (CardValue < 11) { for (int CurDot = 0; CurDot < CardValue; CurDot++) { double OffsetX = 0, OffsetY = 0; GetSuitOffset(ref OffsetX, ref OffsetY, CurDot, (int)CardValue); DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + OffsetX, CardBounds.Bottom + OffsetY)); DestGraphics.Render(suitPath, SuitColor); } } else { DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + 9, CardBounds.Bottom + 17)); DestGraphics.Render(suitPath, SuitColor); DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Right - 9, CardBounds.Top - 17)); DestGraphics.Render(suitPath, SuitColor); stringToDraw = new TextWidget(ValueString, 22); textBounds = stringToDraw.Printer.LocalBounds; DestGraphics.SetTransform(Affine.NewTranslation(-1 + CardBounds.Left + CardBounds.Width / 2 - textBounds.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - textBounds.Height / 2)); DestGraphics.Render(stringToDraw.Printer, new RGBA_Bytes(0, 0, 0)); } } else { RGBA_Bytes HoleColor = new RGBA_Bytes(0, 0, 0); String OpenSpaceString; if (!MomsGame.SpaceIsClickable(CardX, CardY)) { HoleColor = new RGBA_Bytes(0xf8, 0xe2, 0xe8); OpenSpaceString = "X"; } else { HoleColor = new RGBA_Bytes(0xe1, 0xe0, 0xf6); OpenSpaceString = "O"; } TextWidget stringToDraw = new TextWidget(OpenSpaceString, 35); RectangleDouble Size = stringToDraw.Printer.LocalBounds; DestGraphics.SetTransform(Affine.NewTranslation(CardBounds.Left + CardBounds.Width / 2 - Size.Width / 2, CardBounds.Bottom + CardBounds.Height / 2 - Size.Height / 2)); DestGraphics.Render(stringToDraw.Printer, HoleColor); } }