Mixing guis

For Apple specific issues

Mixing guis

Postby masshacker » Tue Oct 11, 2011 3:30 pm

Hi, I have a couple of questions about mixing JUCE and native IOS guis.

First question:
Where do I need to include the native IOS files in order to get the native stuff? I'm using the Introjucer for my projects (modules branch), so all project files have this in the beginning:

Code: Select all
#include "../JuceLibraryCode/JuceHeader.h"


When I try to include a file like SomeFile.mm, which includes, let's say, <UIKit/UIKit.h>, I get more than 1000 errors...

Second question:
Is it possible to embed a JUCE Component inside a UIScrollView?
If the answer is yes, then how can I do it?

Thanks,
masshacker
User avatar
masshacker
JUCE UberWeenie
 
Posts: 314
Joined: Thu Jan 08, 2009 10:53 am

Re: Mixing guis

Postby masshacker » Tue Oct 11, 2011 4:59 pm

Nevermind question 1... I did it.
User avatar
masshacker
JUCE UberWeenie
 
Posts: 314
Joined: Thu Jan 08, 2009 10:53 am

Re: Mixing guis

Postby dave96 » Tue Oct 11, 2011 10:49 pm

This was niggling at me so gave it a go and yes, it is definitely possible, a little convoluted but this process could probably be simplified using a static helper method.

Simply create a UIScrollView in your xib file and an accompanying property in your view controller class's header. Make sure you synthesize the property in your implementation and attach it from your 'File's Owner' in Interface Builder to your UIScrollView.

Now you have to do a bit of Juce trickery to add your component to a UIView first. Create one with the size you want your content to be. Then add your component to the UIView you have just created, make it visible and set its bounds to that of the UIView. Then you need to update the UIScrollView's contentSize property with your UIView's bounds. Finally you need to add your UIView to to your UIScrollView.

The code might help make sense of that:
Code: Select all
@interface MainViewController : UIViewController
{
    TextButton textButton;
}

@property (nonatomic, retain) IBOutlet UIScrollView* scrollView;

@end


and in the implementation file:
Code: Select all
@implementation MainViewController

@synthesize scrollView;

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIView* contentUIView = [[UIView alloc] initWithFrame:CGRectMake(0, 0,                                  // x,y offset
                                                                     scrollView.bounds.size.width * 2,      // content width
                                                                     scrollView.bounds.size.height * 2)];   // content height
   
    textButton.addToDesktop (0, (void*) contentUIView);
    textButton.setVisible (true);
    textButton.setBounds(contentUIView.bounds.origin.x, contentUIView.bounds.origin.y,
                         contentUIView.bounds.size.width, contentUIView.bounds.size.height);

    scrollView.contentSize = contentUIViewForScrollToHold.bounds.size;
       
    [scrollView addSubview:contentUIView];
    [contentUIView release];
}

@end


I'm not sure how this would react if you changed the scroll view's size or the internal UIView's size, you would probably have to update the component's size as well. The other problem is that any transparency in Juce components seems to just be black, I haven't really looked into this yet.

If you make any improvements to this let us know because mixing iOS and Juce is something I'm sure a lot of people want to do.
dave96
JUCE UberWeenie
 
Posts: 462
Joined: Sat Dec 27, 2008 9:29 pm

Re: Mixing guis

Postby masshacker » Wed Oct 12, 2011 11:25 am

Thank you very much dave, this worked great!
I'll keep you posted if I'll get any improvements, I'm sure many others here would find it useful too.
User avatar
masshacker
JUCE UberWeenie
 
Posts: 314
Joined: Thu Jan 08, 2009 10:53 am


Return to MacOSX and iOS

Who is online

Users browsing this forum: No registered users and 1 guest