moved wxWave, wxJoystick and wxTaskBarIcon to wxAdvanced
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22490 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1,368 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: joystick.cpp
|
||||
// Purpose: wxJoystick class
|
||||
// Author: Ported to Linux by Guilhem Lavaux
|
||||
// Modified by:
|
||||
// Created: 05/23/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Guilhem Lavaux
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "joystick.h"
|
||||
#endif
|
||||
|
||||
#include "wx/defs.h"
|
||||
|
||||
#if wxUSE_JOYSTICK
|
||||
|
||||
#include "wx/joystick.h"
|
||||
|
||||
#include <linux/joystick.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "wx/event.h"
|
||||
#include "wx/window.h"
|
||||
|
||||
#define JOYSTICK_AXE_MAX 32767
|
||||
#define JOYSTICK_AXE_MIN -32767
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxJoystick, wxObject)
|
||||
|
||||
wxJoystick::wxJoystick(int joystick)
|
||||
{
|
||||
wxString dev_name;
|
||||
// Assume it's the same device name on all Linux systems ...
|
||||
dev_name.Printf( wxT("/dev/js%d"), (joystick == wxJOYSTICK1) ? 0 : 1); // FIXME Unicode?
|
||||
|
||||
m_joystick = open(dev_name.fn_str(), O_RDWR);
|
||||
m_lastposition = wxPoint(-1, -1);
|
||||
for (int i=0;i<15;i++)
|
||||
m_axe[i] = 0;
|
||||
if (m_joystick != -1)
|
||||
Create();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Background thread
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
void *wxJoystick::Entry(void)
|
||||
{
|
||||
struct js_event j_evt;
|
||||
wxJoystickEvent jwx_event;
|
||||
fd_set read_fds;
|
||||
struct timeval time_out = {0, 0};
|
||||
|
||||
FD_ZERO(&read_fds);
|
||||
while (1) {
|
||||
TestDestroy();
|
||||
|
||||
if (m_polling) {
|
||||
FD_SET(m_joystick, &read_fds);
|
||||
select(m_joystick+1, &read_fds, NULL, NULL, &time_out);
|
||||
if (FD_ISSET(m_joystick, &read_fds))
|
||||
read(m_joystick, &j_evt, sizeof(j_evt));
|
||||
else
|
||||
j_evt.type = 0;
|
||||
} else {
|
||||
read(m_joystick, &j_evt, sizeof(j_evt));
|
||||
}
|
||||
|
||||
if ((j_evt.type & JS_EVENT_AXIS) == JS_EVENT_AXIS) {
|
||||
switch (j_evt.number) {
|
||||
case 1:
|
||||
m_lastposition.x = j_evt.value;
|
||||
jwx_event.SetEventType(wxEVT_JOY_MOVE);
|
||||
break;
|
||||
case 2:
|
||||
m_lastposition.y = j_evt.value;
|
||||
jwx_event.SetEventType(wxEVT_JOY_MOVE);
|
||||
break;
|
||||
case 3:
|
||||
m_axe[3] = j_evt.value;
|
||||
jwx_event.SetEventType(wxEVT_JOY_ZMOVE);
|
||||
break;
|
||||
default:
|
||||
m_axe[j_evt.number] = j_evt.value;
|
||||
jwx_event.SetEventType(wxEVT_JOY_MOVE);
|
||||
break;
|
||||
}
|
||||
jwx_event.SetPosition(m_lastposition);
|
||||
jwx_event.SetZPosition(m_axe[3]);
|
||||
}
|
||||
if ((j_evt.type & JS_EVENT_BUTTON) == JS_EVENT_BUTTON) {
|
||||
register int mask = 1 << j_evt.number;
|
||||
char button = m_buttons & mask;
|
||||
|
||||
m_buttons &= ~mask;
|
||||
if (button) {
|
||||
jwx_event.SetEventType(wxEVT_JOY_BUTTON_UP);
|
||||
} else {
|
||||
jwx_event.SetEventType(wxEVT_JOY_BUTTON_DOWN);
|
||||
m_buttons |= mask;
|
||||
}
|
||||
|
||||
jwx_event.SetButtonState(m_buttons);
|
||||
jwx_event.SetButtonChange(j_evt.number);
|
||||
}
|
||||
}
|
||||
if (m_catchwin)
|
||||
m_catchwin->ProcessEvent(jwx_event);
|
||||
if (m_polling)
|
||||
usleep(m_polling*1000);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// State
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxPoint wxJoystick::GetPosition(void) const
|
||||
{
|
||||
return m_lastposition;
|
||||
}
|
||||
|
||||
int wxJoystick::GetZPosition(void) const
|
||||
{
|
||||
return m_axe[3];
|
||||
}
|
||||
|
||||
int wxJoystick::GetButtonState(void) const
|
||||
{
|
||||
return m_buttons;
|
||||
}
|
||||
|
||||
int wxJoystick::GetPOVPosition(void) const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wxJoystick::GetPOVCTSPosition(void) const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wxJoystick::GetRudderPosition(void) const
|
||||
{
|
||||
return m_axe[4];
|
||||
}
|
||||
|
||||
int wxJoystick::GetUPosition(void) const
|
||||
{
|
||||
return m_axe[5];
|
||||
}
|
||||
|
||||
int wxJoystick::GetVPosition(void) const
|
||||
{
|
||||
return m_axe[6];
|
||||
}
|
||||
|
||||
int wxJoystick::GetMovementThreshold(void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void wxJoystick::SetMovementThreshold(int threshold)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Capabilities
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool wxJoystick::IsOk(void) const
|
||||
{
|
||||
return (m_joystick != -1);
|
||||
}
|
||||
|
||||
int wxJoystick::GetNumberJoysticks(void) const
|
||||
{
|
||||
wxString dev_name;
|
||||
int fd, j;
|
||||
|
||||
for (j=0;j<2;j++) {
|
||||
dev_name.Printf(wxT("/dev/js%d"), j);
|
||||
fd = open(dev_name.fn_str(), O_RDONLY);
|
||||
if (fd == -1)
|
||||
return j;
|
||||
close(fd);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
int wxJoystick::GetManufacturerId(void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wxJoystick::GetProductId(void) const
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
wxString wxJoystick::GetProductName(void) const
|
||||
{
|
||||
wxString dev_name;
|
||||
// 2002-08-20 johan@linkdata.se
|
||||
// Return the device name in lieu of a better one
|
||||
dev_name.Printf( wxT("/dev/js%d"), (m_joystick == wxJOYSTICK1) ? 0 : 1); // FIXME Unicode?
|
||||
return dev_name;
|
||||
}
|
||||
|
||||
int wxJoystick::GetXMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetYMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetZMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetXMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetYMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetZMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetNumberButtons(void) const
|
||||
{
|
||||
int nb;
|
||||
|
||||
ioctl(m_joystick, JSIOCGBUTTONS, &nb);
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
int wxJoystick::GetNumberAxes(void) const
|
||||
{
|
||||
int nb;
|
||||
|
||||
ioctl(m_joystick, JSIOCGAXES, &nb);
|
||||
|
||||
return nb;
|
||||
}
|
||||
|
||||
int wxJoystick::GetMaxButtons(void) const
|
||||
{
|
||||
return 15; // internal
|
||||
}
|
||||
|
||||
int wxJoystick::GetMaxAxes(void) const
|
||||
{
|
||||
return 15; // internal
|
||||
}
|
||||
|
||||
int wxJoystick::GetPollingMin(void) const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wxJoystick::GetPollingMax(void) const
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
int wxJoystick::GetRudderMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MIN;
|
||||
}
|
||||
|
||||
int wxJoystick::GetRudderMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetUMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MIN;
|
||||
}
|
||||
|
||||
int wxJoystick::GetUMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
int wxJoystick::GetVMin(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MIN;
|
||||
}
|
||||
|
||||
int wxJoystick::GetVMax(void) const
|
||||
{
|
||||
return JOYSTICK_AXE_MAX;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasRudder(void) const
|
||||
{
|
||||
return GetNumberAxes() >= 4;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasZ(void) const
|
||||
{
|
||||
return GetNumberAxes() >= 3;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasU(void) const
|
||||
{
|
||||
return GetNumberAxes() >= 5;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasV(void) const
|
||||
{
|
||||
return GetNumberAxes() >= 6;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasPOV(void) const
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasPOV4Dir(void) const
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
bool wxJoystick::HasPOVCTS(void) const
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Operations
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
bool wxJoystick::SetCapture(wxWindow* win, int pollingFreq)
|
||||
{
|
||||
m_catchwin = win;
|
||||
m_polling = pollingFreq;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxJoystick::ReleaseCapture(void)
|
||||
{
|
||||
m_catchwin = NULL;
|
||||
m_polling = 0;
|
||||
return TRUE;
|
||||
}
|
||||
#endif // wxUSE_JOYSTICK
|
||||
|
@@ -1,228 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Name: wave.cpp
|
||||
// Purpose: wxWave
|
||||
// Author: Marcel Rasche
|
||||
// Modified by:
|
||||
// Created: 25/10/98
|
||||
// RCS-ID: $Id$
|
||||
// Copyright: (c) Julian Smart
|
||||
// Licence: wxWindows licence
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __GNUG__
|
||||
#pragma implementation "wave.h"
|
||||
#endif
|
||||
|
||||
#include "wx/setup.h"
|
||||
|
||||
#if wxUSE_WAVE
|
||||
|
||||
// For compilers that support precompilation, includes "wx.h".
|
||||
#include "wx/wxprec.h"
|
||||
|
||||
#if defined(__BORLANDC__)
|
||||
#pragma hdrstop
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <linux/soundcard.h>
|
||||
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/wx.h"
|
||||
#endif
|
||||
|
||||
#include "wx/file.h"
|
||||
#include "wx/wave.h"
|
||||
|
||||
//-----------------------------------------------------------------
|
||||
// wxWave
|
||||
//-----------------------------------------------------------------
|
||||
|
||||
wxWave::wxWave()
|
||||
: m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
wxWave::wxWave(const wxString& sFileName, bool isResource)
|
||||
: m_waveData(NULL), m_waveLength(0), m_isResource(isResource)
|
||||
{
|
||||
Create(sFileName, isResource);
|
||||
}
|
||||
|
||||
wxWave::wxWave(int size, const wxByte* data)
|
||||
: m_waveData(NULL), m_waveLength(0), m_isResource(FALSE)
|
||||
{
|
||||
Create(size, data);
|
||||
}
|
||||
|
||||
wxWave::~wxWave()
|
||||
{
|
||||
Free();
|
||||
}
|
||||
|
||||
bool wxWave::Create(const wxString& fileName, bool isResource)
|
||||
{
|
||||
Free();
|
||||
|
||||
if (isResource)
|
||||
{
|
||||
// todo
|
||||
return (m_waveData ? TRUE : FALSE);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_isResource = FALSE;
|
||||
|
||||
wxFile fileWave;
|
||||
if (!fileWave.Open(fileName, wxFile::read))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
m_waveLength = (int) fileWave.Length();
|
||||
|
||||
m_waveData = new wxByte[m_waveLength];
|
||||
if (!m_waveData)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
fileWave.Read(m_waveData, m_waveLength);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
bool wxWave::Create(int size, const wxByte* data)
|
||||
{
|
||||
Free();
|
||||
m_isResource = FALSE;
|
||||
m_waveLength=size;
|
||||
m_waveData = new wxByte[size];
|
||||
if (!m_waveData)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for (int i=0; i<size; i++) m_waveData[i] = data[i];
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxWave::Play(bool async, bool looped)
|
||||
{
|
||||
if (!IsOk()) return FALSE;
|
||||
|
||||
int dev = OpenDSP();
|
||||
|
||||
if (dev<0) return FALSE;
|
||||
|
||||
ioctl(dev,SNDCTL_DSP_SYNC,0);
|
||||
|
||||
bool play=TRUE;
|
||||
int i,l=0;
|
||||
do
|
||||
{
|
||||
i= (int)((l+m_DSPblkSize) < m_sizeData ? m_DSPblkSize : (m_sizeData-l));
|
||||
if ( write(dev,&m_data[l],i) != i )
|
||||
{
|
||||
play=FALSE;
|
||||
}
|
||||
l +=i;
|
||||
} while (play == TRUE && l<m_sizeData);
|
||||
|
||||
close(dev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
bool wxWave::Free()
|
||||
{
|
||||
if (m_waveData)
|
||||
{
|
||||
delete[] m_waveData;
|
||||
m_waveData = NULL;
|
||||
m_waveLength = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned long uiSize;
|
||||
unsigned short uiFormatTag;
|
||||
unsigned short uiChannels;
|
||||
unsigned long ulSamplesPerSec;
|
||||
unsigned long ulAvgBytesPerSec;
|
||||
unsigned short uiBlockAlign;
|
||||
unsigned short uiBitsPerSample;
|
||||
} WAVEFORMAT;
|
||||
|
||||
#define MONO 1 // and stereo is 2 by wav format
|
||||
#define WAVE_FORMAT_PCM 1
|
||||
#define WAVE_INDEX 8
|
||||
#define FMT_INDEX 12
|
||||
|
||||
int wxWave::OpenDSP(void)
|
||||
{
|
||||
WAVEFORMAT waveformat;
|
||||
int dev=-1;
|
||||
unsigned long ul;
|
||||
|
||||
if (m_waveLength < (int)(32+sizeof(WAVEFORMAT)))
|
||||
return -1;
|
||||
|
||||
memcpy(&waveformat,&m_waveData[FMT_INDEX+4],sizeof(WAVEFORMAT));
|
||||
|
||||
if (memcmp(m_waveData, "RIFF", 4) != 0)
|
||||
return -1;
|
||||
if (memcmp(&m_waveData[WAVE_INDEX], "WAVE", 4) != 0)
|
||||
return -1;
|
||||
if (memcmp(&m_waveData[FMT_INDEX], "fmt ", 4) != 0)
|
||||
return -1;
|
||||
if (memcmp(&m_waveData[FMT_INDEX+waveformat.uiSize+8], "data", 4) != 0)
|
||||
return -1;
|
||||
memcpy(&ul,&m_waveData[FMT_INDEX+waveformat.uiSize+12],4);
|
||||
m_sizeData=ul;
|
||||
if ((int)(m_sizeData+FMT_INDEX+waveformat.uiSize+16) != m_waveLength)
|
||||
return -1;
|
||||
m_data=(char *)(&m_waveData[FMT_INDEX+waveformat.uiSize+8]);
|
||||
|
||||
if (waveformat.uiFormatTag != WAVE_FORMAT_PCM)
|
||||
return -1;
|
||||
if (waveformat.ulSamplesPerSec != waveformat.ulAvgBytesPerSec/waveformat.uiBlockAlign)
|
||||
return -1;
|
||||
|
||||
if ((dev = open(AUDIODEV,O_RDWR,0)) <0)
|
||||
return -1;
|
||||
|
||||
if (!InitDSP(dev,(int)waveformat.uiBitsPerSample,waveformat.uiChannels == MONO ? 0:1,waveformat.ulSamplesPerSec))
|
||||
{
|
||||
close(dev);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return dev;
|
||||
}
|
||||
|
||||
bool wxWave::InitDSP(int dev, int iDataBits, int iChannel,unsigned long ulSamplingRate)
|
||||
{
|
||||
if ( ioctl(dev,SNDCTL_DSP_GETBLKSIZE,&m_DSPblkSize) < 0 )
|
||||
return FALSE;
|
||||
if (m_DSPblkSize < 4096 || m_DSPblkSize > 65536)
|
||||
return FALSE;
|
||||
if ( ioctl(dev,SNDCTL_DSP_SAMPLESIZE,&iDataBits) < 0 )
|
||||
return FALSE;
|
||||
if ( ioctl(dev,SNDCTL_DSP_STEREO,&iChannel) < 0 )
|
||||
return FALSE;
|
||||
if ( ioctl(dev,SNDCTL_DSP_SPEED,&ulSamplingRate) < 0 )
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user