From 2d496c2b4d4edae4ea4727b7d5873207e2e7cc7b Mon Sep 17 00:00:00 2001 From: Timur Pocheptsov <Timur.Pocheptsov@cern.ch> Date: Tue, 25 Oct 2011 12:16:50 +0000 Subject: [PATCH] Modify SlideViewController to use external pads. git-svn-id: http://root.cern.ch/svn/root/trunk@41569 27541ba8-7e3a-0410-8455-c3a389f83636 --- test/ios/RootBrowser/SlideView.h | 3 +- test/ios/RootBrowser/SlideView.m | 12 ++++++-- test/ios/RootBrowser/SlideshowController.h | 1 - test/ios/RootBrowser/SlideshowController.mm | 34 +++++++-------------- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/test/ios/RootBrowser/SlideView.h b/test/ios/RootBrowser/SlideView.h index d90217ff9b0..e67486bde70 100644 --- a/test/ios/RootBrowser/SlideView.h +++ b/test/ios/RootBrowser/SlideView.h @@ -15,6 +15,7 @@ class Pad; + (CGSize) slideSize; + (CGRect) slideFrame; -- (id) initWithFrame : (CGRect)rect andPad : (ROOT::iOS::Pad *)pad; +- (id) initWithFrame : (CGRect)rect; +- (void) setPad : (ROOT::iOS::Pad *)pad; @end diff --git a/test/ios/RootBrowser/SlideView.m b/test/ios/RootBrowser/SlideView.m index 8e914946e8e..a3c4d1d4d04 100644 --- a/test/ios/RootBrowser/SlideView.m +++ b/test/ios/RootBrowser/SlideView.m @@ -23,13 +23,11 @@ static const CGRect slideFrame = CGRectMake(0.f, 0.f, 650.f, 650.f); } //____________________________________________________________________________________________________ -- (id) initWithFrame : (CGRect)frame andPad : (ROOT::iOS::Pad *)p +- (id) initWithFrame : (CGRect)frame { self = [super initWithFrame : frame]; if (self) { - pad = p; - self.layer.shadowOpacity = 0.3f; self.layer.shadowColor = [UIColor blackColor].CGColor; self.layer.shadowOffset = CGSizeMake(10.f, 10.f); @@ -39,6 +37,11 @@ static const CGRect slideFrame = CGRectMake(0.f, 0.f, 650.f, 650.f); return self; } +- (void) setPad : (ROOT::iOS::Pad *)newPad +{ + pad = newPad; +} + //____________________________________________________________________________________________________ - (void) drawRect : (CGRect)rect { @@ -47,6 +50,9 @@ static const CGRect slideFrame = CGRectMake(0.f, 0.f, 650.f, 650.f); CGContextSetRGBFillColor(ctx, 1.f, 1.f, 1.f, 1.f); CGContextFillRect(ctx, rect); + if (!pad) + return; + CGContextTranslateCTM(ctx, 0.f, rect.size.height); CGContextScaleCTM(ctx, 1.f, -1.f); diff --git a/test/ios/RootBrowser/SlideshowController.h b/test/ios/RootBrowser/SlideshowController.h index 19dc6ded885..8dcd18428dc 100644 --- a/test/ios/RootBrowser/SlideshowController.h +++ b/test/ios/RootBrowser/SlideshowController.h @@ -13,7 +13,6 @@ class Pad; @interface SlideshowController : UIViewController <UIScrollViewDelegate> { @private - ROOT::iOS::Pad *pads[2]; SlideView *padViews[2];//The current and the next in a slide show. unsigned visiblePad; diff --git a/test/ios/RootBrowser/SlideshowController.mm b/test/ios/RootBrowser/SlideshowController.mm index 269be2bbe94..6a111aaea0f 100644 --- a/test/ios/RootBrowser/SlideshowController.mm +++ b/test/ios/RootBrowser/SlideshowController.mm @@ -47,29 +47,21 @@ nObjects = 2; for (unsigned i = 0; i < nObjects; ++i) { - pads[i] = new ROOT::iOS::Pad(padFrame.size.width, padFrame.size.height); - padViews[i] = [[SlideView alloc] initWithFrame : padFrame andPad : pads[i]]; + padViews[i] = [[SlideView alloc] initWithFrame : padFrame]; [padParentView addSubview : padViews[i]]; padViews[i].hidden = YES; + [padViews[i] release]; } } -//____________________________________________________________________________________________________ -- (void) drawObject : (TObject *)obj inAPad : (ROOT::iOS::Pad *)pad option : (const char *)opt -{ - pad->cd(); - pad->Clear(); - obj->Draw(opt); -} - //____________________________________________________________________________________________________ - (id)initWithNibName : (NSString *)nibNameOrNil bundle : (NSBundle *)nibBundleOrNil fileContainer : (ROOT::iOS::FileContainer *)container { self = [super initWithNibName : nibNameOrNil bundle : nibBundleOrNil]; - [self view]; - if (self) { + [self view]; + fileContainer = container; if (fileContainer->GetNumberOfObjects()) { @@ -78,11 +70,11 @@ nCurrentObject = 0; visiblePad = 0; - [self drawObject : fileContainer->GetObject(0) inAPad : pads[0] option:fileContainer->GetDrawOption(0)]; + [padViews[0] setPad : fileContainer->GetPadAttached(0)]; [padViews[0] setNeedsDisplay]; if (fileContainer->GetNumberOfObjects() > 1) { - [self drawObject : fileContainer->GetObject(1) inAPad : pads[1] option:fileContainer->GetDrawOption(1)]; + [padViews[1] setPad:fileContainer->GetPadAttached(1)]; [padParentView addSubview : padViews[1]]; } @@ -94,14 +86,8 @@ } //____________________________________________________________________________________________________ -- (void)dealloc +- (void) dealloc { - for (unsigned i = 0; i < 2; ++i) { - //Delete for null and message to nil means nothing. - delete pads[i]; - [padViews[i] release]; - } - if (timer) [timer invalidate]; @@ -147,7 +133,8 @@ //____________________________________________________________________________________________________ - (void) viewDidAppear : (BOOL)animated { - timer = [NSTimer scheduledTimerWithTimeInterval : 2.f target : self selector : @selector(changeViews) userInfo : nil repeats : YES]; + if (fileContainer->GetNumberOfObjects() > 1) + timer = [NSTimer scheduledTimerWithTimeInterval : 2.f target : self selector : @selector(changeViews) userInfo : nil repeats : YES]; } @@ -174,6 +161,7 @@ } #pragma mark - Animation. + //____________________________________________________________________________________________________ - (void) changeViews { @@ -197,7 +185,7 @@ nCurrentObject + 1 == fileContainer->GetNumberOfObjects() ? nCurrentObject = 0 : ++nCurrentObject; visiblePad = viewToShow; const unsigned next = nCurrentObject + 1 == fileContainer->GetNumberOfObjects() ? 0 : nCurrentObject + 1; - [self drawObject : fileContainer->GetObject(next) inAPad : pads[viewToHide] option : fileContainer->GetDrawOption(next)]; + [padViews[viewToHide] setPad : fileContainer->GetPadAttached(next)]; [padViews[viewToHide] setNeedsDisplay]; } -- GitLab