//
//  MyView.m
//  CyTV
//
//  Created by Andreas Junghans on Sun Jun 06 2004.
//  Copyright (c) 2004 Andreas Junghans. All rights reserved.
//
//  Some of the code here is copied from Apple example code.
//

#import "MyView.h"

@implementation MyView

//This routine is called at app launch time when this class is unpacked from the nib.
//We get set up here. [Comment copied from Apple example code]
- (void)awakeFromNib
{
    // load the overlay images (relative to the resources dir)
    _skipForwardImage = [NSImage imageNamed:@"overlay_skipForward"];
    _skipBackwardImage = [NSImage imageNamed:@"overlay_skipBackward"];
    _channelUpImage = [NSImage imageNamed:@"overlay_channelUp"];
    _channelDownImage = [NSImage imageNamed:@"overlay_channelDown"];

    //tell ourselves that we need displaying
    // [Comment copied from Apple example code]
    [self setNeedsDisplay:YES];
}


- (void)drawRect:(NSRect)rect
{
    [[NSColor clearColor] set];
    NSRectFill([self frame]);
    
    if (_currentImage != nil) {
        NSSize currentSize = [_currentImage size];
        NSPoint dest = {
            ([self frame].size.width - currentSize.width)/2,
            ([self frame].size.height - currentSize.height)/2
        };
        [_currentImage compositeToPoint:dest operation:NSCompositeSourceOver];
    }
}

- (void)setOverlay:(int)overlayConstant {
    if (overlayConstant == overlaySkipForward) {
        _currentImage = _skipForwardImage;
    } else if (overlayConstant == overlaySkipBackward) {
        _currentImage = _skipBackwardImage;
    } else if (overlayConstant == overlayChannelUp) {
        _currentImage = _channelUpImage;
    } else if (overlayConstant == overlayChannelDown) {
        _currentImage = _channelDownImage;
    }
}

@end
