aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm')
-rw-r--r--libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm3784
1 files changed, 1892 insertions, 1892 deletions
diff --git a/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm b/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
index 43453f4..6862c0a 100644
--- a/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
+++ b/libraries/irrlicht-1.8/source/Irrlicht/MacOSX/CIrrDeviceMacOSX.mm
@@ -1,1892 +1,1892 @@
1// Copyright (C) 2005-2006 Etienne Petitjean 1// Copyright (C) 2005-2006 Etienne Petitjean
2// Copyright (C) 2007-2012 Christian Stehno 2// Copyright (C) 2007-2012 Christian Stehno
3// This file is part of the "Irrlicht Engine". 3// This file is part of the "Irrlicht Engine".
4// For conditions of distribution and use, see copyright notice in Irrlicht.h 4// For conditions of distribution and use, see copyright notice in Irrlicht.h
5 5
6#include "IrrCompileConfig.h" 6#include "IrrCompileConfig.h"
7 7
8#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_ 8#ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
9 9
10#import <Cocoa/Cocoa.h> 10#import <Cocoa/Cocoa.h>
11#import <OpenGL/gl.h> 11#import <OpenGL/gl.h>
12#ifndef __MAC_10_6 12#ifndef __MAC_10_6
13#import <Carbon/Carbon.h> 13#import <Carbon/Carbon.h>
14#endif 14#endif
15 15
16#include "CIrrDeviceMacOSX.h" 16#include "CIrrDeviceMacOSX.h"
17#include "IEventReceiver.h" 17#include "IEventReceiver.h"
18#include "irrList.h" 18#include "irrList.h"
19#include "os.h" 19#include "os.h"
20#include "CTimer.h" 20#include "CTimer.h"
21#include "irrString.h" 21#include "irrString.h"
22#include "Keycodes.h" 22#include "Keycodes.h"
23#include <stdio.h> 23#include <stdio.h>
24#include <sys/utsname.h> 24#include <sys/utsname.h>
25#include "COSOperator.h" 25#include "COSOperator.h"
26#include "CColorConverter.h" 26#include "CColorConverter.h"
27#include "irrlicht.h" 27#include "irrlicht.h"
28 28
29 29
30#import <wchar.h> 30#import <wchar.h>
31#import <time.h> 31#import <time.h>
32#import "AppDelegate.h" 32#import "AppDelegate.h"
33 33
34#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 34#if defined _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
35 35
36#include <IOKit/IOKitLib.h> 36#include <IOKit/IOKitLib.h>
37#include <IOKit/IOCFPlugIn.h> 37#include <IOKit/IOCFPlugIn.h>
38#ifdef MACOS_10_0_4 38#ifdef MACOS_10_0_4
39#include <IOKit/hidsystem/IOHIDUsageTables.h> 39#include <IOKit/hidsystem/IOHIDUsageTables.h>
40#else 40#else
41/* The header was moved here in Mac OS X 10.1 */ 41/* The header was moved here in Mac OS X 10.1 */
42#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h> 42#include <Kernel/IOKit/hidsystem/IOHIDUsageTables.h>
43#endif 43#endif
44#include <IOKit/hid/IOHIDLib.h> 44#include <IOKit/hid/IOHIDLib.h>
45#include <IOKit/hid/IOHIDKeys.h> 45#include <IOKit/hid/IOHIDKeys.h>
46 46
47// only OSX 10.5 seems to not need these defines... 47// only OSX 10.5 seems to not need these defines...
48#if !defined(__MAC_10_5) || defined(__MAC_10_6) 48#if !defined(__MAC_10_5) || defined(__MAC_10_6)
49// Contents from Events.h from Carbon/HIToolbox but we need it with Cocoa too 49// Contents from Events.h from Carbon/HIToolbox but we need it with Cocoa too
50// and for some reason no Cocoa equivalent of these constants seems provided. 50// and for some reason no Cocoa equivalent of these constants seems provided.
51// So I'm doing like everyone else and using copy-and-paste. 51// So I'm doing like everyone else and using copy-and-paste.
52 52
53/* 53/*
54 * Summary: 54 * Summary:
55 * Virtual keycodes 55 * Virtual keycodes
56 * 56 *
57 * Discussion: 57 * Discussion:
58 * These constants are the virtual keycodes defined originally in 58 * These constants are the virtual keycodes defined originally in
59 * Inside Mac Volume V, pg. V-191. They identify physical keys on a 59 * Inside Mac Volume V, pg. V-191. They identify physical keys on a
60 * keyboard. Those constants with "ANSI" in the name are labeled 60 * keyboard. Those constants with "ANSI" in the name are labeled
61 * according to the key position on an ANSI-standard US keyboard. 61 * according to the key position on an ANSI-standard US keyboard.
62 * For example, kVK_ANSI_A indicates the virtual keycode for the key 62 * For example, kVK_ANSI_A indicates the virtual keycode for the key
63 * with the letter 'A' in the US keyboard layout. Other keyboard 63 * with the letter 'A' in the US keyboard layout. Other keyboard
64 * layouts may have the 'A' key label on a different physical key; 64 * layouts may have the 'A' key label on a different physical key;
65 * in this case, pressing 'A' will generate a different virtual 65 * in this case, pressing 'A' will generate a different virtual
66 * keycode. 66 * keycode.
67 */ 67 */
68enum { 68enum {
69 kVK_ANSI_A = 0x00, 69 kVK_ANSI_A = 0x00,
70 kVK_ANSI_S = 0x01, 70 kVK_ANSI_S = 0x01,
71 kVK_ANSI_D = 0x02, 71 kVK_ANSI_D = 0x02,
72 kVK_ANSI_F = 0x03, 72 kVK_ANSI_F = 0x03,
73 kVK_ANSI_H = 0x04, 73 kVK_ANSI_H = 0x04,
74 kVK_ANSI_G = 0x05, 74 kVK_ANSI_G = 0x05,
75 kVK_ANSI_Z = 0x06, 75 kVK_ANSI_Z = 0x06,
76 kVK_ANSI_X = 0x07, 76 kVK_ANSI_X = 0x07,
77 kVK_ANSI_C = 0x08, 77 kVK_ANSI_C = 0x08,
78 kVK_ANSI_V = 0x09, 78 kVK_ANSI_V = 0x09,
79 kVK_ANSI_B = 0x0B, 79 kVK_ANSI_B = 0x0B,
80 kVK_ANSI_Q = 0x0C, 80 kVK_ANSI_Q = 0x0C,
81 kVK_ANSI_W = 0x0D, 81 kVK_ANSI_W = 0x0D,
82 kVK_ANSI_E = 0x0E, 82 kVK_ANSI_E = 0x0E,
83 kVK_ANSI_R = 0x0F, 83 kVK_ANSI_R = 0x0F,
84 kVK_ANSI_Y = 0x10, 84 kVK_ANSI_Y = 0x10,
85 kVK_ANSI_T = 0x11, 85 kVK_ANSI_T = 0x11,
86 kVK_ANSI_1 = 0x12, 86 kVK_ANSI_1 = 0x12,
87 kVK_ANSI_2 = 0x13, 87 kVK_ANSI_2 = 0x13,
88 kVK_ANSI_3 = 0x14, 88 kVK_ANSI_3 = 0x14,
89 kVK_ANSI_4 = 0x15, 89 kVK_ANSI_4 = 0x15,
90 kVK_ANSI_6 = 0x16, 90 kVK_ANSI_6 = 0x16,
91 kVK_ANSI_5 = 0x17, 91 kVK_ANSI_5 = 0x17,
92 kVK_ANSI_Equal = 0x18, 92 kVK_ANSI_Equal = 0x18,
93 kVK_ANSI_9 = 0x19, 93 kVK_ANSI_9 = 0x19,
94 kVK_ANSI_7 = 0x1A, 94 kVK_ANSI_7 = 0x1A,
95 kVK_ANSI_Minus = 0x1B, 95 kVK_ANSI_Minus = 0x1B,
96 kVK_ANSI_8 = 0x1C, 96 kVK_ANSI_8 = 0x1C,
97 kVK_ANSI_0 = 0x1D, 97 kVK_ANSI_0 = 0x1D,
98 kVK_ANSI_RightBracket = 0x1E, 98 kVK_ANSI_RightBracket = 0x1E,
99 kVK_ANSI_O = 0x1F, 99 kVK_ANSI_O = 0x1F,
100 kVK_ANSI_U = 0x20, 100 kVK_ANSI_U = 0x20,
101 kVK_ANSI_LeftBracket = 0x21, 101 kVK_ANSI_LeftBracket = 0x21,
102 kVK_ANSI_I = 0x22, 102 kVK_ANSI_I = 0x22,
103 kVK_ANSI_P = 0x23, 103 kVK_ANSI_P = 0x23,
104 kVK_ANSI_L = 0x25, 104 kVK_ANSI_L = 0x25,
105 kVK_ANSI_J = 0x26, 105 kVK_ANSI_J = 0x26,
106 kVK_ANSI_Quote = 0x27, 106 kVK_ANSI_Quote = 0x27,
107 kVK_ANSI_K = 0x28, 107 kVK_ANSI_K = 0x28,
108 kVK_ANSI_Semicolon = 0x29, 108 kVK_ANSI_Semicolon = 0x29,
109 kVK_ANSI_Backslash = 0x2A, 109 kVK_ANSI_Backslash = 0x2A,
110 kVK_ANSI_Comma = 0x2B, 110 kVK_ANSI_Comma = 0x2B,
111 kVK_ANSI_Slash = 0x2C, 111 kVK_ANSI_Slash = 0x2C,
112 kVK_ANSI_N = 0x2D, 112 kVK_ANSI_N = 0x2D,
113 kVK_ANSI_M = 0x2E, 113 kVK_ANSI_M = 0x2E,
114 kVK_ANSI_Period = 0x2F, 114 kVK_ANSI_Period = 0x2F,
115 kVK_ANSI_Grave = 0x32, 115 kVK_ANSI_Grave = 0x32,
116 kVK_ANSI_KeypadDecimal = 0x41, 116 kVK_ANSI_KeypadDecimal = 0x41,
117 kVK_ANSI_KeypadMultiply = 0x43, 117 kVK_ANSI_KeypadMultiply = 0x43,
118 kVK_ANSI_KeypadPlus = 0x45, 118 kVK_ANSI_KeypadPlus = 0x45,
119 kVK_ANSI_KeypadClear = 0x47, 119 kVK_ANSI_KeypadClear = 0x47,
120 kVK_ANSI_KeypadDivide = 0x4B, 120 kVK_ANSI_KeypadDivide = 0x4B,
121 kVK_ANSI_KeypadEnter = 0x4C, 121 kVK_ANSI_KeypadEnter = 0x4C,
122 kVK_ANSI_KeypadMinus = 0x4E, 122 kVK_ANSI_KeypadMinus = 0x4E,
123 kVK_ANSI_KeypadEquals = 0x51, 123 kVK_ANSI_KeypadEquals = 0x51,
124 kVK_ANSI_Keypad0 = 0x52, 124 kVK_ANSI_Keypad0 = 0x52,
125 kVK_ANSI_Keypad1 = 0x53, 125 kVK_ANSI_Keypad1 = 0x53,
126 kVK_ANSI_Keypad2 = 0x54, 126 kVK_ANSI_Keypad2 = 0x54,
127 kVK_ANSI_Keypad3 = 0x55, 127 kVK_ANSI_Keypad3 = 0x55,
128 kVK_ANSI_Keypad4 = 0x56, 128 kVK_ANSI_Keypad4 = 0x56,
129 kVK_ANSI_Keypad5 = 0x57, 129 kVK_ANSI_Keypad5 = 0x57,
130 kVK_ANSI_Keypad6 = 0x58, 130 kVK_ANSI_Keypad6 = 0x58,
131 kVK_ANSI_Keypad7 = 0x59, 131 kVK_ANSI_Keypad7 = 0x59,
132 kVK_ANSI_Keypad8 = 0x5B, 132 kVK_ANSI_Keypad8 = 0x5B,
133 kVK_ANSI_Keypad9 = 0x5C 133 kVK_ANSI_Keypad9 = 0x5C
134}; 134};
135 135
136/* keycodes for keys that are independent of keyboard layout*/ 136/* keycodes for keys that are independent of keyboard layout*/
137enum { 137enum {
138 kVK_Return = 0x24, 138 kVK_Return = 0x24,
139 kVK_Tab = 0x30, 139 kVK_Tab = 0x30,
140 kVK_Space = 0x31, 140 kVK_Space = 0x31,
141 kVK_Delete = 0x33, 141 kVK_Delete = 0x33,
142 kVK_Escape = 0x35, 142 kVK_Escape = 0x35,
143 kVK_Command = 0x37, 143 kVK_Command = 0x37,
144 kVK_Shift = 0x38, 144 kVK_Shift = 0x38,
145 kVK_CapsLock = 0x39, 145 kVK_CapsLock = 0x39,
146 kVK_Option = 0x3A, 146 kVK_Option = 0x3A,
147 kVK_Control = 0x3B, 147 kVK_Control = 0x3B,
148 kVK_RightShift = 0x3C, 148 kVK_RightShift = 0x3C,
149 kVK_RightOption = 0x3D, 149 kVK_RightOption = 0x3D,
150 kVK_RightControl = 0x3E, 150 kVK_RightControl = 0x3E,
151 kVK_Function = 0x3F, 151 kVK_Function = 0x3F,
152 kVK_F17 = 0x40, 152 kVK_F17 = 0x40,
153 kVK_VolumeUp = 0x48, 153 kVK_VolumeUp = 0x48,
154 kVK_VolumeDown = 0x49, 154 kVK_VolumeDown = 0x49,
155 kVK_Mute = 0x4A, 155 kVK_Mute = 0x4A,
156 kVK_F18 = 0x4F, 156 kVK_F18 = 0x4F,
157 kVK_F19 = 0x50, 157 kVK_F19 = 0x50,
158 kVK_F20 = 0x5A, 158 kVK_F20 = 0x5A,
159 kVK_F5 = 0x60, 159 kVK_F5 = 0x60,
160 kVK_F6 = 0x61, 160 kVK_F6 = 0x61,
161 kVK_F7 = 0x62, 161 kVK_F7 = 0x62,
162 kVK_F3 = 0x63, 162 kVK_F3 = 0x63,
163 kVK_F8 = 0x64, 163 kVK_F8 = 0x64,
164 kVK_F9 = 0x65, 164 kVK_F9 = 0x65,
165 kVK_F11 = 0x67, 165 kVK_F11 = 0x67,
166 kVK_F13 = 0x69, 166 kVK_F13 = 0x69,
167 kVK_F16 = 0x6A, 167 kVK_F16 = 0x6A,
168 kVK_F14 = 0x6B, 168 kVK_F14 = 0x6B,
169 kVK_F10 = 0x6D, 169 kVK_F10 = 0x6D,
170 kVK_F12 = 0x6F, 170 kVK_F12 = 0x6F,
171 kVK_F15 = 0x71, 171 kVK_F15 = 0x71,
172 kVK_Help = 0x72, 172 kVK_Help = 0x72,
173 kVK_Home = 0x73, 173 kVK_Home = 0x73,
174 kVK_PageUp = 0x74, 174 kVK_PageUp = 0x74,
175 kVK_ForwardDelete = 0x75, 175 kVK_ForwardDelete = 0x75,
176 kVK_F4 = 0x76, 176 kVK_F4 = 0x76,
177 kVK_End = 0x77, 177 kVK_End = 0x77,
178 kVK_F2 = 0x78, 178 kVK_F2 = 0x78,
179 kVK_PageDown = 0x79, 179 kVK_PageDown = 0x79,
180 kVK_F1 = 0x7A, 180 kVK_F1 = 0x7A,
181 kVK_LeftArrow = 0x7B, 181 kVK_LeftArrow = 0x7B,
182 kVK_RightArrow = 0x7C, 182 kVK_RightArrow = 0x7C,
183 kVK_DownArrow = 0x7D, 183 kVK_DownArrow = 0x7D,
184 kVK_UpArrow = 0x7E 184 kVK_UpArrow = 0x7E
185}; 185};
186#endif 186#endif
187 187
188struct JoystickComponent 188struct JoystickComponent
189{ 189{
190 IOHIDElementCookie cookie; // unique value which identifies element, will NOT change 190 IOHIDElementCookie cookie; // unique value which identifies element, will NOT change
191 long min; // reported min value possible 191 long min; // reported min value possible
192 long max; // reported max value possible 192 long max; // reported max value possible
193 193
194 long minRead; //min read value 194 long minRead; //min read value
195 long maxRead; //max read value 195 long maxRead; //max read value
196 196
197 JoystickComponent() : min(0), minRead(0), max(0), maxRead(0) 197 JoystickComponent() : min(0), minRead(0), max(0), maxRead(0)
198 { 198 {
199 } 199 }
200}; 200};
201 201
202struct JoystickInfo 202struct JoystickInfo
203{ 203{
204 irr::core::array <JoystickComponent> axisComp; 204 irr::core::array <JoystickComponent> axisComp;
205 irr::core::array <JoystickComponent> buttonComp; 205 irr::core::array <JoystickComponent> buttonComp;
206 irr::core::array <JoystickComponent> hatComp; 206 irr::core::array <JoystickComponent> hatComp;
207 207
208 int hats; 208 int hats;
209 int axes; 209 int axes;
210 int buttons; 210 int buttons;
211 int numActiveJoysticks; 211 int numActiveJoysticks;
212 212
213 irr::SEvent persistentData; 213 irr::SEvent persistentData;
214 214
215 IOHIDDeviceInterface ** interface; 215 IOHIDDeviceInterface ** interface;
216 bool removed; 216 bool removed;
217 char joystickName[256]; 217 char joystickName[256];
218 long usage; // usage page from IOUSBHID Parser.h which defines general usage 218 long usage; // usage page from IOUSBHID Parser.h which defines general usage
219 long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage 219 long usagePage; // usage within above page from IOUSBHID Parser.h which defines specific usage
220 220
221 JoystickInfo() : hats(0), axes(0), buttons(0), interface(0), removed(false), usage(0), usagePage(0), numActiveJoysticks(0) 221 JoystickInfo() : hats(0), axes(0), buttons(0), interface(0), removed(false), usage(0), usagePage(0), numActiveJoysticks(0)
222 { 222 {
223 interface = NULL; 223 interface = NULL;
224 memset(joystickName, '\0', 256); 224 memset(joystickName, '\0', 256);
225 axisComp.clear(); 225 axisComp.clear();
226 buttonComp.clear(); 226 buttonComp.clear();
227 hatComp.clear(); 227 hatComp.clear();
228 228
229 persistentData.EventType = irr::EET_JOYSTICK_INPUT_EVENT; 229 persistentData.EventType = irr::EET_JOYSTICK_INPUT_EVENT;
230 persistentData.JoystickEvent.POV = 65535; 230 persistentData.JoystickEvent.POV = 65535;
231 persistentData.JoystickEvent.ButtonStates = 0; 231 persistentData.JoystickEvent.ButtonStates = 0;
232 } 232 }
233}; 233};
234irr::core::array<JoystickInfo> ActiveJoysticks; 234irr::core::array<JoystickInfo> ActiveJoysticks;
235 235
236//helper functions for init joystick 236//helper functions for init joystick
237static IOReturn closeJoystickDevice (JoystickInfo* joyInfo) 237static IOReturn closeJoystickDevice (JoystickInfo* joyInfo)
238{ 238{
239 IOReturn result = kIOReturnSuccess; 239 IOReturn result = kIOReturnSuccess;
240 if (joyInfo && joyInfo->interface) 240 if (joyInfo && joyInfo->interface)
241 { 241 {
242 /* close the interface */ 242 /* close the interface */
243 result = (*(joyInfo->interface))->close (joyInfo->interface); 243 result = (*(joyInfo->interface))->close (joyInfo->interface);
244 if (kIOReturnNotOpen == result) 244 if (kIOReturnNotOpen == result)
245 { 245 {
246 /* do nothing as device was not opened, thus can't be closed */ 246 /* do nothing as device was not opened, thus can't be closed */
247 } 247 }
248 else if (kIOReturnSuccess != result) 248 else if (kIOReturnSuccess != result)
249 irr::os::Printer::log("IOHIDDeviceInterface failed to close", irr::ELL_ERROR); 249 irr::os::Printer::log("IOHIDDeviceInterface failed to close", irr::ELL_ERROR);
250 /* release the interface */ 250 /* release the interface */
251 result = (*(joyInfo->interface))->Release (joyInfo->interface); 251 result = (*(joyInfo->interface))->Release (joyInfo->interface);
252 if (kIOReturnSuccess != result) 252 if (kIOReturnSuccess != result)
253 irr::os::Printer::log("IOHIDDeviceInterface failed to release", irr::ELL_ERROR); 253 irr::os::Printer::log("IOHIDDeviceInterface failed to release", irr::ELL_ERROR);
254 joyInfo->interface = NULL; 254 joyInfo->interface = NULL;
255 } 255 }
256 return result; 256 return result;
257} 257}
258 258
259static void addComponentInfo (CFTypeRef refElement, JoystickComponent *pComponent, int numActiveJoysticks) 259static void addComponentInfo (CFTypeRef refElement, JoystickComponent *pComponent, int numActiveJoysticks)
260{ 260{
261 long number; 261 long number;
262 CFTypeRef refType; 262 CFTypeRef refType;
263 263
264 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementCookieKey)); 264 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementCookieKey));
265 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number)) 265 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number))
266 pComponent->cookie = (IOHIDElementCookie) number; 266 pComponent->cookie = (IOHIDElementCookie) number;
267 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMinKey)); 267 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMinKey));
268 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number)) 268 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number))
269 pComponent->minRead = pComponent->min = number; 269 pComponent->minRead = pComponent->min = number;
270 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMaxKey)); 270 refType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementMaxKey));
271 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number)) 271 if (refType && CFNumberGetValue ((CFNumberRef)refType, kCFNumberLongType, &number))
272 pComponent->maxRead = pComponent->max = number; 272 pComponent->maxRead = pComponent->max = number;
273} 273}
274 274
275static void getJoystickComponentArrayHandler (const void * value, void * parameter); 275static void getJoystickComponentArrayHandler (const void * value, void * parameter);
276 276
277static void addJoystickComponent (CFTypeRef refElement, JoystickInfo* joyInfo) 277static void addJoystickComponent (CFTypeRef refElement, JoystickInfo* joyInfo)
278{ 278{
279 long elementType, usagePage, usage; 279 long elementType, usagePage, usage;
280 CFTypeRef refElementType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementTypeKey)); 280 CFTypeRef refElementType = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementTypeKey));
281 CFTypeRef refUsagePage = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsagePageKey)); 281 CFTypeRef refUsagePage = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsagePageKey));
282 CFTypeRef refUsage = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsageKey)); 282 CFTypeRef refUsage = CFDictionaryGetValue ((CFDictionaryRef)refElement, CFSTR(kIOHIDElementUsageKey));
283 283
284 if ((refElementType) && (CFNumberGetValue ((CFNumberRef)refElementType, kCFNumberLongType, &elementType))) 284 if ((refElementType) && (CFNumberGetValue ((CFNumberRef)refElementType, kCFNumberLongType, &elementType)))
285 { 285 {
286 /* look at types of interest */ 286 /* look at types of interest */
287 if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) || 287 if ((elementType == kIOHIDElementTypeInput_Misc) || (elementType == kIOHIDElementTypeInput_Button) ||
288 (elementType == kIOHIDElementTypeInput_Axis)) 288 (elementType == kIOHIDElementTypeInput_Axis))
289 { 289 {
290 if (refUsagePage && CFNumberGetValue ((CFNumberRef)refUsagePage, kCFNumberLongType, &usagePage) && 290 if (refUsagePage && CFNumberGetValue ((CFNumberRef)refUsagePage, kCFNumberLongType, &usagePage) &&
291 refUsage && CFNumberGetValue ((CFNumberRef)refUsage, kCFNumberLongType, &usage)) 291 refUsage && CFNumberGetValue ((CFNumberRef)refUsage, kCFNumberLongType, &usage))
292 { 292 {
293 switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */ 293 switch (usagePage) /* only interested in kHIDPage_GenericDesktop and kHIDPage_Button */
294 { 294 {
295 case kHIDPage_GenericDesktop: 295 case kHIDPage_GenericDesktop:
296 { 296 {
297 switch (usage) /* look at usage to determine function */ 297 switch (usage) /* look at usage to determine function */
298 { 298 {
299 case kHIDUsage_GD_X: 299 case kHIDUsage_GD_X:
300 case kHIDUsage_GD_Y: 300 case kHIDUsage_GD_Y:
301 case kHIDUsage_GD_Z: 301 case kHIDUsage_GD_Z:
302 case kHIDUsage_GD_Rx: 302 case kHIDUsage_GD_Rx:
303 case kHIDUsage_GD_Ry: 303 case kHIDUsage_GD_Ry:
304 case kHIDUsage_GD_Rz: 304 case kHIDUsage_GD_Rz:
305 case kHIDUsage_GD_Slider: 305 case kHIDUsage_GD_Slider:
306 case kHIDUsage_GD_Dial: 306 case kHIDUsage_GD_Dial:
307 case kHIDUsage_GD_Wheel: 307 case kHIDUsage_GD_Wheel:
308 { 308 {
309 joyInfo->axes++; 309 joyInfo->axes++;
310 JoystickComponent newComponent; 310 JoystickComponent newComponent;
311 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); 311 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks);
312 joyInfo->axisComp.push_back(newComponent); 312 joyInfo->axisComp.push_back(newComponent);
313 } 313 }
314 break; 314 break;
315 case kHIDUsage_GD_Hatswitch: 315 case kHIDUsage_GD_Hatswitch:
316 { 316 {
317 joyInfo->hats++; 317 joyInfo->hats++;
318 JoystickComponent newComponent; 318 JoystickComponent newComponent;
319 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); 319 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks);
320 joyInfo->hatComp.push_back(newComponent); 320 joyInfo->hatComp.push_back(newComponent);
321 } 321 }
322 break; 322 break;
323 } 323 }
324 } 324 }
325 break; 325 break;
326 case kHIDPage_Button: 326 case kHIDPage_Button:
327 { 327 {
328 joyInfo->buttons++; 328 joyInfo->buttons++;
329 JoystickComponent newComponent; 329 JoystickComponent newComponent;
330 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks); 330 addComponentInfo(refElement, &newComponent, joyInfo->numActiveJoysticks);
331 joyInfo->buttonComp.push_back(newComponent); 331 joyInfo->buttonComp.push_back(newComponent);
332 } 332 }
333 break; 333 break;
334 default: 334 default:
335 break; 335 break;
336 } 336 }
337 } 337 }
338 } 338 }
339 else if (kIOHIDElementTypeCollection == elementType) 339 else if (kIOHIDElementTypeCollection == elementType)
340 { 340 {
341 //get elements 341 //get elements
342 CFTypeRef refElementTop = CFDictionaryGetValue ((CFMutableDictionaryRef) refElement, CFSTR(kIOHIDElementKey)); 342 CFTypeRef refElementTop = CFDictionaryGetValue ((CFMutableDictionaryRef) refElement, CFSTR(kIOHIDElementKey));
343 if (refElementTop) 343 if (refElementTop)
344 { 344 {
345 CFTypeID type = CFGetTypeID (refElementTop); 345 CFTypeID type = CFGetTypeID (refElementTop);
346 if (type == CFArrayGetTypeID()) 346 if (type == CFArrayGetTypeID())
347 { 347 {
348 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)}; 348 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
349 CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo); 349 CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, joyInfo);
350 } 350 }
351 } 351 }
352 } 352 }
353 } 353 }
354} 354}
355 355
356static void getJoystickComponentArrayHandler (const void * value, void * parameter) 356static void getJoystickComponentArrayHandler (const void * value, void * parameter)
357{ 357{
358 if (CFGetTypeID (value) == CFDictionaryGetTypeID ()) 358 if (CFGetTypeID (value) == CFDictionaryGetTypeID ())
359 addJoystickComponent ((CFTypeRef) value, (JoystickInfo *) parameter); 359 addJoystickComponent ((CFTypeRef) value, (JoystickInfo *) parameter);
360} 360}
361 361
362static void joystickTopLevelElementHandler (const void * value, void * parameter) 362static void joystickTopLevelElementHandler (const void * value, void * parameter)
363{ 363{
364 CFTypeRef refCF = 0; 364 CFTypeRef refCF = 0;
365 if (CFGetTypeID (value) != CFDictionaryGetTypeID ()) 365 if (CFGetTypeID (value) != CFDictionaryGetTypeID ())
366 return; 366 return;
367 refCF = CFDictionaryGetValue ((CFDictionaryRef)value, CFSTR(kIOHIDElementUsagePageKey)); 367 refCF = CFDictionaryGetValue ((CFDictionaryRef)value, CFSTR(kIOHIDElementUsagePageKey));
368 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *) parameter)->usagePage)) 368 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *) parameter)->usagePage))
369 irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usagePage", irr::ELL_ERROR); 369 irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usagePage", irr::ELL_ERROR);
370 refCF = CFDictionaryGetValue ((CFDictionaryRef)value, CFSTR(kIOHIDElementUsageKey)); 370 refCF = CFDictionaryGetValue ((CFDictionaryRef)value, CFSTR(kIOHIDElementUsageKey));
371 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *) parameter)->usage)) 371 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &((JoystickInfo *) parameter)->usage))
372 irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usage", irr::ELL_ERROR); 372 irr::os::Printer::log("CFNumberGetValue error retrieving JoystickInfo->usage", irr::ELL_ERROR);
373} 373}
374 374
375static void getJoystickDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, JoystickInfo *joyInfo) 375static void getJoystickDeviceInfo (io_object_t hidDevice, CFMutableDictionaryRef hidProperties, JoystickInfo *joyInfo)
376{ 376{
377 CFMutableDictionaryRef usbProperties = 0; 377 CFMutableDictionaryRef usbProperties = 0;
378 io_registry_entry_t parent1, parent2; 378 io_registry_entry_t parent1, parent2;
379 379
380 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also 380 /* Mac OS X currently is not mirroring all USB properties to HID page so need to look at USB device page also
381 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties 381 * get dictionary for usb properties: step up two levels and get CF dictionary for USB properties
382 */ 382 */
383 if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) && 383 if ((KERN_SUCCESS == IORegistryEntryGetParentEntry (hidDevice, kIOServicePlane, &parent1)) &&
384 (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) && 384 (KERN_SUCCESS == IORegistryEntryGetParentEntry (parent1, kIOServicePlane, &parent2)) &&
385 (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions))) 385 (KERN_SUCCESS == IORegistryEntryCreateCFProperties (parent2, &usbProperties, kCFAllocatorDefault, kNilOptions)))
386 { 386 {
387 if (usbProperties) 387 if (usbProperties)
388 { 388 {
389 CFTypeRef refCF = 0; 389 CFTypeRef refCF = 0;
390 /* get device info 390 /* get device info
391 * try hid dictionary first, if fail then go to usb dictionary 391 * try hid dictionary first, if fail then go to usb dictionary
392 */ 392 */
393 393
394 /* get joystickName name */ 394 /* get joystickName name */
395 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey)); 395 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDProductKey));
396 if (!refCF) 396 if (!refCF)
397 refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name")); 397 refCF = CFDictionaryGetValue (usbProperties, CFSTR("USB Product Name"));
398 if (refCF) 398 if (refCF)
399 { 399 {
400 if (!CFStringGetCString ((CFStringRef)refCF, joyInfo->joystickName, 256, CFStringGetSystemEncoding ())) 400 if (!CFStringGetCString ((CFStringRef)refCF, joyInfo->joystickName, 256, CFStringGetSystemEncoding ()))
401 irr::os::Printer::log("CFStringGetCString error getting joyInfo->joystickName", irr::ELL_ERROR); 401 irr::os::Printer::log("CFStringGetCString error getting joyInfo->joystickName", irr::ELL_ERROR);
402 } 402 }
403 403
404 /* get usage page and usage */ 404 /* get usage page and usage */
405 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey)); 405 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsagePageKey));
406 if (refCF) 406 if (refCF)
407 { 407 {
408 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usagePage)) 408 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usagePage))
409 irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usagePage", irr::ELL_ERROR); 409 irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usagePage", irr::ELL_ERROR);
410 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey)); 410 refCF = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDPrimaryUsageKey));
411 if (refCF) 411 if (refCF)
412 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usage)) 412 if (!CFNumberGetValue ((CFNumberRef)refCF, kCFNumberLongType, &joyInfo->usage))
413 irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usage", irr::ELL_ERROR); 413 irr::os::Printer::log("CFNumberGetValue error getting joyInfo->usage", irr::ELL_ERROR);
414 } 414 }
415 415
416 if (NULL == refCF) /* get top level element HID usage page or usage */ 416 if (NULL == refCF) /* get top level element HID usage page or usage */
417 { 417 {
418 /* use top level element instead */ 418 /* use top level element instead */
419 CFTypeRef refCFTopElement = 0; 419 CFTypeRef refCFTopElement = 0;
420 refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); 420 refCFTopElement = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
421 { 421 {
422 /* refCFTopElement points to an array of element dictionaries */ 422 /* refCFTopElement points to an array of element dictionaries */
423 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refCFTopElement)}; 423 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refCFTopElement)};
424 CFArrayApplyFunction ((CFArrayRef)refCFTopElement, range, joystickTopLevelElementHandler, joyInfo); 424 CFArrayApplyFunction ((CFArrayRef)refCFTopElement, range, joystickTopLevelElementHandler, joyInfo);
425 } 425 }
426 } 426 }
427 427
428 CFRelease (usbProperties); 428 CFRelease (usbProperties);
429 } 429 }
430 else 430 else
431 irr::os::Printer::log("IORegistryEntryCreateCFProperties failed to create usbProperties", irr::ELL_ERROR); 431 irr::os::Printer::log("IORegistryEntryCreateCFProperties failed to create usbProperties", irr::ELL_ERROR);
432 432
433 if (kIOReturnSuccess != IOObjectRelease (parent2)) 433 if (kIOReturnSuccess != IOObjectRelease (parent2))
434 irr::os::Printer::log("IOObjectRelease failed to release parent2", irr::ELL_ERROR); 434 irr::os::Printer::log("IOObjectRelease failed to release parent2", irr::ELL_ERROR);
435 if (kIOReturnSuccess != IOObjectRelease (parent1)) 435 if (kIOReturnSuccess != IOObjectRelease (parent1))
436 irr::os::Printer::log("IOObjectRelease failed to release parent1", irr::ELL_ERROR); 436 irr::os::Printer::log("IOObjectRelease failed to release parent1", irr::ELL_ERROR);
437 } 437 }
438} 438}
439 439
440#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 440#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
441 441
442//------------------------------------------------------------------------------------------ 442//------------------------------------------------------------------------------------------
443Boolean GetDictionaryBoolean(CFDictionaryRef theDict, const void* key) 443Boolean GetDictionaryBoolean(CFDictionaryRef theDict, const void* key)
444{ 444{
445 // get a boolean from the dictionary 445 // get a boolean from the dictionary
446 Boolean value = false; 446 Boolean value = false;
447 CFBooleanRef boolRef; 447 CFBooleanRef boolRef;
448 boolRef = (CFBooleanRef)CFDictionaryGetValue(theDict, key); 448 boolRef = (CFBooleanRef)CFDictionaryGetValue(theDict, key);
449 if (boolRef != NULL) 449 if (boolRef != NULL)
450 value = CFBooleanGetValue(boolRef); 450 value = CFBooleanGetValue(boolRef);
451 return value; 451 return value;
452} 452}
453//------------------------------------------------------------------------------------------ 453//------------------------------------------------------------------------------------------
454long GetDictionaryLong(CFDictionaryRef theDict, const void* key) 454long GetDictionaryLong(CFDictionaryRef theDict, const void* key)
455{ 455{
456 // get a long from the dictionary 456 // get a long from the dictionary
457 long value = 0; 457 long value = 0;
458 CFNumberRef numRef; 458 CFNumberRef numRef;
459 numRef = (CFNumberRef)CFDictionaryGetValue(theDict, key); 459 numRef = (CFNumberRef)CFDictionaryGetValue(theDict, key);
460 if (numRef != NULL) 460 if (numRef != NULL)
461 CFNumberGetValue(numRef, kCFNumberLongType, &value); 461 CFNumberGetValue(numRef, kCFNumberLongType, &value);
462 return value; 462 return value;
463} 463}
464 464
465namespace irr 465namespace irr
466{ 466{
467 namespace video 467 namespace video
468 { 468 {
469 IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& param, io::IFileSystem* io, CIrrDeviceMacOSX *device); 469 IVideoDriver* createOpenGLDriver(const SIrrlichtCreationParameters& param, io::IFileSystem* io, CIrrDeviceMacOSX *device);
470 } 470 }
471} // end namespace irr 471} // end namespace irr
472 472
473static bool firstLaunch = true; 473static bool firstLaunch = true;
474 474
475namespace irr 475namespace irr
476{ 476{
477//! constructor 477//! constructor
478CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) 478CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
479 : CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL), 479 : CIrrDeviceStub(param), Window(NULL), CGLContext(NULL), OGLContext(NULL),
480 SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0), 480 SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0),
481 ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), SoftwareRendererType(0), 481 ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), SoftwareRendererType(0),
482 IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false) 482 IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false)
483{ 483{
484 struct utsname name; 484 struct utsname name;
485 NSString *path; 485 NSString *path;
486 486
487 #ifdef _DEBUG 487 #ifdef _DEBUG
488 setDebugName("CIrrDeviceMacOSX"); 488 setDebugName("CIrrDeviceMacOSX");
489 #endif 489 #endif
490 490
491 if (firstLaunch) 491 if (firstLaunch)
492 { 492 {
493 firstLaunch = false; 493 firstLaunch = false;
494 494
495 if(!CreationParams.WindowId) //load menus if standalone application 495 if(!CreationParams.WindowId) //load menus if standalone application
496 { 496 {
497 [[NSAutoreleasePool alloc] init]; 497 [[NSAutoreleasePool alloc] init];
498 [NSApplication sharedApplication]; 498 [NSApplication sharedApplication];
499 [NSApp setDelegate:[[[AppDelegate alloc] initWithDevice:this] autorelease]]; 499 [NSApp setDelegate:[[[AppDelegate alloc] initWithDevice:this] autorelease]];
500 [NSBundle loadNibNamed:@"MainMenu" owner:[NSApp delegate]]; 500 [NSBundle loadNibNamed:@"MainMenu" owner:[NSApp delegate]];
501 [NSApp finishLaunching]; 501 [NSApp finishLaunching];
502 } 502 }
503 503
504 path = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent]; 504 path = [[[NSBundle mainBundle] bundlePath] stringByDeletingLastPathComponent];
505 chdir([path fileSystemRepresentation]); 505 chdir([path fileSystemRepresentation]);
506 [path release]; 506 [path release];
507 } 507 }
508 508
509 uname(&name); 509 uname(&name);
510 Operator = new COSOperator(name.version); 510 Operator = new COSOperator(name.version);
511 os::Printer::log(name.version,ELL_INFORMATION); 511 os::Printer::log(name.version,ELL_INFORMATION);
512 512
513 initKeycodes(); 513 initKeycodes();
514 514
515 VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>([[NSScreen mainScreen] frame].size.width, [[NSScreen mainScreen] frame].size.height)); 515 VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>([[NSScreen mainScreen] frame].size.width, [[NSScreen mainScreen] frame].size.height));
516 516
517 bool success = true; 517 bool success = true;
518 if (CreationParams.DriverType != video::EDT_NULL) 518 if (CreationParams.DriverType != video::EDT_NULL)
519 success = createWindow(); 519 success = createWindow();
520 520
521 // in case of failure, one can check VideoDriver for initialization 521 // in case of failure, one can check VideoDriver for initialization
522 if (!success) 522 if (!success)
523 return; 523 return;
524 524
525 setResizable(false); 525 setResizable(false);
526 CursorControl = new CCursorControl(CreationParams.WindowSize, this); 526 CursorControl = new CCursorControl(CreationParams.WindowSize, this);
527 527
528 createDriver(); 528 createDriver();
529 createGUIAndScene(); 529 createGUIAndScene();
530} 530}
531 531
532CIrrDeviceMacOSX::~CIrrDeviceMacOSX() 532CIrrDeviceMacOSX::~CIrrDeviceMacOSX()
533{ 533{
534 [SoftwareDriverTarget release]; 534 [SoftwareDriverTarget release];
535#ifdef __MAC_10_6 535#ifdef __MAC_10_6
536 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)]; 536 [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
537#else 537#else
538 SetSystemUIMode(kUIModeNormal, kUIOptionAutoShowMenuBar); 538 SetSystemUIMode(kUIModeNormal, kUIOptionAutoShowMenuBar);
539#endif 539#endif
540 closeDevice(); 540 closeDevice();
541#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) 541#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
542 for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) 542 for (u32 joystick = 0; joystick < ActiveJoysticks.size(); ++joystick)
543 { 543 {
544 if (ActiveJoysticks[joystick].interface) 544 if (ActiveJoysticks[joystick].interface)
545 closeJoystickDevice(&ActiveJoysticks[joystick]); 545 closeJoystickDevice(&ActiveJoysticks[joystick]);
546 } 546 }
547#endif 547#endif
548} 548}
549 549
550void CIrrDeviceMacOSX::closeDevice() 550void CIrrDeviceMacOSX::closeDevice()
551{ 551{
552 if (Window != NULL) 552 if (Window != NULL)
553 { 553 {
554 [Window setIsVisible:FALSE]; 554 [Window setIsVisible:FALSE];
555 555
556 if (OGLContext != NULL) 556 if (OGLContext != NULL)
557 { 557 {
558 [OGLContext clearDrawable]; 558 [OGLContext clearDrawable];
559 [OGLContext release]; 559 [OGLContext release];
560 OGLContext = NULL; 560 OGLContext = NULL;
561 } 561 }
562 562
563 [Window setReleasedWhenClosed:TRUE]; 563 [Window setReleasedWhenClosed:TRUE];
564 [Window release]; 564 [Window release];
565 Window = NULL; 565 Window = NULL;
566 566
567 if (IsFullscreen) 567 if (IsFullscreen)
568 CGReleaseAllDisplays(); 568 CGReleaseAllDisplays();
569 } 569 }
570 else 570 else
571 { 571 {
572 if (CGLContext != NULL) 572 if (CGLContext != NULL)
573 { 573 {
574 if(CreationParams.WindowId) 574 if(CreationParams.WindowId)
575 { 575 {
576 [(NSOpenGLContext *)OGLContext clearDrawable]; 576 [(NSOpenGLContext *)OGLContext clearDrawable];
577 [(NSOpenGLContext *)OGLContext release]; 577 [(NSOpenGLContext *)OGLContext release];
578 OGLContext = NULL; 578 OGLContext = NULL;
579 } 579 }
580 else 580 else
581 { 581 {
582 CGLSetCurrentContext(NULL); 582 CGLSetCurrentContext(NULL);
583 CGLClearDrawable(CGLContext); 583 CGLClearDrawable(CGLContext);
584 CGLDestroyContext(CGLContext); 584 CGLDestroyContext(CGLContext);
585 CGReleaseAllDisplays(); 585 CGReleaseAllDisplays();
586 } 586 }
587 } 587 }
588 } 588 }
589 589
590 IsFullscreen = false; 590 IsFullscreen = false;
591 IsActive = false; 591 IsActive = false;
592 CGLContext = NULL; 592 CGLContext = NULL;
593} 593}
594 594
595bool CIrrDeviceMacOSX::createWindow() 595bool CIrrDeviceMacOSX::createWindow()
596{ 596{
597 CGDisplayErr error; 597 CGDisplayErr error;
598 bool result=false; 598 bool result=false;
599 CGDirectDisplayID display=CGMainDisplayID(); 599 CGDirectDisplayID display=CGMainDisplayID();
600 CGLPixelFormatObj pixelFormat; 600 CGLPixelFormatObj pixelFormat;
601 CGRect displayRect; 601 CGRect displayRect;
602#ifdef __MAC_10_6 602#ifdef __MAC_10_6
603 CGDisplayModeRef displaymode, olddisplaymode; 603 CGDisplayModeRef displaymode, olddisplaymode;
604#else 604#else
605 CFDictionaryRef displaymode, olddisplaymode; 605 CFDictionaryRef displaymode, olddisplaymode;
606#endif 606#endif
607 GLint numPixelFormats, newSwapInterval; 607 GLint numPixelFormats, newSwapInterval;
608 608
609 int alphaSize = CreationParams.WithAlphaChannel?4:0; 609 int alphaSize = CreationParams.WithAlphaChannel?4:0;
610 int depthSize = CreationParams.ZBufferBits; 610 int depthSize = CreationParams.ZBufferBits;
611 if (CreationParams.WithAlphaChannel && (CreationParams.Bits == 32)) 611 if (CreationParams.WithAlphaChannel && (CreationParams.Bits == 32))
612 alphaSize = 8; 612 alphaSize = 8;
613 613
614 ScreenWidth = (int) CGDisplayPixelsWide(display); 614 ScreenWidth = (int) CGDisplayPixelsWide(display);
615 ScreenHeight = (int) CGDisplayPixelsHigh(display); 615 ScreenHeight = (int) CGDisplayPixelsHigh(display);
616 616
617 // we need to check where the exceptions may happen and work at them 617 // we need to check where the exceptions may happen and work at them
618 // for now we will just catch them to be able to avoid an app exit 618 // for now we will just catch them to be able to avoid an app exit
619 @try 619 @try
620 { 620 {
621 if (!CreationParams.Fullscreen) 621 if (!CreationParams.Fullscreen)
622 { 622 {
623 if(!CreationParams.WindowId) //create another window when WindowId is null 623 if(!CreationParams.WindowId) //create another window when WindowId is null
624 { 624 {
625 NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained; 625 NSBackingStoreType type = (CreationParams.DriverType == video::EDT_OPENGL) ? NSBackingStoreBuffered : NSBackingStoreNonretained;
626 626
627 Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:type defer:FALSE]; 627 Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:type defer:FALSE];
628 } 628 }
629 629
630 if (Window != NULL || CreationParams.WindowId) 630 if (Window != NULL || CreationParams.WindowId)
631 { 631 {
632 if (CreationParams.DriverType == video::EDT_OPENGL) 632 if (CreationParams.DriverType == video::EDT_OPENGL)
633 { 633 {
634 NSOpenGLPixelFormatAttribute windowattribs[] = 634 NSOpenGLPixelFormatAttribute windowattribs[] =
635 { 635 {
636 NSOpenGLPFANoRecovery, 636 NSOpenGLPFANoRecovery,
637 NSOpenGLPFAAccelerated, 637 NSOpenGLPFAAccelerated,
638 NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize, 638 NSOpenGLPFADepthSize, (NSOpenGLPixelFormatAttribute)depthSize,
639 NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits, 639 NSOpenGLPFAColorSize, (NSOpenGLPixelFormatAttribute)CreationParams.Bits,
640 NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize, 640 NSOpenGLPFAAlphaSize, (NSOpenGLPixelFormatAttribute)alphaSize,
641 NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1, 641 NSOpenGLPFASampleBuffers, (NSOpenGLPixelFormatAttribute)1,
642 NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias, 642 NSOpenGLPFASamples, (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias,
643 NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0), 643 NSOpenGLPFAStencilSize, (NSOpenGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
644 NSOpenGLPFADoubleBuffer, 644 NSOpenGLPFADoubleBuffer,
645 (NSOpenGLPixelFormatAttribute)nil 645 (NSOpenGLPixelFormatAttribute)nil
646 }; 646 };
647 647
648 if (CreationParams.AntiAlias<2) 648 if (CreationParams.AntiAlias<2)
649 { 649 {
650 windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0; 650 windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
651 windowattribs[11] = (NSOpenGLPixelFormatAttribute)0; 651 windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
652 } 652 }
653 653
654 NSOpenGLPixelFormat *format; 654 NSOpenGLPixelFormat *format;
655 for (int i=0; i<3; ++i) 655 for (int i=0; i<3; ++i)
656 { 656 {
657 if (1==i) 657 if (1==i)
658 { 658 {
659 // Second try without stencilbuffer 659 // Second try without stencilbuffer
660 if (CreationParams.Stencilbuffer) 660 if (CreationParams.Stencilbuffer)
661 { 661 {
662 windowattribs[13]=(NSOpenGLPixelFormatAttribute)0; 662 windowattribs[13]=(NSOpenGLPixelFormatAttribute)0;
663 } 663 }
664 else 664 else
665 continue; 665 continue;
666 } 666 }
667 else if (2==i) 667 else if (2==i)
668 { 668 {
669 // Third try without Doublebuffer 669 // Third try without Doublebuffer
670 os::Printer::log("No doublebuffering available.", ELL_WARNING); 670 os::Printer::log("No doublebuffering available.", ELL_WARNING);
671 windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil; 671 windowattribs[14]=(NSOpenGLPixelFormatAttribute)nil;
672 } 672 }
673 673
674 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs]; 674 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
675 if (format == NULL) 675 if (format == NULL)
676 { 676 {
677 if (CreationParams.AntiAlias>1) 677 if (CreationParams.AntiAlias>1)
678 { 678 {
679 while (!format && windowattribs[12]>1) 679 while (!format && windowattribs[12]>1)
680 { 680 {
681 windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1); 681 windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
682 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs]; 682 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
683 } 683 }
684 684
685 if (!format) 685 if (!format)
686 { 686 {
687 windowattribs[9] = (NSOpenGLPixelFormatAttribute)0; 687 windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
688 windowattribs[11] = (NSOpenGLPixelFormatAttribute)0; 688 windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
689 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs]; 689 format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
690 if (!format) 690 if (!format)
691 { 691 {
692 // reset values for next try 692 // reset values for next try
693 windowattribs[9] = (NSOpenGLPixelFormatAttribute)1; 693 windowattribs[9] = (NSOpenGLPixelFormatAttribute)1;
694 windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias; 694 windowattribs[11] = (NSOpenGLPixelFormatAttribute)CreationParams.AntiAlias;
695 } 695 }
696 else 696 else
697 { 697 {
698 os::Printer::log("No FSAA available.", ELL_WARNING); 698 os::Printer::log("No FSAA available.", ELL_WARNING);
699 } 699 }
700 } 700 }
701 } 701 }
702 } 702 }
703 else 703 else
704 break; 704 break;
705 } 705 }
706 CreationParams.AntiAlias = windowattribs[11]; 706 CreationParams.AntiAlias = windowattribs[11];
707 CreationParams.Stencilbuffer=(windowattribs[13]==1); 707 CreationParams.Stencilbuffer=(windowattribs[13]==1);
708 708
709 if (format != NULL) 709 if (format != NULL)
710 { 710 {
711 OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL]; 711 OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
712 [format release]; 712 [format release];
713 } 713 }
714 } 714 }
715 715
716 if (OGLContext != NULL || CreationParams.DriverType != video::EDT_OPENGL) 716 if (OGLContext != NULL || CreationParams.DriverType != video::EDT_OPENGL)
717 { 717 {
718 if (!CreationParams.WindowId) 718 if (!CreationParams.WindowId)
719 { 719 {
720 [Window center]; 720 [Window center];
721 [Window setDelegate:[NSApp delegate]]; 721 [Window setDelegate:[NSApp delegate]];
722 722
723 if(CreationParams.DriverType == video::EDT_OPENGL) 723 if(CreationParams.DriverType == video::EDT_OPENGL)
724 [OGLContext setView:[Window contentView]]; 724 [OGLContext setView:[Window contentView]];
725 725
726 [Window setAcceptsMouseMovedEvents:TRUE]; 726 [Window setAcceptsMouseMovedEvents:TRUE];
727 [Window setIsVisible:TRUE]; 727 [Window setIsVisible:TRUE];
728 [Window makeKeyAndOrderFront:nil]; 728 [Window makeKeyAndOrderFront:nil];
729 } 729 }
730 else if(CreationParams.DriverType == video::EDT_OPENGL) //use another window for drawing 730 else if(CreationParams.DriverType == video::EDT_OPENGL) //use another window for drawing
731 [OGLContext setView:(NSView*)CreationParams.WindowId]; 731 [OGLContext setView:(NSView*)CreationParams.WindowId];
732 732
733 if (CreationParams.DriverType == video::EDT_OPENGL) 733 if (CreationParams.DriverType == video::EDT_OPENGL)
734 CGLContext = (CGLContextObj) [OGLContext CGLContextObj]; 734 CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
735 735
736 DeviceWidth = CreationParams.WindowSize.Width; 736 DeviceWidth = CreationParams.WindowSize.Width;
737 DeviceHeight = CreationParams.WindowSize.Height; 737 DeviceHeight = CreationParams.WindowSize.Height;
738 result = true; 738 result = true;
739 } 739 }
740 } 740 }
741 } 741 }
742 else 742 else
743 { 743 {
744 IsFullscreen = true; 744 IsFullscreen = true;
745 745
746#ifdef __MAC_10_6 746#ifdef __MAC_10_6
747 displaymode = CGDisplayCopyDisplayMode(display); 747 displaymode = CGDisplayCopyDisplayMode(display);
748 748
749 CFArrayRef Modes = CGDisplayCopyAllDisplayModes(display, NULL); 749 CFArrayRef Modes = CGDisplayCopyAllDisplayModes(display, NULL);
750 750
751 for(int i = 0; i < CFArrayGetCount(Modes); ++i) 751 for(int i = 0; i < CFArrayGetCount(Modes); ++i)
752 { 752 {
753 CGDisplayModeRef CurrentMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(Modes, i); 753 CGDisplayModeRef CurrentMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(Modes, i);
754 754
755 u8 Depth = 0; 755 u8 Depth = 0;
756 756
757 CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(CurrentMode); 757 CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(CurrentMode);
758 758
759 if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 759 if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
760 Depth = 32; 760 Depth = 32;
761 else 761 else
762 if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 762 if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
763 Depth = 16; 763 Depth = 16;
764 else 764 else
765 if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 765 if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
766 Depth = 8; 766 Depth = 8;
767 767
768 if(Depth == CreationParams.Bits) 768 if(Depth == CreationParams.Bits)
769 if((CGDisplayModeGetWidth(CurrentMode) == CreationParams.WindowSize.Width) && (CGDisplayModeGetHeight(CurrentMode) == CreationParams.WindowSize.Height)) 769 if((CGDisplayModeGetWidth(CurrentMode) == CreationParams.WindowSize.Width) && (CGDisplayModeGetHeight(CurrentMode) == CreationParams.WindowSize.Height))
770 { 770 {
771 displaymode = CurrentMode; 771 displaymode = CurrentMode;
772 break; 772 break;
773 } 773 }
774 } 774 }
775#else 775#else
776 displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL); 776 displaymode = CGDisplayBestModeForParameters(display,CreationParams.Bits,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height,NULL);
777#endif 777#endif
778 778
779 if (displaymode != NULL) 779 if (displaymode != NULL)
780 { 780 {
781#ifdef __MAC_10_6 781#ifdef __MAC_10_6
782 olddisplaymode = CGDisplayCopyDisplayMode(display); 782 olddisplaymode = CGDisplayCopyDisplayMode(display);
783#else 783#else
784 olddisplaymode = CGDisplayCurrentMode(display); 784 olddisplaymode = CGDisplayCurrentMode(display);
785#endif 785#endif
786 786
787 error = CGCaptureAllDisplays(); 787 error = CGCaptureAllDisplays();
788 if (error == CGDisplayNoErr) 788 if (error == CGDisplayNoErr)
789 { 789 {
790#ifdef __MAC_10_6 790#ifdef __MAC_10_6
791 error = CGDisplaySetDisplayMode(display, displaymode, NULL); 791 error = CGDisplaySetDisplayMode(display, displaymode, NULL);
792#else 792#else
793 error = CGDisplaySwitchToMode(display, displaymode); 793 error = CGDisplaySwitchToMode(display, displaymode);
794#endif 794#endif
795 795
796 if (error == CGDisplayNoErr) 796 if (error == CGDisplayNoErr)
797 { 797 {
798 if (CreationParams.DriverType == video::EDT_OPENGL) 798 if (CreationParams.DriverType == video::EDT_OPENGL)
799 { 799 {
800 CGLPixelFormatAttribute fullattribs[] = 800 CGLPixelFormatAttribute fullattribs[] =
801 { 801 {
802 kCGLPFAFullScreen, 802 kCGLPFAFullScreen,
803 kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display), 803 kCGLPFADisplayMask, (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(display),
804 kCGLPFADoubleBuffer, 804 kCGLPFADoubleBuffer,
805 kCGLPFANoRecovery, 805 kCGLPFANoRecovery,
806 kCGLPFAAccelerated, 806 kCGLPFAAccelerated,
807 kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize, 807 kCGLPFADepthSize, (CGLPixelFormatAttribute)depthSize,
808 kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits, 808 kCGLPFAColorSize, (CGLPixelFormatAttribute)CreationParams.Bits,
809 kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize, 809 kCGLPFAAlphaSize, (CGLPixelFormatAttribute)alphaSize,
810 kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0), 810 kCGLPFASampleBuffers, (CGLPixelFormatAttribute)(CreationParams.AntiAlias?1:0),
811 kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias, 811 kCGLPFASamples, (CGLPixelFormatAttribute)CreationParams.AntiAlias,
812 kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0), 812 kCGLPFAStencilSize, (CGLPixelFormatAttribute)(CreationParams.Stencilbuffer?1:0),
813 (CGLPixelFormatAttribute)NULL 813 (CGLPixelFormatAttribute)NULL
814 }; 814 };
815 815
816 pixelFormat = NULL; 816 pixelFormat = NULL;
817 numPixelFormats = 0; 817 numPixelFormats = 0;
818 CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats); 818 CGLChoosePixelFormat(fullattribs,&pixelFormat,&numPixelFormats);
819 819
820 if (pixelFormat != NULL) 820 if (pixelFormat != NULL)
821 { 821 {
822 CGLCreateContext(pixelFormat,NULL,&CGLContext); 822 CGLCreateContext(pixelFormat,NULL,&CGLContext);
823 CGLDestroyPixelFormat(pixelFormat); 823 CGLDestroyPixelFormat(pixelFormat);
824 } 824 }
825 825
826 if (CGLContext != NULL) 826 if (CGLContext != NULL)
827 { 827 {
828#ifdef __MAC_10_6 828#ifdef __MAC_10_6
829 CGLSetFullScreenOnDisplay(CGLContext, CGDisplayIDToOpenGLDisplayMask(display)); 829 CGLSetFullScreenOnDisplay(CGLContext, CGDisplayIDToOpenGLDisplayMask(display));
830#else 830#else
831 CGLSetFullScreen(CGLContext); 831 CGLSetFullScreen(CGLContext);
832#endif 832#endif
833 displayRect = CGDisplayBounds(display); 833 displayRect = CGDisplayBounds(display);
834 ScreenWidth = DeviceWidth = (int)displayRect.size.width; 834 ScreenWidth = DeviceWidth = (int)displayRect.size.width;
835 ScreenHeight = DeviceHeight = (int)displayRect.size.height; 835 ScreenHeight = DeviceHeight = (int)displayRect.size.height;
836 CreationParams.WindowSize.set(ScreenWidth, ScreenHeight); 836 CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
837 result = true; 837 result = true;
838 } 838 }
839 } 839 }
840 else 840 else
841 { 841 {
842 Window = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO screen:[NSScreen mainScreen]]; 842 Window = [[NSWindow alloc] initWithContentRect:[[NSScreen mainScreen] frame] styleMask:NSBorderlessWindowMask backing:NSBackingStoreNonretained defer:NO screen:[NSScreen mainScreen]];
843 843
844 [Window setLevel: CGShieldingWindowLevel()]; 844 [Window setLevel: CGShieldingWindowLevel()];
845 [Window setAcceptsMouseMovedEvents:TRUE]; 845 [Window setAcceptsMouseMovedEvents:TRUE];
846 [Window setIsVisible:TRUE]; 846 [Window setIsVisible:TRUE];
847 [Window makeKeyAndOrderFront:nil]; 847 [Window makeKeyAndOrderFront:nil];
848 848
849 displayRect = CGDisplayBounds(display); 849 displayRect = CGDisplayBounds(display);
850 ScreenWidth = DeviceWidth = (int)displayRect.size.width; 850 ScreenWidth = DeviceWidth = (int)displayRect.size.width;
851 ScreenHeight = DeviceHeight = (int)displayRect.size.height; 851 ScreenHeight = DeviceHeight = (int)displayRect.size.height;
852 CreationParams.WindowSize.set(ScreenWidth, ScreenHeight); 852 CreationParams.WindowSize.set(ScreenWidth, ScreenHeight);
853 result = true; 853 result = true;
854 } 854 }
855 } 855 }
856 if (!result) 856 if (!result)
857 CGReleaseAllDisplays(); 857 CGReleaseAllDisplays();
858 } 858 }
859 } 859 }
860 } 860 }
861 } 861 }
862 @catch (NSException *exception) 862 @catch (NSException *exception)
863 { 863 {
864 closeDevice(); 864 closeDevice();
865 result = false; 865 result = false;
866 } 866 }
867 867
868 if (result) 868 if (result)
869 { 869 {
870 // fullscreen? 870 // fullscreen?
871 if (Window == NULL && !CreationParams.WindowId) //hide menus in fullscreen mode only 871 if (Window == NULL && !CreationParams.WindowId) //hide menus in fullscreen mode only
872#ifdef __MAC_10_6 872#ifdef __MAC_10_6
873 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)]; 873 [NSApp setPresentationOptions:(NSApplicationPresentationAutoHideDock | NSApplicationPresentationAutoHideMenuBar)];
874#else 874#else
875 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); 875 SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
876#endif 876#endif
877 877
878 if(CreationParams.DriverType == video::EDT_OPENGL) 878 if(CreationParams.DriverType == video::EDT_OPENGL)
879 { 879 {
880 CGLSetCurrentContext(CGLContext); 880 CGLSetCurrentContext(CGLContext);
881 newSwapInterval = (CreationParams.Vsync) ? 1 : 0; 881 newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
882 CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval); 882 CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval);
883 } 883 }
884 } 884 }
885 885
886 return (result); 886 return (result);
887} 887}
888 888
889void CIrrDeviceMacOSX::setResize(int width, int height) 889void CIrrDeviceMacOSX::setResize(int width, int height)
890{ 890{
891 // set new window size 891 // set new window size
892 DeviceWidth = width; 892 DeviceWidth = width;
893 DeviceHeight = height; 893 DeviceHeight = height;
894 894
895 // update the size of the opengl rendering context 895 // update the size of the opengl rendering context
896 if(OGLContext); 896 if(OGLContext);
897 [OGLContext update]; 897 [OGLContext update];
898 898
899 // resize the driver to the inner pane size 899 // resize the driver to the inner pane size
900 if (Window) 900 if (Window)
901 { 901 {
902 NSRect driverFrame = [Window contentRectForFrameRect:[Window frame]]; 902 NSRect driverFrame = [Window contentRectForFrameRect:[Window frame]];
903 getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)driverFrame.size.width, (s32)driverFrame.size.height)); 903 getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)driverFrame.size.width, (s32)driverFrame.size.height));
904 } 904 }
905 else 905 else
906 getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height)); 906 getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)width, (s32)height));
907 907
908 if (CreationParams.WindowId && OGLContext) 908 if (CreationParams.WindowId && OGLContext)
909 [(NSOpenGLContext *)OGLContext update]; 909 [(NSOpenGLContext *)OGLContext update];
910} 910}
911 911
912 912
913void CIrrDeviceMacOSX::createDriver() 913void CIrrDeviceMacOSX::createDriver()
914{ 914{
915 switch (CreationParams.DriverType) 915 switch (CreationParams.DriverType)
916 { 916 {
917 case video::EDT_SOFTWARE: 917 case video::EDT_SOFTWARE:
918 #ifdef _IRR_COMPILE_WITH_SOFTWARE_ 918 #ifdef _IRR_COMPILE_WITH_SOFTWARE_
919 VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); 919 VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
920 SoftwareRendererType = 2; 920 SoftwareRendererType = 2;
921 #else 921 #else
922 os::Printer::log("No Software driver support compiled in.", ELL_ERROR); 922 os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
923 #endif 923 #endif
924 break; 924 break;
925 925
926 case video::EDT_BURNINGSVIDEO: 926 case video::EDT_BURNINGSVIDEO:
927 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ 927 #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
928 VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this); 928 VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
929 SoftwareRendererType = 1; 929 SoftwareRendererType = 1;
930 #else 930 #else
931 os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR); 931 os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
932 #endif 932 #endif
933 break; 933 break;
934 934
935 case video::EDT_OPENGL: 935 case video::EDT_OPENGL:
936 #ifdef _IRR_COMPILE_WITH_OPENGL_ 936 #ifdef _IRR_COMPILE_WITH_OPENGL_
937 VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this); 937 VideoDriver = video::createOpenGLDriver(CreationParams, FileSystem, this);
938 #else 938 #else
939 os::Printer::log("No OpenGL support compiled in.", ELL_ERROR); 939 os::Printer::log("No OpenGL support compiled in.", ELL_ERROR);
940 #endif 940 #endif
941 break; 941 break;
942 942
943 case video::EDT_DIRECT3D8: 943 case video::EDT_DIRECT3D8:
944 case video::EDT_DIRECT3D9: 944 case video::EDT_DIRECT3D9:
945 os::Printer::log("This driver is not available in OSX. Try OpenGL or Software renderer.", ELL_ERROR); 945 os::Printer::log("This driver is not available in OSX. Try OpenGL or Software renderer.", ELL_ERROR);
946 break; 946 break;
947 947
948 case video::EDT_NULL: 948 case video::EDT_NULL:
949 VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize); 949 VideoDriver = video::createNullDriver(FileSystem, CreationParams.WindowSize);
950 break; 950 break;
951 951
952 default: 952 default:
953 os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); 953 os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
954 break; 954 break;
955 } 955 }
956} 956}
957 957
958void CIrrDeviceMacOSX::flush() 958void CIrrDeviceMacOSX::flush()
959{ 959{
960 if (CGLContext != NULL) 960 if (CGLContext != NULL)
961 { 961 {
962 glFinish(); 962 glFinish();
963 CGLFlushDrawable(CGLContext); 963 CGLFlushDrawable(CGLContext);
964 } 964 }
965} 965}
966 966
967bool CIrrDeviceMacOSX::run() 967bool CIrrDeviceMacOSX::run()
968{ 968{
969 NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init]; 969 NSAutoreleasePool* Pool = [[NSAutoreleasePool alloc] init];
970 970
971 NSEvent *event; 971 NSEvent *event;
972 irr::SEvent ievent; 972 irr::SEvent ievent;
973 973
974 os::Timer::tick(); 974 os::Timer::tick();
975 storeMouseLocation(); 975 storeMouseLocation();
976 976
977 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES]; 977 event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES];
978 if (event != nil) 978 if (event != nil)
979 { 979 {
980 bzero(&ievent,sizeof(ievent)); 980 bzero(&ievent,sizeof(ievent));
981 981
982 switch([(NSEvent *)event type]) 982 switch([(NSEvent *)event type])
983 { 983 {
984 case NSKeyDown: 984 case NSKeyDown:
985 postKeyEvent(event,ievent,true); 985 postKeyEvent(event,ievent,true);
986 break; 986 break;
987 987
988 case NSKeyUp: 988 case NSKeyUp:
989 postKeyEvent(event,ievent,false); 989 postKeyEvent(event,ievent,false);
990 break; 990 break;
991 991
992 case NSFlagsChanged: 992 case NSFlagsChanged:
993 ievent.EventType = irr::EET_KEY_INPUT_EVENT; 993 ievent.EventType = irr::EET_KEY_INPUT_EVENT;
994 ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; 994 ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0;
995 ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; 995 ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0;
996 996
997 if (IsShiftDown != ievent.KeyInput.Shift) 997 if (IsShiftDown != ievent.KeyInput.Shift)
998 { 998 {
999 ievent.KeyInput.Char = irr::KEY_SHIFT; 999 ievent.KeyInput.Char = irr::KEY_SHIFT;
1000 ievent.KeyInput.Key = irr::KEY_SHIFT; 1000 ievent.KeyInput.Key = irr::KEY_SHIFT;
1001 ievent.KeyInput.PressedDown = ievent.KeyInput.Shift; 1001 ievent.KeyInput.PressedDown = ievent.KeyInput.Shift;
1002 1002
1003 IsShiftDown = ievent.KeyInput.Shift; 1003 IsShiftDown = ievent.KeyInput.Shift;
1004 1004
1005 postEventFromUser(ievent); 1005 postEventFromUser(ievent);
1006 } 1006 }
1007 1007
1008 if (IsControlDown != ievent.KeyInput.Control) 1008 if (IsControlDown != ievent.KeyInput.Control)
1009 { 1009 {
1010 ievent.KeyInput.Char = irr::KEY_CONTROL; 1010 ievent.KeyInput.Char = irr::KEY_CONTROL;
1011 ievent.KeyInput.Key = irr::KEY_CONTROL; 1011 ievent.KeyInput.Key = irr::KEY_CONTROL;
1012 ievent.KeyInput.PressedDown = ievent.KeyInput.Control; 1012 ievent.KeyInput.PressedDown = ievent.KeyInput.Control;
1013 1013
1014 IsControlDown = ievent.KeyInput.Control; 1014 IsControlDown = ievent.KeyInput.Control;
1015 1015
1016 postEventFromUser(ievent); 1016 postEventFromUser(ievent);
1017 } 1017 }
1018 1018
1019 [NSApp sendEvent:event]; 1019 [NSApp sendEvent:event];
1020 break; 1020 break;
1021 1021
1022 case NSLeftMouseDown: 1022 case NSLeftMouseDown:
1023 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1023 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1024 ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN; 1024 ievent.MouseInput.Event = irr::EMIE_LMOUSE_PRESSED_DOWN;
1025 MouseButtonStates |= irr::EMBSM_LEFT; 1025 MouseButtonStates |= irr::EMBSM_LEFT;
1026 ievent.MouseInput.ButtonStates = MouseButtonStates; 1026 ievent.MouseInput.ButtonStates = MouseButtonStates;
1027 postMouseEvent(event,ievent); 1027 postMouseEvent(event,ievent);
1028 break; 1028 break;
1029 1029
1030 case NSLeftMouseUp: 1030 case NSLeftMouseUp:
1031 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1031 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1032 MouseButtonStates &= !irr::EMBSM_LEFT; 1032 MouseButtonStates &= !irr::EMBSM_LEFT;
1033 ievent.MouseInput.ButtonStates = MouseButtonStates; 1033 ievent.MouseInput.ButtonStates = MouseButtonStates;
1034 ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP; 1034 ievent.MouseInput.Event = irr::EMIE_LMOUSE_LEFT_UP;
1035 postMouseEvent(event,ievent); 1035 postMouseEvent(event,ievent);
1036 break; 1036 break;
1037 1037
1038 case NSOtherMouseDown: 1038 case NSOtherMouseDown:
1039 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1039 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1040 ievent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN; 1040 ievent.MouseInput.Event = irr::EMIE_MMOUSE_PRESSED_DOWN;
1041 MouseButtonStates |= irr::EMBSM_MIDDLE; 1041 MouseButtonStates |= irr::EMBSM_MIDDLE;
1042 ievent.MouseInput.ButtonStates = MouseButtonStates; 1042 ievent.MouseInput.ButtonStates = MouseButtonStates;
1043 postMouseEvent(event,ievent); 1043 postMouseEvent(event,ievent);
1044 break; 1044 break;
1045 1045
1046 case NSOtherMouseUp: 1046 case NSOtherMouseUp:
1047 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1047 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1048 MouseButtonStates &= !irr::EMBSM_MIDDLE; 1048 MouseButtonStates &= !irr::EMBSM_MIDDLE;
1049 ievent.MouseInput.ButtonStates = MouseButtonStates; 1049 ievent.MouseInput.ButtonStates = MouseButtonStates;
1050 ievent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP; 1050 ievent.MouseInput.Event = irr::EMIE_MMOUSE_LEFT_UP;
1051 postMouseEvent(event,ievent); 1051 postMouseEvent(event,ievent);
1052 break; 1052 break;
1053 1053
1054 case NSMouseMoved: 1054 case NSMouseMoved:
1055 case NSLeftMouseDragged: 1055 case NSLeftMouseDragged:
1056 case NSRightMouseDragged: 1056 case NSRightMouseDragged:
1057 case NSOtherMouseDragged: 1057 case NSOtherMouseDragged:
1058 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1058 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1059 ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; 1059 ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
1060 ievent.MouseInput.ButtonStates = MouseButtonStates; 1060 ievent.MouseInput.ButtonStates = MouseButtonStates;
1061 postMouseEvent(event,ievent); 1061 postMouseEvent(event,ievent);
1062 break; 1062 break;
1063 1063
1064 case NSRightMouseDown: 1064 case NSRightMouseDown:
1065 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1065 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1066 ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN; 1066 ievent.MouseInput.Event = irr::EMIE_RMOUSE_PRESSED_DOWN;
1067 MouseButtonStates |= irr::EMBSM_RIGHT; 1067 MouseButtonStates |= irr::EMBSM_RIGHT;
1068 ievent.MouseInput.ButtonStates = MouseButtonStates; 1068 ievent.MouseInput.ButtonStates = MouseButtonStates;
1069 postMouseEvent(event,ievent); 1069 postMouseEvent(event,ievent);
1070 break; 1070 break;
1071 1071
1072 case NSRightMouseUp: 1072 case NSRightMouseUp:
1073 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1073 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1074 ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP; 1074 ievent.MouseInput.Event = irr::EMIE_RMOUSE_LEFT_UP;
1075 MouseButtonStates &= !irr::EMBSM_RIGHT; 1075 MouseButtonStates &= !irr::EMBSM_RIGHT;
1076 ievent.MouseInput.ButtonStates = MouseButtonStates; 1076 ievent.MouseInput.ButtonStates = MouseButtonStates;
1077 postMouseEvent(event,ievent); 1077 postMouseEvent(event,ievent);
1078 break; 1078 break;
1079 1079
1080 case NSScrollWheel: 1080 case NSScrollWheel:
1081 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1081 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1082 ievent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL; 1082 ievent.MouseInput.Event = irr::EMIE_MOUSE_WHEEL;
1083 ievent.MouseInput.Wheel = [(NSEvent *)event deltaY]; 1083 ievent.MouseInput.Wheel = [(NSEvent *)event deltaY];
1084 if (ievent.MouseInput.Wheel < 1.0f) 1084 if (ievent.MouseInput.Wheel < 1.0f)
1085 ievent.MouseInput.Wheel *= 10.0f; 1085 ievent.MouseInput.Wheel *= 10.0f;
1086 else 1086 else
1087 ievent.MouseInput.Wheel *= 5.0f; 1087 ievent.MouseInput.Wheel *= 5.0f;
1088 postMouseEvent(event,ievent); 1088 postMouseEvent(event,ievent);
1089 break; 1089 break;
1090 1090
1091 default: 1091 default:
1092 [NSApp sendEvent:event]; 1092 [NSApp sendEvent:event];
1093 break; 1093 break;
1094 } 1094 }
1095 } 1095 }
1096 1096
1097 pollJoysticks(); 1097 pollJoysticks();
1098 1098
1099 [Pool release]; 1099 [Pool release];
1100 1100
1101 return (![[NSApp delegate] isQuit] && IsActive); 1101 return (![[NSApp delegate] isQuit] && IsActive);
1102} 1102}
1103 1103
1104 1104
1105//! Pause the current process for the minimum time allowed only to allow other processes to execute 1105//! Pause the current process for the minimum time allowed only to allow other processes to execute
1106void CIrrDeviceMacOSX::yield() 1106void CIrrDeviceMacOSX::yield()
1107{ 1107{
1108 struct timespec ts = {0,0}; 1108 struct timespec ts = {0,0};
1109 nanosleep(&ts, NULL); 1109 nanosleep(&ts, NULL);
1110} 1110}
1111 1111
1112 1112
1113//! Pause execution and let other processes to run for a specified amount of time. 1113//! Pause execution and let other processes to run for a specified amount of time.
1114void CIrrDeviceMacOSX::sleep(u32 timeMs, bool pauseTimer=false) 1114void CIrrDeviceMacOSX::sleep(u32 timeMs, bool pauseTimer=false)
1115{ 1115{
1116 bool wasStopped = Timer ? Timer->isStopped() : true; 1116 bool wasStopped = Timer ? Timer->isStopped() : true;
1117 1117
1118 struct timespec ts; 1118 struct timespec ts;
1119 ts.tv_sec = (time_t) (timeMs / 1000); 1119 ts.tv_sec = (time_t) (timeMs / 1000);
1120 ts.tv_nsec = (long) (timeMs % 1000) * 1000000; 1120 ts.tv_nsec = (long) (timeMs % 1000) * 1000000;
1121 1121
1122 if (pauseTimer && !wasStopped) 1122 if (pauseTimer && !wasStopped)
1123 Timer->stop(); 1123 Timer->stop();
1124 1124
1125 nanosleep(&ts, NULL); 1125 nanosleep(&ts, NULL);
1126 1126
1127 if (pauseTimer && !wasStopped) 1127 if (pauseTimer && !wasStopped)
1128 Timer->start(); 1128 Timer->start();
1129} 1129}
1130 1130
1131 1131
1132void CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text) 1132void CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text)
1133{ 1133{
1134 size_t size; 1134 size_t size;
1135 char title[1024]; 1135 char title[1024];
1136 1136
1137 if (Window != NULL) 1137 if (Window != NULL)
1138 { 1138 {
1139 size = wcstombs(title,text,1024); 1139 size = wcstombs(title,text,1024);
1140 title[1023] = 0; 1140 title[1023] = 0;
1141#ifdef __MAC_10_6 1141#ifdef __MAC_10_6
1142 NSString* name = [NSString stringWithCString:title encoding:NSUTF8StringEncoding]; 1142 NSString* name = [NSString stringWithCString:title encoding:NSUTF8StringEncoding];
1143#else 1143#else
1144 NSString* name = [NSString stringWithCString:title length:size]; 1144 NSString* name = [NSString stringWithCString:title length:size];
1145#endif 1145#endif
1146 [Window setTitle:name]; 1146 [Window setTitle:name];
1147 [name release]; 1147 [name release];
1148 } 1148 }
1149} 1149}
1150 1150
1151 1151
1152bool CIrrDeviceMacOSX::isWindowActive() const 1152bool CIrrDeviceMacOSX::isWindowActive() const
1153{ 1153{
1154 return (IsActive); 1154 return (IsActive);
1155} 1155}
1156 1156
1157 1157
1158bool CIrrDeviceMacOSX::isWindowFocused() const 1158bool CIrrDeviceMacOSX::isWindowFocused() const
1159{ 1159{
1160 if (Window != NULL) 1160 if (Window != NULL)
1161 return [Window isKeyWindow]; 1161 return [Window isKeyWindow];
1162 return false; 1162 return false;
1163} 1163}
1164 1164
1165 1165
1166bool CIrrDeviceMacOSX::isWindowMinimized() const 1166bool CIrrDeviceMacOSX::isWindowMinimized() const
1167{ 1167{
1168 if (Window != NULL) 1168 if (Window != NULL)
1169 return [Window isMiniaturized]; 1169 return [Window isMiniaturized];
1170 return false; 1170 return false;
1171} 1171}
1172 1172
1173 1173
1174void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed) 1174void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed)
1175{ 1175{
1176 NSString *str; 1176 NSString *str;
1177 std::map<int,int>::const_iterator iter; 1177 std::map<int,int>::const_iterator iter;
1178 unsigned int result,c,mkey,mchar; 1178 unsigned int result,c,mkey,mchar;
1179 const unsigned char *cStr; 1179 const unsigned char *cStr;
1180 BOOL skipCommand; 1180 BOOL skipCommand;
1181 1181
1182 str = [(NSEvent *)event characters]; 1182 str = [(NSEvent *)event characters];
1183 if ((str != nil) && ([str length] > 0)) 1183 if ((str != nil) && ([str length] > 0))
1184 { 1184 {
1185 mkey = mchar = 0; 1185 mkey = mchar = 0;
1186 skipCommand = false; 1186 skipCommand = false;
1187 c = [str characterAtIndex:0]; 1187 c = [str characterAtIndex:0];
1188 mchar = c; 1188 mchar = c;
1189 1189
1190 iter = KeyCodes.find([(NSEvent *)event keyCode]); 1190 iter = KeyCodes.find([(NSEvent *)event keyCode]);
1191 if (iter != KeyCodes.end()) 1191 if (iter != KeyCodes.end())
1192 mkey = (*iter).second; 1192 mkey = (*iter).second;
1193 else if ((iter = KeyCodes.find(c)) != KeyCodes.end()) 1193 else if ((iter = KeyCodes.find(c)) != KeyCodes.end())
1194 mkey = (*iter).second; 1194 mkey = (*iter).second;
1195 else 1195 else
1196 { 1196 {
1197 // workaround for period character 1197 // workaround for period character
1198 if (c == 0x2E) 1198 if (c == 0x2E)
1199 { 1199 {
1200 mkey = irr::KEY_PERIOD; 1200 mkey = irr::KEY_PERIOD;
1201 mchar = '.'; 1201 mchar = '.';
1202 } 1202 }
1203 else 1203 else
1204 { 1204 {
1205 cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding]; 1205 cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
1206 if (cStr != NULL && strlen((char*)cStr) > 0) 1206 if (cStr != NULL && strlen((char*)cStr) > 0)
1207 { 1207 {
1208 mchar = cStr[0]; 1208 mchar = cStr[0];
1209 mkey = toupper(mchar); 1209 mkey = toupper(mchar);
1210 if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask) 1210 if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
1211 { 1211 {
1212 if (mkey == 'C' || mkey == 'V' || mkey == 'X') 1212 if (mkey == 'C' || mkey == 'V' || mkey == 'X')
1213 { 1213 {
1214 mchar = 0; 1214 mchar = 0;
1215 skipCommand = true; 1215 skipCommand = true;
1216 } 1216 }
1217 } 1217 }
1218 } 1218 }
1219 } 1219 }
1220 } 1220 }
1221 1221
1222 ievent.EventType = irr::EET_KEY_INPUT_EVENT; 1222 ievent.EventType = irr::EET_KEY_INPUT_EVENT;
1223 ievent.KeyInput.Key = (irr::EKEY_CODE)mkey; 1223 ievent.KeyInput.Key = (irr::EKEY_CODE)mkey;
1224 ievent.KeyInput.PressedDown = pressed; 1224 ievent.KeyInput.PressedDown = pressed;
1225 ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; 1225 ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0;
1226 ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; 1226 ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0;
1227 ievent.KeyInput.Char = mchar; 1227 ievent.KeyInput.Char = mchar;
1228 1228
1229 if (skipCommand) 1229 if (skipCommand)
1230 ievent.KeyInput.Control = true; 1230 ievent.KeyInput.Control = true;
1231 else if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask) 1231 else if ([(NSEvent *)event modifierFlags] & NSCommandKeyMask)
1232 [NSApp sendEvent:(NSEvent *)event]; 1232 [NSApp sendEvent:(NSEvent *)event];
1233 1233
1234 postEventFromUser(ievent); 1234 postEventFromUser(ievent);
1235 } 1235 }
1236} 1236}
1237 1237
1238 1238
1239void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent) 1239void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
1240{ 1240{
1241 bool post = true; 1241 bool post = true;
1242 1242
1243 if (Window != NULL) 1243 if (Window != NULL)
1244 { 1244 {
1245 ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x; 1245 ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x;
1246 ievent.MouseInput.Y = DeviceHeight - (int)[(NSEvent *)event locationInWindow].y; 1246 ievent.MouseInput.Y = DeviceHeight - (int)[(NSEvent *)event locationInWindow].y;
1247 1247
1248 if (ievent.MouseInput.Y < 0) 1248 if (ievent.MouseInput.Y < 0)
1249 post = false; 1249 post = false;
1250 } 1250 }
1251 else 1251 else
1252 { 1252 {
1253 CGEventRef ourEvent = CGEventCreate(NULL); 1253 CGEventRef ourEvent = CGEventCreate(NULL);
1254 CGPoint point = CGEventGetLocation(ourEvent); 1254 CGPoint point = CGEventGetLocation(ourEvent);
1255 CFRelease(ourEvent); 1255 CFRelease(ourEvent);
1256 1256
1257 ievent.MouseInput.X = (int)point.x; 1257 ievent.MouseInput.X = (int)point.x;
1258 ievent.MouseInput.Y = (int)point.y; 1258 ievent.MouseInput.Y = (int)point.y;
1259 1259
1260 if (ievent.MouseInput.Y < 0) 1260 if (ievent.MouseInput.Y < 0)
1261 post = false; 1261 post = false;
1262 } 1262 }
1263 1263
1264 if (post) 1264 if (post)
1265 postEventFromUser(ievent); 1265 postEventFromUser(ievent);
1266 1266
1267 [NSApp sendEvent:(NSEvent *)event]; 1267 [NSApp sendEvent:(NSEvent *)event];
1268} 1268}
1269 1269
1270 1270
1271void CIrrDeviceMacOSX::storeMouseLocation() 1271void CIrrDeviceMacOSX::storeMouseLocation()
1272{ 1272{
1273 int x,y; 1273 int x,y;
1274 1274
1275 if (Window != NULL) 1275 if (Window != NULL)
1276 { 1276 {
1277 NSPoint p; 1277 NSPoint p;
1278 p = [NSEvent mouseLocation]; 1278 p = [NSEvent mouseLocation];
1279 p = [Window convertScreenToBase:p]; 1279 p = [Window convertScreenToBase:p];
1280 x = (int)p.x; 1280 x = (int)p.x;
1281 y = DeviceHeight - (int)p.y; 1281 y = DeviceHeight - (int)p.y;
1282 } 1282 }
1283 else 1283 else
1284 { 1284 {
1285 CGEventRef ourEvent = CGEventCreate(NULL); 1285 CGEventRef ourEvent = CGEventCreate(NULL);
1286 CGPoint point = CGEventGetLocation(ourEvent); 1286 CGPoint point = CGEventGetLocation(ourEvent);
1287 CFRelease(ourEvent); 1287 CFRelease(ourEvent);
1288 1288
1289 x = (int)point.x; 1289 x = (int)point.x;
1290 y = (int)point.y; 1290 y = (int)point.y;
1291 1291
1292 const core::position2di& curr = ((CCursorControl *)CursorControl)->getPosition(); 1292 const core::position2di& curr = ((CCursorControl *)CursorControl)->getPosition();
1293 if (curr.X != x || curr.Y != y) 1293 if (curr.X != x || curr.Y != y)
1294 { 1294 {
1295 // In fullscreen mode, events are not sent regularly so rely on polling 1295 // In fullscreen mode, events are not sent regularly so rely on polling
1296 irr::SEvent ievent; 1296 irr::SEvent ievent;
1297 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT; 1297 ievent.EventType = irr::EET_MOUSE_INPUT_EVENT;
1298 ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED; 1298 ievent.MouseInput.Event = irr::EMIE_MOUSE_MOVED;
1299 ievent.MouseInput.X = x; 1299 ievent.MouseInput.X = x;
1300 ievent.MouseInput.Y = y; 1300 ievent.MouseInput.Y = y;
1301 postEventFromUser(ievent); 1301 postEventFromUser(ievent);
1302 } 1302 }
1303 } 1303 }
1304 1304
1305 ((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y); 1305 ((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y);
1306} 1306}
1307 1307
1308 1308
1309void CIrrDeviceMacOSX::setMouseLocation(int x,int y) 1309void CIrrDeviceMacOSX::setMouseLocation(int x,int y)
1310{ 1310{
1311 NSPoint p; 1311 NSPoint p;
1312 CGPoint c; 1312 CGPoint c;
1313 1313
1314 if (Window != NULL) 1314 if (Window != NULL)
1315 { 1315 {
1316 // Irrlicht window exists 1316 // Irrlicht window exists
1317 p.x = (float) x; 1317 p.x = (float) x;
1318 p.y = (float) (DeviceHeight - y); 1318 p.y = (float) (DeviceHeight - y);
1319 p = [Window convertBaseToScreen:p]; 1319 p = [Window convertBaseToScreen:p];
1320 p.y = ScreenHeight - p.y; 1320 p.y = ScreenHeight - p.y;
1321 } 1321 }
1322 else 1322 else
1323 { 1323 {
1324 p.x = (float) x; 1324 p.x = (float) x;
1325 p.y = (float) y + (ScreenHeight - DeviceHeight); 1325 p.y = (float) y + (ScreenHeight - DeviceHeight);
1326 } 1326 }
1327 1327
1328 c.x = p.x; 1328 c.x = p.x;
1329 c.y = p.y; 1329 c.y = p.y;
1330 1330
1331#ifdef __MAC_10_6 1331#ifdef __MAC_10_6
1332 /*CGEventSourceRef SourceRef = CGEventSourceCreate(0); 1332 /*CGEventSourceRef SourceRef = CGEventSourceCreate(0);
1333 CGEventSourceSetLocalEventsSuppressionInterval(SourceRef, 0); 1333 CGEventSourceSetLocalEventsSuppressionInterval(SourceRef, 0);
1334 CFRelease(SourceRef);*/ 1334 CFRelease(SourceRef);*/
1335 CGSetLocalEventsSuppressionInterval(0); 1335 CGSetLocalEventsSuppressionInterval(0);
1336#else 1336#else
1337 CGSetLocalEventsSuppressionInterval(0); 1337 CGSetLocalEventsSuppressionInterval(0);
1338#endif 1338#endif
1339 CGWarpMouseCursorPosition(c); 1339 CGWarpMouseCursorPosition(c);
1340} 1340}
1341 1341
1342 1342
1343void CIrrDeviceMacOSX::setCursorVisible(bool visible) 1343void CIrrDeviceMacOSX::setCursorVisible(bool visible)
1344{ 1344{
1345 if (visible) 1345 if (visible)
1346 CGDisplayShowCursor(CGMainDisplayID()); 1346 CGDisplayShowCursor(CGMainDisplayID());
1347 else 1347 else
1348 CGDisplayHideCursor(CGMainDisplayID()); 1348 CGDisplayHideCursor(CGMainDisplayID());
1349} 1349}
1350 1350
1351 1351
1352void CIrrDeviceMacOSX::initKeycodes() 1352void CIrrDeviceMacOSX::initKeycodes()
1353{ 1353{
1354 KeyCodes[kVK_UpArrow] = irr::KEY_UP; 1354 KeyCodes[kVK_UpArrow] = irr::KEY_UP;
1355 KeyCodes[kVK_DownArrow] = irr::KEY_DOWN; 1355 KeyCodes[kVK_DownArrow] = irr::KEY_DOWN;
1356 KeyCodes[kVK_LeftArrow] = irr::KEY_LEFT; 1356 KeyCodes[kVK_LeftArrow] = irr::KEY_LEFT;
1357 KeyCodes[kVK_RightArrow] = irr::KEY_RIGHT; 1357 KeyCodes[kVK_RightArrow] = irr::KEY_RIGHT;
1358 KeyCodes[kVK_F1] = irr::KEY_F1; 1358 KeyCodes[kVK_F1] = irr::KEY_F1;
1359 KeyCodes[kVK_F2] = irr::KEY_F2; 1359 KeyCodes[kVK_F2] = irr::KEY_F2;
1360 KeyCodes[kVK_F3] = irr::KEY_F3; 1360 KeyCodes[kVK_F3] = irr::KEY_F3;
1361 KeyCodes[kVK_F4] = irr::KEY_F4; 1361 KeyCodes[kVK_F4] = irr::KEY_F4;
1362 KeyCodes[kVK_F5] = irr::KEY_F5; 1362 KeyCodes[kVK_F5] = irr::KEY_F5;
1363 KeyCodes[kVK_F6] = irr::KEY_F6; 1363 KeyCodes[kVK_F6] = irr::KEY_F6;
1364 KeyCodes[kVK_F7] = irr::KEY_F7; 1364 KeyCodes[kVK_F7] = irr::KEY_F7;
1365 KeyCodes[kVK_F8] = irr::KEY_F8; 1365 KeyCodes[kVK_F8] = irr::KEY_F8;
1366 KeyCodes[kVK_F9] = irr::KEY_F9; 1366 KeyCodes[kVK_F9] = irr::KEY_F9;
1367 KeyCodes[kVK_F10] = irr::KEY_F10; 1367 KeyCodes[kVK_F10] = irr::KEY_F10;
1368 KeyCodes[kVK_F11] = irr::KEY_F11; 1368 KeyCodes[kVK_F11] = irr::KEY_F11;
1369 KeyCodes[kVK_F12] = irr::KEY_F12; 1369 KeyCodes[kVK_F12] = irr::KEY_F12;
1370 KeyCodes[kVK_F13] = irr::KEY_F13; 1370 KeyCodes[kVK_F13] = irr::KEY_F13;
1371 KeyCodes[kVK_F14] = irr::KEY_F14; 1371 KeyCodes[kVK_F14] = irr::KEY_F14;
1372 KeyCodes[kVK_F15] = irr::KEY_F15; 1372 KeyCodes[kVK_F15] = irr::KEY_F15;
1373 KeyCodes[kVK_F16] = irr::KEY_F16; 1373 KeyCodes[kVK_F16] = irr::KEY_F16;
1374 KeyCodes[kVK_F17] = irr::KEY_F17; 1374 KeyCodes[kVK_F17] = irr::KEY_F17;
1375 KeyCodes[kVK_F18] = irr::KEY_F18; 1375 KeyCodes[kVK_F18] = irr::KEY_F18;
1376 KeyCodes[kVK_F19] = irr::KEY_F19; 1376 KeyCodes[kVK_F19] = irr::KEY_F19;
1377 KeyCodes[kVK_F20] = irr::KEY_F20; 1377 KeyCodes[kVK_F20] = irr::KEY_F20;
1378 KeyCodes[kVK_Home] = irr::KEY_HOME; 1378 KeyCodes[kVK_Home] = irr::KEY_HOME;
1379 KeyCodes[kVK_End] = irr::KEY_END; 1379 KeyCodes[kVK_End] = irr::KEY_END;
1380 KeyCodes[NSInsertFunctionKey] = irr::KEY_INSERT; 1380 KeyCodes[NSInsertFunctionKey] = irr::KEY_INSERT;
1381 KeyCodes[kVK_ForwardDelete] = irr::KEY_DELETE; 1381 KeyCodes[kVK_ForwardDelete] = irr::KEY_DELETE;
1382 KeyCodes[kVK_Help] = irr::KEY_HELP; 1382 KeyCodes[kVK_Help] = irr::KEY_HELP;
1383 KeyCodes[NSSelectFunctionKey] = irr::KEY_SELECT; 1383 KeyCodes[NSSelectFunctionKey] = irr::KEY_SELECT;
1384 KeyCodes[NSPrintFunctionKey] = irr::KEY_PRINT; 1384 KeyCodes[NSPrintFunctionKey] = irr::KEY_PRINT;
1385 KeyCodes[NSExecuteFunctionKey] = irr::KEY_EXECUT; 1385 KeyCodes[NSExecuteFunctionKey] = irr::KEY_EXECUT;
1386 KeyCodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT; 1386 KeyCodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT;
1387 KeyCodes[NSPauseFunctionKey] = irr::KEY_PAUSE; 1387 KeyCodes[NSPauseFunctionKey] = irr::KEY_PAUSE;
1388 KeyCodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL; 1388 KeyCodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL;
1389 KeyCodes[kVK_Delete] = irr::KEY_BACK; 1389 KeyCodes[kVK_Delete] = irr::KEY_BACK;
1390 KeyCodes[kVK_Tab] = irr::KEY_TAB; 1390 KeyCodes[kVK_Tab] = irr::KEY_TAB;
1391 KeyCodes[kVK_Return] = irr::KEY_RETURN; 1391 KeyCodes[kVK_Return] = irr::KEY_RETURN;
1392 KeyCodes[kVK_Escape] = irr::KEY_ESCAPE; 1392 KeyCodes[kVK_Escape] = irr::KEY_ESCAPE;
1393 KeyCodes[kVK_Control] = irr::KEY_CONTROL; 1393 KeyCodes[kVK_Control] = irr::KEY_CONTROL;
1394 KeyCodes[kVK_RightControl] = irr::KEY_RCONTROL; 1394 KeyCodes[kVK_RightControl] = irr::KEY_RCONTROL;
1395 KeyCodes[kVK_Command] = irr::KEY_MENU; 1395 KeyCodes[kVK_Command] = irr::KEY_MENU;
1396 KeyCodes[kVK_Shift] = irr::KEY_SHIFT; 1396 KeyCodes[kVK_Shift] = irr::KEY_SHIFT;
1397 KeyCodes[kVK_RightShift] = irr::KEY_RSHIFT; 1397 KeyCodes[kVK_RightShift] = irr::KEY_RSHIFT;
1398 KeyCodes[kVK_Space] = irr::KEY_SPACE; 1398 KeyCodes[kVK_Space] = irr::KEY_SPACE;
1399 1399
1400 KeyCodes[kVK_ANSI_A] = irr::KEY_KEY_A; 1400 KeyCodes[kVK_ANSI_A] = irr::KEY_KEY_A;
1401 KeyCodes[kVK_ANSI_B] = irr::KEY_KEY_B; 1401 KeyCodes[kVK_ANSI_B] = irr::KEY_KEY_B;
1402 KeyCodes[kVK_ANSI_C] = irr::KEY_KEY_C; 1402 KeyCodes[kVK_ANSI_C] = irr::KEY_KEY_C;
1403 KeyCodes[kVK_ANSI_D] = irr::KEY_KEY_D; 1403 KeyCodes[kVK_ANSI_D] = irr::KEY_KEY_D;
1404 KeyCodes[kVK_ANSI_E] = irr::KEY_KEY_E; 1404 KeyCodes[kVK_ANSI_E] = irr::KEY_KEY_E;
1405 KeyCodes[kVK_ANSI_F] = irr::KEY_KEY_F; 1405 KeyCodes[kVK_ANSI_F] = irr::KEY_KEY_F;
1406 KeyCodes[kVK_ANSI_G] = irr::KEY_KEY_G; 1406 KeyCodes[kVK_ANSI_G] = irr::KEY_KEY_G;
1407 KeyCodes[kVK_ANSI_H] = irr::KEY_KEY_H; 1407 KeyCodes[kVK_ANSI_H] = irr::KEY_KEY_H;
1408 KeyCodes[kVK_ANSI_I] = irr::KEY_KEY_I; 1408 KeyCodes[kVK_ANSI_I] = irr::KEY_KEY_I;
1409 KeyCodes[kVK_ANSI_J] = irr::KEY_KEY_J; 1409 KeyCodes[kVK_ANSI_J] = irr::KEY_KEY_J;
1410 KeyCodes[kVK_ANSI_K] = irr::KEY_KEY_K; 1410 KeyCodes[kVK_ANSI_K] = irr::KEY_KEY_K;
1411 KeyCodes[kVK_ANSI_L] = irr::KEY_KEY_L; 1411 KeyCodes[kVK_ANSI_L] = irr::KEY_KEY_L;
1412 KeyCodes[kVK_ANSI_M] = irr::KEY_KEY_M; 1412 KeyCodes[kVK_ANSI_M] = irr::KEY_KEY_M;
1413 KeyCodes[kVK_ANSI_N] = irr::KEY_KEY_N; 1413 KeyCodes[kVK_ANSI_N] = irr::KEY_KEY_N;
1414 KeyCodes[kVK_ANSI_O] = irr::KEY_KEY_O; 1414 KeyCodes[kVK_ANSI_O] = irr::KEY_KEY_O;
1415 KeyCodes[kVK_ANSI_P] = irr::KEY_KEY_P; 1415 KeyCodes[kVK_ANSI_P] = irr::KEY_KEY_P;
1416 KeyCodes[kVK_ANSI_Q] = irr::KEY_KEY_Q; 1416 KeyCodes[kVK_ANSI_Q] = irr::KEY_KEY_Q;
1417 KeyCodes[kVK_ANSI_R] = irr::KEY_KEY_R; 1417 KeyCodes[kVK_ANSI_R] = irr::KEY_KEY_R;
1418 KeyCodes[kVK_ANSI_S] = irr::KEY_KEY_S; 1418 KeyCodes[kVK_ANSI_S] = irr::KEY_KEY_S;
1419 KeyCodes[kVK_ANSI_T] = irr::KEY_KEY_T; 1419 KeyCodes[kVK_ANSI_T] = irr::KEY_KEY_T;
1420 KeyCodes[kVK_ANSI_U] = irr::KEY_KEY_U; 1420 KeyCodes[kVK_ANSI_U] = irr::KEY_KEY_U;
1421 KeyCodes[kVK_ANSI_V] = irr::KEY_KEY_V; 1421 KeyCodes[kVK_ANSI_V] = irr::KEY_KEY_V;
1422 KeyCodes[kVK_ANSI_W] = irr::KEY_KEY_W; 1422 KeyCodes[kVK_ANSI_W] = irr::KEY_KEY_W;
1423 KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X; 1423 KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X;
1424 KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X; 1424 KeyCodes[kVK_ANSI_X] = irr::KEY_KEY_X;
1425 KeyCodes[kVK_ANSI_Y] = irr::KEY_KEY_Y; 1425 KeyCodes[kVK_ANSI_Y] = irr::KEY_KEY_Y;
1426 KeyCodes[kVK_ANSI_Z] = irr::KEY_KEY_Z; 1426 KeyCodes[kVK_ANSI_Z] = irr::KEY_KEY_Z;
1427 1427
1428 KeyCodes[kVK_ANSI_0] = irr::KEY_KEY_0; 1428 KeyCodes[kVK_ANSI_0] = irr::KEY_KEY_0;
1429 KeyCodes[kVK_ANSI_1] = irr::KEY_KEY_1; 1429 KeyCodes[kVK_ANSI_1] = irr::KEY_KEY_1;
1430 KeyCodes[kVK_ANSI_2] = irr::KEY_KEY_2; 1430 KeyCodes[kVK_ANSI_2] = irr::KEY_KEY_2;
1431 KeyCodes[kVK_ANSI_3] = irr::KEY_KEY_3; 1431 KeyCodes[kVK_ANSI_3] = irr::KEY_KEY_3;
1432 KeyCodes[kVK_ANSI_4] = irr::KEY_KEY_4; 1432 KeyCodes[kVK_ANSI_4] = irr::KEY_KEY_4;
1433 KeyCodes[kVK_ANSI_5] = irr::KEY_KEY_5; 1433 KeyCodes[kVK_ANSI_5] = irr::KEY_KEY_5;
1434 KeyCodes[kVK_ANSI_6] = irr::KEY_KEY_6; 1434 KeyCodes[kVK_ANSI_6] = irr::KEY_KEY_6;
1435 KeyCodes[kVK_ANSI_7] = irr::KEY_KEY_7; 1435 KeyCodes[kVK_ANSI_7] = irr::KEY_KEY_7;
1436 KeyCodes[kVK_ANSI_8] = irr::KEY_KEY_8; 1436 KeyCodes[kVK_ANSI_8] = irr::KEY_KEY_8;
1437 KeyCodes[kVK_ANSI_9] = irr::KEY_KEY_9; 1437 KeyCodes[kVK_ANSI_9] = irr::KEY_KEY_9;
1438 1438
1439 KeyCodes[kVK_ANSI_Slash] = irr::KEY_DIVIDE; 1439 KeyCodes[kVK_ANSI_Slash] = irr::KEY_DIVIDE;
1440 KeyCodes[kVK_ANSI_Comma] = irr::KEY_COMMA; 1440 KeyCodes[kVK_ANSI_Comma] = irr::KEY_COMMA;
1441 KeyCodes[kVK_ANSI_Period] = irr::KEY_PERIOD; 1441 KeyCodes[kVK_ANSI_Period] = irr::KEY_PERIOD;
1442 KeyCodes[kVK_PageUp] = irr::KEY_PRIOR; 1442 KeyCodes[kVK_PageUp] = irr::KEY_PRIOR;
1443 KeyCodes[kVK_PageDown] = irr::KEY_NEXT; 1443 KeyCodes[kVK_PageDown] = irr::KEY_NEXT;
1444 1444
1445 KeyCodes[kVK_ANSI_Keypad0] = irr::KEY_NUMPAD0; 1445 KeyCodes[kVK_ANSI_Keypad0] = irr::KEY_NUMPAD0;
1446 KeyCodes[kVK_ANSI_Keypad1] = irr::KEY_NUMPAD1; 1446 KeyCodes[kVK_ANSI_Keypad1] = irr::KEY_NUMPAD1;
1447 KeyCodes[kVK_ANSI_Keypad2] = irr::KEY_NUMPAD2; 1447 KeyCodes[kVK_ANSI_Keypad2] = irr::KEY_NUMPAD2;
1448 KeyCodes[kVK_ANSI_Keypad3] = irr::KEY_NUMPAD3; 1448 KeyCodes[kVK_ANSI_Keypad3] = irr::KEY_NUMPAD3;
1449 KeyCodes[kVK_ANSI_Keypad4] = irr::KEY_NUMPAD4; 1449 KeyCodes[kVK_ANSI_Keypad4] = irr::KEY_NUMPAD4;
1450 KeyCodes[kVK_ANSI_Keypad5] = irr::KEY_NUMPAD5; 1450 KeyCodes[kVK_ANSI_Keypad5] = irr::KEY_NUMPAD5;
1451 KeyCodes[kVK_ANSI_Keypad6] = irr::KEY_NUMPAD6; 1451 KeyCodes[kVK_ANSI_Keypad6] = irr::KEY_NUMPAD6;
1452 KeyCodes[kVK_ANSI_Keypad7] = irr::KEY_NUMPAD7; 1452 KeyCodes[kVK_ANSI_Keypad7] = irr::KEY_NUMPAD7;
1453 KeyCodes[kVK_ANSI_Keypad8] = irr::KEY_NUMPAD8; 1453 KeyCodes[kVK_ANSI_Keypad8] = irr::KEY_NUMPAD8;
1454 KeyCodes[kVK_ANSI_Keypad9] = irr::KEY_NUMPAD9; 1454 KeyCodes[kVK_ANSI_Keypad9] = irr::KEY_NUMPAD9;
1455 1455
1456 KeyCodes[kVK_ANSI_KeypadDecimal] = irr::KEY_DECIMAL; 1456 KeyCodes[kVK_ANSI_KeypadDecimal] = irr::KEY_DECIMAL;
1457 KeyCodes[kVK_ANSI_KeypadMultiply] = irr::KEY_MULTIPLY; 1457 KeyCodes[kVK_ANSI_KeypadMultiply] = irr::KEY_MULTIPLY;
1458 KeyCodes[kVK_ANSI_KeypadPlus] = irr::KEY_PLUS; 1458 KeyCodes[kVK_ANSI_KeypadPlus] = irr::KEY_PLUS;
1459 KeyCodes[kVK_ANSI_KeypadClear] = irr::KEY_OEM_CLEAR; 1459 KeyCodes[kVK_ANSI_KeypadClear] = irr::KEY_OEM_CLEAR;
1460 KeyCodes[kVK_ANSI_KeypadDivide] = irr::KEY_DIVIDE; 1460 KeyCodes[kVK_ANSI_KeypadDivide] = irr::KEY_DIVIDE;
1461 KeyCodes[kVK_ANSI_KeypadEnter] = irr::KEY_RETURN; 1461 KeyCodes[kVK_ANSI_KeypadEnter] = irr::KEY_RETURN;
1462 KeyCodes[kVK_ANSI_KeypadMinus] = irr::KEY_SUBTRACT; 1462 KeyCodes[kVK_ANSI_KeypadMinus] = irr::KEY_SUBTRACT;
1463} 1463}
1464 1464
1465 1465
1466//! Sets if the window should be resizable in windowed mode. 1466//! Sets if the window should be resizable in windowed mode.
1467void CIrrDeviceMacOSX::setResizable(bool resize) 1467void CIrrDeviceMacOSX::setResizable(bool resize)
1468{ 1468{
1469 IsResizable = resize; 1469 IsResizable = resize;
1470#if 0 1470#if 0
1471 if (resize) 1471 if (resize)
1472 [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask]; 1472 [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask];
1473 else 1473 else
1474 [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask]; 1474 [Window setStyleMask:NSTitledWindowMask|NSClosableWindowMask];
1475#endif 1475#endif
1476} 1476}
1477 1477
1478 1478
1479bool CIrrDeviceMacOSX::isResizable() const 1479bool CIrrDeviceMacOSX::isResizable() const
1480{ 1480{
1481 return IsResizable; 1481 return IsResizable;
1482} 1482}
1483 1483
1484 1484
1485void CIrrDeviceMacOSX::minimizeWindow() 1485void CIrrDeviceMacOSX::minimizeWindow()
1486{ 1486{
1487 if (Window != NULL) 1487 if (Window != NULL)
1488 [Window miniaturize:[NSApp self]]; 1488 [Window miniaturize:[NSApp self]];
1489} 1489}
1490 1490
1491 1491
1492//! Maximizes the window if possible. 1492//! Maximizes the window if possible.
1493void CIrrDeviceMacOSX::maximizeWindow() 1493void CIrrDeviceMacOSX::maximizeWindow()
1494{ 1494{
1495 // todo: implement 1495 // todo: implement
1496} 1496}
1497 1497
1498 1498
1499//! Restore the window to normal size if possible. 1499//! Restore the window to normal size if possible.
1500void CIrrDeviceMacOSX::restoreWindow() 1500void CIrrDeviceMacOSX::restoreWindow()
1501{ 1501{
1502 [Window deminiaturize:[NSApp self]]; 1502 [Window deminiaturize:[NSApp self]];
1503} 1503}
1504 1504
1505 1505
1506bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src ) 1506bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )
1507{ 1507{
1508 // todo: implement window ID and src rectangle 1508 // todo: implement window ID and src rectangle
1509 1509
1510 if (!surface) 1510 if (!surface)
1511 return false; 1511 return false;
1512 1512
1513 if (SoftwareRendererType > 0) 1513 if (SoftwareRendererType > 0)
1514 { 1514 {
1515 const u32 colorSamples=3; 1515 const u32 colorSamples=3;
1516 // do we need to change the size? 1516 // do we need to change the size?
1517 const bool updateSize = !SoftwareDriverTarget || 1517 const bool updateSize = !SoftwareDriverTarget ||
1518 s32([SoftwareDriverTarget size].width) != surface->getDimension().Width || 1518 s32([SoftwareDriverTarget size].width) != surface->getDimension().Width ||
1519 s32([SoftwareDriverTarget size].height) != surface->getDimension().Height; 1519 s32([SoftwareDriverTarget size].height) != surface->getDimension().Height;
1520 1520
1521 NSRect areaRect = NSMakeRect(0.0, 0.0, surface->getDimension().Width, surface->getDimension().Height); 1521 NSRect areaRect = NSMakeRect(0.0, 0.0, surface->getDimension().Width, surface->getDimension().Height);
1522 const u32 destPitch = (colorSamples * areaRect.size.width); 1522 const u32 destPitch = (colorSamples * areaRect.size.width);
1523 1523
1524 // create / update the target 1524 // create / update the target
1525 if (updateSize) 1525 if (updateSize)
1526 { 1526 {
1527 [SoftwareDriverTarget release]; 1527 [SoftwareDriverTarget release];
1528 // allocate target for IImage 1528 // allocate target for IImage
1529 SoftwareDriverTarget = [[NSBitmapImageRep alloc] 1529 SoftwareDriverTarget = [[NSBitmapImageRep alloc]
1530 initWithBitmapDataPlanes: nil 1530 initWithBitmapDataPlanes: nil
1531 pixelsWide: areaRect.size.width 1531 pixelsWide: areaRect.size.width
1532 pixelsHigh: areaRect.size.height 1532 pixelsHigh: areaRect.size.height
1533 bitsPerSample: 8 1533 bitsPerSample: 8
1534 samplesPerPixel: colorSamples 1534 samplesPerPixel: colorSamples
1535 hasAlpha: NO 1535 hasAlpha: NO
1536 isPlanar: NO 1536 isPlanar: NO
1537 colorSpaceName: NSCalibratedRGBColorSpace 1537 colorSpaceName: NSCalibratedRGBColorSpace
1538 bytesPerRow: destPitch 1538 bytesPerRow: destPitch
1539 bitsPerPixel: 8*colorSamples]; 1539 bitsPerPixel: 8*colorSamples];
1540 } 1540 }
1541 1541
1542 if (SoftwareDriverTarget==nil) 1542 if (SoftwareDriverTarget==nil)
1543 return false; 1543 return false;
1544 1544
1545 // get pointer to image data 1545 // get pointer to image data
1546 unsigned char* imgData = (unsigned char*)surface->lock(); 1546 unsigned char* imgData = (unsigned char*)surface->lock();
1547 1547
1548 u8* srcdata = reinterpret_cast<u8*>(imgData); 1548 u8* srcdata = reinterpret_cast<u8*>(imgData);
1549 u8* destData = reinterpret_cast<u8*>([SoftwareDriverTarget bitmapData]); 1549 u8* destData = reinterpret_cast<u8*>([SoftwareDriverTarget bitmapData]);
1550 const u32 srcheight = core::min_(surface->getDimension().Height, (u32)areaRect.size.height); 1550 const u32 srcheight = core::min_(surface->getDimension().Height, (u32)areaRect.size.height);
1551 const u32 srcPitch = surface->getPitch(); 1551 const u32 srcPitch = surface->getPitch();
1552 const u32 minWidth = core::min_(surface->getDimension().Width, (u32)areaRect.size.width); 1552 const u32 minWidth = core::min_(surface->getDimension().Width, (u32)areaRect.size.width);
1553 for (u32 y=0; y!=srcheight; ++y) 1553 for (u32 y=0; y!=srcheight; ++y)
1554 { 1554 {
1555 if(SoftwareRendererType == 2) 1555 if(SoftwareRendererType == 2)
1556 { 1556 {
1557 if (surface->getColorFormat() == video::ECF_A8R8G8B8) 1557 if (surface->getColorFormat() == video::ECF_A8R8G8B8)
1558 video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData); 1558 video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData);
1559 else if (surface->getColorFormat() == video::ECF_A1R5G5B5) 1559 else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
1560 video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData); 1560 video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData);
1561 else 1561 else
1562 video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8); 1562 video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
1563 } 1563 }
1564 else 1564 else
1565 { 1565 {
1566 if (surface->getColorFormat() == video::ECF_A8R8G8B8) 1566 if (surface->getColorFormat() == video::ECF_A8R8G8B8)
1567 video::CColorConverter::convert_A8R8G8B8toR8G8B8(srcdata, minWidth, destData); 1567 video::CColorConverter::convert_A8R8G8B8toR8G8B8(srcdata, minWidth, destData);
1568 else if (surface->getColorFormat() == video::ECF_A1R5G5B5) 1568 else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
1569 video::CColorConverter::convert_A1R5G5B5toR8G8B8(srcdata, minWidth, destData); 1569 video::CColorConverter::convert_A1R5G5B5toR8G8B8(srcdata, minWidth, destData);
1570 else 1570 else
1571 video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8); 1571 video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
1572 } 1572 }
1573 1573
1574 srcdata += srcPitch; 1574 srcdata += srcPitch;
1575 destData += destPitch; 1575 destData += destPitch;
1576 } 1576 }
1577 1577
1578 // unlock the data 1578 // unlock the data
1579 surface->unlock(); 1579 surface->unlock();
1580 1580
1581 // todo: draw properly into a sub-view 1581 // todo: draw properly into a sub-view
1582 [SoftwareDriverTarget draw]; 1582 [SoftwareDriverTarget draw];
1583 } 1583 }
1584 1584
1585 return false; 1585 return false;
1586} 1586}
1587 1587
1588 1588
1589#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) 1589#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
1590static void joystickRemovalCallback(void * target, 1590static void joystickRemovalCallback(void * target,
1591 IOReturn result, void * refcon, void * sender) 1591 IOReturn result, void * refcon, void * sender)
1592{ 1592{
1593 JoystickInfo *joy = (JoystickInfo *) refcon; 1593 JoystickInfo *joy = (JoystickInfo *) refcon;
1594 joy->removed = 1; 1594 joy->removed = 1;
1595} 1595}
1596#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 1596#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
1597 1597
1598 1598
1599bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickInfo) 1599bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickInfo)
1600{ 1600{
1601#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) 1601#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
1602 ActiveJoysticks.clear(); 1602 ActiveJoysticks.clear();
1603 joystickInfo.clear(); 1603 joystickInfo.clear();
1604 1604
1605 io_object_t hidObject = 0; 1605 io_object_t hidObject = 0;
1606 io_iterator_t hidIterator = 0; 1606 io_iterator_t hidIterator = 0;
1607 IOReturn result = kIOReturnSuccess; 1607 IOReturn result = kIOReturnSuccess;
1608 mach_port_t masterPort = 0; 1608 mach_port_t masterPort = 0;
1609 CFMutableDictionaryRef hidDictionaryRef = NULL; 1609 CFMutableDictionaryRef hidDictionaryRef = NULL;
1610 1610
1611 result = IOMasterPort (bootstrap_port, &masterPort); 1611 result = IOMasterPort (bootstrap_port, &masterPort);
1612 if (kIOReturnSuccess != result) 1612 if (kIOReturnSuccess != result)
1613 { 1613 {
1614 os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR); 1614 os::Printer::log("initialiseJoysticks IOMasterPort failed", ELL_ERROR);
1615 return false; 1615 return false;
1616 } 1616 }
1617 1617
1618 hidDictionaryRef = IOServiceMatching (kIOHIDDeviceKey); 1618 hidDictionaryRef = IOServiceMatching (kIOHIDDeviceKey);
1619 if (!hidDictionaryRef) 1619 if (!hidDictionaryRef)
1620 { 1620 {
1621 os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR); 1621 os::Printer::log("initialiseJoysticks IOServiceMatching failed", ELL_ERROR);
1622 return false; 1622 return false;
1623 } 1623 }
1624 result = IOServiceGetMatchingServices (masterPort, hidDictionaryRef, &hidIterator); 1624 result = IOServiceGetMatchingServices (masterPort, hidDictionaryRef, &hidIterator);
1625 1625
1626 if (kIOReturnSuccess != result) 1626 if (kIOReturnSuccess != result)
1627 { 1627 {
1628 os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR); 1628 os::Printer::log("initialiseJoysticks IOServiceGetMatchingServices failed", ELL_ERROR);
1629 return false; 1629 return false;
1630 } 1630 }
1631 1631
1632 //no joysticks just return 1632 //no joysticks just return
1633 if (!hidIterator) 1633 if (!hidIterator)
1634 return false; 1634 return false;
1635 1635
1636 u32 jindex = 0u; 1636 u32 jindex = 0u;
1637 while ((hidObject = IOIteratorNext (hidIterator))) 1637 while ((hidObject = IOIteratorNext (hidIterator)))
1638 { 1638 {
1639 JoystickInfo info; 1639 JoystickInfo info;
1640 1640
1641 // get dictionary for HID properties 1641 // get dictionary for HID properties
1642 CFMutableDictionaryRef hidProperties = 0; 1642 CFMutableDictionaryRef hidProperties = 0;
1643 1643
1644 kern_return_t kern_result = IORegistryEntryCreateCFProperties (hidObject, &hidProperties, kCFAllocatorDefault, kNilOptions); 1644 kern_return_t kern_result = IORegistryEntryCreateCFProperties (hidObject, &hidProperties, kCFAllocatorDefault, kNilOptions);
1645 if ((kern_result == KERN_SUCCESS) && hidProperties) 1645 if ((kern_result == KERN_SUCCESS) && hidProperties)
1646 { 1646 {
1647 HRESULT plugInResult = S_OK; 1647 HRESULT plugInResult = S_OK;
1648 SInt32 score = 0; 1648 SInt32 score = 0;
1649 IOCFPlugInInterface ** ppPlugInInterface = NULL; 1649 IOCFPlugInInterface ** ppPlugInInterface = NULL;
1650 result = IOCreatePlugInInterfaceForService (hidObject, kIOHIDDeviceUserClientTypeID, 1650 result = IOCreatePlugInInterfaceForService (hidObject, kIOHIDDeviceUserClientTypeID,
1651 kIOCFPlugInInterfaceID, &ppPlugInInterface, &score); 1651 kIOCFPlugInInterfaceID, &ppPlugInInterface, &score);
1652 if (kIOReturnSuccess == result) 1652 if (kIOReturnSuccess == result)
1653 { 1653 {
1654 plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface, 1654 plugInResult = (*ppPlugInInterface)->QueryInterface (ppPlugInInterface,
1655 CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void **) &(info.interface)); 1655 CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID), (void **) &(info.interface));
1656 if (plugInResult != S_OK) 1656 if (plugInResult != S_OK)
1657 os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR); 1657 os::Printer::log("initialiseJoysticks query HID class device interface failed", ELL_ERROR);
1658 (*ppPlugInInterface)->Release(ppPlugInInterface); 1658 (*ppPlugInInterface)->Release(ppPlugInInterface);
1659 } 1659 }
1660 else 1660 else
1661 continue; 1661 continue;
1662 1662
1663 if (info.interface != NULL) 1663 if (info.interface != NULL)
1664 { 1664 {
1665 result = (*(info.interface))->open (info.interface, 0); 1665 result = (*(info.interface))->open (info.interface, 0);
1666 if (result == kIOReturnSuccess) 1666 if (result == kIOReturnSuccess)
1667 { 1667 {
1668 (*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info); 1668 (*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info);
1669 getJoystickDeviceInfo(hidObject, hidProperties, &info); 1669 getJoystickDeviceInfo(hidObject, hidProperties, &info);
1670 1670
1671 // get elements 1671 // get elements
1672 CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); 1672 CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
1673 if (refElementTop) 1673 if (refElementTop)
1674 { 1674 {
1675 CFTypeID type = CFGetTypeID (refElementTop); 1675 CFTypeID type = CFGetTypeID (refElementTop);
1676 if (type == CFArrayGetTypeID()) 1676 if (type == CFArrayGetTypeID())
1677 { 1677 {
1678 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)}; 1678 CFRange range = {0, CFArrayGetCount ((CFArrayRef)refElementTop)};
1679 info.numActiveJoysticks = ActiveJoysticks.size(); 1679 info.numActiveJoysticks = ActiveJoysticks.size();
1680 CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info); 1680 CFArrayApplyFunction ((CFArrayRef)refElementTop, range, getJoystickComponentArrayHandler, &info);
1681 } 1681 }
1682 } 1682 }
1683 } 1683 }
1684 else 1684 else
1685 { 1685 {
1686 CFRelease (hidProperties); 1686 CFRelease (hidProperties);
1687 os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR); 1687 os::Printer::log("initialiseJoysticks Open interface failed", ELL_ERROR);
1688 continue; 1688 continue;
1689 } 1689 }
1690 1690
1691 CFRelease (hidProperties); 1691 CFRelease (hidProperties);
1692 1692
1693 result = IOObjectRelease (hidObject); 1693 result = IOObjectRelease (hidObject);
1694 1694
1695 if ( (info.usagePage != kHIDPage_GenericDesktop) || 1695 if ( (info.usagePage != kHIDPage_GenericDesktop) ||
1696 ((info.usage != kHIDUsage_GD_Joystick && 1696 ((info.usage != kHIDUsage_GD_Joystick &&
1697 info.usage != kHIDUsage_GD_GamePad && 1697 info.usage != kHIDUsage_GD_GamePad &&
1698 info.usage != kHIDUsage_GD_MultiAxisController)) ) 1698 info.usage != kHIDUsage_GD_MultiAxisController)) )
1699 { 1699 {
1700 closeJoystickDevice (&info); 1700 closeJoystickDevice (&info);
1701 continue; 1701 continue;
1702 } 1702 }
1703 1703
1704 for (u32 i = 0; i < 6; ++i) 1704 for (u32 i = 0; i < 6; ++i)
1705 info.persistentData.JoystickEvent.Axis[i] = 0; 1705 info.persistentData.JoystickEvent.Axis[i] = 0;
1706 1706
1707 ActiveJoysticks.push_back(info); 1707 ActiveJoysticks.push_back(info);
1708 1708
1709 SJoystickInfo returnInfo; 1709 SJoystickInfo returnInfo;
1710 returnInfo.Joystick = jindex; 1710 returnInfo.Joystick = jindex;
1711 returnInfo.Axes = info.axes; 1711 returnInfo.Axes = info.axes;
1712 //returnInfo.Hats = info.hats; 1712 //returnInfo.Hats = info.hats;
1713 returnInfo.Buttons = info.buttons; 1713 returnInfo.Buttons = info.buttons;
1714 returnInfo.Name = info.joystickName; 1714 returnInfo.Name = info.joystickName;
1715 returnInfo.PovHat = SJoystickInfo::POV_HAT_UNKNOWN; 1715 returnInfo.PovHat = SJoystickInfo::POV_HAT_UNKNOWN;
1716 ++ jindex; 1716 ++ jindex;
1717 1717
1718 //if (info.hatComp.size()) 1718 //if (info.hatComp.size())
1719 // returnInfo.PovHat = SJoystickInfo::POV_HAT_PRESENT; 1719 // returnInfo.PovHat = SJoystickInfo::POV_HAT_PRESENT;
1720 //else 1720 //else
1721 // returnInfo.PovHat = SJoystickInfo::POV_HAT_ABSENT; 1721 // returnInfo.PovHat = SJoystickInfo::POV_HAT_ABSENT;
1722 1722
1723 joystickInfo.push_back(returnInfo); 1723 joystickInfo.push_back(returnInfo);
1724 } 1724 }
1725 1725
1726 } 1726 }
1727 else 1727 else
1728 { 1728 {
1729 continue; 1729 continue;
1730 } 1730 }
1731 } 1731 }
1732 result = IOObjectRelease (hidIterator); 1732 result = IOObjectRelease (hidIterator);
1733 1733
1734 return true; 1734 return true;
1735#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 1735#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
1736 1736
1737 return false; 1737 return false;
1738} 1738}
1739 1739
1740void CIrrDeviceMacOSX::pollJoysticks() 1740void CIrrDeviceMacOSX::pollJoysticks()
1741{ 1741{
1742#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_) 1742#if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
1743 if(0 == ActiveJoysticks.size()) 1743 if(0 == ActiveJoysticks.size())
1744 return; 1744 return;
1745 1745
1746 u32 joystick; 1746 u32 joystick;
1747 for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) 1747 for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick)
1748 { 1748 {
1749 if (ActiveJoysticks[joystick].removed) 1749 if (ActiveJoysticks[joystick].removed)
1750 continue; 1750 continue;
1751 1751
1752 bool found = false; 1752 bool found = false;
1753 ActiveJoysticks[joystick].persistentData.JoystickEvent.Joystick = joystick; 1753 ActiveJoysticks[joystick].persistentData.JoystickEvent.Joystick = joystick;
1754 1754
1755 if (ActiveJoysticks[joystick].interface) 1755 if (ActiveJoysticks[joystick].interface)
1756 { 1756 {
1757 for (u32 n = 0; n < ActiveJoysticks[joystick].axisComp.size(); n++) 1757 for (u32 n = 0; n < ActiveJoysticks[joystick].axisComp.size(); n++)
1758 { 1758 {
1759 IOReturn result = kIOReturnSuccess; 1759 IOReturn result = kIOReturnSuccess;
1760 IOHIDEventStruct hidEvent; 1760 IOHIDEventStruct hidEvent;
1761 hidEvent.value = 0; 1761 hidEvent.value = 0;
1762 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].axisComp[n].cookie, &hidEvent); 1762 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].axisComp[n].cookie, &hidEvent);
1763 if (kIOReturnSuccess == result) 1763 if (kIOReturnSuccess == result)
1764 { 1764 {
1765 const f32 min = -32768.0f; 1765 const f32 min = -32768.0f;
1766 const f32 max = 32767.0f; 1766 const f32 max = 32767.0f;
1767 const f32 deviceScale = max - min; 1767 const f32 deviceScale = max - min;
1768 const f32 readScale = (f32)ActiveJoysticks[joystick].axisComp[n].maxRead - (f32)ActiveJoysticks[joystick].axisComp[n].minRead; 1768 const f32 readScale = (f32)ActiveJoysticks[joystick].axisComp[n].maxRead - (f32)ActiveJoysticks[joystick].axisComp[n].minRead;
1769 1769
1770 if (hidEvent.value < ActiveJoysticks[joystick].axisComp[n].minRead) 1770 if (hidEvent.value < ActiveJoysticks[joystick].axisComp[n].minRead)
1771 ActiveJoysticks[joystick].axisComp[n].minRead = hidEvent.value; 1771 ActiveJoysticks[joystick].axisComp[n].minRead = hidEvent.value;
1772 if (hidEvent.value > ActiveJoysticks[joystick].axisComp[n].maxRead) 1772 if (hidEvent.value > ActiveJoysticks[joystick].axisComp[n].maxRead)
1773 ActiveJoysticks[joystick].axisComp[n].maxRead = hidEvent.value; 1773 ActiveJoysticks[joystick].axisComp[n].maxRead = hidEvent.value;
1774 1774
1775 if (readScale != 0.0f) 1775 if (readScale != 0.0f)
1776 hidEvent.value = (int)(((f32)((f32)hidEvent.value - (f32)ActiveJoysticks[joystick].axisComp[n].minRead) * deviceScale / readScale) + min); 1776 hidEvent.value = (int)(((f32)((f32)hidEvent.value - (f32)ActiveJoysticks[joystick].axisComp[n].minRead) * deviceScale / readScale) + min);
1777 1777
1778 if (ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] != (s16)hidEvent.value) 1778 if (ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] != (s16)hidEvent.value)
1779 found = true; 1779 found = true;
1780 ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] = (s16)hidEvent.value; 1780 ActiveJoysticks[joystick].persistentData.JoystickEvent.Axis[n] = (s16)hidEvent.value;
1781 } 1781 }
1782 }//axis check 1782 }//axis check
1783 1783
1784 for (u32 n = 0; n < ActiveJoysticks[joystick].buttonComp.size(); n++) 1784 for (u32 n = 0; n < ActiveJoysticks[joystick].buttonComp.size(); n++)
1785 { 1785 {
1786 IOReturn result = kIOReturnSuccess; 1786 IOReturn result = kIOReturnSuccess;
1787 IOHIDEventStruct hidEvent; 1787 IOHIDEventStruct hidEvent;
1788 hidEvent.value = 0; 1788 hidEvent.value = 0;
1789 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent); 1789 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].buttonComp[n].cookie, &hidEvent);
1790 if (kIOReturnSuccess == result) 1790 if (kIOReturnSuccess == result)
1791 { 1791 {
1792 u32 ButtonStates = 0; 1792 u32 ButtonStates = 0;
1793 1793
1794 if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false) ) 1794 if (hidEvent.value && !((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false) )
1795 found = true; 1795 found = true;
1796 else if (!hidEvent.value && ((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false)) 1796 else if (!hidEvent.value && ((ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates & (1 << n)) ? true : false))
1797 found = true; 1797 found = true;
1798 1798
1799 if (hidEvent.value) 1799 if (hidEvent.value)
1800 ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates |= (1 << n); 1800 ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates |= (1 << n);
1801 else 1801 else
1802 ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates &= ~(1 << n); 1802 ActiveJoysticks[joystick].persistentData.JoystickEvent.ButtonStates &= ~(1 << n);
1803 } 1803 }
1804 }//button check 1804 }//button check
1805 //still ToDo..will be done soon :) 1805 //still ToDo..will be done soon :)
1806/* 1806/*
1807 for (u32 n = 0; n < ActiveJoysticks[joystick].hatComp.size(); n++) 1807 for (u32 n = 0; n < ActiveJoysticks[joystick].hatComp.size(); n++)
1808 { 1808 {
1809 IOReturn result = kIOReturnSuccess; 1809 IOReturn result = kIOReturnSuccess;
1810 IOHIDEventStruct hidEvent; 1810 IOHIDEventStruct hidEvent;
1811 hidEvent.value = 0; 1811 hidEvent.value = 0;
1812 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].hatComp[n].cookie, &hidEvent); 1812 result = (*(ActiveJoysticks[joystick].interface))->getElementValue(ActiveJoysticks[joystick].interface, ActiveJoysticks[joystick].hatComp[n].cookie, &hidEvent);
1813 if (kIOReturnSuccess == result) 1813 if (kIOReturnSuccess == result)
1814 { 1814 {
1815 if (ActiveJoysticks[joystick].persistentData.JoystickEvent.POV != hidEvent.value) 1815 if (ActiveJoysticks[joystick].persistentData.JoystickEvent.POV != hidEvent.value)
1816 found = true; 1816 found = true;
1817 ActiveJoysticks[joystick].persistentData.JoystickEvent.POV = hidEvent.value; 1817 ActiveJoysticks[joystick].persistentData.JoystickEvent.POV = hidEvent.value;
1818 } 1818 }
1819 }//hat check 1819 }//hat check
1820*/ 1820*/
1821 } 1821 }
1822 1822
1823 if (found) 1823 if (found)
1824 postEventFromUser(ActiveJoysticks[joystick].persistentData); 1824 postEventFromUser(ActiveJoysticks[joystick].persistentData);
1825 } 1825 }
1826#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_ 1826#endif // _IRR_COMPILE_WITH_JOYSTICK_EVENTS_
1827} 1827}
1828 1828
1829video::IVideoModeList* CIrrDeviceMacOSX::getVideoModeList() 1829video::IVideoModeList* CIrrDeviceMacOSX::getVideoModeList()
1830{ 1830{
1831 if (!VideoModeList.getVideoModeCount()) 1831 if (!VideoModeList.getVideoModeCount())
1832 { 1832 {
1833 CGDirectDisplayID display; 1833 CGDirectDisplayID display;
1834 display = CGMainDisplayID(); 1834 display = CGMainDisplayID();
1835 1835
1836#ifdef __MAC_10_6 1836#ifdef __MAC_10_6
1837 CFArrayRef Modes = CGDisplayCopyAllDisplayModes(display, NULL); 1837 CFArrayRef Modes = CGDisplayCopyAllDisplayModes(display, NULL);
1838 1838
1839 for(int i = 0; i < CFArrayGetCount(Modes); ++i) 1839 for(int i = 0; i < CFArrayGetCount(Modes); ++i)
1840 { 1840 {
1841 CGDisplayModeRef CurrentMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(Modes, i); 1841 CGDisplayModeRef CurrentMode = (CGDisplayModeRef)CFArrayGetValueAtIndex(Modes, i);
1842 1842
1843 u8 Depth = 0; 1843 u8 Depth = 0;
1844 1844
1845 CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(CurrentMode); 1845 CFStringRef pixEnc = CGDisplayModeCopyPixelEncoding(CurrentMode);
1846 1846
1847 if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 1847 if(CFStringCompare(pixEnc, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
1848 Depth = 32; 1848 Depth = 32;
1849 else 1849 else
1850 if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 1850 if(CFStringCompare(pixEnc, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
1851 Depth = 16; 1851 Depth = 16;
1852 else 1852 else
1853 if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo) 1853 if(CFStringCompare(pixEnc, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
1854 Depth = 8; 1854 Depth = 8;
1855 1855
1856 if(Depth) 1856 if(Depth)
1857 { 1857 {
1858 unsigned int Width = CGDisplayModeGetWidth(CurrentMode); 1858 unsigned int Width = CGDisplayModeGetWidth(CurrentMode);
1859 unsigned int Height = CGDisplayModeGetHeight(CurrentMode); 1859 unsigned int Height = CGDisplayModeGetHeight(CurrentMode);
1860 1860
1861 VideoModeList.addMode(core::dimension2d<u32>(Width, Height), Depth); 1861 VideoModeList.addMode(core::dimension2d<u32>(Width, Height), Depth);
1862 } 1862 }
1863 } 1863 }
1864#else 1864#else
1865 CFArrayRef availableModes = CGDisplayAvailableModes(display); 1865 CFArrayRef availableModes = CGDisplayAvailableModes(display);
1866 unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes); 1866 unsigned int numberOfAvailableModes = CFArrayGetCount(availableModes);
1867 for (u32 i= 0; i<numberOfAvailableModes; ++i) 1867 for (u32 i= 0; i<numberOfAvailableModes; ++i)
1868 { 1868 {
1869 // look at each mode in the available list 1869 // look at each mode in the available list
1870 CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, i); 1870 CFDictionaryRef mode = (CFDictionaryRef)CFArrayGetValueAtIndex(availableModes, i);
1871 long bitsPerPixel = GetDictionaryLong(mode, kCGDisplayBitsPerPixel); 1871 long bitsPerPixel = GetDictionaryLong(mode, kCGDisplayBitsPerPixel);
1872 Boolean safeForHardware = GetDictionaryBoolean(mode, kCGDisplayModeIsSafeForHardware); 1872 Boolean safeForHardware = GetDictionaryBoolean(mode, kCGDisplayModeIsSafeForHardware);
1873 Boolean stretched = GetDictionaryBoolean(mode, kCGDisplayModeIsStretched); 1873 Boolean stretched = GetDictionaryBoolean(mode, kCGDisplayModeIsStretched);
1874 1874
1875 if (!safeForHardware) 1875 if (!safeForHardware)
1876 continue; 1876 continue;
1877 1877
1878 long width = GetDictionaryLong(mode, kCGDisplayWidth); 1878 long width = GetDictionaryLong(mode, kCGDisplayWidth);
1879 long height = GetDictionaryLong(mode, kCGDisplayHeight); 1879 long height = GetDictionaryLong(mode, kCGDisplayHeight);
1880 // long refresh = GetDictionaryLong((mode), kCGDisplayRefreshRate); 1880 // long refresh = GetDictionaryLong((mode), kCGDisplayRefreshRate);
1881 VideoModeList.addMode(core::dimension2d<u32>(width, height), 1881 VideoModeList.addMode(core::dimension2d<u32>(width, height),
1882 bitsPerPixel); 1882 bitsPerPixel);
1883 } 1883 }
1884#endif 1884#endif
1885 } 1885 }
1886 return &VideoModeList; 1886 return &VideoModeList;
1887} 1887}
1888 1888
1889} // end namespace 1889} // end namespace
1890 1890
1891#endif // _IRR_COMPILE_WITH_OSX_DEVICE_ 1891#endif // _IRR_COMPILE_WITH_OSX_DEVICE_
1892 1892