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

Last change on this file since 66 was 66, checked in by epyon, 12 years ago
  • gui_element class and gui_common file
  • additions to object class
File size: 1.7 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( root* aroot, const rectangle r )
13        : object( aroot, "", 0 ), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true )
14{
15
16}
17
18void element::on_update( uint32 elapsed )
19{
20        if ( is_visible() )
21        {
22                for ( object* i : *this )
23                {
24                        ((element*)i)->on_update( elapsed );
25                }
26        }
27}
28
29void element::on_draw()
30{
31        if ( is_visible() )
32        {
33                for ( object* i : *this )
34                {
35                        ((element*)i)->on_draw();
36                }
37        }
38}
39
40element* element::get_element( const position& p )
41{
42        if ( !is_visible() ) return nullptr;
43
44        element* result = nullptr;
45        list::reverse_iterator it = m_children.rbegin();
46
47        while ( it != m_children.rend() )
48        {
49                result = ((element*)(*it))->get_element( p );
50                if ( result ) return result;
51                ++it;
52        }
53
54        if ( contains( p ) ) return this;
55        return nullptr;
56}
57
58bool element::contains( const position& p ) const
59{
60        return m_absolute.contains( p );
61}
62
63void element::set_relative( const rectangle& r )
64{
65        m_relative = r;
66        recalculate_absolute();
67}
68
69void element::set_relative( const position& p )
70{
71        set_relative( rectangle( p, p + m_relative.get_size() ) );
72}
73
74void element::recalculate_absolute()
75{
76        rectangle pabsolute;
77
78        if ( m_parent )
79        {
80                pabsolute = ((element*)(m_parent))->m_absolute;
81        }
82
83        m_absolute = m_relative + pabsolute.upper_left;
84
85        for ( object* o : *this )
86        {
87                ((element*)o)->recalculate_absolute();
88        }
89}
Note: See TracBrowser for help on using the repository browser.