# HG changeset patch # User benoitrigolleau # Date 1195226324 0 # Node ID 2ac52ea3c1c41ef7c8d95b9c7beff6c5892ba446 # Parent 0442224a95539ac09dd3bc6f2d731c711c6df4d2 video mouse events are in SDL now. The code is really better now, but there is a display bug when you zoom in, zoom out diff -r 0442224a9553 -r 2ac52ea3c1c4 data/fileio/VideoFileReader.cpp --- a/data/fileio/VideoFileReader.cpp Fri Nov 16 13:17:55 2007 +0000 +++ b/data/fileio/VideoFileReader.cpp Fri Nov 16 15:18:44 2007 +0000 @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -32,10 +33,10 @@ #ifdef WIN32 #include #endif -extern float zoomFivan; long long countFreq; int Videow=320; int Videoh=240; +float zoomFivan=1; VideoFileReader::VideoFileReader(QString path, bool showProgress, CacheMode mode) : CodedAudioFileReader(mode), m_path(path) @@ -47,6 +48,7 @@ m_bitrateNum = 0; m_bitrateDenom = 0; m_cancelled = false; + m_zoomfactor = 1; struct stat stat; if (::stat(path.toLocal8Bit().data(), &stat) == -1 || stat.st_size == 0) { @@ -195,17 +197,24 @@ SDL_ffmpegGetVideoSize(file, &w, &h); MainWindow * MWins=MainWindow::instance(); - MWins->setSDLInitSize(w,h); + SDL_Init(SDL_INIT_VIDEO); - Videow=w=320*zoomFivan; - Videoh=h=240*zoomFivan; + Videow=w;//=320*m_zoomfactor; + Videoh=h;//=240*m_zoomfactor; + + //TODO update the size according to the component size + // this will not work if video size is bigger than window size. + m_width =w; + m_height =h; + + MWins->setSDLInitSize(w,h); // Open the Video device screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); //SDL_WM_SetCaption("EASAIER Video Player", "EASAIER Video Player"); if(!screen) { - printf("Couldn't open video: %s\n", SDL_GetError()); + fprintf(stderr, "Couldn't open video: %s\n", SDL_GetError()); return false; } return true; @@ -216,6 +225,61 @@ return ((VideoFileReader *)t)->videoPlay(); } +void VideoFileReader::processEvents() +{ + SDL_Event event; + + while (SDL_PollEvent(&event)) + { + float signe = 1; + switch (event.type) + { + case SDL_MOUSEMOTION: + break; + case SDL_MOUSEBUTTONDOWN: + switch(event.button.button){ + case SDL_BUTTON_LEFT : + break; + case SDL_BUTTON_MIDDLE: + break; + case SDL_BUTTON_RIGHT: + break; + default: + break; + } + break; + case SDL_MOUSEBUTTONUP: + + switch(event.button.button){ + case SDL_BUTTON_LEFT : + break; + case SDL_BUTTON_MIDDLE: + break; + case SDL_BUTTON_RIGHT: + break; + case SDL_BUTTON_WHEELDOWN: + signe = -1; + case SDL_BUTTON_WHEELUP: + float f,f2; + f = m_zoomfactor + signe * 0.1; + f2 = f; + if((int)(m_width*f+0.5)%4){ + f = (m_width*f - (int)(m_width*f+0.5)%4)/m_width; + } + m_zoomfactor=f; + + break; + default: + break; + } + break; + + default: + break; + } + } +} + int VideoFileReader::videoPlay() { @@ -243,12 +307,24 @@ film->vs[film->videoStream]->lastTimeStamp=0; while( film->videoThreadActive ) { - if (!(w==(int)(320*zoomFivan))){ - w=320*zoomFivan; - h=240*zoomFivan; - // Open the Video device - screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); + if (!(w==(int)(Videow*m_zoomfactor))){ + w=Videow*m_zoomfactor; + h=Videoh*m_zoomfactor; + if (w<80 || h<60){ + w=80; + h=60; + m_zoomfactor = 80.0/Videow; + } + // Open the Video device + zoomFivan = m_zoomfactor; + screen = SDL_SetVideoMode(w, h, 0, SDL_DOUBLEBUF|SDL_HWSURFACE|SDL_RESIZABLE|SDL_ASYNCBLIT|SDL_HWACCEL); + MWins->setSDLInitSize(w,h); + m_width =w; + m_height =h; + } + // calls process events function, to take in account the user input + processEvents(); if (MWins->isAudioPlaying()) { if ((SDL_ffmpegGetState(film))||((long)(abs((long)(film->audioTime - (int64_t)(MWins->Get_CurAudioTime()))))>=1000)) diff -r 0442224a9553 -r 2ac52ea3c1c4 data/fileio/VideoFileReader.h --- a/data/fileio/VideoFileReader.h Fri Nov 16 13:17:55 2007 +0000 +++ b/data/fileio/VideoFileReader.h Fri Nov 16 15:18:44 2007 +0000 @@ -42,6 +42,7 @@ virtual QString getError() const { return m_error; } static void getSupportedExtensions(std::set &extensions); + void VideoFileReader::processEvents(); protected: QString m_path; @@ -55,6 +56,7 @@ bool m_cancelled; int m_width; int m_height; + float m_zoomfactor; diff -r 0442224a9553 -r 2ac52ea3c1c4 data/model/SDLWidget.cpp --- a/data/model/SDLWidget.cpp Fri Nov 16 13:17:55 2007 +0000 +++ b/data/model/SDLWidget.cpp Fri Nov 16 15:18:44 2007 +0000 @@ -2,7 +2,7 @@ #include #include #include "SDLWidget.h" -float zoomFivan=1; + @@ -11,7 +11,6 @@ { setAttribute(Qt::WA_PaintOnScreen); setAttribute(Qt::WA_NoSystemBackground); - m_zoomFactor = 1; connect(this,SIGNAL(initSizeChanged()),this,SLOT(updateMinSize())); } @@ -21,54 +20,17 @@ SDL_Quit(); } -void SDLWidget::setZoomFactor( float f ) -{ - int w, h; - - if( f == m_zoomFactor ) - return; - - m_zoomFactor = f; - - w = m_width*m_zoomFactor; - h = m_height*m_zoomFactor; - setMinimumSize( w, h ); - emit(sizeChanged(w,h)); - emit(zoomfactorChanged(f)); - - /*QWidget *p = dynamic_cast( parent() ); - if( p ){ - resize( p->width(), p->height() ); - }*/ -} - -void SDLWidget::wheelEvent( QWheelEvent *event ) -{ - float f; - - f = m_zoomFactor + 0.001*event->delta(); - - if( f < 32.0/m_width ){ - f = 32.0/m_height; - } - if((int)(m_width*f)%4){ - f = (m_width*f - (int)(m_width*f)%4)/m_width; - } -zoomFivan=f; - setZoomFactor( f ); -} void SDLWidget::setInitSize(int w, int h){ - if(m_width<=0 && m_height<=0){ - m_width = w; - m_height =h; - emit(initSizeChanged()); - } + m_width = w; + m_height =h; + emit(initSizeChanged()); } void SDLWidget::updateMinSize() { - setMinimumSize( m_width*m_zoomFactor,m_height*m_zoomFactor ); + setMinimumSize( m_width,m_height); + setMaximumSize( m_width,m_height); } @@ -77,6 +39,9 @@ { (void)e; + + //QWidget::showEvent(e); + if(!windowInitialized) { // it's here the link between SDL and QT diff -r 0442224a9553 -r 2ac52ea3c1c4 data/model/SDLWidget.h --- a/data/model/SDLWidget.h Fri Nov 16 13:17:55 2007 +0000 +++ b/data/model/SDLWidget.h Fri Nov 16 15:18:44 2007 +0000 @@ -22,16 +22,13 @@ void setInitSize(int w, int h); signals: - void sizeChanged(int w, int h); - void zoomfactorChanged(float factor); void initSizeChanged(); public slots: - void setZoomFactor( float ); - void wheelEvent( QWheelEvent* ); + protected: - + bool windowInitialized; SDL_Surface *screen; int m_width; @@ -42,8 +39,6 @@ protected slots: void updateMinSize(); -private: - float m_zoomFactor; }; diff -r 0442224a9553 -r 2ac52ea3c1c4 sv/videoio/SDL_ffmpeg.cpp --- a/sv/videoio/SDL_ffmpeg.cpp Fri Nov 16 13:17:55 2007 +0000 +++ b/sv/videoio/SDL_ffmpeg.cpp Fri Nov 16 15:18:44 2007 +0000 @@ -609,8 +609,9 @@ // if new timestamp is from future, we proceed // if(buf->timestamp >= SDL_ffmpegGetPosition(file)) // { - int w=320*zoomFivan; - int h=240*zoomFivan; + int w=(int)(zoomFivan*320+0.5); + int h=(int)(zoomFivan*240+0.5); + if ((w>file->vs[file->videoStream]->width)||(h>file->vs[file->videoStream]->height)){ w=file->vs[file->videoStream]->width; h=file->vs[file->videoStream]->height; diff -r 0442224a9553 -r 2ac52ea3c1c4 widgets/svwidgets.vcproj --- a/widgets/svwidgets.vcproj Fri Nov 16 13:17:55 2007 +0000 +++ b/widgets/svwidgets.vcproj Fri Nov 16 15:18:44 2007 +0000 @@ -590,7 +590,7 @@ @@ -601,7 +601,7 @@ @@ -1162,7 +1162,7 @@ @@ -1173,7 +1173,7 @@