public void SetCaretToCursor(int mouseX, int mouseY, IDrawer2D drawer) { string text = Text; if (Password) { text = new String('*', text.Length); } mouseX -= X; mouseY -= Y; DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = drawer.MeasureText(ref args); if (mouseX >= size.Width) { Chars.CaretPos = -1; return; } for (int i = 0; i < Text.Length; i++) { args.Text = text.Substring(0, i); int trimmedWidth = drawer.MeasureText(ref args).Width; args.Text = new String(text[i], 1); int charWidth = drawer.MeasureText(ref args).Width; if (mouseX >= trimmedWidth && mouseX < trimmedWidth + charWidth) { Chars.CaretPos = i; return; } } }
public Rectangle MeasureCaret(IDrawer2D drawer) { string text = Text; if (Password) { text = new String('*', text.Length); } Rectangle r = new Rectangle(X + 5, Y + Height - 5, 0, 2); DrawTextArgs args = new DrawTextArgs(text, font, true); if (Chars.CaretPos == -1) { Size size = drawer.MeasureText(ref args); r.X += size.Width; r.Width = 10; } else { args.Text = text.Substring(0, Chars.CaretPos); int trimmedWidth = drawer.MeasureText(ref args).Width; args.Text = new String(text[Chars.CaretPos], 1); int charWidth = drawer.MeasureText(ref args).Width; r.X += trimmedWidth; r.Width = charWidth; } return(r); }
/// <summary> Calculates the location and size of the caret character </summary> protected void UpdateCaret() { int maxChars = UsedLines * MaxCharsPerLine; if (caret >= maxChars) { caret = -1; } Text.GetCoords(caret, lines, out caretX, out caretY); DrawTextArgs args = new DrawTextArgs(null, font, false); IDrawer2D drawer = game.Drawer2D; caretAccumulator = 0; if (caretX == MaxCharsPerLine) { caretTex.X1 = X + Padding + lineSizes[caretY].Width; caretCol = PackedCol.Yellow; caretTex.Width = (ushort)caretWidth; } else { args.Text = lines[caretY].Substring(0, caretX); Size trimmedSize = drawer.MeasureText(ref args); if (caretY == 0) { trimmedSize.Width += prefixWidth; } caretTex.X1 = X + Padding + trimmedSize.Width; caretCol = PackedCol.Scale(PackedCol.White, 0.8f); string line = lines[caretY]; if (caretX < line.Length) { args.Text = new String(line[caretX], 1); args.UseShadow = true; caretTex.Width = (ushort)drawer.MeasureText(ref args).Width; } else { caretTex.Width = (ushort)caretWidth; } } caretTex.Y1 = lineSizes[0].Height * caretY + inputTex.Y1 + 2; // Update the colour of the caret char code = GetLastCol(caretX, caretY); if (code != '\0') { caretCol = IDrawer2D.GetCol(code); } }
bool DrawColumnEntry(IDrawer2D drawer, ref DrawTextArgs args, int maxWidth, int x, ref int y, ref TableEntry entry) { Size size = drawer.MeasureText(ref args); bool empty = args.Text == ""; if (empty) { size.Height = entryHeight; } if (y + size.Height > table.Y + table.Height) { y = table.Y + table.Height + 2; return(false); } entry.Y = y; entry.Height = size.Height; if (!empty) { size.Width = Math.Min(maxWidth, size.Width); args.SkipPartsCheck = false; Drawer2DExt.DrawClippedText(ref args, drawer, x, y, maxWidth); } y += size.Height + 2; return(true); }
public override void Redraw(IDrawer2D drawer) { string text = Text; if (Password) { text = new String('*', text.Length); } DrawTextArgs args = new DrawTextArgs("&0" + text, font, false); Size size = drawer.MeasureText(ref args); RealWidth = Math.Max(ButtonWidth, size.Width + 20); textHeight = size.Height; args.SkipPartsCheck = true; if (Window.Minimised || !Visible) { return; } using (FastBitmap bmp = Window.LockBits()) { DrawOuterBorder(bmp); DrawInnerBorder(bmp); Clear(bmp, PackedCol.White, X + 2, Y + 2, RealWidth - 4, Height - 4); BlendBoxTop(bmp); } DrawText(drawer, args); }
public void SetDrawData(IDrawer2D drawer, string text) { DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = drawer.MeasureText(ref args); Width = size.Width; Height = size.Height; CalculatePosition(); Text = text; }
public void SetDrawData(IDrawer2D drawer, string text, Font font, int width, int height) { Width = width; Height = height; CalculatePosition(); this.font = font; Text = text; DrawTextArgs args = new DrawTextArgs(text, font, true); textSize = drawer.MeasureText(ref args); }
public static void DrawClippedText(ref DrawTextArgs args, IDrawer2D drawer, int x, int y, int maxWidth) { Size size = drawer.MeasureText(ref args); // No clipping needed if (size.Width <= maxWidth) { args.SkipPartsCheck = true; drawer.DrawText(ref args, x, y); return; } string text = args.Text; char[] chars = new char[text.Length + 2]; for (int i = 0; i < text.Length; i++) { chars[i] = text[i]; } chars[text.Length] = '.'; chars[text.Length + 1] = '.'; DrawTextArgs part = args; for (int i = text.Length - 1; i > 0; i--) { chars[i] = '.'; if (text[i - 1] == ' ') { continue; } part.Text = new string(chars, 0, i + 2); if (TryDraw(ref part, drawer, x, y, maxWidth)) { return; } // If down to <= 2 chars, try omit trailing .. if (i > 2) { continue; } part.Text = new string(chars, 0, i); if (TryDraw(ref part, drawer, x, y, maxWidth)) { return; } } }
protected void SetCaretToCursor(int mouseX, int mouseY) { mouseX -= inputTex.X1; mouseY -= inputTex.Y1; DrawTextArgs args = new DrawTextArgs(null, font, true); IDrawer2D drawer = game.Drawer2D; int offset = 0, charHeight = caretTex.Height; for (int y = 0; y < lines.Length; y++) { string line = lines[y]; if (line == null) { continue; } for (int x = 0; x < line.Length; x++) { args.Text = line.Substring(0, x); int charOffset = drawer.MeasureText(ref args).Width; if (y == 0) { charOffset += prefixWidth; } args.Text = new string(line[x], 1); int charWidth = drawer.MeasureText(ref args).Width; if (GuiElement.Contains(charOffset, y * charHeight, charWidth, charHeight, mouseX, mouseY)) { caret = offset + x; UpdateCaret(); return; } } offset += line.Length; } caret = -1; UpdateCaret(); }
static bool TryDraw(ref DrawTextArgs args, IDrawer2D drawer, int x, int y, int maxWidth) { Size size = drawer.MeasureText(ref args); if (size.Width > maxWidth) { return(false); } args.SkipPartsCheck = true; drawer.DrawText(ref args, x, y); return(true); }
public void SetDrawData(IDrawer2D drawer, string text) { Text = text; if (Password) { text = new String('*', text.Length); } DrawTextArgs args = new DrawTextArgs(text, font, true); Size size = drawer.MeasureText(ref args); RealWidth = Math.Max(ButtonWidth, size.Width + 15); textHeight = size.Height; }
public override void RemakeTexture() { DrawTextArgs args = new DrawTextArgs(lines[0], font, false); Size size = game.Drawer2D.MeasureText(ref args); caretAccumulator = 0; // Ensure we don't have 0 text height if (size.Height == 0) { args.Text = Validator.Range; size.Height = game.Drawer2D.MeasureText(ref args).Height; args.Text = lines[0]; } else { args.SkipPartsCheck = true; } Width = Math.Max(size.Width, MinWidth); Height = Math.Max(size.Height, MinHeight); Size adjSize = size; adjSize.Width = Width; using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(adjSize)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); drawer.DrawText(ref args, Padding, 0); args.Text = Validator.Range; args.SkipPartsCheck = false; Size hintSize = drawer.MeasureText(ref args); args.SkipPartsCheck = true; int hintX = adjSize.Width - hintSize.Width; if (size.Width + 3 < hintX) { drawer.DrawText(ref args, hintX, 0); } inputTex = drawer.Make2DTexture(bmp, adjSize, 0, 0); } Reposition(); inputTex.X1 = X; inputTex.Y1 = Y; if (size.Height < MinHeight) { inputTex.Y1 += MinHeight / 2 - size.Height / 2; } }
void DrawTitle() { using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); drawer.UseBitmappedChat = (useBitmappedFont || ClassicBackground) && fontPng; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureText(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawText(ref args, xStart + 4, 4); args.Text = "&eClassical&fSharp"; drawer.DrawText(ref args, xStart, 0); drawer.UseBitmappedChat = false; } }
void DrawText(IDrawer2D drawer, DrawTextArgs args) { if (Text.Length != 0 || HintText == null) { int y = Y + 2 + (Height - textHeight) / 2; drawer.DrawText(ref args, X + 5, y); } else { args.SkipPartsCheck = false; args.Text = HintText; args.Font = hintFont; Size hintSize = drawer.MeasureText(ref args); int y = Y + (Height - hintSize.Height) / 2; args.SkipPartsCheck = true; drawer.DrawText(ref args, X + 5, y); } }