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

Last change on this file since 522 was 505, checked in by epyon, 9 years ago
  • several STL updates
  • several minor fixes
File size: 3.4 KB
RevLine 
[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
[470]9#include <nv/core/time.hh>
10
[352]11wxBEGIN_EVENT_TABLE( nv::wx_gl_canvas, wxWindow )
12EVT_PAINT( nv::wx_gl_canvas::on_paint )
13wxEND_EVENT_TABLE()
14
[505]15nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, input* in )
[352]16        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
17        wxFULL_REPAINT_ON_RESIZE )
18{
19        nv::load_gl_no_context();
20        wxClientDC dc( this );
[505]21        m_render  = true;
22        m_wm      = new nv::sdl::window_manager;
23        m_device  = new nv::gl_device();
24        if ( !in ) in = new nv::sdl::input;
25        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
26        m_context = m_window->get_context();
27        m_main    = true;
28}
29
30nv::wx_gl_canvas::wx_gl_canvas( wxWindow *parent, wx_gl_canvas *sibling, input* in )
31        : wxWindow( parent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
32                wxFULL_REPAINT_ON_RESIZE )
33{
34        wxClientDC dc( this );
[353]35        m_render = true;
[505]36        m_wm = sibling->m_wm;
[352]37        m_device = new nv::gl_device();
[505]38        if ( !in ) in = new nv::sdl::input;
39        m_window = new nv::gl_window( m_device, m_wm, in, GetHWND(), dc.GetHDC() );
[352]40        m_context = m_window->get_context();
[505]41        make_current();
42        m_main = false;
43
[352]44}
45
46nv::wx_gl_canvas::~wx_gl_canvas()
47{
[505]48        make_current();
[352]49        delete m_window;
50        delete m_device;
51}
52
53void nv::wx_gl_canvas::on_paint( wxPaintEvent& )
54{
[505]55        make_current();
[352]56        const wxSize client_size = GetClientSize();
57        m_context->set_viewport( nv::ivec4( nv::ivec2(), client_size.x, client_size.y ) );
58        on_update();
59}
60
61void nv::wx_gl_canvas::stop()
62{
63        Disconnect( wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
64        //m_update_timer->Stop();
65}
66
67void nv::wx_gl_canvas::start()
68{
69        Connect( wxID_ANY, wxEVT_IDLE, wxIdleEventHandler( wx_gl_canvas::on_idle ) );
70        //m_update_timer->Start(20);
71}
72
73void nv::wx_gl_canvas::on_idle( wxIdleEvent& evt )
74{
[505]75        nv::sleep( 1 );
[352]76        if ( m_render )
77        {
[505]78                make_current();
[352]79                on_update();
80                evt.RequestMore(); // render continuously, not only once on idle
81        }
82}
83
[505]84void nv::wx_gl_canvas::make_current()
85{
86        m_window->make_current();
87}
88
[352]89nv::wx_log_text_ctrl_sink::wx_log_text_ctrl_sink( wxTextCtrl* a_text_ctrl ) : m_text_ctrl( a_text_ctrl )
90{
91
92}
93
[467]94static wxColor wx_log_color[] =
95{
96        wxColor( *wxWHITE ),
97        wxColor( *wxRED ),
98        wxColor( *wxRED ),
99        wxColor( *wxRED ),
100        wxColor( *wxYELLOW ),
101        wxColor( *wxGREEN ),
102        wxColor( *wxLIGHT_GREY ),
103        wxColor( *wxLIGHT_GREY ),
104        wxColor( *wxLIGHT_GREY ),
105        wxColor( *wxLIGHT_GREY ),
106        wxColor( *wxLIGHT_GREY ),
107};
108
[410]109void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message )
[352]110{
111        wxString str;
[410]112        char stamp[16];
113        size_t ssize = timestamp( stamp );
[467]114        m_text_ctrl->SetDefaultStyle( wxTextAttr( wx_log_color[ level / 10 ] ) );
115        str << "[" << padded_level_name( level ).data() << "] " << message.data() << "\n";
[352]116        m_text_ctrl->AppendText( str );
117}
118
119nv::wx_app_base::wx_app_base()
[410]120        : m_logger( nv::LOG_TRACE )
[352]121{
[410]122        nv::log_sink* sink = new nv::log_file_sink( "log.txt" );
123        m_logger.add_sink( sink, nv::LOG_TRACE );
[352]124        NV_LOG( nv::LOG_NOTICE, "Logging started" );
125}
126
127bool nv::wx_app_base::OnInit()
128{
129        if ( !wxApp::OnInit() )
130                return false;
131
132        return initialize();
133}
134
135int nv::wx_app_base::OnExit()
136{
137        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
138        return wxApp::OnExit();
139}
Note: See TracBrowser for help on using the repository browser.