[395] | 1 | // Copyright (C) 2014-2015 ChaosForge Ltd
|
---|
[352] | 2 | // http://chaosforge.org/
|
---|
| 3 | //
|
---|
[395] | 4 | // This file is part of Nova libraries.
|
---|
| 5 | // For conditions of distribution and use, see copying.txt file in root folder.
|
---|
[352] | 6 |
|
---|
| 7 | #include <nv/wx/wx_canvas.hh>
|
---|
| 8 |
|
---|
| 9 | wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow )
|
---|
| 10 | EVT_PAINT( nv::wx_gl_canvas::on_paint )
|
---|
| 11 | wxEND_EVENT_TABLE()
|
---|
| 12 |
|
---|
| 13 | nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent )
|
---|
| 14 | : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
---|
| 15 | wxFULL_REPAINT_ON_RESIZE )
|
---|
| 16 | {
|
---|
| 17 | nv::load_gl_no_context();
|
---|
| 18 | wxClientDC dc( this );
|
---|
[353] | 19 | m_render = true;
|
---|
[352] | 20 | m_wm = new nv::sdl::window_manager;
|
---|
| 21 | m_device = new nv::gl_device();
|
---|
| 22 | m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() );
|
---|
| 23 | m_context = m_window->get_context();
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | nv::wx_gl_canvas::~wx_gl_canvas()
|
---|
| 27 | {
|
---|
| 28 | delete m_window;
|
---|
| 29 | delete m_device;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | void nv::wx_gl_canvas::on_paint( wxPaintEvent& )
|
---|
| 33 | {
|
---|
| 34 | const wxSize client_size = GetClientSize();
|
---|
| 35 | m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) );
|
---|
| 36 | on_update();
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | void nv::wx_gl_canvas::stop()
|
---|
| 40 | {
|
---|
| 41 | Disconnect( wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
|
---|
| 42 | //m_update_timer->Stop();
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | void nv::wx_gl_canvas::start()
|
---|
| 46 | {
|
---|
| 47 | Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
|
---|
| 48 | //m_update_timer->Start(20);
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
|
---|
| 52 | {
|
---|
| 53 | if ( m_render )
|
---|
| 54 | {
|
---|
| 55 | on_update();
|
---|
| 56 | evt.RequestMore(); // render continuously, not only once on idle
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | nv::wx_log_text_ctrl_sink::wx_log_text_ctrl_sink( wxTextCtrl* a_text_ctrl ) : m_text_ctrl( a_text_ctrl )
|
---|
| 61 | {
|
---|
| 62 |
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const std::string& message )
|
---|
| 66 | {
|
---|
| 67 | wxString str;
|
---|
| 68 | str << timestamp() << " [" << padded_level_name( level ) << "] " << message << "\n";
|
---|
| 69 | m_text_ctrl->AppendText( str );
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | nv::wx_app_base::wx_app_base()
|
---|
| 73 | {
|
---|
| 74 | static nv::logger log( nv::LOG_TRACE );
|
---|
| 75 | log.add_sink( new nv::log_file_sink( "log.txt" ), nv::LOG_TRACE );
|
---|
| 76 | NV_LOG( nv::LOG_NOTICE, "Logging started" );
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | bool nv::wx_app_base::OnInit()
|
---|
| 80 | {
|
---|
| 81 | if ( !wxApp::OnInit() )
|
---|
| 82 | return false;
|
---|
| 83 |
|
---|
| 84 | return initialize();
|
---|
| 85 | }
|
---|
| 86 |
|
---|
| 87 | int nv::wx_app_base::OnExit()
|
---|
| 88 | {
|
---|
| 89 | NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
|
---|
| 90 | return wxApp::OnExit();
|
---|
| 91 | }
|
---|