updated some CofhLib Files trying to fix text rendering, still not working

This commit is contained in:
modmuss50 2015-06-17 11:24:41 +01:00
parent 74525d260a
commit d8e6e88797
3 changed files with 1029 additions and 1171 deletions

View file

@ -48,13 +48,14 @@ public class GuiIDSU extends GuiBase {
@Override
public void initGui() {
super.initGui();
this.buttonList.clear();
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-"));
this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--"));
// this.buttonList.clear();
// int k = (this.width - this.xSize) / 2;
// int l = (this.height - this.ySize) / 2;
// this.buttonList.add(new GuiButton(0, k + 96, l + 8, 18, 20, "++"));
// this.buttonList.add(new GuiButton(1, k + 96, l + 8 + 22, 18, 20, "+"));
// this.buttonList.add(new GuiButton(2, k + 96, l + 8 + (22*2), 18, 20, "-"));
// this.buttonList.add(new GuiButton(3, k + 96, l + 8 + (22*3), 18, 20, "--"));
listBox = new ElementListBox(this, 20, 20, 60, 60);
for (int i = 0; i < 15; i++) {
listBox.add(new ListBoxElementText("Name " + i));

File diff suppressed because it is too large Load diff

View file

@ -1,367 +1,339 @@
package techreborn.cofhLib.gui.element;
import techreborn.cofhLib.gui.GuiBase;
import techreborn.cofhLib.gui.GuiColor;
import techreborn.cofhLib.gui.element.listbox.IListBoxElement;
import techreborn.cofhLib.util.helpers.StringHelper;
import org.lwjgl.opengl.GL11;
import static org.lwjgl.opengl.GL11.*;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
public class ElementListBox extends ElementBase
{
public class ElementListBox extends ElementBase {
public int borderColor = new techreborn.cofhLib.gui.GuiColor(120, 120, 120, 255).getColor();
public int backgroundColor = new techreborn.cofhLib.gui.GuiColor(0, 0, 0, 255).getColor();
public int selectedLineColor = new techreborn.cofhLib.gui.GuiColor(0, 0, 0, 255).getColor();
public int textColor = new techreborn.cofhLib.gui.GuiColor(150, 150, 150, 255).getColor();
public int selectedTextColor = new techreborn.cofhLib.gui.GuiColor(255, 255, 255, 255).getColor();
public int borderColor = new GuiColor(120, 120, 120, 255).getColor();
public int backgroundColor = new GuiColor(0, 0, 0, 255).getColor();
public int selectedLineColor = new GuiColor(0, 0, 0, 255).getColor();
public int textColor = new GuiColor(150, 150, 150, 255).getColor();
public int selectedTextColor = new GuiColor(255, 255, 255, 255).getColor();
private final int _marginTop = 2;
private final int _marginLeft = 2;
private final int _marginRight = 2;
private final int _marginBottom = 2;
private final int _marginTop = 2;
private final int _marginLeft = 2;
private final int _marginRight = 2;
private final int _marginBottom = 2;
private final List<techreborn.cofhLib.gui.element.listbox.IListBoxElement> _elements = new LinkedList<techreborn.cofhLib.gui.element.listbox.IListBoxElement>();
private final List<IListBoxElement> _elements = new LinkedList<IListBoxElement>();
private int _firstIndexDisplayed;
private int _selectedIndex;
private int scrollHoriz;
private int _firstIndexDisplayed;
private int _selectedIndex;
private int scrollHoriz;
public ElementListBox(techreborn.cofhLib.gui.GuiBase containerScreen, int x, int y, int width, int height)
{
public ElementListBox(GuiBase containerScreen, int x, int y, int width, int height) {
super(containerScreen, x, y, width, height);
}
super(containerScreen, x, y, width, height);
}
public void add(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
public void add(IListBoxElement element) {
_elements.add(element);
}
_elements.add(element);
}
public void add(Collection<? extends techreborn.cofhLib.gui.element.listbox.IListBoxElement> elements)
{
public void add(Collection<? extends IListBoxElement> elements) {
_elements.addAll(elements);
}
_elements.addAll(elements);
}
public void remove(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
public void remove(IListBoxElement element) {
_elements.remove(element);
}
_elements.remove(element);
}
public void removeAt(int index)
{
public void removeAt(int index) {
_elements.remove(index);
}
_elements.remove(index);
}
public int getInternalWidth()
{
public void removeAll() {
int width = 0;
for (int i = 0; i < _elements.size(); i++)
{
width = Math.max(_elements.get(i).getWidth(), width);
}
return width;
}
_elements.clear();
}
public int getInternalHeight()
{
public int getInternalWidth() {
int height = 0;
for (int i = 0; i < _elements.size(); i++)
{
height += _elements.get(i).getHeight();
}
return height;
}
public int getContentWidth()
{
int width = 0;
for (int i = 0; i < _elements.size(); i++) {
width = Math.max(_elements.get(i).getWidth(), width);
}
return width;
}
return sizeX - _marginLeft - _marginRight;
}
public int getContentHeight()
{
return sizeY - _marginTop - _marginBottom;
}
public int getContentTop()
{
return posY + _marginTop;
}
public int getContentLeft()
{
return posX + _marginLeft;
}
public final int getContentBottom()
{
return getContentTop() + getContentHeight();
}
public final int getContentRight()
{
return getContentLeft() + getContentWidth();
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks)
{
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
}
@Override
public void drawForeground(int mouseX, int mouseY)
{
int heightDrawn = 0;
int nextElement = _firstIndexDisplayed;
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glPushMatrix();
GL11.glEnable(GL11.GL_STENCIL_TEST);
GL11.glClear(GL11.GL_STENCIL_BUFFER_BIT);
drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
GL11.glTranslated(-scrollHoriz, 0, 0);
int e = _elements.size();
while (nextElement < e && heightDrawn <= getContentHeight())
{
if (nextElement == _selectedIndex)
{
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
}
else
{
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor);
}
heightDrawn += _elements.get(nextElement).getHeight();
nextElement++;
}
GL11.glDisable(GL11.GL_STENCIL_TEST);
GL11.glPopMatrix();
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton)
{
int heightChecked = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++)
{
if (heightChecked > getContentHeight())
{
break;
}
int elementHeight = _elements.get(i).getHeight();
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY)
{
setSelectedIndex(i);
onElementClicked(_elements.get(i));
break;
}
heightChecked += elementHeight;
}
return true;
}
@Override
public boolean onMouseWheel(int mouseX, int mouseY, int movement)
{
if (StringHelper.isControlKeyDown())
{
if (movement > 0)
{
scrollLeft();
}
else if (movement < 0)
{
scrollRight();
}
}
else
{
if (movement > 0)
{
scrollUp();
}
else if (movement < 0)
{
scrollDown();
}
}
return true;
}
public void scrollDown()
{
int heightDisplayed = 0;
int elementsDisplayed = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++)
{
if (heightDisplayed + _elements.get(i).getHeight() > sizeY)
{
break;
}
heightDisplayed += _elements.get(i).getHeight();
elementsDisplayed++;
}
if (_firstIndexDisplayed + elementsDisplayed < _elements.size())
{
_firstIndexDisplayed++;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollUp()
{
if (_firstIndexDisplayed > 0)
{
_firstIndexDisplayed--;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollLeft()
{
scrollHoriz = Math.max(scrollHoriz - 15, 0);
onScrollH(scrollHoriz);
}
public void scrollRight()
{
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
onScrollH(scrollHoriz);
}
public int getLastScrollPosition()
{
int position = _elements.size() - 1;
int heightUsed = _elements.get(position).getHeight();
while (position > 0 && heightUsed < sizeY)
{
position--;
heightUsed += _elements.get(position).getHeight();
}
return position + 1;
}
public int getLastScrollPositionH()
{
return Math.max(getInternalWidth() - getContentWidth(), 0);
}
public int getSelectedIndex()
{
return _selectedIndex;
}
public int getIndexOf(Object value)
{
for (int i = 0; i < _elements.size(); i++)
{
if (_elements.get(i).getValue().equals(value))
{
return i;
}
}
return -1;
}
public techreborn.cofhLib.gui.element.listbox.IListBoxElement getSelectedElement()
{
public int getInternalHeight() {
return _elements.get(_selectedIndex);
}
int height = 0;
for (int i = 0; i < _elements.size(); i++) {
height += _elements.get(i).getHeight();
}
return height;
}
public void setSelectedIndex(int index)
{
public int getContentWidth() {
if (index >= 0 && index < _elements.size() && index != _selectedIndex)
{
_selectedIndex = index;
onSelectionChanged(_selectedIndex, getSelectedElement());
}
}
return sizeX - _marginLeft - _marginRight;
}
public techreborn.cofhLib.gui.element.listbox.IListBoxElement getElement(int index)
{
public int getContentHeight() {
return _elements.get(index);
}
return sizeY - _marginTop - _marginBottom;
}
public int getElementCount()
{
public int getContentTop() {
return _elements.size();
}
return posY + _marginTop;
}
public void scrollToV(int index)
{
public int getContentLeft() {
if (index >= 0 && index < _elements.size())
{
_firstIndexDisplayed = index;
}
}
return posX + _marginLeft;
}
public void scrollToH(int index)
{
public final int getContentBottom() {
if (index >= 0 && index <= getLastScrollPositionH())
{
scrollHoriz = index;
}
}
return getContentTop() + getContentHeight();
}
protected void onElementClicked(techreborn.cofhLib.gui.element.listbox.IListBoxElement element)
{
public final int getContentRight() {
}
return getContentLeft() + getContentWidth();
}
protected void onScrollV(int newStartIndex)
{
public ElementListBox setTextColor(Number textColor, Number selectedTextColor) {
}
if (textColor != null) {
this.textColor = textColor.intValue();
}
if (selectedTextColor != null) {
this.selectedTextColor = selectedTextColor.intValue();
}
return this;
}
protected void onScrollH(int newStartIndex)
{
public ElementListBox setSelectionColor(Number selectedLineColor) {
}
if (selectedLineColor != null) {
this.selectedLineColor = selectedLineColor.intValue();
}
return this;
}
public ElementListBox setBackgroundColor(Number backgroundColor, Number borderColor) {
if (backgroundColor != null) {
this.backgroundColor = backgroundColor.intValue();
}
if (borderColor != null) {
this.borderColor = borderColor.intValue();
}
return this;
}
@Override
public void drawBackground(int mouseX, int mouseY, float gameTicks) {
drawModalRect(posX - 1, posY - 1, posX + sizeX + 1, posY + sizeY + 1, borderColor);
drawModalRect(posX, posY, posX + sizeX, posY + sizeY, backgroundColor);
}
@Override
public void drawForeground(int mouseX, int mouseY) {
int heightDrawn = 0;
int nextElement = _firstIndexDisplayed;
glPushMatrix();
glDisable(GL_LIGHTING);
glEnable(GL_STENCIL_TEST);
glClear(GL_STENCIL_BUFFER_BIT);
drawStencil(getContentLeft(), getContentTop(), getContentRight(), getContentBottom(), 1);
glTranslated(-scrollHoriz, 0, 0);
int e = _elements.size();
while (nextElement < e && heightDrawn <= getContentHeight()) {
if (nextElement == _selectedIndex) {
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, selectedLineColor, selectedTextColor);
} else {
_elements.get(nextElement).draw(this, getContentLeft(), getContentTop() + heightDrawn, backgroundColor, textColor);
}
heightDrawn += _elements.get(nextElement).getHeight();
nextElement++;
}
glDisable(GL_STENCIL_TEST);
glPopMatrix();
}
@Override
public boolean onMousePressed(int mouseX, int mouseY, int mouseButton) {
int heightChecked = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
if (heightChecked > getContentHeight()) {
break;
}
int elementHeight = _elements.get(i).getHeight();
if (getContentTop() + heightChecked <= mouseY && getContentTop() + heightChecked + elementHeight >= mouseY) {
setSelectedIndex(i);
onElementClicked(_elements.get(i));
break;
}
heightChecked += elementHeight;
}
return true;
}
@Override
public boolean onMouseWheel(int mouseX, int mouseY, int movement) {
if (StringHelper.isControlKeyDown()) {
if (movement > 0) {
scrollLeft();
} else if (movement < 0) {
scrollRight();
}
} else {
if (movement > 0) {
scrollUp();
} else if (movement < 0) {
scrollDown();
}
}
return true;
}
public void scrollDown() {
int heightDisplayed = 0;
int elementsDisplayed = 0;
for (int i = _firstIndexDisplayed; i < _elements.size(); i++) {
if (heightDisplayed + _elements.get(i).getHeight() > sizeY) {
break;
}
heightDisplayed += _elements.get(i).getHeight();
elementsDisplayed++;
}
if (_firstIndexDisplayed + elementsDisplayed < _elements.size()) {
_firstIndexDisplayed++;
}
onScrollV(_firstIndexDisplayed);
}
public void scrollUp() {
if (_firstIndexDisplayed > 0) {
_firstIndexDisplayed--;
}
onScrollV(_firstIndexDisplayed);
}
protected void onSelectionChanged(int newIndex, techreborn.cofhLib.gui.element.listbox.IListBoxElement newElement)
{
public void scrollLeft() {
scrollHoriz = Math.max(scrollHoriz - 15, 0);
onScrollH(scrollHoriz);
}
public void scrollRight() {
}
scrollHoriz = Math.min(scrollHoriz + 15, getLastScrollPositionH());
onScrollH(scrollHoriz);
}
public int getLastScrollPosition() {
int position = _elements.size() - 1;
int heightUsed = _elements.get(position).getHeight();
while (position > 0 && heightUsed < sizeY) {
position--;
heightUsed += _elements.get(position).getHeight();
}
return position + 1;
}
public int getLastScrollPositionH() {
return Math.max(getInternalWidth() - getContentWidth(), 0);
}
public int getSelectedIndex() {
}
return _selectedIndex;
}
public int getIndexOf(Object value) {
for (int i = 0; i < _elements.size(); i++) {
if (_elements.get(i).getValue().equals(value)) {
return i;
}
}
return -1;
}
public IListBoxElement getSelectedElement() {
if (_selectedIndex == -1 || _selectedIndex == _elements.size()) {
return null;
}
return _elements.get(_selectedIndex);
}
public void setSelectedIndex(int index) {
if (index >= -1 && index != _selectedIndex && index < _elements.size()) {
_selectedIndex = index;
onSelectionChanged(_selectedIndex, getSelectedElement());
}
}
public IListBoxElement getElement(int index) {
return _elements.get(index);
}
public int getElementCount() {
return _elements.size();
}
public void scrollToV(int index) {
if (index >= 0 && index < _elements.size()) {
_firstIndexDisplayed = index;
}
}
public void scrollToH(int index) {
if (index >= 0 && index <= getLastScrollPositionH()) {
scrollHoriz = index;
}
}
protected void onElementClicked(IListBoxElement element) {
}
protected void onScrollV(int newStartIndex) {
}
protected void onScrollH(int newStartIndex) {
}
protected void onSelectionChanged(int newIndex, IListBoxElement newElement) {
}
}