//Edits the current text based on the last-pressed key. public void update() { if (lastChar == '\0') { return; } if (delay > 0) { return; } delay = HOLDDELAY; if (lastChar == '\b') { if (text.Length > 0) { text = text.Remove(text.Length - 1); } } else { text = text + lastChar; } size = Font.calcTextSize(font, text, fontSize); if (size.x < minWidth) { size = new Vector2(minWidth, size.y); } if (size.x > maxWidth) { size = new Vector2(maxWidth, size.y); } }
/* Constructor * * @param gui The game gui * @param isDown The default state for this radio button * @param uncheckedImg A handle for the image that will be drawn if the button is unpressed (isDown = false). * @param checkedImg A handle for the image that will be drawn if the button is pressed (isDown = true). */ public GUIRadioButton(GUI gui, bool isDown, string text, Handle uncheckedImg = null, Handle checkedImg = null) : base(gui, uncheckedImg, checkedImg, text) { ResourceComponent rc = gui.graphics.engine.resourceComponent; radioUpImage = uncheckedImg; radioDownImage = checkedImg; //Sets default radio buttons if none are specified if (radioUpImage == null) { radioUpImage = rc.get(Path.GetFullPath(Path.Combine(gui.rootDirectory, RADIOUP))); } if (radioDownImage == null) { radioDownImage = rc.get(Path.GetFullPath(Path.Combine(gui.rootDirectory, RADIODOWN))); } this.isDown = isDown; //Will make the picture display correctly based on the default pressed state refresh(); // Size the text and image Vector2 textSize = Vector2.Zero; Vector2 imgSize = Vector2.Zero; if (text != null) { if (this.font == null) { this.font = rc.get(gui.defaultFontPath); } textSize = Font.calcTextSize(font, text, fontSize); } if (texture != null) { Texture2D bgTex = texture.getResource <Texture2D>(); imgSize = new Vector2(bgTex.width, bgTex.height); } size = new Vector2(imgSize.x + textSize.x, Math.Max(imgSize.y, textSize.y)); stretchImage = false; textOffset = new Vector2(imgSize.x + 2, 0); this.pos = Vector2.Zero; }
/* Constructs the checkbox. * * @param gui The gui to draw on * @param isDown The initial checked state for the button * @param text The text to display on the button * @param uncheckedImg The image to display when the button is unchecked. * @param checkedImg The image to display when the button is checked. */ public GUICheckBox(GUI gui, bool isDown, string text, Handle uncheckedImg = null, Handle checkedImg = null) : base(gui, uncheckedImg, checkedImg, text) { ResourceComponent rc = gui.graphics.engine.resourceComponent; checkUpImage = uncheckedImg; checkDownImage = checkedImg; //If no images are specified in the constructor, we'll use the default ones if (checkUpImage == null) { checkUpImage = rc.get(Path.GetFullPath(Path.Combine(gui.rootDirectory, CHECKUP))); } if (checkDownImage == null) { checkDownImage = rc.get(Path.GetFullPath(Path.Combine(gui.rootDirectory, CHECKDOWN))); } this.isDown = isDown; refresh(); // Size the text and image Vector2 textSize = Vector2.Zero; Vector2 imgSize = Vector2.Zero; if (text != null) { if (font == null) { font = rc.get(gui.defaultFontPath); } textSize = Font.calcTextSize(font, text, fontSize); } if (texture != null) { Texture2D bgTex = texture.getResource <Texture2D>(); imgSize = new Vector2(bgTex.width, bgTex.height); } size = new Vector2(imgSize.x + textSize.x, Math.Max(imgSize.y, textSize.y)); stretchImage = false; textOffset = new Vector2(imgSize.x + 2, 0); this.pos = Vector2.Zero; }