本文整理匯總了Golang中github.com/nsf/termbox-go.SetCell函數的典型用法代碼示例。如果您正苦於以下問題:Golang SetCell函數的具體用法?Golang SetCell怎麽用?Golang SetCell使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了SetCell函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: draw
func draw() bool {
termbox.Clear(termbox.ColorDefault, termbox.ColorDefault)
dots := NewCellsBox([]termbox.Cell{dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
dot, dot, dot, dot, dot,
}, 5)
greenPlus := NewCellsBox([]termbox.Cell{greenPlus, greenPlus, greenPlus, greenPlus}, 2)
if err := greenPlus.DrawInto(dots, 1, 2); err != nil {
termbox.Close()
fmt.Fprintf(os.Stderr, "%v1\r\n", err)
return false
}
if err := dots.DrawInto(&TermBox{}, 0, 0); err != nil {
termbox.Close()
fmt.Fprintf(os.Stderr, "%v2\r\n", err)
return false
}
termbox.SetCell(0, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.SetCell(1, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.SetCell(7, 0, '+', termbox.ColorRed, termbox.ColorDefault)
termbox.Flush()
return true
}
示例2: highlightPos
func (b *board) highlightPos(x, y int) {
if !b.in(x, y) {
return
}
b.curPosVert = !b.curPosVert
fg := fgcolor | termbox.AttrBold
bg := bgcolor | termbox.AttrBold
defch := '·'
var xch, ych rune
if b.curPosVert {
xch = defch
ych = '⇣'
} else {
xch = '⇢'
ych = defch
}
// draw position indicators
for i := b.x; i < x; i += 2 {
termbox.SetCell(i, y, xch, fg, bg)
}
for i := b.y; i <= y; i++ {
if (x-b.x)%2 == 1 {
termbox.SetCell(x-1, i, ych, fg, bg)
} else {
termbox.SetCell(x, i, ych, fg, bg)
}
}
termbox.Flush()
}
示例3: draw_piece
func draw_piece(well *Well, operation string, this_piece *Tetronimo) {
well_depth := len(well.debris_map)
term_col, term_row := tb.Size()
vert_headroom := int((term_row-well_depth)/2) - 1
well_bottom := len(well.debris_map) + vert_headroom
well_left := ((term_col / 2) - len(well.debris_map[0]))
for t_vert := range this_piece.shape {
for t_horz := range this_piece.shape[t_vert] {
if this_piece.shape[t_vert][t_horz] > 0 {
color := tb.ColorDefault
if operation == "draw" {
color = set_color(this_piece.shape[t_vert][t_horz])
}
height := (well_bottom - this_piece.height + t_vert)
longitude := (well_left + (this_piece.longitude * 2) + (t_horz * 2))
tb.SetCell(longitude, height, 0, 0, color)
tb.SetCell(longitude+1, height, 0, 0, color)
}
}
}
}
示例4: drawSections
func drawSections() {
if term.dm.Curr == nil || len(term.dm.Curr.Sections) == 0 {
return
}
st := term.ofs.trk
en := st + len(term.dm.Curr.Sections) + 3
drawBottomCorners(en)
drawHLines(en)
drawVLines(vLine{0, st, en}, vLine{79, st, en}, vLine{28, st, en})
// pattern tempo
if term.mode == tempoMode {
msg := fmt.Sprintf("tracks, bpm = %v", term.input.String())
tbPrintDef(2, st, msg)
tbPrint(16+len(msg), st, tb.ColorBlack, tb.ColorYellow, " ")
} else {
msg := fmt.Sprintf("tracks, bpm = %v", term.dm.Curr.Tempo)
tbPrintDef(2, st, msg)
}
// beat numbers
for i := 0; i < 16; i++ {
if term.beat == i {
tbPrintf(i*3+30, st, tb.ColorBlue, tb.ColorBlack, "%2d", i+1)
} else {
tbPrintf(i*3+30, st, tb.ColorWhite, tb.ColorBlack, "%2d", i+1)
}
}
// sequence sections
for i, sec := range term.dm.Curr.Sections {
tbPrintf(2, st+2+i, tb.ColorWhite, tb.ColorBlack, "%4d", sec.ID)
if sec.Enabled {
tbPrintf(8, st+2+i, tb.ColorGreen, tb.ColorBlack, "%18s", sec.Name)
} else {
tbPrintf(8, st+2+i, tb.ColorWhite, tb.ColorBlack, "%18s", sec.Name)
}
if term.cur.sec == 1 && term.cur.row == i {
tbPrint(27, st+2+i, tb.ColorWhite, tb.ColorBlack, "*")
}
for j, beat := range sec.Beats {
conb := term.cur.sec == 1 && term.cur.row == i && term.cur.col == j
if beat && conb {
tb.SetCell(j*3+31, st+2+i, 'x', tb.ColorMagenta, tb.ColorYellow)
} else if beat && j == term.beat {
tb.SetCell(j*3+31, st+2+i, 'x', tb.ColorBlue, tb.ColorBlack)
} else if beat {
setCellDefaultColor(j*3+31, st+2+i, 'x')
} else if conb {
tb.SetCell(j*3+31, st+2+i, ' ', tb.ColorDefault, tb.ColorGreen)
}
}
}
}
示例5: DrawBorder
// Draws borders _outside_ the
func DrawBorder(p BorderedPanel) {
r := p.Bounds()
b := p.Border()
var border []rune
switch b.Ch {
case 's', 'S':
border = singleBorder
case 'd', 'D':
border = doubleBorder
default:
border = []rune{b.Ch, b.Ch, b.Ch, b.Ch, b.Ch, b.Ch}
}
termbox.SetCell(r.Min.X-1, r.Min.Y-1, borderClash(r.Min.X-1, r.Min.Y-1, border[4], 3), b.Fg, b.Bg)
termbox.SetCell(r.Max.X, r.Min.Y-1, borderClash(r.Max.X, r.Min.Y-1, border[5], 6), b.Fg, b.Bg)
termbox.SetCell(r.Min.X-1, r.Max.Y, borderClash(r.Min.X-1, r.Max.Y, border[3], 9), b.Fg, b.Bg)
termbox.SetCell(r.Max.X, r.Max.Y, borderClash(r.Max.X, r.Max.Y, border[2], 12), b.Fg, b.Bg)
for x := r.Min.X; x < r.Min.X+r.Dx(); x++ {
termbox.SetCell(x, r.Min.Y-1, borderClash(x, r.Min.Y-1, border[0], 2), b.Fg, b.Bg)
termbox.SetCell(x, r.Min.Y+r.Dy(), borderClash(x, r.Min.Y+r.Dy(), border[0], 8), b.Fg, b.Bg)
}
for y := r.Min.Y; y < r.Min.Y+r.Dy(); y++ {
termbox.SetCell(r.Min.X-1, y, borderClash(r.Min.X-1, y, border[1], 1), b.Fg, b.Bg)
termbox.SetCell(r.Min.X+r.Dx(), y, borderClash(r.Min.X+r.Dx(), y, border[1], 4), b.Fg, b.Bg)
}
}
示例6: Init
func (m *Mainboard) Init(xStart int, yStart int, width int, height int) {
m.xStart = xStart
m.yStart = yStart
m.width = width
m.height = height
var x int = xStart + 1
var y int = yStart + 1
// Draw Top
tm.SetCell(xStart, yStart, '+', tm.ColorDefault, tm.ColorDefault)
for x < xStart+width {
tm.SetCell(x, yStart, '-', tm.ColorDefault, tm.ColorDefault)
x++
}
tm.SetCell(x, yStart, '+', tm.ColorDefault, tm.ColorDefault)
// Draw Sides
for y < yStart+height {
tm.SetCell(xStart, y, '|', tm.ColorDefault, tm.ColorDefault)
tm.SetCell(xStart+width, y, '|', tm.ColorDefault, tm.ColorDefault)
y++
}
// Draw Bottom
x = xStart + 1
tm.SetCell(xStart, y, '+', tm.ColorDefault, tm.ColorDefault)
for x < xStart+width {
tm.SetCell(x, y, '-', tm.ColorDefault, tm.ColorDefault)
x++
}
tm.SetCell(x, y, '+', tm.ColorDefault, tm.ColorDefault)
}
示例7: drawRectWithAttr
// drawRectWithAttr draws a rectangle with unicode borders at position (x,y) with area of
// w*h with the given foreground and background attributes. Attributes can be
// colors and/or styling.
func drawRectWithAttr(x, y, w, h int, fgattr, bgattr termbox.Attribute) {
// top border
termbox.SetCell(x-1, y-1, '┌', fgattr, bgattr)
fill(x, y-1, w, 1, '─')
termbox.SetCell(x+w, y-1, '┐', fgattr, bgattr)
// body border
fill(x-1, y, 1, h, '│')
fill(x+w, y, 1, h, '│')
// bottom border
termbox.SetCell(x-1, y+h, '└', fgcolor, bgcolor)
fill(x, y+h, w, 1, '─')
termbox.SetCell(x+w, y+h, '┘', fgcolor, bgcolor)
}
示例8: Repaint
func (w *Window) Repaint() error {
w.Lock()
err := termbox.Clear(w.Fg, w.Bg)
width, height := termbox.Size()
if err != nil {
return err
}
for _, row := range w.Widgets[w.scrollPos:] {
j := 0
for _, c := range row.Text {
termbox.SetCell(w.x, w.y, rune(c), row.Fg[j], row.Bg[j])
j++
if w.x += 1; w.x > width {
break
}
}
w.x = 0
if w.y += 1; w.y > height {
break
}
}
w.y = 0
w.x = 0
w.Unlock()
return nil
}
示例9: print_tb
func print_tb(x, y int, fg, bg tb.Attribute, msg string) {
for _, c := range msg {
tb.SetCell(x, y, c, fg, bg)
x++
}
tb.Flush()
}
示例10: Clear
func (a *area) Clear() {
for i := 0; i < a.w; i++ {
for j := 0; j < a.h; j++ {
termbox.SetCell(a.x+i, a.y+j, ' ', a.fgColor, a.bgColor)
}
}
}
示例11: fillInBox
func fillInBox(xStart, xMax, yStart, yMax int, fg, bg tb.Attribute) {
for i := xStart; i <= xMax; i++ {
for j := yStart; j <= yMax; j++ {
tb.SetCell(i, j, ' ', fg, bg)
}
}
}
示例12: main
func main() {
err := tb.Init()
if err != nil {
panic(err)
}
defer tb.Close()
tb.SetInputMode(tb.InputEsc)
tb.Clear(tb.ColorCyan, tb.ColorBlue)
tb.Flush()
loop:
for i := 0; ; i++ {
ev := tb.PollEvent()
switch ev.Type {
case tb.EventKey:
if ev.Key == tb.KeyCtrlC {
break loop
}
tb.SetCell(i, i, ev.Ch, tb.ColorGreen, tb.ColorBlack)
tb.Flush()
case tb.EventError:
panic(ev.Err)
}
}
}
示例13: fill
// fill draws a rectangle at position (x,y) with area of w*h and fills the
// inside with r.
func fill(x, y, w, h int, r rune) {
for ly := 0; ly < h; ly++ {
for lx := 0; lx < w; lx++ {
termbox.SetCell(x+lx, y+ly, r, fgcolor, bgcolor)
}
}
}
示例14: tbprint
func tbprint(origin coord, msg string, fg, bg termbox.Attribute) coord {
for _, r := range msg {
termbox.SetCell(origin.x, origin.y, r, fg, bg)
origin = origin.right(1)
}
return origin
}
示例15: buildInnerField
func buildInnerField(f field, origin coord) {
var symbol rune
fg := termbox.ColorWhite
bg := termbox.ColorBlack
for y := 0; y < f.dimensions.y; y++ {
for x := 0; x < f.dimensions.x; x++ {
theoretical := coord{x, y}
statusHere := f.statusAt(theoretical)
switch statusHere {
case unknown:
symbol = ' '
case empty:
symbol = '~'
fg = termbox.ColorCyan
case miss:
symbol = '~'
fg = termbox.ColorGreen
case hit:
symbol = '▓'
fg = termbox.ColorRed
case occupied:
symbol = '█'
}
actual := theoretical.viewPos(origin)
termbox.SetCell(actual.x, actual.y, symbol, fg, bg)
}
}
}