source: trunk/src/gui/gui_element.cc @ 266

Last change on this file since 266 was 266, checked in by epyon, 11 years ago
  • decoupling - uid_store independent of nv::object
  • decoupling - nv::object no longer linked with lua in any way
  • decoupling - gui::element related object methods moved to element
  • uid_store can operate on void* or specialized base class
  • root class no longer carries uid store nor lua state (will be removed later)
File size: 2.3 KB
Line 
1// Copyright (C) 2012-2013 ChaosForge / Kornel Kisielewicz
2// http://chaosforge.org/
3//
4// This file is part of NV Libraries.
5// For conditions of distribution and use, see copyright notice in nv.hh
6
7#include "nv/gui/gui_element.hh"
8
9using namespace nv;
10using namespace nv::gui;
11
12element::element( const rectangle& r )
13        : object( "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr )
14{
15
16}
17
18bool element::on_event( const io_event& event )
19{
20        return m_parent ? ((element*)m_parent)->on_event( event ) : false;
21}
22
23element* element::get_element( const position& p )
24{
25        if ( !is_visible() ) return nullptr;
26
27        element* result = nullptr;
28        list::reverse_iterator it = m_children.rbegin();
29
30        while ( it != m_children.rend() )
31        {
32                result = ((element*)(*it))->get_element( p );
33                if ( result ) return result;
34                ++it;
35        }
36
37        if ( contains( p ) ) return this;
38        return nullptr;
39}
40
41bool element::contains( const position& p ) const
42{
43        return m_absolute.contains( p );
44}
45
46void element::set_relative( const rectangle& r )
47{
48        m_dirty    = true;
49        m_relative = r;
50        recalculate_absolute();
51}
52
53void element::set_relative( const position& p )
54{
55        set_relative( rectangle( p, p + m_relative.get_size() ) );
56}
57
58void element::recalculate_absolute()
59{
60        rectangle pabsolute;
61
62        if ( m_parent )
63        {
64                pabsolute = ((element*)(m_parent))->m_absolute;
65        }
66
67        m_absolute = m_relative + pabsolute.ul;
68
69        for ( object* o : *this )
70        {
71                ((element*)o)->recalculate_absolute();
72        }
73}
74
75void element::recalculate_absolute_children()
76{
77        for ( object* o : *this )
78        {
79                ((element*)o)->recalculate_absolute();
80        }
81}
82
83
84bool element::move_to_top( element* child )
85{
86        list::iterator it = std::find( m_children.begin(), m_children.end(), (object*)child );
87        if ( it != m_children.end() )
88        {
89                m_children.erase( it );
90                m_children.push_back( child );
91                return true;
92        }       
93        return false;
94}
95
96bool element::move_to_bottom( element* child )
97{
98        list::iterator it = std::find( m_children.begin(), m_children.end(), (object*)child );
99        if ( it != m_children.end() )
100        {
101                m_children.erase( it );
102                m_children.push_front( child );
103                return true;
104        }       
105        return false;
106}
107
108element::~element()
109{
110        delete m_render_data;
111}
Note: See TracBrowser for help on using the repository browser.