-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
858 additions
and
527 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
common/src/main/java/io/github/notenoughupdates/moulconfig/common/DynamicTextureReference.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package io.github.notenoughupdates.moulconfig.common | ||
|
||
import org.jetbrains.annotations.ApiStatus | ||
import java.awt.image.BufferedImage | ||
import java.io.Closeable | ||
|
||
/** | ||
* A dynamically loaded texture. Must be destroyed manually. | ||
*/ | ||
@ApiStatus.NonExtendable | ||
abstract class DynamicTextureReference : Closeable { | ||
/** | ||
* An opaque reference to this dynamic texture. Can be used with [RenderContext.bindTexture]. | ||
*/ | ||
abstract val identifier: MyResourceLocation | ||
|
||
/** | ||
* Destroy this texture. Using [identifier] after calling this will cause issues. | ||
*/ | ||
fun destroy() { | ||
if (!wasDestroyed) | ||
doDestroy() | ||
wasDestroyed = true | ||
} | ||
|
||
abstract fun update(bufferedImage: BufferedImage) | ||
|
||
protected abstract fun doDestroy() | ||
|
||
private var wasDestroyed = false | ||
|
||
override fun close() { | ||
destroy() | ||
} | ||
|
||
protected fun finalize() { | ||
if (!wasDestroyed) | ||
IMinecraft.instance.getLogger("DynamicTextureReference").warn("Dangling DynamicTextureReference") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,5 @@ interface IKeyboardConstants { | |
val keyC: Int | ||
val keyX: Int | ||
val keyV: Int | ||
val keyN: Int | ||
} |
5 changes: 5 additions & 0 deletions
5
common/src/main/java/io/github/notenoughupdates/moulconfig/common/IMinecraft.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
common/src/main/java/io/github/notenoughupdates/moulconfig/internal/DrawContextExt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.github.notenoughupdates.moulconfig.internal | ||
|
||
import io.github.notenoughupdates.moulconfig.common.IFontRenderer | ||
import io.github.notenoughupdates.moulconfig.common.RenderContext | ||
|
||
object DrawContextExt { | ||
@JvmOverloads | ||
@JvmStatic | ||
fun RenderContext.drawStringCenteredScalingDownWithMaxWidth( | ||
text: String, | ||
centerX: Int, | ||
centerY: Int, | ||
maxWidth: Int, | ||
color: Int, | ||
shadow: Boolean = false, | ||
fr: IFontRenderer = minecraft.defaultFontRenderer, | ||
) { | ||
pushMatrix() | ||
val width = fr.getStringWidth(text) | ||
val factor = (maxWidth / width.toFloat()).coerceAtMost(1f) | ||
translate(centerX.toFloat(), centerY.toFloat(), 0F) | ||
scale(factor, factor, 1F) | ||
drawString(fr, text, -width / 2, -fr.height / 2, color, shadow) | ||
popMatrix() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.