- Timestamp:
- 02/15/15 21:33:48 (10 years ago)
- Location:
- trunk
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/nv/gui/gui_common.hh
r319 r351 16 16 #include <nv/core/common.hh> 17 17 #include <nv/core/handle.hh> 18 #include <nv/core/flags.hh> 18 19 19 20 namespace nv … … 21 22 namespace gui 22 23 { 24 enum flag 25 { 26 ENABLED, //!< GUI element accepts events 27 VISIBLE, //!< GUI element visible 28 DIRTY, //!< GUI element needs redraw 29 SELECTED, //!< GUI element selected 30 HOVER, //!< GUI element in hover zone 31 }; 32 23 33 enum alignment 24 34 { … … 43 53 typedef nv::handle<> handle; 44 54 55 typedef nv::flags< 32, flag > flags; 56 45 57 } // namespace gui 46 58 -
trunk/nv/gui/gui_element.hh
r319 r351 32 32 typedef std::list<handle> list; 33 33 34 35 element()36 : m_id( "" )37 , m_child_count(0)38 , m_class("")39 , m_enabled( true )40 , m_visible( true )41 , m_dirty( true )42 , m_render_data( nullptr ) {}43 44 34 string m_id; ///< id type of the object 45 35 handle m_parent; ///< pointer to parent 36 flags m_flags; 46 37 list m_children; ///< children objects 47 38 size_t m_child_count; ///< number of children … … 50 41 rectangle m_relative; ///< Position relative to parent. 51 42 rectangle m_absolute; ///< Position relative to window/screen. 52 bool m_enabled; ///< Whether the element accepts events.53 bool m_visible; ///< Whether the element is drawn.54 bool m_dirty; ///< Whether the element needs updating.55 43 render_data* m_render_data; ///< -?- 56 44 }; -
trunk/nv/gui/gui_environment.hh
r347 r351 43 43 virtual ~environment(); 44 44 protected: 45 bool set_selected( handle e ); 45 46 handle get_element( const position& p ); 46 47 void add_child( handle child ); … … 57 58 void set_relative( handle e, const position& p ); 58 59 void recalculate_absolute( handle e ); 59 60 60 61 handle_store< element, handle > m_elements; 61 62 renderer* m_renderer; … … 63 64 handle m_screen; 64 65 rectangle m_area; 66 position m_mouse_position; 67 handle m_selected; 65 68 }; 66 69 -
trunk/nv/gui/gui_renderer.hh
r328 r351 30 30 namespace gui 31 31 { 32 struct vertex33 {34 ivec2 position;35 vec2 texcoord;36 vec4 color;37 vertex() {}38 vertex( const nv::ivec2& cr, const nv::vec2& tc, const nv::vec4& c )39 : position( cr ), texcoord( tc ), color( c ) {}40 };41 42 32 struct image_info 43 33 { … … 63 53 void draw( element* e ); 64 54 void draw(); 55 void on_hover_change( element* e, bool hover ); 56 void on_select_change( element* e, bool select ); 65 57 virtual ~renderer(); 66 58 private: -
trunk/nv/gui/gui_style.hh
r350 r351 28 28 style(); 29 29 void load_style( const std::string& filename ); 30 bool get( element* e, const char* centry, std::string& s );31 bool get( element* e, const char* centry, vec4& vec );32 bool get( element* e, const char* centry, int& i );33 bool get( element* e, const char* centry, double& d );30 bool get( element* e, const char* centry, const char* cselector, std::string& s ); 31 bool get( element* e, const char* centry, const char* cselector, vec4& vec ); 32 bool get( element* e, const char* centry, const char* cselector, int& i ); 33 bool get( element* e, const char* centry, const char* cselector, double& d ); 34 34 ~style(); 35 35 protected: 36 bool resolve( const char* cid, const char* cclass, const char* centry, int type ); 36 bool find_entry( const char* cselector, const char* centry, int type ); 37 bool resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type ); 37 38 protected: 38 39 lua::state m_lua; //!< separate lua state for style calculation -
trunk/nv/interface/image_data.hh
r340 r351 28 28 RGB16F, 29 29 RGBA16F, 30 BGR, 31 BGRA, 30 32 }; 31 33 … … 48 50 const ivec2 get_size() const { return m_size; } 49 51 // TODO : better depth check (template?) 50 size_t get_depth() const { return m_format.format == RGB ? 3 : 4; }52 size_t get_depth() const { return m_format.format == RGB || m_format.format == BGR ? 3 : 4; } 51 53 image_format get_format() const { return m_format; } 52 54 ~image_data() { if (m_data) delete[] m_data; } -
trunk/nv/lib/detail/gl_types.inc
r331 r351 243 243 #define GL_UNSIGNED_INT_8_8_8_8_REV 0x8367 244 244 #define GL_BGR 0x80E0 245 #define GL_BGRA 0x80E1 245 246 #define GL_MAX_ELEMENTS_VERTICES 0x80E8 246 247 #define GL_MAX_ELEMENTS_INDICES 0x80E9 -
trunk/src/gl/gl_enum.cc
r350 r351 180 180 case RGB16F : return GL_RGB; 181 181 case RGBA16F : return GL_RGBA; 182 case BGR : return GL_BGR; 183 case BGRA : return GL_BGRA; 182 184 NV_RETURN_COVERED_DEFAULT( 0 ); 183 185 } … … 194 196 case RGB16F : return GL_RGBA16F; 195 197 case RGBA16F : return GL_RGBA16F; 198 case BGR : return GL_RGB8; 199 case BGRA : return GL_RGBA8; 196 200 NV_RETURN_COVERED_DEFAULT( 0 ); 197 201 } -
trunk/src/gui/gui_environment.cc
r344 r351 29 29 { 30 30 m_area.dim( dimension( w->get_width(), w->get_height() ) ); 31 32 m_screen = m_elements.create();33 element* screen = m_elements.get( m_screen );34 screen->m_absolute = m_area;35 screen->m_relative = m_area;36 37 31 m_renderer = new renderer( w ); 32 m_screen = create_element( handle(), m_area ); 38 33 } 39 34 … … 51 46 { 52 47 if ( parent.is_nil() ) parent = m_screen; 48 53 49 handle result = m_elements.create(); 54 50 element* e = m_elements.get( result ); … … 58 54 if ( ar.ul.y < 0 ) { ar.ul.y += m_area.lr.y; ar.lr.y += m_area.lr.y; } 59 55 56 e->m_child_count = 0; 57 e->m_flags[ENABLED] = true; 58 e->m_flags[VISIBLE] = true; 59 e->m_flags[DIRTY] = true; 60 e->m_render_data = nullptr; 60 61 e->m_absolute = ar; 61 62 e->m_relative = ar; 62 add_child( parent, result ); 63 64 if ( !parent.is_nil() ) // screen creation 65 add_child( parent, result ); 63 66 return result; 64 67 } … … 83 86 if ( !el ) return; 84 87 // el->on_update( elapsed ); 85 if ( el->m_visible ) 88 if ( el->m_flags[ENABLED] ) 89 { 90 bool hover = el->m_flags[HOVER]; 91 bool new_hover = el->m_absolute.contains( m_mouse_position ); 92 if ( hover != new_hover ) 93 { 94 el->m_flags[HOVER] = new_hover; 95 // gain loose hover event 96 m_renderer->on_hover_change( el, hover ); 97 } 98 } 99 100 if ( el->m_flags[VISIBLE] ) 86 101 { 87 102 for ( handle i : el->m_children ) … … 90 105 } 91 106 } 92 if ( el->m_ dirty|| el->m_render_data == nullptr )107 if ( el->m_flags[DIRTY] || el->m_render_data == nullptr ) 93 108 { 94 109 m_renderer->redraw( el, elapsed ); 95 el->m_ dirty= false;110 el->m_flags[DIRTY] = false; 96 111 } 97 112 } … … 101 116 element* el = m_elements.get( e ); 102 117 if ( !el ) return; 103 if ( el->m_ visible)118 if ( el->m_flags[VISIBLE] ) 104 119 { 105 120 // el->on_draw(); … … 160 175 } 161 176 162 bool nv::gui::environment::process_io_event( const io_event& ) 163 { 177 bool nv::gui::environment::process_io_event( const io_event& ev ) 178 { 179 switch ( ev.type ) 180 { 181 // case EV_KEY : 182 case EV_MOUSE_BUTTON : 183 if ( ev.mbutton.pressed && ev.mbutton.button == MOUSE_LEFT ) 184 { 185 handle h = get_element( position( ev.mbutton.x, ev.mbutton.y ) ); 186 set_selected( h ); 187 return true; 188 } 189 return false; 190 case EV_MOUSE_MOVE: 191 m_mouse_position = position( ev.mmove.x, ev.mmove.y ); 192 return false; 193 // case EV_MOUSE_WHEEL : 194 default: 195 break; 196 } 197 return false; 198 } 199 200 bool nv::gui::environment::set_selected( handle e ) 201 { 202 if ( e != m_selected ) 203 { 204 element* eold = m_elements.get( m_selected ); 205 element* el = m_elements.get( e ); 206 if ( eold ) 207 { 208 eold->m_flags[SELECTED] = false; 209 m_renderer->on_select_change( eold, false ); 210 } 211 if ( el ) 212 { 213 el->m_flags[SELECTED] = true; 214 m_renderer->on_select_change( el, true ); 215 } 216 m_selected = e; 217 return true; 218 } 164 219 return false; 165 220 } … … 179 234 { 180 235 element* el = m_elements.get(e); 181 if ( !el && !el->m_ visible) return handle();236 if ( !el && !el->m_flags[VISIBLE] ) return handle(); 182 237 183 238 handle result; … … 206 261 parent->m_children.erase( it ); 207 262 parent->m_children.push_back( child ); 208 parent->m_ dirty= true;263 parent->m_flags[DIRTY] = true; 209 264 } 210 265 } … … 222 277 parent->m_children.erase( it ); 223 278 parent->m_children.push_front( child ); 224 parent->m_ dirty= true;279 parent->m_flags[DIRTY] = true; 225 280 } 226 281 } … … 232 287 if ( el ) 233 288 { 234 el->m_ dirty= true;235 el->m_relative = r;289 el->m_flags[DIRTY] = true; 290 el->m_relative = r; 236 291 recalculate_absolute( e ); 237 292 } … … 264 319 if ( ep != nullptr ) 265 320 { 266 ep->m_class = text;267 ep->m_ dirty= true;321 ep->m_class = text; 322 ep->m_flags[DIRTY] = true; 268 323 } 269 324 } … … 274 329 if ( ep != nullptr ) 275 330 { 276 ep->m_text = text;277 ep->m_ dirty= true;331 ep->m_text = text; 332 ep->m_flags[DIRTY] = true; 278 333 } 279 334 } -
trunk/src/gui/gui_renderer.cc
r346 r351 44 44 using namespace nv; 45 45 using namespace nv::gui; 46 47 struct vertex 48 { 49 ivec2 position; 50 vec2 texcoord; 51 vec4 color; 52 vertex() {} 53 vertex( const nv::ivec2& cr, const nv::vec2& tc, const nv::vec4& c ) 54 : position( cr ), texcoord( tc ), color( c ) 55 { 56 } 57 }; 46 58 47 59 const ivec2 atlas_size = ivec2( 1024, 1024 ); … … 239 251 std::string path; 240 252 std::string text; 241 242 if ( m_style.get( e, "skin", path ) ) 253 const char* stext[] = { nullptr, "selected", "hover" }; 254 const char* selector = stext[border]; 255 if ( e->m_flags[HOVER] ) selector = stext[2]; 256 if ( e->m_flags[SELECTED] ) selector = stext[1]; 257 258 if ( m_style.get( e, "skin", selector, path ) ) 243 259 { 244 260 size_t image_id = load_image( path ); … … 286 302 { 287 303 288 if ( m_style.get( e, "border", border ) && m_style.get( e, "border_color", color ) )304 if ( m_style.get( e, "border", selector, border ) && m_style.get( e, "border_color", selector, color ) ) 289 305 { 290 306 rectangle inner = abs.shrinked( border ); … … 296 312 } 297 313 298 if ( m_style.get( e, "background_color", color ) )314 if ( m_style.get( e, "background_color", selector, color ) ) 299 315 { 300 316 qvec.emplace_back( abs.ul, abs.lr, color ); … … 305 321 if ( !text.empty() ) 306 322 { 307 if ( m_style.get( e, "text_color", color ) && m_style.get( e, "text_font", path ) && m_style.get( e, "text_size", border ) )323 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 ) ) 308 324 { 309 325 size_t font_id = load_font( path, (uint16)border ); … … 331 347 } 332 348 349 void renderer::on_hover_change( element* e, bool hover ) 350 { 351 // TODO: FIX 352 NV_LOG( nv::LOG_DEBUG, "on_hover_change" ); 353 e->m_flags[DIRTY] = true; 354 } 355 356 void renderer::on_select_change( element* e, bool select ) 357 { 358 // TODO: FIX 359 NV_LOG( nv::LOG_DEBUG, "on_select_change" ); 360 e->m_flags[DIRTY] = true; 361 } 362 363 333 364 void renderer::draw( element* e ) 334 365 { -
trunk/src/gui/gui_style.cc
r350 r351 21 21 } 22 22 23 bool style::get( element* e, const char* centry, std::string& s )23 bool style::get( element* e, const char* centry, const char* cselector, std::string& s ) 24 24 { 25 25 lua::stack_guard guard( m_lua ); 26 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), c entry, LUA_TSTRING ) ) return false;26 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TSTRING ) ) return false; 27 27 s = lua_tostring( m_lua, -1 ); 28 28 return true; 29 29 } 30 30 31 bool style::get( element* e, const char* centry, vec4& vec )31 bool style::get( element* e, const char* centry, const char* cselector, vec4& vec ) 32 32 { 33 33 lua::stack_guard guard( m_lua ); 34 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), c entry, LUA_TTABLE ) ) return false;34 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TTABLE ) ) return false; 35 35 vec = vec4(); 36 36 for (size_t i = 0; i < 4; ++i ) … … 44 44 } 45 45 46 bool style::get( element* e, const char* centry, int& i )46 bool style::get( element* e, const char* centry, const char* cselector, int& i ) 47 47 { 48 48 lua::stack_guard guard( m_lua ); 49 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), c entry, LUA_TNUMBER ) ) return false;49 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false; 50 50 i = static_cast< int >( lua_tointeger( m_lua, -1 ) ); 51 51 return true; 52 52 } 53 53 54 bool style::get( element* e, const char* centry, double& d )54 bool style::get( element* e, const char* centry, const char* cselector, double& d ) 55 55 { 56 56 lua::stack_guard guard( m_lua ); 57 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), c entry, LUA_TNUMBER ) ) return false;57 if ( !resolve( e->m_id.c_str(), e->m_class.c_str(), cselector, centry, LUA_TNUMBER ) ) return false; 58 58 d = lua_tonumber( m_lua, -1 ); 59 59 return true; … … 64 64 } 65 65 66 bool style::resolve( const char* cid, const char* cclass, const char* centry, int type ) 66 bool style::find_entry( const char* cselector, const char* centry, int type ) 67 { 68 if ( lua_istable( m_lua, -1 ) ) 69 { 70 if ( cselector ) 71 { 72 lua_getfield( m_lua, -1, cselector ); 73 if ( lua_istable( m_lua, -1 ) ) 74 { 75 lua_getfield( m_lua, -1, centry ); 76 if ( lua_type( m_lua, -1 ) == type ) 77 { 78 return true; 79 } 80 lua_pop( m_lua, 1 ); 81 } 82 lua_pop( m_lua, 1 ); 83 } 84 85 lua_getfield( m_lua, -1, centry ); 86 if ( lua_type( m_lua, -1 ) == type ) return true; 87 } 88 return false; 89 } 90 91 bool style::resolve( const char* cid, const char* cclass, const char* cselector, const char* centry, int type ) 67 92 { 68 93 lua_getglobal( m_lua, "default" ); … … 71 96 // check id 72 97 lua_getfield( m_lua, -1, cid ); 73 if ( lua_istable( m_lua, -1 ) ) 74 { 75 lua_getfield( m_lua, -1, centry ); 76 if ( lua_type( m_lua, -1 ) == type ) return true; 77 } 98 if ( find_entry( cselector, centry, type ) ) return true; 78 99 lua_settop( m_lua, global ); 79 100 80 101 // check class 81 102 lua_getfield( m_lua, -1, cclass ); 82 if ( lua_istable( m_lua, -1 ) ) 83 { 84 lua_getfield( m_lua, -1, centry ); 85 if ( lua_type( m_lua, -1 ) == type ) return true; 86 } 103 if ( find_entry( cselector, centry, type ) ) return true; 87 104 lua_settop( m_lua, global ); 88 105 89 106 // check entry 90 lua_getfield( m_lua, -1, centry ); 91 if ( lua_type( m_lua, -1 ) == type ) return true; 107 if ( find_entry( cselector, centry, type ) ) return true; 92 108 return false; 93 109 } -
trunk/tests/gui_test/nv_gui_test.cc
r328 r351 80 80 break; 81 81 } 82 m_guienv->process_io_event( event ); 82 83 } 83 84 } -
trunk/tests/gui_test/premake4.lua
r321 r351 15 15 objdir ("../../".._ACTION.."/release") 16 16 17 dofile("../../nv.lua") 17 18 dofile("gui_test.lua") 18 dofile("../../nv.lua") -
trunk/tests/gui_test/test.style.lua
r329 r351 10 10 skin = "button.png", 11 11 12 [":hover"]= {12 hover = { 13 13 text_color = { 1.0, 1.0, 1.0, 1.0 }, 14 }, 15 16 selected = { 17 text_color = { 1.0, 1.0, 0.0, 1.0 }, 14 18 } 15 19
Note: See TracChangeset
for help on using the changeset viewer.