[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [269] branches/fusegl/fuse/fusepb
Brought to you by:
fredm
From: <fr...@us...> - 2006-12-29 12:30:00
|
Revision: 269 http://svn.sourceforge.net/fuse-for-macosx/?rev=269&view=rev Author: fredm Date: 2006-12-29 04:29:57 -0800 (Fri, 29 Dec 2006) Log Message: ----------- Some refactoring around the DisplayOpenGLView class. Modified Paths: -------------- branches/fusegl/fuse/fusepb/Fuse.xcodeproj/project.pbxproj branches/fusegl/fuse/fusepb/controllers/FuseController.h branches/fusegl/fuse/fusepb/controllers/FuseController.m branches/fusegl/fuse/fusepb/controllers/PreferencesController.h branches/fusegl/fuse/fusepb/controllers/PreferencesController.m branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/keyedobjects.nib branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m Added Paths: ----------- branches/fusegl/fuse/fusepb/views/DisplayController.h branches/fusegl/fuse/fusepb/views/DisplayController.m Modified: branches/fusegl/fuse/fusepb/Fuse.xcodeproj/project.pbxproj =================================================================== --- branches/fusegl/fuse/fusepb/Fuse.xcodeproj/project.pbxproj 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/Fuse.xcodeproj/project.pbxproj 2006-12-29 12:29:57 UTC (rev 269) @@ -9,6 +9,8 @@ /* Begin PBXBuildFile section */ B615BFE70B4261E50082D535 /* HIDJoysticks.h in Headers */ = {isa = PBXBuildFile; fileRef = B615BFE50B4261E50082D535 /* HIDJoysticks.h */; }; B615BFE80B4261E50082D535 /* HIDJoysticks.m in Sources */ = {isa = PBXBuildFile; fileRef = B615BFE60B4261E50082D535 /* HIDJoysticks.m */; }; + B615C0130B45159B0082D535 /* DisplayController.h in Headers */ = {isa = PBXBuildFile; fileRef = B615C0110B45159B0082D535 /* DisplayController.h */; }; + B615C0140B45159B0082D535 /* DisplayController.m in Sources */ = {isa = PBXBuildFile; fileRef = B615C0120B45159B0082D535 /* DisplayController.m */; }; B61F459309121DF100C8096C /* Fuse Help in CopyFiles */ = {isa = PBXBuildFile; fileRef = B6F905ED05CDA24300C2F10D /* Fuse Help */; }; B61F459409121DF100C8096C /* disk_plus3.szx in CopyFiles */ = {isa = PBXBuildFile; fileRef = B650C3F2076596C700DE7E81 /* disk_plus3.szx */; }; B61F459509121DF100C8096C /* tape_16.szx in CopyFiles */ = {isa = PBXBuildFile; fileRef = B650C3F4076596FD00DE7E81 /* tape_16.szx */; }; @@ -359,6 +361,8 @@ B611196806A1FBB6006D2711 /* JoystickConfiguration.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = JoystickConfiguration.nib; path = nibs/JoystickConfiguration.nib; sourceTree = "<group>"; }; B615BFE50B4261E50082D535 /* HIDJoysticks.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = HIDJoysticks.h; path = content_arrays/HIDJoysticks.h; sourceTree = "<group>"; }; B615BFE60B4261E50082D535 /* HIDJoysticks.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = HIDJoysticks.m; path = content_arrays/HIDJoysticks.m; sourceTree = "<group>"; }; + B615C0110B45159B0082D535 /* DisplayController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DisplayController.h; sourceTree = "<group>"; }; + B615C0120B45159B0082D535 /* DisplayController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = DisplayController.m; sourceTree = "<group>"; }; B619FC2E090D9BC200344F94 /* SavePanelAccessoryView.nib */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = SavePanelAccessoryView.nib; path = nibs/SavePanelAccessoryView.nib; sourceTree = "<group>"; }; B61EF5B905FED7930081DF70 /* hq3x.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = hq3x.cpp; path = scaler/hq3x.cpp; sourceTree = SOURCE_ROOT; }; B61F46A909121DF100C8096C /* Info-Fuse.plist */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "Info-Fuse.plist"; sourceTree = "<group>"; }; @@ -919,6 +923,8 @@ B6CE7FCF0B28FBEC00EB65B3 /* Views */ = { isa = PBXGroup; children = ( + B615C0110B45159B0082D535 /* DisplayController.h */, + B615C0120B45159B0082D535 /* DisplayController.m */, B6CE7FCB0B28FBD600EB65B3 /* DisplayOpenGLView.h */, B6CE7FCC0B28FBD600EB65B3 /* DisplayOpenGLView.m */, ); @@ -1227,6 +1233,7 @@ B6CE7FCD0B28FBD600EB65B3 /* DisplayOpenGLView.h in Headers */, B6A6F11F0B3EA737000B88E9 /* cocoascreenshot.h in Headers */, B615BFE70B4261E50082D535 /* HIDJoysticks.h in Headers */, + B615C0130B45159B0082D535 /* DisplayController.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1464,6 +1471,7 @@ B6A6F10E0B3D6360000B88E9 /* cocoaerror.m in Sources */, B6A6F1200B3EA737000B88E9 /* cocoascreenshot.m in Sources */, B615BFE80B4261E50082D535 /* HIDJoysticks.m in Sources */, + B615C0140B45159B0082D535 /* DisplayController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; Modified: branches/fusegl/fuse/fusepb/controllers/FuseController.h =================================================================== --- branches/fusegl/fuse/fusepb/controllers/FuseController.h 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/controllers/FuseController.h 2006-12-29 12:29:57 UTC (rev 269) @@ -71,6 +71,8 @@ } + (FuseController *)singleton; +-(void) awakeFromNib; + - (IBAction)cocoa_break:(id)sender; - (IBAction)disk_eject_a:(id)sender; - (IBAction)disk_eject_b:(id)sender; Modified: branches/fusegl/fuse/fusepb/controllers/FuseController.m =================================================================== --- branches/fusegl/fuse/fusepb/controllers/FuseController.m 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/controllers/FuseController.m 2006-12-29 12:29:57 UTC (rev 269) @@ -45,6 +45,7 @@ #include "divide.h" #include "event.h" #include "fuse.h" +#include "fusepb/main.h" #include "if1.h" #include "if2.h" #include "libspectrum.h" @@ -217,6 +218,14 @@ return singleton; } +-(void) awakeFromNib +{ + /* FIXME: Don't really like the argc, argv stuff being here... */ + if( fuse_init( ac, av ) ) { + fprintf( stderr, "%s: error initialising -- giving up!\n", fuse_progname ); + } +} + - (IBAction)disk_eject_a:(id)sender { cocoaui_disk_eject( SPECPLUS3_DRIVE_A, 0 ); Modified: branches/fusegl/fuse/fusepb/controllers/PreferencesController.h =================================================================== --- branches/fusegl/fuse/fusepb/controllers/PreferencesController.h 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/controllers/PreferencesController.h 2006-12-29 12:29:57 UTC (rev 269) @@ -40,6 +40,7 @@ NSMutableArray *machineRoms; } ++ (void)initialize; - (void)awakeFromNib; - (void)windowDidLoad; - (void)windowDidMove:(NSNotification *)aNotification; Modified: branches/fusegl/fuse/fusepb/controllers/PreferencesController.m =================================================================== --- branches/fusegl/fuse/fusepb/controllers/PreferencesController.m 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/controllers/PreferencesController.m 2006-12-29 12:29:57 UTC (rev 269) @@ -28,13 +28,17 @@ #include <string.h> +#import "PreferencesController.h" + +#import "CAMachines.h" #import "FuseController.h" -#import "DisplayOpenGLView.h" +#import "HIDJoysticks.h" #import "JoystickConfigurationController.h" -#import "PreferencesController.h" -#import "CAMachines.h" #import "Joysticks.h" -#import "HIDJoysticks.h" +#import "MachineNameToIdTransformer.h" +#import "MachineScalerIsEnabled.h" +#import "ScalerNameToIdTransformer.h" +#import "VolumeSliderToPrefTransformer.h" #include "fuse.h" #include "joystick.h" @@ -51,6 +55,44 @@ @implementation PreferencesController ++(void) initialize +{ + ScalerNameToIdTransformer *sNToITransformer; + MachineScalerIsEnabled *machineScalerIsEnabled; + MachineNameToIdTransformer *mToITransformer; + VolumeSliderToPrefTransformer *vsToPTransformer; + + sNToITransformer = [[[ScalerNameToIdTransformer alloc] init] autorelease]; + + [NSValueTransformer setValueTransformer:sNToITransformer + forName:@"ScalerNameToIdTransformer"]; + + machineScalerIsEnabled = [[MachineScalerIsEnabled + machineScalerIsEnabledWithInt:1] + autorelease]; + + [NSValueTransformer setValueTransformer:machineScalerIsEnabled + forName:@"MachineTimexIsEnabled"]; + + machineScalerIsEnabled = [[MachineScalerIsEnabled + machineScalerIsEnabledWithInt:0] + autorelease]; + + [NSValueTransformer setValueTransformer:machineScalerIsEnabled + forName:@"MachineTimexIsDisabled"]; + + mToITransformer = [[[MachineNameToIdTransformer alloc] init] autorelease]; + + [NSValueTransformer setValueTransformer:mToITransformer + forName:@"MachineNameToIdTransformer"]; + + vsToPTransformer = [[[VolumeSliderToPrefTransformer alloc] init] autorelease]; + + [NSValueTransformer setValueTransformer:vsToPTransformer + forName:@"VolumeSliderToPrefTransformer"]; + +} + - (void)awakeFromNib { } @@ -122,10 +164,6 @@ [machineRoms release]; fuse_emulation_unpause(); - - /* If we've enabled sound we want to put some data in the buffers before - too long to avoid glitches */ - if( sound_enabled ) [[DisplayOpenGLView instance] updateEmulationForTimeDelta:0]; } - (IBAction)chooseFile:(id)sender Modified: branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib =================================================================== --- branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/classes.nib 2006-12-29 12:29:57 UTC (rev 269) @@ -1,6 +1,12 @@ { IBClasses = ( - {CLASS = DisplayOpenGLView; LANGUAGE = ObjC; SUPERCLASS = NSOpenGLView; }, + {CLASS = DisplayController; LANGUAGE = ObjC; SUPERCLASS = NSResponder; }, + { + CLASS = DisplayOpenGLView; + LANGUAGE = ObjC; + OUTLETS = {controller = NSResponder; }; + SUPERCLASS = NSOpenGLView; + }, {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, { ACTIONS = { Modified: branches/fusegl/fuse/fusepb/nibs/MainMenu.nib/keyedobjects.nib =================================================================== (Binary files differ) Copied: branches/fusegl/fuse/fusepb/views/DisplayController.h (from rev 268, branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h) =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayController.h (rev 0) +++ branches/fusegl/fuse/fusepb/views/DisplayController.h 2006-12-29 12:29:57 UTC (rev 269) @@ -0,0 +1,60 @@ +/* DisplayController.h: Implementation for the DisplayController class + Copyright (c) 2006 Fredrick Meunier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Author contact information: + + E-mail: fr...@sp... + Postal address: 3/66 Roslyn Gardens, Ruscutters Bay, NSW 2011, Australia + +*/ + +#import <Cocoa/Cocoa.h> + +#include <libspectrum.h> + +#include "input.h" + +@interface DisplayController : NSResponder +{ + GHashTable *unicode_keysyms_hash; + + BOOL optDown; + BOOL ctrlDown; + BOOL shiftDown; + + int cocoakeyboard_caps_shift_pressed; + int cocoakeyboard_symbol_shift_pressed; + input_key unicode_keysym; +} +-(void) awakeFromNib; + +-(void) mouseMoved:(NSEvent *)theEvent; +-(void) mouseDown:(NSEvent *)theEvent; +-(void) mouseUp:(NSEvent *)theEvent; +-(void) rightMouseDown:(NSEvent *)theEvent; +-(void) rightMouseUp:(NSEvent *)theEvent; +-(void) otherMouseDown:(NSEvent *)theEvent; +-(void) otherMouseUp:(NSEvent *)theEvent; + +-(void) initKeyboard; +-(void) flagsChanged:(NSEvent *)theEvent; +-(input_key) otherKeysymsRemap:(libspectrum_dword)ui_keysym inHash:(GHashTable*)hash; +-(void) keyChange:(NSEvent *)theEvent type:(input_event_type)type; +-(void) keyDown:(NSEvent *)theEvent; +-(void) keyUp:(NSEvent *)theEvent; + +@end Copied: branches/fusegl/fuse/fusepb/views/DisplayController.m (from rev 268, branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m) =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayController.m (rev 0) +++ branches/fusegl/fuse/fusepb/views/DisplayController.m 2006-12-29 12:29:57 UTC (rev 269) @@ -0,0 +1,192 @@ +/* DisplayController.m: Implementation for the DisplayController class + Copyright (c) 2006 Fredrick Meunier + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Author contact information: + + E-mail: fr...@sp... + Postal address: 3/66 Roslyn Gardens, Ruscutters Bay, NSW 2011, Australia + +*/ + +#import "DisplayController.h" + +#include "event.h" +#include "keyboard.h" +#include "ui/ui.h" + +extern keysyms_map_t unicode_keysyms_map[]; + +@implementation DisplayController + +-(void) awakeFromNib +{ + optDown = NO; + ctrlDown = NO; + shiftDown = NO; + + cocoakeyboard_caps_shift_pressed = 0; + cocoakeyboard_symbol_shift_pressed = 0; + unicode_keysym = INPUT_KEY_NONE; + + [self initKeyboard]; +} + +-(void) mouseMoved:(NSEvent *)theEvent +{ + if( ui_mouse_grabbed ) { + int dx = [theEvent deltaX]; + int dy = [theEvent deltaY]; + + if( dx < -128 ) dx = -128; + else if( dx > 128 ) dx = 128; + + if( dy < -128 ) dy = -128; + else if( dy > 128 ) dy = 128; + + ui_mouse_motion( dx, dy ); + } +} + +-(void) mouseDown:(NSEvent *)theEvent +{ + ui_mouse_button( 1, 1 ); +} + +-(void) mouseUp:(NSEvent *)theEvent +{ + ui_mouse_button( 1, 0 ); +} + +-(void) rightMouseDown:(NSEvent *)theEvent +{ + ui_mouse_button( 3, 1 ); +} + +-(void) rightMouseUp:(NSEvent *)theEvent +{ + ui_mouse_button( 3, 0 ); +} + +-(void) otherMouseDown:(NSEvent *)theEvent +{ + ui_mouse_button( 2, 1 ); +} + +-(void) otherMouseUp:(NSEvent *)theEvent +{ + ui_mouse_button( 2, 0 ); +} + +-(void) initKeyboard +{ + keysyms_map_t *ptr3; + + unicode_keysyms_hash = g_hash_table_new( g_int_hash, g_int_equal ); + + for( ptr3 = (keysyms_map_t *)unicode_keysyms_map; ptr3->ui; ptr3++ ) + g_hash_table_insert( unicode_keysyms_hash, &( ptr3->ui ), + &( ptr3->fuse ) ); +} + +-(void) modifierChange:(input_event_type)theType oldState:(BOOL)old newState:(BOOL)new +{ + if( old != new ) { + input_event_t fuse_event; + fuse_event.types.key.spectrum_key = theType; + if( new == YES ) + fuse_event.type = INPUT_EVENT_KEYPRESS; + else + fuse_event.type = INPUT_EVENT_KEYRELEASE; + input_event( &fuse_event ); + } +} + +-(void) flagsChanged:(NSEvent *)theEvent +{ + int flags = [theEvent modifierFlags]; + BOOL optDownNew = (flags & NSAlternateKeyMask) ? YES : NO; + BOOL ctrlDownNew = (flags & NSControlKeyMask) ? YES : NO; + BOOL shiftDownNew = ( flags & NSShiftKeyMask ) ? YES : NO; + + [self modifierChange:INPUT_KEY_Alt_L oldState:optDown newState:optDownNew]; + [self modifierChange:INPUT_KEY_Control_L oldState:ctrlDown newState:ctrlDownNew]; + [self modifierChange:INPUT_KEY_Shift_L oldState:shiftDown newState:shiftDownNew]; + + optDown = optDownNew; + ctrlDown = ctrlDownNew; + shiftDown = shiftDownNew; +} + +-(input_key) otherKeysymsRemap:(libspectrum_dword)ui_keysym inHash:(GHashTable*)hash +{ + const input_key *ptr; + + ptr = g_hash_table_lookup( hash, &ui_keysym ); + + return ptr ? *ptr : INPUT_KEY_NONE; +} + +-(void) keyChange:(NSEvent *)theEvent type:(input_event_type)type +{ + unsigned short keyCode = [theEvent keyCode]; + NSString *characters = [theEvent charactersIgnoringModifiers]; + if ([characters length]) { + input_key fuse_keysym; + input_event_t fuse_event; + + fuse_keysym = keysyms_remap( keyCode ); + if( fuse_keysym == INPUT_KEY_NONE ) { + fuse_keysym = [self otherKeysymsRemap:[characters characterAtIndex:0] + inHash:unicode_keysyms_hash]; + if( fuse_keysym != INPUT_KEY_NONE ) { + unicode_keysym = fuse_keysym; + /* record current values of caps and symbol shift. We will temoprarily + * override these for the duration of the unicoded simulated keypresses + */ + if( ( cocoakeyboard_caps_shift_pressed = keyboard_state( KEYBOARD_Caps ) ) ) + { + keyboard_release( KEYBOARD_Caps ); + } + if( ( cocoakeyboard_symbol_shift_pressed = + keyboard_state( KEYBOARD_Symbol ) ) ) { + keyboard_release( KEYBOARD_Symbol ); + } + } + } + + fuse_event.type = type; + if( unicode_keysym == INPUT_KEY_NONE ) + fuse_event.types.key.native_key = fuse_keysym; + else + fuse_event.types.key.native_key = unicode_keysym; + fuse_event.types.key.spectrum_key = fuse_keysym; + + input_event( &fuse_event ); + } +} + +-(void) keyDown:(NSEvent *)theEvent +{ + [self keyChange:theEvent type:INPUT_EVENT_KEYPRESS]; +} + +-(void) keyUp:(NSEvent *)theEvent +{ + [self keyChange:theEvent type:INPUT_EVENT_KEYRELEASE]; +} + +@end Modified: branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-29 12:29:57 UTC (rev 269) @@ -42,20 +42,12 @@ BOOL screenTexInitialised; - GHashTable *unicode_keysyms_hash; - - BOOL optDown; - BOOL ctrlDown; - BOOL shiftDown; - - int cocoakeyboard_caps_shift_pressed; - int cocoakeyboard_symbol_shift_pressed; - input_key unicode_keysym; - CFAbsoluteTime time; + + /* Controller */ + IBOutlet NSResponder *controller; } +(DisplayOpenGLView *) instance; -+(void) initialize; -(void) createTexture:(Cocoa_Texture*)newScreen; -(void) destroyTexture; @@ -74,11 +66,7 @@ -(void) otherMouseDown:(NSEvent *)theEvent; -(void) otherMouseUp:(NSEvent *)theEvent; --(void) initKeyboard; --(void) modifierChange:(input_event_type)theType oldState:(BOOL)old newState:(BOOL)new; -(void) flagsChanged:(NSEvent *)theEvent; --(input_key) otherKeysymsRemap:(libspectrum_dword)ui_keysym inHash:(GHashTable*)hash; --(void) keyChange:(NSEvent *)theEvent type:(input_event_type)type; -(void) keyDown:(NSEvent *)theEvent; -(void) keyUp:(NSEvent *)theEvent; Modified: branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m 2006-12-27 12:55:52 UTC (rev 268) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m 2006-12-29 12:29:57 UTC (rev 269) @@ -23,25 +23,16 @@ */ #import "DisplayOpenGLView.h" -#import "ScalerNameToIdTransformer.h" -#import "MachineScalerIsEnabled.h" -#import "MachineNameToIdTransformer.h" -#import "VolumeSliderToPrefTransformer.h" #include "event.h" #include "fuse.h" -#include "fusepb/main.h" -#include "keyboard.h" #include "settings.h" #include "sound.h" -extern keysyms_map_t unicode_keysyms_map[]; - #include <CoreAudio/AudioHardware.h> #include "sound/sfifo.h" extern sfifo_t sound_fifo; -extern AudioStreamBasicDescription deviceFormat; @implementation DisplayOpenGLView @@ -52,44 +43,6 @@ return instance; } -+(void) initialize -{ - ScalerNameToIdTransformer *sNToITransformer; - MachineScalerIsEnabled *machineScalerIsEnabled; - MachineNameToIdTransformer *mToITransformer; - VolumeSliderToPrefTransformer *vsToPTransformer; - - sNToITransformer = [[[ScalerNameToIdTransformer alloc] init] autorelease]; - - [NSValueTransformer setValueTransformer:sNToITransformer - forName:@"ScalerNameToIdTransformer"]; - - machineScalerIsEnabled = [[MachineScalerIsEnabled - machineScalerIsEnabledWithInt:1] - autorelease]; - - [NSValueTransformer setValueTransformer:machineScalerIsEnabled - forName:@"MachineTimexIsEnabled"]; - - machineScalerIsEnabled = [[MachineScalerIsEnabled - machineScalerIsEnabledWithInt:0] - autorelease]; - - [NSValueTransformer setValueTransformer:machineScalerIsEnabled - forName:@"MachineTimexIsDisabled"]; - - mToITransformer = [[[MachineNameToIdTransformer alloc] init] autorelease]; - - [NSValueTransformer setValueTransformer:mToITransformer - forName:@"MachineNameToIdTransformer"]; - - vsToPTransformer = [[[VolumeSliderToPrefTransformer alloc] init] autorelease]; - - [NSValueTransformer setValueTransformer:vsToPTransformer - forName:@"VolumeSliderToPrefTransformer"]; - -} - -(id) initWithFrame:(NSRect)frameRect { /* Init pixel format attribs */ @@ -127,14 +80,6 @@ screenTexInitialised = NO; - optDown = NO; - ctrlDown = NO; - shiftDown = NO; - - cocoakeyboard_caps_shift_pressed = 0; - cocoakeyboard_symbol_shift_pressed = 0; - unicode_keysym = INPUT_KEY_NONE; - return self; } @@ -143,13 +88,6 @@ /* keep the window in the standard aspect ratio if the user resizes */ [[self window] setContentAspectRatio:NSMakeSize(4.0,3.0)]; - /* FIXME: Don't really like the argc, argv stuff being here... */ - if( fuse_init( ac, av ) ) { - fprintf( stderr, "%s: error initialising -- giving up!\n", fuse_progname ); - } - - [self initKeyboard]; - time = CFAbsoluteTimeGetCurrent(); /* set emulation time start time */ } @@ -336,146 +274,62 @@ -(void) mouseMoved:(NSEvent *)theEvent { - if( ui_mouse_grabbed ) { - int dx = [theEvent deltaX]; - int dy = [theEvent deltaY]; - - if( dx < -128 ) dx = -128; - else if( dx > 128 ) dx = 128; - - if( dy < -128 ) dy = -128; - else if( dy > 128 ) dy = 128; - - ui_mouse_motion( dx, dy ); - } + /* Delegate to our controller object. */ + [controller mouseMoved:theEvent]; } -(void) mouseDown:(NSEvent *)theEvent { - ui_mouse_button( 1, 1 ); + /* Delegate to our controller object. */ + [controller mouseDown:theEvent]; } -(void) mouseUp:(NSEvent *)theEvent { - ui_mouse_button( 1, 0 ); + /* Delegate to our controller object. */ + [controller mouseUp:theEvent]; } -(void) rightMouseDown:(NSEvent *)theEvent { - ui_mouse_button( 3, 1 ); + /* Delegate to our controller object. */ + [controller rightMouseDown:theEvent]; } -(void) rightMouseUp:(NSEvent *)theEvent { - ui_mouse_button( 3, 0 ); + /* Delegate to our controller object. */ + [controller rightMouseUp:theEvent]; } -(void) otherMouseDown:(NSEvent *)theEvent { - ui_mouse_button( 2, 1 ); + /* Delegate to our controller object. */ + [controller otherMouseDown:theEvent]; } -(void) otherMouseUp:(NSEvent *)theEvent { - ui_mouse_button( 2, 0 ); + /* Delegate to our controller object. */ + [controller otherMouseUp:theEvent]; } --(void) initKeyboard -{ - keysyms_map_t *ptr3; - - unicode_keysyms_hash = g_hash_table_new( g_int_hash, g_int_equal ); - - for( ptr3 = (keysyms_map_t *)unicode_keysyms_map; ptr3->ui; ptr3++ ) - g_hash_table_insert( unicode_keysyms_hash, &( ptr3->ui ), - &( ptr3->fuse ) ); -} - --(void) modifierChange:(input_event_type)theType oldState:(BOOL)old newState:(BOOL)new -{ - if( old != new ) { - input_event_t fuse_event; - fuse_event.types.key.spectrum_key = theType; - if( new == YES ) - fuse_event.type = INPUT_EVENT_KEYPRESS; - else - fuse_event.type = INPUT_EVENT_KEYRELEASE; - input_event( &fuse_event ); - } -} - -(void) flagsChanged:(NSEvent *)theEvent { - int flags = [theEvent modifierFlags]; - BOOL optDownNew = (flags & NSAlternateKeyMask) ? YES : NO; - BOOL ctrlDownNew = (flags & NSControlKeyMask) ? YES : NO; - BOOL shiftDownNew = ( flags & NSShiftKeyMask ) ? YES : NO; - - [self modifierChange:INPUT_KEY_Alt_L oldState:optDown newState:optDownNew]; - [self modifierChange:INPUT_KEY_Control_L oldState:ctrlDown newState:ctrlDownNew]; - [self modifierChange:INPUT_KEY_Shift_L oldState:shiftDown newState:shiftDownNew]; - - optDown = optDownNew; - ctrlDown = ctrlDownNew; - shiftDown = shiftDownNew; + /* Delegate to our controller object. */ + [controller flagsChanged:theEvent]; } --(input_key) otherKeysymsRemap:(libspectrum_dword)ui_keysym inHash:(GHashTable*)hash -{ - const input_key *ptr; - - ptr = g_hash_table_lookup( hash, &ui_keysym ); - - return ptr ? *ptr : INPUT_KEY_NONE; -} - --(void) keyChange:(NSEvent *)theEvent type:(input_event_type)type -{ - unsigned short keyCode = [theEvent keyCode]; - NSString *characters = [theEvent charactersIgnoringModifiers]; - if ([characters length]) { - input_key fuse_keysym; - input_event_t fuse_event; - - fuse_keysym = keysyms_remap( keyCode ); - if( fuse_keysym == INPUT_KEY_NONE ) { - fuse_keysym = [self otherKeysymsRemap:[characters characterAtIndex:0] - inHash:unicode_keysyms_hash]; - if( fuse_keysym != INPUT_KEY_NONE ) { - unicode_keysym = fuse_keysym; - /* record current values of caps and symbol shift. We will temoprarily - * override these for the duration of the unicoded simulated keypresses - */ - if( ( cocoakeyboard_caps_shift_pressed = keyboard_state( KEYBOARD_Caps ) ) ) - { - keyboard_release( KEYBOARD_Caps ); - } - if( ( cocoakeyboard_symbol_shift_pressed = - keyboard_state( KEYBOARD_Symbol ) ) ) { - keyboard_release( KEYBOARD_Symbol ); - } - } - } - - fuse_event.type = type; - if( unicode_keysym == INPUT_KEY_NONE ) - fuse_event.types.key.native_key = fuse_keysym; - else - fuse_event.types.key.native_key = unicode_keysym; - fuse_event.types.key.spectrum_key = fuse_keysym; - - input_event( &fuse_event ); - } -} - -(void) keyDown:(NSEvent *)theEvent { - [self keyChange:theEvent type:INPUT_EVENT_KEYPRESS]; + /* Delegate to our controller object. */ + [controller keyDown:theEvent]; } -(void) keyUp:(NSEvent *)theEvent { - [self keyChange:theEvent type:INPUT_EVENT_KEYRELEASE]; + /* Delegate to our controller object. */ + [controller keyUp:theEvent]; } -(BOOL) acceptsFirstResponder This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |