Files
bdlib/src/net/bdew/lib/gui/widgets/WidgetFillDataslot.scala
T

35 lines
1.1 KiB
Scala

/*
* 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
* http://bdew.net/minecraft-mod-public-license/
*/
package net.bdew.lib.gui.widgets
import net.bdew.lib.data.base.DataSlotNumeric
import net.bdew.lib.gui._
class WidgetFillDataslot[T](val rect: Rect, val texture: Texture, dir: Direction.Direction, dslot: DataSlotNumeric[T], maxval: T)(implicit num: Numeric[T]) extends Widget {
import num.mkNumericOps
override def draw(mouse: Point) {
val fill = dslot.cval.toFloat() / maxval.toFloat()
dir match {
case Direction.UP =>
parent.drawTextureInterpolate(rect, texture, 0, 1 - fill, 1, 1)
case Direction.DOWN =>
parent.drawTextureInterpolate(rect, texture, 0, 0, 1, fill)
case Direction.LEFT =>
parent.drawTextureInterpolate(rect, texture, 1 - fill, 0, 1, 1)
case Direction.RIGHT =>
parent.drawTextureInterpolate(rect, texture, 0, 0, fill, 1)
}
}
}