The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Showing a UIViewController on an SDL based iOS project
Tim Angus
Guest

Maybe this is useful for other people. It needs to be compiled as .mm in
order to be callable from C++.

void PresentModalView( const char* viewName )
{
SDL_SysWMinfo info;
SDL_VERSION( &info.version );

if( SDL_GetWindowWMInfo( window, &info ) )
{
UIWindow* uiWindow = (UIWindow*)info.info.uikit.window;
UIView* view = [uiWindow.subviews objectAtIndex:0];
id nextResponder = [view nextResponder];
if( [nextResponder isKindOfClass:[UIViewController class]] )
{
UIViewController* viewController =
(UIViewController*)nextResponder;

// You can do some terrifying things with Objective-C
NSString* className = [NSString stringWithUTF8String:viewName];
Class ViewControllerClass = NSClassFromString(className);
id subviewController = [[[ViewControllerClass alloc]
initWithNibName:className bundle:nil] autorelease];

[viewController presentModalViewController:
subviewController animated:YES];
}
}
}
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
michelleC


Joined: 08 Feb 2010
Posts: 108
I think Sam added a function that makes this unnecessary , I don't recall the name.

Here IS how we used to do it.


-(void) swapViews {
UIWindow *windows = [[UIApplication sharedApplication] keyWindow];
NSLog(@"the app has %d views ",[windows.subviews count]);
//toggle_pause();
UIView *view = [window.subviews objectAtIndex:0];
[view removeFromSuperview];
[windows addSubview:view];
}



-(void) swapViewsWithTransition {
UIWindow *windows = [[UIApplication sharedApplication] keyWindow];
UIView *firstView = [window.subviews objectAtIndex:0];
UIView *secondView = [window.subviews objectAtIndex:1];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationTransition:([secondView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:firstView cache:YES];
[firstView removeFromSuperview];
[windows addSubview:firstView];
[UIView commitAnimations];
Showing a UIViewController on an SDL based iOS project
Tim Angus
Guest

On Sun, 17 Jul 2011 07:56:14 -0700 michelleC wrote:
Quote:
I think Sam added a function that makes this unnecessary , I don't
recall the name.

Hmm really? I can't seem to find it. I'm not sure it's really
appropriate for SDL anyway. It should however be possible as it's
likely to be a very common thing to want to do. Worth bunging in the
wiki somewhere anyway; though I'm not sure where.

Quote:
Here IS how we used to do it.


-(void) swapViews {
UIWindow *windows = [[UIApplication sharedApplication]
keyWindow];

I guess this makes the assumption that there is only one window? The
part I negelected to mention in my post is that "window" is an
SDL_Window* global, but it could just as easily be a parameter.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: Showing a UIViewController on an SDL based iOS project
michelleC


Joined: 08 Feb 2010
Posts: 108
Tim Angus wrote:
On Sun, 17 Jul 2011 07:56:14 -0700 michelleC wrote:
Quote:
I think Sam added a function that makes this unnecessary , I don't
recall the name.

Hmm really? I can't seem to find it. I'm not sure it's really
appropriate for SDL anyway. It should however be possible as it's
likely to be a very common thing to want to do. Worth bunging in the
wiki somewhere anyway; though I'm not sure where.

Quote:
Here IS how we used to do it.


-(void) swapViews {
UIWindow *windows = [[UIApplication sharedApplication]
keyWindow];

I guess this makes the assumption that there is only one window? The
part I negelected to mention in my post is that "window" is an
SDL_Window* global, but it could just as easily be a parameter.
_______________________________________________


Sure, but thats usually how an iphone app is structured, one window but x number of viewcontrollers.

multiple windows don't make sense on the iphone

However I guess you could have two windows and swap between them.

http://code.google.com/p/ffmpeg4iphone/source/browse/WebStreamx/WebStreamXNoLibs/uikit/SDL_uikitappdelegate.m
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Showing a UIViewController on an SDL based iOS project
Vittorio G.
Guest

That's exactly how I implemented my application; I have subclassed the sdlappuikitdelegate and created my objc frontend, then i call some code that instances a second uiwindow and fills it with a sdl context
More details here: http://code.google.com/p/hedgewars/source/browse/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m

bye
Vittorio

On Sun, Jul 17, 2011 at 11:47 PM, michelleC wrote:
Quote:


Sure, but thats usually how an iphone app is structured, one window but x number of viewcontrollers.

multiple windows don't make sense on the iphone

However I guess you could have two windows and swap between them.

http://code.google.com/p/ffmpeg4iphone/source/browse/WebStreamx/WebStreamXNoLibs/uikit/SDL_uikitappdelegate.m
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org






_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Re: Showing a UIViewController on an SDL based iOS project
michelleC


Joined: 08 Feb 2010
Posts: 108
Yep, I've seen your app , nice.

I originally used multiple windows, but it really breaks (model wise not technically) the ios implementation.

I pretty easy to get hold of the sdl window and add view controllers to it, or get the encapsulated sdl view and add it to a view controller.

Is there any particular reason you used freepascal??

Also I am very interested in your android experience, I am having a great deal of problems with our app because it uses software yuv12 textures, and runs into memory issues very quick.

I have not been able to get sam's open gles 2 renderer to work, which should solve the problems.

Here's one for the road as they say

/* construct our view, passing in SDL's OpenGL configuration data */
view = [[SDL_uikitopenglview alloc] initWithFrame: [[UIScreen mainScreen] applicationFrame] \
retainBacking: _this->gl_config.retained_backing \
rBits: _this->gl_config.red_size \
gBits: _this->gl_config.green_size \
bBits: _this->gl_config.blue_size \
aBits: _this->gl_config.alpha_size \
depthBits: _this->gl_config.depth_size];

data->view = view;

UINavigationController *localNavigationController;
RootViewController *rootViewController;
rootViewController = [[RootViewController alloc] init];
SDLUIKitDelegate *appDelegate = [SDLUIKitDelegate sharedAppDelegate];
localNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];

//rootViewController.view.opaque = YES;
localNavigationController.view.alpha = 1.0;
localNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[localNavigationController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];

if (firstTime) {

[appDelegate setSettingUp:NO];
[data->uiwindow addSubview: view ];
[data->uiwindow addSubview:localNavigationController.view];
printf("created two windows local first");
}else {
[data->uiwindow addSubview:localNavigationController.view];
[data->uiwindow addSubview: view ];
printf("created two windows sdl second");


}





Vittorio G. wrote:
That's exactly how I implemented my application; I have subclassed the sdlappuikitdelegate and created my objc frontend, then i call some code that instances a second uiwindow and fills it with a sdl context
More details here: http://code.google.com/p/hedgewars/source/browse/project_files/HedgewarsMobile/Classes/HedgewarsAppDelegate.m

bye
Vittorio

On Sun, Jul 17, 2011 at 11:47 PM, michelleC wrote:
Quote:


Sure, but thats usually how an iphone app is structured, one window but x number of viewcontrollers.

multiple windows don't make sense on the iphone

However I guess you could have two windows and swap between them.

http://code.google.com/p/ffmpeg4iphone/source/browse/WebStreamx/WebStreamXNoLibs/uikit/SDL_uikitappdelegate.m
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org






_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org