Date: Tue, 21 Aug 2001 03:50:01 +0200

From: Max Horn <max@quendi.de>
Subject: New patch for OS X

Attached a .patch file for SDL/OSX with some nice bug fixes / enhancments.

* fixes the activation issues, which also caused the window to be
always drawn like an inactive. The close/minimize widgets now are
animated properly, too.

* the menu items are automatically adjusted to use the app name
instead of just "SDL App". I did this so that we really can use one
central SDLMain.nib file, w/o requiring developers to make a copy of
it and adjust it.

* libSDLMain now contains the proper cocoa code, not as before the
carbon code. This means apps no longer have to carry a copy of
SDLMain.m/SDLMain.h

* revamped configure.in to properly build a Cocoa/Quartz SDL lib, not
a Carbon based SDL lib

--HG--
extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%40159
This commit is contained in:
Sam Lantinga 2001-08-21 07:19:59 +00:00
parent 6dbdba950a
commit 75ab0e7ade
8 changed files with 170 additions and 62 deletions

View file

@ -223,7 +223,7 @@ static void QZ_DoDeactivate (_THIS) {
}
static void QZ_PumpEvents (_THIS)
{
{
NSDate *distantPast;
NSEvent *event;
NSRect winRect;
@ -247,27 +247,29 @@ static void QZ_PumpEvents (_THIS)
if (event != nil) {
unsigned int type;
BOOL isForGameWin;
#define DO_MOUSE_DOWN(button, sendToWindow) \
#define DO_MOUSE_DOWN(button, sendToWindow) do { \
if ( inForeground ) { \
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
NSPointInRect([event locationInWindow], winRect) ) \
SDL_PrivateMouseButton (SDL_PRESSED, button, 0, 0); \
else if (sendToWindow) \
[ window sendEvent:event ]; \
} \
else { \
QZ_DoActivate (this); \
}
#define DO_MOUSE_UP(button, sendToWindow) \
} \
[ NSApp sendEvent:event ]; \
} while(0)
#define DO_MOUSE_UP(button, sendToWindow) do { \
if ( (SDL_VideoSurface->flags & SDL_FULLSCREEN) || \
!NSPointInRect([event locationInWindow], titleBarRect) )\
SDL_PrivateMouseButton (SDL_RELEASED, button, 0, 0); \
if (sendToWindow) \
[ window sendEvent:event ]
[ NSApp sendEvent:event ]; \
} while(0)
type = [ event type ];
isForGameWin = (qz_window == [ event window ]);
switch (type) {
case NSLeftMouseDown:
@ -351,8 +353,8 @@ static void QZ_PumpEvents (_THIS)
case NSFlagsChanged:
QZ_DoModifiers( [ event modifierFlags ] );
break;
case NSMouseEntered: break;
case NSMouseExited: break;
// case NSMouseEntered: break;
// case NSMouseExited: break;
case NSAppKitDefined:
switch ( [ event subtype ] ) {
case NSApplicationActivatedEventType:
@ -361,14 +363,14 @@ static void QZ_PumpEvents (_THIS)
case NSApplicationDeactivatedEventType:
QZ_DoDeactivate (this);
break;
case NSWindowMovedEventType:
[ window sendEvent:event ];
break;
}
[ NSApp sendEvent:event ];
break;
case NSApplicationDefined: break;
case NSPeriodic: break;
case NSCursorUpdate: break;
// case NSApplicationDefined: break;
// case NSPeriodic: break;
// case NSCursorUpdate: break;
default:
[ NSApp sendEvent:event ];
}
}
} while (event != nil);

View file

@ -44,10 +44,6 @@
- Launch times are slow, maybe prebinding will help
- Direct framebuffer access has some artifacts, maybe a driver issue
- Cursor in 8 bit modes is screwy
- Modifier + mouse-down maps alternate mouse button, but if modifier is released
before mouse button, corresponding mouse-up event is not generated.
- Clicking in content activates app, but doesn't generate the activate event,
and subsequent switches generate no activate/deactivate events! (OS Bug I hope)
*/
#include <ApplicationServices/ApplicationServices.h>
@ -107,7 +103,7 @@ typedef struct SDL_PrivateVideoData {
#define device_bpp (this->hidden->bpp)
#define mode_flags (this->hidden->flags)
#define video_set (this->hidden->video_is_set)
#define window (this->hidden->window)
#define qz_window (this->hidden->window)
#define windowView (this->hidden->view)
/* Interface for hardware fill not (yet) in the public API */

View file

@ -267,9 +267,9 @@ static void QZ_UnsetVideoMode (_THIS) {
UnlockPortBits ( [ windowView qdPort ] );
[ windowView release ];
}
[ window setContentView:nil ];
[ window setDelegate:nil ];
[ window close ];
[ qz_window setContentView:nil ];
[ qz_window setDelegate:nil ];
[ qz_window close ];
}
/* Set pixels to null (so other code doesn't try to free it) */
@ -408,9 +408,9 @@ static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
}
/* Manually create a window, avoids having a nib file resource */
window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect
qz_window = [ [ SDL_QuartzWindow alloc ] initWithContentRect:rect
styleMask:style backing:NSBackingStoreBuffered defer:NO ];
if (window == nil) {
if (qz_window == nil) {
SDL_SetError ("Could not create the Cocoa window");
return NULL;
}
@ -419,12 +419,12 @@ static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
current->w = width;
current->h = height;
[ window setReleasedWhenClosed:YES ];
[ qz_window setReleasedWhenClosed:YES ];
QZ_SetCaption(this, this->wm_title, this->wm_icon);
[ window setAcceptsMouseMovedEvents:YES ];
[ window setViewsNeedDisplay:NO ];
[ window center ];
[ window setDelegate:
[ qz_window setAcceptsMouseMovedEvents:YES ];
[ qz_window setViewsNeedDisplay:NO ];
[ qz_window center ];
[ qz_window setDelegate:
[ [ [ SDL_QuartzWindowDelegate alloc ] init ] autorelease ] ];
/* For OpenGL, we set the content view to a NSOpenGLView */
@ -434,17 +434,17 @@ static SDL_Surface* QZ_SetVideoWindowed (_THIS, SDL_Surface *current, int width,
return NULL;
}
[ gl_context setView: [ window contentView ] ];
[ gl_context setView: [ qz_window contentView ] ];
[ gl_context makeCurrentContext];
[ window orderFront:nil ];
[ qz_window makeKeyAndOrderFront:nil ];
current->flags |= SDL_OPENGL;
}
/* For 2D, we set the content view to a NSQuickDrawView */
else {
windowView = [ [ NSQuickDrawView alloc ] init ];
[ window setContentView:windowView ];
[ window orderFront:nil ];
[ qz_window setContentView:windowView ];
[ qz_window makeKeyAndOrderFront:nil ];
LockPortBits ( [ windowView qdPort ] );
current->pixels = GetPixBaseAddr ( GetPortPixMap ( [ windowView qdPort ] ) );

View file

@ -96,7 +96,7 @@ static void QZ_PrivateWarpCursor (_THIS, int fullscreen, int h, int x, int y) {
/* Convert to absolute screen coordinates */
NSPoint base, screen;
base = NSMakePoint (p.x, p.y);
screen = [ window convertBaseToScreen:base ];
screen = [ qz_window convertBaseToScreen:base ];
p.x = screen.x;
p.y = device_height - screen.y;
CGDisplayMoveCursorToPoint (display_id, p);
@ -122,16 +122,16 @@ static void QZ_CheckMouseMode (_THIS) { }
static void QZ_SetCaption (_THIS, const char *title, const char *icon) {
if ( window != nil ) {
if ( qz_window != nil ) {
NSString *string;
if ( title != NULL ) {
string = [ [ NSString alloc ] initWithCString:title ];
[ window setTitle:string ];
[ qz_window setTitle:string ];
[ string release ];
}
if ( icon != NULL ) {
string = [ [ NSString alloc ] initWithCString:icon ];
[ window setMiniwindowTitle:string ];
[ qz_window setMiniwindowTitle:string ];
[ string release ];
}
}
@ -144,19 +144,19 @@ static void QZ_SetIcon (_THIS, SDL_Surface *icon, Uint8 *mask) {
static int QZ_IconifyWindow (_THIS) {
/* Bug! minimize erases the framebuffer */
if ( ! [ window isMiniaturized ] ) {
[ window miniaturize:nil ];
if ( ! [ qz_window isMiniaturized ] ) {
[ qz_window miniaturize:nil ];
return 1;
}
else {
SDL_SetError ("window already iconified");
SDL_SetError ("qz_window already iconified");
return 0;
}
}
/*
static int QZ_GetWMInfo (_THIS, SDL_SysWMinfo *info) {
info->nsWindowPtr = window;
info->nsWindowPtr = qz_window;
return 0;
}*/