Commit b82e5ec7 authored by h2b's avatar h2b

Demo added.

parent 9105aeb3
......@@ -18,7 +18,7 @@
package de.h2b.scala.lib.simgraf.event
import de.h2b.scala.lib.util.Logger
import de.h2b.scala.lib.util.{ Level, Logger }
* Provides an actor publishing `Event`s to the package object's global event
......@@ -29,11 +29,14 @@ import de.h2b.scala.lib.util.Logger
class Publisher extends Actor {
private val log = Logger(getClass)
private val log = Logger(getClass) at Level.Warn
def receive = {
case e: Event stream.publish(e)
case unknown log.warn(s"unknown message received: $unknown")
case e: Event
log.debug(s"event received: $e")
case unknown
log.warn(s"unknown message received: $unknown")
......@@ -32,13 +32,8 @@ import{ ActorSystem, Props }
package object event {
private val system = ActorSystem("SimGraf")
* The actor publishing all events to the global event stream that are
* triggered by drivers.
private[simgraf] val publisher = system.actorOf(Props[Publisher])
/** The actor system used in this package. */
val system = ActorSystem("SimGraf")
* The event stream global to this package.
......@@ -47,4 +42,10 @@ package object event {
val stream = system.eventStream
* The actor publishing all events to the global event stream that are
* triggered by drivers.
val publisher = system.actorOf(Props[Publisher])
SimGraf - A Simple Scala Graphics Library
Copyright 2016-2017 Hans-Hermann Bode
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
package de.h2b.scala.lib.simgraf.demo
import scala.util.Random
import{ Actor, Props }
import de.h2b.scala.lib.simgraf.event.{ Event, KeyEvent, MouseEvent, stream, system }
import de.h2b.scala.lib.simgraf.layout.GridLayout
import de.h2b.scala.lib.simgraf.shapes.{ Coloring, Rectangle }
import de.h2b.scala.lib.simgraf.{ Color, Point, World }
object EventEchoDemo extends App {
val frame = Rectangle(Point(-100,-100), Point(100,100))
val cell = GridLayout.onScreen(1, 1).fit(400, 400)
val title = "Event Echo demo"
val world = World.withEvents(frame)(cell, title)
world.fill(Coloring(_ =>
Color(Random.nextInt(256), Random.nextInt(256), Random.nextInt(256))))
class EventSubscriber extends Actor {
override def preStart = stream.subscribe(self, classOf[Event])
def receive = {
case e: Event println(e)
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