コード例 #1
0
ファイル: cli_label.go プロジェクト: jteeuwen/dcpu
// Draw draws the label to the given buffer.
func (l *Label) Draw(dst *tulib.Buffer) {
	r := l.rect

	if r.Width < 0 || r.Height < 0 {
		return
	}

	dst.Fill(r, l.proto)
	dst.DrawLabel(r, &l.params, []byte(string(l.text)))
}
コード例 #2
0
ファイル: cli_input.go プロジェクト: jteeuwen/dcpu
// drawCursor draws the cursor.
func (i *Input) drawCursor(dst *tulib.Buffer) {
	if !i.focus {
		return
	}

	r := i.rect

	if r.Width < 0 || r.Height < 0 {
		return
	}

	cs := i.cursorPos
	r.X += len(i.prompt) + cs
	r.Width = 1

	var data []byte
	if cs >= len(i.text) {
		data = []byte{' '}
	} else {
		data = []byte(string(i.text[cs : cs+1]))
	}

	dst.DrawLabel(r, &i.cursorParams, data)
}
コード例 #3
0
ファイル: cli_textbox.go プロジェクト: jteeuwen/dcpu
// Draw draws the Textbox to the given buffer.
func (t *Textbox) Draw(dst *tulib.Buffer) {
	r := t.rect
	if r.Width < 0 || r.Height < 0 {
		return
	}

	// Draw title bar.
	r.Height = 1
	dst.Fill(r, t.titleProto)
	dst.DrawLabel(r, &t.titleParams, []byte(t.title))

	r = t.rect
	if r.Height < 1 {
		return
	}

	r.Y++
	r.Height--

	// Text background.
	dst.Fill(r, t.textProto)

	// Text lines.
	lines := t.lines
	if len(lines) > r.Height {
		lines = lines[len(lines)-r.Height:]
	}

	max := r.Y + r.Height
	r.Height = 1

	for _, line := range lines {
		wrapped := linewrap.SingleLine(line, r.Width, 0, 0, linewrap.Left)

		for _, w := range wrapped {
			dst.DrawLabel(r, &t.textParams, []byte(w))
			r.Y++

			if r.Y > max {
				return
			}
		}
	}
}
コード例 #4
0
ファイル: cli_input.go プロジェクト: jteeuwen/dcpu
// Draw draws the Input to the given buffer.
func (i *Input) Draw(dst *tulib.Buffer) {
	r := i.rect

	if r.Width < 0 || r.Height < 0 {
		return
	}

	dst.Fill(r, i.proto)
	dst.DrawLabel(r, &i.promptParams, i.prompt)

	r.X += len(i.prompt)
	r.Width -= r.X

	dst.DrawLabel(r, &i.textParams, []byte(string(i.text)))
	i.drawCursor(dst)
}
コード例 #5
0
ファイル: autocomplete.go プロジェクト: magenbluten/godit
func (ac *autocompl) draw_onto(buf *tulib.Buffer, x, y int) {
	ac.validate_cursor()

	h := ac.desired_height()
	dst := find_place_for_rect(buf.Rect, tulib.Rect{x, y + 1, 1, h})
	ac.adjust_view(dst.Height)
	w := ac.desired_width(dst.Height)
	dst = find_place_for_rect(buf.Rect, tulib.Rect{x, y + 1, w, h})

	slider_i, slider_r := ac.slider_pos_and_rune(dst.Height)
	lp := default_label_params

	r := dst
	r.Width--
	r.Height = 1
	for i := 0; i < dst.Height; i++ {
		lp.Fg = termbox.ColorBlack
		lp.Bg = termbox.ColorWhite

		n := ac.view + i
		if n == ac.cursor {
			lp.Fg = termbox.ColorWhite
			lp.Bg = termbox.ColorBlue
		}
		buf.Fill(r, termbox.Cell{
			Fg: lp.Fg,
			Bg: lp.Bg,
			Ch: ' ',
		})
		buf.DrawLabel(r, &lp, ac.actual_proposals()[n].display)

		sr := ' '
		if i == slider_i {
			sr = slider_r
		}
		buf.Set(r.X+r.Width, r.Y, termbox.Cell{
			Fg: termbox.ColorWhite,
			Bg: termbox.ColorBlue,
			Ch: sr,
		})
		r.Y++
	}
}
コード例 #6
0
ファイル: tuikit.go プロジェクト: sgeb/go-tuikit
func clearRect(buffer *tulib.Buffer, rect Rect) {
	buffer.Fill(rect.TulibRect(), termbox.Cell{Ch: ' '})
}
コード例 #7
0
ファイル: text_view.go プロジェクト: sgeb/go-tuikit
func (v *TextView) PaintTo(buffer *tulib.Buffer, rect Rect) error {
	clearRect(buffer, rect)
	buffer.DrawLabel(rect.TulibRect(), v.params, v.text)
	return nil
}
コード例 #8
0
ファイル: filler_view.go プロジェクト: sgeb/go-tuikit
func (v *FillerView) PaintTo(buffer *tulib.Buffer, rect Rect) error {
	buffer.Fill(rect.TulibRect(), v.proto)
	return nil
}
コード例 #9
0
ファイル: gameobject.go プロジェクト: stephenbalaban/goland
func (gob *GameObject) Draw(buf *tulib.Buffer, pos image.Point) {
	buf.Set(pos.X, pos.Y, gob.Glyph)
}
コード例 #10
0
ファイル: map.go プロジェクト: stephenbalaban/goland
func (t *Terrain) Draw(b *tulib.Buffer, pt image.Point) {
	b.Set(pt.X, pt.Y, t.Glyph)
}