leadro wrote:
I’m try to add the UIKit controls after SDL’s window + renderer creation. For adding UIKit controls, for example UIView, I’m use next code:
Code:
UIView* newView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
newView.backgroundColor = [UIColor yellowColor];
[self.view addSubView:newView];
In the above bit of code, what is ‘self’? Is it a UIViewController, or a subclass of one? SDL2, as of this writing, has its own subclass of UIViewController. Assuming you’re creating everything in one UIViewController, then trying to display SDL’s view controller (via SDL_RenderPresent), SDL’s view could end up being overlaid on top of yours.
In my experience, it’s possible to overlay UIKit controls on top of SDL’s in either of two ways:
- by getting a pointer to SDL’s view controller, getting its view, then adding new controls as subviews. I’ve done this in the past to overlay a UIKit text field onto an SDL app, in order to get use of iOS’ cut, copy, paste, and deletion controls.
- by getting a pointer to SDL’s view controller, creating a new view controller, then displaying it modally over SDL’s view controller. This can be used to display a Game Center view controller, or a score-sharing view controller, for example.
Here is one way to get SDL’s view controller: create your window, create the renderer (using the OpenGL ES based renderer, not the software-only one), use SDL_GetWindowWMInfo to get a pointer to the app’s UIWindow, then use the ‘rootViewController’ method on the UIWindow to get the view controller. Here’s some extremely rough example code:
Code:
// Retrieve SDL’s root UIViewController (iOS only!)
// This function is completely NOT guaranteed to work in the future.
// Use it at your own risk!
UIViewController * GetSDLViewController(SDL_Window * sdlWindow)
{
SDL_SysWMinfo systemWindowInfo;
SDL_VERSION(&systemWindowInfo.version);
if ( ! SDL_GetWindowWMInfo(sdlWindow, &systemWindowInfo)) {
// consider doing some kind of error handling here
return nil;
}
UIWindow * appWindow = mainWindowWMInfo.info.uikit.window;
UIViewController * rootViewController = appWindow.rootViewController;
return rootViewController;
}
With this, one or more UIKit controls could then be added to the screen as such:
Code:
void SetupIOSControls(SDL_Window * sdlWindow)
{
UIViewController * rootViewController = GetSDLViewController(sdlWindow);
if ( ! rootViewController ) {
// handle this error as appropriate
} else {
UIView * myView = /* create and configure a UIView, or an appropriate subclass of UIView, such as UITextField */
[rootViewController.view addSubview:myView];
[myView release]; // This line probably isn’t necessary if ARC is being used.
}
}
leadro wrote:
I need to integrate the SDL features for drawing images into iOS application.
But, as I say previously, I have a problem with showing UIKit controls over SDL_Window + SDL_Renderer
UIKit is very much capable of drawing images. Is there some feature that SDL has that UIKit doesn’t have, outside of platform-independence, that you’re looking for? The code you posted looks fairly iOS-centric and non-portable. I’m wondering if you wouldn’t just be happier and/or better off using UIKit instead of SDL for the time being.