diff --git a/diylc/diylc-core/src/org/diylc/presenter/update.xml b/diylc/diylc-core/src/org/diylc/presenter/update.xml
index 7f79307d..9a2ef701 100644
--- a/diylc/diylc-core/src/org/diylc/presenter/update.xml
+++ b/diylc/diylc-core/src/org/diylc/presenter/update.xml
@@ -3257,7 +3257,15 @@
NEW_FEATURE
macOS: added quick action toolbar that was already available for other platforms
-
+
+
+ NEW_FEATURE
+ Added ability to rotate images
+
+
+ BUG_FIX
+ Project cloud -> replace project had no effect
+
https://github.com/bancika/diy-layout-creator/releases
diff --git a/diylc/diylc-library/src/org/diylc/components/misc/Image.java b/diylc/diylc-library/src/org/diylc/components/misc/Image.java
index 816ee442..1f9c9ea3 100644
--- a/diylc/diylc-library/src/org/diylc/components/misc/Image.java
+++ b/diylc/diylc-library/src/org/diylc/components/misc/Image.java
@@ -34,7 +34,9 @@ import org.apache.poi.util.IOUtils;
import org.diylc.appframework.miscutils.IconImageConverter;
import org.diylc.awt.ImageUtils;
import org.diylc.common.ObjectCache;
+import org.diylc.common.Orientation;
import org.diylc.components.AbstractTransparentComponent;
+import org.diylc.components.transform.ImageTransformer;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.IDrawingObserver;
@@ -49,7 +51,7 @@ import com.thoughtworks.xstream.annotations.XStreamConverter;
@ComponentDescriptor(name = "Image", author = "Branislav Stojkovic", category = "Misc",
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 {
private static final long serialVersionUID = 1L;
@@ -59,6 +61,8 @@ public class Image extends AbstractTransparentComponent {
private Point2D.Double point = new Point2D.Double(0, 0);
private Point2D.Double secondPoint = null;
+
+ private Orientation orientation;
static {
String name = "image.png";
@@ -124,8 +128,14 @@ public class Image extends AbstractTransparentComponent {
x = Math.min(point.getX(), secondPoint.getX());
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.drawImage(imageIcon.getImage(), (int) (x / scaleX), (int) (y / scaleY), null);
if (componentState == ComponentState.SELECTED) {
g2d.setComposite(oldComposite);
@@ -249,6 +259,17 @@ public class Image extends AbstractTransparentComponent {
@Override
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 {
TwoPoints("Opposing Points"), Scale("Scale");
diff --git a/diylc/diylc-library/src/org/diylc/components/transform/ImageTransformer.java b/diylc/diylc-library/src/org/diylc/components/transform/ImageTransformer.java
new file mode 100644
index 00000000..3da1131e
--- /dev/null
+++ b/diylc/diylc-library/src/org/diylc/components/transform/ImageTransformer.java
@@ -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 .
+
+*/
+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) {
+ }
+}