mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-31 10:09:36 -06:00
Emulated Wiimote: Don't report IR positions outside the screen (leave them at 0xff), don't report A and B button mouse clicks when the cursor is outside the screen
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@2042 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
@ -180,7 +180,7 @@ void SendReportCoreAccelIr12(u16 _channelID) {
|
||||
FillReportInfo(pReport->c);
|
||||
FillReportAcc(pReport->a);
|
||||
|
||||
// We settle with emulating two objects, not all four
|
||||
// We settle with emulating two objects, not all four. We leave object 2 and 3 with zero.
|
||||
FillReportIR(pReport->ir[0], pReport->ir[1]);
|
||||
|
||||
LOGV(WII_IPC_WIIMOTE, 2, " SendReportCoreAccelIr12()");
|
||||
|
@ -57,30 +57,41 @@ u16 convert16bit(const u8* src) {
|
||||
|
||||
|
||||
// ===================================================
|
||||
/* Calibrate the mouse position to the emulation window. */
|
||||
/* Calibrate the mouse position to the emulation window. g_WiimoteInitialize.hWnd is the rendering window handle. */
|
||||
// ----------------
|
||||
void GetMousePos(float& x, float& y)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
POINT point;
|
||||
|
||||
// Get the cursor position for the entire screen
|
||||
GetCursorPos(&point);
|
||||
// Get the cursor position relative to the upper left corner of the rendering window
|
||||
ScreenToClient(g_WiimoteInitialize.hWnd, &point);
|
||||
|
||||
// Get the size of the rendering window. In my case top and left was zero.
|
||||
RECT Rect;
|
||||
GetClientRect(g_WiimoteInitialize.hWnd, &Rect);
|
||||
|
||||
// Width and height is the size of the rendering window
|
||||
int width = Rect.right - Rect.left;
|
||||
int height = Rect.bottom - Rect.top;
|
||||
|
||||
// Return the mouse position as a fraction of one
|
||||
x = point.x / (float)width;
|
||||
y = point.y / (float)height;
|
||||
|
||||
/*
|
||||
Console::ClearScreen();
|
||||
Console::Print("GetCursorPos: %i %i\n", point.x, point.y);
|
||||
Console::Print("GetClientRect: %i %i %i %i\n", Rect.left, Rect.right, Rect.top, Rect.bottom);
|
||||
Console::Print("x and y: %f %f\n", x, y);
|
||||
*/
|
||||
#else
|
||||
// TODO fix on linux
|
||||
// TODO fix on linux
|
||||
x = 0.5f;
|
||||
y = 0.5f;
|
||||
#endif
|
||||
}
|
||||
// ==============
|
||||
|
||||
|
||||
// ===================================================
|
||||
|
@ -197,11 +197,15 @@ void FillReportInfo(wm_core& _core)
|
||||
// These keys are reserved for the recording
|
||||
if ( GetAsyncKeyState(VK_SHIFT) || GetAsyncKeyState(VK_CONTROL) ) return;
|
||||
|
||||
// Check the mouse position. Don't allow mouse clicks from outside the window.
|
||||
float x, y; GetMousePos(x, y);
|
||||
bool InsideScreen = !(x < 0 || x > 1 || y < 0 || y > 1);
|
||||
|
||||
// Allow both mouse buttons and keyboard to press a and b
|
||||
if(GetAsyncKeyState(VK_LBUTTON) ? 1 : 0 || GetAsyncKeyState('A') ? 1 : 0)
|
||||
if((GetAsyncKeyState(VK_LBUTTON) && InsideScreen) || GetAsyncKeyState('A') ? 1 : 0)
|
||||
_core.a = 1;
|
||||
|
||||
if(GetAsyncKeyState(VK_RBUTTON) ? 1 : 0 || GetAsyncKeyState('B') ? 1 : 0)
|
||||
if((GetAsyncKeyState(VK_RBUTTON) && InsideScreen) || GetAsyncKeyState('B') ? 1 : 0)
|
||||
_core.b = 1;
|
||||
|
||||
_core.one = GetAsyncKeyState('1') ? 1 : 0;
|
||||
@ -447,6 +451,9 @@ void FillReportAcc(wm_accel& _acc)
|
||||
/////////////////////////
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
// The extended 12 byte (3 byte per object) reporting
|
||||
// ---------------
|
||||
void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1)
|
||||
{
|
||||
|
||||
@ -465,13 +472,17 @@ void FillReportIR(wm_ir_extended& _ir0, wm_ir_extended& _ir1)
|
||||
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
||||
}
|
||||
|
||||
// Fill with 0xff (0r 0x00?) if empty
|
||||
memset(&_ir0, 0x00, sizeof(wm_ir_extended));
|
||||
memset(&_ir1, 0x00, sizeof(wm_ir_extended));
|
||||
/* Fill with 0xff if empty. The real Wiimote seems to use 0xff when it sees to ojbects, at least from
|
||||
how WiiMoteReal::SendEvent() works. */
|
||||
memset(&_ir0, 0xff, sizeof(wm_ir_extended));
|
||||
memset(&_ir1, 0xff, sizeof(wm_ir_extended));
|
||||
|
||||
float MouseX, MouseY;
|
||||
GetMousePos(MouseX, MouseY);
|
||||
|
||||
// If we are outside the screen leave the values at 0xff
|
||||
if(MouseX > 1 || MouseX < 0 || MouseY > 1 || MouseY < 0) return;
|
||||
|
||||
int y0 = Top + (MouseY * (Bottom - Top));
|
||||
int y1 = Top + (MouseY * (Bottom - Top));
|
||||
|
||||
@ -548,13 +559,16 @@ void FillReportIRBasic(wm_ir_basic& _ir0, wm_ir_basic& _ir1)
|
||||
Bottom = BOTTOM; SensorBarRadius = SENSOR_BAR_RADIUS;
|
||||
}
|
||||
|
||||
// Fill with 0x00 if empty
|
||||
memset(&_ir0, 0x00, sizeof(wm_ir_basic));
|
||||
memset(&_ir1, 0x00, sizeof(wm_ir_basic));
|
||||
// Fill with 0xff if empty
|
||||
memset(&_ir0, 0xff, sizeof(wm_ir_basic));
|
||||
memset(&_ir1, 0xff, sizeof(wm_ir_basic));
|
||||
|
||||
float MouseX, MouseY;
|
||||
GetMousePos(MouseX, MouseY);
|
||||
|
||||
// If we are outside the screen leave the values at 0xff
|
||||
if(MouseX > 1 || MouseX < 0 || MouseY > 1 || MouseY < 0) return;
|
||||
|
||||
int y1 = Top + (MouseY * (Bottom - Top));
|
||||
int y2 = Top + (MouseY * (Bottom - Top));
|
||||
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "main.h"
|
||||
#include "Config.h"
|
||||
#include "EmuMain.h"
|
||||
#include "EmuDefinitions.h"
|
||||
#define EXCLUDE_H // Avoid certain declarations in wiimote_real.h
|
||||
#include "wiimote_real.h"
|
||||
#if defined(HAVE_WX) && HAVE_WX
|
||||
@ -243,6 +244,15 @@ void SendEvent(SEvent& _rEvent)
|
||||
memcpy(&Buffer[Offset], _rEvent.m_PayLoad, MAX_PAYLOAD);
|
||||
Offset += MAX_PAYLOAD;
|
||||
|
||||
/* Debugging
|
||||
//if(GetAsyncKeyState('V'))
|
||||
{
|
||||
std::string Temp = ArrayToString(Buffer, Offset, 0, 30);
|
||||
Console::ClearScreen();
|
||||
Console::Print("Reporting Mode: 0x%02x\n", WiiMoteEmu::g_ReportingMode);
|
||||
Console::Print("DataFrame: %s\n", Temp.c_str());
|
||||
}*/
|
||||
|
||||
g_WiimoteInitialize.pWiimoteInput(m_channelID, Buffer, Offset);
|
||||
}
|
||||
/////////////////////
|
||||
|
Reference in New Issue
Block a user