Skip to content

Commit

Permalink
Improved image rendering and strand mode display
Browse files Browse the repository at this point in the history
  • Loading branch information
Crazydiamonde committed May 23, 2024
1 parent 9dbe149 commit 940b03b
Show file tree
Hide file tree
Showing 20 changed files with 169 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public boolean isAdditive() {
public abstract Image getImage();


/** Returns if this image is from a geometry object. */
public boolean isGeometryImage() {
return false;
}


public double getAlpha() {
return 1.0;
}
Expand Down Expand Up @@ -114,7 +120,7 @@ public void draw(GraphicsContext graphicsContext, boolean selected) {
if (isResizable()) {

graphicsContext.setStroke(Renderer.selectionOutline);
if (!true) {
if (isGeometryImage()) {
graphicsContext.fillRect(topLeft.getX() - 4, topLeft.getY() - 4, 8, 8);
graphicsContext.fillRect(bottomRight.getX() - 4, bottomRight.getY() - 4, 8, 8);
graphicsContext.fillRect(bottomLeft.getX() - 4, bottomLeft.getY() - 4, 8, 8);
Expand All @@ -131,7 +137,7 @@ public void draw(GraphicsContext graphicsContext, boolean selected) {
if (isRotatable()) {

graphicsContext.setStroke(Renderer.selectionOutline);
if (!true) {
if (isGeometryImage()) {
graphicsContext.fillOval(left.getX() - 4, left.getY() - 4, 8, 8);
graphicsContext.fillOval(right.getX() - 4, right.getY() - 4, 8, 8);
graphicsContext.setStroke(Renderer.selectionOutline2);
Expand All @@ -147,16 +153,19 @@ public void draw(GraphicsContext graphicsContext, boolean selected) {

if (isSelectable()) {

double absWidth = Math.abs(width);
double absHeight = Math.abs(height);

graphicsContext.setStroke(Renderer.selectionOutline2);
graphicsContext.setLineWidth(1);
graphicsContext.setLineDashes(3);
graphicsContext.setLineDashOffset(0);
graphicsContext.strokeRect(screenX2 - width * zoom / 2, screenY2 - height * zoom / 2, width * zoom, height * zoom);
graphicsContext.strokeRect(screenX2 - absWidth * zoom / 2, screenY2 - absHeight * zoom / 2, absWidth * zoom, absHeight * zoom);

graphicsContext.setStroke(Renderer.selectionOutline);
graphicsContext.setLineWidth(1);
graphicsContext.setLineDashOffset(3);
graphicsContext.strokeRect(screenX2 - width * zoom / 2, screenY2 - height * zoom / 2, width * zoom, height * zoom);
graphicsContext.strokeRect(screenX2 - absWidth * zoom / 2, screenY2 - absHeight * zoom / 2, absWidth * zoom, absHeight * zoom);
graphicsContext.setLineDashes(0);

}
Expand All @@ -175,8 +184,8 @@ public DragSettings mouseIntersection(double mouseX, double mouseY) {
double x = getX();
double y = getY();
double rotation = getRotation();
double width = image.getWidth() * getScaleX();
double height = image.getHeight() * getScaleY();
double width = image.getWidth() * Math.abs(getScaleX());
double height = image.getHeight() * Math.abs(getScaleY());

Point2D rotated = ObjectUtil.rotate(new Point2D(mouseX, mouseY), -rotation, new Point2D(x, y));

Expand Down Expand Up @@ -209,8 +218,8 @@ public DragSettings mouseIntersectingCorners(double mouseX, double mouseY) {
double x = getX();
double y = getY();
double rotation = getRotation();
double width = image.getWidth() * getScaleX();
double height = image.getHeight() * getScaleY();
double width = image.getWidth() * Math.abs(getScaleX());
double height = image.getHeight() * Math.abs(getScaleY());

Point2D center = new Point2D(x, y);

Expand Down Expand Up @@ -299,6 +308,8 @@ public DragSettings mouseIntersectingCorners(double mouseX, double mouseY) {
resizeSettings.setInitialSourceY(dragSourceRotated.getY());
resizeSettings.setAnchorX(dragAnchorRotated.getX());
resizeSettings.setAnchorY(dragAnchorRotated.getY());
resizeSettings.setInitialScaleX(getScaleX());
resizeSettings.setInitialScaleY(getScaleY());
return resizeSettings;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
public class ObjectResize {

public static void resizeFromMouse(double mouseX, double mouseY,
double resizeDragAnchorX, double resizeDragAnchorY) {
double resizeDragSourceX, double resizeDragSourceY,
double resizeDragAnchorX, double resizeDragAnchorY,
double resizeInitialScaleX, double resizeInitialScaleY) {

ObjectComponent objectComponent = SelectionManager.getDragSettings().getObjectComponent();

Expand All @@ -32,12 +34,18 @@ public static void resizeFromMouse(double mouseX, double mouseY,
double deltaX = rotatedReal.getX() - rotatedAnchor.getX();
double deltaY = rotatedReal.getY() - rotatedAnchor.getY();

deltaX *= Math.signum(resizeInitialScaleX);
deltaX *= Math.signum(resizeDragSourceX - resizeDragAnchorX);

deltaY *= Math.signum(resizeInitialScaleY);
deltaY *= Math.signum(resizeDragSourceY - resizeDragAnchorY);

if (objectComponent instanceof RectangleComponent rectangleComponent) {
rectangleComponent.setWidth(Math.abs(deltaX));
rectangleComponent.setHeight(Math.abs(deltaY));
} else if (objectComponent instanceof ImageComponent imageComponent) {
imageComponent.setScaleX(Math.abs(deltaX) / imageComponent.getImage().getWidth());
imageComponent.setScaleY(Math.abs(deltaY) / imageComponent.getImage().getHeight());
imageComponent.setScaleX(deltaX / imageComponent.getImage().getWidth());
imageComponent.setScaleY(deltaY / imageComponent.getImage().getHeight());
}

objectComponent.setX(center.getX());
Expand Down
75 changes: 75 additions & 0 deletions src/main/java/com/woogleFX/engine/EffectsManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.woogleFX.engine;

import com.woogleFX.editorObjects.EditorObject;
import com.woogleFX.editorObjects.objectComponents.ImageComponent;
import com.woogleFX.editorObjects.objectComponents.ObjectComponent;
import com.woogleFX.file.FileManager;
import com.woogleFX.file.resourceManagers.GlobalResourceManager;
import com.woogleFX.structures.GameVersion;
import javafx.geometry.Point2D;
import javafx.scene.image.Image;

import java.io.FileNotFoundException;

public class EffectsManager {

public static ObjectComponent getPlacingStrand(EditorObject goo1, double mouseX, double mouseY) {

Image strandImage;

try {
if (FileManager.hasNewWOG())
strandImage = GlobalResourceManager.getImage("IMAGE_BALL_GENERIC_ARM_INACTIVE", GameVersion.NEW);
else strandImage = GlobalResourceManager.getImage("IMAGE_BALL_GENERIC_ARM_INACTIVE", GameVersion.OLD);
} catch (FileNotFoundException e) {
return null;
}

return new ImageComponent() {
public double getX() {
double x1 = goo1.getAttribute("x").doubleValue();
return (x1 + mouseX) / 2;
}
public double getY() {
double y1 = -goo1.getAttribute("y").doubleValue();
return (y1 + mouseY) / 2;
}
public double getRotation() {

double x1 = goo1.getAttribute("x").doubleValue();
double y1 = -goo1.getAttribute("y").doubleValue();

return Math.PI / 2 + Renderer.angleTo(new Point2D(x1, y1), new Point2D(mouseX, mouseY));

}
public double getScaleX() {
return 0.15;
}
public double getScaleY() {

double x1 = goo1.getAttribute("x").doubleValue();
double y1 = -goo1.getAttribute("y").doubleValue();

return Math.hypot(mouseX - x1, mouseY - y1) / strandImage.getHeight();

}
public Image getImage() {
return strandImage;
}
public double getDepth() {
return 0.00000001;
}
public boolean isDraggable() {
return false;
}
public boolean isResizable() {
return false;
}
public boolean isRotatable() {
return false;
}
};

}

}
7 changes: 7 additions & 0 deletions src/main/java/com/woogleFX/engine/Renderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static void draw() {
}
canvas.getGraphicsContext2D().clearRect(-5000000, -5000000, 10000000, 10000000);
drawLevelToCanvas(level, canvas);

} else {
clear(canvas);
}
Expand Down Expand Up @@ -123,6 +124,12 @@ public static void drawLevelToCanvas(WorldLevel worldLevel, Canvas canvas) {

ArrayList<ObjectComponent> objectPositionsOrderedByDepth = orderObjectPositionsByDepth(worldLevel);

if (SelectionManager.getStrand1Gooball() != null) {
double gameRelativeX = (SelectionManager.getMouseX() - worldLevel.getOffsetX()) / worldLevel.getZoom();
double gameRelativeY = (SelectionManager.getMouseY() - worldLevel.getOffsetY()) / worldLevel.getZoom();
addObjectPositionToListByDepth(objectPositionsOrderedByDepth, EffectsManager.getPlacingStrand(SelectionManager.getStrand1Gooball(), gameRelativeX, gameRelativeY));
}

for (ObjectComponent objectComponent : objectPositionsOrderedByDepth) {

if (!objectComponent.isVisible()) continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static void eventMouseDragged(MouseEvent event) {
// performed.
switch (SelectionManager.getDragSettings().getType()) {
case DragSettings.MOVE -> ObjectDrag.dragFromMouse(gameRelativeMouseX, gameRelativeMouseY, SelectionManager.getDragSettings().getInitialSourceX(), SelectionManager.getDragSettings().getInitialSourceY());
case DragSettings.RESIZE -> ObjectResize.resizeFromMouse(gameRelativeMouseX, gameRelativeMouseY, SelectionManager.getDragSettings().getAnchorX(), SelectionManager.getDragSettings().getAnchorY());
case DragSettings.RESIZE -> ObjectResize.resizeFromMouse(gameRelativeMouseX, gameRelativeMouseY, SelectionManager.getDragSettings().getInitialSourceX(), SelectionManager.getDragSettings().getInitialSourceY(), SelectionManager.getDragSettings().getAnchorX(), SelectionManager.getDragSettings().getAnchorY(), SelectionManager.getDragSettings().getInitialScaleX(), SelectionManager.getDragSettings().getInitialScaleY());
case DragSettings.ROTATE -> ObjectRotate.rotateFromMouse(gameRelativeMouseX, gameRelativeMouseY, SelectionManager.getDragSettings().getInitialSourceX(), SelectionManager.getDragSettings().getInitialSourceY(), SelectionManager.getDragSettings().getRotateAngleOffset());
case DragSettings.SETANCHOR -> ObjectSetAnchor.setAnchor(gameRelativeMouseX, gameRelativeMouseY, SelectionManager.getDragSettings().getInitialSourceX(), SelectionManager.getDragSettings().getInitialSourceY());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public static void eventMouseReleased(MouseEvent event) {

level.getLevel().add(strand);
ObjectAdder.addAnything(strand, level.getLevelObject());

SelectionManager.getStrand1Gooball().update();
ball.update();

break;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public static void mouseWheelMoved(ScrollEvent e) {

case DragSettings.RESIZE -> ObjectResize.resizeFromMouse(
gameRelativeMouseX, gameRelativeMouseY,
dragSettings.getAnchorX(), dragSettings.getAnchorY());
dragSettings.getInitialSourceX(), dragSettings.getInitialSourceY(),
dragSettings.getAnchorX(), dragSettings.getAnchorY(),
SelectionManager.getDragSettings().getInitialScaleX(), SelectionManager.getDragSettings().getInitialScaleY());

case DragSettings.ROTATE -> ObjectRotate.rotateFromMouse(
gameRelativeMouseX, gameRelativeMouseY, dragSettings.getInitialSourceX(), dragSettings.getInitialSourceY(), dragSettings.getRotateAngleOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public static void undo() {
} else if (change instanceof ImportResourceAction) {
LevelResourceManager.deleteResource(level, change.getObject().getAttribute("path").stringValue());
ObjectManager.deleteItem(level, change.getObject(), false);
} else if (change instanceof HierarchyDragAction) {
HierarchyDragAction dragAction = (HierarchyDragAction) change;
} else if (change instanceof HierarchyDragAction dragAction) {
int toIndex = dragAction.getToPosition();
int fromIndex = dragAction.getFromPosition();
// Shift all the items opposite of the direction the original item was dragged
Expand Down Expand Up @@ -105,8 +104,7 @@ public static void redo() {
// TODO make this work with loopsounds instead of just music
LevelResourceManager.importMusic(level, new File(((ImportResourceAction) change).getPath()), false);
}
} else if (change instanceof HierarchyDragAction) {
HierarchyDragAction dragAction = (HierarchyDragAction) change;
} else if (change instanceof HierarchyDragAction dragAction) {
int toIndex = dragAction.getToPosition();
int fromIndex = dragAction.getFromPosition();
if (toIndex > fromIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,25 @@
import com.woogleFX.editorObjects.EditorObject;

public class AttributeChangeAction extends UserAction {
private final String attributeName;
private final String oldValue;
private final String newValue;

private final String attributeName;
public String getAttributeName() {
return attributeName;
}


private final String oldValue;
public String getOldValue() {
return oldValue;
}


private final String newValue;
public String getNewValue() {
return newValue;
}


public AttributeChangeAction(EditorObject object, String attributeName, String oldValue, String newValue) {
super(object);
this.attributeName = attributeName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@

public class HierarchyDragAction extends UserAction {

private int toPosition;
private int fromPosition;

private final int toPosition;
public int getToPosition() {
return toPosition;
}


private final int fromPosition;
public int getFromPosition() {
return fromPosition;
}

public void setToPosition(int toPosition) {
this.toPosition = toPosition;
}

public void setFromPosition(int fromPosition) {
this.fromPosition = fromPosition;
}

public HierarchyDragAction(EditorObject object, int fromPosition, int toPosition) {
super(object);
this.fromPosition = fromPosition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
public class ImportResourceAction extends UserAction {

private final String path;

public String getPath() {
return path;
}


public ImportResourceAction(EditorObject object, String path) {
super(object);
this.path = path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

public class ObjectCreationAction extends UserAction {

private int position;

private final int position;
public int getPosition() {
return position;
}

public void setPosition(int position) {
this.position = position;
}

public ObjectCreationAction(EditorObject object, int position) {
super(object);
this.position = position;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

public class ObjectDestructionAction extends UserAction {

private int position;

private final int position;
public int getPosition() {
return position;
}

public void setPosition(int position) {
this.position = position;
}

public ObjectDestructionAction(EditorObject object, int position) {
super(object);
this.position = position;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
public class UserAction {

private final EditorObject object;

public EditorObject getObject() {
return object;
}


public UserAction(EditorObject object) {
this.object = object;
}
Expand Down
Loading

0 comments on commit 940b03b

Please sign in to comment.