Mercurial > sdl-ios-xcode
view src/video/cocoa/SDL_cocoaevents.m @ 3097:0d12e8f1de3c
Date: Thu, 05 Feb 2009 18:07:35 +0100
From: Stefan Klug
Subject: [SDL] SDL 1.3 WinCE backend
as promised, I've started to work on the WinCE backend of SDL 1.3
I've modified the win32 video backend and the gdi renderer, to work
properly in WinCE.
The results till now are great, but there is still some work to do.
Attached are two patches with my changes.
I would be happy if someone could review and propably commit them.
The first one (configure.in.patch) should be straight forward without
any side effects.
The second one does the necessary changes to the win32 backend. I was
really unhappy to start slicing this shiny new backend with
#ifdef/#endif but I saw no other option.
The most problematic issues are:
- WinCe has no GetDIBits, so its practically impossible to fill a
BITMAPINFO with correct values. I therefore removed the bmi member from
the GDI_RenderData in SDL_gdirender.c to prevent usage of a not or not
properly initialized bmi.
- In SDL_win32window.c I exchanged some ASCII function by their general
counterparts, (In CE only the Unicode versions are available). I don't
know if this has a negative effect when running in win32
Cheers
Stefan
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 23 Mar 2009 05:35:21 +0000 |
parents | 54fac87e1f34 |
children | 1282a042d530 |
line wrap: on
line source
/* SDL - Simple DirectMedia Layer Copyright (C) 1997-2009 Sam Lantinga This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Sam Lantinga slouken@libsdl.org */ #include "SDL_config.h" #include "SDL_cocoavideo.h" #include "../../events/SDL_events_c.h" /* setAppleMenu disappeared from the headers in 10.4 */ #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4 @interface NSApplication(NSAppleMenu) - (void)setAppleMenu:(NSMenu *)menu; @end #endif @implementation NSApplication(SDL) - (void)setRunning { _running = 1; } @end @interface SDLAppDelegate : NSObject - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender; @end @implementation SDLAppDelegate : NSObject - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { SDL_SendQuit(); return NSTerminateCancel; } @end static NSString * GetApplicationName(void) { NSDictionary *dict; NSString *appName = 0; /* Determine the application name */ dict = (NSDictionary *)CFBundleGetInfoDictionary(CFBundleGetMainBundle()); if (dict) appName = [dict objectForKey: @"CFBundleName"]; if (![appName length]) appName = [[NSProcessInfo processInfo] processName]; return appName; } static void CreateApplicationMenus(void) { NSString *appName; NSString *title; NSMenu *appleMenu; NSMenu *windowMenu; NSMenuItem *menuItem; /* Create the main menu bar */ [NSApp setMainMenu:[[NSMenu alloc] init]]; /* Create the application menu */ appName = GetApplicationName(); appleMenu = [[NSMenu alloc] initWithTitle:@""]; /* Add menu items */ title = [@"About " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(orderFrontStandardAboutPanel:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; title = [@"Hide " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(hide:) keyEquivalent:@/*"h"*/""]; menuItem = (NSMenuItem *)[appleMenu addItemWithTitle:@"Hide Others" action:@selector(hideOtherApplications:) keyEquivalent:@/*"h"*/""]; [menuItem setKeyEquivalentModifierMask:(NSAlternateKeyMask|NSCommandKeyMask)]; [appleMenu addItemWithTitle:@"Show All" action:@selector(unhideAllApplications:) keyEquivalent:@""]; [appleMenu addItem:[NSMenuItem separatorItem]]; title = [@"Quit " stringByAppendingString:appName]; [appleMenu addItemWithTitle:title action:@selector(terminate:) keyEquivalent:@/*"q"*/""]; /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"" action:nil keyEquivalent:@""]; [menuItem setSubmenu:appleMenu]; [[NSApp mainMenu] addItem:menuItem]; [menuItem release]; /* Tell the application object that this is now the application menu */ [NSApp setAppleMenu:appleMenu]; [appleMenu release]; /* Create the window menu */ windowMenu = [[NSMenu alloc] initWithTitle:@"Window"]; /* "Minimize" item */ menuItem = [[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@/*"m"*/""]; [windowMenu addItem:menuItem]; [menuItem release]; /* Put menu into the menubar */ menuItem = [[NSMenuItem alloc] initWithTitle:@"Window" action:nil keyEquivalent:@""]; [menuItem setSubmenu:windowMenu]; [[NSApp mainMenu] addItem:menuItem]; [menuItem release]; /* Tell the application object that this is now the window menu */ [NSApp setWindowsMenu:windowMenu]; [windowMenu release]; } void Cocoa_RegisterApp(void) { ProcessSerialNumber psn; NSAutoreleasePool *pool; if (!GetCurrentProcess(&psn)) { TransformProcessType(&psn, kProcessTransformToForegroundApplication); SetFrontProcess(&psn); } pool = [[NSAutoreleasePool alloc] init]; if (NSApp == nil) { [NSApplication sharedApplication]; if ([NSApp mainMenu] == nil) { CreateApplicationMenus(); } [NSApp finishLaunching]; } if ([NSApp delegate] == nil) { [NSApp setDelegate:[[SDLAppDelegate alloc] init]]; } [NSApp setRunning]; [pool release]; } void Cocoa_PumpEvents(_THIS) { NSAutoreleasePool *pool; /* Update activity every 30 seconds to prevent screensaver */ if (_this->suspend_screensaver) { SDL_VideoData *data = (SDL_VideoData *)_this->driverdata; Uint32 now = SDL_GetTicks(); if (!data->screensaver_activity || (int)(now-data->screensaver_activity) >= 30000) { UpdateSystemActivity(UsrActivity); data->screensaver_activity = now; } } pool = [[NSAutoreleasePool alloc] init]; while ([NSApp isRunning]) { NSEvent *event = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:NSDefaultRunLoopMode dequeue:YES ]; if ( event == nil ) { break; } switch ([event type]) { case NSKeyDown: case NSKeyUp: case NSFlagsChanged: Cocoa_HandleKeyEvent(_this, event); /* Fall through to pass event to NSApp; er, nevermind... */ /* FIXME: Find a way to stop the beeping, using delegate */ break; default: [NSApp sendEvent:event]; break; } } [pool release]; } /* vi: set ts=4 sw=4 expandtab: */