mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
Added ability to rotate images
This commit is contained in:
@@ -3258,6 +3258,14 @@
|
||||
<changeType>NEW_FEATURE</changeType>
|
||||
<description>macOS: added quick action toolbar that was already available for other platforms</description>
|
||||
</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>
|
||||
<url>https://github.com/bancika/diy-layout-creator/releases</url>
|
||||
</org.diylc.appframework.update.Version>
|
||||
|
||||
@@ -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<Void> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -60,6 +62,8 @@ public class Image extends AbstractTransparentComponent<Void> {
|
||||
private Point2D.Double point = new Point2D.Double(0, 0);
|
||||
private Point2D.Double secondPoint = null;
|
||||
|
||||
private Orientation orientation;
|
||||
|
||||
static {
|
||||
String name = "image.png";
|
||||
java.net.URL imgURL = Image.class.getResource(name);
|
||||
@@ -125,7 +129,13 @@ public class Image extends AbstractTransparentComponent<Void> {
|
||||
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<Void> {
|
||||
@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");
|
||||
|
||||
|
||||
@@ -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