From 26137a88d7aef5d0b40436592b7173081355c178 Mon Sep 17 00:00:00 2001 From: bdew Date: Thu, 27 Feb 2014 09:33:26 +0200 Subject: [PATCH] Added a separate method to Widget that draws the background layer --- src/net/bdew/lib/gui/BaseScreen.scala | 14 +++++--------- src/net/bdew/lib/gui/WidgetContainer.scala | 13 ++++++++++--- src/net/bdew/lib/gui/widgets/Widget.scala | 2 ++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/net/bdew/lib/gui/BaseScreen.scala b/src/net/bdew/lib/gui/BaseScreen.scala index adb6485..cdf6b4b 100644 --- a/src/net/bdew/lib/gui/BaseScreen.scala +++ b/src/net/bdew/lib/gui/BaseScreen.scala @@ -12,8 +12,6 @@ package net.bdew.lib.gui import net.minecraft.client.gui.inventory.GuiContainer import net.minecraft.inventory.Container import scala.collection.mutable -import net.minecraft.util.ResourceLocation -import org.lwjgl.opengl.GL11 abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContainer(cont) { xSize = xSz @@ -21,7 +19,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai val widgets = new WidgetContainerWindow(this, xSz, ySz) - val texture: ResourceLocation + val background: Texture def rect = new Rect(guiLeft, guiTop, xSize, ySize) @@ -59,11 +57,9 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai drawHoveringText(tip, x, y, fontRenderer) } - protected def drawGuiContainerBackgroundLayer(f: Float, i: Int, j: Int) { - GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F) - mc.renderEngine.bindTexture(texture) - val x = (width - xSize) / 2 - val y = (height - ySize) / 2 - this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize) + protected def drawGuiContainerBackgroundLayer(f: Float, x: Int, y: Int) { + if (background != null) + widgets.drawTexture(rect, background) + widgets.drawBackground(Point(x, y)) } } diff --git a/src/net/bdew/lib/gui/WidgetContainer.scala b/src/net/bdew/lib/gui/WidgetContainer.scala index 92e2e2a..e8b8ea7 100644 --- a/src/net/bdew/lib/gui/WidgetContainer.scala +++ b/src/net/bdew/lib/gui/WidgetContainer.scala @@ -45,6 +45,16 @@ trait WidgetContainer extends DrawTarget { return false } + def drawBackground(mouse: Point) { + val p = mouse - rect.origin + GL11.glPushMatrix() + GL11.glTranslatef(rect.origin.x, rect.origin.y, 0) + for (w <- activeWidgets) { + w.drawBackground(p) + } + GL11.glPopMatrix() + } + def draw(mouse: Point) { val p = mouse - rect.origin GL11.glPushMatrix() @@ -73,6 +83,3 @@ class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends def getOffsetFromWindow = Point(0, 0) val rect = Rect(0, 0, xSz, ySz) } - - - diff --git a/src/net/bdew/lib/gui/widgets/Widget.scala b/src/net/bdew/lib/gui/widgets/Widget.scala index 9aeb573..b65dcd7 100644 --- a/src/net/bdew/lib/gui/widgets/Widget.scala +++ b/src/net/bdew/lib/gui/widgets/Widget.scala @@ -22,6 +22,7 @@ trait BaseWidget { def mouseClicked(p: Point, button: Int) def keyTyped(c: Char, i: Int): Boolean def draw(mouse: Point) + def drawBackground(mouse: Point) def looseFocus() } @@ -31,6 +32,7 @@ trait Widget extends BaseWidget { def mouseClicked(p: Point, button: Int) {} def keyTyped(c: Char, i: Int): Boolean = false def draw(mouse: Point) {} + def drawBackground(mouse: Point) {} def looseFocus() {} def bindTexture(res: ResourceLocation) = Minecraft.getMinecraft.renderEngine.bindTexture(res)