Button vs cursor pos fix

This commit is contained in:
Jindra Petřík
2022-12-17 12:30:20 +01:00
parent f51e46f8b9
commit ef3dccb922
12 changed files with 36 additions and 29 deletions

View File

@@ -116,7 +116,7 @@ public class DefineScalingGridTag extends Tag implements CharacterIdTag {
}
public RECT getRect() {
Shape s = getOutline(0, 0, 0, new RenderContext(), new Matrix(), new Matrix(), true);
Shape s = getOutline(0, 0, 0, new RenderContext(), new Matrix(), new Matrix(), true, new ExportRectangle(0, 0, 1, 1)/*?*/, 1);
if (s == null) {
return null;
}
@@ -124,7 +124,7 @@ public class DefineScalingGridTag extends Tag implements CharacterIdTag {
return new RECT(r.x, r.x + r.width, r.y, r.y + r.height);
}
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, Matrix prevTransform, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, Matrix prevTransform, boolean stroked, ExportRectangle viewRect, double unzoom) {
CharacterTag ct = swf.getCharacter(characterId);
if (ct == null) {
return null;
@@ -135,7 +135,7 @@ public class DefineScalingGridTag extends Tag implements CharacterIdTag {
double[] coords = new double[6];
DrawableTag dt = (DrawableTag) ct;
Shape path = dt.getOutline(frame, time, ratio, renderContext, transformation, stroked);
Shape path = dt.getOutline(frame, time, ratio, renderContext, transformation, stroked, viewRect, unzoom);
PathIterator iterator = path.getPathIterator(new AffineTransform());
GeneralPath gp = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
ExportRectangle boundsRect = new ExportRectangle(dt.getRect());

View File

@@ -377,8 +377,8 @@ public class DefineSpriteTag extends DrawableTag implements Timelined {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
return getTimeline().getOutline(frame, time, renderContext, transformation, stroked);
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return getTimeline().getOutline(frame, time, renderContext, transformation, stroked, viewRect, unzoom);
}
@Override

View File

@@ -295,7 +295,7 @@ public class DefineVideoStreamTag extends DrawableTag implements BoundedTag, Tim
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return transformation.toTransform().createTransformedShape(new Rectangle2D.Double(0, 0, width * SWF.unitDivisor, height * SWF.unitDivisor));
}

View File

@@ -88,8 +88,8 @@ public abstract class ButtonTag extends DrawableTag implements Timelined {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
return getTimeline().getOutline(frame, time, renderContext, transformation, stroked);
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return getTimeline().getOutline(frame, time, renderContext, transformation, stroked, viewRect, unzoom);
}
@Override

View File

@@ -44,7 +44,7 @@ public abstract class DrawableTag extends CharacterTag implements BoundedTag {
public abstract int getUsedParameters();
public abstract Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked);
public abstract Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom);
public abstract void toImage(int frame, int time, int ratio, RenderContext renderContext, SerializableImage image, SerializableImage fullImage, boolean isClip, Matrix transformation, Matrix prevTransformation, Matrix absoluteTransformation, Matrix fullTransformation, ColorTransform colorTransform, double unzoom, boolean sameImage, ExportRectangle viewRect, boolean scaleStrokes, int drawMode, int blendMode);

View File

@@ -427,7 +427,7 @@ public abstract class FontTag extends DrawableTag implements AloneTag {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
RECT r = getRect();
return new Area(new Rectangle(r.Xmin, r.Ymin, r.getWidth(), r.getHeight()));
}

View File

@@ -229,7 +229,7 @@ public abstract class ImageTag extends DrawableTag {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return transformation.toTransform().createTransformedShape(getShape(1).getOutline(1, swf, stroked));
}

View File

@@ -349,7 +349,7 @@ public abstract class MorphShapeTag extends DrawableTag {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return transformation.toTransform().createTransformedShape(getShapeAtRatio(ratio).getOutline(getShapeNum() == 2 ? 4 : 1, swf, stroked));
}

View File

@@ -183,7 +183,7 @@ public abstract class ShapeTag extends DrawableTag implements LazyObject {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
return transformation.toTransform().createTransformedShape(getShapes().getOutline(getShapeNum(), swf, stroked));
}

View File

@@ -783,7 +783,7 @@ public abstract class TextTag extends DrawableTag {
}
@Override
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, int ratio, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
RECT r = getBounds();
Shape shp = new Rectangle.Double(r.Xmin, r.Ymin, r.getWidth(), r.getHeight());
return transformation.toTransform().createTransformedShape(shp); //TODO: match character shapes (?)

View File

@@ -795,9 +795,9 @@ public class Timeline {
if (renderContext.cursorPosition != null) {
int dx = (int) (viewRect.xMin * unzoom);
int dy = (int) (viewRect.yMin * unzoom);
Point cursorPositionInView = new Point(renderContext.cursorPosition.x - dx, renderContext.cursorPosition.y - dy);
Point cursorPositionInView = new Point((int)Math.round(renderContext.cursorPosition.x * unzoom) - dx, (int)Math.round(renderContext.cursorPosition.y * unzoom) - dy);
Shape buttonShape = drawable.getOutline(ButtonTag.FRAME_HITTEST, time, ratio, renderContext, absMat, true);
Shape buttonShape = drawable.getOutline(ButtonTag.FRAME_HITTEST, time, ratio, renderContext, absMat, true, viewRect, unzoom);
if (buttonShape.contains(cursorPositionInView)) {
renderContext.mouseOverButton = (ButtonTag) drawable;
if (renderContext.mouseButton > 0) {
@@ -950,15 +950,15 @@ public class Timeline {
clips.add(clip);
} else {
if (renderContext.cursorPosition != null) {
int dx = (int) (viewRect.xMin * unzoom);
int dy = (int) (viewRect.yMin * unzoom);
Point cursorPositionInView = new Point(renderContext.cursorPosition.x - dx, renderContext.cursorPosition.y - dy);
int dx = (int) Math.round(viewRect.xMin * unzoom);
int dy = (int) Math.round(viewRect.yMin * unzoom);
Point cursorPositionInView = new Point((int) Math.round(renderContext.cursorPosition.x * unzoom) - dx, (int) Math.round(renderContext.cursorPosition.y * unzoom) - dy);
if (drawable instanceof DefineSpriteTag) {
if (renderContext.stateUnderCursor.size() > stateCount) {
renderContext.stateUnderCursor.add(layer);
}
} else if (absMat.transform(new ExportRectangle(boundRect)).contains(cursorPositionInView)) {
Shape shape = drawable.getOutline(dframe, time, layer.ratio, renderContext, absMat, true);
Shape shape = drawable.getOutline(dframe, time, layer.ratio, renderContext, absMat, true, viewRect, unzoom);
if (shape.contains(cursorPositionInView)) {
renderContext.stateUnderCursor.add(layer);
}
@@ -969,7 +969,7 @@ public class Timeline {
Graphics2D g2 = (Graphics2D) renderContext.borderImage.getGraphics();
g2.setPaint(Color.red);
g2.setStroke(new BasicStroke(2));
Shape shape = drawable.getOutline(dframe, time, layer.ratio, renderContext, absMat.preConcatenate(Matrix.getScaleInstance(1 / SWF.unitDivisor)), true);
Shape shape = drawable.getOutline(dframe, time, layer.ratio, renderContext, absMat.preConcatenate(Matrix.getScaleInstance(1 / SWF.unitDivisor)), true, viewRect, unzoom);
g2.draw(shape);
}
if (!(sameImage && canUseSameImage)) {
@@ -1319,7 +1319,7 @@ public class Timeline {
}
}
public Shape getOutline(int frame, int time, RenderContext renderContext, Matrix transformation, boolean stroked) {
public Shape getOutline(int frame, int time, RenderContext renderContext, Matrix transformation, boolean stroked, ExportRectangle viewRect, double unzoom) {
Frame fr = getFrame(frame);
Area area = new Area();
Stack<Clip> clips = new Stack<>();
@@ -1356,8 +1356,11 @@ public class Timeline {
dframe = ButtonTag.FRAME_UP;
if (renderContext.cursorPosition != null) {
ButtonTag buttonTag = (ButtonTag) character;
Shape buttonShape = buttonTag.getOutline(ButtonTag.FRAME_HITTEST, time, layer.ratio, renderContext, m, stroked);
if (buttonShape.contains(renderContext.cursorPosition)) {
Shape buttonShape = buttonTag.getOutline(ButtonTag.FRAME_HITTEST, time, layer.ratio, renderContext, m, stroked, viewRect, unzoom);
int dx = (int) Math.round(viewRect.xMin * unzoom);
int dy = (int) Math.round(viewRect.yMin * unzoom);
Point cursorPositionInView = new Point((int) Math.round(renderContext.cursorPosition.x * unzoom) - dx, (int) Math.round(renderContext.cursorPosition.y * unzoom) - dy);
if (buttonShape.contains(cursorPositionInView)) {
if (renderContext.mouseButton > 0) {
dframe = ButtonTag.FRAME_DOWN;
} else {
@@ -1367,7 +1370,7 @@ public class Timeline {
}
}
Shape cshape = ((DrawableTag) character).getOutline(dframe, time, layer.ratio, renderContext, m, stroked);
Shape cshape = ((DrawableTag) character).getOutline(dframe, time, layer.ratio, renderContext, m, stroked, viewRect, unzoom);
Area addArea = new Area(cshape);
if (currentClip != null) {
Area a = new Area(new Rectangle(displayRect.Xmin, displayRect.Ymin, displayRect.getWidth(), displayRect.getHeight()));