Skip to content

Commit

Permalink
Refactored ImagePane slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Aug 7, 2018
1 parent c6af09c commit ef9da48
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class TriPaintController(view: TriPaintView) {
view.askForWhereToPutImage() match {
case Some((x, y)) =>
addImage(TriImage(
makeImageContent(TriImageCoords(x, y), imagePool.fromBGColor(new Color(view.imageDisplay.secondaryColor()), imageGrid.imageSize)),
makeImageContent(TriImageCoords(x, y), imagePool.fromBGColor(new Color(view.imageDisplay.colors.secondaryColor()), imageGrid.imageSize)),
view.imageDisplay
))
case _ =>
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/com/martomate/tripaint/gui/MainStage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ class MainStage extends PrimaryStage with TriPaintView {

private def makeColorBox() = {
//overlay and imageDisplay
val colorPicker1 = new ColorPicker(new Color(imageDisplay.primaryColor()))
val colorPicker2 = new ColorPicker(new Color(imageDisplay.secondaryColor()))
val colorPicker1 = new ColorPicker(new Color(imageDisplay.colors.primaryColor()))
val colorPicker2 = new ColorPicker(new Color(imageDisplay.colors.secondaryColor()))

imageDisplay.primaryColor <==> colorPicker1.value
imageDisplay.secondaryColor <==> colorPicker2.value
imageDisplay.colors.primaryColor <==> colorPicker1.value
imageDisplay.colors.secondaryColor <==> colorPicker2.value

new VBox(
new Label("Primary color:"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import scalafx.scene.layout.Pane
import scalafx.scene.paint.Color

class ImagePane(imageGrid: ImageGrid) extends Pane with ImageGridView with ImageGridListener {
private val (_primaryColor, _secondaryColor) = (ObjectProperty(Color.Black), ObjectProperty(Color.White))
private var _zoom = 1d
def zoom: Double = _zoom

private var _xScroll: Double = 0
def xScroll: Double = _xScroll

private var _yScroll: Double = 0
def yScroll: Double = _yScroll

private val gridSearcher: ImageGridSearcher = new ImageGridSearcher(imageGrid)

Expand All @@ -23,9 +27,6 @@ class ImagePane(imageGrid: ImageGrid) extends Pane with ImageGridView with Image
private def images: Seq[TriImage] = imageGrid.images
def imageSize: Int = imageGrid.imageSize

def zoom: Double = _zoom
def xScroll: Double = _xScroll
def yScroll: Double = _yScroll
def sideLength: Double = (imageGrid.imageSize * 2 + 1) * zoom

private object drag {
Expand Down Expand Up @@ -120,8 +121,8 @@ class ImagePane(imageGrid: ImageGrid) extends Pane with ImageGridView with Image
}

def primaryOrSecondaryColor: Option[ObjectProperty[paint.Color]] = e.getButton match {
case MouseButton.PRIMARY => Some(primaryColor)
case MouseButton.SECONDARY => Some(secondaryColor)
case MouseButton.PRIMARY => Some(colors.primaryColor)
case MouseButton.SECONDARY => Some(colors.secondaryColor)
case _ => None
}
}
Expand All @@ -134,28 +135,30 @@ class ImagePane(imageGrid: ImageGrid) extends Pane with ImageGridView with Image
}
}

def primaryColor: ObjectProperty[paint.Color] = _primaryColor
def primaryColor_=(col: Color): Unit = primaryColor.value = col
object colors {
val primaryColor: ObjectProperty[paint.Color] = ObjectProperty(Color.Black)
def primaryColor_=(col: Color): Unit = primaryColor.value = col

def secondaryColor: ObjectProperty[paint.Color] = _secondaryColor
def secondaryColor_=(col: Color): Unit = secondaryColor.value = col
val secondaryColor: ObjectProperty[paint.Color] = ObjectProperty(Color.White)
def secondaryColor_=(col: Color): Unit = secondaryColor.value = col
}

def undo: Boolean = imageGrid.selectedImages.forall(_.undo)
def redo: Boolean = imageGrid.selectedImages.forall(_.redo)

this.width onChange updateSize
this.height onChange updateSize

def updateSize(): Unit = {
private def updateSize(): Unit = {
this.clip() = new Rectangle(0, 0, width(), height())
relocateChildren()
}

def relocateChildren(): Unit = {
private def relocateChildren(): Unit = {
images.foreach(relocateImage)
}

def relocateImage(image: TriImage): Unit = {
private def relocateImage(image: TriImage): Unit = {
image.relocate(width() / 2 + xScroll, height() / 2 + yScroll)
}

Expand Down

0 comments on commit ef9da48

Please sign in to comment.