MotionCal/gui.cpp

153 lines
2.9 KiB
C++
Raw Normal View History

2016-02-16 17:19:44 -08:00
#include "gui.h"
#include "imuread.h"
2016-02-18 01:31:30 -08:00
wxBEGIN_EVENT_TABLE(MyCanvas, wxGLCanvas)
EVT_SIZE(MyCanvas::OnSize)
EVT_PAINT(MyCanvas::OnPaint)
//EVT_CHAR(MyCanvas::OnChar)
//EVT_MOUSE_EVENTS(MyCanvas::OnMouseEvent)
wxEND_EVENT_TABLE()
MyCanvas::MyCanvas(wxWindow *parent, wxWindowID id, int* gl_attrib)
: wxGLCanvas(parent, id, gl_attrib)
{
//m_xrot = 0;
//m_yrot = 0;
//m_numverts = 0;
// Explicitly create a new rendering context instance for this canvas.
m_glRC = new wxGLContext(this);
}
MyCanvas::~MyCanvas()
{
delete m_glRC;
}
void MyCanvas::OnSize(wxSizeEvent& event)
{
//printf("OnSize\n");
if (!IsShownOnScreen()) return;
SetCurrent(*m_glRC);
resize_callback(event.GetSize().x, event.GetSize().y);
}
void MyCanvas::OnPaint( wxPaintEvent& WXUNUSED(event) )
{
//printf("OnPaint\n");
wxPaintDC dc(this);
SetCurrent(*m_glRC);
display_callback();
SwapBuffers();
}
void MyCanvas::InitGL()
{
//printf("Init\n");
SetCurrent(*m_glRC);
visualize_init();
}
2016-02-16 17:19:44 -08:00
BEGIN_EVENT_TABLE(MyFrame,wxFrame)
EVT_MENU(wxID_ABOUT, MyFrame::OnAbout)
EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
2016-02-18 01:31:30 -08:00
EVT_TIMER(ID_TIMER, MyFrame::OnTimer)
2016-02-16 17:19:44 -08:00
END_EVENT_TABLE()
MyFrame::MyFrame(wxWindow *parent, wxWindowID id, const wxString &title,
const wxPoint &position, const wxSize& size, long style) :
wxFrame( parent, id, title, position, size, style )
{
2016-02-18 01:31:30 -08:00
wxMenuBar *menuBar;
wxMenu *menu;
2016-02-19 17:05:16 -08:00
//wxMenuItem *item;
2016-02-18 01:31:30 -08:00
menuBar = new wxMenuBar;
menu = new wxMenu;
menu->Append(wxID_EXIT, wxT("Quit"));
menuBar->Append(menu, wxT("&File"));
2016-02-16 17:19:44 -08:00
2016-02-18 01:31:30 -08:00
menu = new wxMenu;
//item = new wxMenuItem(menu, ID_ABOUT, "About");
menu->Append(wxID_ABOUT, wxT("About"));
menuBar->Append(menu, wxT("&Help"));
SetMenuBar(menuBar);
int gl_attrib[20] =
{ WX_GL_RGBA, WX_GL_MIN_RED, 1, WX_GL_MIN_GREEN, 1,
WX_GL_MIN_BLUE, 1, WX_GL_DEPTH_SIZE, 1,
WX_GL_DOUBLEBUFFER,
2016-02-19 17:05:16 -08:00
0};
2016-02-18 01:31:30 -08:00
m_canvas = new MyCanvas(this, wxID_ANY, gl_attrib);
Show(true);
Raise();
m_canvas->InitGL();
open_port(PORT);
m_timer = new wxTimer(this, ID_TIMER);
m_timer->Start(40, wxTIMER_CONTINUOUS);
}
void MyFrame::OnTimer(wxTimerEvent &event)
{
//printf("OnTimer\n");
read_serial_data();
m_canvas->Refresh();
2016-02-16 17:19:44 -08:00
}
void MyFrame::OnAbout(wxCommandEvent &event)
{
wxMessageDialog dialog(this,
"IMU Read\n\n\nCopyright 2016, PJRC.COM, LLC.",
"About IMUREAD", wxOK|wxICON_INFORMATION);
dialog.ShowModal();
}
void MyFrame::OnQuit( wxCommandEvent &event )
{
Close(true);
}
MyFrame::~MyFrame(void)
{
2016-02-18 01:31:30 -08:00
close_port();
2016-02-16 17:19:44 -08:00
}
IMPLEMENT_APP(MyApp)
MyApp::MyApp()
{
}
bool MyApp::OnInit()
{
// make sure we exit properly on macosx
SetExitOnFrameDelete(true);
wxPoint pos(100, 100);
MyFrame *frame = new MyFrame(NULL, -1, wxT("Teensy"), pos, wxDefaultSize,
wxDEFAULT_FRAME_STYLE & ~(wxMAXIMIZE_BOX | wxRESIZE_BORDER));
frame->Show( true );
return true;
}
int MyApp::OnExit()
{
return 0;
}