mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
added image alpha
This commit is contained in:
Binary file not shown.
+13
-4
@@ -1,11 +1,13 @@
|
||||
package org.diylc.components.misc;
|
||||
|
||||
import java.awt.AlphaComposite;
|
||||
import java.awt.Composite;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Point;
|
||||
|
||||
import javax.swing.ImageIcon;
|
||||
|
||||
import org.diylc.components.AbstractComponent;
|
||||
import org.diylc.components.AbstractTransparentComponent;
|
||||
import org.diylc.core.ComponentState;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.IDrawingObserver;
|
||||
@@ -15,7 +17,7 @@ import org.diylc.core.annotations.ComponentDescriptor;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc", description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.TEXT, stretchable = false)
|
||||
public class Image extends AbstractComponent<Void> {
|
||||
public class Image extends AbstractTransparentComponent<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
public static String DEFAULT_TEXT = "Double click to edit text";
|
||||
@@ -37,13 +39,20 @@ public class Image extends AbstractComponent<Void> {
|
||||
@Override
|
||||
public void draw(Graphics2D g2d, ComponentState componentState, Project project,
|
||||
IDrawingObserver drawingObserver) {
|
||||
Composite oldComposite = g2d.getComposite();
|
||||
if (alpha < MAX_ALPHA) {
|
||||
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1f * alpha
|
||||
/ MAX_ALPHA));
|
||||
}
|
||||
double s = 1d * scale / DEFAULT_SCALE;
|
||||
g2d.scale(s, s);
|
||||
g2d.drawImage(image.getImage(), (int) (point.x / s), (int) (point.y / s), null);
|
||||
g2d.setComposite(oldComposite);
|
||||
g2d.scale(1 / s, 1 / s);
|
||||
if (componentState == ComponentState.SELECTED) {
|
||||
g2d.setColor(SELECTION_COLOR);
|
||||
g2d.drawRect((int) (point.x / s), (int) (point.y / s), image.getIconWidth(), image
|
||||
.getIconHeight());
|
||||
g2d.drawRect(point.x, point.y, (int) (image.getIconWidth() * s), (int) (image
|
||||
.getIconHeight() * s));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user