1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| //
// Waiting_Screen.m
#import "Waiting_Screen.h"
#import <QuartzCore/QuartzCore.h>
#import <mach/mach_time.h>
#import "../AppData.h"
#import "../Utils/Utils.h"
@implementation Waiting_Screen
- (id) initWithFrame:(CGRect) frame {
self = [super initWithFrame:frame];
if (self != nil) {
// Initialization code
current_percent = 0.0f;
self.backgroundColor = [UIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
is_busy = NO;
mach_timebase_info_data_t info;
mach_timebase_info(&info);
delta = (double) (info.numer / info.denom / 1000000000.0);
last_time = 0;
begin_R = begin_G = begin_B = 0.0f;
end_R = end_G = end_B = 0.0f;
begin_percent = 0.0f; end_percent = 1.0f;
}
return self;
}
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void) drawRect:(CGRect) rect {
// Drawing code
[super drawRect:rect];
CGContextRef context = UIGraphicsGetCurrentContext();
CGRect frame = CGRectMake(rect.origin.x, rect.origin.y,rect.size.width, rect.size.height);
CGContextSetRGBFillColor(context, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(context, frame);
float current_R = (begin_R + ((current_percent - begin_percent) * (end_R - begin_R) / (end_percent - begin_percent)));
float current_G = (begin_G + ((current_percent - begin_percent) * (end_G - begin_G) / (end_percent - begin_percent)));
float current_B = (begin_B + ((current_percent - begin_percent) * (end_B - begin_B) / (end_percent - begin_percent)));
float position = (self.frame.size.width * current_percent / 100.0f);
CGContextSetLineWidth(context, 2);
CGContextSetRGBStrokeColor(context, (current_R / 255.0f), (current_G / 255.0f), (current_B / 255.0f), 1.0f);
CGContextMoveToPoint(context, 0, ((self.frame.size.height / 2.0) - 1.0f));
CGContextAddLineToPoint(context, position, ((self.frame.size.height / 2.0) - 1.0f));
CGContextStrokePath(context);
// DLOG( (@"Waiting_Screen::drawRect - (0 -> %f) (%f, %f, %f)", position, current_R, current_G, current_B) )
}
- (void) update_screen {
if (is_busy) { return; }
is_busy = YES;
uint64_t now = mach_absolute_time();
if (last_time == 0) { last_time = now; }
double delta_time = (double) ((now - last_time) * delta);
if (delta_time > (TIME_WAITING_DURATION / 1000.0f)) { delta_time = (TIME_WAITING_DURATION / 1000.0f); }
current_percent = (0.0f + (delta_time * 100.0f / (TIME_WAITING_DURATION / 1000.0f)));
if (current_percent >= 99.0f) { last_time = now; }
// DLOG( (@"Waiting_Screen::update_screen - Current Percent: %f", current_percent) )
if ((current_percent > 0) && (current_percent < 25.0f)) {
begin_R = 255; begin_G = 255; begin_B = 255;
end_R = 246; end_G = 3; end_B = 220;
begin_percent = 0.0f; end_percent = 25.0f;
} else if ((current_percent > 25.0f) && (current_percent < 50.0f)) {
begin_R = 246; begin_G = 3; begin_B = 220;
end_R = 246; end_G = 101; end_B = 3;
begin_percent = 25.0f; end_percent = 50.0f;
} else if ((current_percent > 50.0f) && (current_percent < 75.0f)) {
begin_R = 246; begin_G = 101; begin_B = 3;
end_R = 249; end_G = 21; end_B = 0;
begin_percent = 50.0f; end_percent = 75.0f;
} else if (current_percent > 75.0f) {
begin_R = 249; begin_G = 21; begin_B = 0;
end_R = 254; end_G = 227; end_B = 25;
begin_percent = 75.0f; end_percent = 100.0f;
}
[self setNeedsDisplay];
is_busy = NO;
}
- (void) start_animation {
AppData* data = [AppData sharedData];
[data add_graphic_update:self];
}
- (void) stop_animation {
AppData* data = [AppData sharedData];
[data stop_graphic_update];
}
@end |
Partager