Commit a7f93092 authored by bitplane's avatar bitplane

Added mouse button states to drag/move events

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2216 dfc29bdd-3216-0410-991c-e03cc46cb475
parent ba385262
...@@ -168,7 +168,7 @@ bool CGUIWindow::OnEvent(const SEvent& event) ...@@ -168,7 +168,7 @@ bool CGUIWindow::OnEvent(const SEvent& event)
Dragging = false; Dragging = false;
return true; return true;
case EMIE_MOUSE_MOVED: case EMIE_MOUSE_MOVED:
if ( !event.MouseInput.isLeftPressed () ) if ( !event.MouseInput.isLeftPressed() )
Dragging = false; Dragging = false;
if (Dragging) if (Dragging)
......
...@@ -201,13 +201,15 @@ namespace irr ...@@ -201,13 +201,15 @@ namespace irr
void *_window; void *_window;
CGLContextObj _cglcontext; CGLContextObj _cglcontext;
void *_oglcontext; void *_oglcontext;
int _width; int _width,
int _height; _height;
std::map<int,int> _keycodes; std::map<int,int> _keycodes;
int _screenWidth; int _screenWidth,
int _screenHeight; _screenHeight;
bool _active; bool _active;
bool IsShiftDown, IsControlDown; bool IsShiftDown,
IsControlDown;
u32 MouseButtonStates;
void pollJoysticks(); void pollJoysticks();
}; };
......
...@@ -91,7 +91,8 @@ irr::core::array<JoystickInfo> ActiveJoysticks; ...@@ -91,7 +91,8 @@ irr::core::array<JoystickInfo> ActiveJoysticks;
static IOReturn closeJoystickDevice (JoystickInfo* joyInfo) static IOReturn closeJoystickDevice (JoystickInfo* joyInfo)
{ {
IOReturn result = kIOReturnSuccess; IOReturn result = kIOReturnSuccess;
if (joyInfo && joyInfo->interface) { if (joyInfo && joyInfo->interface)
{
/* close the interface */ /* close the interface */
result = (*(joyInfo->interface))->close (joyInfo->interface); result = (*(joyInfo->interface))->close (joyInfo->interface);
if (kIOReturnNotOpen == result) if (kIOReturnNotOpen == result)
...@@ -190,12 +191,15 @@ static void addJoystickComponent (CFTypeRef refElement, JoystickInfo* joyInfo) ...@@ -190,12 +191,15 @@ static void addJoystickComponent (CFTypeRef refElement, JoystickInfo* joyInfo)
} }
} }
} }
else if (kIOHIDElementTypeCollection == elementType) { else if (kIOHIDElementTypeCollection == elementType)
{
//get elements //get elements
CFTypeRef refElementTop = CFDictionaryGetValue ((CFMutableDictionaryRef) refElement, CFSTR(kIOHIDElementKey)); CFTypeRef refElementTop = CFDictionaryGetValue ((CFMutableDictionaryRef) refElement, CFSTR(kIOHIDElementKey));
if (refElementTop) { if (refElementTop)
{
CFTypeID type = CFGetTypeID (refElementTop); CFTypeID type = CFGetTypeID (refElementTop);
if (type == CFArrayGetTypeID()) { if (type == CFArrayGetTypeID())
{
CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)}; CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo); CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo);
} }
...@@ -330,7 +334,7 @@ namespace irr ...@@ -330,7 +334,7 @@ namespace irr
//! constructor //! constructor
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL), : CIrrDeviceStub(param), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL),
IsShiftDown(false), IsControlDown(false) IsShiftDown(false), IsControlDown(false), MouseButtonStates(0)
{ {
struct utsname name; struct utsname name;
NSString *path; NSString *path;
...@@ -564,7 +568,8 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -564,7 +568,8 @@ bool CIrrDeviceMacOSX::createWindow()
fullattribs[index++] = kCGLPFAAlphaSize; fullattribs[index++] = kCGLPFAAlphaSize;
fullattribs[index++] = (CGLPixelFormatAttribute)alphaSize; fullattribs[index++] = (CGLPixelFormatAttribute)alphaSize;
if (CreationParams.AntiAlias) { if (CreationParams.AntiAlias)
{
fullattribs[index++] = kCGLPFASampleBuffers; fullattribs[index++] = kCGLPFASampleBuffers;
fullattribs[index++] = (CGLPixelFormatAttribute)1; fullattribs[index++] = (CGLPixelFormatAttribute)1;
fullattribs[index++] = kCGLPFASamples; fullattribs[index++] = kCGLPFASamples;
...@@ -738,11 +743,15 @@ bool CIrrDeviceMacOSX::run() ...@@ -738,11 +743,15 @@ bool CIrrDeviceMacOSX::run()
case NSLeftMouseDown: case NSLeftMouseDown:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN; ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
MouseButtonStates |= 1;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent); postMouseEvent(event,ievent);
break; break;
case NSLeftMouseUp: case NSLeftMouseUp:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
MouseButtonStates &= !1;
ievent.MouseInput.ButtonStates = MouseButtonStates;
ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP; ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
postMouseEvent(event,ievent); postMouseEvent(event,ievent);
break; break;
...@@ -752,18 +761,23 @@ bool CIrrDeviceMacOSX::run() ...@@ -752,18 +761,23 @@ bool CIrrDeviceMacOSX::run()
case NSRightMouseDragged: case NSRightMouseDragged:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent); postMouseEvent(event,ievent);
break; break;
case NSRightMouseDown: case NSRightMouseDown:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN; ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
MouseButtonStates |= 2;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent); postMouseEvent(event,ievent);
break; break;
case NSRightMouseUp: case NSRightMouseUp:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP; ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
MouseButtonStates &= !2;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent); postMouseEvent(event,ievent);
break; break;
...@@ -911,13 +925,15 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed ...@@ -911,13 +925,15 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent) void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
{ {
BOOL post = true; bool post = true;
if (_window != NULL) if (_window != NULL)
{ {
ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x; ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x;
ievent.MouseInput.Y = _height - (int)[(NSEvent *)event locationInWindow].y; ievent.MouseInput.Y = _height - (int)[(NSEvent *)event locationInWindow].y;
if (ievent.MouseInput.Y < 0) post = false;
if (ievent.MouseInput.Y < 0)
post = false;
} }
else else
{ {
...@@ -925,7 +941,9 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent) ...@@ -925,7 +941,9 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
ievent.MouseInput.Y = _height - (int)[NSEvent mouseLocation].y; ievent.MouseInput.Y = _height - (int)[NSEvent mouseLocation].y;
} }
if (post) postEventFromUser(ievent); if (post)
postEventFromUser(ievent);
[NSApp sendEvent:(NSEvent *)event]; [NSApp sendEvent:(NSEvent *)event];
} }
...@@ -1093,19 +1111,22 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1093,19 +1111,22 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
CFMutableDictionaryRef hidDictionaryRef = NULL; CFMutableDictionaryRef hidDictionaryRef = NULL;
result = IOMasterPort (bootstrap_port, &masterPort); result = IOMasterPort (bootstrap_port, &masterPort);
if (kIOReturnSuccess != result) { if (kIOReturnSuccess != result)
{
os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR); os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR);
return false; return false;
} }
hidDictionaryRef = IOServiceMatching (kIOHIDDeviceKey); hidDictionaryRef = IOServiceMatching (kIOHIDDeviceKey);
if (!hidDictionaryRef) { if (!hidDictionaryRef)
{
os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR); os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR);
return false; return false;
} }
result = IOServiceGetMatchingServices (masterPort, hidDictionaryRef, &hidIterator); result = IOServiceGetMatchingServices (masterPort, hidDictionaryRef, &hidIterator);
if (kIOReturnSuccess != result) { if (kIOReturnSuccess != result)
{
os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR); os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR);
return false; return false;
} }
...@@ -1122,39 +1143,47 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1122,39 +1143,47 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
CFMutableDictionaryRef hidProperties = 0; CFMutableDictionaryRef hidProperties = 0;
kern_return_t kern_result = IORegistryEntryCreateCFProperties (hidObject, &hidProperties, kCFAllocatorDefault, kNilOptions); kern_return_t kern_result = IORegistryEntryCreateCFProperties (hidObject, &hidProperties, kCFAllocatorDefault, kNilOptions);
if ((kern_result == KERN_SUCCESS) && hidProperties) { if ((kern_result == KERN_SUCCESS) && hidProperties)
{
HRESULT plugInResult = S_OK; HRESULT plugInResult = S_OK;
SInt32 score = 0; SInt32 score = 0;
IOCFPlugInInterface ** ppPlugInInterface = NULL; IOCFPlugInInterface ** ppPlugInInterface = NULL;
result = IOCreatePlugInInterfaceForService (hidObject, kIOHIDDeviceUserClientTypeID, result = IOCreatePlugInInterfaceForService (hidObject, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); kIOCFPlugInInterfaceID, &ppPlugInInterface, &score);
if (kIOReturnSuccess == result) { if (kIOReturnSuccess == result)
{
plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface,
CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void **) &(info.interface)); CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void **) &(info.interface));
if (plugInResult != S_OK) if (plugInResult != S_OK)
os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR); os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR);
(*ppPlugInInterface)->Release (ppPlugInInterface); (*ppPlugInInterface)->Release(ppPlugInInterface);
} }
else else
continue; continue;
if (info.interface != NULL) { if (info.interface != NULL)
{
result = (*(info.interface))->open (info.interface, 0); result = (*(info.interface))->open (info.interface, 0);
if (result == kIOReturnSuccess) { if (result == kIOReturnSuccess)
{
(*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info); (*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info);
getJoystickDeviceInfo(hidObject, hidProperties, &info); getJoystickDeviceInfo(hidObject, hidProperties, &info);
//get elements //get elements
CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
if (refElementTop) { if (refElementTop)
{
CFTypeID type = CFGetTypeID (refElementTop); CFTypeID type = CFGetTypeID (refElementTop);
if (type == CFArrayGetTypeID()) { if (type == CFArrayGetTypeID())
{
CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)}; CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
info.numActiveJoysticks = ActiveJoysticks.size(); info.numActiveJoysticks = ActiveJoysticks.size();
CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info); CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info);
} }
} }
} else { }
else
{
CFRelease (hidProperties); CFRelease (hidProperties);
os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR); os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR);
continue; continue;
...@@ -1167,7 +1196,8 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1167,7 +1196,8 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
if ( (info.usagePage != kHIDPage_GenericDesktop) || if ( (info.usagePage != kHIDPage_GenericDesktop) ||
((info.usage != kHIDUsage_GD_Joystick && ((info.usage != kHIDUsage_GD_Joystick &&
info.usage != kHIDUsage_GD_GamePad && info.usage != kHIDUsage_GD_GamePad &&
info.usage != kHIDUsage_GD_MultiAxisController)) ) { info.usage != kHIDUsage_GD_MultiAxisController)) )
{
closeJoystickDevice (&info); closeJoystickDevice (&info);
continue; continue;
} }
...@@ -1192,9 +1222,12 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1192,9 +1222,12 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
joystickInfo.push_back(returnInfo); joystickInfo.push_back(returnInfo);
} }
} else }
else
{
continue; continue;
} }
}
result = IOObjectRelease (hidIterator); result = IOObjectRelease (hidIterator);
return true; return true;
...@@ -1220,12 +1253,14 @@ void CIrrDeviceMacOSX::pollJoysticks() ...@@ -1220,12 +1253,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
if (ActiveJoysticks[joystick].interface) if (ActiveJoysticks[joystick].interface)
{ {
for (u32 n = 0; n < ActiveJoysticks[joystick].axisComp.size(); n++) { for (u32 n = 0; n < ActiveJoysticks[joystick].axisComp.size(); n++)
{
IOReturn result = kIOReturnSuccess; IOReturn result = kIOReturnSuccess;
IOHIDEventStruct hidEvent; IOHIDEventStruct hidEvent;
hidEvent.value = 0; hidEvent.value = 0;
result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].axisComp[n].cookie, &hidEvent); result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].axisComp[n].cookie, &hidEvent);
if (kIOReturnSuccess == result) { if (kIOReturnSuccess == result)
{
f32 min = -32768.0f; f32 min = -32768.0f;
f32 max = 32768.0f; f32 max = 32768.0f;
f32 deviceScale = max - min; f32 deviceScale = max - min;
...@@ -1245,12 +1280,14 @@ void CIrrDeviceMacOSX::pollJoysticks() ...@@ -1245,12 +1280,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
} }
}//axis check }//axis check
for (u32 n = 0; n < ActiveJoysticks[joystick].buttonComp.size(); n++) { for (u32 n = 0; n < ActiveJoysticks[joystick].buttonComp.size(); n++)
{
IOReturn result = kIOReturnSuccess; IOReturn result = kIOReturnSuccess;
IOHIDEventStruct hidEvent; IOHIDEventStruct hidEvent;
hidEvent.value = 0; hidEvent.value = 0;
result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent); result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent);
if (kIOReturnSuccess == result) { if (kIOReturnSuccess == result)
{
u32 ButtonStates = 0; u32 ButtonStates = 0;
if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false) ) if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false) )
...@@ -1266,12 +1303,14 @@ void CIrrDeviceMacOSX::pollJoysticks() ...@@ -1266,12 +1303,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
}//button check }//button check
//still ToDo..will be done soon :) //still ToDo..will be done soon :)
/* /*
for (u32 n = 0; n < ActiveJoysticks[joystick].hatComp.size(); n++) { for (u32 n = 0; n < ActiveJoysticks[joystick].hatComp.size(); n++)
{
IOReturn result = kIOReturnSuccess; IOReturn result = kIOReturnSuccess;
IOHIDEventStruct hidEvent; IOHIDEventStruct hidEvent;
hidEvent.value = 0; hidEvent.value = 0;
result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].hatComp[n].cookie, &hidEvent); result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].hatComp[n].cookie, &hidEvent);
if (kIOReturnSuccess == result) { if (kIOReturnSuccess == result)
{
if (ActiveJoysticks[joystick].persistentData.JoystickEvent.POV != hidEvent.value) if (ActiveJoysticks[joystick].persistentData.JoystickEvent.POV != hidEvent.value)
found = true; found = true;
ActiveJoysticks[joystick].persistentData.JoystickEvent.POV = hidEvent.value; ActiveJoysticks[joystick].persistentData.JoystickEvent.POV = hidEvent.value;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment