public static string doTextBox(int myID, int x, int y, int width, int lines, string str, SpriteFont font) { string str1 = str; if (font == null) { font = GuiData.smallfont; } TextBox.BoxWasActivated = false; Rectangle tmpRect = GuiData.tmpRect; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = lines * TextBox.LINE_HEIGHT; if (tmpRect.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.mouseWasPressed()) { if (GuiData.hot == myID) { if (GuiData.active == myID) { int num = GuiData.mouse.X - x; bool flag = false; for (int length = 1; length <= str.Length; ++length) { if ((double)font.MeasureString(str.Substring(0, length)).X > (double)num) { TextBox.cursorPosition = length - 1; break; } if (!flag) { TextBox.cursorPosition = str.Length; } } } else { GuiData.active = myID; TextBox.cursorPosition = str.Length; } } else if (GuiData.active == myID) { GuiData.active = -1; } } if (GuiData.active == myID) { GuiData.willBlockTextInput = true; str1 = TextBox.getStringInput(str1, GuiData.getKeyboadState(), GuiData.getLastKeyboadState()); KeyboardState keyboardState = GuiData.getKeyboadState(); int num; if (keyboardState.IsKeyDown(Keys.Enter)) { keyboardState = GuiData.getLastKeyboadState(); num = !keyboardState.IsKeyDown(Keys.Enter) ? 1 : 0; } else { num = 1; } if (num == 0) { TextBox.BoxWasActivated = true; GuiData.active = -1; } } ++TextBox.FramesSelected; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = lines * TextBox.LINE_HEIGHT; GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.active == myID ? GuiData.Default_Lit_Backing_Color : (GuiData.hot == myID ? GuiData.Default_Selected_Color : GuiData.Default_Dark_Background_Color)); tmpRect.X += 2; tmpRect.Y += 2; tmpRect.Width -= 4; tmpRect.Height -= 4; GuiData.spriteBatch.Draw(Utils.white, tmpRect, GuiData.Default_Light_Backing_Color); float num1 = (float)(((double)TextBox.LINE_HEIGHT - (double)font.MeasureString(str1).Y) / 2.0); GuiData.spriteBatch.DrawString(font, str1, new Vector2((float)(x + 2), (float)y + num1), Color.White); if (GuiData.active == myID) { tmpRect.X = (int)((double)x + (double)font.MeasureString(str1.Substring(0, TextBox.cursorPosition)).X) + 3; tmpRect.Y = y + 2; tmpRect.Width = 1; tmpRect.Height = TextBox.LINE_HEIGHT - 4; GuiData.spriteBatch.Draw(Utils.white, tmpRect, TextBox.FramesSelected % 60 < 40 ? Color.White : Color.Gray); } return(str1); }
public static string doTextBox(int myID, int x, int y, int width, int lines, string str, SpriteFont font) { var str1 = str; if (font == null) { font = GuiData.smallfont; } BoxWasActivated = false; var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = lines * LINE_HEIGHT; if (destinationRectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.mouseWasPressed()) { if (GuiData.hot == myID) { if (GuiData.active == myID) { var num = GuiData.mouse.X - x; var flag = false; for (var length = 1; length <= str.Length; ++length) { if (font.MeasureString(str.Substring(0, length)).X > (double)num) { cursorPosition = length - 1; break; } if (!flag) { cursorPosition = str.Length; } } } else { GuiData.active = myID; cursorPosition = str.Length; } } else if (GuiData.active == myID) { GuiData.active = -1; } } if (GuiData.active == myID) { GuiData.willBlockTextInput = true; str1 = getStringInput(str1, GuiData.getKeyboadState(), GuiData.getLastKeyboadState()); if (GuiData.getKeyboadState().IsKeyDown(Keys.Enter) && GuiData.getLastKeyboadState().IsKeyDown(Keys.Enter)) { BoxWasActivated = true; GuiData.active = -1; } } ++FramesSelected; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = lines * LINE_HEIGHT; GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.active == myID ? GuiData.Default_Lit_Backing_Color : (GuiData.hot == myID ? GuiData.Default_Selected_Color : GuiData.Default_Dark_Background_Color)); destinationRectangle.X += 2; destinationRectangle.Y += 2; destinationRectangle.Width -= 4; destinationRectangle.Height -= 4; GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.Default_Light_Backing_Color); var num1 = (float)((LINE_HEIGHT - (double)font.MeasureString(str1).Y) / 2.0); GuiData.spriteBatch.DrawString(font, str1, new Vector2(x + 2, y + num1), Color.White); if (GuiData.active == myID) { destinationRectangle.X = (int)(x + (double)font.MeasureString(str1.Substring(0, cursorPosition)).X) + 3; destinationRectangle.Y = y + 2; destinationRectangle.Width = 1; destinationRectangle.Height = LINE_HEIGHT - 4; GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, FramesSelected % 60 < 40 ? Color.White : Color.Gray); } return(str1); }
public static string doTerminalTextField(int myID, int x, int y, int width, int selectionHeight, int lines, string str, SpriteFont font) { string s = str; if (font == null) { font = GuiData.smallfont; } TextBox.BoxWasActivated = false; TextBox.UpWasPresed = false; TextBox.DownWasPresed = false; TextBox.TabWasPresed = false; Rectangle tmpRect = GuiData.tmpRect; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = 0; if (tmpRect.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.mouseWasPressed()) { if (GuiData.hot == myID) { if (GuiData.active == myID) { int num = GuiData.mouse.X - x; bool flag = false; for (int length = 1; length <= str.Length; ++length) { if ((double)font.MeasureString(str.Substring(0, length)).X > (double)num) { TextBox.cursorPosition = length - 1; break; } if (!flag) { TextBox.cursorPosition = str.Length; } } } else { GuiData.active = myID; TextBox.cursorPosition = str.Length; } } else if (GuiData.active == myID) { GuiData.active = -1; } } int active1 = GuiData.active; bool flag1 = false; string filteredStringInput = TextBox.getFilteredStringInput(s, GuiData.getKeyboadState(), GuiData.getLastKeyboadState()); KeyboardState keyboardState = GuiData.getKeyboadState(); int num1; if (keyboardState.IsKeyDown(Keys.Enter)) { keyboardState = GuiData.getLastKeyboadState(); num1 = keyboardState.IsKeyDown(Keys.Enter) ? 1 : 0; } else { num1 = 1; } if (num1 == 0) { TextBox.BoxWasActivated = true; TextBox.cursorPosition = 0; TextBox.textDrawOffsetPosition = 0; } tmpRect.Height = lines * TextBox.LINE_HEIGHT; ++TextBox.FramesSelected; tmpRect.X = x; tmpRect.Y = y; tmpRect.Width = width; tmpRect.Height = 10; tmpRect.X += 2; tmpRect.Y += 2; tmpRect.Width -= 4; tmpRect.Height -= 4; float num2 = (float)(((double)TextBox.LINE_HEIGHT - (double)font.MeasureString(filteredStringInput).Y) / 2.0); string str1 = filteredStringInput; int num3 = 0; int startIndex = 0; int length1; for (string text = str1; (double)font.MeasureString(text).X > (double)(width - 5); text = str1.Substring(startIndex, length1)) { ++num3; length1 = str1.Length - startIndex - (num3 - startIndex); if (length1 < 0) { break; } } if (TextBox.cursorPosition < TextBox.textDrawOffsetPosition) { TextBox.textDrawOffsetPosition = Math.Max(0, TextBox.textDrawOffsetPosition - 1); } while (TextBox.cursorPosition > TextBox.textDrawOffsetPosition + (str1.Length - num3)) { ++TextBox.textDrawOffsetPosition; } if (str1.Length <= num3 || TextBox.textDrawOffsetPosition < 0) { TextBox.textDrawOffsetPosition = TextBox.textDrawOffsetPosition > str1.Length - num3 ? 0 : str1.Length - num3; } else if (TextBox.textDrawOffsetPosition > num3) { num3 = TextBox.textDrawOffsetPosition; } if (num3 > str1.Length) { num3 = str1.Length - 1; } if (TextBox.textDrawOffsetPosition >= str1.Length) { TextBox.textDrawOffsetPosition = 0; } string text1 = str1.Substring(TextBox.textDrawOffsetPosition, str1.Length - num3); if (TextBox.MaskingText) { string str2 = ""; for (int index = 0; index < filteredStringInput.Length; ++index) { str2 += "*"; } text1 = str2; } GuiData.spriteBatch.DrawString(font, text1, Utils.ClipVec2ForTextRendering(new Vector2((float)(x + 2), (float)y + num2)), Color.White); int active2 = GuiData.active; flag1 = false; if (filteredStringInput != "") { int length2 = Math.Min(TextBox.cursorPosition - TextBox.textDrawOffsetPosition, text1.Length); if (length2 <= 0) { length2 = 1; } tmpRect.X = text1.Length != 0 ? (int)((double)x + (double)font.MeasureString(text1.Substring(0, length2)).X) + 3 : x; } else { tmpRect.X = x + 3; } tmpRect.Y = y + 2; tmpRect.Width = 1; tmpRect.Height = TextBox.LINE_HEIGHT - 4; if (LocaleActivator.ActiveLocaleIsCJK()) { tmpRect.Y += 4; } GuiData.spriteBatch.Draw(Utils.white, tmpRect, TextBox.FramesSelected % 60 < 40 ? Color.White : Color.Gray); return(filteredStringInput); }
public static string doTerminalTextField(int myID, int x, int y, int width, int selectionHeight, int lines, string str, SpriteFont font) { var s = str; if (font == null) { font = GuiData.smallfont; } BoxWasActivated = false; UpWasPresed = false; DownWasPresed = false; TabWasPresed = false; var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = 0; if (destinationRectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.mouseWasPressed()) { if (GuiData.hot == myID) { if (GuiData.active == myID) { var num = GuiData.mouse.X - x; var flag = false; for (var length = 1; length <= str.Length; ++length) { if (font.MeasureString(str.Substring(0, length)).X > (double)num) { cursorPosition = length - 1; break; } if (!flag) { cursorPosition = str.Length; } } } else { GuiData.active = myID; cursorPosition = str.Length; } } else if (GuiData.active == myID) { GuiData.active = -1; } } var num1 = GuiData.active; var filteredStringInput = getFilteredStringInput(s, GuiData.getKeyboadState(), GuiData.getLastKeyboadState()); if (GuiData.getKeyboadState().IsKeyDown(Keys.Enter) && !GuiData.getLastKeyboadState().IsKeyDown(Keys.Enter)) { BoxWasActivated = true; cursorPosition = 0; textDrawOffsetPosition = 0; } destinationRectangle.Height = lines * LINE_HEIGHT; ++FramesSelected; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = 10; destinationRectangle.X += 2; destinationRectangle.Y += 2; destinationRectangle.Width -= 4; destinationRectangle.Height -= 4; var num2 = (float)((LINE_HEIGHT - (double)font.MeasureString(filteredStringInput).Y) / 2.0); var str1 = filteredStringInput; var num3 = 0; var startIndex = 0; int length1; for (var text = str1; font.MeasureString(text).X > (double)(width - 5); text = str1.Substring(startIndex, length1)) { ++num3; length1 = str1.Length - startIndex - (num3 - startIndex); } if (cursorPosition < textDrawOffsetPosition) { textDrawOffsetPosition = Math.Max(0, textDrawOffsetPosition - 1); } while (cursorPosition > textDrawOffsetPosition + (str1.Length - num3)) { ++textDrawOffsetPosition; } if (str1.Length <= num3 || textDrawOffsetPosition < 0) { textDrawOffsetPosition = textDrawOffsetPosition > str1.Length - num3 ? 0 : str1.Length - num3; } else if (textDrawOffsetPosition > num3) { num3 = textDrawOffsetPosition; } var text1 = str1.Substring(textDrawOffsetPosition, str1.Length - num3); if (MaskingText) { var str2 = ""; for (var index = 0; index < filteredStringInput.Length; ++index) { str2 += "*"; } text1 = str2; } GuiData.spriteBatch.DrawString(font, text1, new Vector2(x + 2, y + num2), Color.White); var num4 = GuiData.active; if (filteredStringInput != "") { var length2 = Math.Min(cursorPosition - textDrawOffsetPosition, text1.Length); destinationRectangle.X = (int)(x + (double)font.MeasureString(text1.Substring(0, length2)).X) + 3; } else { destinationRectangle.X = x + 3; } destinationRectangle.Y = y + 2; destinationRectangle.Width = 1; destinationRectangle.Height = LINE_HEIGHT - 4; GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, FramesSelected % 60 < 40 ? Color.White : Color.Gray); return(filteredStringInput); }