| 5 | import io.github.humbleui.types.*; |
| 6 | |
| 7 | public abstract class Scene { |
| 8 | public static final Typeface inter = FontMgr.getDefault().makeFromFile(file("fonts/InterHinted-Regular.ttf")); |
| 9 | public static final Typeface jbMono = FontMgr.getDefault().makeFromFile(file("fonts/JetBrainsMono-Regular.ttf")); |
| 10 | public static final Font inter13 = new Font(inter, 13).setSubpixel(true); |
| 11 | public static final Paint blackFill = new Paint().setColor(0xFF000000); |
| 12 | |
| 13 | public String[] _variants = new String[] { "Default" }; |
| 14 | public int _variantIdx = 0; |
| 15 | |
| 16 | public boolean scale() { |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | public String variantTitle() { |
| 21 | return _variants[_variantIdx]; |
| 22 | } |
| 23 | |
| 24 | public void changeVariant(int delta) { |
| 25 | _variantIdx = (_variantIdx + _variants.length + delta) % _variants.length; |
| 26 | } |
| 27 | |
| 28 | public abstract void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos); |
| 29 | |
| 30 | public void onScroll(float dx, float dy) {} |
| 31 | |
| 32 | public static String file(String path) { |
| 33 | return "../scenes/" + path; |
| 34 | } |
| 35 | |
| 36 | public static void drawStringCentered(Canvas canvas, String text, float x, float y, Font font, Paint paint) { |
| 37 | Rect bounds = font.measureText(text, paint); |
| 38 | float lineHeight = font.getMetrics().getCapHeight(); |
| 39 | canvas.drawString(text, |
| 40 | x - bounds.getRight() / 2, |
| 41 | y + lineHeight / 2, |
| 42 | font, paint); |
| 43 | } |
| 44 | |
| 45 | public static void drawStringLeft(Canvas canvas, String text, Rect outer, Font font, Paint paint) { |
| 46 | Rect inner = font.measureText(text, paint); |
| 47 | FontMetrics metrics = font.getMetrics(); |
| 48 | float innerHeight = metrics.getDescent() - metrics.getAscent(); |
| 49 | |
| 50 | canvas.drawString(text, |
| 51 | outer.getLeft(), |
| 52 | outer.getTop() + (outer.getHeight() - innerHeight) / 2f - metrics.getAscent(), |
| 53 | font, paint); |
| 54 | } |
| 55 | |
| 56 | public static float phase() { |
| 57 | var angle = (System.currentTimeMillis() % 5000) / 5000.0 * Math.PI * 2.0; |
| 58 | var phase = Math.sin(angle) * 1.2; |
| 59 | phase = Math.min(1.0, Math.max(-1.0, phase)); |
| 60 | return (float) (phase + 1) / 2f; |
| 61 | } |
| 62 | |
| 63 | public static String formatFloat(float f) { |
| 64 | return String.format(Locale.ENGLISH, "%.02f", f).replaceAll("\\.?0+$", ""); |
nothing calls this directly
no test coverage detected