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

delegate method #9

Open
kindlychung opened this issue Sep 20, 2015 · 0 comments
Open

delegate method #9

kindlychung opened this issue Sep 20, 2015 · 0 comments

Comments

@kindlychung
Copy link

Here is some code from the reversi app:

package proscalafx.ch04.reversi.ui

import javafx.scene.{layout => jfxsl}

import proscalafx.ch04.reversi.model.ReversiModel

import scalafx.Includes._
import scalafx.animation.FadeTransition
import scalafx.geometry.{HPos, VPos}
import scalafx.scene.effect.{Light, Lighting}
import scalafx.scene.input.MouseEvent
import scalafx.scene.layout.Region
import scalafx.util.Duration

class ReversiSquare(val x: Int, val y: Int) extends Region {

  private val highlight = new Region {
    opacity = 0
    style = "-fx-border-width: 3; -fx-border-color: dodgerblue"
  }

//  override val delegate: jfxsl.Region = new jfxsl.Region {
//    getChildren.add(highlight)
//    protected override def layoutChildren() {
//      layoutInArea(highlight, 0, 0, getWidth, getHeight, getBaselineOffset, HPos.Center, VPos.Center)
//    }
//  }

  private val highlightTransition = new FadeTransition {
    node = highlight
    duration = Duration(200)
    fromValue = 0
    toValue = 1
  }

  style <== when(ReversiModel.legalMove(x, y)) choose
    "-fx-background-color: derive(dodgerblue, -60%)" otherwise
    "-fx-background-color: burlywood"

  effect = new Lighting {
    light = new Light.Distant {
      azimuth = -135
      elevation = 30
    }
  }

  prefHeight = 200
  prefWidth = 200

//  onMouseEntered = (e: MouseEvent) => {
//    if (ReversiModel.legalMove(x, y).get) {
//      highlightTransition.rate() = 1
//      highlightTransition.play()
//    }
//  }
//
//  onMouseExited = (e: MouseEvent) => {
//    highlightTransition.rate = -1
//    highlightTransition.play()
//  }

  onMouseClicked = (e: MouseEvent) => {
    ReversiModel.play(x, y)
//    highlightTransition.rate() = -1
//    highlightTransition.play()
  }
}

Note that I have commented out the delegate method and the app works the same as before.

Could you please explain a bit what this method actually does? It's never used in the app and I am having some difficulty understanding it. It's creating a new Region object with an overridden method layoutChildren, but what's the purpose?

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

1 participant