use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class AbstractGuiContainer method addElements.
@Override
public T addElements(LayoutData layoutData, GuiElement... elements) {
if (layoutData == null) {
layoutData = LayoutData.NONE;
}
for (GuiElement element : elements) {
this.elements.put(element, layoutData);
element.setContainer(this);
}
return getThis();
}
use of de.johni0702.minecraft.gui.element.GuiElement in project jGui by ReplayMod.
the class AbstractGuiContainer method draw.
@Override
public void draw(GuiRenderer renderer, ReadableDimension size, RenderInfo renderInfo) {
super.draw(renderer, size, renderInfo);
if (backgroundColor != null && renderInfo.getLayer() == 0) {
renderer.drawRect(0, 0, size.getWidth(), size.getHeight(), backgroundColor);
}
for (final Map.Entry<GuiElement, Pair<ReadablePoint, ReadableDimension>> e : layedOutElements.entrySet()) {
GuiElement element = e.getKey();
boolean strict;
if (element instanceof ComposedGuiElement) {
if (((ComposedGuiElement) element).getMaxLayer() < renderInfo.layer) {
continue;
}
strict = renderInfo.layer == 0;
} else {
if (element.getLayer() != renderInfo.layer) {
continue;
}
strict = true;
}
final ReadablePoint ePosition = e.getValue().getLeft();
final ReadableDimension eSize = e.getValue().getRight();
try {
OffsetGuiRenderer eRenderer = new OffsetGuiRenderer(renderer, ePosition, eSize, strict);
eRenderer.startUsing();
e.getKey().draw(eRenderer, eSize, renderInfo.offsetMouse(ePosition.getX(), ePosition.getY()).layer(renderInfo.getLayer() - e.getKey().getLayer()));
eRenderer.stopUsing();
} catch (Exception ex) {
CrashReport crashReport = CrashReport.create(ex, "Rendering Gui");
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());
MCVer.addDetail(category, "Layout", layout::toString);
category = crashReport.addElement("Gui element details");
MCVer.addDetail(category, "Element", () -> e.getKey().toString());
MCVer.addDetail(category, "Position", ePosition::toString);
MCVer.addDetail(category, "Size", eSize::toString);
if (e.getKey() instanceof GuiContainer) {
MCVer.addDetail(category, "Layout", () -> ((GuiContainer) e.getKey()).getLayout().toString());
}
throw new CrashException(crashReport);
}
}
}
use of de.johni0702.minecraft.gui.element.GuiElement 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);
}
}
}
}
use of de.johni0702.minecraft.gui.element.GuiElement 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.element.GuiElement in project jGui by ReplayMod.
the class HorizontalLayout method calcMinSize.
@Override
public ReadableDimension calcMinSize(GuiContainer<?> container) {
int maxHeight = 0;
int width = 0;
int spacing = 0;
for (Map.Entry<GuiElement, LayoutData> entry : container.getElements().entrySet()) {
width += spacing;
spacing = this.spacing;
GuiElement element = entry.getKey();
ReadableDimension minSize = element.getMinSize();
int height = minSize.getHeight();
if (height > maxHeight) {
maxHeight = height;
}
width += minSize.getWidth();
}
return new Dimension(width, maxHeight);
}
Aggregations