use of de.johni0702.minecraft.gui.utils.lwjgl.Point 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.Point 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.Point 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.Point in project jGui by ReplayMod.
the class AbstractGuiSlider method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
int width = size.getWidth();
int height = size.getHeight();
renderer.bindTexture(GuiButton.WIDGETS_TEXTURE);
// Draw background
renderer.drawTexturedRect(0, 0, 0, 46, width / 2, height);
renderer.drawTexturedRect(width / 2, 0, 200 - width / 2, 46, width / 2, height);
// Draw slider
int sliderX = (width - 8) * value / steps;
renderer.drawTexturedRect(sliderX, 0, 0, 66, 4, 20);
renderer.drawTexturedRect(sliderX + 4, 0, 196, 66, 4, 20);
// Draw text
int color = 0xe0e0e0;
if (!isEnabled()) {
color = 0xa0a0a0;
} else if (isMouseHovering(new Point(renderInfo.mouseX, renderInfo.mouseY))) {
color = 0xffffa0;
}
renderer.drawCenteredString(width / 2, height / 2 - 4, color, text);
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point 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;
}
Aggregations