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 // Copyright (C) 2002-2009 Nikolaus Gebhardt
// This file is part of the "Irrlicht Engine". // This file is part of the "Irrlicht Engine".
// For conditions of distribution and use, see copyright notice in irrlicht.h // For conditions of distribution and use, see copyright notice in irrlicht.h
#include "CGUIWindow.h" #include "CGUIWindow.h"
#ifdef _IRR_COMPILE_WITH_GUI_ #ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUISkin.h" #include "IGUISkin.h"
#include "IGUIEnvironment.h" #include "IGUIEnvironment.h"
#include "IVideoDriver.h" #include "IVideoDriver.h"
#include "IGUIButton.h" #include "IGUIButton.h"
#include "IGUIFont.h" #include "IGUIFont.h"
#include "IGUIFontBitmap.h" #include "IGUIFontBitmap.h"
namespace irr namespace irr
{ {
namespace gui namespace gui
{ {
//! constructor //! constructor
CGUIWindow::CGUIWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle) CGUIWindow::CGUIWindow(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIWindow(environment, parent, id, rectangle), Dragging(false) : IGUIWindow(environment, parent, id, rectangle), Dragging(false)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUIWindow"); setDebugName("CGUIWindow");
#endif #endif
IGUISkin* skin = 0; IGUISkin* skin = 0;
if (environment) if (environment)
skin = environment->getSkin(); skin = environment->getSkin();
IGUISpriteBank* sprites = 0; IGUISpriteBank* sprites = 0;
video::SColor color(255,255,255,255); video::SColor color(255,255,255,255);
s32 buttonw = 15; s32 buttonw = 15;
if (skin) if (skin)
{ {
buttonw = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH); buttonw = skin->getSize(EGDS_WINDOW_BUTTON_WIDTH);
sprites = skin->getSpriteBank(); sprites = skin->getSpriteBank();
color = skin->getColor(EGDC_WINDOW_SYMBOL); color = skin->getColor(EGDC_WINDOW_SYMBOL);
} }
s32 posx = RelativeRect.getWidth() - buttonw - 4; s32 posx = RelativeRect.getWidth() - buttonw - 4;
CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1, CloseButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close" ); L"", skin ? skin->getDefaultText(EGDT_WINDOW_CLOSE) : L"Close" );
CloseButton->setSubElement(true); CloseButton->setSubElement(true);
CloseButton->setTabStop(false); CloseButton->setTabStop(false);
CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); CloseButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites) if (sprites)
{ {
CloseButton->setSpriteBank(sprites); CloseButton->setSpriteBank(sprites);
CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color); CloseButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_CLOSE), color);
CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color); CloseButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_CLOSE), color);
} }
posx -= buttonw + 2; posx -= buttonw + 2;
RestoreButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1, RestoreButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_RESTORE) : L"Restore" ); L"", skin ? skin->getDefaultText(EGDT_WINDOW_RESTORE) : L"Restore" );
RestoreButton->setVisible(false); RestoreButton->setVisible(false);
RestoreButton->setSubElement(true); RestoreButton->setSubElement(true);
RestoreButton->setTabStop(false); RestoreButton->setTabStop(false);
RestoreButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); RestoreButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites) if (sprites)
{ {
RestoreButton->setSpriteBank(sprites); RestoreButton->setSpriteBank(sprites);
RestoreButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_RESTORE), color); RestoreButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_RESTORE), color);
RestoreButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_RESTORE), color); RestoreButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_RESTORE), color);
} }
posx -= buttonw + 2; posx -= buttonw + 2;
MinButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1, MinButton = Environment->addButton(core::rect<s32>(posx, 3, posx + buttonw, 3 + buttonw), this, -1,
L"", skin ? skin->getDefaultText(EGDT_WINDOW_MINIMIZE) : L"Minimize" ); L"", skin ? skin->getDefaultText(EGDT_WINDOW_MINIMIZE) : L"Minimize" );
MinButton->setVisible(false); MinButton->setVisible(false);
MinButton->setSubElement(true); MinButton->setSubElement(true);
MinButton->setTabStop(false); MinButton->setTabStop(false);
MinButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT); MinButton->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_UPPERLEFT);
if (sprites) if (sprites)
{ {
MinButton->setSpriteBank(sprites); MinButton->setSpriteBank(sprites);
MinButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_MINIMIZE), color); MinButton->setSprite(EGBS_BUTTON_UP, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
MinButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_MINIMIZE), color); MinButton->setSprite(EGBS_BUTTON_DOWN, skin->getIcon(EGDI_WINDOW_MINIMIZE), color);
} }
MinButton->grab(); MinButton->grab();
RestoreButton->grab(); RestoreButton->grab();
CloseButton->grab(); CloseButton->grab();
// this element is a tab group // this element is a tab group
setTabGroup(true); setTabGroup(true);
setTabStop(true); setTabStop(true);
setTabOrder(-1); setTabOrder(-1);
} }
//! destructor //! destructor
CGUIWindow::~CGUIWindow() CGUIWindow::~CGUIWindow()
{ {
if (MinButton) if (MinButton)
MinButton->drop(); MinButton->drop();
if (RestoreButton) if (RestoreButton)
RestoreButton->drop(); RestoreButton->drop();
if (CloseButton) if (CloseButton)
CloseButton->drop(); CloseButton->drop();
} }
//! called if an event happened. //! called if an event happened.
bool CGUIWindow::OnEvent(const SEvent& event) bool CGUIWindow::OnEvent(const SEvent& event)
{ {
if (IsEnabled) if (IsEnabled)
{ {
switch(event.EventType) switch(event.EventType)
{ {
case EET_GUI_EVENT: case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST) if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST)
{ {
Dragging = false; Dragging = false;
} }
else else
if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED) if (event.GUIEvent.EventType == EGET_ELEMENT_FOCUSED)
{ {
if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller))) if (Parent && ((event.GUIEvent.Caller == this) || isMyChild(event.GUIEvent.Caller)))
Parent->bringToFront(this); Parent->bringToFront(this);
} }
else else
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{ {
if (event.GUIEvent.Caller == CloseButton) if (event.GUIEvent.Caller == CloseButton)
{ {
if (Parent) if (Parent)
{ {
// send close event to parent // send close event to parent
SEvent e; SEvent e;
e.EventType = EET_GUI_EVENT; e.EventType = EET_GUI_EVENT;
e.GUIEvent.Caller = this; e.GUIEvent.Caller = this;
e.GUIEvent.Element = 0; e.GUIEvent.Element = 0;
e.GUIEvent.EventType = EGET_ELEMENT_CLOSED; e.GUIEvent.EventType = EGET_ELEMENT_CLOSED;
// if the event was not absorbed // if the event was not absorbed
if (!Parent->OnEvent(e)) if (!Parent->OnEvent(e))
remove(); remove();
return true; return true;
} }
else else
{ {
remove(); remove();
return true; return true;
} }
} }
} }
break; break;
case EET_MOUSE_INPUT_EVENT: case EET_MOUSE_INPUT_EVENT:
switch(event.MouseInput.Event) switch(event.MouseInput.Event)
{ {
case EMIE_LMOUSE_PRESSED_DOWN: case EMIE_LMOUSE_PRESSED_DOWN:
DragStart.X = event.MouseInput.X; DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y; DragStart.Y = event.MouseInput.Y;
Dragging = true; Dragging = true;
if (Parent) if (Parent)
Parent->bringToFront(this); Parent->bringToFront(this);
return true; return true;
case EMIE_LMOUSE_LEFT_UP: case EMIE_LMOUSE_LEFT_UP:
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)
{ {
// gui window should not be dragged outside its parent // gui window should not be dragged outside its parent
if (Parent && if (Parent &&
(event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 || (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 ||
event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 || event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 ||
event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 || event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 ||
event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1)) event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1))
return true; return true;
move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y));
DragStart.X = event.MouseInput.X; DragStart.X = event.MouseInput.X;
DragStart.Y = event.MouseInput.Y; DragStart.Y = event.MouseInput.Y;
return true; return true;
} }
break; break;
default: default:
break; break;
} }
default: default:
break; break;
} }
} }
return IGUIElement::OnEvent(event); return IGUIElement::OnEvent(event);
} }
//! Updates the absolute position. //! Updates the absolute position.
void CGUIWindow::updateAbsolutePosition() void CGUIWindow::updateAbsolutePosition()
{ {
IGUIElement::updateAbsolutePosition(); IGUIElement::updateAbsolutePosition();
} }
//! draws the element and its children //! draws the element and its children
void CGUIWindow::draw() void CGUIWindow::draw()
{ {
if ( IsVisible ) if ( IsVisible )
{ {
IGUISkin* skin = Environment->getSkin(); IGUISkin* skin = Environment->getSkin();
core::rect<s32> rect = AbsoluteRect; core::rect<s32> rect = AbsoluteRect;
// draw body fast // draw body fast
rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER), rect = skin->draw3DWindowBackground(this, true, skin->getColor(EGDC_ACTIVE_BORDER),
AbsoluteRect, &AbsoluteClippingRect); AbsoluteRect, &AbsoluteClippingRect);
if (Text.size()) if (Text.size())
{ {
rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X); rect.UpperLeftCorner.X += skin->getSize(EGDS_TEXT_DISTANCE_X);
rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y); rect.UpperLeftCorner.Y += skin->getSize(EGDS_TEXT_DISTANCE_Y);
rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5; rect.LowerRightCorner.X -= skin->getSize(EGDS_WINDOW_BUTTON_WIDTH) + 5;
IGUIFont* font = skin->getFont(EGDF_WINDOW); IGUIFont* font = skin->getFont(EGDF_WINDOW);
if (font) if (font)
{ {
font->draw(Text.c_str(), rect, font->draw(Text.c_str(), rect,
skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect); skin->getColor(EGDC_ACTIVE_CAPTION), false, true, &AbsoluteClippingRect);
} }
} }
} }
IGUIElement::draw(); IGUIElement::draw();
} }
//! Returns pointer to the close button //! Returns pointer to the close button
IGUIButton* CGUIWindow::getCloseButton() const IGUIButton* CGUIWindow::getCloseButton() const
{ {
return CloseButton; return CloseButton;
} }
//! Returns pointer to the minimize button //! Returns pointer to the minimize button
IGUIButton* CGUIWindow::getMinimizeButton() const IGUIButton* CGUIWindow::getMinimizeButton() const
{ {
return MinButton; return MinButton;
} }
//! Returns pointer to the maximize button //! Returns pointer to the maximize button
IGUIButton* CGUIWindow::getMaximizeButton() const IGUIButton* CGUIWindow::getMaximizeButton() const
{ {
return RestoreButton; return RestoreButton;
} }
} // end namespace gui } // end namespace gui
} // end namespace irr } // end namespace irr
#endif // _IRR_COMPILE_WITH_GUI_ #endif // _IRR_COMPILE_WITH_GUI_
...@@ -198,16 +198,18 @@ namespace irr ...@@ -198,16 +198,18 @@ namespace irr
void postMouseEvent(void *event,irr::SEvent &ievent); void postMouseEvent(void *event,irr::SEvent &ievent);
void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed); void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed);
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,8 +1222,11 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1192,8 +1222,11 @@ 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);
...@@ -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