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

Adds .setCompassImage(image: Image) and .setCompassImage(compassImage: CompassImage) Functions #16

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions src/main/kotlin/org/rowlandhall/meepmeep/MeepMeep.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import java.awt.event.KeyListener
import java.awt.event.MouseEvent
import java.awt.event.MouseListener
import java.awt.event.MouseMotionListener
import java.awt.image.BufferedImage
import javax.imageio.ImageIO
import javax.swing.UIManager

Expand Down Expand Up @@ -467,6 +468,52 @@ class MeepMeep @JvmOverloads constructor(
return this
}

/**
* Sets the compass image for the MeepMeep application.
*
* @param compassImage The [CompassImage] enum representing the wanted compass image.
* @return The [MeepMeep] instance for method chaining.
*/
fun setCompassImage(compassImage: CompassImage): MeepMeep {
val classLoader = Thread.currentThread().contextClassLoader

val compassImageMap = CompassImage.values().associateWith { img ->
val path = when (img) {
CompassImage.SIMPLE -> if (colorManager.isDarkMode) "misc/simple-compass-white.png" else "misc/simple-compass-black.png"
CompassImage.SIMPLE_BLACK -> "misc/simple-compass-black.png"
CompassImage.SIMPLE_WHITE -> "misc/simple-compass-white.png"
CompassImage.COMPASS_ROSE -> if (colorManager.isDarkMode) "misc/compass-rose-white-text.png" else "misc/compass-rose-black-text.png"
CompassImage.COMPASS_ROSE_WHITE -> "misc/compass-rose-white-text.png"
CompassImage.COMPASS_ROSE_BLACK -> "misc/compass-rose-black-text.png"
}

path
}

// Get the path and dark mode boolean from the compass image map
val path = compassImageMap[compassImage]!!
val newImage = ImageIO.read(classLoader.getResourceAsStream(path))
DEFAULT_COMPASS_ENTITY.setCompassImage(newImage, colorManager.isDarkMode)

return this
}

/**
* Sets the compass image for the MeepMeep application.
*
* This method scales the provided [Image] and sets it as the compass image, allowing for custom compass images.
*
* @param image The [Image] to be set as the compass image.
* @return The [MeepMeep] instance for method chaining.
*/
fun setCompassImage(image: Image): MeepMeep {
// Read the image into a buffered image
val bufferedImage = image as BufferedImage
DEFAULT_COMPASS_ENTITY.setCompassImage(bufferedImage, colorManager.isDarkMode)

return this
}

/**
* Sets the display position for the mouse coordinates on the canvas.
*
Expand Down Expand Up @@ -791,4 +838,40 @@ class MeepMeep @JvmOverloads constructor(
FIELD_INTOTHEDEEP_JUICE_GREYSCALE,
FIELD_INTOTHEDEEP_JUICE_BLACK
}

/**
* Enum class representing various compass image options for the MeepMeep
* application.
*
* Each enum constant corresponds to a specific compass image that can be
* set using the [MeepMeep.setCompassImage] method.
*
* @see [MeepMeep.setCompassImage]
* @see [MeepMeep.setCompassImage]
*/
enum class CompassImage {
/**
* Simple Compass type, automatically selects black or white text based on
* color scheme ([ColorManager.isDarkMode]).
*/
SIMPLE,

/** Simple Compass type with black text. */
SIMPLE_BLACK,

/** Simple Compass type with white text. */
SIMPLE_WHITE,

/**
* Compass Rose type, automatically selects white or black text based on
* color scheme ([ColorManager.isDarkMode]).
*/
COMPASS_ROSE,

/** Compass Rose type with white text. */
COMPASS_ROSE_WHITE,

/** Compass Rose type with black text. */
COMPASS_ROSE_BLACK
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,18 @@ class CompassEntity(
}
}

/**
* Switches the image used by the compass entity. This function is to be
* used through [MeepMeep.setCompassImage], not directly.
*
* @param image The new image.
*/
fun setCompassImage(image: BufferedImage, isDark: Boolean) {
bgDark = image
bgLight = image
redraw()
}

/**
* Handles mouse moved events to animate the compass opacity.
*
Expand Down
Loading