mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Added ability to rotate images
This commit is contained in:
@@ -3257,7 +3257,15 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>NEW_FEATURE</changeType>
|
<changeType>NEW_FEATURE</changeType>
|
||||||
<description>macOS: added quick action toolbar that was already available for other platforms</description>
|
<description>macOS: added quick action toolbar that was already available for other platforms</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>NEW_FEATURE</changeType>
|
||||||
|
<description>Added ability to rotate images</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>BUG_FIX</changeType>
|
||||||
|
<description>Project cloud -> replace project had no effect</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
</changes>
|
</changes>
|
||||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||||
</org.diylc.appframework.update.Version>
|
</org.diylc.appframework.update.Version>
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ import org.apache.poi.util.IOUtils;
|
|||||||
import org.diylc.appframework.miscutils.IconImageConverter;
|
import org.diylc.appframework.miscutils.IconImageConverter;
|
||||||
import org.diylc.awt.ImageUtils;
|
import org.diylc.awt.ImageUtils;
|
||||||
import org.diylc.common.ObjectCache;
|
import org.diylc.common.ObjectCache;
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
import org.diylc.components.AbstractTransparentComponent;
|
import org.diylc.components.AbstractTransparentComponent;
|
||||||
|
import org.diylc.components.transform.ImageTransformer;
|
||||||
import org.diylc.core.ComponentState;
|
import org.diylc.core.ComponentState;
|
||||||
import org.diylc.core.IDIYComponent;
|
import org.diylc.core.IDIYComponent;
|
||||||
import org.diylc.core.IDrawingObserver;
|
import org.diylc.core.IDrawingObserver;
|
||||||
@@ -49,7 +51,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
|
|||||||
|
|
||||||
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
|
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
|
||||||
description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT,
|
description = "User defined image", instanceNamePrefix = "Img", zOrder = IDIYComponent.COMPONENT,
|
||||||
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW)
|
flexibleZOrder = true, bomPolicy = BomPolicy.NEVER_SHOW, transformer = ImageTransformer.class)
|
||||||
public class Image extends AbstractTransparentComponent<Void> {
|
public class Image extends AbstractTransparentComponent<Void> {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
@@ -59,6 +61,8 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
|
|
||||||
private Point2D.Double point = new Point2D.Double(0, 0);
|
private Point2D.Double point = new Point2D.Double(0, 0);
|
||||||
private Point2D.Double secondPoint = null;
|
private Point2D.Double secondPoint = null;
|
||||||
|
|
||||||
|
private Orientation orientation;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
String name = "image.png";
|
String name = "image.png";
|
||||||
@@ -124,8 +128,14 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
x = Math.min(point.getX(), secondPoint.getX());
|
x = Math.min(point.getX(), secondPoint.getX());
|
||||||
y = Math.min(point.getY(), secondPoint.getY());
|
y = Math.min(point.getY(), secondPoint.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (getOrientation() != Orientation.DEFAULT) {
|
||||||
|
double theta = getOrientation().toRadians();
|
||||||
|
g2d.rotate(theta, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
g2d.scale(scaleX, scaleY);
|
g2d.scale(scaleX, scaleY);
|
||||||
|
|
||||||
g2d.drawImage(imageIcon.getImage(), (int) (x / scaleX), (int) (y / scaleY), null);
|
g2d.drawImage(imageIcon.getImage(), (int) (x / scaleX), (int) (y / scaleY), null);
|
||||||
if (componentState == ComponentState.SELECTED) {
|
if (componentState == ComponentState.SELECTED) {
|
||||||
g2d.setComposite(oldComposite);
|
g2d.setComposite(oldComposite);
|
||||||
@@ -249,6 +259,17 @@ public class Image extends AbstractTransparentComponent<Void> {
|
|||||||
@Override
|
@Override
|
||||||
public void setValue(Void value) {}
|
public void setValue(Void value) {}
|
||||||
|
|
||||||
|
@EditableProperty
|
||||||
|
public Orientation getOrientation() {
|
||||||
|
if (orientation == null)
|
||||||
|
orientation = Orientation.DEFAULT;
|
||||||
|
return orientation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrientation(Orientation orientation) {
|
||||||
|
this.orientation = orientation;
|
||||||
|
}
|
||||||
|
|
||||||
public static enum ImageSizingMode {
|
public static enum ImageSizingMode {
|
||||||
TwoPoints("Opposing Points"), Scale("Scale");
|
TwoPoints("Opposing Points"), Scale("Scale");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
DIY Layout Creator (DIYLC).
|
||||||
|
Copyright (c) 2009-2018 held jointly by the individual authors.
|
||||||
|
|
||||||
|
This file is part of DIYLC.
|
||||||
|
|
||||||
|
DIYLC is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
DIYLC is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with DIYLC. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
*/
|
||||||
|
package org.diylc.components.transform;
|
||||||
|
|
||||||
|
import java.awt.geom.AffineTransform;
|
||||||
|
import java.awt.geom.Point2D;
|
||||||
|
|
||||||
|
import org.diylc.common.IComponentTransformer;
|
||||||
|
import org.diylc.common.Orientation;
|
||||||
|
import org.diylc.components.misc.Image;
|
||||||
|
import org.diylc.core.IDIYComponent;
|
||||||
|
|
||||||
|
public class ImageTransformer implements IComponentTransformer {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRotate(IDIYComponent<?> component) {
|
||||||
|
return component.getClass().equals(Image.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canMirror(IDIYComponent<?> component) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mirroringChangesCircuit() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void rotate(IDIYComponent<?> component, Point2D center, int direction) {
|
||||||
|
AffineTransform rotate = AffineTransform.getRotateInstance(Math.PI / 2 * direction, center.getX(), center.getY());
|
||||||
|
for (int index = 0; index < component.getControlPointCount(); index++) {
|
||||||
|
Point2D p = new Point2D.Double();
|
||||||
|
rotate.transform(component.getControlPoint(index), p);
|
||||||
|
component.setControlPoint(p, index);
|
||||||
|
}
|
||||||
|
|
||||||
|
Image snap = (Image) component;
|
||||||
|
Orientation o = snap.getOrientation();
|
||||||
|
int oValue = o.ordinal();
|
||||||
|
oValue += direction;
|
||||||
|
if (oValue < 0)
|
||||||
|
oValue = Orientation.values().length - 1;
|
||||||
|
if (oValue >= Orientation.values().length)
|
||||||
|
oValue = 0;
|
||||||
|
o = Orientation.values()[oValue];
|
||||||
|
snap.setOrientation(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void mirror(IDIYComponent<?> component, Point2D center, int direction) {
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user