diff --git a/src/main/resources/shaders/fancy_rect.glsl b/src/main/resources/shaders/fancy_rect.glsl index 5c09a184..e7073f2b 100644 --- a/src/main/resources/shaders/fancy_rect.glsl +++ b/src/main/resources/shaders/fancy_rect.glsl @@ -25,6 +25,7 @@ in float internalAspectRatio; out vec4 color; uniform vec4 col; +uniform bool inverted; void main() { vec2 distToEdge2d = 0.5 - abs(internalPosition - 0.5); @@ -39,6 +40,8 @@ void main() { topLeftNess = (clamp(((1 - internalPosition.x) - (1 - internalPosition.y) * internalAspectRatio) * 200, -1, 1) + 1) * 0.5; } + if (inverted) topLeftNess = 1 - topLeftNess; + if (isCloseToEdge) { color = col + vec4(1, 1, 1, 0) * edgeEffect * mix(-0.3, 0.3, smoothstep(0, 1, topLeftNess)); } else { diff --git a/src/main/scala/hexacraft/gui/comp/Component.scala b/src/main/scala/hexacraft/gui/comp/Component.scala index 41416be8..aea49390 100644 --- a/src/main/scala/hexacraft/gui/comp/Component.scala +++ b/src/main/scala/hexacraft/gui/comp/Component.scala @@ -84,7 +84,8 @@ object Component: xoffset: Float, yoffset: Float, color: Vector4f, - windowAspectRatio: Float + windowAspectRatio: Float, + inverted: Boolean = false ): Unit = fancyRectShader.enable() @@ -94,6 +95,7 @@ object Component: .scale(location.w, location.h, 1) ) fancyRectShader.setColor(color) + fancyRectShader.setInverted(inverted) fancyRectShader.setWindowAspectRatio(windowAspectRatio) Component.rectRenderer.render(rectVAO) diff --git a/src/main/scala/hexacraft/gui/comp/FancyRectShader.scala b/src/main/scala/hexacraft/gui/comp/FancyRectShader.scala index e25cf285..10490362 100644 --- a/src/main/scala/hexacraft/gui/comp/FancyRectShader.scala +++ b/src/main/scala/hexacraft/gui/comp/FancyRectShader.scala @@ -17,5 +17,8 @@ class FancyRectShader { def setColor(color: Vector4f): Unit = shader.setUniform4f("col", color) + def setInverted(inverted: Boolean): Unit = + shader.setUniform1i("inverted", if inverted then 1 else 0) + def enable(): Unit = shader.activate() } diff --git a/src/main/scala/hexacraft/gui/comp/TextField.scala b/src/main/scala/hexacraft/gui/comp/TextField.scala index 1bdace03..ceadf77a 100644 --- a/src/main/scala/hexacraft/gui/comp/TextField.scala +++ b/src/main/scala/hexacraft/gui/comp/TextField.scala @@ -12,7 +12,7 @@ class TextField( centered: Boolean = true, maxFontSize: Float = 4f ) extends Component: - private val bgColor = new Vector4f(0.5f) + private val bgColor = new Vector4f(0.4f, 0.4f, 0.4f, 0.8f) private val textColor = new Vector3f(1.0f) private val contentText: Text = makeContentText() @@ -71,7 +71,14 @@ class TextField( cursorTextVisible = false override def render(transformation: GUITransformation)(using context: RenderContext): Unit = - Component.drawRect(location, transformation.x, transformation.y, bgColor, context.windowAspectRatio) + Component.drawFancyRect( + location, + transformation.x, + transformation.y, + bgColor, + context.windowAspectRatio, + inverted = true + ) super.render(transformation) override def handleEvent(event: Event): Boolean =