Files
common/src/main/java/org/saturnclient/ui/Utils.java
T
selimaj-devandclaude 136621cc8d Remove UI code and icons nothing uses
TextureButton, ClickableTexture, Text, Notification and the FadeOut and
SlideX animations only Notification used, Utils.getOrNull and the
commented-out notify, Element.duration, the 17 PNG icons the Lucide SVGs
replaced, and the Textures constants for them and for files that don't
exist.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-27 19:14:17 +02:00

66 lines
2.6 KiB
Java

package org.saturnclient.ui;
import org.saturnclient.common.provider.GLFWProvider;
public class Utils {
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
return mouseX >= 0 &&
mouseX <= (elementWidth * elementScale) &&
mouseY >= 0 &&
mouseY <= (elementHeight * elementScale);
}
public static char getCharFromKey(int keyCode, int modifiers) {
boolean shift = (modifiers & GLFWProvider.GLFW_MOD_SHIFT) != 0;
// A-Z
if (keyCode >= GLFWProvider.GLFW_KEY_A && keyCode <= GLFWProvider.GLFW_KEY_Z) {
return (char) (shift
? 'A' + (keyCode - GLFWProvider.GLFW_KEY_A)
: 'a' + (keyCode - GLFWProvider.GLFW_KEY_A));
}
// 0-9
if (keyCode >= GLFWProvider.GLFW_KEY_0 && keyCode <= GLFWProvider.GLFW_KEY_9) {
return shift
? ")!@#$%^&*(".charAt(keyCode - GLFWProvider.GLFW_KEY_0)
: (char) ('0' + (keyCode - GLFWProvider.GLFW_KEY_0));
}
// Special characters
return switch (keyCode) {
case GLFWProvider.GLFW_KEY_SPACE -> ' ';
case GLFWProvider.GLFW_KEY_PERIOD -> shift ? '>' : '.';
case GLFWProvider.GLFW_KEY_COMMA -> shift ? '<' : ',';
case GLFWProvider.GLFW_KEY_MINUS -> shift ? '_' : '-';
case GLFWProvider.GLFW_KEY_EQUAL -> shift ? '+' : '=';
case GLFWProvider.GLFW_KEY_SEMICOLON -> shift ? ':' : ';';
case GLFWProvider.GLFW_KEY_APOSTROPHE -> shift ? '"' : '\'';
case GLFWProvider.GLFW_KEY_SLASH -> shift ? '?' : '/';
case GLFWProvider.GLFW_KEY_BACKSLASH -> shift ? '|' : '\\';
case GLFWProvider.GLFW_KEY_LEFT_BRACKET -> shift ? '{' : '[';
case GLFWProvider.GLFW_KEY_RIGHT_BRACKET -> shift ? '}' : ']';
case GLFWProvider.GLFW_KEY_GRAVE_ACCENT -> shift ? '~' : '`';
default -> '\0';
};
}
/**
* A display name from an id: each underscore-separated word capitalized, so
* "black_hole_white" becomes "Black Hole White".
*/
public static String nameFromId(String id) {
StringBuilder builder = new StringBuilder();
for (String word : id.split("_")) {
if (word.isEmpty()) {
continue;
}
if (!builder.isEmpty()) {
builder.append(' ');
}
builder.append(Character.toUpperCase(word.charAt(0))).append(word.substring(1));
}
return builder.toString();
}
}