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

Last change on this file since 469 was 467, checked in by epyon, 10 years ago
  • wx_canvas - color logging
  • string - _sh64/_sh32 literal support
  • skeletal_mesh - removed obsolete CPU support
File size: 2.7 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
65static wxColor wx_log_color[] =
66{
67        wxColor( *wxWHITE ),
68        wxColor( *wxRED ),
69        wxColor( *wxRED ),
70        wxColor( *wxRED ),
71        wxColor( *wxYELLOW ),
72        wxColor( *wxGREEN ),
73        wxColor( *wxLIGHT_GREY ),
74        wxColor( *wxLIGHT_GREY ),
75        wxColor( *wxLIGHT_GREY ),
76        wxColor( *wxLIGHT_GREY ),
77        wxColor( *wxLIGHT_GREY ),
78};
79
80void nv::wx_log_text_ctrl_sink::log( nv::log_level level, const nv::string_view& message )
81{
82        wxString str;
83        char stamp[16];
84        size_t ssize = timestamp( stamp );
85        m_text_ctrl->SetDefaultStyle( wxTextAttr( wx_log_color[ level / 10 ] ) );
86        str << "[" << padded_level_name( level ).data() << "] " << message.data() << "\n";
87        m_text_ctrl->AppendText( str );
88}
89
90nv::wx_app_base::wx_app_base()
91        : m_logger( nv::LOG_TRACE )
92{
93        nv::log_sink* sink = new nv::log_file_sink( "log.txt" );
94        m_logger.add_sink( sink, nv::LOG_TRACE );
95        NV_LOG( nv::LOG_NOTICE, "Logging started" );
96}
97
98bool nv::wx_app_base::OnInit()
99{
100        if ( !wxApp::OnInit() )
101                return false;
102
103        return initialize();
104}
105
106int nv::wx_app_base::OnExit()
107{
108        NV_LOG( nv::LOG_NOTICE, "Logging stopped" );
109        return wxApp::OnExit();
110}
Note: See TracBrowser for help on using the repository browser.