package dev.photosync.mcapi.render;

/**
 * The drawing primitives every PhotoSync screen is built from.
 *
 * <p>Eleven methods, chosen because each one maps to something Minecraft has had
 * continuously since 1.20 even as the class holding it was renamed, moved behind
 * a render pipeline, or had its parameters reordered. Everything else the UI
 * draws -- buttons, scrollbars, text fields, tooltips, the timeline grid -- is
 * composed from these in {@code :shared:ui}, so a new Minecraft version costs
 * one adapter rather than one widget set.
 *
 * <p>Colours are packed 0xAARRGGBB. Coordinates are in GUI space, already
 * divided by the GUI scale, with the origin at the top-left.
 *
 * <p>An instance is only valid for the duration of the render call it was handed
 * to. Holding one past that draws into a frame that no longer exists.
 */
public interface RenderBridge {

    /** Width of the drawable area in GUI space. */
    int width();

    /** Height of the drawable area in GUI space. */
    int height();

    /** Fraction of a tick elapsed since the last one, for smooth animation. */
    float tickDelta();

    void fill(int x, int y, int width, int height, int argb);

    /** A vertical gradient. Cheap polish that would otherwise cost three fills and still look flat. */
    void gradient(int x, int y, int width, int height, int topArgb, int bottomArgb);

    /** A one-pixel outline drawn just inside the given rectangle. */
    void border(int x, int y, int width, int height, int argb);

    void text(String text, int x, int y, int argb, boolean shadow);

    /** Width of {@code text} in GUI pixels, for every layout decision the UI makes. */
    int textWidth(String text);

    /** Height of one line of text including its leading. */
    int lineHeight();

    void image(TextureHandle texture, int x, int y, int width, int height);

    /**
     * Draws part of a texture, with UVs in the 0..1 range.
     *
     * <p>The timeline crops tiles to a square this way instead of squashing
     * them, which is the whole reason the region variant exists.
     */
    void image(TextureHandle texture, int x, int y, int width, int height,
               float u0, float v0, float u1, float v1);

    /**
     * Clips subsequent drawing to a rectangle until the matching
     * {@link #popClip()}. Nests.
     */
    void pushClip(int x, int y, int width, int height);

    void popClip();
}
