Skip to content

ImageIndicator

roosit edited this page May 31, 2026 · 2 revisions

ImageIndicator

Up | Previous | Next | Русский

Full source code with brief explanations

Below is the full source code of the class in documentation form. Comments inside the block explain the purpose of class parts, but they are not stored in the working file ImageIndicator.java: production code stays clean, and explanations live in the wiki.

package com.velitask.plugin.official;

import com.velitask.sdk.Indicator;
import com.velitask.sdk.IndicatorContext;
import com.velitask.sdk.IndicatorSkin;
import com.velitask.sdk.properties.BorderProperty;
import com.velitask.sdk.properties.DisplayConfig;
import com.velitask.sdk.properties.IProperty;
import com.velitask.sdk.properties.ImageSourceProperty;
import com.velitask.sdk.properties.PropertyGroup;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import org.abricos.core.state.maket.HorizontalAlign;
import org.abricos.core.state.maket.Maket;
import org.abricos.core.state.maket.VerticalAlign;

/*
 * Static image overlay: takes a frame from the selected image source,
 * fits it inside the layer and, if needed, draws a border (straight or
 * rounded) over the edges.
 */
public class ImageIndicator extends Indicator {

    /* Stable indicator name for saved projects, templates, and localization. */
    public static final String NAME = "image";

    /* Base localization key for title, description, tags, and skin. */
    private static final String KEY = _KEY + "." + NAME;

    /* Image source. The frame is static and does not depend on player time. */
    private final ImageSourceProperty mImage = new ImageSourceProperty();

    /* Border: color, thickness, line style, and corner radius. */
    private final BorderProperty mBorder = new BorderProperty();

    /* Access to the image property for runtime and UI. */
    public ImageSourceProperty getImage() {
        return mImage;
    }

    /* Access to the border property for runtime and UI. */
    public BorderProperty getBorder() {
        return mBorder;
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    public String getTitle() {
        return localized(KEY + ".title");
    }

    @Override
    public String getDescription() {
        return localized(KEY + ".description");
    }

    @Override
    public String getTags() {
        return localized(KEY + ".tags");
    }

    /*
     * Initial layout: bottom-right, 50 px margin from bottom and right, 480 x 270 layer.
     */
    @Override
    public void defineMaket(Maket maket) {
        maket.setVertical(VerticalAlign.BOTTOM);
        maket.setHorizontal(HorizontalAlign.RIGHT);
        maket.setLayerMargin(null, null, 50d, 50d);
        maket.setLayerSize(480d, 270d);
    }

    /*
     * Registers properties in UI order: image source, border.
     */
    @Override
    public IProperty[] defineProperties() {
        return new IProperty[]{
            mImage, mBorder
        };
    }

    /*
     * In the property panel, the border belongs to appearance.
     */
    @Override
    public void configureDisplay(DisplayConfig config) {
        config.set(mBorder, PropertyGroup.APPEARANCE);
    }

    /*
     * Two skins change only the border parameters:
     * framed — white straight border, thickness 4, no rounding;
     * rounded — no border, corner radius 30.
     */
    @Override
    public IndicatorSkin[] defineSkins() {
        return new IndicatorSkin[]{
            IndicatorSkin.builder("framed", localized(KEY + ".skin.framed"))
            .set(mBorder.getColor().skin(Color.WHITE))
            .set(mBorder.getThickness().skin(4))
            .set(mBorder.getRadius().skin(0))
            .build(),
            IndicatorSkin.builder("rounded", localized(KEY + ".skin.rounded"))
            .set(mBorder.getColor().skin(Color.WHITE))
            .set(mBorder.getThickness().skin(0))
            .set(mBorder.getRadius().skin(30))
            .build()
        };
    }

    /*
     * Render fits the frame inside the layer accounting for border thickness, with a
     * non-zero radius clips the image by a rounded rectangle and strokes the outline.
     */
    @Override
    public void render(IndicatorContext indicatorContext) {
        ImageContext ctx = (ImageContext) indicatorContext;
        Graphics2D g = ctx.graphics;

        /* Thickness and radius are scaled to the current frame size. */
        int bw = (int) (ctx.border.thickness * ctx.scale);
        int cr = (int) (ctx.border.radius * ctx.scale);
        /* Inner area — layer minus space for the border, at least 1 px. */
        int innerW = Math.max(1, ctx.width - bw);
        int innerH = Math.max(1, ctx.height - bw);

        /*
         * Player time is converted to source raw-time. The image is static,
         * so rawTime does not affect the result, but the frame is requested at
         * the needed size innerW x innerH.
         */
        long rawTime = mImage.convertToRawTime(ctx.player.time);
        BufferedImage frame = ctx.image.frameAt(rawTime, innerW, innerH);
        if (frame == null) {
            return;
        }

        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

        /* With rounding a clip by RoundRectangle is set temporarily, then restored. */
        Shape originalClip = g.getClip();
        if (cr > 0) {
            g.setClip(new RoundRectangle2D.Float(
                    bw / 2f, bw / 2f, innerW, innerH, cr, cr)
            );
        }
        g.drawImage(frame, bw / 2, bw / 2, innerW, innerH, null);
        g.setClip(originalClip);

        /* The border is drawn only at non-zero thickness, straight or rounded. */
        if (bw > 0) {
            g.setColor(ctx.border.color);
            g.setStroke(new BasicStroke(bw));
            if (cr > 0) {
                g.drawRoundRect(bw / 2, bw / 2, innerW, innerH, cr, cr);
            } else {
                g.drawRect(bw / 2, bw / 2, innerW, innerH);
            }
        }
    }

    /* Context fixes property snapshots for a specific frame. */
    public class ImageContext extends IndicatorContext {

        public final BorderProperty.BorderContext border;
        public final ImageSourceProperty.ImageSourceContext image;

        public ImageContext(Player player, Canvas canvas) {
            super(player, canvas);
            border = mBorder.createContext();
            image = mImage.createContext();
        }
    }

    @Override
    public IndicatorContext createContext(IndicatorContext.Player player, IndicatorContext.Canvas canvas) {
        return new ImageContext(player, canvas);
    }
}

Purpose

ImageIndicator is a static image overlay indicator. It takes a frame from the selected project image source, fits it into the layer, and optionally strokes it with a border. The main use case is overlaying a logo, photo, or arbitrary picture on top of a Mixel, similar to VideoIndicator but without time dependency.

How it works

Data. Through ImageSourceProperty, the indicator gets a BufferedImage via the frameAt(rawTime, w, h) method. Player time is converted to source raw-time through convertToRawTime, but the image is static: the same frame is returned for the entire source duration, and rawTime is accepted only for symmetry with video access. The frame is requested directly at the target inner area size, so scaling is done by the source itself with caching.

Settings. Two properties: image source (ImageSourceProperty) and border (BorderProperty). BorderProperty extends LineProperty (color, thickness, line style, dash pattern) and adds CornerRadiusProperty — the corner radius. The source is structural and does not participate in skin/template; the border belongs to appearance.

Drawing. Border thickness bw and radius cr are scaled by ctx.scale. The inner area is computed as the layer size minus bw (at least 1 px). The frame is requested at innerW x innerH; when cr > 0 the image is clipped by a RoundRectangle2D, then drawn via drawImage. If bw > 0, the outline is stroked with drawRoundRect or drawRect in the border color with antialiasing enabled.

Features and limitations

  • If the image source is not selected or empty, frameAt returns null and the indicator draws nothing.
  • The image is static: player time does not affect the shown frame, seeking does not change the picture.
  • Thickness and radius are set in base-frame coordinates and scaled to the actual layer size through ctx.scale.
  • The border is drawn over the image edges: half its thickness goes outward relative to the inner area.
  • Skin framed gives a white straight border of thickness 4 without rounding, skin rounded — rounding 30 without a border; the user can override both parameters manually.

Clone this wiki locally