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

Last change on this file since 450 was 410, checked in by epyon, 10 years ago
  • merge of vertex_descriptor and key_descriptor concepts - unified raw data description via data_descriptor
  • minor bugfixes
File size: 2.3 KB
Line 
1// Copyright (C) 2014-2015 ChaosForge Ltd
2// http://chaosforge.org/
3//
4// This file is part of Nova libraries.
5// For conditions of distribution and use, see copying.txt file in root folder.
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_render = true;
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
26nv::wx_gl_canvas::~wx_gl_canvas()
27{
28        delete m_window;
29        delete m_device;
30}
31
32void 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
39void nv::wx_gl_canvas::stop()
40{
41        Disconnect( wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
42        //m_update_timer->Stop();
43}
44
45void 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
51void 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
60nv::wx_log_text_ctrl_sink::wx_log_text_ctrl_sink( wxTextCtrl* a_text_ctrl ) : m_text_ctrl( a_text_ctrl )
61{
62
63}
64
65void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message )
66{
67        wxString str;
68        char stamp[16];
69        size_t ssize = timestamp( stamp );
70        str << stamp << " [" << padded_level_name( level ).data() << "] " << message.data() << "\n";
71        m_text_ctrl->AppendText( str );
72}
73
74nv::wx_app_base::wx_app_base()
75        : m_logger( nv::LOG_TRACE )
76{
77        nv::log_sink* sink = new nv::log_file_sink( "log.txt" );
78        m_logger.add_sink( sink, nv::LOG_TRACE );
79        NV_LOG( nv::LOG_NOTICE, "Logging started" );
80}
81
82bool nv::wx_app_base::OnInit()
83{
84        if ( !wxApp::OnInit() )
85                return false;
86
87        return initialize();
88}
89
90int nv::wx_app_base::OnExit()
91{
92        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
93        return wxApp::OnExit();
94}
Note: See TracBrowser for help on using the repository browser.