Skip to content

Commit

Permalink
finished pointable showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
wwagner4 committed Apr 10, 2016
1 parent 1cab734 commit 703ff05
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 5 deletions.
11 changes: 6 additions & 5 deletions jvm/src/main/scala/doctus/jvm/DoctusFx.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import javafx.scene.input.KeyEvent
import javafx.scene.input.KeyCode
import javafx.scene.control.ComboBox
import javafx.scene.control.TextInputControl
import javafx.scene.Node

case class DoctusGraphicsFx(gc: GraphicsContext) extends DoctusGraphics {

Expand Down Expand Up @@ -191,7 +192,7 @@ case class DoctusSelectFx[T](comboBox: ComboBox[T], f: (T) => String = (t: T) =>

}

case class DoctusPointableFx(comp: Parent) extends DoctusPointable {
case class DoctusPointableFx(comp: Node) extends DoctusPointable {

def onStart(f: DoctusPoint Unit): Unit = _onStart = Some(f)
def onStop(f: DoctusPoint Unit): Unit = _onStop = Some(f)
Expand All @@ -200,14 +201,14 @@ case class DoctusPointableFx(comp: Parent) extends DoctusPointable {
var _onStop = Option.empty[DoctusPoint Unit]

comp.setOnMousePressed(DoctusJvmUtil.handler { e =>
val x = e.getScreenX
val y = e.getScreenY
val x = e.getX
val y = e.getY
_onStart.foreach(f => f(DoctusPoint(x, y)))
})

comp.setOnMouseReleased(DoctusJvmUtil.handler { e =>
val x = e.getScreenX
val y = e.getScreenY
val x = e.getX
val y = e.getY
_onStop.foreach(f => f(DoctusPoint(x, y)))
})
}
Expand Down
63 changes: 63 additions & 0 deletions showcase-jvm/src/main/scala/doctus/jvm/ShowcaseJvmPointable.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package doctus.jvm

import doctus.core._
import java.util.ArrayList
import java.util.List
import java.util.Random
import javafx.application.Application
import javafx.scene._
import javafx.stage.Stage
import javafx.scene.canvas.Canvas
import javafx.application._
import javafx.scene._
import javafx.scene.paint._
import javafx.stage.Stage
import javafx.stage.WindowEvent
import javafx.event.EventHandler
import javafx.event.ActionEvent
import javafx.event.Event

object ShowcaseJvmPointable extends App {

Application.launch(classOf[MyApp], args: _*);

class MyApp extends Application {

override def start(stage: Stage) {

val width = 700
val height = 500

val canvasFx = new Canvas(width, height);

val canvas = DoctusCanvasFx(canvasFx)
val pointable = DoctusPointableFx(canvasFx)


val grp = new Group();
grp.getChildren().add(canvasFx);

val bgCol = Color.WHITE;
val scene = new Scene(grp, width, height, bgCol);

// Start the controller
DoctusControllerPointable(pointable, canvas)

stage.setScene(scene);

stage.show();
def handler[T <: Event](h: (T => Unit)): EventHandler[T] =
new EventHandler[T] {
override def handle(event: T): Unit = h(event)
}

// Find a better solution to exit
stage.setOnCloseRequest(handler(e => System.exit(0)))



}
}

}

0 comments on commit 703ff05

Please sign in to comment.