public static bool doHoldDownButton(int myID, int x, int y, int width, int height, string text, bool hasOutline, Color?outlineColor, Color?selectedColor) { wasPressedDown = false; wasReleased = false; if (!outlineColor.HasValue) { outlineColor = Color.White; } if (!selectedColor.HasValue) { selectedColor = GuiData.Default_Selected_Color; } var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = x; destinationRectangle.Y = y; destinationRectangle.Width = width; destinationRectangle.Height = height; var flag = GuiData.isMouseLeftDown() && GuiData.active == myID; if (destinationRectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; if (GuiData.mouseWasPressed()) { wasPressedDown = true; } if (GuiData.isMouseLeftDown()) { GuiData.active = myID; flag = true; } } else { if (GuiData.hot == myID) { GuiData.hot = -1; } if (!GuiData.isMouseLeftDown() && GuiData.active == myID && GuiData.active == myID) { GuiData.active = -1; } } if (GuiData.mouseLeftUp()) { wasReleased = true; } GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.active == myID ? selectedColor.Value : (GuiData.hot == myID ? GuiData.Default_Lit_Backing_Color : GuiData.Default_Light_Backing_Color)); if (hasOutline) { RenderedRectangle.doRectangleOutline(x, y, width, height, 2, outlineColor); } return(flag); }
public override bool Draw() { IsDragging = false; if (IsActive && !InBorder) { if (!IsHeldDown) { if (GuiData.mouseWasPressed()) { OriginalClickPosition = GuiData.getMousePos(); OriginalClickPosition.X -= X; OriginalClickPosition.Y -= Y; ClickPositionOffset = new Vector2(OriginalClickPosition.X - X, OriginalClickPosition.Y - Y); } } } if (IsHeldDown) { float mvx = MovedPosition.X, mvy = MovedPosition.Y; if (XBound.HasValue) { mvx = GuiData.mouse.X - X - OriginalClickPosition.X; mvx = Math.Min(Math.Max(Y + mvx, XBound.Value.Min), XBound.Value.Max) - X; } if (YBound.HasValue) { mvy = GuiData.mouse.Y - Y - OriginalClickPosition.Y; mvy = Math.Min(Math.Max(Y + mvy, YBound.Value.Min), YBound.Value.Max) - Y; } MovedPosition = new Vector2(mvx, mvy); IsDragging = true; } GuiData.blockingInput |= IsActive || IsHeldDown; base.Draw(); return(IsDragging); }
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 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 Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height, float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX, float xMax, float yMax, float xMin, float yMin) { DraggableRectangle.isDragging = false; if (!selectedColor.HasValue) { selectedColor = new Color?(GuiData.Default_Selected_Color); } if (!deselectedColor.HasValue) { deselectedColor = new Color?(GuiData.Default_Unselected_Color); } Vector2 temp = GuiData.temp; temp.X = 0.0f; temp.Y = 0.0f; Rectangle tmpRect1 = GuiData.tmpRect; tmpRect1.X = (int)x; tmpRect1.Y = (int)y; tmpRect1.Width = width; tmpRect1.Height = height; Rectangle tmpRect2 = GuiData.tmpRect; tmpRect2.X = (int)((double)x + (double)selectableBorder); tmpRect2.Y = (int)((double)y + (double)selectableBorder); tmpRect2.Width = (double)selectableBorder == -1.0 ? 0 : (int)((double)width - 2.0 * (double)selectableBorder); tmpRect2.Height = (double)selectableBorder == -1.0 ? 0 : (int)((double)height - 2.0 * (double)selectableBorder); if (tmpRect1.Contains(GuiData.getMousePoint()) && !tmpRect2.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; if (GuiData.active != myID && GuiData.mouseWasPressed()) { GuiData.active = myID; DraggableRectangle.originalClickPos = GuiData.getMousePos(); DraggableRectangle.originalClickPos.X -= x; DraggableRectangle.originalClickPos.Y -= y; DraggableRectangle.originalClickOffset = new Vector2(DraggableRectangle.originalClickPos.X - x, DraggableRectangle.originalClickPos.Y - y); } } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.active == myID) { if (GuiData.mouseLeftUp()) { GuiData.active = -1; } else { if (canMoveX) { temp.X = (float)GuiData.mouse.X - x - DraggableRectangle.originalClickPos.X; temp.X = Math.Min(Math.Max((float)tmpRect1.X + temp.X, xMin), xMax) - (float)tmpRect1.X; } if (canMoveY) { temp.Y = (float)GuiData.mouse.Y - y - DraggableRectangle.originalClickPos.Y; temp.Y = Math.Min(Math.Max((float)tmpRect1.Y + temp.Y, yMin), yMax) - (float)tmpRect1.Y; } tmpRect1.X += (int)temp.X; tmpRect1.Y += (int)temp.Y; DraggableRectangle.isDragging = true; } } if (GuiData.active == myID || GuiData.hot == myID) { GuiData.blockingInput = true; } GuiData.spriteBatch.Draw(Utils.white, tmpRect1, GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value); return(temp); }
public static Vector2 doDraggableRectangle(int myID, float x, float y, int width, int height, float selectableBorder, Color?selectedColor, Color?deselectedColor, bool canMoveY, bool canMoveX, float xMax, float yMax, float xMin, float yMin) { isDragging = false; if (!selectedColor.HasValue) { selectedColor = GuiData.Default_Selected_Color; } if (!deselectedColor.HasValue) { deselectedColor = GuiData.Default_Unselected_Color; } var vector2 = GuiData.temp; vector2.X = 0.0f; vector2.Y = 0.0f; var destinationRectangle = GuiData.tmpRect; destinationRectangle.X = (int)x; destinationRectangle.Y = (int)y; destinationRectangle.Width = width; destinationRectangle.Height = height; var rectangle = GuiData.tmpRect; rectangle.X = (int)(x + (double)selectableBorder); rectangle.Y = (int)(y + (double)selectableBorder); rectangle.Width = selectableBorder == -1.0 ? 0 : (int)(width - 2.0 * selectableBorder); rectangle.Height = selectableBorder == -1.0 ? 0 : (int)(height - 2.0 * selectableBorder); if (destinationRectangle.Contains(GuiData.getMousePoint()) && !rectangle.Contains(GuiData.getMousePoint())) { GuiData.hot = myID; if (GuiData.active != myID && GuiData.mouseWasPressed()) { GuiData.active = myID; originalClickPos = GuiData.getMousePos(); originalClickPos.X -= x; originalClickPos.Y -= y; originalClickOffset = new Vector2(originalClickPos.X - x, originalClickPos.Y - y); } } else if (GuiData.hot == myID) { GuiData.hot = -1; } if (GuiData.active == myID) { if (GuiData.mouseLeftUp()) { GuiData.active = -1; } else { if (canMoveX) { vector2.X = GuiData.mouse.X - x - originalClickPos.X; vector2.X = Math.Min(Math.Max(destinationRectangle.X + vector2.X, xMin), xMax) - destinationRectangle.X; } if (canMoveY) { vector2.Y = GuiData.mouse.Y - y - originalClickPos.Y; vector2.Y = Math.Min(Math.Max(destinationRectangle.Y + vector2.Y, yMin), yMax) - destinationRectangle.Y; } destinationRectangle.X += (int)vector2.X; destinationRectangle.Y += (int)vector2.Y; isDragging = true; } } if (GuiData.active == myID || GuiData.hot == myID) { GuiData.blockingInput = true; } GuiData.spriteBatch.Draw(Utils.white, destinationRectangle, GuiData.hot == myID || GuiData.active == myID ? selectedColor.Value : deselectedColor.Value); return(vector2); }
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) { 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); }