Commit 8a0a5544 authored by bitplane's avatar bitplane

adapted OSX device code style to Irrlicht's rather than Cocoa's. Initial...

adapted OSX device code style to Irrlicht's rather than Cocoa's. Initial attempt at software driver support, isn't refreshing each frame yet

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2227 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 96ae0085
...@@ -122,13 +122,9 @@ int main() ...@@ -122,13 +122,9 @@ int main()
dimensions, etc. dimensions, etc.
*/ */
IrrlichtDevice *device = IrrlichtDevice *device =
#ifdef _IRR_OSX_PLATFORM_
createDevice( video::EDT_OPENGL, dimension2d<u32>(640, 480), 16,
false, false, false, 0);
#else
createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16, createDevice( video::EDT_SOFTWARE, dimension2d<u32>(640, 480), 16,
false, false, false, 0); false, false, false, 0);
#endif
if (!device) if (!device)
return 1; return 1;
......
...@@ -48,6 +48,14 @@ ...@@ -48,6 +48,14 @@
_quit = TRUE; _quit = TRUE;
} }
- (NSSize)windowWillResize:(NSWindow *)window toSize:(NSSize)proposedFrameSize
{
if (_device->isResizeAble())
return proposedFrameSize;
else
return [window frame].size;
}
- (void)windowDidResize:(NSNotification *)aNotification - (void)windowDidResize:(NSNotification *)aNotification
{ {
NSWindow *window; NSWindow *window;
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
#include <OpenGL/OpenGL.h> #include <OpenGL/OpenGL.h>
#include <map> #include <map>
class NSWindow;
class NSOpenGLContext;
class NSBitmapImageRep;
namespace irr namespace irr
{ {
class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter class CIrrDeviceMacOSX : public CIrrDeviceStub, video::IImagePresenter
...@@ -58,9 +62,12 @@ namespace irr ...@@ -58,9 +62,12 @@ namespace irr
//! notifies the device that it should close itself //! notifies the device that it should close itself
virtual void closeDevice(); virtual void closeDevice();
//! Sets if the window should be resizeable in windowed mode. //! Sets if the window should be resizable in windowed mode.
virtual void setResizeAble(bool resize); virtual void setResizeAble(bool resize);
//! Returns true if the window is resizable, false if not
virtual bool isResizeAble() const;
//! Activate any joysticks, and generate events for them. //! Activate any joysticks, and generate events for them.
virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo); virtual bool activateJoysticks(core::array<SJoystickInfo> & joystickInfo);
...@@ -83,18 +90,21 @@ namespace irr ...@@ -83,18 +90,21 @@ namespace irr
{ {
public: public:
CCursorControl(const core::dimension2d<u32>& wsize, CIrrDeviceMacOSX *device) : WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), _device(device), UseReferenceRect(false) CCursorControl(const core::dimension2d<u32>& wsize, CIrrDeviceMacOSX *device)
: WindowSize(wsize), IsVisible(true), InvWindowSize(0.0f, 0.0f), Device(device), UseReferenceRect(false)
{ {
CursorPos.X = CursorPos.Y = 0; CursorPos.X = CursorPos.Y = 0;
if (WindowSize.Width!=0) InvWindowSize.Width = 1.0f / WindowSize.Width; if (WindowSize.Width!=0)
if (WindowSize.Height!=0) InvWindowSize.Height = 1.0f / WindowSize.Height; InvWindowSize.Width = 1.0f / WindowSize.Width;
if (WindowSize.Height!=0)
InvWindowSize.Height = 1.0f / WindowSize.Height;
} }
//! Changes the visible state of the mouse cursor. //! Changes the visible state of the mouse cursor.
virtual void setVisible(bool visible) virtual void setVisible(bool visible)
{ {
IsVisible = visible; IsVisible = visible;
_device->setCursorVisible(visible); Device->setCursorVisible(visible);
} }
//! Returns if the cursor is currently visible. //! Returns if the cursor is currently visible.
...@@ -127,11 +137,11 @@ namespace irr ...@@ -127,11 +137,11 @@ namespace irr
{ {
if (UseReferenceRect) if (UseReferenceRect)
{ {
_device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y); Device->setMouseLocation(ReferenceRect.UpperLeftCorner.X + x, ReferenceRect.UpperLeftCorner.Y + y);
} }
else else
{ {
_device->setMouseLocation(x,y); Device->setMouseLocation(x,y);
} }
} }
...@@ -187,7 +197,7 @@ namespace irr ...@@ -187,7 +197,7 @@ namespace irr
core::dimension2d<s32> WindowSize; core::dimension2d<s32> WindowSize;
core::dimension2d<float> InvWindowSize; core::dimension2d<float> InvWindowSize;
core::rect<s32> ReferenceRect; core::rect<s32> ReferenceRect;
CIrrDeviceMacOSX *_device; CIrrDeviceMacOSX *Device;
bool IsVisible; bool IsVisible;
bool UseReferenceRect; bool UseReferenceRect;
}; };
...@@ -195,23 +205,25 @@ namespace irr ...@@ -195,23 +205,25 @@ namespace irr
bool createWindow(); bool createWindow();
void initKeycodes(); void initKeycodes();
void storeMouseLocation(); void storeMouseLocation();
void postMouseEvent(void *event,irr::SEvent &ievent); void postMouseEvent(void *event, irr::SEvent &ievent);
void postKeyEvent(void *event,irr::SEvent &ievent,bool pressed); void postKeyEvent(void *event, irr::SEvent &ievent, bool pressed);
void *_window;
CGLContextObj _cglcontext;
void *_oglcontext;
int _width,
_height;
std::map<int,int> _keycodes;
int _screenWidth,
_screenHeight;
bool _active;
bool IsShiftDown,
IsControlDown;
u32 MouseButtonStates;
void pollJoysticks(); void pollJoysticks();
NSWindow *Window;
CGLContextObj CGLContext;
NSOpenGLContext *OGLContext;
int DeviceWidth,
DeviceHeight;
std::map<int,int> KeyCodes;
int ScreenWidth,
ScreenHeight;
bool IsActive;
NSBitmapImageRep *SoftwareDriverTarget;
bool IsSoftwareRenderer,
IsShiftDown,
IsControlDown,
IsResizable;
u32 MouseButtonStates;
}; };
......
...@@ -20,7 +20,10 @@ ...@@ -20,7 +20,10 @@
#include <stdio.h> #include <stdio.h>
#include <sys/utsname.h> #include <sys/utsname.h>
#include "COSOperator.h" #include "COSOperator.h"
#include "irrlicht.h" #include "CColorConverter.h"
#include "Irrlicht.h"
#import <wchar.h> #import <wchar.h>
#import <time.h> #import <time.h>
#import "AppDelegate.h" #import "AppDelegate.h"
...@@ -333,7 +336,8 @@ namespace irr ...@@ -333,7 +336,8 @@ namespace irr
{ {
//! constructor //! constructor
CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
: CIrrDeviceStub(param), _window(NULL), _active(true), _oglcontext(NULL), _cglcontext(NULL), : CIrrDeviceStub(param), Window(NULL), IsActive(true), OGLContext(NULL), CGLContext(NULL),
SoftwareDriverTarget(0), IsSoftwareRenderer(false), IsResizable(false),
IsShiftDown(false), IsControlDown(false), MouseButtonStates(0) IsShiftDown(false), IsControlDown(false), MouseButtonStates(0)
{ {
struct utsname name; struct utsname name;
...@@ -369,6 +373,12 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param) ...@@ -369,6 +373,12 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
CursorControl = new CCursorControl(CreationParams.WindowSize, this); CursorControl = new CCursorControl(CreationParams.WindowSize, this);
createDriver(); createDriver();
if (IsSoftwareRenderer && CreationParams.DriverType != video::EDT_NULL)
{
// create context for rendering raw bitmap
}
createGUIAndScene(); createGUIAndScene();
} }
...@@ -387,33 +397,33 @@ CIrrDeviceMacOSX::~CIrrDeviceMacOSX() ...@@ -387,33 +397,33 @@ CIrrDeviceMacOSX::~CIrrDeviceMacOSX()
void CIrrDeviceMacOSX::closeDevice() void CIrrDeviceMacOSX::closeDevice()
{ {
if (_window != NULL) if (Window != NULL)
{ {
[(NSWindow *)_window setIsVisible:FALSE]; [Window setIsVisible:FALSE];
if (_oglcontext != NULL) if (OGLContext != NULL)
{ {
[(NSOpenGLContext *)_oglcontext clearDrawable]; [OGLContext clearDrawable];
[(NSOpenGLContext *)_oglcontext release]; [OGLContext release];
_oglcontext = NULL; OGLContext = NULL;
} }
[(NSWindow *)_window setReleasedWhenClosed:TRUE]; [Window setReleasedWhenClosed:TRUE];
[(NSWindow *)_window release]; [Window release];
_window = NULL; Window = NULL;
} }
else else
{ {
if (_cglcontext != NULL) if (CGLContext != NULL)
{ {
CGLSetCurrentContext(NULL); CGLSetCurrentContext(NULL);
CGLClearDrawable(_cglcontext); CGLClearDrawable(CGLContext);
CGLDestroyContext(_cglcontext); CGLDestroyContext(CGLContext);
} }
} }
_active = FALSE; IsActive = false;
_cglcontext = NULL; CGLContext = NULL;
} }
bool CIrrDeviceMacOSX::createWindow() bool CIrrDeviceMacOSX::createWindow()
...@@ -424,8 +434,8 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -424,8 +434,8 @@ bool CIrrDeviceMacOSX::createWindow()
CGLPixelFormatObj pixelFormat; CGLPixelFormatObj pixelFormat;
CGRect displayRect; CGRect displayRect;
CGLPixelFormatAttribute fullattribs[32]; CGLPixelFormatAttribute fullattribs[32];
CFDictionaryRef displaymode,olddisplaymode; CFDictionaryRef displaymode, olddisplaymode;
GLint numPixelFormats,newSwapInterval; GLint numPixelFormats, newSwapInterval;
int alphaSize = CreationParams.WithAlphaChannel?4:0, depthSize = CreationParams.ZBufferBits; int alphaSize = CreationParams.WithAlphaChannel?4:0, depthSize = CreationParams.ZBufferBits;
if (CreationParams.WithAlphaChannel && (CreationParams.Bits == 32)) if (CreationParams.WithAlphaChannel && (CreationParams.Bits == 32))
...@@ -433,15 +443,15 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -433,15 +443,15 @@ bool CIrrDeviceMacOSX::createWindow()
result = false; result = false;
display = CGMainDisplayID(); display = CGMainDisplayID();
_screenWidth = (int) CGDisplayPixelsWide(display); ScreenWidth = (int) CGDisplayPixelsWide(display);
_screenHeight = (int) CGDisplayPixelsHigh(display); ScreenHeight = (int) CGDisplayPixelsHigh(display);
VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(_screenWidth, _screenHeight)); VideoModeList.setDesktop(CreationParams.Bits, core::dimension2d<u32>(ScreenWidth, ScreenHeight));
if (!CreationParams.Fullscreen) if (!CreationParams.Fullscreen)
{ {
_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE]; Window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,CreationParams.WindowSize.Width,CreationParams.WindowSize.Height) styleMask:NSTitledWindowMask+NSClosableWindowMask+NSResizableWindowMask backing:NSBackingStoreBuffered defer:FALSE];
if (_window != NULL) if (Window != NULL)
{ {
NSOpenGLPixelFormatAttribute windowattribs[] = NSOpenGLPixelFormatAttribute windowattribs[] =
{ {
...@@ -459,7 +469,7 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -459,7 +469,7 @@ bool CIrrDeviceMacOSX::createWindow()
if (CreationParams.AntiAlias<2) if (CreationParams.AntiAlias<2)
{ {
windowattribs[9] = (NSOpenGLPixelFormatAttribute)0; windowattribs[ 9] = (NSOpenGLPixelFormatAttribute)0;
windowattribs[11] = (NSOpenGLPixelFormatAttribute)0; windowattribs[11] = (NSOpenGLPixelFormatAttribute)0;
} }
...@@ -493,6 +503,7 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -493,6 +503,7 @@ bool CIrrDeviceMacOSX::createWindow()
windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1); windowattribs[12] = (NSOpenGLPixelFormatAttribute)((int)windowattribs[12]-1);
format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs]; format = [[NSOpenGLPixelFormat alloc] initWithAttributes:windowattribs];
} }
if (!format) if (!format)
{ {
windowattribs[9] = (NSOpenGLPixelFormatAttribute)0; windowattribs[9] = (NSOpenGLPixelFormatAttribute)0;
...@@ -515,27 +526,27 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -515,27 +526,27 @@ bool CIrrDeviceMacOSX::createWindow()
else else
break; break;
} }
CreationParams.AntiAlias=windowattribs[11]; CreationParams.AntiAlias = windowattribs[11];
CreationParams.Stencilbuffer=(windowattribs[13]==1); CreationParams.Stencilbuffer=(windowattribs[13]==1);
if (format != NULL) if (format != NULL)
{ {
_oglcontext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL]; OGLContext = [[NSOpenGLContext alloc] initWithFormat:format shareContext:NULL];
[format release]; [format release];
} }
if (_oglcontext != NULL) if (OGLContext != NULL)
{ {
[(NSWindow *)_window center]; [Window center];
[(NSWindow *)_window setDelegate:[NSApp delegate]]; [Window setDelegate:[NSApp delegate]];
[(NSOpenGLContext *)_oglcontext setView:[(NSWindow *)_window contentView]]; [OGLContext setView:[Window contentView]];
[(NSWindow *)_window setAcceptsMouseMovedEvents:TRUE]; [Window setAcceptsMouseMovedEvents:TRUE];
[(NSWindow *)_window setIsVisible:TRUE]; [Window setIsVisible:TRUE];
[(NSWindow *)_window makeKeyAndOrderFront:nil]; [Window makeKeyAndOrderFront:nil];
_cglcontext = (CGLContextObj) [(NSOpenGLContext *)_oglcontext CGLContextObj]; CGLContext = (CGLContextObj) [OGLContext CGLContextObj];
_width = CreationParams.WindowSize.Width; DeviceWidth = CreationParams.WindowSize.Width;
_height = CreationParams.WindowSize.Height; DeviceHeight = CreationParams.WindowSize.Height;
result = true; result = true;
} }
} }
...@@ -587,16 +598,16 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -587,16 +598,16 @@ bool CIrrDeviceMacOSX::createWindow()
if (pixelFormat != NULL) if (pixelFormat != NULL)
{ {
CGLCreateContext(pixelFormat,NULL,&_cglcontext); CGLCreateContext(pixelFormat,NULL,&CGLContext);
CGLDestroyPixelFormat(pixelFormat); CGLDestroyPixelFormat(pixelFormat);
} }
if (_cglcontext != NULL) if (CGLContext != NULL)
{ {
CGLSetFullScreen(_cglcontext); CGLSetFullScreen(CGLContext);
displayRect = CGDisplayBounds(display); displayRect = CGDisplayBounds(display);
_screenWidth = _width = (int)displayRect.size.width; ScreenWidth = DeviceWidth = (int)displayRect.size.width;
_screenHeight = _height = (int)displayRect.size.height; ScreenHeight = DeviceHeight = (int)displayRect.size.height;
result = true; result = true;
} }
} }
...@@ -606,12 +617,12 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -606,12 +617,12 @@ bool CIrrDeviceMacOSX::createWindow()
if (result) if (result)
{ {
if (_window == NULL) if (Window == NULL)
SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar); SetSystemUIMode(kUIModeAllHidden, kUIOptionAutoShowMenuBar);
CGLSetCurrentContext(_cglcontext); CGLSetCurrentContext(CGLContext);
newSwapInterval = (CreationParams.Vsync) ? 1 : 0; newSwapInterval = (CreationParams.Vsync) ? 1 : 0;
CGLSetParameter(_cglcontext,kCGLCPSwapInterval,&newSwapInterval); CGLSetParameter(CGLContext,kCGLCPSwapInterval,&newSwapInterval);
glViewport(0,0,_width,_height); glViewport(0,0,DeviceWidth,DeviceHeight);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
...@@ -624,14 +635,14 @@ bool CIrrDeviceMacOSX::createWindow() ...@@ -624,14 +635,14 @@ bool CIrrDeviceMacOSX::createWindow()
void CIrrDeviceMacOSX::setResize(int width, int height) void CIrrDeviceMacOSX::setResize(int width, int height)
{ {
// set new window size // set new window size
_width = width; DeviceWidth = width;
_height = height; DeviceHeight = height;
// update the size of the opengl rendering context // update the size of the opengl rendering context
[(NSOpenGLContext *)_oglcontext update]; [OGLContext update];
// resize the driver to the inner pane size // resize the driver to the inner pane size
NSRect driverFrame = [(NSWindow*)_window contentRectForFrameRect:[(NSWindow*)_window frame]]; NSRect driverFrame = [Window contentRectForFrameRect:[Window frame]];
getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)driverFrame.size.width, (s32)driverFrame.size.height)); getVideoDriver()->OnResize(core::dimension2d<u32>( (s32)driverFrame.size.width, (s32)driverFrame.size.height));
} }
...@@ -642,6 +653,7 @@ void CIrrDeviceMacOSX::createDriver() ...@@ -642,6 +653,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_SOFTWARE: case video::EDT_SOFTWARE:
#ifdef _IRR_COMPILE_WITH_SOFTWARE_ #ifdef _IRR_COMPILE_WITH_SOFTWARE_
VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
IsSoftwareRenderer = true;
#else #else
os::Printer::log("No Software driver support compiled in.", ELL_ERROR); os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
#endif #endif
...@@ -650,6 +662,7 @@ void CIrrDeviceMacOSX::createDriver() ...@@ -650,6 +662,7 @@ void CIrrDeviceMacOSX::createDriver()
case video::EDT_BURNINGSVIDEO: case video::EDT_BURNINGSVIDEO:
#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_ #ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
VideoDriver = video::createSoftwareDriver2(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this); VideoDriver = video::createSoftwareDriver2(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
IsSoftwareRenderer = true;
#else #else
os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR); os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
#endif #endif
...@@ -676,14 +689,15 @@ void CIrrDeviceMacOSX::createDriver() ...@@ -676,14 +689,15 @@ void CIrrDeviceMacOSX::createDriver()
os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR); os::Printer::log("Unable to create video driver of unknown type.", ELL_ERROR);
break; break;
} }
} }
void CIrrDeviceMacOSX::flush() void CIrrDeviceMacOSX::flush()
{ {
if (_cglcontext != NULL) if (CGLContext != NULL)
{ {
glFinish(); glFinish();
CGLFlushDrawable(_cglcontext); CGLFlushDrawable(CGLContext);
} }
} }
...@@ -712,7 +726,7 @@ bool CIrrDeviceMacOSX::run() ...@@ -712,7 +726,7 @@ bool CIrrDeviceMacOSX::run()
case NSFlagsChanged: case NSFlagsChanged:
ievent.EventType = irr::EET_KEY_INPUT_EVENT; ievent.EventType = irr::EET_KEY_INPUT_EVENT;
ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask) != 0; ievent.KeyInput.Shift = ([(NSEvent *)event modifierFlags] & NSShiftKeyMask ) != 0;
ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0; ievent.KeyInput.Control = ([(NSEvent *)event modifierFlags] & NSControlKeyMask) != 0;
if (IsShiftDown != ievent.KeyInput.Shift) if (IsShiftDown != ievent.KeyInput.Shift)
...@@ -815,7 +829,7 @@ bool CIrrDeviceMacOSX::run() ...@@ -815,7 +829,7 @@ bool CIrrDeviceMacOSX::run()
pollJoysticks(); pollJoysticks();
return (![[NSApp delegate] isQuit] && _active); return (![[NSApp delegate] isQuit] && IsActive);
} }
//! Pause the current process for the minimum time allowed only to allow other processes to execute //! Pause the current process for the minimum time allowed only to allow other processes to execute
...@@ -851,33 +865,33 @@ void CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text) ...@@ -851,33 +865,33 @@ void CIrrDeviceMacOSX::setWindowCaption(const wchar_t* text)
size_t size; size_t size;
char title[1024]; char title[1024];
if (_window != NULL) if (Window != NULL)
{ {
size = wcstombs(title,text,1024); size = wcstombs(title,text,1024);
if (size == 1024) title[1023] = 0; if (size == 1024) title[1023] = 0;
[(NSWindow *)_window setTitle:[NSString stringWithCString:title length:size]]; [Window setTitle:[NSString stringWithCString:title length:size]];
} }
} }
bool CIrrDeviceMacOSX::isWindowActive() const bool CIrrDeviceMacOSX::isWindowActive() const
{ {
return (_active); return (IsActive);
} }
bool CIrrDeviceMacOSX::isWindowFocused() const bool CIrrDeviceMacOSX::isWindowFocused() const
{ {
if (_window != NULL) if (Window != NULL)
return [(NSWindow *)_window isKeyWindow]; return [Window isKeyWindow];
return false; return false;
} }
bool CIrrDeviceMacOSX::isWindowMinimized() const bool CIrrDeviceMacOSX::isWindowMinimized() const
{ {
if (_window != NULL) if (Window != NULL)
return [(NSWindow *)_window isMiniaturized]; return [Window isMiniaturized];
return false; return false;
} }
...@@ -897,8 +911,8 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed ...@@ -897,8 +911,8 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
skipCommand = false; skipCommand = false;
c = [str characterAtIndex:0]; c = [str characterAtIndex:0];
iter = _keycodes.find(c); iter = KeyCodes.find(c);
if (iter != _keycodes.end()) mkey = (*iter).second; if (iter != KeyCodes.end()) mkey = (*iter).second;
else else
{ {
// workaround for period character // workaround for period character
...@@ -906,7 +920,9 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed ...@@ -906,7 +920,9 @@ void CIrrDeviceMacOSX::postKeyEvent(void *event,irr::SEvent &ievent,bool pressed
{ {
mkey = irr::KEY_PERIOD; mkey = irr::KEY_PERIOD;
mchar = '.'; mchar = '.';
} else { }
else
{
cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding]; cStr = (unsigned char *)[str cStringUsingEncoding:NSWindowsCP1252StringEncoding];
if (cStr != NULL && strlen((char*)cStr) > 0) if (cStr != NULL && strlen((char*)cStr) > 0)
{ {
...@@ -944,10 +960,10 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent) ...@@ -944,10 +960,10 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
{ {
bool post = true; bool post = true;
if (_window != NULL) if (Window != NULL)
{ {
ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x; ievent.MouseInput.X = (int)[(NSEvent *)event locationInWindow].x;
ievent.MouseInput.Y = _height - (int)[(NSEvent *)event locationInWindow].y; ievent.MouseInput.Y = DeviceHeight - (int)[(NSEvent *)event locationInWindow].y;
if (ievent.MouseInput.Y < 0) if (ievent.MouseInput.Y < 0)
post = false; post = false;
...@@ -955,7 +971,7 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent) ...@@ -955,7 +971,7 @@ void CIrrDeviceMacOSX::postMouseEvent(void *event,irr::SEvent &ievent)
else else
{ {
ievent.MouseInput.X = (int)[NSEvent mouseLocation].x; ievent.MouseInput.X = (int)[NSEvent mouseLocation].x;
ievent.MouseInput.Y = _height - (int)[NSEvent mouseLocation].y; ievent.MouseInput.Y = DeviceHeight - (int)[NSEvent mouseLocation].y;
} }
if (post) if (post)
...@@ -971,17 +987,17 @@ void CIrrDeviceMacOSX::storeMouseLocation() ...@@ -971,17 +987,17 @@ void CIrrDeviceMacOSX::storeMouseLocation()
p = [NSEvent mouseLocation]; p = [NSEvent mouseLocation];
if (_window != NULL) if (Window != NULL)
{ {
p = [(NSWindow *)_window convertScreenToBase:p]; p = [Window convertScreenToBase:p];
x = (int)p.x; x = (int)p.x;
y = _height - (int)p.y; y = DeviceHeight - (int)p.y;
} }
else else
{ {
x = (int)p.x; x = (int)p.x;
y = (int)p.y; y = (int)p.y;
y -= (_screenHeight - _height); y -= (ScreenHeight - DeviceHeight);
} }
((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y); ((CCursorControl *)CursorControl)->updateInternalCursorPosition(x,y);
...@@ -993,18 +1009,18 @@ void CIrrDeviceMacOSX::setMouseLocation(int x,int y) ...@@ -993,18 +1009,18 @@ void CIrrDeviceMacOSX::setMouseLocation(int x,int y)
NSPoint p; NSPoint p;
CGPoint c; CGPoint c;
if (_window != NULL) if (Window != NULL)
{ {
// Irrlicht window exists // Irrlicht window exists
p.x = (float) x; p.x = (float) x;
p.y = (float) (_height - y); p.y = (float) (DeviceHeight - y);
p = [(NSWindow *)_window convertBaseToScreen:p]; p = [Window convertBaseToScreen:p];
p.y = _screenHeight - p.y; p.y = ScreenHeight - p.y;
} }
else else
{ {
p.x = (float) x; p.x = (float) x;
p.y = (float) y + (_screenHeight - _height); p.y = (float) y + (ScreenHeight - DeviceHeight);
} }
c.x = p.x; c.x = p.x;
...@@ -1028,42 +1044,42 @@ void CIrrDeviceMacOSX::setCursorVisible(bool visible) ...@@ -1028,42 +1044,42 @@ void CIrrDeviceMacOSX::setCursorVisible(bool visible)
void CIrrDeviceMacOSX::initKeycodes() void CIrrDeviceMacOSX::initKeycodes()
{ {
_keycodes[NSUpArrowFunctionKey] = irr::KEY_UP; KeyCodes[NSUpArrowFunctionKey] = irr::KEY_UP;
_keycodes[NSDownArrowFunctionKey] = irr::KEY_DOWN; KeyCodes[NSDownArrowFunctionKey] = irr::KEY_DOWN;
_keycodes[NSLeftArrowFunctionKey] = irr::KEY_LEFT; KeyCodes[NSLeftArrowFunctionKey] = irr::KEY_LEFT;
_keycodes[NSRightArrowFunctionKey] = irr::KEY_RIGHT; KeyCodes[NSRightArrowFunctionKey] = irr::KEY_RIGHT;
_keycodes[NSF1FunctionKey] = irr::KEY_F1; KeyCodes[NSF1FunctionKey] = irr::KEY_F1;
_keycodes[NSF2FunctionKey] = irr::KEY_F2; KeyCodes[NSF2FunctionKey] = irr::KEY_F2;
_keycodes[NSF3FunctionKey] = irr::KEY_F3; KeyCodes[NSF3FunctionKey] = irr::KEY_F3;
_keycodes[NSF4FunctionKey] = irr::KEY_F4; KeyCodes[NSF4FunctionKey] = irr::KEY_F4;
_keycodes[NSF5FunctionKey] = irr::KEY_F5; KeyCodes[NSF5FunctionKey] = irr::KEY_F5;
_keycodes[NSF6FunctionKey] = irr::KEY_F6; KeyCodes[NSF6FunctionKey] = irr::KEY_F6;
_keycodes[NSF7FunctionKey] = irr::KEY_F7; KeyCodes[NSF7FunctionKey] = irr::KEY_F7;
_keycodes[NSF8FunctionKey] = irr::KEY_F8; KeyCodes[NSF8FunctionKey] = irr::KEY_F8;
_keycodes[NSF9FunctionKey] = irr::KEY_F9; KeyCodes[NSF9FunctionKey] = irr::KEY_F9;
_keycodes[NSF10FunctionKey] = irr::KEY_F10; KeyCodes[NSF10FunctionKey] = irr::KEY_F10;
_keycodes[NSF11FunctionKey] = irr::KEY_F11; KeyCodes[NSF11FunctionKey] = irr::KEY_F11;
_keycodes[NSF12FunctionKey] = irr::KEY_F12; KeyCodes[NSF12FunctionKey] = irr::KEY_F12;
_keycodes[NSF13FunctionKey] = irr::KEY_F13; KeyCodes[NSF13FunctionKey] = irr::KEY_F13;
_keycodes[NSF14FunctionKey] = irr::KEY_F14; KeyCodes[NSF14FunctionKey] = irr::KEY_F14;
_keycodes[NSF15FunctionKey] = irr::KEY_F15; KeyCodes[NSF15FunctionKey] = irr::KEY_F15;
_keycodes[NSF16FunctionKey] = irr::KEY_F16; KeyCodes[NSF16FunctionKey] = irr::KEY_F16;
_keycodes[NSHomeFunctionKey] = irr::KEY_HOME; KeyCodes[NSHomeFunctionKey] = irr::KEY_HOME;
_keycodes[NSEndFunctionKey] = irr::KEY_END; KeyCodes[NSEndFunctionKey] = irr::KEY_END;
_keycodes[NSInsertFunctionKey] = irr::KEY_INSERT; KeyCodes[NSInsertFunctionKey] = irr::KEY_INSERT;
_keycodes[NSDeleteFunctionKey] = irr::KEY_DELETE; KeyCodes[NSDeleteFunctionKey] = irr::KEY_DELETE;
_keycodes[NSHelpFunctionKey] = irr::KEY_HELP; KeyCodes[NSHelpFunctionKey] = irr::KEY_HELP;
_keycodes[NSSelectFunctionKey] = irr::KEY_SELECT; KeyCodes[NSSelectFunctionKey] = irr::KEY_SELECT;
_keycodes[NSPrintFunctionKey] = irr::KEY_PRINT; KeyCodes[NSPrintFunctionKey] = irr::KEY_PRINT;
_keycodes[NSExecuteFunctionKey] = irr::KEY_EXECUT; KeyCodes[NSExecuteFunctionKey] = irr::KEY_EXECUT;
_keycodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT; KeyCodes[NSPrintScreenFunctionKey] = irr::KEY_SNAPSHOT;
_keycodes[NSPauseFunctionKey] = irr::KEY_PAUSE; KeyCodes[NSPauseFunctionKey] = irr::KEY_PAUSE;
_keycodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL; KeyCodes[NSScrollLockFunctionKey] = irr::KEY_SCROLL;
_keycodes[0x7F] = irr::KEY_BACK; KeyCodes[0x7F] = irr::KEY_BACK;
_keycodes[0x09] = irr::KEY_TAB; KeyCodes[0x09] = irr::KEY_TAB;
_keycodes[0x0D] = irr::KEY_RETURN; KeyCodes[0x0D] = irr::KEY_RETURN;
_keycodes[0x03] = irr::KEY_RETURN; KeyCodes[0x03] = irr::KEY_RETURN;
_keycodes[0x1B] = irr::KEY_ESCAPE; KeyCodes[0x1B] = irr::KEY_ESCAPE;
} }
...@@ -1071,35 +1087,78 @@ void CIrrDeviceMacOSX::initKeycodes() ...@@ -1071,35 +1087,78 @@ void CIrrDeviceMacOSX::initKeycodes()
//! Sets if the window should be resizeable in windowed mode. //! Sets if the window should be resizeable in windowed mode.
void CIrrDeviceMacOSX::setResizeAble(bool resize) void CIrrDeviceMacOSX::setResizeAble(bool resize)
{ {
// todo: Hacky method, clicking the bottom right corner freezes the window. IsResizable = resize;
// We can't set the resize flag without destroying the window, so we'll set the max size to the current size }
bool CIrrDeviceMacOSX::isResizeAble() const
{
return IsResizable;
}
if (!_window)
return;
NSSize s; bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )
{
// todo: implement window ID and src rectangle
if (!surface)
return false;
if (IsSoftwareRenderer)
{
// do we need to change the size?
bool updateSize = !SoftwareDriverTarget ||
s32([SoftwareDriverTarget size].width) != surface->getDimension().Width ||
s32([SoftwareDriverTarget size].height) != surface->getDimension().Height;
// release if necessary
if (SoftwareDriverTarget && updateSize)
[SoftwareDriverTarget release];
NSRect areaRect = NSMakeRect(0.0, 0.0, surface->getDimension().Width, surface->getDimension().Height);
// get pointer to image data
unsigned char* imgData = (unsigned char*)surface->lock();
if (resize) // create / update the target
if (updateSize)
{ {
s.width = 0.0f; // allocate target for IImage
s.height = 0.0f; SoftwareDriverTarget = [[NSBitmapImageRep alloc]
[(NSWindow *)_window setMinSize: s]; initWithBitmapDataPlanes: nil
s.width = float(_screenWidth); pixelsWide: areaRect.size.width
s.height = float(_screenHeight); pixelsHigh: areaRect.size.height
[(NSWindow *)_window setMaxSize: s]; bitsPerSample: 8
samplesPerPixel: 3
hasAlpha: NO
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: (3 * areaRect.size.width)
bitsPerPixel: 24];
} }
else
const u32 destwidth = areaRect.size.width;
const u32 minWidth = core::min_(surface->getDimension().Width, destwidth);
const u32 destPitch = (3 * areaRect.size.width);
u8* srcdata = reinterpret_cast<u8*>(imgData);
u8* destData = reinterpret_cast<u8*>([SoftwareDriverTarget bitmapData]);
const u32 destheight = areaRect.size.height;
const u32 srcheight = core::min_(surface->getDimension().Height, destheight);
const u32 srcPitch = surface->getPitch();
for (u32 y=0; y!=srcheight; ++y)
{ {
s = [(NSWindow *)_window frame].size; video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
[(NSWindow *)_window setMinSize: s]; srcdata += srcPitch;
[(NSWindow *)_window setMaxSize: s]; destData += destPitch;
} }
}
// unlock the data
surface->unlock();
// todo: draw properly into a sub-view
[SoftwareDriverTarget draw];
}
bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )
{
// todo: implement
return false; return false;
} }
...@@ -1186,7 +1245,7 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn ...@@ -1186,7 +1245,7 @@ bool CIrrDeviceMacOSX::activateJoysticks(core::array<SJoystickInfo> & joystickIn
(*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info); (*(info.interface))->setRemovalCallback (info.interface, joystickRemovalCallback, &info, &info);
getJoystickDeviceInfo(hidObject, hidProperties, &info); getJoystickDeviceInfo(hidObject, hidProperties, &info);
//get elements // get elements
CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey)); CFTypeRef refElementTop = CFDictionaryGetValue (hidProperties, CFSTR(kIOHIDElementKey));
if (refElementTop) if (refElementTop)
{ {
...@@ -1260,7 +1319,7 @@ void CIrrDeviceMacOSX::pollJoysticks() ...@@ -1260,7 +1319,7 @@ void CIrrDeviceMacOSX::pollJoysticks()
return; return;
u32 joystick; u32 joystick;
for(joystick = 0; joystick < ActiveJoysticks.size(); ++joystick) for (joystick = 0; joystick < ActiveJoysticks.size(); ++joystick)
{ {
if (ActiveJoysticks[joystick].removed) if (ActiveJoysticks[joystick].removed)
continue; continue;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment