istereo2
diff src/ios/viewctl.m @ 1:2d5abf441307
ads done
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Sep 2015 23:02:50 +0300 |
parents | 7841e9365065 |
children | 81d35769f546 |
line diff
1.1 --- a/src/ios/viewctl.m Wed Sep 16 07:10:02 2015 +0300 1.2 +++ b/src/ios/viewctl.m Fri Sep 18 23:02:50 2015 +0300 1.3 @@ -3,10 +3,16 @@ 1.4 1.5 @interface ViewController () { 1.6 EAGLContext *ctx; 1.7 + 1.8 + ADBannerView *ad; 1.9 + BOOL ad_visible; 1.10 } 1.11 1.12 -- (void)initgl; 1.13 -- (void)destroygl; 1.14 + 1.15 +- (void)create_ad; 1.16 + 1.17 +- (void)init_gl; 1.18 +- (void)destroy_gl; 1.19 @end 1.20 1.21 @implementation ViewController 1.22 @@ -24,12 +30,15 @@ 1.23 view.context = self->ctx; 1.24 view.drawableDepthFormat = GLKViewDrawableDepthFormat24; 1.25 1.26 - [self initgl]; 1.27 + [self create_ad]; 1.28 + 1.29 + 1.30 + [self init_gl]; 1.31 } 1.32 1.33 - (void)dealloc 1.34 { 1.35 - [self destroygl]; 1.36 + [self destroy_gl]; 1.37 1.38 if([EAGLContext currentContext] == self->ctx) { 1.39 [EAGLContext setCurrentContext: nil]; 1.40 @@ -43,7 +52,7 @@ 1.41 if([self isViewLoaded] && ([[self view] window] == nil)) { 1.42 self.view = nil; 1.43 1.44 - [self destroygl]; 1.45 + [self destroy_gl]; 1.46 1.47 if([EAGLContext currentContext] == self->ctx) { 1.48 [EAGLContext setCurrentContext: nil]; 1.49 @@ -59,25 +68,55 @@ 1.50 return YES; 1.51 } 1.52 1.53 -- (void)initgl 1.54 +- (void)create_ad 1.55 +{ 1.56 + ad_visible = NO; 1.57 + ad = [[ADBannerView alloc] initWithAdType: ADAdTypeBanner]; 1.58 + [ad setAutoresizingMask: UIViewAutoresizingFlexibleWidth]; 1.59 + ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); 1.60 + [self.view addSubview: ad]; 1.61 + ad.delegate = self; 1.62 +} 1.63 + 1.64 +- (void)init_gl 1.65 { 1.66 [EAGLContext setCurrentContext: self->ctx]; 1.67 1.68 glClearColor(1.0, 0.0, 0.0, 1.0); 1.69 } 1.70 1.71 -- (void)destroygl 1.72 +- (void)destroy_gl 1.73 { 1.74 [EAGLContext setCurrentContext: self->ctx]; 1.75 } 1.76 1.77 -- (void)update 1.78 -{ 1.79 -} 1.80 1.81 - (void)glkView: (GLKView*)view drawInRect: (CGRect)rect 1.82 { 1.83 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 1.84 } 1.85 1.86 +// ADBannerDelegate functions 1.87 + 1.88 +- (void)bannerViewDidLoadAd: (ADBannerView*)banner 1.89 +{ 1.90 + if(!ad_visible) { 1.91 + CGRect rect = ad.frame; 1.92 + rect.origin.y = 0; 1.93 + ad.frame = rect; 1.94 + ad_visible = YES; 1.95 + } 1.96 +} 1.97 + 1.98 +- (void)bannerView: (ADBannerView*)banner didFailToReceiveAdWithError: (NSError*)error 1.99 +{ 1.100 + if(ad_visible) { 1.101 + ad_visible = NO; 1.102 + ad.frame = CGRectOffset(ad.frame, 0, -ad.frame.size.height); 1.103 + } 1.104 + 1.105 + NSLog(@"Failed to retrieve ad"); 1.106 +} 1.107 + 1.108 + 1.109 @end /* implementation ViewController */