use of de.johni0702.minecraft.gui.utils.lwjgl.Point 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.Point 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());
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiOverlay method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
if (mouseVisible && renderInfo.layer == getMaxLayer()) {
final GuiElement tooltip = forEach(GuiElement.class, e -> e.getTooltip(renderInfo));
if (tooltip != null) {
final ReadableDimension tooltipSize = tooltip.getMinSize();
int x, y;
if (renderInfo.mouseX + 8 + tooltipSize.getWidth() < screenSize.getWidth()) {
x = renderInfo.mouseX + 8;
} else {
x = screenSize.getWidth() - tooltipSize.getWidth() - 1;
}
if (renderInfo.mouseY + 8 + tooltipSize.getHeight() < screenSize.getHeight()) {
y = renderInfo.mouseY + 8;
} else {
y = screenSize.getHeight() - tooltipSize.getHeight() - 1;
}
final ReadablePoint position = new Point(x, y);
try {
OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, position, tooltipSize);
tooltip.draw(eRenderer, tooltipSize, renderInfo);
} catch (Exception ex) {
CrashReport crashReport = CrashReport.create(ex, "Rendering Gui Tooltip");
renderInfo.addTo(crashReport);
CrashReportSection category = crashReport.addElement("Gui container details");
MCVer.addDetail(category, "Container", this::toString);
MCVer.addDetail(category, "Width", () -> "" + size.getWidth());
MCVer.addDetail(category, "Height", () -> "" + size.getHeight());
category = crashReport.addElement("Tooltip details");
MCVer.addDetail(category, "Element", tooltip::toString);
MCVer.addDetail(category, "Position", position::toString);
MCVer.addDetail(category, "Size", tooltipSize::toString);
throw new CrashException(crashReport);
}
}
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiVerticalList method convert.
private ReadablePoint convert(ReadablePoint readablePoint) {
if (getContainer() != null) {
Point point = new Point(readablePoint);
getContainer().convertFor(this, point);
return point;
}
return readablePoint;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiTimeline method getTimeAt.
/**
* Returns the time which the mouse is at.
* @param mouseX X coordinate of the mouse
* @param mouseY Y coordinate of the mouse
* @return The time or -1 if the mouse isn't on the timeline
*/
protected int getTimeAt(int mouseX, int mouseY) {
if (getLastSize() == null) {
return -1;
}
Point mouse = new Point(mouseX, mouseY);
getContainer().convertFor(this, mouse);
mouseX = mouse.getX();
mouseY = mouse.getY();
if (mouseX < 0 || mouseY < 0 || mouseX > size.getWidth() || mouseY > size.getHeight()) {
return -1;
}
int width = size.getWidth();
int bodyWidth = width - BORDER_LEFT - BORDER_RIGHT;
double segmentLength = length * zoom;
double segmentTime = segmentLength * (mouseX - BORDER_LEFT) / bodyWidth;
return Math.min(Math.max((int) Math.round(offset + segmentTime), 0), length);
}
Aggregations