use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class AtlasFormat method load.
@Override
public AtlasData load(ResourceUrn urn, List<AssetDataFile> inputs) throws IOException {
try (Reader reader = new InputStreamReader(inputs.get(0).openStream(), Charsets.UTF_8)) {
AtlasDefinition def = gson.fromJson(reader, AtlasDefinition.class);
Optional<? extends Texture> texture = assetManager.getAsset(def.getTexture(), Texture.class);
if (texture.isPresent()) {
Vector2i size = def.getTextureSize();
if (size == null) {
size = new Vector2i(texture.get().getWidth(), texture.get().getHeight());
}
Map<Name, SubtextureData> result = Maps.newHashMap();
if (def.getGrid() != null) {
process(def.getGrid(), texture.get(), size, result);
}
if (def.getGrids() != null) {
for (GridDefinition grid : def.getGrids()) {
process(grid, texture.get(), size, result);
}
}
if (def.getSubimage() != null) {
process(def.getSubimage(), texture.get(), size, result);
}
if (def.getSubimages() != null) {
for (FreeformDefinition freeform : def.getSubimages()) {
process(freeform, texture.get(), size, result);
}
}
return new AtlasData(result);
}
return null;
}
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class NUIManagerInternal method mouseWheelEvent.
// mouse wheel events
@ReceiveEvent(components = ClientComponent.class, priority = EventPriority.PRIORITY_HIGH)
public void mouseWheelEvent(MouseWheelEvent event, EntityRef entity) {
if (!mouse.isVisible()) {
return;
}
Vector2i mousePosition = event.getMousePosition();
if (focus != null) {
NUIMouseWheelEvent nuiEvent = new NUIMouseWheelEvent(mouse, keyboard, mousePosition, event.getWheelTurns());
focus.onMouseWheelEvent(nuiEvent);
if (nuiEvent.isConsumed()) {
event.consume();
return;
}
}
if (canvas.processMouseWheel(event.getWheelTurns(), mousePosition)) {
event.consume();
}
if (isReleasingMouse()) {
event.consume();
}
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class ContextMenuScreen method onDraw.
@Override
public void onDraw(Canvas canvas) {
canvas.addInteractionRegion(mainListener);
Vector2i currentPosition = null;
int currentWidth = 0;
for (UIList<AbstractContextMenuItem> level : menuWidgets) {
if (level.isVisible()) {
if (currentPosition == null) {
currentPosition = new Vector2i(position);
} else {
currentPosition.x += currentWidth;
}
Vector2i preferredSize = canvas.calculatePreferredSize(level);
Rectanglei region = new Rectanglei(currentPosition.x, currentPosition.y).setSize(preferredSize.x, preferredSize.y);
double percentageThreshold = 0.9;
int canvasHeight = canvas.getRegion().getSizeY();
if (region.maxY > canvasHeight * percentageThreshold) {
region = new Rectanglei(region.minX, region.minY - (region.maxY - canvasHeight) - (int) (canvasHeight * (1 - percentageThreshold))).setSize(region.maxX, canvasHeight);
}
currentWidth = canvas.calculatePreferredSize(level).x() - 8;
canvas.drawWidget(level, region);
}
}
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class ModuleDetailsScreen method setUpModules.
private void setUpModules() {
modules.subscribeSelection(((widget, item) -> {
if (item != null) {
dependencies.setList(getSortedDependencies(item));
dependencies.setSelection(null);
dependencies.select(0);
this.updateOpenInBrowserButton();
}
}));
modules.setItemRenderer(new StringTextRenderer<Module>() {
@Override
public String getString(Module value) {
if (value != null) {
return value.getMetadata().getDisplayName().toString();
}
return "";
}
@Override
public void draw(Module value, Canvas canvas) {
if (!validateModuleDependencies(value.getId())) {
canvas.setMode(("invalid"));
} else {
canvas.setMode("available");
}
canvas.drawText(getString(value), canvas.getRegion());
}
@Override
public Vector2i getPreferredSize(Module value, Canvas canvas) {
String text = getString(value);
return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
}
});
}
use of org.joml.Vector2i in project Terasology by MovingBlocks.
the class ModuleDetailsScreen method setUpDependencies.
private void setUpDependencies() {
dependencies.setList(Collections.emptyList());
dependencies.setItemRenderer(new AbstractItemRenderer<DependencyInfo>() {
private String getString(DependencyInfo value) {
if (value != null) {
return value.getId().toString();
}
return "";
}
@Override
public void draw(DependencyInfo value, Canvas canvas) {
Module module = moduleManager.getRegistry().getLatestModuleVersion(value.getId());
if (module == null || !(value.versionPredicate().test(module.getVersion()))) {
canvas.setMode("invalid");
} else {
canvas.setMode("available");
}
canvas.drawText(getString(value), canvas.getRegion());
}
@Override
public Vector2i getPreferredSize(DependencyInfo value, Canvas canvas) {
String text = getString(value);
canvas.getCurrentStyle().setTextColor(Color.RED);
return new Vector2i(canvas.getCurrentStyle().getFont().getWidth(text), canvas.getCurrentStyle().getFont().getLineHeight());
}
});
dependencies.subscribe(((widget, item) -> {
if (item != null) {
modules.getList().stream().filter(m -> item.getId().equals(m.getId())).findFirst().ifPresent(m -> modules.setSelection(m));
}
}));
}
Aggregations