Changeset 440 for trunk/src/gui


Ignore:
Timestamp:
07/23/15 21:16:01 (10 years ago)
Author:
epyon
Message:
  • 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
Location:
trunk/src/gui
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/gui/gui_ascii_renderer.cc

    r406 r440  
    4949                er->clear = true;
    5050                int color = 0;
    51                 std::string path;
    52                 std::string text;
     51                string128 path;
    5352                const char* stext[] = { nullptr, "selected", "hover" };
    5453                const char* selector = stext[0];
  • trunk/src/gui/gui_environment.cc

    r433 r440  
    99#include "nv/gui/gui_renderer.hh"
    1010
    11 #include <algorithm> // std::find on std::list
    12 
    1311        /*
    1412
     
    2725        : m_renderer( r )
    2826{
     27        r->set_environment( this );
    2928        m_screen   = create_element( handle(), m_renderer->get_area() );
    3029}
     
    161160                while ( !parent->m_children.empty() )
    162161                {
    163                         destroy_element( parent->m_children.front() );
     162                        destroy_element( parent->m_children.back() );
    164163                }
    165164        }
     
    196195}
    197196
     197nv::string_view nv::gui::environment::get_string( shash64 h )
     198{
     199        return m_strings[h];
     200}
     201
    198202bool nv::gui::environment::set_selected( handle e )
    199203{
     
    235239
    236240        handle result;
    237         element::list::reverse_iterator it = el->m_children.rbegin();
     241        auto it = el->m_children.rbegin();
    238242
    239243        while ( it != el->m_children.rend() )
     
    254258        if ( e && parent )
    255259        {
    256                 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
     260                auto it = find( parent->m_children.begin(), parent->m_children.end(), child );
    257261                if ( it != parent->m_children.end() )
    258262                {
     
    264268}
    265269
    266 void nv::gui::environment::move_to_bottom( handle child )
    267 {
    268         element* e      = m_elements.get( child );
    269         element* parent = m_elements.get( e->m_parent );
    270         if ( e && parent )
    271         {
    272                 auto it = std::find( parent->m_children.begin(), parent->m_children.end(), child );
    273                 if ( it != parent->m_children.end() )
    274                 {
    275                         parent->m_children.erase( it );
    276                         parent->m_children.push_front( child );
    277                         parent->m_flags[DIRTY] = true;
    278                 }
    279         }
    280 }
    281 
    282270void nv::gui::environment::set_relative( handle e, const rectangle& r )
    283271{
     
    312300}
    313301
    314 void nv::gui::environment::set_class( handle e, const std::string& text )
     302void nv::gui::environment::set_class( handle e, const string_view& text )
    315303{
    316304        element* ep = m_elements.get(e);
    317305        if ( ep != nullptr )
    318306        {
    319                 ep->m_class        = text;
     307                ep->m_class        = m_strings.insert( text );
    320308                ep->m_flags[DIRTY] = true;
    321309        }
    322310}
    323311
    324 void nv::gui::environment::set_text( handle e, const std::string& text )
     312void nv::gui::environment::set_text( handle e, const string_twine& text )
    325313{
    326314        element* ep = m_elements.get(e);
    327315        if ( ep != nullptr )
    328316        {
    329                 ep->m_text         = text;
     317                ep->m_text.assign( text );
    330318                ep->m_flags[DIRTY] = true;
    331319        }
     
    337325        if ( p )
    338326        {
    339                 auto it = std::find( p->m_children.begin(), p->m_children.end(), child );
     327                auto it = find( p->m_children.begin(), p->m_children.end(), child );
    340328                if ( it != p->m_children.end() )
    341329                {
    342330                        element* e = m_elements.get( *it );
    343331                        e->m_parent = handle();
    344                         p->m_children.erase(it);
    345                 }       
    346         }
    347 }
    348 
     332                        p->m_children.erase( it );
     333                }
     334        }
     335}
     336
  • trunk/src/gui/gui_gfx_renderer.cc

    r437 r440  
    243243                int border = 0;
    244244                vec4 color;
    245                 std::string path;
    246                 std::string text;
    247                 const char* stext[] = { nullptr, "selected", "hover" };
     245                string128 path;
     246                const char* stext[] = { "", "selected", "hover" };
    248247                const char* selector = stext[border];
    249248                if ( e->m_flags[HOVER] )    selector = stext[2];
     
    252251                if ( m_style.get( e, "skin", selector, path ) )
    253252                {
    254                         size_t image_id = load_image( string_view( path.c_str(), path.size() ) );
     253                        size_t image_id = load_image( path );
    255254                        const image_info* image = get_image( image_id );
    256255                        if ( image )
     
    312311                }
    313312
    314                 text = e->m_text;
    315                 if ( !text.empty() )
     313                e->m_text;
     314                if ( !e->m_text.empty() )
    316315                {
    317316                        if ( m_style.get( e, "text_color", selector, color ) && m_style.get( e, "text_font", selector, path ) && m_style.get( e, "text_size", selector, border ) )
    318317                        {
    319                                 size_t font_id = load_font( string_view( path.c_str(), path.size() ), size_t( border ) );
     318                                size_t font_id = load_font( path, size_t( border ) );
    320319                                texture_font* font = get_font( font_id );
    321320                                position p = abs.ul + position( 0, border );
    322                                 for ( char c : text )
     321                                for ( char c : e->m_text )
    323322                                {
    324323                                        const texture_glyph* g = font->get_glyph( static_cast<uint16>( c ) );
  • trunk/src/gui/gui_style.cc

    r433 r440  
    77#include "nv/gui/gui_style.hh"
    88
     9#include "nv/gui/gui_environment.hh"
    910#include <nv/lua/lua_raw.hh>
    1011
     
    1213using namespace nv::gui;
    1314
    14 style::style()
    15 {
    16 }
    17 
    1815void style::load_style( const string_view& filename )
    1916{
     17        NV_ASSERT_ALWAYS( m_env, "Environment not set in style!" );
    2018        m_lua.do_file( filename );
    2119}
    2220
    23 bool style::get( element* e, const char* centry, const char* cselector, std::string& s )
     21bool style::get( element* e, const string_view& centry, const string_view& cselector, string128& s )
    2422{
    2523        lua::stack_guard guard( m_lua );
    26         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false;
    27         s = lua_tostring( m_lua, -1 );
     24        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TSTRING ) ) return false;
     25        // TODO: create lua_tostringbuffer< size >
     26        s.assign( lua_tostring( m_lua, -1 ) );
    2827        return true;
    2928}
    3029
    31 bool style::get( element* e, const char* centry, const char* cselector, vec4& vec )
     30bool style::get( element* e, const string_view& centry, const string_view& cselector, vec4& vec )
    3231{
    3332        lua::stack_guard guard( m_lua );
    34         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false;
     33        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TTABLE ) ) return false;
    3534        vec = vec4();
    3635        for ( int i = 0; i < 4; ++i )
     
    4443}
    4544
    46 bool style::get( element* e, const char* centry, const char* cselector, int& i )
     45bool style::get( element* e, const string_view& centry, const string_view& cselector, int& i )
    4746{
    4847        lua::stack_guard guard( m_lua );
    49         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
     48        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false;
    5049        i = static_cast< int >( lua_tointeger( m_lua, -1 ) );
    5150        return true;
    5251}
    5352
    54 bool style::get( element* e, const char* centry, const char* cselector, double& d )
     53bool style::get( element* e, const string_view& centry, const string_view& cselector, double& d )
    5554{
    5655        lua::stack_guard guard( m_lua );
    57         if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false;
     56        if ( !resolve( e->m_id, e->m_class, cselector, centry, LUA_TNUMBER ) ) return false;
    5857        d = lua_tonumber( m_lua, -1 );
    5958        return true;
     
    6463}
    6564
    66 bool style::find_entry( const char* cselector, const char* centry, int type )
     65bool style::find_entry( const string_view& cselector, const string_view& centry, int type )
    6766{
    6867        if ( lua_istable( m_lua, -1 ) )
    6968        {
    70                 if ( cselector )
     69                if ( !cselector.empty() )
    7170                {
    72                         lua_getfield( m_lua, -1, cselector );
     71                        lua_getfield( m_lua, -1, cselector.data() );
    7372                        if ( lua_istable( m_lua, -1 ) )
    7473                        {
    75                                 lua_getfield( m_lua, -1, centry );
     74                                lua_getfield( m_lua, -1, centry.data() );
    7675                                if ( lua_type( m_lua, -1 ) == type )
    7776                                {
     
    8382                }
    8483
    85                 lua_getfield( m_lua, -1, centry );
     84                lua_getfield( m_lua, -1, centry.data() );
    8685                if ( lua_type( m_lua, -1 ) == type ) return true;
    8786        }
     
    8988}
    9089
    91 bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type )
     90bool style::resolve( shash64 cid, shash64 cclass, const string_view& cselector, const string_view& centry, int type )
    9291{
    9392        lua_getglobal( m_lua, "default" );
     
    9594
    9695        // check id
    97         lua_getfield( m_lua, -1, cid );
    98         if ( find_entry( cselector, centry, type ) ) return true;
    99         lua_settop( m_lua, global );
    100 
     96        string_view id( m_env->get_string( cid ) );
     97        if ( !id.empty() )
     98        {
     99                lua_getfield( m_lua, -1, id.data() );
     100                if ( find_entry( cselector, centry, type ) ) return true;
     101                lua_settop( m_lua, global );
     102        }
    101103        // check class
    102         lua_getfield( m_lua, -1, cclass );
    103         if ( find_entry( cselector, centry, type ) ) return true;
    104         lua_settop( m_lua, global );
     104        string_view klass( m_env->get_string( cclass ) );
     105        if ( !klass.empty() )
     106        {
     107                lua_getfield( m_lua, -1, klass.data() );
     108                if ( find_entry( cselector, centry, type ) ) return true;
     109                lua_settop( m_lua, global );
     110        }
    105111
    106112        // check entry
Note: See TracChangeset for help on using the changeset viewer.