use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiDropdownMenu method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
TextRenderer fontRenderer = MCVer.getFontRenderer();
if (renderInfo.layer == 0) {
int width = size.getWidth();
int height = size.getHeight();
// Draw box
renderer.drawRect(0, 0, width, height, OUTLINE_COLOR);
renderer.drawRect(1, 1, width - 2, height - 2, ReadableColor.BLACK);
renderer.drawRect(width - height, 0, 1, height, OUTLINE_COLOR);
// Draw triangle
int base = height - 6;
int tHeight = base / 2;
int x = width - 3 - base / 2;
int y = height / 2 - 2;
for (int layer = tHeight; layer > 0; layer--) {
renderer.drawRect(x - layer, y + (tHeight - layer), layer * 2 - 1, 1, OUTLINE_COLOR);
}
renderer.drawString(3, height / 2 - fontRenderer.fontHeight / 2, ReadableColor.WHITE, toString.apply(getSelectedValue()));
} else if (renderInfo.layer == 1) {
ReadablePoint offsetPoint = new Point(0, size.getHeight());
ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.fontHeight + 5) * values.length);
OffsetGuiRenderer offsetRenderer = new OffsetGuiRenderer(renderer, offsetPoint, offsetSize);
offsetRenderer.startUsing();
try {
dropdown.draw(offsetRenderer, offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0));
} finally {
offsetRenderer.stopUsing();
}
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiDropdownMenu method layout.
@Override
public void layout(ReadableDimension size, RenderInfo renderInfo) {
super.layout(size, renderInfo);
TextRenderer fontRenderer = MCVer.getFontRenderer();
if (renderInfo.layer == 1) {
ReadablePoint offsetPoint = new Point(0, size.getHeight());
ReadableDimension offsetSize = new Dimension(size.getWidth(), (fontRenderer.fontHeight + 5) * values.length);
dropdown.layout(offsetSize, renderInfo.offsetMouse(0, offsetPoint.getY()).layer(0));
}
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class CustomLayout method layOut.
@Override
@SuppressWarnings("unchecked")
public Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> layOut(GuiContainer container, ReadableDimension size) {
result.clear();
if (parent == null) {
Collection<GuiElement> elements = container.getChildren();
for (GuiElement element : elements) {
result.put(element, Pair.of(new Point(0, 0), new Dimension(element.getMinSize())));
}
} else {
Map<GuiElement, Pair<ReadablePoint, ReadableDimension>> elements = parent.layOut(container, size);
for (Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> entry : elements.entrySet()) {
Pair<ReadablePoint, ReadableDimension> pair = entry.getValue();
result.put(entry.getKey(), Pair.of(new Point(pair.getLeft()), new Dimension(pair.getRight())));
}
}
layout((T) container, size.getWidth(), size.getHeight());
return (Map) result;
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class MouseUtils method getMousePos.
public static Point getMousePos() {
// #if MC>=11400
int mouseX = (int) mc.mouse.getX();
int mouseY = (int) mc.mouse.getY();
Window mainWindow = MCVer.newScaledResolution(mc);
mouseX = (int) Math.round((double) mouseX * mainWindow.getScaledWidth() / mainWindow.getWidth());
mouseY = (int) Math.round((double) mouseY * mainWindow.getScaledHeight() / mainWindow.getHeight());
return new Point(mouseX, mouseY);
}
use of de.johni0702.minecraft.gui.utils.lwjgl.Point in project jGui by ReplayMod.
the class AbstractGuiScreen method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
if (renderInfo.layer == 0) {
switch(background) {
case NONE:
break;
case DEFAULT:
// #if MC>=11600
wrapped.renderBackground(renderer.getMatrixStack());
// #endif
break;
case TRANSPARENT:
int top = 0xc0_10_10_10, bottom = 0xd0_10_10_10;
renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), top, top, bottom, bottom);
break;
case DIRT:
// #if MC>=11600
wrapped.renderBackgroundTexture(0);
// #endif
break;
}
if (title != null) {
ReadableDimension titleSize = title.getMinSize();
int x = screenSize.getWidth() / 2 - titleSize.getWidth() / 2;
OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, new Point(x, 10), new Dimension(0, 0));
title.draw(eRenderer, titleSize, renderInfo);
}
}
super.draw(renderer, size, renderInfo);
if (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);
}
}
}
}
Aggregations