Advertisement
zephyrtronium

Untitled

Mar 16th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.54 KB | None | 0 0
  1. func Blit(x, y, width int, cells []termbox.Cell) {
  2.     tw, th := termbox.Size()
  3.     height := len(cells) / width
  4.     rw, rh := width, height
  5.     offset := 0
  6.     if x > tw || y > th {
  7.         return
  8.     }
  9.     if x+width > tw {
  10.         rw = tw - x
  11.     }
  12.     if x < 0 {
  13.         rw += x
  14.         offset = -x
  15.         if offset > width {
  16.             return
  17.         }
  18.     }
  19.     if y+height > th {
  20.         rh = th - y
  21.     }
  22.     if y < 0 {
  23.         rh += y
  24.         if rh <= 0 {
  25.             return
  26.         }
  27.         y = 0
  28.     }
  29.     bb := termbox.CellBuffer()
  30.     for i := 0; i < rh; i++ {
  31.         copy(bb[(y+i)*tw+x+offset:], cells[i*width+offset:i*width+offset+rw])
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement