Example #1
0
File: text.go Project: num5/steven
// Draw draws this to the target region.
func (t *Text) Draw(r Region, delta float64) {
	if t.isNew || t.isDirty() || forceDirty {
		t.isNew = false
		cw, ch := t.Size()
		sx, sy := r.W/cw, r.H/ch
		var text render.UIText
		if t.rotation == 0 {
			text = render.NewUITextScaled(t.value, r.X, r.Y, sx*t.scaleX, sy*t.scaleY, t.r, t.g, t.b)
		} else {
			c := math.Cos(t.rotation)
			s := math.Sin(t.rotation)
			tmpx := r.W / 2
			tmpy := r.H / 2
			w := math.Abs(tmpx*c - tmpy*s)
			h := math.Abs(tmpy*c + tmpx*s)
			text = render.NewUITextRotated(t.value, r.X+w-(r.W/2), r.Y+h-(r.H/2), sx*t.scaleX, sy*t.scaleY, t.rotation, t.r, t.g, t.b)
		}
		text.Alpha(t.a)
		for _, txt := range text.Elements {
			txt.Layer = t.Layer()
		}
		t.data = text.Bytes()
	}
	render.UIAddBytes(t.data)
}
Example #2
0
// Draw draws this to the target region.
func (b *Button) Draw(r Region, delta float64) {
	if b.isNew || b.isDirty() || forceDirty {
		b.isNew = false
		if b.disabled {
			b.currentTex = render.RelativeTexture(render.GetTexture("gui/widgets"), 256, 256).
				Sub(0, 46, 200, 20)
		} else {
			off := 66
			if b.hovered {
				off += 20
			}
			b.currentTex = render.RelativeTexture(render.GetTexture("gui/widgets"), 256, 256).
				Sub(0, off, 200, 20)
		}
		b.data = b.data[:0]

		cw, ch := b.Size()
		sx, sy := r.W/cw, r.H/ch
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X, r.Y, 4*sx, 4*sy, 0, 0, 2/200.0, 2/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X+r.W-4*sx, r.Y, 4*sx, 4*sy, 198/200.0, 0, 2/200.0, 2/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X, r.Y+r.H-6*sy, 4*sx, 6*sy, 0, 17/20.0, 2/200.0, 3/20.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex, r.X+r.W-4*sx, r.Y+r.H-6*sy, 4*sx, 6*sy, 198/200.0, 17/20.0, 2/200.0, 3/20.0).Bytes()...)

		w := (r.W/sx)/2 - 4
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 0, 196, 2), r.X+4*sx, r.Y, r.W-8*sx, 4*sy, 0, 0, w/196.0, 1.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 17, 196, 3), r.X+4*sx, r.Y+r.H-6*sy, r.W-8*sx, 6*sy, 0, 0, w/196.0, 1.0).Bytes()...)

		h := (r.H/sy)/2 - 5
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(0, 2, 2, 15), r.X, r.Y+4*sy, 4*sx, r.H-10*sy, 0.0, 0.0, 1.0, h/16.0).Bytes()...)
		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(198, 2, 2, 15), r.X+r.W-4*sx, r.Y+4*sy, 4*sx, r.H-10*sy, 0.0, 0.0, 1.0, h/16.0).Bytes()...)

		b.data = append(b.data, b.newUIElement(b.currentTex.Sub(2, 2, 196, 15), r.X+4*sx, r.Y+4*sy, r.W-8*sx, r.H-10*sy, 0.0, 0.0, w/196.0, h/16.0).Bytes()...)
	}
	render.UIAddBytes(b.data)
}
Example #3
0
File: image.go Project: num5/steven
// Draw draws this to the target region.
func (i *Image) Draw(r Region, delta float64) {
	if i.isNew || i.isDirty() || forceDirty {
		i.isNew = false
		e := render.NewUIElement(i.texture, r.X, r.Y, r.W, r.H, i.tx, i.ty, i.tw, i.th)
		e.R = byte(i.r)
		e.G = byte(i.g)
		e.B = byte(i.b)
		e.A = byte(i.a)
		e.Layer = i.Layer()
		i.data = e.Bytes()
	}
	render.UIAddBytes(i.data)
}
Example #4
0
// Draw draws this to the target region.
func (f *Formatted) Draw(r Region, delta float64) {
	if f.isNew || f.isDirty() || forceDirty {
		cw, ch := f.Size()
		sx, sy := r.W/cw, r.H/ch
		f.data = f.data[:0]
		for _, t := range f.Text {
			r := getDrawRegion(t, sx, sy)
			t.SetLayer(f.layer)
			t.dirty = true
			t.Draw(r, delta)
			f.data = append(f.data, t.data...)
		}
		f.isNew = false
	}
	render.UIAddBytes(f.data)
}
Example #5
0
// Draw draws this to the target region.
func (t *TextBox) Draw(r Region, delta float64) {
	t.tick(delta)
	if t.isNew || t.isDirty() || forceDirty {
		t.isNew = false
		cw, ch := t.Size()
		sx, sy := r.W/cw, r.H/ch
		t.data = t.data[:0]

		r := getDrawRegion(t.btn, sx, sy)
		t.SetLayer(t.layer)
		t.btn.dirty = true
		t.btn.Draw(r, delta)
		t.data = append(t.data, t.btn.data...)

		r = getDrawRegion(t.text, sx, sy)
		t.SetLayer(t.layer)
		t.text.dirty = true
		t.text.Draw(r, delta)
		t.data = append(t.data, t.text.data...)
	}
	render.UIAddBytes(t.data)
}
Example #6
0
File: model.go Project: num5/steven
// Draw draws this to the target region.
func (m *Model) Draw(r Region, delta float64) {
	if m.isNew || m.isDirty() || forceDirty {
		m.isNew = false
		data := m.data[:0]

		for _, v := range m.verts {
			vec := mgl32.Vec3{v.X - 0.5, v.Y - 0.5, v.Z - 0.5}
			vec = m.mat.Mul4x1(vec.Vec4(1)).Vec3().
				Add(mgl32.Vec3{0.5, 0.5, 0.5})
			vX, vY, vZ := vec[0], 1.0-vec[1], vec[2]

			dx := r.X + r.W*float64(vX)
			dy := r.Y + r.H*float64(vY)
			dx /= scaledWidth
			dy /= scaledHeight
			data = appendShort(data, int16(math.Floor((dx*float64(lastWidth))+0.5)))
			data = appendShort(data, int16(math.Floor((dy*float64(lastHeight))+0.5)))
			data = appendShort(data, 256*int16(m.Layer())+int16(256*vZ))
			data = appendShort(data, 0)
			data = appendUnsignedShort(data, v.TX)
			data = appendUnsignedShort(data, v.TY)
			data = appendUnsignedShort(data, v.TW)
			data = appendUnsignedShort(data, v.TH)
			data = appendShort(data, v.TOffsetX)
			data = appendShort(data, v.TOffsetY)
			data = appendShort(data, v.TAtlas)
			data = appendShort(data, 0)
			data = appendUnsignedByte(data, v.R)
			data = appendUnsignedByte(data, v.G)
			data = appendUnsignedByte(data, v.B)
			data = appendUnsignedByte(data, v.A)
		}
		m.data = data
	}
	render.UIAddBytes(m.data)
}