diff --git a/src/dfEditor/GraphicPanel.java b/src/dfEditor/GraphicPanel.java index af63a8b..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; @@ -45,13 +48,29 @@ 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)}; + 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; @@ -62,7 +81,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 +236,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,9 +346,9 @@ 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; + Graphics2D g2d = (Graphics2D)g; Rectangle graphicRect = graphic.getRect(); @@ -580,11 +599,7 @@ protected void dropGraphic(GraphicObject aGraphic, boolean aUndoable) protected void setDrawStack(ArrayList aDrawStack) { _drawStack.clear(); - - for (int i=0; i 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> 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) { 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;