Search
lxdream.org :: lxdream/src/cocoaui/cocoa_win.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_win.c
changeset 681:1755a126b109
next705:03dd1ea35c69
author nkeynes
date Sat Jun 14 11:54:15 2008 +0000 (15 years ago)
permissions -rw-r--r--
last change Change colour params to float
Convert background processing over to scene structure (fixes some depth issues as well)
Add color unclamp when supported
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/cocoaui/cocoa_win.c Sat Jun 14 11:54:15 2008 +0000
1.3 @@ -0,0 +1,190 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Construct and maintain the main window under cocoa.
1.8 + *
1.9 + * Copyright (c) 2008 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include "cocoaui/cocoaui.h"
1.23 +#include "lxdream.h"
1.24 +#include <ApplicationServices/ApplicationServices.h>
1.25 +
1.26 +#define STATUSBAR_HEIGHT 20
1.27 +
1.28 +@interface LxdreamToolbarDelegate : NSObject {
1.29 + NSArray *identifiers;
1.30 + NSArray *defaults;
1.31 + NSDictionary *items;
1.32 +}
1.33 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
1.34 + tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action;
1.35 +@end
1.36 +
1.37 +@implementation LxdreamToolbarDelegate
1.38 +- (id) init
1.39 +{
1.40 + NSToolbarItem *mount = [self createToolbarItem: @"GdromMount" label: @"Open Image"
1.41 + tooltip: @"Mount a cdrom disc" icon: @"tb-cdrom"
1.42 + action: @selector(mount_action:)];
1.43 + NSToolbarItem *reset = [self createToolbarItem: @"Reset" label: @"Reset"
1.44 + tooltip: @"Reset dreamcast" icon: @"tb-reset"
1.45 + action: @selector(reset_action:)];
1.46 + NSToolbarItem *pause = [self createToolbarItem: @"Pause" label: @"Pause"
1.47 + tooltip: @"Pause dreamcast" icon: @"tb-pause"
1.48 + action: @selector(pause_action:)];
1.49 + NSToolbarItem *run = [self createToolbarItem: @"Run" label: @"Resume"
1.50 + tooltip: @"Resume" icon: @"tb-run"
1.51 + action: @selector(run_action:)];
1.52 + NSToolbarItem *load = [self createToolbarItem: @"LoadState" label: @"Load State..."
1.53 + tooltip: @"Load an lxdream save state" icon: @"tb-load"
1.54 + action: @selector(load_action:)];
1.55 + NSToolbarItem *save = [self createToolbarItem: @"SaveState" label: @"Save State..."
1.56 + tooltip: @"Create an lxdream save state" icon: @"tb-save"
1.57 + action: @selector(save_action:)];
1.58 + [pause setEnabled: NO];
1.59 + identifiers =
1.60 + [NSArray arrayWithObjects: @"GdromMount", @"Reset", @"Pause", @"Run", @"LoadState", @"SaveState", nil ];
1.61 + defaults =
1.62 + [NSArray arrayWithObjects: @"GdromMount", @"Reset", @"Pause", @"Run",
1.63 + NSToolbarSeparatorItemIdentifier, @"LoadState", @"SaveState", nil ];
1.64 + NSArray *values = [NSArray arrayWithObjects: mount, reset, pause, run, load, save, nil ];
1.65 + items = [NSDictionary dictionaryWithObjects: values forKeys: identifiers];
1.66 + return self;
1.67 +}
1.68 +
1.69 +- (NSToolbarItem *) createToolbarItem: (NSString *)id label: (NSString *) label
1.70 + tooltip: (NSString *)tooltip icon: (NSString *)icon action: (SEL) action
1.71 +{
1.72 + NSToolbarItem *item = [[NSToolbarItem alloc] initWithItemIdentifier: id];
1.73 + [item setLabel: label];
1.74 + [item setToolTip: tooltip];
1.75 + [item setTarget: [NSApp delegate]];
1.76 + NSString *iconFile = [[NSBundle mainBundle] pathForResource:icon ofType:@"png"];
1.77 + NSImage *image = [[NSImage alloc] initWithContentsOfFile: iconFile];
1.78 + [item setImage: image];
1.79 + [item setAction: action];
1.80 + return item;
1.81 +}
1.82 +
1.83 +- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *)toolbar
1.84 +{
1.85 + return identifiers;
1.86 +}
1.87 +
1.88 +- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *)toolbar
1.89 +{
1.90 + return defaults;
1.91 +}
1.92 +
1.93 +- (NSArray *)toolbarSelectableItemIdentifiers: (NSToolbar *)toolbar
1.94 +{
1.95 + return [NSArray arrayWithObjects: @"Pause", @"Run", nil];
1.96 +}
1.97 +
1.98 +- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar itemForItemIdentifier:(NSString *)itemIdentifier
1.99 + willBeInsertedIntoToolbar:(BOOL)flag
1.100 +{
1.101 + return [items objectForKey: itemIdentifier];
1.102 +}
1.103 +@end
1.104 +
1.105 +@implementation LxdreamMainWindow
1.106 +- (id)initWithContentRect:(NSRect)videoRect
1.107 +{
1.108 + NSRect contentRect = NSMakeRect(videoRect.origin.x,videoRect.origin.y,
1.109 + videoRect.size.width,videoRect.size.height+STATUSBAR_HEIGHT);
1.110 + if( [super initWithContentRect: contentRect
1.111 + styleMask: ( NSTitledWindowMask | NSClosableWindowMask |
1.112 + NSMiniaturizableWindowMask | NSResizableWindowMask |
1.113 + NSTexturedBackgroundWindowMask | NSUnifiedTitleAndToolbarWindowMask )
1.114 + backing: NSBackingStoreBuffered defer: NO ] == nil ) {
1.115 + return nil;
1.116 + } else {
1.117 + isGrabbed = NO;
1.118 + video = video_osx_create_drawable();
1.119 + [video setFrameOrigin: NSMakePoint(0.0,STATUSBAR_HEIGHT)];
1.120 +
1.121 + status =
1.122 + [[NSTextField alloc] initWithFrame: NSMakeRect(0.0,0.0,videoRect.size.width,STATUSBAR_HEIGHT)];
1.123 + [status setStringValue: @"Idle"];
1.124 + [status setEditable: NO];
1.125 + [status setDrawsBackground: NO];
1.126 + [status setBordered: NO];
1.127 + [[self contentView] addSubview: video];
1.128 + [[self contentView] addSubview: status];
1.129 + [self makeFirstResponder: video];
1.130 +
1.131 + [self setAutorecalculatesContentBorderThickness: YES forEdge: NSMinYEdge ];
1.132 + [self setContentBorderThickness: 15.0 forEdge: NSMinYEdge];
1.133 +
1.134 + // Share the app delegate for the purposes of keeping it in one place
1.135 + [self setDelegate: [NSApp delegate]];
1.136 + [self setContentMinSize: contentRect.size];
1.137 + [self setAcceptsMouseMovedEvents: YES];
1.138 +
1.139 + NSString *title = [[NSString alloc] initWithCString: (APP_NAME " " APP_VERSION) encoding: NSASCIIStringEncoding];
1.140 + [self setTitle: title];
1.141 +
1.142 + NSToolbar *toolbar = [[NSToolbar alloc] initWithIdentifier: @"LxdreamToolbar"];
1.143 + [toolbar setDelegate: [[LxdreamToolbarDelegate alloc] init]];
1.144 + [toolbar setDisplayMode: NSToolbarDisplayModeIconOnly];
1.145 + [toolbar setSizeMode: NSToolbarSizeModeSmall];
1.146 + [toolbar setSelectedItemIdentifier: @"Pause"];
1.147 + [self setToolbar: toolbar];
1.148 + return self;
1.149 + }
1.150 +}
1.151 +
1.152 +- (void)setStatusText: (const gchar *)text
1.153 +{
1.154 + if( isGrabbed ) {
1.155 + gchar buf[128];
1.156 + snprintf( buf, sizeof(buf), "%s %s", text, _("(Press <ctrl><alt> to release grab)") );
1.157 + NSString *s = [NSString stringWithUTF8String: buf];
1.158 + [status setStringValue: s];
1.159 + } else {
1.160 + NSString *s = [NSString stringWithUTF8String: text];
1.161 + [status setStringValue: s];
1.162 + }
1.163 +}
1.164 +- (void)setRunning:(BOOL)isRunning
1.165 +{
1.166 + if( isRunning ) {
1.167 + [[self toolbar] setSelectedItemIdentifier: @"Run"];
1.168 + [self setStatusText: _("Running")];
1.169 + } else {
1.170 + [[self toolbar] setSelectedItemIdentifier: @"Pause"];
1.171 + [self setStatusText: _("Stopped")];
1.172 + }
1.173 +}
1.174 +- (BOOL)isGrabbed
1.175 +{
1.176 + return isGrabbed;
1.177 +}
1.178 +- (void)setIsGrabbed:(BOOL)grab
1.179 +{
1.180 + if( grab != isGrabbed ) {
1.181 + isGrabbed = grab;
1.182 + [self setRunning: dreamcast_is_running() ? YES : NO];
1.183 + }
1.184 +}
1.185 +
1.186 +@end
1.187 +
1.188 +NSWindow *cocoa_gui_create_main_window()
1.189 +{
1.190 + NSRect contentRect = {{0,0},{640,480}};
1.191 + NSWindow *main_win = [[LxdreamMainWindow alloc] initWithContentRect: contentRect];
1.192 + return main_win;
1.193 +}
.