int ui_event(void) { XEvent event; XFlush( display ); while( XEventsQueued( display, QueuedAlready ) ) { XNextEvent( display, &event ); switch(event.type) { case ConfigureNotify: xdisplay_configure_notify(event.xconfigure.width, event.xconfigure.height); break; case Expose: xdisplay_area( event.xexpose.x, event.xexpose.y, event.xexpose.width, event.xexpose.height ); break; case ButtonPress: ui_mouse_button( event.xbutton.button, 1 ); break; case ButtonRelease: ui_mouse_button( event.xbutton.button, 0 ); break; case MotionNotify: if( ui_mouse_grabbed ) { ui_mouse_motion( event.xmotion.x - 128, event.xmotion.y - 128 ); if( event.xmotion.x != 128 || event.xmotion.y != 128 ) XWarpPointer( display, None, xui_mainWindow, 0, 0, 0, 0, 128, 128 ); } break; case FocusOut: keyboard_release_all(); ui_mouse_suspend(); break; case FocusIn: ui_mouse_resume(); break; case KeyPress: xkeyboard_keypress(&(event.xkey)); break; case KeyRelease: xkeyboard_keyrelease(&(event.xkey)); break; case ClientMessage: if( event.xclient.format == 32 && event.xclient.data.l[0] == delete_window_atom ) { fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); } break; } } return 0; }
int ui_event( void ) { SDL_Event event; while ( SDL_PollEvent( &event ) ) { switch ( event.type ) { case SDL_KEYDOWN: sdlkeyboard_keypress( &(event.key) ); break; case SDL_KEYUP: sdlkeyboard_keyrelease( &(event.key) ); break; case SDL_MOUSEBUTTONDOWN: ui_mouse_button( event.button.button, 1 ); break; case SDL_MOUSEBUTTONUP: ui_mouse_button( event.button.button, 0 ); break; case SDL_MOUSEMOTION: if( ui_mouse_grabbed ) { ui_mouse_motion( event.motion.x - 128, event.motion.y - 128 ); if( event.motion.x != 128 || event.motion.y != 128 ) SDL_WarpMouse( 128, 128 ); } break; #if defined USE_JOYSTICK && !defined HAVE_JSW_H case SDL_JOYBUTTONDOWN: sdljoystick_buttonpress( &(event.jbutton) ); break; case SDL_JOYBUTTONUP: sdljoystick_buttonrelease( &(event.jbutton) ); break; case SDL_JOYAXISMOTION: sdljoystick_axismove( &(event.jaxis) ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ case SDL_QUIT: fuse_emulation_pause(); menu_file_exit(0); fuse_emulation_unpause(); break; case SDL_VIDEOEXPOSE: display_refresh_all(); break; case SDL_ACTIVEEVENT: if( event.active.state & SDL_APPINPUTFOCUS ) { if( event.active.gain ) ui_mouse_resume(); else ui_mouse_suspend(); } break; default: break; } } return 0; }
static LRESULT WINAPI fuse_window_proc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ) { switch( msg ) { #if defined USE_JOYSTICK && !defined HAVE_JSW_H case WM_CREATE: if( joysticks_supported > 0 ) if( joySetCapture( hWnd, JOYSTICKID1, 0, FALSE ) ) ui_error( UI_ERROR_ERROR, "Couldn't start capture for joystick 1" ); if( joysticks_supported > 1 ) if( joySetCapture( hWnd, JOYSTICKID2, 0, FALSE ) ) ui_error( UI_ERROR_ERROR, "Couldn't start capture for joystick 2" ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ case WM_COMMAND: if( ! handle_menu( LOWORD( wParam ), hWnd ) ) return 0; break; case WM_DROPFILES: handle_drop( ( HDROP )wParam ); return 0; case WM_CLOSE: menu_file_exit( 0 ); return 0; case WM_KEYDOWN: win32keyboard_keypress( wParam, lParam ); return 0; case WM_KEYUP: win32keyboard_keyrelease( wParam, lParam ); return 0; case WM_PAINT: if( ! win32ui_window_paint( hWnd, wParam, lParam ) ) return 0; break; case WM_SIZING: if( win32ui_window_resizing( hWnd, wParam, lParam ) ) return TRUE; break; case WM_SIZE: if( ! win32ui_window_resize( hWnd, wParam, lParam ) ) return 0; break; case WM_DRAWITEM: if( wParam == ID_STATUSBAR ) { win32statusbar_redraw( hWnd, lParam ); return TRUE; } break; case WM_DESTROY: fuse_exiting = 1; PostQuitMessage( 0 ); /* Stop the paused state to allow us to exit (occurs from main emulation loop) */ if( paused ) menu_machine_pause( 0 ); return 0; case WM_ENTERMENULOOP: case WM_ENTERSIZEMOVE: { fuse_emulation_pause(); return 0; } case WM_EXITMENULOOP: case WM_EXITSIZEMOVE: { fuse_emulation_unpause(); return 0; } case WM_LBUTTONUP: win32mouse_button( 1, 0 ); return 0; case WM_LBUTTONDOWN: win32mouse_button( 1, 1 ); return 0; case WM_MBUTTONUP: win32mouse_button( 2, 0 ); return 0; case WM_MBUTTONDOWN: win32mouse_button( 2, 1 ); return 0; case WM_RBUTTONUP: win32mouse_button( 3, 0 ); return 0; case WM_RBUTTONDOWN: win32mouse_button( 3, 1 ); return 0; case WM_MOUSEMOVE: win32mouse_position( lParam ); return 0; case WM_SETCURSOR: /* prevent the cursor from being redrawn if fuse has grabbed the mouse */ if( ui_mouse_grabbed ) return TRUE; else return( DefWindowProc( hWnd, msg, wParam, lParam ) ); case WM_ACTIVATE: if( ( LOWORD( wParam ) == WA_ACTIVE ) || ( LOWORD( wParam ) == WA_CLICKACTIVE ) ) win32ui_gain_focus( hWnd, wParam, lParam ); else if( LOWORD( wParam ) == WA_INACTIVE ) win32ui_lose_focus( hWnd, wParam, lParam ); /* We'll call DefWindowProc to get keyboard focus when debugger window is open and inactive */ break; case WM_USER_EXIT_PROCESS_MESSAGES: /* Odd case when message loop is overridden by a modal dialog. This should not be caught here, so we delay this notification */ exit_process_messages++; return 0; case WM_ERASEBKGND: /* Improves speed and avoid flickering when main window is invalidated by another window */ return TRUE; #if defined USE_JOYSTICK && !defined HAVE_JSW_H case MM_JOY1BUTTONDOWN: win32joystick_buttonevent( 0, 1, wParam ); break; case MM_JOY1BUTTONUP: win32joystick_buttonevent( 0, 0, wParam ); break; case MM_JOY2BUTTONDOWN: win32joystick_buttonevent( 1, 1, wParam ); break; case MM_JOY2BUTTONUP: win32joystick_buttonevent( 1, 0, wParam ); break; case MM_JOY1MOVE: win32joystick_move( 0, LOWORD( lParam ), HIWORD( lParam ) ); break; case MM_JOY2MOVE: win32joystick_move( 1, LOWORD( lParam ), HIWORD( lParam ) ); break; #endif /* if defined USE_JOYSTICK && !defined HAVE_JSW_H */ } return( DefWindowProc( hWnd, msg, wParam, lParam ) ); }
static int keypress( const input_event_key_t *event ) { int swallow; const keyboard_spectrum_keys_t *ptr; #ifdef USE_WIDGET if( widget_level >= 0 ) { widget_keyhandler( event->native_key ); return 0; } #endif /* #ifdef USE_WIDGET */ /* Escape => ask UI to end mouse grab, return if grab ended */ if( event->native_key == INPUT_KEY_Escape && ui_mouse_grabbed ) { ui_mouse_grabbed = ui_mouse_release( 0 ); if( !ui_mouse_grabbed ) return 0; } swallow = 0; /* Joystick emulation via keyboard keys */ if ( event->spectrum_key == settings_current.joystick_keyboard_up ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_UP , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_down ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_DOWN , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_left ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_LEFT , 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_right ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_RIGHT, 1 ); } else if( event->spectrum_key == settings_current.joystick_keyboard_fire ) { swallow = joystick_press( JOYSTICK_KEYBOARD, JOYSTICK_BUTTON_FIRE , 1 ); } if( swallow ) return 0; ptr = keyboard_get_spectrum_keys( event->spectrum_key ); if( ptr ) { keyboard_press( ptr->key1 ); keyboard_press( ptr->key2 ); } #ifdef USE_WIDGET switch( event->native_key ) { case INPUT_KEY_F1: fuse_emulation_pause(); widget_do( WIDGET_TYPE_MENU, &widget_menu ); fuse_emulation_unpause(); break; case INPUT_KEY_F2: fuse_emulation_pause(); menu_file_savesnapshot( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F3: fuse_emulation_pause(); menu_file_open( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F4: fuse_emulation_pause(); menu_options_general( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F5: fuse_emulation_pause(); menu_machine_reset( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F6: fuse_emulation_pause(); menu_media_tape_write( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F7: fuse_emulation_pause(); menu_media_tape_open( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F8: menu_media_tape_play( 0 ); break; case INPUT_KEY_F9: fuse_emulation_pause(); menu_machine_select( 0 ); fuse_emulation_unpause(); break; case INPUT_KEY_F10: fuse_emulation_pause(); menu_file_exit( 0 ); fuse_emulation_unpause(); break; default: break; /* Remove gcc warning */ } #endif /* #ifdef USE_WIDGET */ return 0; }