Skip to content

Commit

Permalink
Added PaintReference to clean up paint feature
Browse files Browse the repository at this point in the history
  • Loading branch information
McAJBen committed Feb 2, 2020
1 parent 45d1538 commit 12e521f
Show file tree
Hide file tree
Showing 19 changed files with 865 additions and 960 deletions.
Binary file removed Dungeon Board/Paint/Mornien Underground/7.png
Binary file not shown.
349 changes: 116 additions & 233 deletions src/control/ControlPaint.kt

Large diffs are not rendered by default.

28 changes: 4 additions & 24 deletions src/control/ControlPaintListener.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package control

import util.Resources
import java.awt.Point
import java.awt.image.BufferedImage
import paint.PaintReference

/**
* a listener for events coming from `ControlPaint`
Expand All @@ -12,31 +10,13 @@ import java.awt.image.BufferedImage
interface ControlPaintListener {

/**
* sets the dimension of the image to be painted
* updates the display with a new `PaintReference`
* @param ref the new reference
*/
fun setImageSize()

/**
* sets the mask to draw over the image
* @param mask an image where every pixel is either Color.BLACK or transparent
*/
fun setMask(mask: BufferedImage = Resources.BLANK_CURSOR)
fun setPaintReference(ref: PaintReference)

/**
* tells display to repaint
*/
fun repaint()

/**
* sets the window to a specific scale and position
* @param scale the zoom scale for the image
* @param windowPos the offset of the top left corner of the image
*/
fun setWindow(scale: Double, windowPos: Point)

/**
* sets the window position
* @param windowPos the offset of the top left corner of the image
*/
fun setWindowPos(windowPos: Point)
}
23 changes: 18 additions & 5 deletions src/control/ControlPictures.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@ package control
import display.DisplayPictures
import display.Scale
import main.Mode
import util.Colors
import util.Resources
import util.Settings
import util.createButton
import util.*
import java.awt.BorderLayout
import java.awt.Dimension
import java.io.File
import java.util.concurrent.Executors
import javax.swing.BorderFactory
import javax.swing.JButton
import javax.swing.JComboBox
import javax.swing.JScrollPane

Expand Down Expand Up @@ -123,7 +122,21 @@ class ControlPictures(
}

picturePanel.clearButtons()
PPButtonCreator(picturePanel, folder).run()

val executor = Executors.newFixedThreadPool(Settings.SYS_THREADS)
folder.listFilesInOrder().filter {
it.extension.equals("PNG", ignoreCase = true)
|| it.extension.equals("JPG", ignoreCase = true)
|| it.extension.equals("JPEG", ignoreCase = true)
}.map {
executor.submit<JButton> {
picturePanel.createPPButton(it)
}
}.forEach {
picturePanel.add(it.get())
}
executor.shutdown()

repaint()
revalidate()
display.removeAllImages()
Expand Down
91 changes: 0 additions & 91 deletions src/control/PPButtonCreator.kt

This file was deleted.

14 changes: 7 additions & 7 deletions src/display/Cube.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package display

import util.Resources
import util.Settings
import util.Settings.DISPLAY_SIZE
import java.awt.Graphics2D
import java.awt.Point
import java.util.*
Expand All @@ -26,8 +26,8 @@ class Cube {
* the current position of the top left corner
*/
private val point = Point(
rand.nextInt(Settings.DISPLAY_SIZE!!.width - Resources.ICON_DVD.iconWidth),
rand.nextInt(Settings.DISPLAY_SIZE!!.height - Resources.ICON_DVD.iconHeight)
rand.nextInt(DISPLAY_SIZE.width - Resources.ICON_DVD.iconWidth),
rand.nextInt(DISPLAY_SIZE.height - Resources.ICON_DVD.iconHeight)
)

/**
Expand Down Expand Up @@ -83,8 +83,8 @@ class Cube {
}
} else {
point.x += speed
if (point.x > Settings.DISPLAY_SIZE!!.width - Resources.ICON_DVD.iconWidth) {
point.x = Settings.DISPLAY_SIZE!!.width - Resources.ICON_DVD.iconWidth
if (point.x > DISPLAY_SIZE.width - Resources.ICON_DVD.iconWidth) {
point.x = DISPLAY_SIZE.width - Resources.ICON_DVD.iconWidth
vertical = true
verticalHit = true
}
Expand All @@ -100,8 +100,8 @@ class Cube {
}
} else {
point.y += speed
if (point.y > Settings.DISPLAY_SIZE!!.height - Resources.ICON_DVD.iconHeight) {
point.y = Settings.DISPLAY_SIZE!!.height - Resources.ICON_DVD.iconHeight
if (point.y > DISPLAY_SIZE.height - Resources.ICON_DVD.iconHeight) {
point.y = DISPLAY_SIZE.height - Resources.ICON_DVD.iconHeight
horizontal = true
if (verticalHit) {
flag = true
Expand Down
15 changes: 8 additions & 7 deletions src/display/DisplayLoading.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package display

import main.Mode
import util.Settings
import util.Settings.DISPLAY_SIZE
import java.awt.AlphaComposite
import java.awt.Color
import java.awt.Graphics
Expand Down Expand Up @@ -214,24 +215,24 @@ class DisplayLoading(window: DisplayWindow) : Display(window) {
if (currentImage != null) {
if (upScale) {
if (timer <= FADE_IN) {
g2d.drawImage(oldImage, 0, 0, Settings.DISPLAY_SIZE!!.width, Settings.DISPLAY_SIZE!!.height, null)
g2d.drawImage(oldImage, 0, 0, DISPLAY_SIZE.width, DISPLAY_SIZE.height, null)
}
g2d.composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fade)
g2d.drawImage(currentImage, 0, 0, Settings.DISPLAY_SIZE!!.width, Settings.DISPLAY_SIZE!!.height, null)
g2d.drawImage(currentImage, 0, 0, DISPLAY_SIZE.width, DISPLAY_SIZE.height, null)
} else {
g2d.color = Color(currentImage!!.getRGB(0, 0))
g2d.fillRect(0, 0, Settings.DISPLAY_SIZE!!.width, Settings.DISPLAY_SIZE!!.height)
g2d.fillRect(0, 0, DISPLAY_SIZE.width, DISPLAY_SIZE.height)
if (timer <= FADE_IN && oldImage != null) {
g2d.composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1 - fade)
g2d.drawImage(
oldImage, (Settings.DISPLAY_SIZE!!.width - oldImage!!.width) / 2,
(Settings.DISPLAY_SIZE!!.height - oldImage!!.height) / 2, null
oldImage, (DISPLAY_SIZE.width - oldImage!!.width) / 2,
(DISPLAY_SIZE.height - oldImage!!.height) / 2, null
)
}
g2d.composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, fade)
g2d.drawImage(
currentImage, (Settings.DISPLAY_SIZE!!.width - currentImage!!.width) / 2,
(Settings.DISPLAY_SIZE!!.height - currentImage!!.height) / 2, null
currentImage, (DISPLAY_SIZE.width - currentImage!!.width) / 2,
(DISPLAY_SIZE.height - currentImage!!.height) / 2, null
)
}
}
Expand Down
Loading

0 comments on commit 12e521f

Please sign in to comment.