]> git.lizzy.rs Git - irrlicht.git/blobdiff - source/Irrlicht/CIrrDeviceOSX.mm
SpriteBank: error check on non existing textureNumber
[irrlicht.git] / source / Irrlicht / CIrrDeviceOSX.mm
index dea86d9440b7939260e475f91f54e50ec5cba51e..4069cf1989439d15d85d4872312c38d34bd71a95 100644 (file)
@@ -4,7 +4,6 @@
 // This file is part of the "Irrlicht Engine".
 // For conditions of distribution and use, see copyright notice in Irrlicht.h
 
-#include "IrrCompileConfig.h"
 
 #ifdef _IRR_COMPILE_WITH_OSX_DEVICE_
 
@@ -14,7 +13,6 @@
 #include "CIrrDeviceOSX.h"
 
 #include "IEventReceiver.h"
-#include "irrList.h"
 #include "os.h"
 #include "CTimer.h"
 #include "irrString.h"
@@ -548,12 +546,11 @@ namespace irr
 //! constructor
 CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
        : CIrrDeviceStub(param), Window(NULL), Display(NULL),
-       SoftwareDriverTarget(0), DeviceWidth(0), DeviceHeight(0),
-       ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0), SoftwareRendererType(0),
+       DeviceWidth(0), DeviceHeight(0),
+       ScreenWidth(0), ScreenHeight(0), MouseButtonStates(0),
        IsActive(true), IsFullscreen(false), IsShiftDown(false), IsControlDown(false), IsResizable(false)
 {
        struct utsname name;
-       NSString *path;
 
 #ifdef _DEBUG
        setDebugName("CIrrDeviceMacOSX");
@@ -568,27 +565,31 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
                        [[NSAutoreleasePool alloc] init];
                        [[NSApplication sharedApplication] activateIgnoringOtherApps:YES];
                        [NSApp setDelegate:(id<NSApplicationDelegate>)[[[CIrrDelegateOSX alloc] initWithDevice:this] autorelease]];
-            
+
             // Create menu
-            
+
             NSString* bundleName = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleName"];
-            
+            if (bundleName == nil)
+                bundleName = @"Irrlicht";
+
             NSMenu* mainMenu = [[[NSMenu alloc] initWithTitle:@"MainMenu"] autorelease];
             NSMenu* menu = [[[NSMenu alloc] initWithTitle:bundleName] autorelease];
             NSMenuItem* menuItem = [mainMenu addItemWithTitle:bundleName action:nil keyEquivalent:@""];
             [mainMenu setSubmenu:menu forItem:menuItem];
             menuItem = [menu addItemWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"];
             [menuItem setKeyEquivalentModifierMask:NSCommandKeyMask];
-            
+
             [NSApp setMainMenu:mainMenu];
 
             [NSApp finishLaunching];
                }
 
-               path = [[NSBundle mainBundle] bundlePath];
-        path = [path stringByAppendingString:@"/Contents/Resources"];
-               chdir([path fileSystemRepresentation]);
-        [path release];
+               NSString *path = [[NSBundle mainBundle] bundlePath];
+               if (path != nil) {
+                       path = [path stringByAppendingString:@"/Contents/Resources"];
+                       chdir([path fileSystemRepresentation]);
+                       [path release];
+               }
        }
 
        uname(&name);
@@ -615,7 +616,6 @@ CIrrDeviceMacOSX::CIrrDeviceMacOSX(const SIrrlichtCreationParameters& param)
 
 CIrrDeviceMacOSX::~CIrrDeviceMacOSX()
 {
-       [SoftwareDriverTarget release];
        [NSApp setPresentationOptions:(NSApplicationPresentationDefault)];
        closeDevice();
 #if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
@@ -729,24 +729,6 @@ void CIrrDeviceMacOSX::createDriver()
 {
        switch (CreationParams.DriverType)
        {
-               case video::EDT_SOFTWARE:
-#ifdef _IRR_COMPILE_WITH_SOFTWARE_
-                       VideoDriver = video::createSoftwareDriver(CreationParams.WindowSize, CreationParams.Fullscreen, FileSystem, this);
-                       SoftwareRendererType = 2;
-#else
-                       os::Printer::log("No Software driver support compiled in.", ELL_ERROR);
-#endif
-                       break;
-
-               case video::EDT_BURNINGSVIDEO:
-#ifdef _IRR_COMPILE_WITH_BURNINGSVIDEO_
-                       VideoDriver = video::createBurningVideoDriver(CreationParams, FileSystem, this);
-                       SoftwareRendererType = 1;
-#else
-                       os::Printer::log("Burning's video driver was not compiled in.", ELL_ERROR);
-#endif
-                       break;
-
                case video::EDT_OPENGL:
 #ifdef _IRR_COMPILE_WITH_OPENGL_
             {
@@ -1170,9 +1152,8 @@ void CIrrDeviceMacOSX::setMouseLocation(int x,int y)
        c.x = p.x;
        c.y = p.y;
 
-    CGEventRef ev = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, c, kCGMouseButtonLeft);
-    CGEventPost(kCGHIDEventTap, ev);
-    CFRelease(ev);
+       CGWarpMouseCursorPosition(c);
+       CGAssociateMouseAndMouseCursorPosition(YES);
 }
 
 
@@ -1357,87 +1338,6 @@ core::position2di CIrrDeviceMacOSX::getWindowPosition()
 }
 
 
-
-bool CIrrDeviceMacOSX::present(video::IImage* surface, void* windowId, core::rect<s32>* src )
-{
-       // todo: implement window ID and src rectangle
-
-       if (!surface)
-               return false;
-
-       if (SoftwareRendererType > 0)
-       {
-               const u32 colorSamples=3;
-               // do we need to change the size?
-               const bool updateSize = !SoftwareDriverTarget ||
-                               s32([SoftwareDriverTarget size].width) != surface->getDimension().Width ||
-                               s32([SoftwareDriverTarget size].height) != surface->getDimension().Height;
-
-               NSRect areaRect = NSMakeRect(0.0, 0.0, surface->getDimension().Width, surface->getDimension().Height);
-               const u32 destPitch = (colorSamples * areaRect.size.width);
-
-               // create / update the target
-               if (updateSize)
-               {
-                       [SoftwareDriverTarget release];
-                       // allocate target for IImage
-                       SoftwareDriverTarget = [[NSBitmapImageRep alloc]
-                                       initWithBitmapDataPlanes: nil
-                                       pixelsWide: areaRect.size.width
-                                       pixelsHigh: areaRect.size.height
-                                       bitsPerSample: 8
-                                       samplesPerPixel: colorSamples
-                                       hasAlpha: NO
-                                       isPlanar: NO
-                                       colorSpaceName: NSCalibratedRGBColorSpace
-                                       bytesPerRow: destPitch
-                                       bitsPerPixel: 8*colorSamples];
-               }
-
-               if (SoftwareDriverTarget==nil)
-                       return false;
-
-               // get pointer to image data
-               unsigned char* imgData = (unsigned char*)surface->getData();
-
-               u8* srcdata = reinterpret_cast<u8*>(imgData);
-               u8* destData = reinterpret_cast<u8*>([SoftwareDriverTarget bitmapData]);
-               const u32 srcheight = core::min_(surface->getDimension().Height, (u32)areaRect.size.height);
-               const u32 srcPitch = surface->getPitch();
-               const u32 minWidth = core::min_(surface->getDimension().Width, (u32)areaRect.size.width);
-               for (u32 y=0; y!=srcheight; ++y)
-               {
-                       if(SoftwareRendererType == 2)
-                       {
-                               if (surface->getColorFormat() == video::ECF_A8R8G8B8)
-                                       video::CColorConverter::convert_A8R8G8B8toB8G8R8(srcdata, minWidth, destData);
-                               else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
-                                       video::CColorConverter::convert_A1R5G5B5toB8G8R8(srcdata, minWidth, destData);
-                               else
-                                       video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
-                       }
-                       else
-                       {
-                               if (surface->getColorFormat() == video::ECF_A8R8G8B8)
-                                       video::CColorConverter::convert_A8R8G8B8toR8G8B8(srcdata, minWidth, destData);
-                               else if (surface->getColorFormat() == video::ECF_A1R5G5B5)
-                                       video::CColorConverter::convert_A1R5G5B5toR8G8B8(srcdata, minWidth, destData);
-                               else
-                                       video::CColorConverter::convert_viaFormat(srcdata, surface->getColorFormat(), minWidth, destData, video::ECF_R8G8B8);
-                       }
-
-                       srcdata += srcPitch;
-                       destData += destPitch;
-               }
-
-               // todo: draw properly into a sub-view
-               [SoftwareDriverTarget draw];
-       }
-
-       return false;
-}
-
-
 #if defined (_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)
 static void joystickRemovalCallback(void * target,
                IOReturn result, void * refcon, void * sender)