From 7a7a2af3d7a50f015edca3d9d439f17d9e33c437 Mon Sep 17 00:00:00 2001 From: Julian Date: Sun, 23 Oct 2016 14:54:46 +0200 Subject: [PATCH 1/3] add mouse drag threshold to AnimationStripPanel --- .../animation/AnimationStripPanel.java | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/dfEditor/animation/AnimationStripPanel.java b/src/dfEditor/animation/AnimationStripPanel.java index 420d5ba..0dcd38b 100644 --- a/src/dfEditor/animation/AnimationStripPanel.java +++ b/src/dfEditor/animation/AnimationStripPanel.java @@ -46,11 +46,16 @@ * @author s4m20 */ public class AnimationStripPanel extends javax.swing.JPanel implements AnimationDataListener, MouseMotionListener, MouseListener, ActionListener -{ +{ + // the distance in pixels an animation cell needs to be dragged to count as dragging + private static final int MOUSE_DRAG_THRESHOLD = 10; + private Animation animation = null; private ArrayList slotList = null; private AnimationController controller = null; private Point mousePoint = null; + private Point mousePressedPoint = null; + private boolean dragging = false; private int insertBeforeSlotIndex = -1; private Timer timer = null; private int currentSlotInAnimation = -1; @@ -446,6 +451,13 @@ public void mouseDragged(MouseEvent evt) Point p = evt.getPoint(); mousePoint = p; + + if (!dragging && (Math.abs(p.x - mousePressedPoint.x) <= MOUSE_DRAG_THRESHOLD)) + { + return; + } + + dragging = true; int xOffset = 0; @@ -490,6 +502,7 @@ public void mouseDragged(MouseEvent evt) public void mousePressed(MouseEvent evt) { Point p = evt.getPoint(); + mousePressedPoint = p; controller.stripIndexSelected(-1); boolean selectedSlot = false; @@ -551,7 +564,8 @@ public void mouseReleased(MouseEvent evt) if (orderChanged && insertBeforeSlotIndex < slotList.size()) slotList.get(insertBeforeSlotIndex).setSelected(true); - insertBeforeSlotIndex = -1; + insertBeforeSlotIndex = -1; + dragging = false; } public void mouseExited(MouseEvent evt) @@ -572,7 +586,7 @@ public void mouseClicked(MouseEvent evt) // just a dumb object really... could have come up with an elaborate // design for this whole strip class but just got it working... can always // revisit! - private class Slot + private static class Slot { static final int MARGIN = 3; From 3400fab773b3b8af7eafeccbd26c81fbbd140cc3 Mon Sep 17 00:00:00 2001 From: Julian Date: Sun, 23 Oct 2016 17:39:20 +0200 Subject: [PATCH 2/3] make mouse wheel zoom go towards the cursor instead of the origin --- src/dfEditor/GraphicPanel.java | 37 +++++++++++++++++++----------- src/dfEditor/SpritesheetPanel.java | 26 ++------------------- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/dfEditor/GraphicPanel.java b/src/dfEditor/GraphicPanel.java index af63a8b..f44055c 100644 --- a/src/dfEditor/GraphicPanel.java +++ b/src/dfEditor/GraphicPanel.java @@ -45,6 +45,8 @@ public class GraphicPanel extends javax.swing.JDesktopPane implements MouseMotio private static final int SELECT_BUTTON = MouseEvent.BUTTON1; private static final int DRAG_BUTTON = MouseEvent.BUTTON3; private static final int DRAG_BUTTON_2 = MouseEvent.BUTTON2; + + protected static final float MIN_ZOOM = 0.1f; private static final Color[] checkerBoardCols = {new Color(210,210,210), new Color(255,255,255)};//{new Color(255,200,200), new Color(255,210,210)}; @@ -62,7 +64,7 @@ public class GraphicPanel extends javax.swing.JDesktopPane implements MouseMotio private ArrayList _changeListeners; protected boolean _bAllowsEditing; protected GraphicObject _lastAddedGraphic; - protected Rectangle _multiSelectRect; + protected Rectangle _multiSelectRect; private static final Color _multiSelectFill = new Color(0,0,0,20); private GraphicObject _movingGraphic = null; private int _keyDeltaX = 0; @@ -217,8 +219,8 @@ public void setCommandManager(CommandManager aCM) public void setZoom(float zoom) { - if (zoom < 0.1f) - zoom = 0.1f; + if (zoom < MIN_ZOOM) + zoom = MIN_ZOOM; this._zoom = zoom; @@ -327,7 +329,7 @@ protected void drawStack(Graphics g, Point aOrigin, float aZoom, float aAlpha) } } - protected void drawGraphicRotated(GraphicObject graphic, Graphics g, Point aOrigin, float aZoom, float aAlpha) + protected void drawGraphicRotated(GraphicObject graphic, Graphics g, Point aOrigin, float aZoom, float aAlpha) { Graphics2D g2d = (Graphics2D)g; @@ -580,11 +582,7 @@ protected void dropGraphic(GraphicObject aGraphic, boolean aUndoable) protected void setDrawStack(ArrayList aDrawStack) { _drawStack.clear(); - - for (int i=0; i> 1; - getOrigin().y -= yDiff >> 1; - } - public Rectangle suggestVisibleSpriteRect() { final int edgeInsetPix = 0; @@ -224,8 +204,6 @@ private Point actualImageSize() getZoom() ); } - - @Override public void mouseClicked(MouseEvent e) { From 0887c1e5e99511c2fe867d89008c235308083879 Mon Sep 17 00:00:00 2001 From: Julian Date: Sun, 23 Oct 2016 19:31:45 +0200 Subject: [PATCH 3/3] speed up checkerboard drawing --- src/dfEditor/GraphicPanel.java | 95 +++++++++++------------------- src/dfEditor/SpriteImagePanel.java | 2 +- src/dfEditor/SpritesheetPanel.java | 2 +- 3 files changed, 37 insertions(+), 62 deletions(-) diff --git a/src/dfEditor/GraphicPanel.java b/src/dfEditor/GraphicPanel.java index f44055c..e83c918 100644 --- a/src/dfEditor/GraphicPanel.java +++ b/src/dfEditor/GraphicPanel.java @@ -25,11 +25,14 @@ import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; +import java.awt.TexturePaint; import java.awt.Cursor; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.Color; import java.awt.image.BufferedImage; +import java.awt.image.WritableRaster; + import dfEditor.command.*; import dfEditor.commands.*; import java.awt.geom.AffineTransform; @@ -48,12 +51,26 @@ public class GraphicPanel extends javax.swing.JDesktopPane implements MouseMotio protected static final float MIN_ZOOM = 0.1f; - private static final Color[] checkerBoardCols = {new Color(210,210,210), new Color(255,255,255)};//{new Color(255,200,200), new Color(255,210,210)}; + private static final int[] checkerBoardColors = {210, 255}; + private static final int CHECKER_BOARD_SIZE = 16; + + private static TexturePaint checkerBoardPaint; + + static { + BufferedImage checkerBoardImage = new BufferedImage(2, 2, BufferedImage.TYPE_BYTE_GRAY); + int[] pixels = { + checkerBoardColors[0], checkerBoardColors[1], + checkerBoardColors[1], checkerBoardColors[0], + }; + + checkerBoardImage.getRaster().setPixels(0, 0, 2, 2, pixels); + + checkerBoardPaint = new TexturePaint(checkerBoardImage, new Rectangle(CHECKER_BOARD_SIZE * 2, CHECKER_BOARD_SIZE * 2)); + } protected ArrayList _drawStack; protected float _zoom; protected Point _origin; - protected BufferedImage _checkerBoard; private Point _lastOrigin; private Point _lastClickPoint; protected Rectangle _graphicBounds; @@ -331,7 +348,7 @@ protected void drawStack(Graphics g, Point aOrigin, float aZoom, float aAlpha) protected void drawGraphicRotated(GraphicObject graphic, Graphics g, Point aOrigin, float aZoom, float aAlpha) { - Graphics2D g2d = (Graphics2D)g; + Graphics2D g2d = (Graphics2D)g; Rectangle graphicRect = graphic.getRect(); @@ -693,67 +710,25 @@ public ArrayList selectedGraphics() return selectedGraphics; } - protected void drawCheckerBoardBuffer(final Graphics g, final Rectangle aRect) + protected void drawCheckerBoard(final Graphics g, final Rectangle aRect) { - if (_checkerBoard == null) - _checkerBoard = this.makeCheckerBoardBuffer(new Rectangle(0, 0, 256, 256)); + Graphics2D g2d = (Graphics2D)g; + g2d.setPaint(checkerBoardPaint); - g.clipRect(aRect.x, aRect.y, aRect.width, aRect.height); - for (int x=aRect.x; x