module BBS::FrameBuffer::Drawing
The drawing helpers of a FrameBuffer, all in 1-based coordinates: filled rectangles, lines, frames with a title, drop shadows.
Public Instance Methods
# File lib/bbs/frame_buffer/drawing.rb, line 39 def box(x:, y:, width:, height:, sgr: nil, fill_sgr: nil, style: :single, title: nil, title_sgr: nil, title_indent: 0) return if width < 2 || height < 2 edge = Edge.new(x, width, BOX_CHARS[style] || BOX_CHARS[:single], sgr) top_edge(edge, y, title.to_s, title_sgr || sgr, [title_indent, 0].max) (1...(height - 1)).each { |r| box_side(edge, y + r, fill_sgr) } edge_row(edge, y + height - 1, :bl, :br) end
Draws a frame of width by height cells with its top left at x, y. Does nothing when either side is under 2.
- sgr
-
style of the frame
- fill_sgr
-
when given, the inside is cleared with spaces in this style
- style
-
a BOX_CHARS key; an unknown one draws
:single - title
-
text set into the top edge, clipped to fit
- title_sgr
-
style of the title (defaults to
sgr) - title_indent
-
edge characters drawn before the title
# File lib/bbs/frame_buffer/drawing.rb, line 10 def fill(x:, y:, width:, height:, sgr: nil, char: ' ') height.times { |r| hline(x: x, y: y + r, length: width, char: char, sgr: sgr) } end
Fills the rectangle at x, y of width by height cells with char in style sgr.
# File lib/bbs/frame_buffer/drawing.rb, line 16 def hline(x:, y:, length:, char: '─', sgr: nil) move(x, y) write(char * [length, 0].max, sgr: sgr) end
Draws a horizontal line of length char characters from x, y in style sgr.
# File lib/bbs/frame_buffer/drawing.rb, line 52 def shadow(x:, y:, width:, height:, sgr: nil) sgr ||= Ansi::BG_BLACK height.times { |r| hline(x: x + width, y: y + 1 + r, length: 2, char: ' ', sgr: sgr) } if x + width < @cols hline(x: x + 2, y: y + height, length: width, char: ' ', sgr: sgr) if y + height <= @rows end
Draws the drop shadow of a width by height rectangle at x, y: two columns down its right side and one row under it, offset by one row and two columns, in style sgr (black background by default).
# File lib/bbs/frame_buffer/drawing.rb, line 23 def vline(x:, y:, length:, char: '│', sgr: nil) length.times do |r| move(x, y + r) write(char, sgr: sgr) end end
Draws a vertical line of length char characters down from x, y in style sgr.