PageRenderTime 30ms CodeModel.GetById 12ms app.highlight 15ms RepoModel.GetById 1ms app.codeStats 0ms

/src/ois/src/mac/MacInputManager.cpp

https://bitbucket.org/cabalistic/ogredeps/
C++ | 210 lines | 138 code | 30 blank | 42 comment | 28 complexity | 5d0e40c98a8d1c1d3d66e6c3758e17b0 MD5 | raw file
  1/*
  2 The zlib/libpng License
  3 
  4 Copyright (c) 2005-2007 Phillip Castaneda (pjcast -- www.wreckedgames.com)
  5 
  6 This software is provided 'as-is', without any express or implied warranty. In no event will
  7 the authors be held liable for any damages arising from the use of this software.
  8 
  9 Permission is granted to anyone to use this software for any purpose, including commercial
 10 applications, and to alter it and redistribute it freely, subject to the following
 11 restrictions:
 12 
 13 1. The origin of this software must not be misrepresented; you must not claim that
 14 you wrote the original software. If you use this software in a product,
 15 an acknowledgment in the product documentation would be appreciated but is
 16 not required.
 17 
 18 2. Altered source versions must be plainly marked as such, and must not be
 19 misrepresented as being the original software.
 20 
 21 3. This notice may not be removed or altered from any source distribution.
 22 */
 23
 24#ifndef __LP64__
 25
 26#include "mac/MacInputManager.h"
 27#include "mac/MacKeyboard.h"
 28#include "mac/MacMouse.h"
 29#include "mac/MacHIDManager.h"
 30#include "OISException.h"
 31
 32#include <Carbon/Carbon.h>
 33
 34#include <iostream>
 35using namespace std;
 36
 37using namespace OIS;
 38
 39//--------------------------------------------------------------------------------//
 40MacInputManager::MacInputManager() : InputManager("Mac OS X Input Manager")
 41{
 42    mHideMouse = true;
 43    mUseRepeat = false;
 44    mEventTargetRef = NULL;
 45	mWindow = NULL;
 46
 47	keyboardUsed = mouseUsed = false;
 48
 49	//Setup our internal factories
 50	mFactories.push_back(this);
 51
 52	mHIDManager = new MacHIDManager();
 53	mFactories.push_back(mHIDManager);
 54}
 55
 56//--------------------------------------------------------------------------------//
 57MacInputManager::~MacInputManager()
 58{
 59	delete mHIDManager;
 60}
 61
 62//--------------------------------------------------------------------------------//
 63void MacInputManager::_initialize( ParamList &paramList )
 64{
 65	_parseConfigSettings( paramList );
 66    
 67	//Enumerate all devices attached
 68	_enumerateDevices();
 69	
 70	mHIDManager->initialize();
 71}
 72
 73//--------------------------------------------------------------------------------//
 74void MacInputManager::_parseConfigSettings( ParamList &paramList )
 75{
 76    // Some carbon apps are running in a window, however full screen apps
 77	// do not have a window, so we need to account for that too.
 78	ParamList::iterator i = paramList.find("WINDOW");
 79	if(i != paramList.end())
 80	{
 81		mWindow = (WindowRef)strtoul(i->second.c_str(), 0, 10);
 82		if(mWindow == 0)
 83		{
 84			mWindow = NULL;
 85			mEventTargetRef = GetApplicationEventTarget();
 86		}
 87		else
 88		{
 89			//mEventTargetRef = GetWindowEventTarget(mWindow);
 90			mEventTargetRef = GetApplicationEventTarget();
 91		}
 92    }
 93	else
 94	{
 95		// else get the main active window.. user might not have access to it through some
 96		// graphics libraries, if that fails then try at the application level.
 97		mWindow = ActiveNonFloatingWindow();
 98		if(mWindow == NULL)
 99		{
100			mEventTargetRef = GetApplicationEventTarget();
101		}
102		else
103		{
104			//mEventTargetRef = GetWindowEventTarget(mWindow);
105			mEventTargetRef = GetApplicationEventTarget();
106		}
107	}
108	
109	if(mEventTargetRef == NULL)
110		OIS_EXCEPT( E_General, "MacInputManager::_parseConfigSettings >> Unable to find a window or event target" );
111    
112    // Keyboard
113    if(paramList.find("MacAutoRepeatOn") != paramList.end())
114	{
115        if(paramList.find("MacAutoRepeatOn")->second == "true")
116		{
117            mUseRepeat = true;
118        }
119    }
120}
121
122//--------------------------------------------------------------------------------//
123void MacInputManager::_enumerateDevices()
124{
125}
126
127//--------------------------------------------------------------------------------//
128DeviceList MacInputManager::freeDeviceList()
129{
130	DeviceList ret;
131
132	if( keyboardUsed == false )
133		ret.insert(std::make_pair(OISKeyboard, mInputSystemName));
134
135	if( mouseUsed == false )
136		ret.insert(std::make_pair(OISMouse, mInputSystemName));
137
138	return ret;
139}
140
141//--------------------------------------------------------------------------------//
142int MacInputManager::totalDevices(Type iType)
143{
144	switch(iType)
145	{
146	case OISKeyboard: return 1;
147	case OISMouse: return 1;
148	default: return 0;
149	}
150}
151
152//--------------------------------------------------------------------------------//
153int MacInputManager::freeDevices(Type iType)
154{
155	switch(iType)
156	{
157	case OISKeyboard: return keyboardUsed ? 0 : 1;
158	case OISMouse: return mouseUsed ? 0 : 1;
159	default: return 0;
160	}
161}
162
163//--------------------------------------------------------------------------------//
164bool MacInputManager::vendorExist(Type iType, const std::string & vendor)
165{
166	if( (iType == OISKeyboard || iType == OISMouse) && vendor == mInputSystemName )
167		return true;
168
169	return false;
170}
171
172//--------------------------------------------------------------------------------//
173Object* MacInputManager::createObject(InputManager* creator, Type iType, bool bufferMode, 
174									  const std::string & vendor)
175{
176	Object *obj = 0;
177
178	switch(iType)
179	{
180	case OISKeyboard: 
181	{
182		if( keyboardUsed == false )
183			obj = new MacKeyboard(this, bufferMode, mUseRepeat);
184		break;
185	}
186	case OISMouse:
187	{
188		if( mouseUsed == false )
189			obj = new MacMouse(this, bufferMode);
190		break;
191	}
192	default:
193	{
194		obj = mHIDManager->createObject(creator, iType, bufferMode, vendor);
195		break;
196	}
197	}
198
199	if( obj == 0 )
200		OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type.");
201
202	return obj;
203}
204
205//--------------------------------------------------------------------------------//
206void MacInputManager::destroyObject(Object* obj)
207{
208	delete obj;
209}
210#endif