Skip to content

Commit

Permalink
identifying potential issue
Browse files Browse the repository at this point in the history
  • Loading branch information
regb committed Nov 9, 2016
1 parent 2c02d6c commit b7f25ed
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
44 changes: 23 additions & 21 deletions examples/scalavator/core/src/main/scala/MainScreen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ trait MainScreenComponent {

}


//If these are defined inside Hud, seems to crash scalajs?
class GroupBackground extends SceneNode(0, 0, 0, 0) {
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
canvas.drawColor(Color.Red)
}
}
class TitleLabel extends SceneNode(dp2px(15), dp2px(25), 0, 0) {
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
val textPaint = defaultPaint.withColor(Color.White).withFont(Font.Default.withSize(dp2px(18)))
canvas.drawString("Scalavator", x.toInt, y.toInt, textPaint)
}
}
class ScoreLabel extends SceneNode(WindowWidth-dp2px(25), dp2px(25), 0, 0) {
var score: Int = 0
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
val textPaint = defaultPaint.withColor(Color.White).withFont(Font.Default.withSize(dp2px(18)))
canvas.drawString(score.toString, x.toInt, y.toInt, textPaint.withAlignment(Alignments.Right))
}
}
class Hud {

val sceneGraph = new SceneGraph(WindowWidth, WindowHeight)
Expand All @@ -251,28 +274,7 @@ trait MainScreenComponent {
group.addNode(titleLabel)
group.addNode(scoreLabel)
sceneGraph.addNode(group)

val textPaint = defaultPaint.withColor(Color.White).withFont(Font.Default.withSize(dp2px(18)))

class GroupBackground extends SceneNode(0, 0, 0, 0) {
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
canvas.drawColor(Color.Red)
}
}
class TitleLabel extends SceneNode(dp2px(15), dp2px(25), 0, 0) {
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
canvas.drawString("Scalavator", x.toInt, y.toInt, textPaint)
}
}
class ScoreLabel extends SceneNode(WindowWidth-dp2px(25), dp2px(25), 0, 0) {
var score: Int = 0
override def update(dt: Long): Unit = {}
override def render(canvas: Canvas): Unit = {
canvas.drawString(score.toString, x.toInt, y.toInt, textPaint.withAlignment(Alignments.Right))
}
}
}

}
12 changes: 6 additions & 6 deletions html5/src/main/scala/sgl/html5/Html5GraphicsProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ trait Html5GraphicsProvider extends GraphicsProvider with Lifecycle {
override def width: Int = canvas.width

override def translate(x: Int, y: Int): Unit = {
//context.translate(x, y)
context.translate(x, y)
}

//probably useful to add to the core abstraction at some point
Expand All @@ -111,9 +111,9 @@ trait Html5GraphicsProvider extends GraphicsProvider with Lifecycle {
}

override def clipRect(x: Int, y: Int, width: Int, height: Int): Unit = {
//context.rect(x, y, width, height)
//context.stroke()
//context.clip()
context.rect(x, y, width, height)
context.stroke()
context.clip()
}

override def drawBitmap(bitmap: Bitmap, x: Int, y: Int): Unit = {
Expand Down Expand Up @@ -169,8 +169,8 @@ trait Html5GraphicsProvider extends GraphicsProvider with Lifecycle {
override def drawText(text: TextLayout, x: Int, y: Int): Unit = ???

override def drawColor(color: Color): Unit = {
//context.fillStyle = color
//context.fillRect(0, 0, WindowWidth, WindowHeight)
context.fillStyle = color
context.fillRect(0, 0, WindowWidth, WindowHeight)
}

override def clearRect(x: Int, y: Int, width: Int, height: Int): Unit = {
Expand Down

0 comments on commit b7f25ed

Please sign in to comment.