mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-12 16:27:51 +00:00
Added WidgetContainer.drawTextureScaled
This commit is contained in:
1 parent
97b3e0ea1d
commit
f4f126fed2
5 files changed
+32
-5
No files matched your search
@@ -26,6 +26,7 @@ abstract class BaseScreen(cont: Container, xSz: Int, ySz: Int) extends GuiContai
|
||||
def rect = new Rect(guiLeft, guiTop, xSize, ySize)
|
||||
|
||||
def getFontRenderer = fontRenderer
|
||||
def getZLevel = zLevel
|
||||
|
||||
override def initGui() {
|
||||
super.initGui()
|
||||
|
||||
@@ -12,5 +12,9 @@ package net.bdew.lib.gui
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
class TextureLocation(val resource: ResourceLocation, val p: Point) extends Point(p.x, p.y) {
|
||||
def this(resource: ResourceLocation, x: Int, y: Int) = this(resource, new Point(x, y))
|
||||
def this(resource: ResourceLocation, x: Int, y: Int) = this(resource, Point(x, y))
|
||||
}
|
||||
|
||||
class TextureLocationScaled(val resource: ResourceLocation, val r: Rect) extends Rect(r.x, r.y, r.w, r.h) {
|
||||
def this(resource: ResourceLocation, x: Int, y: Int, w: Int, h: Int) = this(resource, Rect(x, y, w, h))
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import net.minecraft.util.Icon
|
||||
import net.minecraft.client.gui.FontRenderer
|
||||
import net.minecraft.client.Minecraft
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.minecraft.client.renderer.Tessellator
|
||||
|
||||
trait WidgetContainer {
|
||||
val rect: Rect
|
||||
@@ -76,6 +77,7 @@ trait WidgetContainer {
|
||||
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white): Unit
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white)
|
||||
def drawTextureScaled(r: Rect, t: TextureLocationScaled, color: Color = Color.white)
|
||||
}
|
||||
|
||||
class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends WidgetContainer {
|
||||
@@ -83,6 +85,26 @@ class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends
|
||||
def getOffsetFromWindow = Point(0, 0)
|
||||
val rect = Rect(0, 0, xSz, ySz)
|
||||
|
||||
final val F = 1/256F
|
||||
|
||||
def addVertexUVScaled(x: Float, y: Float, z: Float, u: Float, v: Float) {
|
||||
Tessellator.instance.addVertexWithUV(x, y, z, u * F, v * F)
|
||||
}
|
||||
|
||||
def drawTextureScaled(r: Rect, l: TextureLocationScaled, color: Color = Color.white) {
|
||||
val t = l.r
|
||||
val z = parent.getZLevel
|
||||
|
||||
Minecraft.getMinecraft.renderEngine.bindTexture(l.resource)
|
||||
color.activate()
|
||||
Tessellator.instance.startDrawingQuads()
|
||||
addVertexUVScaled(r.x, r.y + r.w, z, t.x, t.y + t.w)
|
||||
addVertexUVScaled(r.x + r.h, r.y + r.w, z, t.x + t.h, t.y + t.w)
|
||||
addVertexUVScaled(r.x + r.h, r.y, z, t.x + t.h, t.y)
|
||||
addVertexUVScaled(r.x, r.y, z, t.x, t.y)
|
||||
Tessellator.instance.draw()
|
||||
}
|
||||
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white) {
|
||||
color.activate()
|
||||
parent.drawTexturedModalRect(r.x, r.y, uv.x, uv.y, r.w, r.h)
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Point, Rect}
|
||||
import scala.collection.mutable
|
||||
import org.lwjgl.opengl.GL11
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
abstract class WidgetMultipane(rect: Rect) extends WidgetSubcontainer(rect) {
|
||||
def getActivePane: BaseWidget
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Color, WidgetContainer, Point, Rect}
|
||||
import net.bdew.lib.gui._
|
||||
import net.minecraft.util.Icon
|
||||
import net.bdew.lib.gui.Rect
|
||||
|
||||
class WidgetSubcontainer(val rect: Rect) extends BaseWidget with WidgetContainer {
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = parent.getOffsetFromWindow + rect.origin
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white) = parent.drawTexture(r, uv, color)
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white) = parent.drawIcon(r, i, color)
|
||||
def drawTextureScaled(r: Rect, t: TextureLocationScaled, color: Color = Color.white) = parent.drawTextureScaled(r, t,color)
|
||||
}
|
||||
Reference in new issue
Block a user