[486] | 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 |
|
---|
[514] | 17 | void ascii_printer::print( const string_view& text, const position& p, term_color color )
|
---|
[486] | 18 | {
|
---|
| 19 | position coord( p );
|
---|
| 20 | for ( char c : text )
|
---|
| 21 | {
|
---|
[514] | 22 | m_terminal->print( coord, color, term_color(), c );
|
---|
[486] | 23 | ++coord.x;
|
---|
| 24 | if ( coord.x >= m_terminal->get_size().x ) break;
|
---|
| 25 | }
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[514] | 28 | void nv::ascii_printer::frame( const nv::rectangle& area, const nv::string_view& border_chars, term_color color )
|
---|
[486] | 29 | {
|
---|
| 30 | if ( border_chars.length() < 8 )
|
---|
| 31 | {
|
---|
[514] | 32 | m_terminal->clear( area, color, term_color() );
|
---|
[486] | 33 | return;
|
---|
| 34 | }
|
---|
[514] | 35 | m_terminal->clear( area.shrinked( 1 ), color, term_color() );
|
---|
[486] | 36 | for ( int x = 0; x < area.get_width(); ++x )
|
---|
| 37 | {
|
---|
[514] | 38 | m_terminal->print( position( area.ul.x + x, area.ul.y ), color, term_color(), border_chars[0] );
|
---|
| 39 | m_terminal->print( position( area.ul.x + x, area.lr.y ), color, term_color(), border_chars[1] );
|
---|
[486] | 40 | }
|
---|
| 41 |
|
---|
| 42 | for ( int y = 0; y < area.get_height(); ++y )
|
---|
| 43 | {
|
---|
[514] | 44 | m_terminal->print( position( area.ul.x, area.ul.y + y ), color, term_color(), border_chars[2] );
|
---|
| 45 | m_terminal->print( position( area.lr.x, area.ul.y + y ), color, term_color(), border_chars[3] );
|
---|
[486] | 46 | }
|
---|
| 47 |
|
---|
[514] | 48 | m_terminal->print( area.ul, color, term_color(), border_chars[4] );
|
---|
| 49 | m_terminal->print( area.ur(), color, term_color(), border_chars[5] );
|
---|
| 50 | m_terminal->print( area.ll(), color, term_color(), border_chars[6] );
|
---|
| 51 | m_terminal->print( area.lr, color, term_color(), border_chars[7] );
|
---|
[486] | 52 | }
|
---|