Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
adding UIKit elements via plugins — Gideros Forum

adding UIKit elements via plugins

atilimatilim Maintainer
edited December 2011 in Bugs and issues
Hi,

In Gideros, OpenGL rendering is done on a different thread (to make touchs more responsive). But this may have problems while adding subviews to the OpenGL view. To overcome this issue, the OpenGL view should be separate from other views. If you have problems while adding UIKit elements, you need to make this modifications to the Xcode project:

1. remove gdr_initialize and gdr_deinitialize functions from GiderosiPhonePlayerViewController.mm

2. add
#import "EAGLView.h"
to the GiderosiPhonePlayerAppDelegate.mm

3. replace application:didFinishLaunchingWithOptions: function with:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIView* glView = self.viewController.view;
    UIView* rootView = [[UIView alloc] initWithFrame:[self.window bounds]];
    [rootView addSubview:glView];
    self.viewController.view = rootView;
    [rootView release];
 
    gdr_initialize((EAGLView *)glView, 320, 480, true);
 
#if 0	// waiting for dropping iOS 3.x compatibility
    self.window.rootViewController = self.viewController;
#else
    [self.window addSubview:self.viewController.view];
#endif
 
    return YES;
}
4. replace applicationWillTerminate: function with:
- (void)applicationWillTerminate:(UIApplication *)application
{
    gdr_exitGameLoop();
    [self.viewController stopAnimation];
    gdr_deinitialize();
}
This modification will be available with the next version.

@MikeHart, did you encounter any problems while adding buttons, webview, etc?

best,

Comments

  • Nope, I am using a different approach. If I use the rootview, then app rendering stops when a webview is shown for an example. An Altert doesn't stop it.

    I am at work and don't have access to my mac. Will let you know later how I did it so far.
  • Here is how I add a button:
    - (void)AddButton:(NSString*) caption, float x1,float y1, float x2, float y2 {
    	//create the button
    	UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     
    	//set the position of the button
    	button.frame = CGRectMake(x1, y1, x2, y2);
     
    	//set the button's title
    	[button setTitle:caption forState:UIControlStateNormal];
     
    	//listen for clicks
    	[button addTarget:self action:<a href="https://forum.giderosmobile.com/profile/selector%28buttonPressed" rel="nofollow">@selector(buttonPressed</a><img class="emoji" src="https://forum.giderosmobile.com/resources/emoji/smile.png" title=":)" alt=":)" height="20" />
    	 forControlEvents:UIControlEventTouchUpInside];
     
    	//add the button to the view
    	[[[UIApplication sharedApplication] keyWindow] addSubview:button];
    }
  • atilimatilim Maintainer
    edited December 2011
    I understand now :) This is a better way to not to mess up with OpenGL view.
  • MikeHartMikeHart Guru
    edited December 2011
    Maybe, I just saw this way in an Monkey module implementation and tried it. It seems to work. Btw, I send you a private message on the board.
Sign In or Register to comment.