[Patchanim-commit] SF.net SVN: patchanim: [96] trunk/patchanim/src/com/mebigfatguy/patchanim/ gui
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2008-02-03 02:35:50
|
Revision: 96
http://patchanim.svn.sourceforge.net/patchanim/?rev=96&view=rev
Author: dbrosius
Date: 2008-02-02 18:35:56 -0800 (Sat, 02 Feb 2008)
Log Message:
-----------
better control point clicking, and add drag ability but commented out till i can figure how to effect the blend with it.
Modified Paths:
--------------
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java
trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-02-03 01:47:06 UTC (rev 95)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JColorControlPatchPanel.java 2008-02-03 02:35:56 UTC (rev 96)
@@ -45,6 +45,8 @@
public class JColorControlPatchPanel extends JPanel implements PatchDecorator {
private static final long serialVersionUID = -2524694507912574529L;
+ private static final double MINCLICKDISTANCESQ = 12.0;
+ private static final double MINDRAGDISTANCESQ = 3.0;
private PatchCoords coords;
private PatchColor color;
@@ -151,19 +153,79 @@
}
}
- public void click(Point p, Rectangle bounds) {
- int newSelectedXPt = ((((p.x - bounds.x) * 100) / bounds.width) + 16) / 33;
- int newSelectedYPt = ((((p.y - bounds.y) * 100) / bounds.height) + 16) / 33;
- if ((newSelectedXPt != selectedXPt) || (newSelectedYPt != selectedYPt)) {
- selectedXPt = newSelectedXPt;
- selectedYPt = newSelectedYPt;
+ public boolean press(Point p, Rectangle bounds) {
+
+ if (setSelectedControlPt(p, bounds)) {
setColorField(false);
- invalidate();
- revalidate();
- repaint();
+ SwingUtilities.invokeLater(new Runnable() {
+ public void run() {
+ invalidate();
+ revalidate();
+ repaint();
+ }
+ });
+ return true;
}
+ return false;
}
+ public boolean drag(Point p, Rectangle bounds) {
+ return false;
+/*
+ double inputX = ((p.x - bounds.x) * 100.0) / bounds.width;
+ double inputY = ((p.y - bounds.y) * 100.0) / bounds.height;
+ Coordinate c= coords.getCoordinate(selectedXPt, selectedYPt);
+ double oldX = c.getX();
+ double oldY = c.getY();
+
+ double xDeltaSq = inputX - oldX;
+ xDeltaSq *= xDeltaSq;
+ double yDeltaSq = inputY - oldY;
+ yDeltaSq *= yDeltaSq;
+
+ if ((xDeltaSq + yDeltaSq) > MINDRAGDISTANCESQ) {
+ c.setX(inputX);
+ c.sety(inputY);
+ return true;
+ }
+
+ return false;
+*/
+ }
+
+ private boolean setSelectedControlPt(Point p, Rectangle bounds) {
+ double minDistanceSq = Double.MAX_VALUE;
+ double inputX = ((p.x - bounds.x) * 100.0) / bounds.width;
+ double inputY = ((p.y - bounds.y) * 100.0) / bounds.height;
+ int minU = 0;
+ int minV = 0;
+
+ for (int u = 0; u < 4; u++) {
+ for (int v = 0; v < 4; v++) {
+ Coordinate c = coords.getCoordinate(u, v);
+ double xSq = c.getX() - inputX;
+ xSq *= xSq;
+ double ySq = c.getY() - inputY;
+ ySq *= ySq;
+
+ double distSq = xSq + ySq;
+ if (distSq < minDistanceSq) {
+ minDistanceSq = distSq;
+ minU = u;
+ minV = v;
+ }
+ }
+ }
+
+ if (minDistanceSq < MINCLICKDISTANCESQ) {
+ selectedXPt = minU;
+ selectedYPt = minV;
+ return true;
+ }
+
+ return false;
+ }
+
class ValueDocumentListener implements DocumentListener
{
public void changedUpdate(DocumentEvent de) {
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-03 01:47:06 UTC (rev 95)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/JPatchSamplePanel.java 2008-02-03 02:35:56 UTC (rev 96)
@@ -27,6 +27,7 @@
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
import java.awt.image.BufferedImage;
import java.util.ResourceBundle;
@@ -65,6 +66,7 @@
private Thread redrawThread = null;
private Object redrawLock = new Object();
private boolean redrawing = false;
+ private boolean dragging = false;
public JPatchSamplePanel(PatchColor c) {
color = c;
@@ -99,24 +101,34 @@
private void initListeners() {
addMouseListener(new MouseAdapter() {
@Override
- public void mouseClicked(MouseEvent me) {
- if (decorator != null)
- decorator.click(me.getPoint(), JPatchSamplePanel.this.getBounds());
- }
-
- @Override
public void mousePressed(MouseEvent me) {
if ((color != PatchColor.Combined) && me.isPopupTrigger())
showPatchContentMenu(me);
+ else if (decorator != null) {
+ dragging = decorator.press(me.getPoint(), JPatchSamplePanel.this.getBounds());
+ }
}
@Override
public void mouseReleased(MouseEvent me) {
if ((color != PatchColor.Combined) && me.isPopupTrigger())
showPatchContentMenu(me);
+ dragging = false;
}
});
+ addMouseMotionListener(new MouseMotionAdapter() {
+ @Override
+ public void mouseDragged(MouseEvent me) {
+ if ((decorator != null) && dragging)
+ if (decorator.drag(me.getPoint(), JPatchSamplePanel.this.getBounds())) {
+ PatchPanelMediator mediator = PatchPanelMediator.getMediator();
+ CombinedPatch currentPatch = mediator.getActivePatch();
+ recalcImage(color, currentPatch);
+ }
+ }
+ });
+
PatchPanelMediator mediator = PatchPanelMediator.getMediator();
mediator.addActivePatchChangedListener(new ActivePatchChangedListener() {
public void activePatchChanged(ActivePatchChangedEvent apce) {
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java 2008-02-03 01:47:06 UTC (rev 95)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchDecorator.java 2008-02-03 02:35:56 UTC (rev 96)
@@ -25,5 +25,7 @@
public interface PatchDecorator {
void drawDecoration(Graphics2D g, Rectangle bounds);
- void click(Point p, Rectangle bounds);
+ boolean press(Point p, Rectangle bounds);
+
+ boolean drag(Point p, Rectangle bounds);
}
Modified: trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java
===================================================================
--- trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-02-03 01:47:06 UTC (rev 95)
+++ trunk/patchanim/src/com/mebigfatguy/patchanim/gui/PatchPanelMediator.java 2008-02-03 02:35:56 UTC (rev 96)
@@ -62,17 +62,23 @@
}
public void addActivePatchChangedListener(ActivePatchChangedListener apcl) {
- apclisteners.add(apcl);
+ synchronized(apclisteners) {
+ apclisteners.add(apcl);
+ }
}
public void addSettingsChangedListener(SettingsChangedListener scl) {
- sclisteners.add(scl);
+ synchronized(sclisteners) {
+ sclisteners.add(scl);
+ }
}
public void fireSettingsChanged() {
- SettingsChangedEvent sce = new SettingsChangedEvent(this, document);
- for (SettingsChangedListener scl : sclisteners) {
- scl.settingsChanged(sce);
+ synchronized(sclisteners) {
+ SettingsChangedEvent sce = new SettingsChangedEvent(this, document);
+ for (SettingsChangedListener scl : sclisteners) {
+ scl.settingsChanged(sce);
+ }
}
}
@@ -83,8 +89,10 @@
public void setNewActivePatch(CombinedPatch patch) {
activePatch = patch;
ActivePatchChangedEvent apce = new ActivePatchChangedEvent(this, patch);
- for (ActivePatchChangedListener apcl : apclisteners) {
- apcl.activePatchChanged(apce);
+ synchronized(apclisteners) {
+ for (ActivePatchChangedListener apcl : apclisteners) {
+ apcl.activePatchChanged(apce);
+ }
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|