⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.cpp

📁 linux下实现视频播放的播放器
💻 CPP
字号:
/* *  Copyright (C) 2005-2008  gulikoza, mtrooper * *  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. *//* $Id$ */#include "main.h"#define USES_BASECLASS#include "video.h"// GUI elements#include "wxgui/Channel_List.h"#include "wxgui/StreamInfo.h"#include "wxgui/Settings.h"//#define DEBUG#include "log.h"#define MOUSEDELAY 300static unsigned int mouseticks1;static unsigned int mouseticks2;#ifdef WIN32// Cursor positionstatic POINT pt;#endif#define MODULE "Events"static void HandleKeyDown(SDL_keysym * keysym);static void HandleEvent(SDL_Event * event);void ProcessEvents(void){    SDL_Event event;    // Process SDL event queue    while(SDL_PollEvent(&event))	HandleEvent(&event);    // Process our own event queue    while(events->Poll(&event)) {	if(event.type == SDL_USEREVENT+1) {	    sdl.decoder = (Decoder *)event.user.data1;	    if(sdl.decoder) {		if(event.user.data2) {		    sdl.decoder->SetFilterInfo(sdl.renderer);		    if(sdl.renderer) {			sdl.renderer->Lock();			// The change will be implemented at the next video switch			sdl.video->colorspace=(unsigned int)PT2L(event.user.data2);			sdl.renderer->Unlock();		    }		} else {		    sdl.decoder->SetFilterInfo(sdl.audio);		}		if(!sdl.silent)		    sdl.decoder->ThreadCreate();	    }	    if(sdl.decoder)		sdl.count++;	    else		sdl.count--;	    LOG_MSG("Received decoder address event: 0x%p, decoders: %d", sdl.decoder, sdl.count);	    break;	} else {	    LOG_MSG("Unknown custom event type 0x%x", event.type);	}    }}static void HandleEvent(SDL_Event * event){    static bool right = false;    switch(event->type) {	case SDL_KEYDOWN:	    HandleKeyDown(&event->key.keysym);	    break;	case SDL_MOUSEMOTION: {	    sdl.lastMouseActivityTicks = SDL_GetTicks();	    if((sdl.hideMouseInFullscreenDelay > 0) && !SDL_ShowCursor(SDL_QUERY)) {		SDL_ShowCursor(SDL_ENABLE);	    }#ifdef WIN32	    SDL_MouseMotionEvent * motion = &event->motion;	    if(!sdl.screen.fullscreen && (motion->state&SDL_BUTTON(1)) && (sdl.hwnd)) {		POINT newpt;		GetCursorPos(&newpt);		DEBUG_MSG("Window move: %dx%d", newpt.x - pt.x, newpt.y - pt.y);		if((newpt.x - pt.x != 0) || (newpt.y - pt.y != 0)) {		    RECT rect;		    GetWindowRect(sdl.hwnd, &rect);		    rect.left += newpt.x - pt.x;		    rect.top += newpt.y - pt.y;		    pt.x = newpt.x;		    pt.y = newpt.y;		    SetWindowPos(sdl.hwnd, 0, rect.left, rect.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE);		}	    }#endif	    break;	}	case SDL_MOUSEBUTTONDOWN: {	    SDL_MouseButtonEvent * button = &event->button;	    switch(button->button) {		case SDL_BUTTON_LEFT: {#ifdef WIN32		    GetCursorPos(&pt);#endif		    unsigned int ticks = SDL_GetTicks();		    if(ticks < mouseticks1 + MOUSEDELAY) {			mouseticks1 = 0;			if(!sdl.silent) {			    sdl.screen.fullscreen = !sdl.screen.fullscreen;	    		    SetupScreen(0, 0, false);			}		    } else			mouseticks1 = ticks;		    break;		}		case SDL_BUTTON_RIGHT: {		    right = true;		    unsigned int ticks = SDL_GetTicks();		    if(ticks < mouseticks2 + MOUSEDELAY) {			mouseticks2 = 0;#ifdef WIN32			if((!sdl.silent) && (sdl.hwnd)) {			    if(sdl.topmost) {				SetWindowPos(sdl.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);				sdl.topmost = FALSE;			    } else {				SetWindowPos(sdl.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);				sdl.topmost = TRUE;			    }			}#endif		    } else			mouseticks2 = ticks;		    break;		}		case SDL_BUTTON_WHEELUP:		    if(right) {			if(sdl.audio->volume < 1.0f) {			    sdl.audio->volume += 0.05f;			    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);			}			break;		    }		    sdl.channel->NextChannel();		break;		case SDL_BUTTON_WHEELDOWN:		    if(right) {			if(sdl.audio->volume > 0.0f) {			    sdl.audio->volume -= 0.05f;			    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);			}			break;		    }		    sdl.channel->PreviousChannel();		break;	    }	    break;	}	case SDL_MOUSEBUTTONUP: {	    SDL_MouseButtonEvent * button = &event->button;	    if(button->button == SDL_BUTTON_RIGHT)		right = false;	    break;	}	case SDL_QUIT:	    QuitProgram(true);	    break;	case SDL_SYSWMEVENT:	    DEBUG_MSG("Received SysWMEvent");	    break;	case SDL_VIDEORESIZE:	    if(!sdl.silent)		SetupScreen(event->resize.w, event->resize.h, false);	    break;	case SDL_USEREVENT:	    if(!sdl.silent)		SetupScreen((int)PT2L(event->user.data1),(int)PT2L(event->user.data2), true);	    break;	case SDL_USEREVENT+2:	    sdl_bar.SetStereo((unsigned int)PT2L(event->user.data2)-1);	    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);	    reinit_audio((unsigned int)PT2L(event->user.data1));	    SDL_SemPost(sdl.audio->audio_change);	    break;	default:	    DEBUG_MSG("Received Event 0x%x", event->type);	    break;    }}static void HandleKeyDown(SDL_keysym* keysym){    switch(keysym->sym) {	case SDLK_BACKSPACE:	    if(keysym->mod & KMOD_CTRL) {		sdl.channel->LastChannel();	    }	    break;	case SDLK_ESCAPE:	    if(!((keysym->mod & KMOD_CTRL) || (keysym->mod & KMOD_ALT) || (keysym->mod & KMOD_SHIFT))) {		ERROR_MSG("Received ESC key");		QuitProgram(true);	    }	    break;	case SDLK_SPACE:	    sdl.deint_mode = ++sdl.deint_mode % 4;	    if(sdl.renderer) sdl.renderer->SetDeinterlace(sdl.deint_mode);	    sdl_bar.SetDeinterlace(sdl.deint_mode);	    break;	case SDLK_0: case SDLK_1: case SDLK_2: case SDLK_3: case SDLK_4:	case SDLK_5: case SDLK_6: case SDLK_7: case SDLK_8: case SDLK_9:	{	    unsigned int ticks = SDL_GetTicks();	    if((sdl.keypress.channel) && (ticks < sdl.keypress.ticks + SWITCHDELAY)) {		sdl.keypress.channel *= 10;		sdl.keypress.channel += keysym->sym - SDLK_0;	    } else		sdl.keypress.channel = keysym->sym - SDLK_0;	    sdl.keypress.ticks = ticks;	    break;	}	case SDLK_a:	    if(sdl.renderer) {		sdl.renderer->Lock();		if(sdl.video->aspect == 0.0) {		    sdl.video->aspect = 16.0/9.0;		    sdl_bar.SetAspect(1);		} else if((sdl.video->aspect == 16.0/9.0) && (!(sdl.video->cropy&0xF00))) {		    sdl.video->cropy |= 0xF00;		    sdl_bar.SetAspect(2);		} else if((sdl.video->aspect == 16.0/9.0) &&   (sdl.video->cropy&0xF00)) {		    sdl.video->cropy = (sdl.video->cropy&0x3F)|0xF000;		    sdl.video->aspect = 16.0/10.0;		    sdl_bar.SetAspect(3);		} else if(sdl.video->aspect == 16.0/10.0) {		    sdl.video->cropy &= 0x3F;		    sdl.video->aspect = 4.0/3.0;		    sdl_bar.SetAspect(4);		} else {		    sdl.video->aspect = 0.0;		    sdl_bar.SetAspect(0);		}		LOG_MSG("AR forced to %.2f", sdl.video->aspect);		sdl.video->changed = true;		sdl.renderer->Unlock();	    }	    break;#if (C_HAVE_WXGUI)	case SDLK_c:	    gui.wxSettings->LoadSettings();	    gui.wxSettings->Show(true);	    break;#endif	case SDLK_f:	    if(!sdl.silent) {		sdl.screen.fullscreen = !sdl.screen.fullscreen;		SetupScreen(0, 0, false);	    }	    break;#if (C_HAVE_WXGUI)	case SDLK_i:	    if(gui.wxStreamInfo->IsVisible())		gui.wxStreamInfo->Show(false);	    else if(!sdl.screen.fullscreen)		gui.wxStreamInfo->Show(true);	    break;	case SDLK_l:	    if(gui.wxChannelList->IsVisible())		gui.wxChannelList->Show(false);	    else if(!sdl.screen.fullscreen) {		gui.wxChannelList->Show(true);		gui.wxChannelList->FocusChanel(sdl.channel->GetNum());	    }	    break;#endif	case SDLK_p:#if (C_HAS_LIBPOSTPROC)	    if(keysym->mod & KMOD_CTRL) {		if(!sdl.ppMode.empty()) {		    sdl.ppEnabled = !sdl.ppEnabled;		    LOG_MSG("Post-process %s", sdl.ppEnabled ? "enabled" : "disabled");		}	    }	    else#endif	    if(sdl.renderer) {		sdl.renderer->Lock();		if(keysym->mod & KMOD_SHIFT) {		    ++(sdl.video->offset);		} else {		    --(sdl.video->offset);		}		sdl.renderer->Unlock();		LOG_MSG("Offset is now %d", sdl.video->offset);	    }	    break;	case SDLK_o:#if (C_HAVE_WXGUI)	    if(keysym->mod & KMOD_CTRL) {		if(!sdl.screen.fullscreen) {		    CStr str = wxFileSelector(wxT("Choose file"), wxT(""), wxT(""), wxT("ts"),			wxT("MPEG transport stream (*.ts)|*.ts|MPEG Transport stream (*.mpg)|*.mpg"), wxFD_OPEN|wxFD_FILE_MUST_EXIST);		    sdl.channel->OpenFile(str);#ifdef WIN32		    ::SetForegroundWindow(sdl.hwnd);#endif		}		break;	    }#endif	    if(sdl.renderer) {		sdl.renderer->Lock();		if(keysym->mod & KMOD_SHIFT) {		    if(sdl.video->cropx&0x3F)			--(sdl.video->cropx);		    if(sdl.video->cropy&0x3F)			--(sdl.video->cropy);		} else {		    if((sdl.video->cropx&0x3F) != 0x3F)			++(sdl.video->cropx);		    if((sdl.video->cropy&0x3F) != 0x3F)			++(sdl.video->cropy);		}		sdl.video->changed = true;		sdl.renderer->Unlock();		LOG_MSG("Crop is now 0x%xx0x%x", sdl.video->cropx, sdl.video->cropy);	    }	    break;	case SDLK_r:	    if(keysym->mod & KMOD_SHIFT) {		sdl.channel->ToggleRecord();		sdl_bar.SetRec(sdl.recording);	    }	    break;	case SDLK_s:	    if(keysym->mod & KMOD_SHIFT) {		if(sdl.channelSurfing) sdl.channelSurfing = 0;		else sdl.channelSurfing = SDL_GetTicks();		sdl_bar.SetChannelSurfing(sdl.channelSurfing != 0);	    } else if(sdl.audio->stereo) {		SDL_LockAudio();		sdl.audio->mode = ++sdl.audio->mode % 3;		SDL_UnlockAudio();		sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);	    }	    break;	case SDLK_KP0: case SDLK_KP1: case SDLK_KP2: case SDLK_KP3: case SDLK_KP4:	case SDLK_KP5: case SDLK_KP6: case SDLK_KP7: case SDLK_KP8: case SDLK_KP9:	{	    unsigned int ticks = SDL_GetTicks();	    if((sdl.keypress.channel) && (ticks < sdl.keypress.ticks + SWITCHDELAY)) {		sdl.keypress.channel *= 10;		sdl.keypress.channel += keysym->sym - SDLK_KP0;	    } else		sdl.keypress.channel = keysym->sym - SDLK_KP0;	    sdl.keypress.ticks = ticks;	    break;	}	case SDLK_PAGEUP: case SDLK_UP:	    sdl.channel->NextChannel();	    break;	case SDLK_PAGEDOWN: case SDLK_DOWN:	    sdl.channel->PreviousChannel();	    break;	case SDLK_LEFT:	    if(sdl.audio->prevVolume > 0.0f) {		sdl.audio->prevVolume -= 0.05f;		sdl.audio->volume = sdl.audio->prevVolume;	    }	    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);	    ERROR_MSG("Volume is %.2f", sdl.audio->volume);	    break;	case SDLK_RIGHT:	    if(sdl.audio->prevVolume < 1.0f) {		sdl.audio->prevVolume += 0.05f;		sdl.audio->volume = sdl.audio->prevVolume;	    }	    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);	    ERROR_MSG("Volume is %.2f", sdl.audio->volume);	    break;	case SDLK_m:	    if(sdl.audio->volume > 0.0f)		sdl.audio->volume = 0.0f;	    else		sdl.audio->volume = sdl.audio->prevVolume;	    sdl_bar.SetVolume(lrintf(sdl.audio->volume*100), sdl.audio->mode);	    break;	default:	    LOG_MSG("Received Key 0x%x", keysym->sym);	    break;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -