Improvements to new emulated wiimote plugin: IR cursor works with mouse or analog stick control. Wiimote mii data is saved/loaded to "User/Wii/mii.bin". Background input checkbox works properly. All reporting modes except the interleaved one should work. Fixed a rumble prob with multiple XInput devices.

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5396 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
Jordan Woyak
2010-04-22 07:11:49 +00:00
parent 140332c02e
commit 7c22b83f66
17 changed files with 622 additions and 270 deletions

View File

@ -76,15 +76,15 @@ void PadSettingCheckBox::UpdateValue()
value = 0.01 * GetValue();
}
PadSettingChoice::PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max )
PadSettingChoice::PadSettingChoice( wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const setting )
: wxChoice( parent, -1, wxDefaultPosition, wxSize( 54, -1 ) )
, value(_value)
, value(setting->value)
{
Append( wxT("0") );
for ( ; min<=max; ++min )
for ( unsigned int i = setting->low; i<=setting->high; ++i )
{
std::ostringstream ss;
ss << min;
ss << i;
Append( wxString::FromAscii( ss.str().c_str() ) );
}
@ -124,10 +124,10 @@ ControlDialog::ControlDialog( wxWindow* const parent, ControllerInterface::Contr
control_chooser = new ControlChooser( this, ref, parent );
wxStaticBoxSizer* d_szr = new wxStaticBoxSizer( wxVERTICAL, this, wxT("Device") );
wxStaticBoxSizer* const d_szr = new wxStaticBoxSizer( wxVERTICAL, this, wxT("Device") );
d_szr->Add( device_cbox, 0, wxEXPAND|wxALL, 5 );
wxBoxSizer* szr = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
szr->Add( d_szr, 0, wxEXPAND|wxLEFT|wxRIGHT|wxTOP, 5 );
szr->Add( control_chooser, 0, wxEXPAND|wxALL, 5 );
@ -416,7 +416,7 @@ void ControlDialog::SelectControl( wxCommandEvent& event )
if (IsBeingDeleted())
return;
wxListBox* lb = (wxListBox*)event.GetEventObject();
wxListBox* const lb = (wxListBox*)event.GetEventObject();
wxArrayInt sels;
lb->GetSelections( sels );
@ -450,14 +450,15 @@ ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::Con
textctrl = new wxTextCtrl( parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
_connect_macro_( textctrl, ControlDialog::SetControl, wxEVT_COMMAND_TEXT_ENTER, parent);
wxButton* detect_button = new wxButton( parent, -1, ref->is_input ? wxT("Detect 1") : wxT("Test") );
wxButton* clear_button = new wxButton( parent, -1, wxT("Clear"), wxDefaultPosition );
wxButton* set_button = new wxButton( parent, -1, wxT("Set")/*, wxDefaultPosition, wxSize( 32, -1 )*/ );
wxButton* const detect_button = new wxButton( parent, -1, ref->is_input ? wxT("Detect 1") : wxT("Test") );
wxButton* const clear_button = new wxButton( parent, -1, wxT("Clear"), wxDefaultPosition );
wxButton* const set_button = new wxButton( parent, -1, wxT("Set")/*, wxDefaultPosition, wxSize( 32, -1 )*/ );
control_lbox = new wxListBox( parent, -1, wxDefaultPosition, wxSize( 256, 128 ), wxArrayString(), wxLB_EXTENDED );
_connect_macro_( control_lbox, ControlDialog::SelectControl, wxEVT_COMMAND_LISTBOX_SELECTED, parent);
wxBoxSizer* button_sizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add( detect_button, 1, 0, 5 );
if ( ref->is_input )
for ( unsigned int i = 2; i<5; ++i )
@ -478,18 +479,19 @@ ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::Con
_connect_macro_( set_button, ControlDialog::SetControl, wxEVT_COMMAND_BUTTON_CLICKED, parent);
_connect_macro_( range_slider, GamepadPage::AdjustControlOption, wxEVT_SCROLL_CHANGED, eventsink);
wxStaticText* range_label = new wxStaticText( parent, -1, wxT("Range"));
wxStaticText* const range_label = new wxStaticText( parent, -1, wxT("Range"));
m_bound_label = new wxStaticText( parent, -1, wxT("") );
wxBoxSizer* range_sizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const range_sizer = new wxBoxSizer( wxHORIZONTAL );
range_sizer->Add( range_label, 0, wxCENTER|wxLEFT, 5 );
range_sizer->Add( range_slider, 1, wxEXPAND|wxLEFT, 5 );
wxBoxSizer* txtbox_szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const txtbox_szr = new wxBoxSizer( wxHORIZONTAL );
txtbox_szr->Add( textctrl, 1, wxEXPAND, 0 );
wxBoxSizer* mode_szr;
Add( range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
if ( control_reference->is_input )
{
mode_cbox = new wxChoice( parent, -1 );
@ -500,14 +502,12 @@ ControlChooser::ControlChooser( wxWindow* const parent, ControllerInterface::Con
_connect_macro_( mode_cbox, GamepadPage::AdjustControlOption, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
mode_szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const mode_szr = new wxBoxSizer( wxHORIZONTAL );
mode_szr->Add( new wxStaticText( parent, -1, wxT("Mode") ), 0, wxCENTER|wxLEFT|wxRIGHT, 5 );
mode_szr->Add( mode_cbox, 0, wxLEFT, 5 );
}
Add( range_sizer, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
if ( control_reference->is_input )
Add( mode_szr, 0, wxEXPAND|wxLEFT|wxRIGHT, 5 );
}
Add( txtbox_szr, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
Add( button_sizer, 0, wxEXPAND|wxBOTTOM|wxLEFT|wxRIGHT, 5 );
Add( control_lbox, 0, wxEXPAND|wxLEFT|wxRIGHT|wxBOTTOM, 5 );
@ -633,9 +633,9 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
for ( unsigned int c = 0; c < group->controls.size(); ++c )
{
wxStaticText* label = new wxStaticText( parent, -1, wxString::FromAscii( group->controls[c]->name )/*.append(wxT(" :"))*/ );
wxStaticText* const label = new wxStaticText( parent, -1, wxString::FromAscii( group->controls[c]->name )/*.append(wxT(" :"))*/ );
ControlButton* control_button = new ControlButton( parent, group->controls[c]->control_ref, 80 );
ControlButton* const control_button = new ControlButton( parent, group->controls[c]->control_ref, 80 );
control_button->SetFont(m_SmallFont);
ControlButton* adv_button = new ControlButton( parent, group->controls[c]->control_ref, 18, "+" );
adv_button->SetFont(m_SmallFont);
@ -646,7 +646,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
_connect_macro_( control_button, GamepadPage::DetectControl, wxEVT_COMMAND_BUTTON_CLICKED, eventsink );
_connect_macro_( adv_button, GamepadPage::ConfigControl, wxEVT_COMMAND_BUTTON_CLICKED, eventsink );
wxBoxSizer* control_sizer = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const control_sizer = new wxBoxSizer( wxHORIZONTAL );
control_sizer->AddStretchSpacer( 1 );
control_sizer->Add( label, 0, wxCENTER | wxRIGHT, 5 );
control_sizer->Add( control_button, 0, 0, 0 );
@ -660,6 +660,7 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
{
case GROUP_TYPE_STICK :
case GROUP_TYPE_TILT :
case GROUP_TYPE_CURSOR :
{
wxBitmap bitmap(64, 64);
wxMemoryDC dc;
@ -669,22 +670,21 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
PadSettingChoice* deadzone_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 50 );
PadSettingChoice* diagonal_cbox = new PadSettingChoice( parent, group->settings[1]->value, 1, 100 );
std::vector< ControllerEmu::ControlGroup::Setting* >::const_iterator
i = group->settings.begin(),
e = group->settings.end();
_connect_macro_( deadzone_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
_connect_macro_( diagonal_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
for ( ; i!=e; ++i )
{
PadSettingChoice* cbox = new PadSettingChoice( parent, *i );
_connect_macro_( cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
options.push_back( cbox );
szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( (*i)->name ) ) );
szr->Add( cbox, 0, wxLEFT, 0 );
}
options.push_back( deadzone_cbox );
options.push_back( diagonal_cbox );
wxBoxSizer* szr = new wxBoxSizer( wxVERTICAL );
szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[0]->name ) ) );
szr->Add( deadzone_cbox, 0, wxLEFT, 0 );
szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[1]->name ) ) );
szr->Add( diagonal_cbox, 0, wxLEFT, 0 );
wxBoxSizer* h_szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const h_szr = new wxBoxSizer( wxHORIZONTAL );
h_szr->Add( szr, 1, 0, 5 );
h_szr->Add( static_bitmap, 0, wxALL|wxCENTER, 5 );
@ -700,12 +700,12 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
dc.SelectObject(wxNullBitmap);
static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 99 );
PadSettingChoice* const threshold_cbox = new PadSettingChoice( parent, group->settings[0] );
_connect_macro_( threshold_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
options.push_back( threshold_cbox );
wxBoxSizer* szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL );
szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[0]->name ) ), 0, wxCENTER|wxRIGHT, 5 );
szr->Add( threshold_cbox, 0, wxRIGHT, 5 );
@ -722,12 +722,12 @@ ControlGroupBox::ControlGroupBox( ControllerEmu::ControlGroup* const group, wxWi
dc.SelectObject(wxNullBitmap);
static_bitmap = new wxStaticBitmap( parent, -1, bitmap, wxDefaultPosition, wxDefaultSize, wxBITMAP_TYPE_BMP );
PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0]->value, 1, 99 );
PadSettingChoice* threshold_cbox = new PadSettingChoice( parent, group->settings[0] );
_connect_macro_( threshold_cbox, GamepadPage::AdjustSetting, wxEVT_COMMAND_CHOICE_SELECTED, eventsink );
options.push_back( threshold_cbox );
wxBoxSizer* szr = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const szr = new wxBoxSizer( wxHORIZONTAL );
szr->Add( new wxStaticText( parent, -1, wxString::FromAscii( group->settings[0]->name ) ), 0, wxCENTER|wxRIGHT, 5 );
szr->Add( threshold_cbox, 0, wxRIGHT, 5 );
@ -813,7 +813,7 @@ GamepadPage::GamepadPage( wxWindow* parent, const unsigned int pad_num, ConfigDi
// device chooser
wxStaticBoxSizer* device_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Device") );
wxStaticBoxSizer* const device_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Device") );
device_cbox = new wxComboBox( this, -1, wxT(""), wxDefaultPosition, wxSize(128,-1), 0, 0, wxTE_PROCESS_ENTER );
@ -826,7 +826,7 @@ GamepadPage::GamepadPage( wxWindow* parent, const unsigned int pad_num, ConfigDi
device_sbox->Add( device_cbox, 1, wxLEFT|wxRIGHT, 5 );
device_sbox->Add( refresh_button, 0, wxRIGHT|wxBOTTOM, 5 );
wxStaticBoxSizer* clear_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Clear") );
wxStaticBoxSizer* const clear_sbox = new wxStaticBoxSizer( wxHORIZONTAL, this, wxT("Clear") );
wxButton* all_button = new wxButton( this, -1, wxT("All"), wxDefaultPosition, wxSize(48,-1) );
clear_sbox->Add( all_button, 1, wxLEFT|wxRIGHT, 5 );
@ -847,12 +847,12 @@ GamepadPage::GamepadPage( wxWindow* parent, const unsigned int pad_num, ConfigDi
profile_sbox->Add( psave_btn, 0, 0, 5 );
profile_sbox->Add( pdelete_btn, 0, wxRIGHT|wxBOTTOM, 5 );
wxBoxSizer* dio = new wxBoxSizer( wxHORIZONTAL );
wxBoxSizer* const dio = new wxBoxSizer( wxHORIZONTAL );
dio->Add( device_sbox, 1, wxEXPAND|wxRIGHT, 5 );
dio->Add( clear_sbox, 0, wxEXPAND|wxRIGHT, 5 );
dio->Add( profile_sbox, 1, wxEXPAND|wxRIGHT, 5 );
wxBoxSizer* mapping = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* const mapping = new wxBoxSizer( wxVERTICAL );
mapping->Add( dio, 1, wxEXPAND|wxLEFT|wxTOP|wxBOTTOM, 5 );
mapping->Add( control_group_sizer, 0, wxLEFT|wxEXPAND, 5 );
@ -886,7 +886,8 @@ ConfigDialog::ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::s
UpdateDeviceComboBox();
UpdateProfileComboBox();
wxButton* close_button = new wxButton( this, -1, wxT("Save"));
wxButton* const close_button = new wxButton( this, -1, wxT("Save"));
_connect_macro_(close_button, ConfigDialog::ClickSave, wxEVT_COMMAND_BUTTON_CLICKED, this);
_connect_macro_(close_button, ConfigDialog::ClickSave, wxEVT_COMMAND_BUTTON_CLICKED, this);
wxBoxSizer* btns = new wxBoxSizer( wxHORIZONTAL );
@ -894,7 +895,7 @@ ConfigDialog::ConfigDialog( wxWindow* const parent, Plugin& plugin, const std::s
btns->AddStretchSpacer();
btns->Add( close_button, 0, 0, 0 );
wxBoxSizer* szr = new wxBoxSizer( wxVERTICAL );
wxBoxSizer* const szr = new wxBoxSizer( wxVERTICAL );
szr->Add( m_pad_notebook, 0, wxEXPAND|wxTOP|wxLEFT|wxRIGHT, 5 );
szr->Add( btns, 0, wxEXPAND|wxALL, 5 );

View File

@ -48,7 +48,7 @@ public:
class PadSettingChoice : public wxChoice, public PadSetting
{
public:
PadSettingChoice( wxWindow* const parent, ControlState& _value, int min, int max );
PadSettingChoice( wxWindow* const parent, ControllerEmu::ControlGroup::Setting* const setting );
void UpdateGUI();
void UpdateValue();

View File

@ -26,13 +26,27 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
{
case GROUP_TYPE_TILT :
case GROUP_TYPE_STICK :
case GROUP_TYPE_CURSOR :
{
float x = 0, y = 0;
// this is starting to be a mess combining all these in one case
float x = 0, y = 0, z = 0;
float xx, yy;
if ( GROUP_TYPE_STICK == (*g)->control_group->type )
switch ((*g)->control_group->type)
{
case GROUP_TYPE_STICK :
((ControllerEmu::AnalogStick*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
else
break;
case GROUP_TYPE_TILT :
((ControllerEmu::Tilt*)(*g)->control_group)->GetState( &x, &y, 32.0, 32-1.5 );
break;
case GROUP_TYPE_CURSOR :
((ControllerEmu::Cursor*)(*g)->control_group)->GetState( &x, &y, &z );
x *= (32-1.5); x+= 32;
y *= (32-1.5); y+= 32;
break;
}
xx = (*g)->control_group->controls[3]->control_ref->State();
xx -= (*g)->control_group->controls[2]->control_ref->State();
@ -49,25 +63,37 @@ void ConfigDialog::UpdateBitmaps(wxTimerEvent& WXUNUSED(event))
// draw the shit
// ir cursor forward movement
if (z)
{
dc.SetPen(*wxRED_PEN);
dc.SetBrush(*wxRED_BRUSH);
dc.DrawRectangle( 0, 64 - z*64, 64, 2);
}
// circle for visual aid for diagonal adjustment
dc.SetPen(*wxLIGHT_GREY_PEN);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.SetBrush(*wxWHITE_BRUSH);
if ( GROUP_TYPE_STICK == (*g)->control_group->type )
dc.DrawCircle( 32, 32, 32);
else
dc.DrawRectangle( 16, 16, 32, 32 );
// deadzone circle
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 );
if ( GROUP_TYPE_CURSOR != (*g)->control_group->type )
{
dc.SetBrush(*wxLIGHT_GREY_BRUSH);
dc.DrawCircle( 32, 32, ((*g)->control_group)->settings[0]->value * 32 );
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
// i like the dot better than the cross i think
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
// raw dot
dc.SetPen(*wxGREY_PEN);
dc.SetBrush(*wxGREY_BRUSH);
// i like the dot better than the cross i think
dc.DrawRectangle( xx - 2, yy - 2, 4, 4 );
//dc.DrawRectangle( xx-1, 64-yy-4, 2, 8 );
//dc.DrawRectangle( xx-4, 64-yy-1, 8, 2 );
}
// adjusted dot
if ( x!=32 || y!=32 )

View File

@ -211,7 +211,7 @@ ControllerEmu::AnalogStick::AnalogStick( const char* const _name ) : ControlGrou
controls.push_back( new Input( modifier ) );
settings.push_back( new Setting("Dead Zone", 0 ) );
settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) );
settings.push_back( new Setting("Square Stick", 0 ) );
}
@ -253,6 +253,97 @@ ControllerEmu::Tilt::Tilt( const char* const _name ) : ControlGroup( _name, GROU
controls.push_back( new Input( modifier ) );
settings.push_back( new Setting("Dead Zone", 0 ) );
settings.push_back( new Setting("Dead Zone", 0, 1, 50 ) );
settings.push_back( new Setting("Circle Stick", 0 ) );
}
ControllerEmu::Cursor::Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize )
: ControlGroup( _name, GROUP_TYPE_CURSOR )
//, z(0)
, wiimote_initialize(_wiimote_initialize)
{
for ( unsigned int i = 0; i < 4; ++i )
controls.push_back( new Input( named_directions[i] ) );
settings.push_back( new Setting("Width", 0.5f ) );
settings.push_back( new Setting("Height", 0.5f ) );
settings.push_back( new Setting("Top", 0.5f ) );
}
//void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize)
//{
//#ifdef _WIN32
// // Get the cursor position for the entire screen
// POINT point;
// GetCursorPos(&point);
// // Get the cursor position relative to the upper left corner of the rendering window
// ScreenToClient(wiimote_initialize->hWnd, &point);
//
// // Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.)
// RECT Rect;
// GetClientRect(wiimote_initialize->hWnd, &Rect);
// // Width and height is the size of the rendering window
// float WinWidth = (float)(Rect.right - Rect.left);
// float WinHeight = (float)(Rect.bottom - Rect.top);
// float XOffset = 0, YOffset = 0;
// float PictureWidth = WinWidth, PictureHeight = WinHeight;
//#endif
//
// x = ((float)point.x - XOffset) / PictureWidth;
// y = ((float)point.y - YOffset) / PictureHeight;
// x *=2; x-=1;
// y *=2; y-=1;
//}
void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize)
{
unsigned int win_width = 2, win_height = 2;
#ifdef _WIN32
// Get the cursor position for the entire screen
POINT point = { 1, 1 };
GetCursorPos(&point);
// Get the cursor position relative to the upper left corner of the rendering window
ScreenToClient(wiimote_initialize->hWnd, &point);
// Get the size of the rendering window. (In my case Rect.top and Rect.left was zero.)
RECT Rect;
GetClientRect(wiimote_initialize->hWnd, &Rect);
// Width and height is the size of the rendering window
win_width = Rect.right - Rect.left;
win_height = Rect.bottom - Rect.top;
#elif defined(HAVE_X11) && HAVE_X11
int root_x, root_y;
struct
{
int x, y;
} point = { 1, 1 };
// i think this if can be taken out, the plugin will handle that
if (IsFocus())
{
Display* const wm_display = (Display*)wiimote_initialize->hWnd;
Window glwin = *(Window *)wiimote_initialize->pXWindow;
XWindowAttributes win_attribs;
XGetWindowAttributes (wm_display, glwin, &win_attribs);
win_width = win_attribs.width;
win_height = win_attribs.height;
Window root_dummy, child_win;
unsigned int mask;
XQueryPointer(wm_display, glwin, &root_dummy, &child_win, &root_x, &root_y, &point.x, &point.y, &mask);
}
#endif
#if ( defined(_WIN32) || (defined(HAVE_X11) && HAVE_X11))
// Return the mouse position as a range from -1 to 1
x = (float)point.x / (float)win_width * 2 - 1;
y = (float)point.y / (float)win_height * 2 - 1;
#else
x = 0;
y = 0;
#endif
}

View File

@ -27,6 +27,7 @@ enum
GROUP_TYPE_FORCE,
GROUP_TYPE_EXTENSION,
GROUP_TYPE_TILT,
GROUP_TYPE_CURSOR,
};
const char * const named_directions[] =
@ -37,6 +38,8 @@ const char * const named_directions[] =
"Right"
};
void GetMousePos(float& x, float& y, const SWiimoteInitialize* const wiimote_initialize);
class ControllerEmu
{
public:
@ -82,11 +85,18 @@ public:
{
public:
Setting(const char* const _name, const float def_value ) : name(_name), value(def_value), default_value(def_value) {}
Setting(const char* const _name, const ControlState def_value
, const unsigned int _low = 1, const unsigned int _high = 100 )
: name(_name)
, value(def_value)
, default_value(def_value)
, low(_low)
, high(_high){}
const char* const name;
ControlState value;
const ControlState default_value;
const unsigned int low, high;
};
ControlGroup( const char* const _name, const unsigned int _type = GROUP_TYPE_OTHER ) : name(_name), type(_type) {}
@ -274,6 +284,62 @@ public:
}
};
class Cursor : public ControlGroup
{
public:
Cursor( const char* const _name, const SWiimoteInitialize* const _wiimote_initialize );
template <typename C>
void GetState( C* const x, C* const y, C* const forward, const bool adjusted = false )
{
// this is flawed when GetState() isn't called at regular intervals
//const ControlState zz = controls[4]->control_ref->State();
//if (z < zz)
// z = std::min( z + 0.01f, zz );
//else
// z = std::max( z - 0.01f, zz );
const ControlState z = controls[4]->control_ref->State();
// hide
if (controls[5]->control_ref->State() > 0.5f)
{
*x = 10000; *y = 0; *forward = 0;
}
else
{
*forward = z;
float xx, yy;
GetMousePos(xx, yy, wiimote_initialize);
// use mouse cursor, or user defined mapping if they have something mapped
// this if seems horrible
if ( controls[0]->control_ref->control_qualifier.name.size() || controls[1]->control_ref->control_qualifier.name.size() )
yy = controls[0]->control_ref->State() - controls[1]->control_ref->State();
else
yy = -yy;
if ( controls[2]->control_ref->control_qualifier.name.size() || controls[3]->control_ref->control_qualifier.name.size() )
xx = controls[3]->control_ref->State() - controls[2]->control_ref->State();
// adjust cursor according to settings
if (adjusted)
{
xx *= ( settings[0]->value * 2 );
yy *= ( settings[1]->value * 2 );
yy += ( settings[2]->value - 0.5f );
}
*x = xx;
*y = yy;
}
}
private:
//ControlState z;
const SWiimoteInitialize* const wiimote_initialize;
};
class Extension : public ControlGroup
{
public:
@ -282,7 +348,7 @@ public:
, switch_extension(0)
, active_extension(0) {}
void GetState( u8* const data );
void GetState( u8* const data, const bool focus = true );
std::vector<ControllerEmu*> attachments;
@ -302,7 +368,6 @@ public:
std::vector< ControlGroup* > groups;
ControlGroup* options;
ControllerInterface::DeviceQualifier default_device;