source: trunk/SapphireFrappliance/FRAppliance/SapphireWaitDisplay.m @ 967

Revision 967, 4.1 KB checked in by gbooker, 4 years ago (diff)

Correctly center the spinner

Line 
1/*
2 * SapphireWaitDisplay.m
3 * Sapphire
4 *
5 * Created by Graham Booker on Feb. 11 2009.
6 * Copyright 2008 Sapphire Development Team and/or www.nanopi.net
7 * All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
10 * General Public License as published by the Free Software Foundation; either version 3 of the License,
11 * or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
14 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
15 * Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with this program; if not,
18 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 */
20
21#import "SapphireWaitDisplay.h"
22#import <SapphireCompatClasses/SapphireFrontRowCompat.h>
23#import "SapphireApplianceController.h"
24
25
26@implementation SapphireWaitDisplay
27
28- (id) initWithScene:(BRRenderScene *)scene title:(NSString *)title invokation:(NSInvocation *)invokation
29{
30        self = [super initWithScene:scene];
31        if(self == nil)
32                return self;
33       
34        [self setListTitle:title];
35        invoke = [invokation retain];
36        [invoke retainArguments];
37       
38        status = [SapphireFrontRowCompat newTextControlWithScene:scene];
39        if([BRWaitSpinnerControl instancesRespondToSelector:@selector(initWithScene:)])
40                spinner = [[BRWaitSpinnerControl alloc] initWithScene:scene];
41        else
42                spinner = [[BRWaitSpinnerControl alloc] init];
43       
44        if([SapphireFrontRowCompat usingLeopard])
45        {
46                [spinner release];
47                spinner = [[BRWaitSpinnerLayer alloc] init];
48        }
49       
50        [self doMyLayout];
51       
52        [self addControl:status];
53        if([SapphireFrontRowCompat usingLeopard])
54                [SapphireFrontRowCompat addSublayer:spinner toControl:self];
55        else
56                [self addControl:spinner];
57       
58        [SapphireLayoutManager setCustomLayoutOnControl:self];
59       
60        return self;
61       
62}
63
64- (void)doMyLayout
65{
66        NSRect frame = [SapphireFrontRowCompat frameOfController:self];
67        NSRect newFrame;
68        newFrame.size.width = newFrame.size.height = frame.size.height / 6.0f;
69        newFrame.origin.y += (frame.size.height - newFrame.size.height) / 2.0f;
70        newFrame.origin.x = (frame.size.width - newFrame.size.width) / 2.0f;
71        [spinner setFrame:newFrame] ;
72}
73
74- (void) dealloc
75{
76        [spinner release];
77        [status release];
78        [invoke release];
79        [super dealloc];
80}
81
82- (void)realCurrentStatus:(NSString *)stat;
83{
84        if(stat == nil)
85                stat = @"";
86        [SapphireFrontRowCompat setText:stat withAtrributes:[SapphireFrontRowCompat paragraphTextAttributes] forControl:status];
87       
88        NSRect master = [SapphireFrontRowCompat frameOfController:self];
89        NSSize progressSize = [SapphireFrontRowCompat textControl:status renderedSizeWithMaxSize:NSMakeSize(master.size.width, master.size.height * 0.3f)];
90       
91        NSRect frame;
92        frame.origin.x =  (master.size.width) * 0.1f;
93        frame.origin.y = (master.size.height * 0.12f) + master.origin.y;
94        frame.size = progressSize;
95        [status setFrame:frame];
96}
97
98- (void)setCurrentStatus:(NSString *)stat;
99{
100        if(runInThread)
101                [self performSelectorOnMainThread:@selector(realCurrentStatus:) withObject:stat waitUntilDone:YES];
102        else
103        {
104                [self realCurrentStatus:stat];
105                [[NSRunLoop currentRunLoop] runUntilDate:[[NSDate date] addTimeInterval:1]];
106        }
107}
108
109- (void)finished
110{
111        BRControl *ret = nil;
112        [invoke getReturnValue:&ret];
113        completed = YES;
114       
115        if(!noPopWhenComplete)
116        {
117                if(ret == nil)
118                        [[self stack] popController];
119                else
120                        [[self stack] swapController:ret];
121        }
122        else if(ret != nil)
123                [[self stack] pushController:ret];
124}
125
126- (void)start
127{
128        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
129       
130        [invoke invoke];
131       
132        [self performSelectorOnMainThread:@selector(finished) withObject:nil waitUntilDone:YES];
133        [pool drain];
134}
135
136- (void)wasPushed
137{
138        [super wasPushed];
139        [SapphireFrontRowCompat setSpinner:spinner toSpin:YES];
140        if(runInThread)
141                [NSThread detachNewThreadSelector:@selector(start) toTarget:self withObject:nil];
142        else
143                [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(start) userInfo:nil repeats:NO];
144}
145
146- (BOOL)brEventAction:(BREvent *)event
147{
148        if(!completed)
149                return YES;
150        return [super brEventAction:event];
151}
152
153@end
Note: See TracBrowser for help on using the repository browser.