1 | // Copyright (C) 2015-2015 ChaosForge Ltd
|
---|
2 | // http://chaosforge.org/
|
---|
3 | //
|
---|
4 | // This file is part of Nova libraries.
|
---|
5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
6 |
|
---|
7 | #include "nv/core/ascii_printer.hh"
|
---|
8 |
|
---|
9 | using namespace nv;
|
---|
10 |
|
---|
11 | ascii_printer::ascii_printer( terminal * term )
|
---|
12 | : m_terminal( term )
|
---|
13 | {
|
---|
14 |
|
---|
15 | }
|
---|
16 |
|
---|
17 | void ascii_printer::print( const string_view& text, const position& p, uint32 color )
|
---|
18 | {
|
---|
19 | position coord( p );
|
---|
20 | for ( char c : text )
|
---|
21 | {
|
---|
22 | m_terminal->print( coord, color, c );
|
---|
23 | ++coord.x;
|
---|
24 | if ( coord.x >= m_terminal->get_size().x ) break;
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | void nv::ascii_printer::frame( const nv::rectangle& area, const nv::string_view& border_chars, uint32 color )
|
---|
29 | {
|
---|
30 | if ( border_chars.length() < 8 )
|
---|
31 | {
|
---|
32 | m_terminal->clear( area );
|
---|
33 | return;
|
---|
34 | }
|
---|
35 | m_terminal->clear( area.shrinked( 1 ) );
|
---|
36 | for ( int x = 0; x < area.get_width(); ++x )
|
---|
37 | {
|
---|
38 | m_terminal->print( position( area.ul.x + x, area.ul.y ), color, border_chars[0] );
|
---|
39 | m_terminal->print( position( area.ul.x + x, area.lr.y ), color, border_chars[1] );
|
---|
40 | }
|
---|
41 |
|
---|
42 | for ( int y = 0; y < area.get_height(); ++y )
|
---|
43 | {
|
---|
44 | m_terminal->print( position( area.ul.x, area.ul.y + y ), color, border_chars[2] );
|
---|
45 | m_terminal->print( position( area.lr.x, area.ul.y + y ), color, border_chars[3] );
|
---|
46 | }
|
---|
47 |
|
---|
48 | m_terminal->print( area.ul, color, border_chars[4] );
|
---|
49 | m_terminal->print( area.ur(), color, border_chars[5] );
|
---|
50 | m_terminal->print( area.ll(), color, border_chars[6] );
|
---|
51 | m_terminal->print( area.lr, color, border_chars[7] );
|
---|
52 | }
|
---|