Skip to content

Commit

Permalink
feat: Image shadow (and color) options.
Browse files Browse the repository at this point in the history
  • Loading branch information
opZywl committed Jan 15, 2025
1 parent 28fde94 commit d787341
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ class SettingComponents(private val module: Module) : Component() {
val colorPickerEndY = colorPickerStartY + colorPickerHeight

val hueSliderX = colorPickerEndX + spacingBetweenSliders
val hueSliderStartY = colorPickerStartY
val hueSliderEndY = colorPickerStartY + hueSliderHeight

val opacityStartX = hueSliderX + hueSliderWidth + spacingBetweenSliders
Expand Down Expand Up @@ -688,7 +687,7 @@ class SettingComponents(private val module: Module) : Component() {
}
},
drawAt = { id ->
drawTexture(id, hueSliderX, hueSliderStartY, hueSliderWidth, hueSliderHeight)
drawTexture(id, hueSliderX, colorPickerStartY, hueSliderWidth, hueSliderHeight)
}
)

Expand All @@ -715,12 +714,12 @@ class SettingComponents(private val module: Module) : Component() {
}
},
drawAt = { id ->
drawTexture(id, opacityStartX, hueSliderStartY, hueSliderWidth, hueSliderHeight)
drawTexture(id, opacityStartX, colorPickerStartY, hueSliderWidth, hueSliderHeight)
}
)

val hueMarkerY = (hueSliderStartY..hueSliderEndY).lerpWith(hue)
val opacityMarkerY = (hueSliderStartY..hueSliderEndY).lerpWith(1 - setting.opacitySliderY)
val hueMarkerY = (colorPickerStartY..hueSliderEndY).lerpWith(hue)
val opacityMarkerY = (colorPickerStartY..hueSliderEndY).lerpWith(1 - setting.opacitySliderY)
RenderUtils.drawBorder(
hueSliderX - 1f,
hueMarkerY - 1f,
Expand All @@ -743,10 +742,10 @@ class SettingComponents(private val module: Module) : Component() {
&& mouseY in colorPickerStartY until colorPickerEndY)
val inHueSlider =
(mouseX in hueSliderX - 1..hueSliderX + hueSliderWidth + 1
&& mouseY in hueSliderStartY until hueSliderEndY)
&& mouseY in colorPickerStartY until hueSliderEndY)
val inOpacitySlider =
(mouseX in opacityStartX - 1..opacityEndX + 1
&& mouseY in hueSliderStartY until hueSliderEndY)
&& mouseY in colorPickerStartY until hueSliderEndY)

val sliderType = setting.lastChosenSlider
if ((type == GuiEvents.CLICK && button == 0 && (inColorPicker || inHueSlider || inOpacitySlider))
Expand All @@ -770,7 +769,7 @@ class SettingComponents(private val module: Module) : Component() {

if (inHueSlider && (sliderType == null || sliderType == ColorValue.SliderType.HUE)) {
setting.hueSliderY =
((mouseY - hueSliderStartY) / hueSliderHeight.toFloat()).coerceIn(0f, 1f)
((mouseY - colorPickerStartY) / hueSliderHeight.toFloat()).coerceIn(0f, 1f)
finalColor = Color(
Color.HSBtoRGB(
setting.hueSliderY,
Expand All @@ -782,7 +781,7 @@ class SettingComponents(private val module: Module) : Component() {

if (inOpacitySlider && (sliderType == null || sliderType == ColorValue.SliderType.OPACITY)) {
setting.opacitySliderY =
1 - ((mouseY - hueSliderStartY) / hueSliderHeight.toFloat()).coerceIn(0f, 1f)
1 - ((mouseY - colorPickerStartY) / hueSliderHeight.toFloat()).coerceIn(0f, 1f)
}

finalColor = finalColor.withAlpha((setting.opacitySliderY * 255).roundToInt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,25 @@
package net.ccbluex.liquidbounce.ui.client.hud.element.elements

import com.google.gson.JsonElement
import net.ccbluex.liquidbounce.config.TextValue
import net.ccbluex.liquidbounce.config.boolean
import net.ccbluex.liquidbounce.config.color
import net.ccbluex.liquidbounce.ui.client.hud.element.Border
import net.ccbluex.liquidbounce.ui.client.hud.element.Element
import net.ccbluex.liquidbounce.ui.client.hud.element.ElementInfo
import net.ccbluex.liquidbounce.utils.io.FileFilters
import net.ccbluex.liquidbounce.utils.io.MiscUtils
import net.ccbluex.liquidbounce.utils.kotlin.RandomUtils.randomNumber
import net.ccbluex.liquidbounce.utils.render.ColorUtils.withAlpha
import net.ccbluex.liquidbounce.utils.render.RenderUtils.drawImage
import net.ccbluex.liquidbounce.config.TextValue
import net.ccbluex.liquidbounce.utils.io.FileFilters
import net.minecraft.client.renderer.texture.DynamicTexture
import net.minecraft.util.ResourceLocation
import java.awt.Color
import java.io.File
import java.util.*
import javax.imageio.ImageIO


/**
* CustomHUD image element
*
Expand All @@ -28,6 +33,9 @@ import javax.imageio.ImageIO
@ElementInfo(name = "Image")
class Image : Element() {

private val shadow by boolean("Shadow", true)
private val shadowColor by color("Color", Color.BLACK.withAlpha(128)) { shadow }

companion object {

/**
Expand Down Expand Up @@ -72,6 +80,10 @@ class Image : Element() {
* Draw element
*/
override fun drawElement(): Border {
if (shadow) {
drawImage(resourceLocation, 1, 1, width / 2, height / 2, shadowColor)
}

drawImage(resourceLocation, 0, 0, width / 2, height / 2)

return Border(0F, 0F, width / 2F, height / 2F)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2318,13 +2318,13 @@ object RenderUtils : MinecraftInstance {
glPopAttrib()
}

fun drawImage(image: ResourceLocation?, x: Int, y: Int, width: Int, height: Int) {
fun drawImage(image: ResourceLocation?, x: Int, y: Int, width: Int, height: Int, color: Color = Color.WHITE) {
glPushMatrix()
glDisable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glDepthMask(false)
GL14.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO)
glColor4f(1f, 1f, 1f, 1f)
glColor(color)
mc.textureManager.bindTexture(image)
drawModalRectWithCustomSizedTexture(
x.toFloat(),
Expand Down Expand Up @@ -3629,13 +3629,7 @@ object RenderUtils : MinecraftInstance {
* @param endColor the end color
*/
fun drawGradientRect(
left: Int,
top: Int,
right: Int,
bottom: Int,
startColor: Int,
endColor: Int,
zLevel: Float
left: Int, top: Int, right: Int, bottom: Int, startColor: Int, endColor: Int, zLevel: Float
) {
val a1 = (startColor shr 24 and 255) / 255f
val r1 = (startColor shr 16 and 255) / 255f
Expand Down

0 comments on commit d787341

Please sign in to comment.