Merge pull request #311 from thatsIch/textfield
Fixes search-box click area
This commit is contained in:
commit
d78b0f87d5
3 changed files with 78 additions and 19 deletions
|
@ -64,7 +64,7 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
myScrollBar.setHeight( 106 );
|
||||
myScrollBar.setTop( 18 );
|
||||
|
||||
searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 107, offsetX ), this.guiTop + 6, 64, fontRendererObj.FONT_HEIGHT );
|
||||
searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 104, offsetX ), this.guiTop + 4, 65, 12 );
|
||||
searchField.setEnableBackgroundDrawing( false );
|
||||
searchField.setMaxStringLength( 25 );
|
||||
searchField.setTextColor( 0xFFFFFF );
|
||||
|
@ -79,8 +79,8 @@ public class GuiInterfaceTerminal extends AEBaseGui
|
|||
|
||||
if ( btn == 1 && searchField.isMouseIn( xCoord, yCoord ) )
|
||||
{
|
||||
searchField.setText( "" );
|
||||
refreshList();
|
||||
this.searchField.setText( "" );
|
||||
this.refreshList();
|
||||
}
|
||||
|
||||
super.mouseClicked( xCoord, yCoord, btn );
|
||||
|
|
|
@ -226,7 +226,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi
|
|||
.getSetting( Settings.TERMINAL_STYLE ) ) );
|
||||
}
|
||||
|
||||
searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 82, offsetX ), this.guiTop + 6, 89, fontRendererObj.FONT_HEIGHT );
|
||||
searchField = new MEGuiTextField( fontRendererObj, this.guiLeft + Math.max( 80, offsetX ), this.guiTop + 4, 90, 12 );
|
||||
searchField.setEnableBackgroundDrawing( false );
|
||||
searchField.setMaxStringLength( 25 );
|
||||
searchField.setTextColor( 0xFFFFFF );
|
||||
|
|
|
@ -1,28 +1,87 @@
|
|||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.client.gui.widgets;
|
||||
|
||||
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
|
||||
/**
|
||||
* A modified version of the Minecraft text field.
|
||||
* You can initialize it over the full element span.
|
||||
* The mouse click area is increased to the full element
|
||||
* subtracted with the defined padding.
|
||||
*
|
||||
* The rendering does pay attention to the size of the '_' caret.
|
||||
*/
|
||||
public class MEGuiTextField extends GuiTextField
|
||||
{
|
||||
private static final int padding = 2;
|
||||
|
||||
final int posX;
|
||||
final int posY;
|
||||
private final int _xPos;
|
||||
private final int _yPos;
|
||||
private final int _width;
|
||||
private final int _height;
|
||||
|
||||
final int myWidth;
|
||||
final int myHeight;
|
||||
|
||||
public MEGuiTextField(FontRenderer par1FontRenderer, int xPos, int yPos, int width, int height) {
|
||||
super( par1FontRenderer, xPos, yPos, width, height );
|
||||
posX = xPos;
|
||||
posY = yPos;
|
||||
myWidth = width;
|
||||
myHeight = height;
|
||||
}
|
||||
|
||||
public boolean isMouseIn(int xCoord, int yCoord)
|
||||
/**
|
||||
* Uses the values to instantiate a padded version of a text field.
|
||||
* Pays attention to the '_' caret.
|
||||
*
|
||||
* @param fontRenderer renderer for the strings
|
||||
* @param xPos absolute left position
|
||||
* @param yPos absolute top position
|
||||
* @param width absolute width
|
||||
* @param height absolute height
|
||||
*/
|
||||
public MEGuiTextField( FontRenderer fontRenderer, int xPos, int yPos, int width, int height )
|
||||
{
|
||||
return xCoord >= posX && xCoord < posX + myWidth && yCoord >= posY && yCoord < posY + myHeight;
|
||||
super( fontRenderer, xPos + padding, yPos + padding, width - 2 * padding - fontRenderer.getCharWidth( '_' ), height - 2 * padding );
|
||||
|
||||
this._xPos = xPos;
|
||||
this._yPos = yPos;
|
||||
this._width = width;
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked( int xPos, int yPos, int button )
|
||||
{
|
||||
super.mouseClicked( xPos, yPos, button );
|
||||
|
||||
final boolean requiresFocus = isMouseIn( xPos, yPos );
|
||||
|
||||
this.setFocused( requiresFocus );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the mouse is within the element
|
||||
*
|
||||
* @param xCoord current x coord of the mouse
|
||||
* @param yCoord current y coord of the mouse
|
||||
*
|
||||
* @return true if mouse position is within the text field area
|
||||
*/
|
||||
public boolean isMouseIn( int xCoord, int yCoord )
|
||||
{
|
||||
final boolean withinXRange = this._xPos <= xCoord && xCoord < this._xPos + this._width;
|
||||
final boolean withinYRange = this._yPos <= yCoord && yCoord < this._yPos + this._height;
|
||||
|
||||
return withinXRange && withinYRange;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue