// Copyright (C) 2014-2015 ChaosForge Ltd // http://chaosforge.org/ // // This file is part of Nova libraries. // For conditions of distribution and use, see copying.txt file in root folder. #include #include wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow ) EVT_PAINT( nv::wx_gl_canvas::on_paint ) wxEND_EVENT_TABLE() nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent ) : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE ) { nv::load_gl_no_context(); wxClientDC dc( this ); m_render = true; m_wm = new nv::sdl::window_manager; m_device = new nv::gl_device(); m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() ); m_context = m_window->get_context(); } nv::wx_gl_canvas::~wx_gl_canvas() { delete m_window; delete m_device; } void nv::wx_gl_canvas::on_paint( wxPaintEvent& ) { const wxSize client_size = GetClientSize(); m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) ); on_update(); } void nv::wx_gl_canvas::stop() { Disconnect( wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) ); //m_update_timer->Stop(); } void nv::wx_gl_canvas::start() { Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) ); //m_update_timer->Start(20); } void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt ) { nv::sleep( 10 ); if ( m_render ) { on_update(); evt.RequestMore(); // render continuously, not only once on idle } } nv::wx_log_text_ctrl_sink::wx_log_text_ctrl_sink( wxTextCtrl* a_text_ctrl ) : m_text_ctrl( a_text_ctrl ) { } static wxColor wx_log_color[] = { wxColor( *wxWHITE ), wxColor( *wxRED ), wxColor( *wxRED ), wxColor( *wxRED ), wxColor( *wxYELLOW ), wxColor( *wxGREEN ), wxColor( *wxLIGHT_GREY ), wxColor( *wxLIGHT_GREY ), wxColor( *wxLIGHT_GREY ), wxColor( *wxLIGHT_GREY ), wxColor( *wxLIGHT_GREY ), }; void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message ) { wxString str; char stamp[16]; size_t ssize = timestamp( stamp ); m_text_ctrl->SetDefaultStyle( wxTextAttr( wx_log_color[ level / 10 ] ) ); str << "[" << padded_level_name( level ).data() << "] " << message.data() << "\n"; m_text_ctrl->AppendText( str ); } nv::wx_app_base::wx_app_base() : m_logger( nv::LOG_TRACE ) { nv::log_sink* sink = new nv::log_file_sink( "log.txt" ); m_logger.add_sink( sink, nv::LOG_TRACE ); NV_LOG( nv::LOG_NOTICE, "Logging started" ); } bool nv::wx_app_base::OnInit() { if ( !wxApp::OnInit() ) return false; return initialize(); } int nv::wx_app_base::OnExit() { NV_LOG( nv::LOG_NOTICE, "Logging stopped" ); return wxApp::OnExit(); }