source: trunk/src/wx/wx_canvas.cc @ 352

Last change on this file since 352 was 352, checked in by epyon, 10 years ago
  • rocket utility classes
  • wx utility classes
  • various utilities
  • handle_test
  • various more changes
File size: 2.2 KB
Line 
1// Copyright (C) 2014 ChaosForge Ltd
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/wx/wx_canvas.hh>
8
9wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow )
10EVT_PAINT( nv::wx_gl_canvas::on_paint )
11wxEND_EVENT_TABLE()
12
13nv::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 );
19        m_wm = new nv::sdl::window_manager;
20        m_device = new nv::gl_device();
21        m_window = new nv::gl_window( m_device, m_wm, new nv::sdl::input(), GetHWND(), dc.GetHDC() );
22        m_context = m_window->get_context();
23}
24
25nv::wx_gl_canvas::~wx_gl_canvas()
26{
27        delete m_window;
28        delete m_device;
29}
30
31void nv::wx_gl_canvas::on_paint( wxPaintEvent& )
32{
33        const wxSize client_size = GetClientSize();
34        m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) );
35        on_update();
36}
37
38void nv::wx_gl_canvas::stop()
39{
40        Disconnect( wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
41        //m_update_timer->Stop();
42}
43
44void nv::wx_gl_canvas::start()
45{
46        Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
47        //m_update_timer->Start(20);
48}
49
50void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
51{
52        if ( m_render )
53        {
54                on_update();
55                evt.RequestMore(); // render continuously, not only once on idle
56        }
57}
58
59nv::wx_log_text_ctrl_sink::wx_log_text_ctrl_sink( wxTextCtrl* a_text_ctrl ) : m_text_ctrl( a_text_ctrl )
60{
61
62}
63
64void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const std::string& message )
65{
66        wxString str;
67        str << timestamp() << " [" << padded_level_name( level ) << "] " << message << "\n";
68        m_text_ctrl->AppendText( str );
69}
70
71nv::wx_app_base::wx_app_base()
72{
73        static nv::logger log( nv::LOG_TRACE );
74        log.add_sink( new nv::log_file_sink( "log.txt" ), nv::LOG_TRACE );
75        NV_LOG( nv::LOG_NOTICE, "Logging started" );
76}
77
78bool nv::wx_app_base::OnInit()
79{
80        if ( !wxApp::OnInit() )
81                return false;
82
83        return initialize();
84}
85
86int nv::wx_app_base::OnExit()
87{
88        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
89        return wxApp::OnExit();
90}
Note: See TracBrowser for help on using the repository browser.