📄 sdl.c
字号:
CloseDisplay( p_vout ); SDL_QuitSubSystem( SDL_INIT_VIDEO ); free( p_vout->p_sys );}/***************************************************************************** * Manage: handle Sys events ***************************************************************************** * This function should be called regularly by video output thread. It returns * a non null value if an error occurred. *****************************************************************************/static int Manage( vout_thread_t *p_vout ){ SDL_Event event; /* SDL event */ vlc_value_t val; unsigned int i_width, i_height, i_x, i_y; /* Process events */ while( SDL_PollEvent(&event) ) { switch( event.type ) { case SDL_VIDEORESIZE: /* Resizing of window */ /* Update dimensions */ p_vout->i_changes |= VOUT_SIZE_CHANGE; p_vout->i_window_width = p_vout->p_sys->i_width = event.resize.w; p_vout->i_window_height = p_vout->p_sys->i_height = event.resize.h; break; case SDL_MOUSEMOTION: vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height, &i_x, &i_y, &i_width, &i_height ); val.i_int = ( event.motion.x - i_x ) * p_vout->render.i_width / i_width; var_Set( p_vout, "mouse-x", val ); val.i_int = ( event.motion.y - i_y ) * p_vout->render.i_height / i_height; var_Set( p_vout, "mouse-y", val ); val.b_bool = VLC_TRUE; var_Set( p_vout, "mouse-moved", val ); if( p_vout->p_sys->b_cursor && (abs(event.motion.xrel) > 2 || abs(event.motion.yrel) > 2) ) { if( p_vout->p_sys->b_cursor_autohidden ) { p_vout->p_sys->b_cursor_autohidden = 0; SDL_ShowCursor( 1 ); } else { p_vout->p_sys->i_lastmoved = mdate(); } } break; case SDL_MOUSEBUTTONUP: switch( event.button.button ) { case SDL_BUTTON_LEFT: val.b_bool = VLC_TRUE; var_Set( p_vout, "mouse-clicked", val ); break; case SDL_BUTTON_RIGHT: { intf_thread_t *p_intf; p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE ); if( p_intf ) { p_intf->b_menu_change = 1; vlc_object_release( p_intf ); } } break; } break; case SDL_MOUSEBUTTONDOWN: switch( event.button.button ) { case SDL_BUTTON_LEFT: /* In this part we will eventually manage * clicks for DVD navigation for instance. */ /* detect double-clicks */ if( ( mdate() - p_vout->p_sys->i_lastpressed ) < 300000 ) p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; p_vout->p_sys->i_lastpressed = mdate(); break; case 4: break; case 5: break; } break; case SDL_QUIT: p_vout->p_vlc->b_die = 1; break; case SDL_KEYDOWN: /* if a key is pressed */ switch( event.key.keysym.sym ) { case SDLK_ESCAPE: if( p_vout->b_fullscreen ) { p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; } else { p_vout->p_vlc->b_die = 1; } break; case SDLK_q: /* quit */ p_vout->p_vlc->b_die = 1; break; case SDLK_f: /* switch to fullscreen */ p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE; break; case SDLK_c: /* toggle grayscale */ p_vout->b_grayscale = ! p_vout->b_grayscale; p_vout->i_changes |= VOUT_GRAYSCALE_CHANGE; break; case SDLK_i: /* toggle info */ p_vout->b_info = ! p_vout->b_info; p_vout->i_changes |= VOUT_INFO_CHANGE; break; case SDLK_s: /* toggle scaling */ p_vout->b_scale = ! p_vout->b_scale; p_vout->i_changes |= VOUT_SCALE_CHANGE; break; case SDLK_SPACE: /* toggle interface */ p_vout->b_interface = ! p_vout->b_interface; p_vout->i_changes |= VOUT_INTF_CHANGE; break; case SDLK_MENU: { intf_thread_t *p_intf; p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF, FIND_ANYWHERE ); if( p_intf != NULL ) { p_intf->b_menu_change = 1; vlc_object_release( p_intf ); } } break; case SDLK_LEFT: break; case SDLK_RIGHT: break; case SDLK_UP: break; case SDLK_DOWN: break; case SDLK_b: { audio_volume_t i_volume; if ( !aout_VolumeDown( p_vout, 1, &i_volume ) ) { msg_Dbg( p_vout, "audio volume is now %d", i_volume ); } else { msg_Dbg( p_vout, "audio volume: operation not supported" ); } } break; case SDLK_n: { audio_volume_t i_volume; if ( !aout_VolumeUp( p_vout, 1, &i_volume ) ) { msg_Dbg( p_vout, "audio volume is now %d", i_volume ); } else { msg_Dbg( p_vout, "audio volume: operation not supported" ); } } break; default: break; } break; default: break; } } /* Fullscreen change */ if( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE ) { p_vout->b_fullscreen = ! p_vout->b_fullscreen; p_vout->p_sys->b_cursor_autohidden = 0; SDL_ShowCursor( p_vout->p_sys->b_cursor && ! p_vout->p_sys->b_cursor_autohidden ); p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE; p_vout->i_changes |= VOUT_SIZE_CHANGE; } /* * Size change */ if( p_vout->i_changes & VOUT_SIZE_CHANGE ) { msg_Dbg( p_vout, "video display resized (%dx%d)", p_vout->p_sys->i_width, p_vout->p_sys->i_height ); CloseDisplay( p_vout ); OpenDisplay( p_vout ); /* We don't need to signal the vout thread about the size change if * we can handle rescaling ourselves */ if( p_vout->p_sys->p_overlay != NULL ) p_vout->i_changes &= ~VOUT_SIZE_CHANGE; } /* Pointer change */ if( ! p_vout->p_sys->b_cursor_autohidden && ( mdate() - p_vout->p_sys->i_lastmoved > 2000000 ) ) { /* Hide the mouse automatically */ p_vout->p_sys->b_cursor_autohidden = 1; SDL_ShowCursor( 0 ); } return VLC_SUCCESS;}/***************************************************************************** * Display: displays previously rendered output ***************************************************************************** * This function sends the currently rendered image to the display. *****************************************************************************/static void Display( vout_thread_t *p_vout, picture_t *p_pic ){ unsigned int x, y, w, h; SDL_Rect disp; vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height, &x, &y, &w, &h ); disp.x = x; disp.y = y; disp.w = w; disp.h = h; if( p_vout->p_sys->p_overlay == NULL ) { /* RGB picture */ SDL_Flip( p_vout->p_sys->p_display ); } else { /* Overlay picture */ SDL_UnlockYUVOverlay( p_pic->p_sys->p_overlay); SDL_DisplayYUVOverlay( p_pic->p_sys->p_overlay , &disp ); SDL_LockYUVOverlay( p_pic->p_sys->p_overlay); }}/* following functions are local *//***************************************************************************** * OpenDisplay: open and initialize SDL device ***************************************************************************** * Open and initialize display according to preferences specified in the vout * thread fields. *****************************************************************************/static int OpenDisplay( vout_thread_t *p_vout ){ uint32_t i_flags; int i_bpp; /* SDL fucked up fourcc definitions on bigendian machines */ uint32_t i_sdl_chroma; /* Set main window's size */ p_vout->p_sys->i_width = p_vout->b_fullscreen ? p_vout->output.i_width : p_vout->i_window_width; p_vout->p_sys->i_height = p_vout->b_fullscreen ? p_vout->output.i_height : p_vout->i_window_height; /* Initialize flags and cursor */ i_flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_DOUBLEBUF;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -