~ubuntu-branches/ubuntu/raring/vice/raring

« back to all changes in this revision

Viewing changes to src/arch/unix/macosx/cocoa/view/peripheraldrawer.m

  • Committer: Bazaar Package Importer
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2009-03-31 00:37:15 UTC
  • mfrom: (1.1.7 upstream) (9.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090331003715-i5yisvcfv7mgz3eh
Tags: 2.1.dfsg-1
* New major upstream release (closes: #495937).
* Add desktop files (closes: #501181).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * peripheraldrawer.m - PeripheralDrawer
3
 
 *
4
 
 * Written by
5
 
 *  Christian Vogelgsang <chris@vogelgsang.org>
6
 
 *  Michael Klein <michael.klein@puffin.lb.shuttle.de>
7
 
 *
8
 
 * This file is part of VICE, the Versatile Commodore Emulator.
9
 
 * See README for copyright notice.
10
 
 *
11
 
 *  This program is free software; you can redistribute it and/or modify
12
 
 *  it under the terms of the GNU General Public License as published by
13
 
 *  the Free Software Foundation; either version 2 of the License, or
14
 
 *  (at your option) any later version.
15
 
 *
16
 
 *  This program is distributed in the hope that it will be useful,
17
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 
 *  GNU General Public License for more details.
20
 
 *
21
 
 *  You should have received a copy of the GNU General Public License
22
 
 *  along with this program; if not, write to the Free Software
23
 
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
24
 
 *  02111-1307  USA.
25
 
 *
26
 
 */
27
 
 
28
 
#include "vice.h"
29
 
#include "log.h"
30
 
#include "machine.h"
31
 
 
32
 
#import <Cocoa/Cocoa.h>
33
 
#import "peripheraldrawer.h"
34
 
#import "vicenotifications.h"
35
 
#import "vicewindow.h"
36
 
 
37
 
#define PERIPH_WIDTH            100
38
 
#define PERIPH_HEIGHT           22
39
 
 
40
 
/* ============================================================== */
41
 
 
42
 
@interface FlippedView : NSView
43
 
@end
44
 
 
45
 
@implementation FlippedView : NSView
46
 
- (BOOL)isFlipped
47
 
{
48
 
    return YES;
49
 
}
50
 
@end
51
 
 
52
 
/* ============================================================== */
53
 
 
54
 
@implementation PeripheralDrawer
55
 
 
56
 
- (id)initWithPreferredEdge:(NSRectEdge)edge
57
 
{
58
 
    if ((self = [super initWithContentSize:NSMakeSize(PERIPH_WIDTH, PERIPH_HEIGHT)
59
 
                             preferredEdge:edge]) != nil)
60
 
    {
61
 
        [self setMinContentSize:NSMakeSize(PERIPH_WIDTH, 5*PERIPH_HEIGHT)];
62
 
 
63
 
        led_color[0] = [[NSColor redColor] retain];
64
 
        led_color[1] = [[NSColor greenColor] retain];
65
 
 
66
 
        FlippedView * v = [[FlippedView alloc]
67
 
            initWithFrame:NSMakeRect(0,0,PERIPH_WIDTH,PERIPH_HEIGHT)];
68
 
        [v setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)];
69
 
 
70
 
        [[NSNotificationCenter defaultCenter] addObserver:self
71
 
                                                 selector:@selector(enableDriveStatus:)
72
 
                                                     name:VICEEnableDriveStatusNotification
73
 
                                                   object:nil];
74
 
 
75
 
        int i;
76
 
        for (i = 0; i < DRIVE_NUM; i++)
77
 
        {
78
 
            NSRect rect = NSMakeRect(0, 0, PERIPH_WIDTH, PERIPH_HEIGHT*2);
79
 
            drive_view[i] = [[DriveView alloc] initWithFrame:rect driveNumber:i];
80
 
            [drive_view[i] setAutoresizingMask: NSViewWidthSizable];
81
 
        }
82
 
 
83
 
        tape_view = [[TapeView alloc] initWithFrame:NSMakeRect(0, 0, PERIPH_WIDTH, PERIPH_HEIGHT)];
84
 
        [tape_view setAutoresizingMask: NSViewWidthSizable];
85
 
 
86
 
//        [self setTapeStatus:0];
87
 
        [v addSubview:tape_view];
88
 
 
89
 
        [self setContentView:v];
90
 
    }
91
 
 
92
 
    return self;
93
 
}
94
 
 
95
 
- (void)dealloc
96
 
{
97
 
    int i;
98
 
    [led_color[0] release];
99
 
    [led_color[1] release];
100
 
 
101
 
    for (i = 0; i < DRIVE_NUM; i++)
102
 
    {
103
 
        [drive_view[i] release];
104
 
    }
105
 
 
106
 
    [tape_view release];
107
 
    [super dealloc];
108
 
}
109
 
 
110
 
- (void)enableDriveStatus:(NSNotification*)notification
111
 
{
112
 
    NSDictionary * dict = [notification userInfo];
113
 
    int drive_led_color = [[dict objectForKey:@"drive_led_color"] intValue];
114
 
    int enable = [[dict objectForKey:@"enabled_drives"] intValue];
115
 
 
116
 
    float width = NSWidth([[self contentView] bounds]);
117
 
 
118
 
    int i, count = 0;
119
 
    for(i = 0; i < DRIVE_NUM; i++)
120
 
    {
121
 
        int flag = 1<<i;
122
 
        if(enable & flag)
123
 
        {
124
 
            int colorIndex = (drive_led_color & flag) != 0 ? 1 : 0; 
125
 
            [[self contentView] addSubview:drive_view[i]];
126
 
            [drive_view[i] initLedColor:led_color[colorIndex]];
127
 
            [drive_view[i] setFrame:NSMakeRect(0, count * PERIPH_HEIGHT * 2, width, PERIPH_HEIGHT*2)];
128
 
            count++;
129
 
        }
130
 
        else
131
 
        {
132
 
            [drive_view[i] removeFromSuperview];
133
 
        }
134
 
    }
135
 
 
136
 
    // reposition tape display and rec/play field
137
 
    [tape_view setFrame:NSMakeRect(0, count++ * PERIPH_HEIGHT * 2, width, PERIPH_HEIGHT)];
138
 
    [[self contentView] setNeedsDisplay:YES];
139
 
}
140
 
 
141
 
- (void)setTapeStatus:(int)status
142
 
{
143
 
    [tape_view setEnabled:status];
144
 
    [[self contentView] setNeedsDisplay:YES];
145
 
}
146
 
 
147
 
@end