Mercurial > sdl-ios-xcode
view docs/man3/SDL_Event.3 @ 4324:1496aa09e41e SDL-1.2
Steven Noonan to sdl
While trying to build the SDLMain.m included with SDL 1.2.14, with
#define SDL_USE_NIB_FILE 1:
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:
In function '-[SDLMain fixMenu:withAppName:]':
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:122:
warning: 'sizeToFit' is deprecated (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/AppKit.framework/Headers/NSMenu.h:281)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:
In function 'main':
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:376:
warning: 'poseAsClass:' is deprecated (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:127)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:376:
error: 'poseAsClass:' is unavailable (declared at
/Developer/SDKs/MacOSX10.6.sdk/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:127)
/Users/steven/Development/darwinia/targets/macosx/Darwinia/SDLMain.m:377:
warning: passing argument 2 of 'NSApplicationMain' from incompatible
pointer type
Eric Wing to Sam
I don't have time today to look at this in detail, but the problem is definitely the poseAsClass: method.
This was deprecated in Obj-C 2.0 and not retained in 64-bit.
I've never used this method and it has always been limited to esoteric uses. I think this is why Apple wanted to dump it (among complicating some other things they do). I have read about others getting bit by this when migrating. Long story short, there really isn't a migration path for this method. The question that then must be asked is why are we using it (what does it accomplish), and then figure out the 'proper' way of accomplishing that.
Glancing at SDLMain.m, it's not obvious to me why it is there or what it is really accomplishing. My only speculation is that NSApplicationMain hardcodes something to look for NSApplication and a subclass (SDLApplication) fails for some reason (assuming that the original coder did this for good reason).
Three thoughts come to mind.
1) The Info.plist has properties to control things related to the startup class and nib.
NSPrincipalClass, NSMainNibFile
Maybe principle class needs to be SDLApplication and we can delete the poseAs
2) I was told that 10.6 introduced new APIs to make programatic NIB wrangling and avoidance easier. Unfortunately, I don't know the specifics.
3) Instead of subclassing NSApplication in SDLMain.m, maybe we can just add a category. It looks like the following is the only thing that is done (quick glance):
@interface SDLApplication : NSApplication
@end
@implementation SDLApplication
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
So instead, we change this to: (warning written in mail and untested)
@interface NSApplication (SDLApplication)
- (void) terminate:(id)sender;
@end
@implementation NSApplication (SDLApplication)
/* Invoked from the Quit menu item */
- (void)terminate:(id)sender
{
/* Post a SDL_QUIT event */
SDL_Event event;
event.type = SDL_QUIT;
SDL_PushEvent(&event);
}
@end
Then everywhere SDLApplication is used, we change it to NSApplication (and remove the poseAsClass line).
Perhaps you could ask the bug reporter to try this solution (#3).
And if that fails, maybe try #1.
-Eric
Steven Noonan to Sam
The suggested change (diff below) seems to work fine.
- Steven
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 12 Oct 2009 21:07:12 +0000 |
parents | 1238da4a7112 |
children |
line wrap: on
line source
.TH "SDL_Event" "3" "Tue 11 Sep 2001, 22:59" "SDL" "SDL API Reference" .SH "NAME" SDL_Event \- General event structure .SH "STRUCTURE DEFINITION" .PP .nf \f(CWtypedef union{ Uint8 type; SDL_ActiveEvent active; SDL_KeyboardEvent key; SDL_MouseMotionEvent motion; SDL_MouseButtonEvent button; SDL_JoyAxisEvent jaxis; SDL_JoyBallEvent jball; SDL_JoyHatEvent jhat; SDL_JoyButtonEvent jbutton; SDL_ResizeEvent resize; SDL_ExposeEvent expose; SDL_QuitEvent quit; SDL_UserEvent user; SDL_SysWMEvent syswm; } SDL_Event;\fR .fi .PP .SH "STRUCTURE DATA" .TP 20 \fBtype\fR The type of event .TP 20 \fBactive\fR \fIActivation event\fR .TP 20 \fBkey\fR \fIKeyboard event\fR .TP 20 \fBmotion\fR \fIMouse motion event\fR .TP 20 \fBbutton\fR \fIMouse button event\fR .TP 20 \fBjaxis\fR \fIJoystick axis motion event\fR .TP 20 \fBjball\fR \fIJoystick trackball motion event\fR .TP 20 \fBjhat\fR \fIJoystick hat motion event\fR .TP 20 \fBjbutton\fR \fIJoystick button event\fR .TP 20 \fBresize\fR \fIApplication window resize event\fR .TP 20 \fBexpose\fR \fIApplication window expose event\fR .TP 20 \fBquit\fR \fIApplication quit request event\fR .TP 20 \fBuser\fR \fIUser defined event\fR .TP 20 \fBsyswm\fR \fIUndefined window manager event\fR .SH "DESCRIPTION" .PP The \fBSDL_Event\fR union is the core to all event handling is SDL, its probably the most important structure after \fBSDL_Surface\fR\&. \fBSDL_Event\fR is a union of all event structures used in SDL, using it is a simple matter of knowing which union member relates to which event \fBtype\fR\&. .PP .TP 20 \fBEvent \fBtype\fR\fR \fBEvent Structure\fR .TP 20 \fBSDL_ACTIVEEVENT\fP \fI\fBSDL_ActiveEvent\fR\fR .TP 20 \fBSDL_KEYDOWN/UP\fP \fI\fBSDL_KeyboardEvent\fR\fR .TP 20 \fBSDL_MOUSEMOTION\fP \fI\fBSDL_MouseMotionEvent\fR\fR .TP 20 \fBSDL_MOUSEBUTTONDOWN/UP\fP \fI\fBSDL_MouseButtonEvent\fR\fR .TP 20 \fBSDL_JOYAXISMOTION\fP \fI\fBSDL_JoyAxisEvent\fR\fR .TP 20 \fBSDL_JOYBALLMOTION\fP \fI\fBSDL_JoyBallEvent\fR\fR .TP 20 \fBSDL_JOYHATMOTION\fP \fI\fBSDL_JoyHatEvent\fR\fR .TP 20 \fBSDL_JOYBUTTONDOWN/UP\fP \fI\fBSDL_JoyButtonEvent\fR\fR .TP 20 \fBSDL_QUIT\fP \fI\fBSDL_QuitEvent\fR\fR .TP 20 \fBSDL_SYSWMEVENT\fP \fI\fBSDL_SysWMEvent\fR\fR .TP 20 \fBSDL_VIDEORESIZE\fP \fI\fBSDL_ResizeEvent\fR\fR .TP 20 \fBSDL_VIDEOEXPOSE\fP \fI\fBSDL_ExposeEvent\fR\fR .TP 20 \fBSDL_USEREVENT\fP \fI\fBSDL_UserEvent\fR\fR .SH "USE" .PP The \fBSDL_Event\fR structure has two uses .IP " \(bu" 6 Reading events on the event queue .IP " \(bu" 6 Placing events on the event queue .PP Reading events from the event queue is done with either \fI\fBSDL_PollEvent\fP\fR or \fI\fBSDL_PeepEvents\fP\fR\&. We\&'ll use \fBSDL_PollEvent\fP and step through an example\&. .PP First off, we create an empty \fBSDL_Event\fR structure\&. .PP .nf \f(CWSDL_Event test_event;\fR .fi .PP \fBSDL_PollEvent\fP removes the next event from the event queue, if there are no events on the queue it returns \fB0\fR otherwise it returns \fB1\fR\&. We use a \fBwhile\fP loop to process each event in turn\&. .PP .nf \f(CWwhile(SDL_PollEvent(&test_event)) {\fR .fi .PP The \fBSDL_PollEvent\fP function take a pointer to an \fBSDL_Event\fR structure that is to be filled with event information\&. We know that if \fBSDL_PollEvent\fP removes an event from the queue then the event information will be placed in our \fBtest_event\fR structure, but we also know that the \fItype\fP of event will be placed in the \fBtype\fR member of \fBtest_event\fR\&. So to handle each event \fBtype\fR seperately we use a \fBswitch\fP statement\&. .PP .nf \f(CW switch(test_event\&.type) {\fR .fi .PP We need to know what kind of events we\&'re looking for \fIand\fP the event \fBtype\fR\&'s of those events\&. So lets assume we want to detect where the user is moving the mouse pointer within our application\&. We look through our event types and notice that \fBSDL_MOUSEMOTION\fP is, more than likely, the event we\&'re looking for\&. A little \fImore\fR research tells use that \fBSDL_MOUSEMOTION\fP events are handled within the \fI\fBSDL_MouseMotionEvent\fR\fR structure which is the \fBmotion\fR member of \fBSDL_Event\fR\&. We can check for the \fBSDL_MOUSEMOTION\fP event \fBtype\fR within our \fBswitch\fP statement like so: .PP .nf \f(CW case SDL_MOUSEMOTION:\fR .fi .PP All we need do now is read the information out of the \fBmotion\fR member of \fBtest_event\fR\&. .PP .nf \f(CW printf("We got a motion event\&. "); printf("Current mouse position is: (%d, %d) ", test_event\&.motion\&.x, test_event\&.motion\&.y); break; default: printf("Unhandled Event! "); break; } } printf("Event queue empty\&. ");\fR .fi .PP .PP It is also possible to push events onto the event queue and so use it as a two-way communication path\&. Both \fI\fBSDL_PushEvent\fP\fR and \fI\fBSDL_PeepEvents\fP\fR allow you to place events onto the event queue\&. This is usually used to place a \fBSDL_USEREVENT\fP on the event queue, however you could use it to post fake input events if you wished\&. Creating your own events is a simple matter of choosing the event type you want, setting the \fBtype\fR member and filling the appropriate member structure with information\&. .PP .nf \f(CWSDL_Event user_event; user_event\&.type=SDL_USEREVENT; user_event\&.user\&.code=2; user_event\&.user\&.data1=NULL; user_event\&.user\&.data2=NULL; SDL_PushEvent(&user_event);\fR .fi .PP .SH "SEE ALSO" .PP \fI\fBSDL_PollEvent\fP\fR, \fI\fBSDL_PushEvent\fP\fR, \fI\fBSDL_PeepEvents\fP\fR .\" created by instant / docbook-to-man, Tue 11 Sep 2001, 22:59