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.MeasureSize(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.MeasureChatSize(ref args).Width; args.Text = new String(text[i], 1); int charWidth = drawer.MeasureChatSize(ref args).Width; if (mouseX >= trimmedWidth && mouseX < trimmedWidth + charWidth) { Chars.CaretPos = i; return; } } }
public void DrawCaret(IDrawer2D drawer, Font font) { string text = Text; if (Password) { text = new String('*', text.Length); } DrawTextArgs args = new DrawTextArgs(text, font, true); if (CaretPos == -1) { Size size = drawer.MeasureSize(ref args); drawer.Clear(FastColour.White, X + 5 + size.Width, Y + Height - 5, 10, 2); } else { args.Text = text.Substring(0, CaretPos); int trimmedWidth = drawer.MeasureChatSize(ref args).Width; args.Text = new String(text[CaretPos], 1); int charWidth = drawer.MeasureChatSize(ref args).Width; drawer.Clear(FastColour.White, X + 5 + trimmedWidth, Y + Height - 5, charWidth, 2); } }
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.MeasureSize(ref args); r.X += size.Width; r.Width = 10; } else { args.Text = text.Substring(0, Chars.CaretPos); int trimmedWidth = drawer.MeasureChatSize(ref args).Width; args.Text = new String(text[Chars.CaretPos], 1); int charWidth = drawer.MeasureChatSize(ref args).Width; r.X += trimmedWidth; r.Width = charWidth; } return(r); }
public void MakeBackground() { if (Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height)) { if (Framebuffer != null) { Framebuffer.Dispose(); } Framebuffer = new Bitmap(Width, Height); } using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); ClearArea(0, 0, Width, Height); drawer.UseBitmappedChat = useBitmappedFont; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 5, 10 + 5); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 10); drawer.UseBitmappedChat = false; } Dirty = true; }
public void SetText(string value) { chatInputText.Clear(); chatInputText.Append(0, value); DrawTextArgs args = new DrawTextArgs(value, font, false); Size textSize = game.Drawer2D.MeasureChatSize(ref args); // Ensure we don't have 0 text height if (textSize.Height == 0) { args.Text = Validator.Range; textSize.Height = game.Drawer2D.MeasureChatSize(ref args).Height; args.Text = value; } else { args.SkipPartsCheck = true; } Size size = new Size(Math.Max(textSize.Width, DesiredMaxWidth), Math.Max(textSize.Height, DesiredMaxHeight)); yOffset = 0; if (textSize.Height < DesiredMaxHeight) { yOffset = DesiredMaxHeight / 2 - textSize.Height / 2; } using (Bitmap bmp = IDrawer2D.CreatePow2Bitmap(size)) using (IDrawer2D drawer = game.Drawer2D) { drawer.SetBitmap(bmp); drawer.DrawRect(backColour, 0, 0, size.Width, size.Height); drawer.DrawChatText(ref args, 3, yOffset); args.Text = Validator.Range; args.SkipPartsCheck = false; Size hintSize = drawer.MeasureChatSize(ref args); args.SkipPartsCheck = true; int hintX = size.Width - hintSize.Width; if (textSize.Width + 3 < hintX) { drawer.DrawChatText(ref args, hintX, yOffset); } chatInputTexture = drawer.Make2DTexture(bmp, size, 0, 0); } X = CalcOffset(game.Width, size.Width, XOffset, HorizontalAnchor); Y = CalcOffset(game.Height, size.Height, YOffset, VerticalAnchor); chatCaretTexture.X1 = chatInputTexture.X1 = X; chatCaretTexture.X1 += textSize.Width; chatCaretTexture.Y1 = chatInputTexture.Y1 = Y; chatCaretTexture.Y1 = (Y + size.Height) - chatCaretTexture.Height; Width = size.Width; Height = size.Height; }
unsafe 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, elemHeight = defaultHeight; string oneChar = new String('A', 1); for (int y = 0; y < lines; y++) { string line = parts[y]; int xOffset = y == 0 ? defaultWidth : 0; if (line == null) { continue; } for (int x = 0; x < line.Length; x++) { args.Text = line.Substring(0, x); int trimmedWidth = drawer.MeasureChatSize(ref args).Width + xOffset; // avoid allocating an unnecessary string fixed(char *ptr = oneChar) ptr[0] = line[x]; args.Text = oneChar; int elemWidth = drawer.MeasureChatSize(ref args).Width; if (Contains(trimmedWidth, y * elemHeight, elemWidth, elemHeight, mouseX, mouseY)) { caretPos = offset + x; CalculateCaretData(); return; } } offset += line.Length; } caretPos = -1; CalculateCaretData(); }
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.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 4, 4); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 0); drawer.UseBitmappedChat = false; } }
public void MakeBackground() { if (Framebuffer == null || (Framebuffer.Width != Width || Framebuffer.Height != Height)) { if (Framebuffer != null) { Framebuffer.Dispose(); } Framebuffer = new Bitmap(Width, Height); } if (ClassicMode) { using (FastBitmap dst = new FastBitmap(Framebuffer, true)) { ClearTile(0, 0, Width, 48, elemSize, 128, 64, dst); ClearTile(0, 48, Width, Height - 48, 0, 96, 96, dst); } } else { ClearArea(0, 0, Width, Height); } using (IDrawer2D drawer = Drawer) { drawer.SetBitmap(Framebuffer); drawer.UseBitmappedChat = useBitmappedFont; DrawTextArgs args = new DrawTextArgs("&eClassical&fSharp", logoFont, false); Size size = drawer.MeasureChatSize(ref args); int xStart = Width / 2 - size.Width / 2; args.Text = "&0Classical&0Sharp"; drawer.DrawChatText(ref args, xStart + 4, 8 + 4); args.Text = "&eClassical&fSharp"; drawer.DrawChatText(ref args, xStart, 8); drawer.UseBitmappedChat = false; } Dirty = true; }