X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/45cbbbb3a40b1f0e0a526db27aafcd92c3663ae5..68f2155bb74506ee9c26afbc762543133e0ad1a9:/samples/joytest/joytest.cpp diff --git a/samples/joytest/joytest.cpp b/samples/joytest/joytest.cpp index 3e99d23496..65ca2e196c 100644 --- a/samples/joytest/joytest.cpp +++ b/samples/joytest/joytest.cpp @@ -24,10 +24,6 @@ # error You must set wxUSE_JOYSTICK to 1 in setup.h #endif -#if !wxUSE_STATUSBAR -# error You must set wxUSE_STATUSBAR to 1 in setup.h -#endif - #include "wx/sound.h" #include "wx/joystick.h" @@ -43,6 +39,7 @@ long ypos = -1; int winNumber = 1; +int nButtons = 0; // Initialise this in OnInit, not statically bool MyApp::OnInit() { @@ -54,7 +51,7 @@ bool MyApp::OnInit() } #if wxUSE_SOUND - m_fire.Create(_T("gun.wav")); + m_fire.Create(_T("buttonpress.wav")); #endif // wxUSE_SOUND m_minX = stick.GetXMin(); @@ -87,7 +84,10 @@ bool MyApp::OnInit() // Associate the menu bar with the frame frame->SetMenuBar(menu_bar); +#if wxUSE_STATUSBAR frame->CreateStatusBar(); + frame->SetStatusText(wxString::Format(wxT("Device [%s] (PID:[%i] MID:[%i]) Ready... # of joysticks:[%i]"), stick.GetProductName().c_str(), stick.GetProductId(), stick.GetManufacturerId(), wxJoystick::GetNumberJoysticks())); +#endif // wxUSE_STATUSBAR frame->CenterOnScreen(); frame->Show(true); @@ -106,6 +106,7 @@ MyCanvas::MyCanvas(wxWindow *parent, const wxPoint& pos, const wxSize& size): wxScrolledWindow(parent, wxID_ANY, pos, size, wxSUNKEN_BORDER) { m_stick = new wxJoystick(wxJOYSTICK1); + nButtons = m_stick->GetNumberButtons(); m_stick->SetCapture(this, 10); } @@ -134,7 +135,7 @@ void MyCanvas::OnJoystickEvent(wxJoystickEvent& event) ymax += abs(ymin); pt.y += abs(ymin); } - + // Scale to canvas size int cw, ch; GetSize(&cw, &ch); @@ -151,13 +152,23 @@ void MyCanvas::OnJoystickEvent(wxJoystickEvent& event) xpos = pt.x; ypos = pt.y; +#if wxUSE_STATUSBAR wxString buf; if (event.ButtonDown()) - buf.Printf(_T("Joystick (%d, %d) Fire!"), pt.x, pt.y); + buf.Printf(_T("Joystick (%d, %d) #%i Fire!"), pt.x, pt.y, event.GetButtonChange()); else - buf.Printf(_T("Joystick (%d, %d)"), pt.x, pt.y); + buf.Printf(_T("Joystick (%d, %d) "), pt.x, pt.y); + +/* + for(int i = 0; i < nButtons; ++i) + { + buf += wxString(wxT("[")) + + ((event.GetButtonState() & (1 << i)) ? wxT("Y") : wxT("N")) + wxString(wxT("]")); + } +*/ frame->SetStatusText(buf); +#endif // wxUSE_STATUSBAR #if wxUSE_SOUND if (event.ButtonDown() && wxGetApp().m_fire.IsOk()) @@ -178,11 +189,6 @@ MyFrame::MyFrame(wxFrame *parent, const wxString& title, const wxPoint& pos, canvas = new MyCanvas(this); } -MyFrame::~MyFrame() -{ - // Empty -} - void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true);