source: trunk/tests/gui_test/nv_gui_test.cc @ 321

Last change on this file since 321 was 321, checked in by epyon, 11 years ago
  • updated all tests to new nova
  • cleaned up tests paths
  • general cleanup of tests and test data
File size: 3.2 KB
RevLine 
[127]1#include <nv/gl/gl_device.hh>
2#include <nv/gui/gui_environment.hh>
[239]3#include <nv/interface/context.hh>
[319]4#include <nv/core/logging.hh>
5#include <nv/core/logger.hh>
[321]6#include <nv/core/random.hh>
[127]7
8class application
9{
10public:
11        application();
12        bool initialize();
13        bool run();
14        void kill_window();
15        void spawn_window();
16        void recolor_window();
[267]17//      void bring_to_front( int i );
[127]18        ~application();
19protected:
20        nv::device* m_device;
21        nv::window* m_window;
22        nv::clear_state m_clear_state;
23        nv::gui::environment* m_guienv;
[269]24        std::vector<nv::gui::handle>   m_windows;
[127]25};
26
27application::application()
28{
29        m_device = new nv::gl_device();
[229]30        m_window = m_device->create_window( 800, 600, false );
[127]31        m_clear_state.buffers = nv::clear_state::COLOR_AND_DEPTH_BUFFER;
32        m_guienv = new nv::gui::environment( m_window );
33        m_guienv->load_style( "test.style.lua" );
34}
35
36bool application::initialize()
37{
38        return true;
39}
40
41bool application::run()
42{
43        int keypress = 0;
44
45        while(!keypress)
46        {
47                m_guienv->update();
48
49                m_window->get_context()->clear( m_clear_state );
50                m_guienv->draw();
51                m_window->swap_buffers();
52
53                nv::io_event event;
54                while(m_window->poll_event(event))
55                {     
56                        switch (event.type)
57                        {
58                        case nv::EV_QUIT:
59                                keypress = 1;
60                                break;
61                        case nv::EV_KEY:
62                                if (event.key.pressed)
63                                {
64                                        switch (event.key.code)
65                                        {
[267]66//                                      case nv::KEY_1      : bring_to_front(0); break;
67//                                      case nv::KEY_2      : bring_to_front(1); break;
68//                                      case nv::KEY_3      : bring_to_front(2); break;
69//                                      case nv::KEY_4      : bring_to_front(3); break;
70//                                      case nv::KEY_5      : bring_to_front(4); break;
[127]71                                        case nv::KEY_N      : spawn_window(); break;
72                                        case nv::KEY_K      : kill_window(); break;
73                                        case nv::KEY_ESCAPE : keypress = 1; break;
74                                        }
75                                }
76                                break;
77                        }
78                }
79        }
80        return true;
81}
82
83void application::spawn_window()
84{
[321]85        nv::ivec2 a = nv::random::get().range( nv::ivec2(), nv::ivec2( 600, 400 ) );
86        nv::ivec2 b = nv::random::get().range( nv::ivec2( 40, 40 ), nv::ivec2( 240, 240 ) );
[269]87        nv::gui::handle e = m_guienv->create_element( nv::rectangle(a).dim(b) );
[268]88        m_guienv->set_class( e, "window" );
89        m_guienv->set_text( e, "Window "+nv::to_string(m_windows.size()+1) );
[127]90        NV_LOG( nv::LOG_INFO, "Spawn (" << a.x << "," << a.y << "x" << b.x << "," << b.y << ")" );
91        m_windows.push_back( e );
92}
93
94void application::kill_window()
95{
96        if ( m_windows.size() == 0 ) return;
[321]97        size_t index = nv::random::get().urand( m_windows.size() );
[267]98        m_guienv->destroy_element( m_windows[index] );
[127]99        m_windows.erase( m_windows.begin() + index );
100}
101
102application::~application()
103{
104        m_windows.clear();
105        delete m_window;
106        delete m_device;
107}
108
[267]109// void application::bring_to_front( int i )
110// {
111//      if ( i >= 0 && i < m_windows.size() )
112//      {
113//              m_guienv->bring_to_front( m_windows[i] );
114//      }
115// }
116
[127]117int main(int, char* [])
118{
[321]119        nv::random::get().randomize();
[127]120        nv::logger log(nv::LOG_TRACE);
121        log.add_sink( new nv::log_file_sink("log.txt"), nv::LOG_TRACE );
122        log.add_sink( new nv::log_console_sink(), nv::LOG_TRACE );
123       
124        NV_LOG( nv::LOG_NOTICE, "Logging started" );
125        application app;
126        if ( app.initialize() )
127        {
128                app.run();
129        }
130        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
131
132        return 0;
133}
134
Note: See TracBrowser for help on using the repository browser.