mirror of
https://github.com/GTNewHorizons/bdlib.git
synced 2026-11-22 21:19:52 +00:00
WidgetContainer draw functions now take color
This commit is contained in:
1 parent
9819600b15
commit
9f6e2d7533
3 files changed
+65
-18
No files matched your search
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui
|
||||
|
||||
import org.lwjgl.opengl.GL11
|
||||
|
||||
case class Color(r: Float, g: Float, b: Float) {
|
||||
def this(c: (Float, Float, Float)) = this(c._1, c._2, c._3)
|
||||
def activate() {
|
||||
GL11.glColor3f(r, g, b)
|
||||
}
|
||||
}
|
||||
|
||||
object Color {
|
||||
final val white = Color(1, 1, 1)
|
||||
}
|
||||
@@ -20,6 +20,8 @@ trait WidgetContainer {
|
||||
val rect: Rect
|
||||
val widgets = mutable.MutableList.empty[BaseWidget]
|
||||
|
||||
def activeWidgets: Iterable[BaseWidget] = widgets
|
||||
|
||||
def getFontRenderer: FontRenderer
|
||||
|
||||
def clear() = widgets.clear()
|
||||
@@ -31,7 +33,7 @@ trait WidgetContainer {
|
||||
}
|
||||
|
||||
def mouseClicked(p: Point, bt: Int) {
|
||||
for (w <- widgets)
|
||||
for (w <- activeWidgets)
|
||||
if (w.rect.contains(p))
|
||||
w.mouseClicked(p - w.rect.origin, bt)
|
||||
else
|
||||
@@ -39,7 +41,7 @@ trait WidgetContainer {
|
||||
}
|
||||
|
||||
def keyTyped(c: Char, i: Int): Boolean = {
|
||||
for (w <- widgets)
|
||||
for (w <- activeWidgets)
|
||||
if (w.keyTyped(c, i))
|
||||
return true
|
||||
return false
|
||||
@@ -47,17 +49,17 @@ trait WidgetContainer {
|
||||
|
||||
def draw(mouse: Point) {
|
||||
val p = mouse - rect.origin
|
||||
for (w <- widgets) {
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslatef(rect.origin.x, rect.origin.y, 0)
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslatef(rect.origin.x, rect.origin.y, 0)
|
||||
for (w <- activeWidgets) {
|
||||
w.draw(p)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
|
||||
def handleTooltip(op: Point, tip: mutable.MutableList[String]) {
|
||||
val p = op
|
||||
for (w <- widgets if w.rect.contains(p))
|
||||
for (w <- activeWidgets if w.rect.contains(p))
|
||||
w.handleTooltip(p - w.rect.origin, tip)
|
||||
}
|
||||
|
||||
@@ -67,28 +69,30 @@ trait WidgetContainer {
|
||||
}
|
||||
|
||||
def looseFocus() =
|
||||
for (w <- widgets)
|
||||
for (w <- activeWidgets)
|
||||
w.looseFocus()
|
||||
|
||||
def getOffsetFromWindow: Point
|
||||
|
||||
def drawTexture(r: Rect, uv: Point): Unit
|
||||
def drawIcon(r: Rect, i: Icon)
|
||||
def drawTexture(r: Rect, uv: Point, color: Color = Color.white): Unit
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white)
|
||||
}
|
||||
|
||||
class WidgetContainerWindow(val parent: BaseScreen, xSz: Int, ySz: Int) extends WidgetContainer {
|
||||
def getFontRenderer = parent.getFontRenderer
|
||||
def getOffsetFromWindow = Point(0, 0)
|
||||
val rect = Rect(0, 0, xSz, ySz)
|
||||
def drawTexture(r: Rect, uv: Point) =
|
||||
|
||||
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)
|
||||
def drawIcon(r: Rect, i: Icon) =
|
||||
}
|
||||
|
||||
def drawIcon(r: Rect, i: Icon, color: Color = Color.white) {
|
||||
color.activate()
|
||||
parent.drawTexturedModelRectFromIcon(r.x, r.y, i, r.w, r.h)
|
||||
}
|
||||
}
|
||||
|
||||
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) = parent.drawTexture(r, uv)
|
||||
def drawIcon(r: Rect, i: Icon) = parent.drawIcon(r, i)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) bdew, 2013 - 2014
|
||||
* https://github.com/bdew/bdlib
|
||||
*
|
||||
* This mod is distributed under the terms of the Minecraft Mod Public
|
||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
||||
* https://raw.github.com/bdew/bdlib/master/MMPL-1.0.txt
|
||||
*/
|
||||
|
||||
package net.bdew.lib.gui.widgets
|
||||
|
||||
import net.bdew.lib.gui.{Color, WidgetContainer, Point, Rect}
|
||||
import net.minecraft.util.Icon
|
||||
|
||||
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)
|
||||
}
|
||||
Reference in new issue
Block a user