All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.harium.etyl.ui.selection.BaseResizer Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.harium.etyl.ui.selection;

import com.harium.etyl.awt.stroke.DashedStroke;
import com.harium.etyl.core.input.mouse.MouseStateChanger;
import com.harium.etyl.commons.layer.Layer;

import java.awt.*;

public class BaseResizer extends Resizer {

    private final DashedStroke dash = new DashedStroke();
    private final BasicStroke resetStroke = new BasicStroke(1);

    public BaseResizer(MouseStateChanger mouseStateChanger) {
        super(mouseStateChanger);
    }

    public void draw(com.harium.etyl.core.graphics.Graphics g) {
        drawOverlay(g);

        if (!isSelected())
            return;

        g.setColor(java.awt.Color.BLACK);
        g.setStroke(dash);
        drawScaledRect(g, selected);

        if (!moveOnly) {
            for (int b = 0; b < 8; b++) {
                points[b].draw(g, offsetX, offsetY);
            }
        }

        g.setStroke(resetStroke);
    }

    public void drawOverlay(com.harium.etyl.core.graphics.Graphics g) {
        if (!overlay.isVisible()) {
            return;
        }

        g.setColor(com.harium.etyl.commons.graphics.Color.BLACK);
        g.setAlpha(60);
        fillScaledRect(g, overlay);
        g.resetOpacity();
    }

    private void drawScaledRect(com.harium.etyl.core.graphics.Graphics g, Layer layer) {
        int sw = (int) (layer.getW() * layer.getScaleX());
        int sh = (int) (layer.getH() * layer.getScaleY());

        int oX = (int) (layer.getW() * (1 - layer.getScaleX())) / 2;
        int oY = (int) (layer.getH() * (1 - layer.getScaleY())) / 2;

        g.drawRect(layer.getX() + oX + offsetX, layer.getY() + oY + offsetY, sw, sh);
    }

    private void fillScaledRect(com.harium.etyl.core.graphics.Graphics g, Layer layer) {
        int sw = (int) (layer.getW() * layer.getScaleX());
        int sh = (int) (layer.getH() * layer.getScaleY());

        int oX = (int) (layer.getW() * (1 - layer.getScaleX())) / 2;
        int oY = (int) (layer.getH() * (1 - layer.getScaleY())) / 2;

        g.fillRect(layer.getX() + oX + offsetX, layer.getY() + oY + offsetY, sw, sh);
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy