Esempio n. 1
0
// Symbol returns the character and its attributes by its coordinates
func Symbol(x, y int) (term.Cell, bool) {
	if x >= 0 && x < canvas.width && y >= 0 && y < canvas.height {
		cells := term.CellBuffer()
		return cells[y*canvas.width+x], true
	}
	return term.Cell{Ch: ' '}, false
}
Esempio n. 2
0
func (panel *Unbuffered) At(x, y int) termbox.Cell {
	if !panel.contains(x, y) {
		return termbox.Cell{}
	}
	width, _ := termbox.Size()
	return termbox.CellBuffer()[(panel.r.Min.Y+y)*width+(panel.r.Min.X+x)]
}
Esempio n. 3
0
// Returns buffered struct of the main screen.
// NOTE: Resize creates new buffer?
func MainScreen() *Buffered {
	width, height := termbox.Size()
	return &Buffered{
		Unbuffered: Unbuffered{r: image.Rect(0, 0, width, height)},
		buffer:     termbox.CellBuffer(),
	}
}
Esempio n. 4
0
func (t *TermBox) GetCell(x, y int) *termbox.Cell {
	w, h := termbox.Size()
	idx := y*w + x
	if idx > w*h {
		return nil
	}
	return &termbox.CellBuffer()[idx]
}
Esempio n. 5
0
func (tb termbox) Read(x, y int) (ch rune, fg, bg Color) {
	cells := T.CellBuffer()
	w, h := T.Size()
	index := x + (y * w)
	if index < 0 || index >= w*h {
		return ' ', ColorBlack, ColorBlack
	}
	cell := cells[index]
	return cell.Ch, termbox_to_color(cell.Fg), termbox_to_color(cell.Bg)
}
Esempio n. 6
0
func (scr *Screen) Blit(x, y int) {
	termWidth, _ := tb.Size()
	startOffset := (y * termWidth) + x
	cells := tb.CellBuffer()

	for i := 0; i < scr.height; i++ {
		tbRangeStart := startOffset + (i * termWidth)
		tbRangeEnd := tbRangeStart + scr.width
		scrRangeStart := i * scr.width
		scrRangeEnd := scrRangeStart + scr.width

		copy(cells[tbRangeStart:tbRangeEnd], scr.buffer[scrRangeStart:scrRangeEnd])
	}
}
Esempio n. 7
0
func calibratePoint(et gaze.EyeTracker, x, y float64) {
	termbox.Clear(0, 0)
	sizeX, sizeY := termbox.Size()
	dx, dy := int(float64(sizeX)*x), int(float64(sizeY)*y)
	termbox.CellBuffer()[sizeX*dy+dx] = termbox.Cell{'#', marker, termbox.ColorDefault}
	termbox.Flush()
	//log.Printf("Termbox Size: (%d, %d)", sizeX, sizeY)
	log.Printf("Calibrating (%.3f, %.3f)", x, y)
	done := make(chan struct{})
	time.Sleep(1 * time.Second) //Minimum time. Gives user time to react.
	et.AddPointToCalibration(gaze.NewPoint2D(x, y), func(err error) {
		close(done) //Synchronizing async call.
	})
	<-done
}
Esempio n. 8
0
func drawPoint(point gaze.Point2D, attributes termbox.Attribute) {
	sizeX, sizeY := termbox.Size()
	x, y := int(float64(sizeX)*point.X()), int(float64(sizeY)*point.Y())
	switch {
	case x < 0:
		x = 0
	case x >= sizeX:
		x = sizeX - 1
	}

	switch {
	case y < 0:
		y = 0
	case y >= sizeY:
		y = sizeY - 1
	}
	termbox.CellBuffer()[sizeX*y+x] = termbox.Cell{'O', attributes, termbox.ColorWhite}
}