use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiSlider method mouseDrag.
@Override
public boolean mouseDrag(ReadablePoint position, int button, long timeSinceLastCall) {
if (dragging) {
Point pos = new Point(position);
if (getContainer() != null) {
getContainer().convertFor(this, pos);
}
updateValue(pos);
}
return dragging;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiTextField method typeKey.
@Override
public boolean typeKey(ReadablePoint mousePosition, int keyCode, char keyChar, boolean ctrlDown, boolean shiftDown) {
if (!this.focused) {
return false;
}
if (keyCode == Keyboard.KEY_TAB) {
Focusable other = shiftDown ? previous : next;
if (other != null) {
setFocused(false);
other.setFocused(true);
// If the other field is a text field, by default select all its text (saves a Ctrl+A)
if (other instanceof AbstractGuiTextField) {
AbstractGuiTextField<?> field = (AbstractGuiTextField<?>) other;
field.cursorPos = 0;
field.selectionPos = field.text.length();
}
}
return true;
}
if (keyCode == Keyboard.KEY_RETURN) {
onEnter();
return true;
}
String textBefore = text;
try {
if (Screen.hasControlDown()) {
switch(keyCode) {
case // Select all
Keyboard.KEY_A:
cursorPos = 0;
selectionPos = text.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(deleteSelectedText());
}
return true;
}
}
boolean words = Screen.hasControlDown();
boolean select = Screen.hasShiftDown();
switch(keyCode) {
case Keyboard.KEY_HOME:
cursorPos = 0;
break;
case Keyboard.KEY_END:
cursorPos = text.length();
break;
case Keyboard.KEY_LEFT:
if (cursorPos != 0) {
if (words) {
cursorPos -= getPreviousWordLength();
} else {
cursorPos--;
}
}
break;
case Keyboard.KEY_RIGHT:
if (cursorPos != text.length()) {
if (words) {
cursorPos += getNextWordLength();
} else {
cursorPos++;
}
}
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) {
selectionPos = cursorPos;
}
return true;
} finally {
if (!textBefore.equals(text)) {
onTextChanged(textBefore);
}
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class HorizontalLayout method layOut.
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
int x = 0;
int spacing = 0;
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
x += spacing;
spacing = this.spacing;
GuiElement element = entry.getKey();
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
Dimension elementSize = new Dimension(element.getMinSize());
ReadableDimension elementMaxSize = element.getMaxSize();
elementSize.setWidth(Math.min(size.getWidth() - x, Math.min(elementSize.getWidth(), elementMaxSize.getWidth())));
elementSize.setHeight(Math.min(size.getHeight(), elementMaxSize.getHeight()));
int remainingHeight = size.getHeight() - elementSize.getHeight();
int y = (int) (data.alignment * remainingHeight);
map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
x += elementSize.getWidth();
}
if (alignment != Alignment.LEFT) {
int remaining = size.getWidth() - x;
if (alignment == Alignment.CENTER) {
remaining /= 2;
}
for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
((Point) pair.getLeft()).translate(remaining, 0);
}
}
return map;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class VerticalLayout method layOut.
@Override
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer<?> container, ReadableDimension size) {
int y = 0;
int spacing = 0;
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> map = new LinkedHashMap<>();
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
y += spacing;
spacing = this.spacing;
GuiElement element = entry.getKey();
Data data = entry.getValue() instanceof Data ? (Data) entry.getValue() : DEFAULT_DATA;
Dimension elementSize = new Dimension(element.getMinSize());
ReadableDimension elementMaxSize = element.getMaxSize();
elementSize.setHeight(Math.min(size.getHeight() - y, Math.min(elementSize.getHeight(), elementMaxSize.getHeight())));
elementSize.setWidth(Math.min(size.getWidth(), (data.maximizeWidth ? elementMaxSize : elementSize).getWidth()));
int remainingWidth = size.getWidth() - elementSize.getWidth();
int x = (int) (data.alignment * remainingWidth);
map.put(element, Pair.<ReadablePoint, ReadableDimension>of(new Point(x, y), elementSize));
y += elementSize.getHeight();
}
if (alignment != Alignment.TOP) {
int remaining = size.getHeight() - y;
if (alignment == Alignment.CENTER) {
remaining /= 2;
}
for (Pair<ReadablePoint, ReadableDimension> pair : map.values()) {
((Point) pair.getLeft()).translate(0, remaining);
}
}
return map;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint in project jGui by ReplayMod.
the class AbstractGuiContainer method convertFor.
@Override
public void convertFor(GuiElement element, Point point, int relativeLayer) {
if (layedOutElements == null || !layedOutElements.containsKey(element)) {
layout(null, new RenderInfo(0, 0, 0, relativeLayer));
}
checkState(layedOutElements != null, "Cannot convert position unless rendered at least once.");
Pair<ReadablePoint, ReadableDimension> pair = layedOutElements.get(element);
checkState(pair != null, "Element " + element + " not part of " + this);
ReadablePoint pos = pair.getKey();
if (getContainer() != null) {
getContainer().convertFor(this, point, relativeLayer + getLayer());
}
point.translate(-pos.getX(), -pos.getY());
}
Aggregations