source: trunk/src/core/ascii_printer.cc @ 506

Last change on this file since 506 was 487, checked in by epyon, 9 years ago
File size: 1.5 KB
Line 
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
9using namespace nv;
10
11ascii_printer::ascii_printer( terminal * term )
12        : m_terminal( term )
13{
14       
15}
16
17void 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
28void 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}
Note: See TracBrowser for help on using the repository browser.