[Fuse-for-macosx-commits] SF.net SVN: fuse-for-macosx: [259] branches/fusegl/fuse/fusepb/views
Brought to you by:
fredm
From: <fr...@us...> - 2006-12-20 08:57:33
|
Revision: 259 http://svn.sourceforge.net/fuse-for-macosx/?rev=259&view=rev Author: fredm Date: 2006-12-20 00:57:32 -0800 (Wed, 20 Dec 2006) Log Message: ----------- Get rid of static variables, move more common code to methods on DisplayOpenGLView. Modified Paths: -------------- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m Modified: branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h =================================================================== --- branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-20 07:40:59 UTC (rev 258) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.h 2006-12-20 08:57:32 UTC (rev 259) @@ -1,8 +1,6 @@ /* DisplayOpenGLView.h: Implementation for the DisplayOpenGLView class Copyright (c) 2006 Fredrick Meunier - $Id$ - 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 @@ -49,6 +47,10 @@ BOOL optDown; BOOL ctrlDown; BOOL shiftDown; + + int cocoakeyboard_caps_shift_pressed; + int cocoakeyboard_symbol_shift_pressed; + input_key unicode_keysym; } +(DisplayOpenGLView *) instance; +(void) initialize; @@ -62,7 +64,9 @@ -(void) awakeFromNib; -(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-20 07:40:59 UTC (rev 258) +++ branches/fusegl/fuse/fusepb/views/DisplayOpenGLView.m 2006-12-20 08:57:32 UTC (rev 259) @@ -1,8 +1,6 @@ /* DisplayOpenGLView.m: Implementation for the DisplayOpenGLView class Copyright (c) 2006 Fredrick Meunier - $Id$ - 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 @@ -37,20 +35,6 @@ extern keysyms_map_t unicode_keysyms_map[]; -static int cocoakeyboard_caps_shift_pressed = 0; -static int cocoakeyboard_symbol_shift_pressed = 0; -static input_key unicode_keysym = INPUT_KEY_NONE; - -static input_key -other_keysyms_remap( libspectrum_dword ui_keysym, GHashTable *hash ) -{ - const input_key *ptr; - - ptr = g_hash_table_lookup( hash, &ui_keysym ); - - return ptr ? *ptr : INPUT_KEY_NONE; -} - @implementation DisplayOpenGLView static DisplayOpenGLView *instance = nil; @@ -139,6 +123,10 @@ ctrlDown = NO; shiftDown = NO; + cocoakeyboard_caps_shift_pressed = 0; + cocoakeyboard_symbol_shift_pressed = 0; + unicode_keysym = INPUT_KEY_NONE; + return self; } @@ -324,48 +312,44 @@ &( ptr3->fuse ) ); } --(void) flagsChanged:(NSEvent *)theEvent +-(void) modifierChange:(input_event_type)theType oldState:(BOOL)old newState:(BOOL)new { - int flags = [theEvent modifierFlags]; - BOOL optDownNew = (flags & NSAlternateKeyMask) ? YES : NO; - BOOL ctrlDownNew = (flags & NSControlKeyMask) ? YES : NO; - BOOL shiftDownNew = ( flags & NSShiftKeyMask ) ? YES : NO; - - if( optDown != optDownNew ) { + if( old != new ) { input_event_t fuse_event; - fuse_event.types.key.spectrum_key = INPUT_KEY_Alt_L; - if( optDownNew == YES ) + 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 ); } +} - if( ctrlDown != ctrlDownNew ) { - input_event_t fuse_event; - fuse_event.types.key.spectrum_key = INPUT_KEY_Control_L; - if( ctrlDownNew == 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; - if( shiftDown != shiftDownNew ) { - input_event_t fuse_event; - fuse_event.types.key.spectrum_key = INPUT_KEY_Shift_L; - if( shiftDownNew == YES ) - fuse_event.type = INPUT_EVENT_KEYPRESS; - else - fuse_event.type = INPUT_EVENT_KEYRELEASE; - input_event( &fuse_event ); - } + [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]; @@ -376,8 +360,8 @@ fuse_keysym = keysyms_remap( keyCode ); if( fuse_keysym == INPUT_KEY_NONE ) { - fuse_keysym = other_keysyms_remap( [characters characterAtIndex:0], - unicode_keysyms_hash ); + 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 @@ -418,7 +402,7 @@ -(BOOL) becomeFirstResponder { - return YES; + return YES; } -(BOOL) resignFirstResponder This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |