source: trunk/src/gui/gui_ascii_renderer.cc @ 440

Last change on this file since 440 was 440, checked in by epyon, 10 years ago
  • massive std::string removal
  • no header depends on std::string anymore (or any other STL header)
  • still some code files do (WIP)
  • massive refactoring where std::string was used
  • lua still messy (grep for string128 - used everywhere)
  • string_twine added
File size: 3.5 KB
RevLine 
[355]1// Copyright (C) 2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
[395]4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
[355]6
7#include "nv/gui/gui_ascii_renderer.hh"
8
[365]9#include "nv/core/logging.hh"
10
[355]11using namespace nv;
12using namespace nv::gui;
13
14
15struct ascii_render_data : public render_data
16{
17        ascii_render_data() {}
[356]18        bool   clear;
[355]19        bool   border;
[406]20        uchar8 border_chars[8];
[355]21        uint32 border_color;
22        uint32 text_color;
23};
24
25
26ascii_renderer::ascii_renderer( terminal* t )
27        : m_terminal(t)
28{
29
30}
31
32void ascii_renderer::redraw( element* e, uint32 )
33{
34        ascii_render_data* er = nullptr;
35        if ( e->m_render_data == nullptr )
36        {
37                er = new ascii_render_data;
38                er->border     = false;
[356]39                er->clear      = false;
[355]40                er->text_color = 0;
41                e->m_render_data = er;
42        }
43        else
[406]44                er = static_cast< ascii_render_data* >( e->m_render_data );
[355]45
46        rectangle abs = e->m_absolute;
47        if ( abs != get_area() )
48        {
[356]49                er->clear = true;
[355]50                int color = 0;
[440]51                string128 path;
[355]52                const char* stext[] = { nullptr, "selected", "hover" };
53                const char* selector = stext[0];
54                if ( e->m_flags[HOVER] )    selector = stext[2];
55                if ( e->m_flags[SELECTED] ) selector = stext[1];
56
57               
58                m_style.get( e, "ascii_color", selector, color );
59                er->text_color = uint32( color );
60                er->border     = false;
61                if ( m_style.get( e, "ascii_border", selector, path ) )
62                {
63                        er->border = true;
64                        er->border_color = er->text_color;
65                        int border_color = 0;
66                        if ( m_style.get( e, "ascii_border_color", selector, border_color ) )
67                                er->border_color = uint32( border_color );
68                        for ( uint32 i = 0; i < 8 && i < path.length(); )
[406]69                                er->border_chars[i] = static_cast< uchar8 >( path[i] );
[355]70                }
71        }
72}
73
74void ascii_renderer::draw( element* e )
75{
[406]76        ascii_render_data* er = static_cast< ascii_render_data* >( e->m_render_data );
[355]77        rectangle abs = e->m_absolute;
[356]78        if ( er->clear ) m_terminal->clear( abs );
[355]79        if ( er->border )
80        {
81                for ( int x = 0; x < abs.get_width(); ++x )
82                {
[406]83                        m_terminal->print( position( abs.ul.y, abs.ul.x + x ), er->border_color, er->border_chars[0] );
84                        m_terminal->print( position( abs.lr.y, abs.ul.x + x ), er->border_color, er->border_chars[1] );
[355]85                }
86
87                for ( int y = 0; y < abs.get_height(); ++y )
88                {
[406]89                        m_terminal->print( position( abs.ul.y + y, abs.ul.x ), er->border_color, er->border_chars[2] );
90                        m_terminal->print( position( abs.ul.y + y, abs.lr.x ), er->border_color, er->border_chars[3] );
[355]91                }
92
[406]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] );
[355]97        }
98        if ( !e->m_text.empty() )
99        {
100                position p = abs.ul;
101                for ( char c : e->m_text )
102                {
[406]103                        m_terminal->print( p, er->text_color, static_cast< unsigned char >( c ) );
[355]104                        ++p.x;
105                }
106        }
107}
108
109void ascii_renderer::draw()
110{
111        m_terminal->update();
112}
113
[364]114void nv::gui::ascii_renderer::on_hover_change( element* e, bool /*hover*/ )
[355]115{
116        // TODO: FIX
[364]117        int fix_me;
[365]118        NV_LOG_DEBUG( "on_hover_change" );
[355]119        e->m_flags[DIRTY] = true;
120}
121
[364]122void nv::gui::ascii_renderer::on_select_change( element* e, bool /*select*/ )
[355]123{
124        // TODO: FIX
[364]125        int fix_me;
[365]126        NV_LOG_DEBUG( "on_select_change" );
[355]127        e->m_flags[DIRTY] = true;
128}
129
130rectangle ascii_renderer::get_area() const
131{
132        return rectangle().dim( m_terminal->get_size() );
133}
134
135ascii_renderer::~ascii_renderer()
136{
137
138}
Note: See TracBrowser for help on using the repository browser.