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

Last change on this file since 189 was 126, checked in by epyon, 12 years ago
  • commiting the gui_element/gui_environment and gui_renderer in it's current state
  • the implementation is very WIP though, but too long stayed out of SVN
  • minor fix to c_file_system
File size: 2.2 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
9#include "nv/gui/gui_environment.hh"
10
11using namespace nv;
12using namespace nv::gui;
13
14element::element( root* aroot, const rectangle& r )
15        : object( aroot, "" ), m_class(""), m_relative( r ), m_absolute( r ), m_enabled( true ), m_visible( true ), m_dirty( true ), m_render_data( nullptr )
16{
17
18}
19
20void element::on_update( uint32 elapsed )
21{
22        if ( is_visible() )
23        {
24                for ( object* i : *this )
25                {
26                        ((element*)i)->on_update( elapsed );
27                }
28        }
29        ((environment*)m_root)->update( this, elapsed );
30}
31
32void element::on_draw()
33{
34        if ( is_visible() )
35        {
36                ((environment*)m_root)->draw( this );
37                for ( object* i : *this )
38                {
39                        ((element*)i)->on_draw();
40                }
41        }
42}
43
44bool element::on_event( const io_event& event )
45{
46        return m_parent ? ((element*)m_parent)->on_event( event ) : false;
47}
48
49element* element::get_element( const position& p )
50{
51        if ( !is_visible() ) return nullptr;
52
53        element* result = nullptr;
54        list::reverse_iterator it = m_children.rbegin();
55
56        while ( it != m_children.rend() )
57        {
58                result = ((element*)(*it))->get_element( p );
59                if ( result ) return result;
60                ++it;
61        }
62
63        if ( contains( p ) ) return this;
64        return nullptr;
65}
66
67bool element::contains( const position& p ) const
68{
69        return m_absolute.contains( p );
70}
71
72void element::set_relative( const rectangle& r )
73{
74        m_dirty    = true;
75        m_relative = r;
76        recalculate_absolute();
77}
78
79void element::set_relative( const position& p )
80{
81        set_relative( rectangle( p, p + m_relative.get_size() ) );
82}
83
84void element::recalculate_absolute()
85{
86        rectangle pabsolute;
87
88        if ( m_parent )
89        {
90                pabsolute = ((element*)(m_parent))->m_absolute;
91        }
92
93        m_absolute = m_relative + pabsolute.ul;
94
95        for ( object* o : *this )
96        {
97                ((element*)o)->recalculate_absolute();
98        }
99}
100
101void element::recalculate_absolute_children()
102{
103        for ( object* o : *this )
104        {
105                ((element*)o)->recalculate_absolute();
106        }
107}
108
109element::~element()
110{
111        delete m_render_data;
112}
Note: See TracBrowser for help on using the repository browser.