Esempio n. 1
0
func (l *Label) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	tw := float64(l.tbuf.Bounds().Max.X - l.tbuf.Bounds().Min.X)
	th := float64(l.tbuf.Bounds().Max.Y - l.tbuf.Bounds().Min.Y)
	gc.Translate((l.Size.X-tw)/2, (l.Size.Y-th)/2)
	gc.DrawImage(l.tbuf)
}
Esempio n. 2
0
func (e *Entry) draw(gc draw2d.GraphicContext) {
	if e.textOffset+e.runeOffsets[e.cursor] < 5 {
		e.textOffset = 5 - e.runeOffsets[e.cursor]
	}
	if e.textOffset+e.runeOffsets[e.cursor] > e.Size.X-5 {
		e.textOffset = e.Size.X - 5 - e.runeOffsets[e.cursor]
	}

	gc.Clear()
	if e.HasKeyFocus {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
		safeRect(gc, geom.Coord{0, 0}, e.Size)
		gc.Fill()
	}
	th := float64(e.textBuffer.Bounds().Max.Y - e.textBuffer.Bounds().Min.Y)
	gc.Save()
	gc.Translate(e.textOffset, 0)

	if e.selecting {
		start := e.runeOffsets[e.cursor]
		end := e.runeOffsets[e.selectCursor]
		if start > end {
			start, end = end, start
		}
		gc.SetFillColor(color.RGBA{200, 200, 200, 255})
		safeRect(gc, geom.Coord{start, 0}, geom.Coord{end, e.Size.Y})
		gc.Fill()
	}

	gc.Translate(0, (e.Size.Y-th)/2)

	gc.DrawImage(e.textBuffer)
	gc.Restore()
	if e.HasKeyFocus {
		un := time.Duration(time.Now().UnixNano())
		ms := un / time.Millisecond
		ms = ms % 750
		var intensity uint8 = 255
		if ms > 550 {
			diff := 650 - ms
			if diff < 0 {
				diff *= -1
			}
			intensity = uint8((diff * 255) / 200)
		}
		offset := float64(int(e.runeOffsets[e.cursor] + e.textOffset))
		gc.SetStrokeColor(color.RGBA{A: intensity})
		gc.MoveTo(offset, 0)
		gc.LineTo(offset, e.Size.Y)
		gc.Stroke()
		e.Invalidate(geom.Rect{
			Min: geom.Coord{offset - 1, 0},
			Max: geom.Coord{offset + 1, e.Size.Y},
		})
	}
}
Esempio n. 3
0
func (l *Label) draw(gc draw2d.GraphicContext) {
	// uik.Report(l.ID, "Label.draw()")
	//gc.Clear()
	// gc.SetFillColor(color.RGBA{A: 1})
	// safeRect(gc, geom.Coord{0, 0}, l.Size)
	// gc.Fill()
	tw := float64(l.tbuf.Bounds().Max.X - l.tbuf.Bounds().Min.X)
	th := float64(l.tbuf.Bounds().Max.Y - l.tbuf.Bounds().Min.Y)
	gc.Translate((l.Size.X-tw)/2, (l.Size.Y-th)/2)
	gc.DrawImage(l.tbuf)
}
Esempio n. 4
0
func (i *Image) draw(gc draw2d.GraphicContext) {
	ib := i.config.Image.Bounds()
	s := ib.Size()
	w := float64(s.X)
	h := float64(s.Y)
	sx := i.Size.X / w
	sy := i.Size.Y / h
	// uik.Report(i.Size, sx, sy)
	gc.Scale(sx, sy)
	gc.DrawImage(i.config.Image)
}
Esempio n. 5
0
func (l *KeyGrab) draw(gc draw2d.GraphicContext) {
	gc.Clear()
	if l.HasKeyFocus {
		gc.SetFillColor(color.RGBA{150, 150, 150, 255})
		safeRect(gc, geom.Coord{0, 0}, l.Size)
		gc.FillStroke()
	}
	tw := float64(l.kbuf.Bounds().Max.X - l.kbuf.Bounds().Min.X)
	th := float64(l.kbuf.Bounds().Max.Y - l.kbuf.Bounds().Min.Y)
	gc.Translate((l.Size.X-tw)/2, (l.Size.Y-th)/2)
	gc.DrawImage(l.kbuf)
}