static void gtkui_drag_data_received( GtkWidget *widget, GdkDragContext *drag_context, gint x, gint y, GtkSelectionData *data, guint info, guint time ) { static char uri_prefix[] = "file://"; char *filename, *p, *data_end; if ( data && data->length > sizeof( uri_prefix ) ) { filename = ( char * )( data->data + sizeof( uri_prefix ) - 1 ); data_end = ( char * )( data->data + data->length ); p = filename; do { if ( *p == '\r' || *p == '\n' ) { *p = '\0'; break; } } while ( p++ != data_end ); if ( ( filename = g_uri_unescape_string( filename, NULL ) ) != NULL ) { fuse_emulation_pause(); utils_open_file( filename, settings_current.auto_load, NULL ); free( filename ); display_refresh_all(); fuse_emulation_unpause(); } } gtk_drag_finish(drag_context, FALSE, FALSE, time); }
static void handle_drop( HDROP hDrop ) { size_t bufsize; char *namebuf; /* Check that only one file was dropped */ if( DragQueryFile( hDrop, ~0UL, NULL, 0 ) == 1) { bufsize = DragQueryFile( hDrop, 0, NULL, 0 ) + 1; if( ( namebuf = malloc( bufsize ) ) ) { DragQueryFile( hDrop, 0, namebuf, bufsize ); fuse_emulation_pause(); utils_open_file( namebuf, tape_can_autoload(), NULL ); free( namebuf ); display_refresh_all(); fuse_emulation_unpause(); } } DragFinish( hDrop ); }
int uidisplay_init( int width, int height ) { int x, y, error; libspectrum_dword black; const char *machine_name; colour_format_t colour_format; #if !GTK_CHECK_VERSION( 3, 0, 0 ) g_signal_connect( G_OBJECT( gtkui_drawing_area ), "expose_event", G_CALLBACK( gtkdisplay_expose ), NULL ); colour_format = FORMAT_x8b8g8r8; #else g_signal_connect( G_OBJECT( gtkui_drawing_area ), "draw", G_CALLBACK( gtkdisplay_draw ), NULL ); colour_format = FORMAT_x8r8g8b8; #endif /* #if !GTK_CHECK_VERSION( 3, 0, 0 ) */ g_signal_connect( G_OBJECT( gtkui_drawing_area ), "configure_event", G_CALLBACK( drawing_area_resize_callback ), NULL ); error = init_colours( colour_format ); if( error ) return error; black = settings_current.bw_tv ? bw_colours[0] : gtkdisplay_colours[0]; for( y = 0; y < DISPLAY_SCREEN_HEIGHT + 4; y++ ) for( x = 0; x < DISPLAY_SCREEN_WIDTH + 3; x++ ) *(libspectrum_dword*)( rgb_image + y * rgb_pitch + 4 * x ) = black; image_width = width; image_height = height; image_scale = width / DISPLAY_ASPECT_WIDTH; register_scalers( 0 ); display_refresh_all(); if ( scaler_select_scaler( current_scaler ) ) scaler_select_scaler( SCALER_NORMAL ); gtkdisplay_load_gfx_mode(); machine_name = libspectrum_machine_name( machine_current->machine ); gtkstatusbar_update_machine( machine_name ); display_ui_initialised = 1; return 0; }
int display_init( int *argc, char ***argv ) { int i, j, k, x, y; int error; if(ui_init(argc, argv)) return 1; /* Set up the 'all pixels must be refreshed' marker */ display_all_dirty = 0; for( i = 0; i < DISPLAY_SCREEN_WIDTH_COLS; i++ ) display_all_dirty = ( display_all_dirty << 1 ) | 0x01; for(i=0;i<3;i++) for(j=0;j<8;j++) for(k=0;k<8;k++) display_line_start[ (64*i) + (8*j) + k ] = 32 * ( (64*i) + j + (k*8) ); for(y=0;y<DISPLAY_HEIGHT;y++) { display_attr_start[y]=6144 + (32*(y/8)); } for(y=0;y<DISPLAY_HEIGHT;y++) for(x=0;x<DISPLAY_WIDTH_COLS;x++) { display_dirty_ytable[ display_line_start[y]+x ] = y; display_dirty_xtable[ display_line_start[y]+x ] = x; } for(y=0;y<DISPLAY_HEIGHT_ROWS;y++) for(x=0;x<DISPLAY_WIDTH_COLS;x++) { display_dirty_ytable2[ (32*y) + x ] = y * 8; display_dirty_xtable2[ (32*y) + x ] = x; } display_frame_count=0; display_flash_reversed=0; display_refresh_all(); border_changes_last = 0; if( border_changes ) { libspectrum_free( border_changes ); } border_changes = NULL; error = add_border_sentinel(); if( error ) return error; display_last_border = scld_last_dec.name.hires ? display_hires_border : display_lores_border; return 0; }
int uidisplay_init(int width, int height) { int error; image_width = width; image_height = height; image_scale = width / DISPLAY_ASPECT_WIDTH; error = register_scalers(); if( error ) return error; display_ui_initialised = 1; display_refresh_all(); return 0; }
int machine_reset( int hard_reset ) { size_t i; int error; /* Clear poke list (undoes effects of active pokes on Spectrum memory) */ pokemem_clear(); sound_ay_reset(); tape_stop(); memory_pool_free(); machine_current->ram.romcs = 0; machine_set_variable_timings( machine_current ); memory_reset(); /* Do the machine-specific bits, including loading the ROMs */ error = machine_current->reset(); if( error ) return error; module_reset( hard_reset ); error = machine_current->memory_map(); if( error ) return error; /* Set up the contention array */ for( i = 0; i < machine_current->timings.tstates_per_frame; i++ ) { ula_contention[ i ] = machine_current->ram.contend_delay( i ); ula_contention_no_mreq[ i ] = machine_current->ram.contend_delay_no_mreq( i ); } /* Update the disk menu items */ ui_menu_disk_update(); /* clear out old display image ready for new one */ display_refresh_all(); return 0; }
int machine_reset( int hard_reset ) { size_t i; int error; sound_ay_reset(); tape_stop(); memory_pool_free(); machine_current->ram.romcs = 0; machine_set_variable_timings( machine_current ); /* Do the machine-specific bits, including loading the ROMs */ error = machine_current->reset(); if( error ) return error; module_reset( hard_reset ); error = machine_current->memory_map(); if( error ) return error; /* Set up the contention array */ for( i = 0; i < machine_current->timings.tstates_per_frame; i++ ) { ula_contention[ i ] = machine_current->ram.contend_delay( i ); ula_contention_no_mreq[ i ] = machine_current->ram.contend_delay_no_mreq( i ); } /* Check for an Interface I ROM */ ui_statusbar_update( UI_STATUSBAR_ITEM_MICRODRIVE, UI_STATUSBAR_STATE_NOT_AVAILABLE ); /* Update the disk menu items */ ui_menu_disk_update(); /* clear out old display image ready for new one */ display_refresh_all(); return 0; }
static int drawing_area_resize( int width, int height, int force_scaler ) { int size; size = width / DISPLAY_ASPECT_WIDTH; if( size > height / DISPLAY_SCREEN_HEIGHT ) size = height / DISPLAY_SCREEN_HEIGHT; /* If we're the same size as before, no need to do anything else */ if( size == gtkdisplay_current_size ) return 0; gtkdisplay_current_size = size; register_scalers( force_scaler ); memset( scaled_image, 0, sizeof( scaled_image ) ); #if GTK_CHECK_VERSION( 3, 0, 0 ) /* Create a bigger surface for the new display size */ float scale = (float)gtkdisplay_current_size / image_scale; if( surface ) cairo_surface_destroy( surface ); surface = cairo_image_surface_create_for_data( scaled_image, CAIRO_FORMAT_RGB24, scale * image_width, scale * image_height, scaled_pitch ); #endif /* #if GTK_CHECK_VERSION( 3, 0, 0 ) */ display_refresh_all(); return 0; }
static void widget_query_generic_keyhandler( widget_query_entry *query, int num_entries, input_key key ) { int new_highlight_line = 0; int cursor_pressed = 0; widget_query_entry *ptr; int menu_width = widget_calculate_query_width( title, query, message_lines, num_message_lines ); int menu_left_edge_x = DISPLAY_WIDTH_COLS/2-menu_width/2; switch( key ) { #if 0 case INPUT_KEY_Resize: /* Fake keypress used on window resize */ widget_dialog_with_border( 1, 2, 30, 2 + 20 ); widget_general_show_all( &widget_options_settings ); break; #endif case INPUT_KEY_Escape: case INPUT_JOYSTICK_FIRE_2: widget_end_widget( WIDGET_FINISHED_CANCEL ); break; case INPUT_KEY_Up: case INPUT_KEY_7: case INPUT_JOYSTICK_UP: if ( highlight_line ) { new_highlight_line = highlight_line - 1; cursor_pressed = 1; } break; case INPUT_KEY_Down: case INPUT_KEY_6: case INPUT_JOYSTICK_DOWN: if ( highlight_line < num_entries - 2 ) { new_highlight_line = highlight_line + 1; cursor_pressed = 1; } break; case INPUT_KEY_Return: case INPUT_KEY_KP_Enter: case INPUT_JOYSTICK_FIRE_1: query[highlight_line].click(); widget_end_all( WIDGET_FINISHED_OK ); display_refresh_all(); return; default: /* Keep gcc happy */ break; } if( cursor_pressed ) { int old_highlight_line = highlight_line; highlight_line = new_highlight_line; widget_query_line_draw( menu_left_edge_x, menu_width, query + old_highlight_line, query[old_highlight_line].text ); widget_query_line_draw( menu_left_edge_x, menu_width, query + highlight_line, query[highlight_line].text ); return; } for( ptr=query; ptr->text != NULL; ptr++ ) { if( key == ptr->key ) { int old_highlight_line = highlight_line; ptr->click(); highlight_line = ptr->index; widget_query_line_draw( menu_left_edge_x, menu_width, query + old_highlight_line, query[old_highlight_line].text ); widget_query_line_draw( menu_left_edge_x, menu_width, ptr, query[highlight_line].text ); break; } } }
int screenshot_scr_read( const char *filename ) { int error = 0; int i; utils_file screen; error = utils_read_file( filename, &screen ); if( error ) return error; switch( screen.length ) { case STANDARD_SCR_SIZE: memcpy( &RAM[ memory_current_screen ][display_get_addr(0,0)], screen.buffer, screen.length ); /* If it is a Timex and it is in hi colour or hires mode, switch out of hires or hicolour mode */ if( scld_last_dec.name.b1 || scld_last_dec.name.hires ) scld_dec_write( 0xff, scld_last_dec.byte & ~HIRES ); break; case HICOLOUR_SCR_SIZE: /* If it is a Timex and it is not in hi colour mode, copy screen and switch mode if neccesary */ /* If it is not a Timex copy the mono bitmap and raise an error */ if( machine_current->timex ) { if( !scld_last_dec.name.b1 ) scld_dec_write( 0xff, ( scld_last_dec.byte & ~HIRESATTR ) | EXTCOLOUR ); memcpy( &RAM[ memory_current_screen ][display_get_addr(0,0) + ALTDFILE_OFFSET], screen.buffer + MONO_BITMAP_SIZE, MONO_BITMAP_SIZE ); } else ui_error( UI_ERROR_INFO, "The file contained a TC2048 high-colour screen, loaded as mono"); memcpy( &RAM[ memory_current_screen ][display_get_addr(0,0)], screen.buffer, MONO_BITMAP_SIZE ); break; case HIRES_SCR_SIZE: /* If it is a Timex and it is not in hi res mode, copy screen and switch mode if neccesary */ /* If it is not a Timex scale the bitmap and raise an error */ if( machine_current->timex ) { memcpy( &RAM[ memory_current_screen ][display_get_addr(0,0)], screen.buffer, MONO_BITMAP_SIZE ); memcpy( &RAM[ memory_current_screen ][display_get_addr(0,0)] + ALTDFILE_OFFSET, screen.buffer + MONO_BITMAP_SIZE, MONO_BITMAP_SIZE ); if( !scld_last_dec.name.hires ) scld_dec_write( 0xff, ( scld_last_dec.byte & ~( HIRESCOLMASK | HIRES ) ) | ( *(screen.buffer + HIRES_ATTR) & ( HIRESCOLMASK | HIRES ) ) ); } else { libspectrum_byte attr = hires_convert_dec( *(screen.buffer + HIRES_ATTR) ); for( i = 0; i < MONO_BITMAP_SIZE; i++ ) RAM[ memory_current_screen ][display_get_addr(0,0) + i] = convert_hires_to_lores( *(screen.buffer + MONO_BITMAP_SIZE + i), *(screen.buffer + i) ); /* set attributes based on hires attribute byte */ for( i = 0; i < 768; i++ ) RAM[ memory_current_screen ][display_get_addr(0,0) + MONO_BITMAP_SIZE + i] = attr; ui_error( UI_ERROR_INFO, "The file contained a TC2048 high-res screen, converted to lores"); } break; default: ui_error( UI_ERROR_ERROR, "'%s' is not a valid scr file", filename ); error = 1; } utils_close_file( &screen ); display_refresh_all(); return error; }
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; }