use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiColorPicker method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
if (renderInfo.layer == 0) {
int width = size.getWidth();
int height = size.getHeight();
// Draw outline
renderer.drawRect(0, 0, width, height, OUTLINE_COLOR);
// Draw color
renderer.drawRect(1, 1, width - 2, height - 2, color);
} else if (renderInfo.layer == 1) {
ReadablePoint offsetPoint = new Point(0, size.getHeight());
ReadableDimension offsetSize = new Dimension(PICKER_SIZE, PICKER_SIZE);
OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize);
offsetRenderer.startUsing();
try {
picker.draw(offsetRenderer, offsetSize, renderInfo);
} finally {
offsetRenderer.stopUsing();
}
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiTextArea method mouseClick.
@Override
public boolean mouseClick(ReadablePoint position, int button) {
if (getContainer() != null) {
getContainer().convertFor(this, (Point) (position = new Point(position)));
}
boolean hovering = isMouseHovering(position);
if (hovering && isFocused() && button == 0) {
updateCurrentOffset();
int mouseX = position.getX() - BORDER;
int mouseY = position.getY() - BORDER;
TextRenderer fontRenderer = MCVer.getFontRenderer();
int textY = clamp(mouseY / (fontRenderer.fontHeight + LINE_SPACING) + currentYOffset, 0, text.length - 1);
if (cursorY != textY) {
currentXOffset = 0;
}
String line = text[textY].substring(currentXOffset);
int textX = fontRenderer.trimToWidth(line, mouseX).length() + currentXOffset;
setCursorPosition(textX, textY);
}
setFocused(hovering);
return hovering;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiTextArea method typeKey.
@Override
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
if (keyCode == Keyboard.KEY_TAB) {
Focusable other = shiftDown ? previous : next;
if (other != null) {
setFocused(false);
other.setFocused(true);
}
return true;
}
if (!this.focused) {
return false;
}
if (Screen.hasControlDown()) {
switch(keyCode) {
case // Select all
Keyboard.KEY_A:
cursorX = cursorY = 0;
selectionY = text.length - 1;
selectionX = text[selectionY].length();
return true;
case // Copy
Keyboard.KEY_C:
MCVer.setClipboardString(getSelectedText());
return true;
case // Paste
Keyboard.KEY_V:
if (isEnabled()) {
writeText(MCVer.getClipboardString());
}
return true;
case // Cut
Keyboard.KEY_X:
if (isEnabled()) {
MCVer.setClipboardString(cutSelectedText());
}
return true;
}
}
boolean words = Screen.hasControlDown();
boolean select = Screen.hasShiftDown();
switch(keyCode) {
case Keyboard.KEY_HOME:
cursorX = 0;
break;
case Keyboard.KEY_END:
cursorX = text[cursorY].length();
break;
case Keyboard.KEY_LEFT:
if (cursorX == 0) {
if (cursorY > 0) {
cursorY--;
cursorX = text[cursorY].length();
}
} else {
if (words) {
cursorX -= getPreviousWordLength();
} else {
cursorX--;
}
}
break;
case Keyboard.KEY_RIGHT:
if (cursorX == text[cursorY].length()) {
if (cursorY < text.length - 1) {
cursorY++;
cursorX = 0;
}
} else {
if (words) {
cursorX += getNextWordLength();
} else {
cursorX++;
}
}
break;
case Keyboard.KEY_UP:
if (cursorY > 0) {
cursorY--;
cursorX = Math.min(cursorX, text[cursorY].length());
}
break;
case Keyboard.KEY_DOWN:
if (cursorY + 1 < text.length) {
cursorY++;
cursorX = Math.min(cursorX, text[cursorY].length());
}
break;
case Keyboard.KEY_BACK:
if (isEnabled()) {
if (getSelectedText().length() > 0) {
deleteSelectedText();
} else if (words) {
deletePreviousWord();
} else {
deletePreviousChar();
}
}
return true;
case Keyboard.KEY_DELETE:
if (isEnabled()) {
if (getSelectedText().length() > 0) {
deleteSelectedText();
} else if (words) {
deleteNextWord();
} else {
deleteNextChar();
}
}
return true;
default:
if (isEnabled()) {
if (keyChar == '\r') {
keyChar = '\n';
}
writeChar(keyChar);
}
return true;
}
if (!select) {
selectionX = cursorX;
selectionY = cursorY;
}
return true;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiHorizontalScrollbar method mouseClick.
@Override
public boolean mouseClick(ReadablePoint position, int button) {
Point pos = new Point(position);
if (getContainer() != null) {
getContainer().convertFor(this, pos);
}
if (isMouseHoveringBar(pos) && isEnabled()) {
dragging = true;
updateValue(pos);
return true;
}
return false;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiHorizontalScrollbar method isMouseHoveringBar.
protected boolean isMouseHoveringBar(ReadablePoint pos) {
int bodyWidth = getLastSize().getWidth() - BORDER_LEFT - BORDER_RIGHT;
int barOffset = (int) (bodyWidth * offset) + BORDER_LEFT;
int barWidth = (int) (bodyWidth * zoom);
return pos.getX() >= barOffset && pos.getY() > BORDER_TOP && pos.getX() <= barOffset + barWidth && pos.getY() < getLastSize().getHeight() - BORDER_BOTTOM;
}
Aggregations