Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added pen owner and clip to work with NEWT
- Loading branch information
1 parent
3dc3208
commit 2c6df1f
Showing
5 changed files
with
156 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package codeanticode.tablet; | ||
|
||
import com.jogamp.newt.Window; | ||
import java.awt.geom.Point2D; | ||
import java.awt.Point; | ||
import jpen.owner.PenClip; | ||
|
||
final class WindowPenClip | ||
implements PenClip { | ||
|
||
final WindowPenOwner windowPenOwner; | ||
|
||
public WindowPenClip(WindowPenOwner windowPenOwner) { | ||
this.windowPenOwner=windowPenOwner; | ||
} | ||
|
||
@Override | ||
public void evalLocationOnScreen(Point pointOnScreen) { | ||
//-> called holding the pen scheduler lock | ||
pointOnScreen.x=pointOnScreen.y=0; | ||
com.jogamp.nativewindow.util.Point joglPoint=windowPenOwner.getWindow().getLocationOnScreen(null); | ||
pointOnScreen.x=joglPoint.getX(); | ||
pointOnScreen.y=joglPoint.getY(); | ||
} | ||
|
||
@Override | ||
public boolean contains(Point2D.Float point) { | ||
//-> called holding the pen scheduler lock | ||
if(point.x<0 || point.y<0) | ||
return false; | ||
Window window=windowPenOwner.getWindow(); | ||
return point.x<=window.getWidth() && point.y<=window.getHeight(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package codeanticode.tablet; | ||
|
||
import com.jogamp.newt.event.MouseAdapter; | ||
import com.jogamp.newt.event.MouseEvent; | ||
import com.jogamp.newt.Window; | ||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import jpen.owner.PenClip; | ||
import jpen.owner.PenOwner; | ||
import jpen.PenEvent; | ||
import jpen.PenProvider; | ||
import jpen.provider.osx.CocoaProvider; | ||
import jpen.provider.wintab.WintabProvider; | ||
import jpen.provider.xinput.XinputProvider; | ||
|
||
public class WindowPenOwner | ||
implements PenOwner { | ||
|
||
private PenManagerHandle penManagerHandle; | ||
private final WindowPenClip WindowPenClip=new WindowPenClip(this); | ||
private final Window window; | ||
private volatile boolean mayBeDraggingOut; | ||
|
||
public WindowPenOwner(Window window) { | ||
this.window=window; | ||
} | ||
|
||
public Window getWindow() { | ||
return window; | ||
} | ||
|
||
@Override | ||
public void setPenManagerHandle(final PenManagerHandle penManagerHandle) { | ||
this.penManagerHandle=penManagerHandle; | ||
window.addMouseListener(new MouseAdapter() { | ||
@Override | ||
public void mouseEntered(MouseEvent ev) { | ||
mayBeDraggingOut=true; | ||
// escape from the EDT to avoid thread-safety issues... | ||
new Thread(new Runnable() { | ||
public void run() { | ||
penManagerHandle.setPenManagerPaused(false); | ||
} | ||
}).start(); | ||
} | ||
|
||
@Override | ||
public void mouseExited(MouseEvent ev) { | ||
mayBeDraggingOut=false; | ||
// escape from the EDT to avoid thread-safety issues... | ||
// Note: this has a side effect: some level events continue to | ||
// be fired for a "very short time" after the mouse has exited, | ||
// we would have to modify jpen internals to filter them out if necessary... | ||
// let me know if this needs to be done for your use case. | ||
new Thread(new Runnable() { | ||
public void run() { | ||
penManagerHandle.setPenManagerPaused(true); | ||
} | ||
}).start(); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Collection<PenProvider.Constructor> getPenProviderConstructors() { | ||
return Arrays.asList( | ||
new PenProvider.Constructor[] { | ||
//Note: do you need a newt mouse/keyboard provider (so that regular newt mouse events/keyboard are fired as jpen events too)? | ||
new XinputProvider.Constructor(), | ||
new WintabProvider.Constructor(), | ||
new CocoaProvider.Constructor(), | ||
} | ||
); | ||
} | ||
|
||
@Override | ||
public PenClip getPenClip() { | ||
return WindowPenClip; | ||
} | ||
|
||
@Override | ||
public boolean isDraggingOut() { | ||
return mayBeDraggingOut; | ||
} | ||
|
||
@Override | ||
public Object evalPenEventTag(PenEvent ev) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean enforceSinglePenManager() { | ||
return true; | ||
} | ||
} |