Search
lxdream.org :: lxdream/src/cocoaui/cocoa_ctrl.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/cocoaui/cocoa_ctrl.c
changeset 765:4cd066048203
next770:429ff505c450
author nkeynes
date Wed Jul 23 11:11:30 2008 +0000 (12 years ago)
permissions -rw-r--r--
last change Cocoa preferences panel work-in-progress
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/cocoaui/cocoa_ctrl.c Wed Jul 23 11:11:30 2008 +0000
1.3 @@ -0,0 +1,101 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Construct and manage the controller configuration pane
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.h"
1.23 +#include "config.h"
1.24 +#include "maple/maple.h"
1.25 +
1.26 +#define MAX_DEVICES 4
1.27 +
1.28 +@implementation LxdreamPrefsControllerPane
1.29 ++ (LxdreamPrefsControllerPane *)new
1.30 +{
1.31 + return [[LxdreamPrefsControllerPane alloc] initWithFrame: NSMakeRect(0,0,600,400)];
1.32 +}
1.33 +- (id)initWithFrame: (NSRect)frameRect
1.34 +{
1.35 + if( [super initWithFrame: frameRect title: NS_("Controllers")] == nil ) {
1.36 + return nil;
1.37 + } else {
1.38 + const struct maple_device_class **devices = maple_get_device_classes();
1.39 + char buf[16];
1.40 + int i,j;
1.41 + int height = [self contentHeight] - TEXT_HEIGHT - TEXT_GAP;
1.42 + for( i=0; i<MAX_DEVICES; i++ ) {
1.43 + save_controller[i] = NULL;
1.44 + maple_device_t device = maple_get_device(i,0);
1.45 + NSRect frame = NSMakeRect( TEXT_GAP, height -((TEXT_HEIGHT+TEXT_GAP)*i - 2),
1.46 + 50, LABEL_HEIGHT );
1.47 + snprintf( buf, sizeof(buf), _("Slot %d."), i );
1.48 + NSTextField *label = [self addLabel: [NSString stringWithUTF8String: buf]
1.49 + withFrame: frame ];
1.50 + [label setAlignment: NSRightTextAlignment];
1.51 + frame = NSMakeRect( 50 + (TEXT_GAP*2), height - ((TEXT_HEIGHT+TEXT_GAP)*i),
1.52 + 150, TEXT_HEIGHT );
1.53 + NSPopUpButton *popup = [[NSPopUpButton alloc] initWithFrame: frame pullsDown: NO];
1.54 + [popup addItemWithTitle: NS_("<empty>")];
1.55 + [popup setAutoresizingMask: (NSViewMinYMargin|NSViewMaxXMargin)];
1.56 + [[popup itemAtIndex: 0] setTag: 0];
1.57 + for( j=0; devices[j] != NULL; j++ ) {
1.58 + [popup addItemWithTitle: [NSString stringWithUTF8String: devices[j]->name]];
1.59 + if( device != NULL && device->device_class == devices[j] ) {
1.60 + [popup selectItemAtIndex: (j+1)];
1.61 + }
1.62 + [[popup itemAtIndex: (j+1)] setTag: (j+1)];
1.63 + }
1.64 + [popup setTarget: self];
1.65 + [popup setAction: @selector(deviceChanged:)];
1.66 + [popup setTag: i];
1.67 + [self addSubview: popup];
1.68 + }
1.69 + return self;
1.70 + }
1.71 +}
1.72 +- (void)deviceChanged: (id)sender
1.73 +{
1.74 + int slot = [sender tag];
1.75 + int new_device_idx = [sender indexOfSelectedItem] - 1;
1.76 + maple_device_class_t new_device_class = NULL;
1.77 +
1.78 + maple_device_t current = maple_get_device(slot,0);
1.79 + maple_device_t new_device = NULL;
1.80 + if( new_device_idx != -1 ) {
1.81 + new_device_class = maple_get_device_classes()[new_device_idx];
1.82 + }
1.83 + if( current == NULL ? new_device_class == NULL : current->device_class == new_device_class ) {
1.84 + // No change
1.85 + return;
1.86 + }
1.87 + if( current != NULL && current->device_class == &controller_class ) {
1.88 + save_controller[slot] = current->clone(current);
1.89 + }
1.90 + if( new_device_class == NULL ) {
1.91 + maple_detach_device(slot,0);
1.92 + } else {
1.93 + if( new_device_class == &controller_class && save_controller[slot] != NULL ) {
1.94 + new_device = save_controller[slot];
1.95 + save_controller[slot] = NULL;
1.96 + } else {
1.97 + new_device = maple_new_device( new_device_class->name );
1.98 + }
1.99 + maple_attach_device(new_device,slot,0);
1.100 + }
1.101 +
1.102 + lxdream_save_config();
1.103 +}
1.104 +@end
.