Changeset 514


Ignore:
Timestamp:
08/08/16 18:25:48 (9 years ago)
Author:
epyon
Message:
  • term_color implementation
  • support for background color
  • support for RGBA encoding
  • initial gfx_terminal implementation
Location:
trunk
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/nv/core/ascii_printer.hh

    r487 r514  
    2626                explicit ascii_printer( terminal * term );
    2727
    28                 void print( char ch, const position& p, uint32 color )
     28                void print( char ch, const position& p, term_color color )
    2929                {
    30                         m_terminal->print( p, color, ch );
     30                        m_terminal->print( p, color, term_color(), ch );
    3131                }
    32                 void print( const string_view& text, const position& p, uint32 color );
    33 //              void print( const string_view& text, const position& p, uint32 color, const rectangle& scissor );
    34                 void frame( const nv::rectangle& area, const nv::string_view& border_chars, uint32 color );
     32                void print( const string_view& text, const position& p, term_color color );
     33//              void print( const string_view& text, const position& p, term_color color, const rectangle& scissor );
     34                void frame( const nv::rectangle& area, const nv::string_view& border_chars, term_color color );
    3535
    3636        protected:
  • trunk/nv/curses/curses_terminal.hh

    r487 r514  
    3535         * Print a character of the given color to the screen memory
    3636         */
    37         virtual void print( position p, uint32 color, char ch );
     37        virtual void print( position p, term_color fgcolor, term_color bgcolor, char ch );
    3838
    3939        /**
    4040                 * Clear screen memory
    4141         */
    42         virtual void clear( rectangle r );
     42        virtual void clear( rectangle r, term_color fgcolor, term_color bgcolor );
    4343
    4444        /**
  • trunk/nv/interface/terminal.hh

    r487 r514  
    1717#include <nv/core/position.hh>
    1818#include <nv/core/io_event.hh>
     19#include <nv/core/term_color.hh>
    1920
    2021namespace nv
    2122{
     23
     24
    2225        class terminal
    2326        {
     
    3639         * Print a character of the given color to the screen memory
    3740         */
    38         virtual void print( position p, uint32 color, char ch ) = 0;
     41        virtual void print( position p, term_color fgcolor, term_color bgcolor, char ch ) = 0;
    3942
    4043        /**
    4144                 * Clear screen memory
    4245         */
    43         virtual void clear( rectangle r ) = 0;
     46        virtual void clear( rectangle r, term_color fgcolor, term_color bgcolor ) = 0;
    4447
    4548        /**
  • trunk/nv/interface/uniform.hh

    r501 r514  
    308308                case FLOAT          : return new uniform< enum_to_type< FLOAT          >::type >( location, length );
    309309                case INT            : return new uniform< enum_to_type< INT            >::type >( location, length );
     310                case UINT           : return new uniform< enum_to_type< UINT           >::type >( location, length );
    310311                case FLOAT_VECTOR_2 : return new uniform< enum_to_type< FLOAT_VECTOR_2 >::type >( location, length );
    311312                case FLOAT_VECTOR_3 : return new uniform< enum_to_type< FLOAT_VECTOR_3 >::type >( location, length );
  • trunk/src/core/ascii_printer.cc

    r487 r514  
    1515}
    1616
    17 void ascii_printer::print( const string_view& text, const position& p, uint32 color )
     17void ascii_printer::print( const string_view& text, const position& p, term_color color )
    1818{
    1919        position coord( p );
    2020        for ( char c : text )
    2121        {
    22                 m_terminal->print( coord, color, c );
     22                m_terminal->print( coord, color, term_color(), c );
    2323                ++coord.x;
    2424                if ( coord.x >= m_terminal->get_size().x ) break;
     
    2626}
    2727
    28 void nv::ascii_printer::frame( const nv::rectangle& area, const nv::string_view& border_chars, uint32 color )
     28void nv::ascii_printer::frame( const nv::rectangle& area, const nv::string_view& border_chars, term_color color )
    2929{
    3030        if ( border_chars.length() < 8 )
    3131        {
    32                 m_terminal->clear( area );
     32                m_terminal->clear( area, color, term_color() );
    3333                return;
    3434        }
    35         m_terminal->clear( area.shrinked( 1 ) );
     35        m_terminal->clear( area.shrinked( 1 ), color, term_color() );
    3636        for ( int x = 0; x < area.get_width(); ++x )
    3737        {
    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] );
     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] );
    4040        }
    4141
    4242        for ( int y = 0; y < area.get_height(); ++y )
    4343        {
    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] );
     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] );
    4646        }
    4747
    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] );
     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] );
    5252}
  • trunk/src/curses/curses_terminal.cc

    r487 r514  
    2828        PDC_save_key_modifiers( true );
    2929
    30         init_pair( 1, 0, 0 );
    31         init_pair( 2, 1, 0 );
    32         init_pair( 3, 2, 0 );
    33         init_pair( 4, 3, 0 );
    34         init_pair( 5, 4, 0 );
    35         init_pair( 6, 5, 0 );
    36         init_pair( 7, 6, 0 );
    37         init_pair( 8, 7, 0 );
     30        for ( short i = 0; i < 64; ++i )
     31                init_pair( i+1, i % 8, i / 8 );
    3832
    3933        clear();
     
    5347}
    5448
    55 void curses_terminal::print( position p, uint32 color, char ch )
     49void curses_terminal::print( position p, term_color fgcolor, term_color bgcolor, char ch )
    5650{
     51        uint32 fcolor = fgcolor.get_color();
     52        uint32 bcolor = ( bgcolor.get_color() % 8 ) * 8;
    5753        m_update_needed = true;
    58         if ( color > 7 )
    59         {
    60                 attrset(((static_cast<uint32>(color-7) << 24)  & 0xff000000ul ) | 0x00800000ul);
    61         }
    62         else
    63         {
    64                 attrset((static_cast<uint32>(color+1) << 24)  & 0xff000000ul);
    65         }
     54        chtype attr = static_cast<chtype>( ( fcolor > 7 ? fcolor - 7 + bcolor : fcolor + bcolor + 1 ) << 24 );
     55        if ( fcolor > 7 ) attr = attr | 0x00800000ul;
     56        attrset(attr);
    6657        mvaddch( p.y-1, p.x-1, chtype(ch) );
    6758        ::move( m_cursor.y-1, m_cursor.x-1 );
    6859}
    6960
    70 void curses_terminal::clear( rectangle r )
     61void curses_terminal::clear( rectangle r, term_color fgcolor, term_color bgcolor )
    7162{
    72         attrset( 0x00000000ul | 0x00800000ul );
     63        uint32 fcolor = fgcolor.get_color();
     64        uint32 bcolor = ( bgcolor.get_color() % 8 ) * 8;
     65        chtype attr = static_cast<chtype>( ( fcolor > 7 ? fcolor - 7 + bcolor : fcolor + bcolor + 1 ) << 24 );
     66        if ( fcolor > 7 ) attr = attr | 0x00800000ul;
     67        attrset( attr );
    7368        for ( int x = r.ul.x-1; x <= r.lr.x-1; ++x )
    7469                for ( int y = r.ul.y-1; y <= r.lr.y-1; ++y )
  • trunk/src/gui/gui_ascii_renderer.cc

    r487 r514  
    1515struct ascii_render_data : public render_data
    1616{
    17         ascii_render_data() {}
    18         bool   clear;
    19         bool   border;
    20         char   border_chars[8];
    21         uint32 border_color;
    22         uint32 text_color;
     17        bool       clear;
     18        bool       border;
     19        char       border_chars[8];
     20        ivec2      padding;
     21        term_color border_color;
     22        term_color text_color;
    2323};
    2424
     
    3838                er->border     = false;
    3939                er->clear      = false;
    40                 er->text_color = 0;
    4140                e->m_render_data = er;
    4241        }
     
    5756               
    5857                m_style.get( e, "ascii_color", selector, color );
    59                 er->text_color = uint32( color );
     58                er->text_color = term_color::color( color );
    6059                er->border     = false;
     60                vec4 padding;
     61                m_style.get( e, "ascii_padding", selector, padding );
     62                er->padding    = ivec2( int( padding.x ), int( padding.y ) );
     63
    6164                if ( m_style.get( e, "ascii_border", selector, path ) )
    6265                {
     
    6568                        int border_color = 0;
    6669                        if ( m_style.get( e, "ascii_border_color", selector, border_color ) )
    67                                 er->border_color = uint32( border_color );
     70                                er->border_color = term_color::color( border_color );
    6871                        for ( uint32 i = 0; i < 8 && i < path.length(); i++ )
    6972                                er->border_chars[i] = path[i];
     
    7679        ascii_render_data* er = static_cast< ascii_render_data* >( e->m_render_data );
    7780        rectangle abs = e->m_absolute;
    78         if ( er->clear ) m_terminal->clear( abs );
     81        if ( er->clear ) m_terminal->clear( abs, term_color::LIGHTGRAY, term_color() );
    7982        if ( er->border )
    8083        {
    8184                for ( int x = 0; x < abs.get_width(); ++x )
    8285                {
    83                         m_terminal->print( position( abs.ul.x + x, abs.ul.y ), er->border_color, er->border_chars[0] );
    84                         m_terminal->print( position( abs.ul.x + x, abs.lr.y ), er->border_color, er->border_chars[1] );
     86                        m_terminal->print( position( abs.ul.x + x, abs.ul.y ), er->border_color, term_color(), er->border_chars[0] );
     87                        m_terminal->print( position( abs.ul.x + x, abs.lr.y ), er->border_color, term_color(), er->border_chars[1] );
    8588                }
    8689
    8790                for ( int y = 0; y < abs.get_height(); ++y )
    8891                {
    89                         m_terminal->print( position( abs.ul.x, abs.ul.y + y ), er->border_color, er->border_chars[2] );
    90                         m_terminal->print( position( abs.lr.x, abs.ul.y + y ), er->border_color, er->border_chars[3] );
     92                        m_terminal->print( position( abs.ul.x, abs.ul.y + y ), er->border_color, term_color(), er->border_chars[2] );
     93                        m_terminal->print( position( abs.lr.x, abs.ul.y + y ), er->border_color, term_color(), er->border_chars[3] );
    9194                }
    9295
    93                 m_terminal->print( abs.ul,   er->border_color, er->border_chars[4] );
    94                 m_terminal->print( abs.ur(), er->border_color, er->border_chars[5] );
    95                 m_terminal->print( abs.ll(), er->border_color, er->border_chars[6] );
    96                 m_terminal->print( abs.lr,   er->border_color, er->border_chars[7] );
     96                m_terminal->print( abs.ul,   er->border_color, term_color(), er->border_chars[4] );
     97                m_terminal->print( abs.ur(), er->border_color, term_color(), er->border_chars[5] );
     98                m_terminal->print( abs.ll(), er->border_color, term_color(), er->border_chars[6] );
     99                m_terminal->print( abs.lr,   er->border_color, term_color(), er->border_chars[7] );
    97100                m_terminal->update();
    98101        }
    99102        if ( !e->m_text.empty() )
    100103        {
    101                 position p = abs.ul;
     104                position p = abs.ul + er->padding;
    102105                for ( char c : e->m_text )
    103106                {
    104                         m_terminal->print( p, er->text_color, c );
     107                        m_terminal->print( p, er->text_color, term_color(), c );
    105108                        ++p.x;
    106109                }
Note: See TracChangeset for help on using the changeset viewer.