Commit 5a9e85ac authored by h2b's avatar h2b

Drag events added.

parent 4a67264b
......@@ -18,7 +18,8 @@
package de.h2b.scala.lib.simgraf.driver
import java.awt.event.{ KeyEvent AwtKeyEvent, KeyListener AwtKeyListener,
MouseEvent AwtMouseEvent, MouseListener AwtMouseListener }
MouseEvent AwtMouseEvent, MouseListener AwtMouseListener,
MouseMotionListener AwtMouseMotionListener }
import de.h2b.scala.lib.simgraf.event._
import de.h2b.scala.lib.simgraf.Pixel
......@@ -37,6 +38,7 @@ trait AwtEventDriver extends AwtScreenDriver {
panel.addKeyListener(KeyListener)
panel.addMouseListener(MouseListener)
panel.addMouseMotionListener(MouseListener)
private object KeyListener extends AwtKeyListener {
......@@ -54,7 +56,9 @@ trait AwtEventDriver extends AwtScreenDriver {
}
private object MouseListener extends AwtMouseListener {
private object MouseListener extends AwtMouseListener with AwtMouseMotionListener {
//AwtMouseListener events
def mouseClicked (e: AwtMouseEvent): Unit = {
panel.requestFocusInWindow()
......@@ -70,13 +74,32 @@ trait AwtEventDriver extends AwtScreenDriver {
}
def mousePressed (e: AwtMouseEvent): Unit = {
//unused in this implementation
drag0 = position(e)
}
def mouseReleased (e: AwtMouseEvent): Unit = {
if (dragging) {
publisher ! dragEvent(e)
dragging = false
}
}
//AwtMouseMotionListener events
private var dragging = false
private var drag0 = Pixel(0, 0)
def mouseDragged (e: AwtMouseEvent): Unit = {
dragging = true
}
def mouseMoved (e: AwtMouseEvent): Unit = {
//unused in this implementation
}
private def dragEvent (e: AwtMouseEvent) =
DragEvent(button(e), modifiers(e), drag0, position(e))
}
private def mouseEvent (e: AwtMouseEvent) =
......
......@@ -37,3 +37,14 @@ case class KeyEvent (char: Char) extends Event
*/
case class MouseEvent (button: Button, modifiers: Set[Modifier], clickCount: Int,
position: Pixel) extends Event
/**
* @constructor
*
* @param position0 the start position of this drag event in coordinates
* of the related screen
* @param position1 the end position of this drag event in coordinates
* of the related screen
*/
case class DragEvent (button: Button, modifiers: Set[Modifier],
position0: Pixel, position1: Pixel) extends Event
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment