Module: Bash_Visual::Painter
- Included in:
- Console
- Defined in:
- lib/bash-visual/painter.rb
Constant Summary collapse
- BORDER_UTF =
["\u250C", "\u2500", "\u2510", "\u2502", "\u2502", "\u2514", "\u2500", "\u2518"]
- BORDER_UTF_ROUND =
["\u256D", "\u2500", "\u256E", "\u2502", "\u2502", "\u2570", "\u2500", "\u256F"]
- BORDER_UTF_DOUBLE =
["\u2554", "\u2550", "\u2557", "\u2551", "\u2551", "\u255A", "\u2550", "\u255D"]
- @@default_window_wrap =
["\u257C ", " \u257E"]
Instance Method Summary collapse
- #draw_border(position, size, params = {}) ⇒ Object
- #draw_filled_rectangle(position, size, color = :white) ⇒ Object
- #draw_window(position, size, text = '', params = {}) ⇒ Object
Instance Method Details
#draw_border(position, size, params = {}) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bash-visual/painter.rb', line 45 def draw_border(position, size, params = {}) x, y = *position width, height = *size raise 'width,height must be great than 1' if (width < 2 or height < 2) border = params[:border] ? params[:border] : BORDER_UTF font = params[:font] ? params[:font] : @font bash = @builder.save_position bash << @builder.set_position(x, y) body_width = width - 2 bash << @builder.write(border[0] + border[1] * body_width + border[2]) row = @builder.move_position(-width, 1) row << @builder.write(border[3] + ' ' * body_width + border[4]) bash << row*(height - 2) bash << @builder.move_position(-width, 1) bash << @builder.write(border[5] + border[6] * body_width + border[7]) bash << @builder.restore_position print @builder.write(bash, font) end |
#draw_filled_rectangle(position, size, color = :white) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/bash-visual/painter.rb', line 24 def draw_filled_rectangle(position, size, color = :white) x, y = *position width, height = *size raise 'width,height must be great than 1' if (width < 1 or height < 1) color = color.background if color.is_a? Font font = Font.new :std, :white, color bash = @builder.save_position bash << @builder.set_position(x+1, y+1) row = @builder.write(' ' * width) row << @builder.move_position(-width, 1) bash << row*height bash << @builder.restore_position print @builder.write(bash, font) end |
#draw_window(position, size, text = '', params = {}) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/bash-visual/painter.rb', line 74 def draw_window(position, size, text = '', params = {}) x, y = *position width, height = *size raise 'width,height must be great than 2' if (width < 3 or height < 3) wrap = params[:wrap].nil? ? @@default_window_wrap : params[:wrap] border = params[:border] ? params[:border] : BORDER_UTF font = params[:font] ? params[:font] : @font body_width = width - 2 text = if wrap wrap_size = wrap[0].size + wrap[1].size text_width = body_width - wrap_size wrap[0] + text.to_s[0, text_width] + wrap[1] else text.to_s.slice(0, body_width) end text = text.center(body_width, border[1]) bash = @builder.save_position bash << @builder.set_position(x, y) bash << @builder.write(border[0] + text + border[2]) row = @builder.move_position(-width, 1) row << @builder.write(border[3] + ' ' * body_width + border[4]) bash << row*(height - 2) bash << @builder.move_position(-width, 1) bash << @builder.write(border[5] + border[6] * body_width + border[7]) bash << @builder.restore_position print @builder.write(bash, font) end |