Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provide simple non-AWT example #10

Open
mikesmullin opened this issue Jul 24, 2017 · 2 comments
Open

provide simple non-AWT example #10

mikesmullin opened this issue Jul 24, 2017 · 2 comments

Comments

@mikesmullin
Copy link

mikesmullin commented Jul 24, 2017

You may have heard some people asking, "Who wouldn't want to use AWT and Swing?"
Just tell 'em its the circle of life.

import jpen.*
import jpen.demo.StatusReport
import jpen.event.PenAdapter
import jpen.event.PenListener
import jpen.owner.AbstractPenOwner
import jpen.owner.PenClip
import java.awt.Point

private class RegularPenClip : PenClip {
	override fun evalLocationOnScreen(pointOnScreen: Point) {
	}

	override operator fun contains(point: java.awt.geom.Point2D.Float): Boolean {
		return true
	}
}

private class RegularPenOwner : AbstractPenOwner() {
	override fun getPenProviderConstructors(): Collection<PenProvider.Constructor> {
		return java.util.Arrays.asList<PenProvider.Constructor>(
				//jpen.provider.system.SystemProvider.Constructor(), 
				jpen.provider.xinput.XinputProvider.Constructor(),
				jpen.provider.wintab.WintabProvider.Constructor(),
				jpen.provider.osx.CocoaProvider.Constructor())
	}

	private val penClip: RegularPenClip = RegularPenClip()

	override fun getPenClip(): PenClip {
		return penClip
	}

	override fun draggingOutDisengaged() {
	}

	override fun init() {
		penManagerHandle.setPenManagerPaused(false)
	}
}

private class JPenExample {
	private val penOwner: RegularPenOwner = RegularPenOwner()
	private val penManager: PenManager = PenManager(penOwner)

	constructor(penListener: PenListener) {
		println(StatusReport(penManager))
		penManager.pen.addListener(penListener)
	}
}

fun main(args: Array<String>) {
	JPenExample((object : PenAdapter() {
		private var pen: Pen? = null

		override fun penLevelEvent(ev: PLevelEvent?) {
			if (null == pen) pen = (ev ?: return).pen
		}

		override fun penTock(availableMillis: Long) {
			println("penTock availableMillis: $availableMillis")
			val _pen = pen ?: return

			println("KIND ${_pen.kind}")

			for (buttonType in PButton.Type.VALUES) {
				if (_pen.getButtonValue(buttonType)) {
					println("BUTTON_TYPE ${buttonType}")
				}
			}

			for (levelType in PLevel.Type.VALUES){
				val value = _pen.getLevelValue(levelType)
				println("LEVEL type: ${levelType}, value: ${value}")
			}

			// only process tocks after an event happens
			pen = null
		}
	}))
}

Long live The Committee for Advanced Pointing Standards (CAPS)!

@mikesmullin
Copy link
Author

NOTE: To get the Pressed Button state, you'll need a way to detect your own keyboard and mouse input events. Meaning, its not provided by Wintab driver; the buttons on the side of the stylus provide actual keyboard/mouse input.

@Ant01n3
Copy link

Ant01n3 commented Mar 7, 2018

Thanks for this very useful example 👍 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants