Added a separate method to Widget that draws the background layer

This commit is contained in:
bdew committed 2014-02-27 09:33:26 +02:00
1 parent 81a0d00a8b
commit 26137a88d7
3 files changed
+17 -12

No files matched your search

+5 -9
View File
@@ -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))
}
}
+10 -3
View File
@@ -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)
}
@@ -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)