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
// Copyright (C) 2002-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CGUIWindow.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
namespace irr
{
namespace gui
{
//! constructor
CGUIWindow::CGUIWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIWindow(environment, parent, id, rectangle), Dragging(false)
{
#ifdef _DEBUG
setDebugName("CGUIWindow");
#endif
IGUISkin* skin = 0;
if (environment)
skin = environment->getSkin();
IGUISpriteBank* sprites = 0;
video::SColor color(255,255,255,255);
s32 buttonw = 15;
if (skin)
{
buttonw = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
sprites = skin->getSpriteBank();
color = skin->getColor(EGDC_WINDOW_SYMBOL);
}
s32 posx = RelativeRect.getWidth() - buttonw - 4;
CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close" );
CloseButton->setSubElement(true);
CloseButton->setTabStop(false);
CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
CloseButton->setSpriteBank(sprites);
CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
}
posx -= buttonw + 2;
RestoreButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_RESTORE) : L"Restore" );
RestoreButton->setVisible(false);
RestoreButton->setSubElement(true);
RestoreButton->setTabStop(false);
RestoreButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
RestoreButton->setSpriteBank(sprites);
RestoreButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_RESTORE), color);
RestoreButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_RESTORE), color);
}
posx -= buttonw + 2;
MinButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_MINIMIZE) : L"Minimize" );
MinButton->setVisible(false);
MinButton->setSubElement(true);
MinButton->setTabStop(false);
MinButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
MinButton->setSpriteBank(sprites);
MinButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
MinButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
}
MinButton->grab();
RestoreButton->grab();
CloseButton->grab();
// this element is a tab group
setTabGroup(true);
setTabStop(true);
setTabOrder(-1);
}
//! destructor
CGUIWindow::~CGUIWindow()
{
if (MinButton)
MinButton->drop();
if (RestoreButton)
RestoreButton->drop();
if (CloseButton)
CloseButton->drop();
}
//! called if an event happened.
bool CGUIWindow::OnEvent(const SEvent& event)
{
if (IsEnabled)
{
switch(event.EventType)
{
case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{
Dragging = false;
}
else
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
{
if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller)))
Parent->bringToFront(this);
}
else
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
if (event.GUIEvent.Caller == CloseButton)
{
if (Parent)
{
// send close event to parent
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
// if the event was not absorbed
if (!Parent->OnEvent(e))
remove();
return true;
}
else
{
remove();
return true;
}
}
}
break;
case EET_MOUSE_INPUT_EVENT:
switch(event.MouseInput.Event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
Dragging = true;
if (Parent)
Parent->bringToFront(this);
return true;
case EMIE_LMOUSE_LEFT_UP:
Dragging = false;
return true;
case EMIE_MOUSE_MOVED:
if ( !event.MouseInput.isLeftPressed () )
Dragging = false;
if (Dragging)
{
// gui window should not be dragged outside its parent
if (Parent &&
(event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1))
return true;
move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
return true;
}
break;
default:
break;
}
default:
break;
}
}
return IGUIElement::OnEvent(event);
}
//! Updates the absolute position.
void CGUIWindow::updateAbsolutePosition()
{
IGUIElement::updateAbsolutePosition();
}
//! draws the element and its children
void CGUIWindow::draw()
{
if ( IsVisible )
{
IGUISkin* skin = Environment->getSkin();
core::rect<s32> rect = AbsoluteRect;
// draw body fast
rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
AbsoluteRect, &AbsoluteClippingRect);
if (Text.size())
{
rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font)
{
font->draw(Text.c_str(), rect,
skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect);
}
}
}
IGUIElement::draw();
}
//! Returns pointer to the close button
IGUIButton* CGUIWindow::getCloseButton() const
{
return CloseButton;
}
//! Returns pointer to the minimize button
IGUIButton* CGUIWindow::getMinimizeButton() const
{
return MinButton;
}
//! Returns pointer to the maximize button
IGUIButton* CGUIWindow::getMaximizeButton() const
{
return RestoreButton;
}
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
// Copyright (C) 2002-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CGUIWindow.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUISkin.h"
#include "IGUIEnvironment.h"
#include "IVideoDriver.h"
#include "IGUIButton.h"
#include "IGUIFont.h"
#include "IGUIFontBitmap.h"
namespace irr
{
namespace gui
{
//! constructor
CGUIWindow::CGUIWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIWindow(environment, parent, id, rectangle), Dragging(false)
{
#ifdef _DEBUG
setDebugName("CGUIWindow");
#endif
IGUISkin* skin = 0;
if (environment)
skin = environment->getSkin();
IGUISpriteBank* sprites = 0;
video::SColor color(255,255,255,255);
s32 buttonw = 15;
if (skin)
{
buttonw = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
sprites = skin->getSpriteBank();
color = skin->getColor(EGDC_WINDOW_SYMBOL);
}
s32 posx = RelativeRect.getWidth() - buttonw - 4;
CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close" );
CloseButton->setSubElement(true);
CloseButton->setTabStop(false);
CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
CloseButton->setSpriteBank(sprites);
CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
}
posx -= buttonw + 2;
RestoreButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_RESTORE) : L"Restore" );
RestoreButton->setVisible(false);
RestoreButton->setSubElement(true);
RestoreButton->setTabStop(false);
RestoreButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
RestoreButton->setSpriteBank(sprites);
RestoreButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_RESTORE), color);
RestoreButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_RESTORE), color);
}
posx -= buttonw + 2;
MinButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_MINIMIZE) : L"Minimize" );
MinButton->setVisible(false);
MinButton->setSubElement(true);
MinButton->setTabStop(false);
MinButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites)
{
MinButton->setSpriteBank(sprites);
MinButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
MinButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
}
MinButton->grab();
RestoreButton->grab();
CloseButton->grab();
// this element is a tab group
setTabGroup(true);
setTabStop(true);
setTabOrder(-1);
}
//! destructor
CGUIWindow::~CGUIWindow()
{
if (MinButton)
MinButton->drop();
if (RestoreButton)
RestoreButton->drop();
if (CloseButton)
CloseButton->drop();
}
//! called if an event happened.
bool CGUIWindow::OnEvent(const SEvent& event)
{
if (IsEnabled)
{
switch(event.EventType)
{
case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{
Dragging = false;
}
else
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
{
if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller)))
Parent->bringToFront(this);
}
else
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{
if (event.GUIEvent.Caller == CloseButton)
{
if (Parent)
{
// send close event to parent
SEvent e;
e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
// if the event was not absorbed
if (!Parent->OnEvent(e))
remove();
return true;
}
else
{
remove();
return true;
}
}
}
break;
case EET_MOUSE_INPUT_EVENT:
switch(event.MouseInput.Event)
{
case EMIE_LMOUSE_PRESSED_DOWN:
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
Dragging = true;
if (Parent)
Parent->bringToFront(this);
return true;
case EMIE_LMOUSE_LEFT_UP:
Dragging = false;
return true;
case EMIE_MOUSE_MOVED:
if ( !event.MouseInput.isLeftPressed() )
Dragging = false;
if (Dragging)
{
// gui window should not be dragged outside its parent
if (Parent &&
(event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1))
return true;
move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y;
return true;
}
break;
default:
break;
}
default:
break;
}
}
return IGUIElement::OnEvent(event);
}
//! Updates the absolute position.
void CGUIWindow::updateAbsolutePosition()
{
IGUIElement::updateAbsolutePosition();
}
//! draws the element and its children
void CGUIWindow::draw()
{
if ( IsVisible )
{
IGUISkin* skin = Environment->getSkin();
core::rect<s32> rect = AbsoluteRect;
// draw body fast
rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
AbsoluteRect, &AbsoluteClippingRect);
if (Text.size())
{
rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font)
{
font->draw(Text.c_str(), rect,
skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect);
}
}
}
IGUIElement::draw();
}
//! Returns pointer to the close button
IGUIButton* CGUIWindow::getCloseButton() const
{
return CloseButton;
}
//! Returns pointer to the minimize button
IGUIButton* CGUIWindow::getMinimizeButton() const
{
return MinButton;
}
//! Returns pointer to the maximize button
IGUIButton* CGUIWindow::getMaximizeButton() const
{
return RestoreButton;
}
} // end namespace gui
} // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_
......@@ -198,16 +198,18 @@ namespace irr
void postMouseEvent(void *event,irr::SEvent &ievent);
void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed);
void *_window;
CGLContextObj _cglcontext;
void *_oglcontext;
int _width;
int _height;
void *_window;
CGLContextObj _cglcontext;
void *_oglcontext;
int _width,
_height;
std::map<int,int> _keycodes;
int _screenWidth;
int _screenHeight;
bool _active;
bool IsShiftDown, IsControlDown;
int _screenWidth,
_screenHeight;
bool _active;
bool IsShiftDown,
IsControlDown;
u32 MouseButtonStates;
void pollJoysticks();
};
......
......@@ -91,7 +91,8 @@ irr::core::array<JoystickInfo> ActiveJoysticks;
static IOReturn closeJoystickDevice (JoystickInfo* joyInfo)
{
IOReturn result = kIOReturnSuccess;
if (joyInfo && joyInfo->interface) {
if (joyInfo && joyInfo->interface)
{
/* close the interface */
result = (*(joyInfo->interface))->close (joyInfo->interface);
if (kIOReturnNotOpen == result)
......@@ -190,12 +191,15 @@ static void addJoystickComponent (CFTypeRef refElement, JoystickInfo* joyInfo)
}
}
}
else if (kIOHIDElementTypeCollection == elementType) {
else if (kIOHIDElementTypeCollection == elementType)
{
//get elements
CFTypeRef refElementTop = CFDictionaryGetValue ((CFMutableDictionaryRef) refElement, CFSTR(kIOHIDElementKey));
if (refElementTop) {
if (refElementTop)
{
CFTypeID type = CFGetTypeID (refElementTop);
if (type == CFArrayGetTypeID()) {
if (type == CFArrayGetTypeID())
{
CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo);
}
......@@ -330,7 +334,7 @@ namespace irr
//! constructor
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL),
IsShiftDown(false), IsControlDown(false)
IsShiftDown(false), IsControlDown(false), MouseButtonStates(0)
{
struct utsname name;
NSString *path;
......@@ -564,7 +568,8 @@ bool CIrrDeviceMacOSX::createWindow()
fullattribs[index++] = kCGLPFAAlphaSize;
fullattribs[index++] = (CGLPixelFormatAttribute)alphaSize;
if (CreationParams.AntiAlias) {
if (CreationParams.AntiAlias)
{
fullattribs[index++] = kCGLPFASampleBuffers;
fullattribs[index++] = (CGLPixelFormatAttribute)1;
fullattribs[index++] = kCGLPFASamples;
......@@ -738,11 +743,15 @@ bool CIrrDeviceMacOSX::run()
case NSLeftMouseDown:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
MouseButtonStates |= 1;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent);
break;
case NSLeftMouseUp:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
MouseButtonStates &= !1;
ievent.MouseInput.ButtonStates = MouseButtonStates;
ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
postMouseEvent(event,ievent);
break;
......@@ -752,18 +761,23 @@ bool CIrrDeviceMacOSX::run()
case NSRightMouseDragged:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent);
break;
case NSRightMouseDown:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
MouseButtonStates |= 2;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent);
break;
case NSRightMouseUp:
ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
MouseButtonStates &= !2;
ievent.MouseInput.ButtonStates = MouseButtonStates;
postMouseEvent(event,ievent);
break;
......@@ -911,13 +925,15 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
{
BOOL post = true;
bool post = true;
if (_window != NULL)
{
ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x;
ievent.MouseInput.Y = _height - (int)[(NSEvent *)event locationInWindow].y;
if (ievent.MouseInput.Y < 0) post = false;
if (ievent.MouseInput.Y < 0)
post = false;
}
else
{
......@@ -925,7 +941,9 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
ievent.MouseInput.Y = _height - (int)[NSEvent mouseLocation].y;
}
if (post) postEventFromUser(ievent);
if (post)
postEventFromUser(ievent);
[NSApp sendEvent:(NSEvent *)event];
}
......@@ -1093,19 +1111,22 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
CFMutableDictionaryRef hidDictionaryRef = NULL;
result = IOMasterPort (bootstrap_port, &masterPort);
if (kIOReturnSuccess != result) {
if (kIOReturnSuccess != result)
{
os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR);
return false;
}
hidDictionaryRef = IOServiceMatching (kIOHIDDeviceKey);
if (!hidDictionaryRef) {
if (!hidDictionaryRef)
{
os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR);
return false;
}
result = IOServiceGetMatchingServices (masterPort, hidDictionaryRef, &hidIterator);
if (kIOReturnSuccess != result) {
if (kIOReturnSuccess != result)
{
os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR);
return false;
}
......@@ -1122,39 +1143,47 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
CFMutableDictionaryRef hidProperties = 0;
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;
SInt32 score = 0;
IOCFPlugInInterface ** ppPlugInInterface = NULL;
result = IOCreatePlugInInterfaceForService (hidObject, kIOHIDDeviceUserClientTypeID,
kIOCFPlugInInterfaceID, &ppPlugInInterface, &score);
if (kIOReturnSuccess == result) {
if (kIOReturnSuccess == result)
{
plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface,
CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void **) &(info.interface));
if (plugInResult != S_OK)
os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR);
(*ppPlugInInterface)->Release (ppPlugInInterface);
(*ppPlugInInterface)->Release(ppPlugInInterface);
}
else
continue;
if (info.interface != NULL) {
if (info.interface != NULL)
{
result = (*(info.interface))->open (info.interface, 0);
if (result == kIOReturnSuccess) {
if (result == kIOReturnSuccess)
{
(*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info);
getJoystickDeviceInfo(hidObject, hidProperties, &info);
//get elements
CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
if (refElementTop) {
if (refElementTop)
{
CFTypeID type = CFGetTypeID (refElementTop);
if (type == CFArrayGetTypeID()) {
if (type == CFArrayGetTypeID())
{
CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
info.numActiveJoysticks = ActiveJoysticks.size();
CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info);
}
}
} else {
}
else
{
CFRelease (hidProperties);
os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR);
continue;
......@@ -1167,7 +1196,8 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
if ( (info.usagePage != kHIDPage_GenericDesktop) ||
((info.usage != kHIDUsage_GD_Joystick &&
info.usage != kHIDUsage_GD_GamePad &&
info.usage != kHIDUsage_GD_MultiAxisController)) ) {
info.usage != kHIDUsage_GD_MultiAxisController)) )
{
closeJoystickDevice (&info);
continue;
}
......@@ -1192,8 +1222,11 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
joystickInfo.push_back(returnInfo);
}
} else
}
else
{
continue;
}
}
result = IOObjectRelease (hidIterator);
......@@ -1220,12 +1253,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
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;
IOHIDEventStruct hidEvent;
hidEvent.value = 0;
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 max = 32768.0f;
f32 deviceScale = max - min;
......@@ -1245,12 +1280,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
}
}//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;
IOHIDEventStruct hidEvent;
hidEvent.value = 0;
result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent);
if (kIOReturnSuccess == result) {
if (kIOReturnSuccess == result)
{
u32 ButtonStates = 0;
if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false) )
......@@ -1266,12 +1303,14 @@ void CIrrDeviceMacOSX::pollJoysticks()
}//button check
//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;
IOHIDEventStruct hidEvent;
hidEvent.value = 0;
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)
found = true;
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