Hello everyone –
I sent this to the original developer for the iPhone port of SDL, but
I haven’t heard from him in over a week now. So, instead of letting
this sit on my hard drive for a while, I figured I would toss it out
for anyone else that’s interested. The patch is against 1.2.12, and
it still requires the SDK changes that Richard had for his version
at http://iphone-sdl-mame.googlecode.com/
Here is a list of what I changed:
- SDL actually works out of the box -- the SVN repository doesn't
actually have the code to register the video bootstrap
- status bar is hidden (only for apps launched from the GUI)
- the SDL surface covers the entire screen now, instead of being
offset by around 20 pixels
- implemented locking, so there is no flicker now
I also have another version that implements mouse (finger) tracking,
but I don’t have a patch ready for that. Possibly in a few days,
I’ll have a new and improved patch with that and some more
functionality as well.
as a side note, if you want to play with this, only 16-bit color is
working right now. Anything else, and you’ll get a corrupted display.
dennis-------
diff -urpN SDL-1.2.12/README.iPhone SDL-1.2.12-iphone/README.iPhone
— SDL-1.2.12/README.iPhone 1969-12-31 19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/README.iPhone 2007-08-24 12:58:59.000000000 -0400
@@ -0,0 +1 @@
+Modified SDL 1.2.12 source for the iPhone. Run the patch or replace/
add the source files. Use ./configure --host=arm-apple-darwin –
prefix=/Developer/SDKs/iPhone/usr --enable-shared=no to configure
SDL. If you have a native SDL already installed you may run into
problems linking, although the provided arm-cc-specs file in iphone-
sdk is setup to avoid this problem. If all else fails, just
temporarily remove your native installation of SDL from /usr/local or
wherever you have it installed. Take a look at the README in iphone-
sdk for additional setup instructions.
\ No newline at end of file
diff -urpN SDL-1.2.12/configure SDL-1.2.12-iphone/configure
— SDL-1.2.12/configure 2007-07-20 01:53:43.000000000 -0400
+++ SDL-1.2.12-iphone/configure 2007-08-24 12:58:59.000000000 -0400
@@ -27784,7 +27784,7 @@ fi;
x11ext_lib=‘libXext.so’
;;
*)
-
x11_lib_spec=`echo $X_LIBS | sed 's/.*-L\([^ ]*
).*/\1/’`
-
x11_lib_path=`echo $X_LIBS | sed 's/.*-L\([^ ]*
)./\1/'for path in $x11_lib_path /usr/lib /usr/X11/ lib /usr/X11R6/lib; do if test "x$x11_lib" = "x"; then x11_lib=
ls – $path/libX11.so.[0-9] 2>/
dev/null | sort -r | sed 's/./(.)/\1/; q’`
@@ -33613,6 +33613,22 @@ _ACEOF
SOURCES="$srcdir/src/main/beos/.cc $SOURCES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -
ldevice -ltextencoding"
;;
- arm-apple-darwin*)
-
arch=iphone
-
cat >>confdefs.h <<\_ACEOF
+#define SDL_VIDEO_DRIVER_IPHONE 1
+_ACEOF
+
-
cat >>confdefs.h <<\_ACEOF
+#define SDL_TIMER_UNIX 1
+_ACEOF
+
-
SOURCES="$SOURCES $srcdir/src/video/iphone/*.m"
-
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
-
SDLMAIN_SOURCES="$srcdir/src/main/iphone/*.m"
-
SDL_LIBS="$SDL_LIBS -lSDLmain -lobjc -framework CoreFoundation -
framework UIKit -framework CoreGraphics -framework CoreSurface"
-
have_timers=yes
-
;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin"
which is
# just the OS X kernel sans upper layers like Carbon and
Cocoa.
diff -urpN SDL-1.2.12/configure.in SDL-1.2.12-iphone/configure.in
— SDL-1.2.12/configure.in 2007-07-20 04:32:39.000000000 -0400
+++ SDL-1.2.12-iphone/configure.in 2007-08-24 12:58:59.000000000 -0400
@@ -2498,6 +2498,16 @@ case “$host” in
SOURCES="$srcdir/src/main/beos/*.cc $SOURCES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -
ldevice -ltextencoding"
;;
- arm-apple-darwin*)
-
arch=iphone
-
AC_DEFINE(SDL_VIDEO_DRIVER_IPHONE)
-
AC_DEFINE(SDL_TIMER_UNIX)
-
SOURCES="$SOURCES $srcdir/src/video/iphone/*.m"
-
SOURCES="$SOURCES $srcdir/src/timer/unix/*.c"
-
SDLMAIN_SOURCES="$srcdir/src/main/iphone/*.m"
-
SDL_LIBS="$SDL_LIBS -lSDLmain -lobjc -framework CoreFoundation -
framework UIKit -framework CoreGraphics -framework CoreSurface"
-
have_timers=yes
-
;; *-*-darwin* ) # This could be either full "Mac OS X", or plain "Darwin"
which is
# just the OS X kernel sans upper layers like Carbon and
Cocoa.
diff -urpN SDL-1.2.12/include/SDL_config.h.in SDL-1.2.12-iphone/
include/SDL_config.h.in
— SDL-1.2.12/include/SDL_config.h.in 2007-07-20 01:52:44.000000000
-0400
+++ SDL-1.2.12-iphone/include/SDL_config.h.in 2007-08-24
12:58:59.000000000 -0400
@@ -263,6 +263,7 @@
#undef SDL_VIDEO_DRIVER_GEM
#undef SDL_VIDEO_DRIVER_GGI
#undef SDL_VIDEO_DRIVER_IPOD
+#undef SDL_VIDEO_DRIVER_IPHONE
#undef SDL_VIDEO_DRIVER_NANOX
#undef SDL_VIDEO_DRIVER_OS2FS
#undef SDL_VIDEO_DRIVER_PHOTON
diff -urpN SDL-1.2.12/src/main/iphone/SDL_iPhoneMain.m SDL-1.2.12-
iphone/src/main/iphone/SDL_iPhoneMain.m
— SDL-1.2.12/src/main/iphone/SDL_iPhoneMain.m 1969-12-31
19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/src/main/iphone/SDL_iPhoneMain.m 2007-08-24
13:01:12.000000000 -0400
@@ -0,0 +1,70 @@
+#import <UIKit/UIKit.h>
+#import <Foundation/NSThread.h>
+#include “…/…/video/iphone/SDL_iphonevideo.h”
+
- at interface SDL_iPhoneMain : UIApplication
+{ - UIWindow* _window;
- SDL_iPhoneView* _view;
+}
± (void) mainLoop: (id)param;
± (SDL_iPhoneView*) getView; - at end
+static int gArgc;
+static char** gArgv;
+
+int main(int argc, char** argv)
+{
- gArgc = argc;
- gArgv = argv;
- [[NSAutoreleasePool alloc] init];
- return UIApplicationMain(argc, argv, [SDL_iPhoneMain class]);
+}
+
- at implementation SDL_iPhoneMain
±(id) init
+{
- [super init];
- _window = nil;
- _view = nil;
- return self;
+}
± (void) mainLoop: (id)param
+{
- [[NSAutoreleasePool alloc] init];
- SDL_main (gArgc, gArgv);
- [UIApp terminate];
+}
± (SDL_iPhoneView*) getView
+{
- return _view;
+}
± (void)applicationDidFinishLaunching:(NSNotification *)aNotification
+{
- // hide the status bar
- [UIHardware _setStatusBarHeight:0.0f];
- [self setStatusBarMode:2 orientation:0 duration:0.0f fenceID:0];
- _window = [[UIWindow alloc] initWithContentRect: [UIHardware
fullScreenApplicationContentRect]]; - [_window retain];
- _view = [[SDL_iPhoneView alloc] initWithFrame: [UIHardware
fullScreenApplicationContentRect]]; - [_window setContentView: _view];
- [_window orderFront: self];
- [_window makeKey: self];
- [NSThread detachNewThreadSelector:@selector(mainLoop:)
toTarget:self withObject:nil];
+} - at end
diff -urpN SDL-1.2.12/src/video/SDL_sysvideo.h SDL-1.2.12-iphone/src/
video/SDL_sysvideo.h
— SDL-1.2.12/src/video/SDL_sysvideo.h 2007-07-20 01:52:25.000000000
-0400
+++ SDL-1.2.12-iphone/src/video/SDL_sysvideo.h 2007-08-24
13:04:44.000000000 -0400
@@ -404,6 +404,9 @@ extern VideoBootStrap OS2FSLib_bootstrap
#if SDL_VIDEO_DRIVER_AALIB
extern VideoBootStrap AALIB_bootstrap;
#endif
+#if SDL_VIDEO_DRIVER_IPHONE
+extern VideoBootStrap iPhone_bootstrap;
+#endif
#if SDL_VIDEO_DRIVER_DUMMY
extern VideoBootStrap DUMMY_bootstrap;
#endif
diff -urpN SDL-1.2.12/src/video/SDL_video.c SDL-1.2.12-iphone/src/
video/SDL_video.c
— SDL-1.2.12/src/video/SDL_video.c 2007-07-20 01:52:25.000000000 -0400
+++ SDL-1.2.12-iphone/src/video/SDL_video.c 2007-08-24
13:04:18.000000000 -0400
@@ -120,6 +120,9 @@ static VideoBootStrap *bootstrap[] = {
#if SDL_VIDEO_DRIVER_AALIB
&AALIB_bootstrap,
#endif
+#if SDL_VIDEO_DRIVER_IPHONE
- &iPhone_bootstrap,
+#endif
#if SDL_VIDEO_DRIVER_DUMMY
&DUMMY_bootstrap,
#endif
diff -urpN SDL-1.2.12/src/video/iphone/SDL_iphoneevents.h SDL-1.2.12-
iphone/src/video/iphone/SDL_iphoneevents.h
— SDL-1.2.12/src/video/iphone/SDL_iphoneevents.h 1969-12-31
19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/src/video/iphone/SDL_iphoneevents.h 2007-08-24
12:58:59.000000000 -0400
@@ -0,0 +1,33 @@
+/* - SDL - Simple DirectMedia Layer
- Copyright © 1997-2006 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 at libsdl.org
+*/
+#include “SDL_config.h”
+#include “SDL_iphonevideo.h”
+
+/* Variables and functions exported by SDL_sysevents.c to other parts
- of the native video subsystem (SDL_sysvideo.c)
+*/
+extern void iPhone_InitOSKeymap(_THIS);
+extern void iPhone_PumpEvents(_THIS);
+/* end of SDL_nullevents_c.h … /
+
diff -urpN SDL-1.2.12/src/video/iphone/SDL_iphoneevents.m SDL-1.2.12-
iphone/src/video/iphone/SDL_iphoneevents.m
— SDL-1.2.12/src/video/iphone/SDL_iphoneevents.m 1969-12-31
19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/src/video/iphone/SDL_iphoneevents.m 2007-08-24
12:58:59.000000000 -0400
@@ -0,0 +1,59 @@
+/
- SDL - Simple DirectMedia Layer
- Copyright © 1997-2006 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 at libsdl.org
+*/
+#include “SDL_config.h”
+#include “SDL.h”
+#include “…/…/events/SDL_sysevents.h”
+#include “…/…/events/SDL_events_c.h”
+
+#include “SDL_iphonevideo.h”
+#include “SDL_iphoneevents.h”
+
+#include <UIKit/UIKit.h>
+
+void iPhone_PumpEvents(_THIS)
+{
- NSArray* events = [[UIApp getView] getEvents];
- if(events == nil) return;
- NSEnumerator* enumerator = [events objectEnumerator];
- id event;
- while(event = [enumerator nextObject])
- {
-
id type = [event objectForKey:@"type"];
-
if(type == nil) continue;
-
if([type isEqualToString:@"mouseDown"])
-
{
-
SDL_PrivateMouseButton (SDL_PRESSED, 1, 0, 0);
-
}else if([type isEqualToString:@"mouseUp"])
-
{
-
SDL_PrivateMouseButton (SDL_RELEASED, 1, 0, 0);
-
}
- }
+}
+void iPhone_InitOSKeymap(_THIS)
+{
+}
+
diff -urpN SDL-1.2.12/src/video/iphone/SDL_iphonevideo.h SDL-1.2.12-
iphone/src/video/iphone/SDL_iphonevideo.h
— SDL-1.2.12/src/video/iphone/SDL_iphonevideo.h 1969-12-31
19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/src/video/iphone/SDL_iphonevideo.h 2007-08-24
12:58:59.000000000 -0400
@@ -0,0 +1,76 @@
+/*
- SDL - Simple DirectMedia Layer
- Copyright © 1997-2006 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 at libsdl.org
+*/
+#include “SDL_config.h”
+#ifndef _SDL_iphonevideo_h
+#define _SDL_iphonevideo_h
+
+#include “…/SDL_sysvideo.h”
+
+#import <UIKit/UIKit.h>
+#import <UIKit/UIView-Geometry.h>
+#import <GraphicsServices/GraphicsServices.h>
+#import <Foundation/Foundation.h>
+#import <CoreSurface/CoreSurface.h>
+#import <LayerKit/LKLayer.h>
+
- at interface SDL_iPhoneView : UIView
+{ - NSMutableArray* _events;
- NSLock* _lock;
- CoreSurfaceBufferRef _screenSurface;
+}
± (id)initWithFrame:(struct CGRect)frame;
+
± (void)lock;
± (void)unlock;
+
± (void)addEvent:(NSDictionary*)event;
± (NSArray*)getEvents;
+
± (void)gestureChanged:(GSEvent*)event;
± (void)gestureEnded:(GSEvent*)event;
± (void)gestureStarted:(GSEvent*)event;
± (void)keyDown:(GSEvent*)event;
± (void)keyUp:(GSEvent*)event;
± (void)mouseDown:(GSEvent*)event;
± (void)mouseDragged:(GSEvent*)event;
± (void)mouseEntered:(GSEvent*)event;
± (void)mouseExited:(GSEvent*)event;
± (void)mouseMoved:(GSEvent*)event;
± (void)mouseUp:(GSEvent*)event;
+
± (void)drawRect:(CGRect)frame;
+
± (CoreSurfaceBufferRef)getSurface;
+
- at end
+#define _THIS SDL_VideoDevice *this
+
+typedef struct SDL_PrivateVideoData
+{
- SDL_iPhoneView* _view;
+} SDL_PrivateVideoData;
+#endif /* _SDL_nullvideo_h /
diff -urpN SDL-1.2.12/src/video/iphone/SDL_iphonevideo.m SDL-1.2.12-
iphone/src/video/iphone/SDL_iphonevideo.m
— SDL-1.2.12/src/video/iphone/SDL_iphonevideo.m 1969-12-31
19:00:00.000000000 -0500
+++ SDL-1.2.12-iphone/src/video/iphone/SDL_iphonevideo.m 2007-08-24
13:08:01.000000000 -0400
@@ -0,0 +1,375 @@
+/
- SDL - Simple DirectMedia Layer
- Copyright © 1997-2006 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 at libsdl.org
+*/
+#include “SDL_config.h”
+#include “SDL_video.h”
+#include “SDL_mouse.h”
+#include “…/SDL_sysvideo.h”
+#include “…/SDL_pixels_c.h”
+#include “…/…/events/SDL_events_c.h”
+
+#include “SDL_iphonevideo.h”
+#include “SDL_iphoneevents.h”
+
+#define IPHONEVID_DRIVER_NAME “iphone”
+
+
+static int iPhone_VideoInit(_THIS, SDL_PixelFormat *vformat);
+static SDL_Rect **iPhone_ListModes(_THIS, SDL_PixelFormat *format,
Uint32 flags);
+static SDL_Surface *iPhone_SetVideoMode(_THIS, SDL_Surface *current,
int width, int height, int bpp, Uint32 flags);
+static int iPhone_SetColors(_THIS, int firstcolor, int ncolors,
SDL_Color *colors);
+static void iPhone_VideoQuit(_THIS);
+static void iPhone_UpdateRects(_THIS, int numrects, SDL_Rect *rects);
+static int iPhone_Available(void) { return 1; }
+static int iPhone_LockHWSurface(_THIS, SDL_Surface *surface);
+static void iPhone_UnlockHWSurface(_THIS, SDL_Surface *surface);
+
+static void iPhone_DeleteDevice(SDL_VideoDevice *device)
+{
- SDL_free(device->hidden);
- SDL_free(device);
+}
+static SDL_VideoDevice *iPhone_CreateDevice(int devindex)
+{
- SDL_VideoDevice *device;
- device = (SDL_VideoDevice *)SDL_malloc(sizeof(SDL_VideoDevice));
- if (device)
- {
-
SDL_memset(device, 0, (sizeof *device));
-
device->hidden = (struct SDL_PrivateVideoData *) SDL_malloc
((sizeof *device->hidden));
- }
- if ( (device == NULL) || (device->hidden == NULL) )
- {
-
SDL_OutOfMemory();
-
if ( device ) SDL_free(device);
-
return 0;
- }
- SDL_memset(device->hidden, 0, (sizeof *device->hidden));
- device->hidden->_view = [UIApp getView];
- device->VideoInit = iPhone_VideoInit;
- device->ListModes = iPhone_ListModes;
- device->SetVideoMode = iPhone_SetVideoMode;
- device->CreateYUVOverlay = NULL;
- device->SetColors = iPhone_SetColors;
- device->UpdateRects = iPhone_UpdateRects;
- device->VideoQuit = iPhone_VideoQuit;
- device->AllocHWSurface = NULL;
- device->CheckHWBlit = NULL;
- device->FillHWRect = NULL;
- device->SetHWColorKey = NULL;
- device->SetHWAlpha = NULL;
- device->LockHWSurface = iPhone_LockHWSurface;
- device->UnlockHWSurface = iPhone_UnlockHWSurface;
- device->FlipHWSurface = NULL;
- device->FreeHWSurface = NULL;
- device->SetCaption = NULL;
- device->SetIcon = NULL;
- device->IconifyWindow = NULL;
- device->GrabInput = NULL;
- device->GetWMInfo = NULL;
- device->InitOSKeymap = iPhone_InitOSKeymap;
- device->PumpEvents = iPhone_PumpEvents;
- device->free = iPhone_DeleteDevice;
- return device;
+}
+VideoBootStrap iPhone_bootstrap =
+{
- IPHONEVID_DRIVER_NAME, “iPhone video driver”,
- iPhone_Available, iPhone_CreateDevice
+};
+int iPhone_VideoInit(_THIS, SDL_PixelFormat *vformat)
+{
- vformat->BitsPerPixel = 16;
- vformat->Rmask = 0xF800;
- vformat->Gmask = 0x07E0;
- vformat->Bmask = 0x001F;
- return 0;
+}
+SDL_Rect** iPhone_ListModes(_THIS, SDL_PixelFormat *format, Uint32
flags)
+{
+
- static SDL_Rect rect;
- static SDL_Rect* rectArray[2] = {&rect, 0};
- CGRect cgRect = [UIHardware fullScreenApplicationContentRect];
- rect.x = 0;
- rect.y = 0;
- rect.w = cgRect.size.width;
- rect.h = cgRect.size.height;
- return (SDL_Rect**)rectArray;
+}
+SDL_Surface *iPhone_SetVideoMode(_THIS, SDL_Surface *current, int
width, int height, int bpp, Uint32 flags)
+{
- current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE);
- current->w = width;
- current->h = height;
- current->pitch = current->w * (bpp / 8);
- current->pixels = CoreSurfaceBufferGetBaseAddress([this->hidden-
_view getSurface]);
- SDL_ReallocFormat(current, bpp, 0xF800, 0x07E0, 0x001F, 0);
- return current;
+}
+int iPhone_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color
*colors)
+{
- return(1);
+}
+void iPhone_VideoQuit(_THIS)
+{
- this->screen->pixels = NULL;
+}
+static void noise_test(_THIS)
+{
- CGRect frame = [this->hidden->_view frame];
- unsigned short* p = CoreSurfaceBufferGetBaseAddress([this->hidden-
_view getSurface]);
- int i,j;
- for(i=0;i<frame.size.height;i++)
- {
-
for(j=0;j<frame.size.width;j++,p++)
-
{
-
*p=(rand()%2) ? 0xF800 : 0x07E0;;
-
}
- }
+}
+static void iPhone_UpdateRects(_THIS, int numrects, SDL_Rect *rects)
+{
+// noise_test(this);
- [this->hidden->_view performSelectorOnMainThread:@selector
(setNeedsDisplay) withObject:nil waitUntilDone: NO];
+}
+static int iPhone_LockHWSurface(_THIS, SDL_Surface *surface)
+{
- CoreSurfaceBufferLock([this->hidden->_view getSurface], 3);
+}
+static void iPhone_UnlockHWSurface(_THIS, SDL_Surface *surface)
+{
- CoreSurfaceBufferUnlock([this->hidden->_view getSurface]);
+}
+/* SDL_iPhoneView */
- at implementation SDL_iPhoneView
± (id)initWithFrame:(struct CGRect)frame
+{
- [super initWithFrame: frame];
- _events = nil;
- _lock = [[NSLock alloc] init];
- [_lock retain];
- int w = frame.size.width;
- int h = frame.size.height;
- int pitch = w * 2, allocSize = 2 * w * h;
- char *pixelFormat = “565L”;
- NSDictionary* dict = [[NSDictionary alloc] initWithObjectsAndKeys:
-
kCFBooleanTrue, kCoreSurfaceBufferGlobal,
-
@"PurpleGFXMem", kCoreSurfaceBufferMemoryRegion,
-
[NSNumber numberWithInt: pitch], kCoreSurfaceBufferPitch,
-
[NSNumber numberWithInt: w], kCoreSurfaceBufferWidth,
-
[NSNumber numberWithInt: h], kCoreSurfaceBufferHeight,
-
[NSNumber numberWithInt: *(int*)pixelFormat],
kCoreSurfaceBufferPixelFormat,
-
[NSNumber numberWithInt: allocSize], kCoreSurfaceBufferAllocSize,
-
nil
- ];
- _screenSurface = CoreSurfaceBufferCreate((CFDictionaryRef)dict);
- CoreSurfaceBufferLock(_screenSurface, 3);
- LKLayer* screenLayer = [LKLayer layer];
- [screenLayer setFrame: CGRectMake(0.0f, 0.0f, w, h)];
- [screenLayer setContents: _screenSurface];
- [screenLayer setOpaque: YES];
- [[self _layer] addSublayer: screenLayer];
- CoreSurfaceBufferUnlock(_screenSurface);
- [dict release];
- return self;
+}
±(void) dealloc
+{
- [_events release];
- [_lock release];
- [super dealloc];
+}
± (void)lock
+{
- [_lock lock];
+}
± (void)unlock
+{
- [_lock unlock];
+}
± (NSArray*)getEvents
+{
- [self lock];
- NSArray* events = _events;
- _events = nil;
- [self unlock];
- [events autorelease];
- return events;
+}
± (void)addEvent:(NSDictionary*)event
+{
- [self lock];
- if(_events == nil)
-
_events = [[NSMutableArray alloc] init];
- [_events addObject: event];
- [self unlock];
+}
± (void)gestureChanged:(GSEvent*)event
+{
- printf(“gestureChanged!\n”);
+}
± (void)gestureEnded:(GSEvent*)event
+{
- printf(“gestureEnded!\n”);
+}
± (void)gestureStarted:(GSEvent*)event
+{
- printf(“gestureStarted!\n”);
+}
± (void)keyDown:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"keyDown", @"type",
-
nil
-
]
- ];
+}
± (void)keyUp:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"keyUp", @"type",
-
nil
-
]
- ];
+}
± (void)mouseDown:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseDown", @"type",
-
nil
-
]
- ];
+}
± (void)mouseDragged:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseDragged",@"type",
-
nil
-
]
- ];
+}
± (void)mouseEntered:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseEntered", @"type",
-
nil
-
]
- ];
+}
± (void)mouseExited:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseExited", @"type",
-
nil
-
]
- ];
+}
± (void)mouseMoved:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseMoved", @"type",
-
nil
-
]
- ];
+}
± (void)mouseUp:(GSEvent*)event
+{
- [self addEvent:
-
[[NSDictionary alloc] initWithObjectsAndKeys:
-
@"mouseUp", @"type",
-
nil
-
]
- ];
+}
± (CoreSurfaceBufferRef)getSurface
+{
- return _screenSurface;
+}
± (void)drawRect:(CGRect)frame
+{
+}
+
- at end