paragui-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[paragui-cvs] CVS: pgmpeg/test pgmpegplayerwindow.cpp,NONE,1.1 pgmpegpla


From: Eric Ross <address@hidden>
Subject: [paragui-cvs] CVS: pgmpeg/test pgmpegplayerwindow.cpp,NONE,1.1 pgmpegplayerwindow.h,NONE,1.1 pgmpegplayerwindowmoveable.h,NONE,1.1 main.cpp,1.2,1.3
Date: Sun, 02 Jun 2002 05:42:59 -0400

Update of /cvsroot/paragui/pgmpeg/test
In directory subversions:/tmp/cvs-serv32189

Modified Files:
        main.cpp 
Added Files:
        pgmpegplayerwindow.cpp pgmpegplayerwindow.h 
        pgmpegplayerwindowmoveable.h 
Log Message:
This is a complete example to show what can you do with the player. It's a 
window with the player inside. The buttons are now inside the main window. I 
think one could create multiple instances and see what happen. Have fun.


--- NEW FILE ---
#include "pgmpegplayerwindow.h"

PG_MPEGPlayerWindow:: PG_MPEGPlayerWindow(char *file, PG_Widget *parent, const 
PG_Rect & r)
  : PG_Window(parent, r, "The Player")
{
        // First, some size constants
        int heightControls = 25, widthControls = 70;

        // Next, calculate some rects
        //                                               slider title controls  
    dummy
        PG_Rect rectPlayer(0, 25, r.Width(), r.Height() - 20 - 25 - 
heightControls - 4);
        PG_Rect rectSlider(0, r.Height() - 20, r.Width(), 20);

        // The two main child widgets
        player = new PG_MPEGPlayer(file, this, rectPlayer);
        pos = new PG_Slider(this, -1, rectSlider, PG_SB_HORIZONTAL);
        
        int xpos = 0, ypos = r.Height() - 22 - heightControls, xskip = 2;

        // Start creating buttons to control the video
        controls["start"]  = new PG_Button(this, PG_IDMPEGPLAYER_PLAY,   
PG_Rect(xpos,ypos,widthControls,heightControls), "Start");
        xpos += widthControls + xskip;
        controls["stop"]   = new PG_Button(this, PG_IDMPEGPLAYER_STOP,   
PG_Rect(xpos,ypos,widthControls,heightControls), "Stop");
        xpos += widthControls + xskip;
        controls["rewind"] = new PG_Button(this, PG_IDMPEGPLAYER_REWIND, 
PG_Rect(xpos,ypos,widthControls,heightControls), "Rewind");
        xpos += widthControls + xskip;
        controls["pause"]  = new PG_Button(this, PG_IDMPEGPLAYER_PAUSE,  
PG_Rect(xpos,ypos,widthControls,heightControls), "Pause");     

        // Connect the signals :)
        player->sigFrameUpdate.connect(slot(*this, 
&PG_MPEGPlayerWindow::FrameUpdate), NULL);
        pos->sigSlide.connect(slot(*this, 
&PG_MPEGPlayerWindow::handle_reposition));

        map<string,PG_Button*>::iterator i;
        for(i=controls.begin();i!=controls.end();i++)
                (*i).second->sigButtonClick.connect(slot(*this, 
&PG_MPEGPlayerWindow::handleControl));

        // Set default values for the slider
        SetSlider();

        SetTransparency(255);
        player->SetTransparency(0);
};
  
PG_MPEGPlayerWindow::~PG_MPEGPlayerWindow()
{
        player->Stop();

        delete player;
        delete pos;

        map<string,PG_Button*>::iterator i;
        for(i=controls.begin();i!=controls.end();i++)
                delete (*i).second;
}

bool PG_MPEGPlayerWindow::handleControl(PG_Button* widget) 
{
        MPEGstatus status;
        int id = widget->GetID();

        switch(id){
        case PG_IDMPEGPLAYER_PLAY:
                player->Play();         
                break;
        case PG_IDMPEGPLAYER_STOP:
                player->Stop();
                break;
        case PG_IDMPEGPLAYER_REWIND:
                status = player->GetStatus();
                player->Rewind();
                if (status == MPEG_PLAYING) player->Play();
                break;
        case PG_IDMPEGPLAYER_PAUSE:
                player->Pause();
                break;
        default:
                return false;
        }
        return true;
}

/* notes from Teunis Peters:
 * it might be an idea to move the 'frameupdate' function into the functions
 * Play(), ...
 * but I haven't yet seen the point - the current method makes a little more
 * sense from the perspective that the PG_MPEGPlayer doesn't know about the
 * widgets.
 */

void PG_MPEGPlayerWindow::SetSlider() 
{
        MPEG_SystemInfo info;
        player->GetSystemInfo(&info);
        double v = info.current_time / info.total_time;

        pos->SetRange(0,100);
        pos->SetPosition(v * 100);
};

bool PG_MPEGPlayerWindow::handle_transparency(PG_Slider* slider, long data) {
        player->SetTransparency(data);
        Update();
        return true;
}

bool PG_MPEGPlayerWindow::handle_fastmode(PG_RadioButton* button) 
{
        player->SetFastMode(button->GetPressed());
        return true;
}

bool PG_MPEGPlayerWindow::handle_reposition(PG_Slider* slider, long data) 
{
        MPEGstatus status = player->GetStatus();
        double setp;
        setp = ((double)(data - slider->GetMinRange()) /
                (double)(slider->GetMaxRange() - slider->GetMinRange()));

        if (status == MPEG_PLAYING) player->Stop();

        MPEG_SystemInfo info;
        player->GetSystemInfo(&info);
        player->Seek(setp * info.total_size);

        if (status == MPEG_PLAYING) player->Play();
        return true;
};

bool PG_MPEGPlayerWindow::FrameUpdate(PG_Pointer *) 
{
        MPEG_SystemInfo info;
        player->GetSystemInfo(&info);
        double v = info.current_time / info.total_time;
        pos->SetPosition(v * 100);
        return true;
};

--- NEW FILE ---
#ifndef PGMPEGPLAYERWINDOW_H
#define PGMPEGPLAYERWINDOW_H

#include "pgmpeg.h"
#include "pgslider.h"
#include "pgwindow.h"
#include "pgcheckbutton.h"

#include <map>
#include <string>

#define PG_IDMPEGPLAYER_PLAY            PG_WIDGETID_INTERNAL + 7645
#define PG_IDMPEGPLAYER_STOP            PG_WIDGETID_INTERNAL + 7646
#define PG_IDMPEGPLAYER_REWIND          PG_WIDGETID_INTERNAL + 7647
#define PG_IDMPEGPLAYER_PAUSE           PG_WIDGETID_INTERNAL + 7648

class PG_MPEGPlayerWindow : public PG_Window
{
protected:
        PG_Slider* pos;
        PG_MPEGPlayer* player;
        map<string, PG_Button *> controls;
public:
        PG_MPEGPlayerWindow(char *file, PG_Widget *parent, const PG_Rect & r);
        ~PG_MPEGPlayerWindow();

        bool handle_transparency(PG_Slider* slider, long data);
        bool handle_fastmode(PG_RadioButton* button);
        bool handle_reposition(PG_Slider* slider, long data);

protected:
        bool FrameUpdate(PG_Pointer *);

        bool handleControl(PG_Button* widget);

private:
        void SetSlider();
};

#endif

--- NEW FILE ---
#include "pgmpegplayerwindow.h"

class PG_MoveableMPEGPlayerWindow : public PG_MPEGPlayerWindow 
{
        bool bDragMode;
public:
        PG_MoveableMPEGPlayerWindow(char *file, PG_Widget *parent, const 
PG_Rect & r)
          : PG_MPEGPlayerWindow(file, parent, r) 
        {
                bDragMode = false;
        };

        ~PG_MoveableMPEGPlayerWindow() { };

protected:
        bool eventMouseButtonDown(const SDL_MouseButtonEvent *button) 
        {
                bDragMode = true;
                StartWidgetDrag();
                SetCapture();
                return true;
        }
  
        bool eventMouseButtonUp(const SDL_MouseButtonEvent *button) 
        {
                if(bDragMode) {
                        EndWidgetDrag(button->x, button->y);
                        ReleaseCapture();
                }
                bDragMode = false;
                return true;
        }
  
        bool eventMouseMotion (const SDL_MouseMotionEvent *motion) 
        {
                if(!bDragMode) { return true; }
                WidgetDrag(motion->x, motion->y);
                return true;
        }
};

Index: main.cpp
===================================================================
RCS file: /cvsroot/paragui/pgmpeg/test/main.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** main.cpp    20 Apr 2002 01:24:33 -0000      1.2
--- main.cpp    2 Jun 2002 09:42:55 -0000       1.3
***************
*** 1,3 ****
- 
  #include "pgmpeg.h"
  #include "pgbutton.h"
--- 1,2 ----
***************
*** 6,98 ****
  #include "pgcheckbutton.h"
  
! class PG_MPEGPlayerWindow : public PG_MPEGPlayer
! {
!       bool bDragMode;
! public:
!       PG_MPEGPlayerWindow(char *file, PG_Widget *parent, const PG_Rect & r)
!         : PG_MPEGPlayer(file, parent, r)
!       {
!               bDragMode = false;
!       };
! 
!       ~PG_MPEGPlayerWindow()
!       {
!       };
! 
! protected:
! 
!       bool eventMouseButtonDown(const SDL_MouseButtonEvent *button) {
!           bDragMode = true;
!           StartWidgetDrag();
!           SetCapture();
!           return true;
!       }
! 
!       bool eventMouseButtonUp(const SDL_MouseButtonEvent *button) {
!           if(bDragMode) {
!               EndWidgetDrag(button->x, button->y);
!               ReleaseCapture();
!           }
!           bDragMode = false;
!           return true;
!       }
  
!       bool eventMouseMotion (const SDL_MouseMotionEvent *motion) {
!           if(!bDragMode) {
!               return true;
!           }
!           WidgetDrag(motion->x, motion->y);
!           return true;
!       }
! };
! 
! PG_MPEGPlayerWindow *thePlayer;
! 
! PARAGUI_CALLBACK(handle_start) 
! {
!       thePlayer->Play();
!         return true;
! }
! 
! PARAGUI_CALLBACK(handle_stop) 
  {
!       thePlayer->Stop();
          return true;
  }
  
! PARAGUI_CALLBACK(handle_rewind) 
  {
!       thePlayer->Rewind();
        return true;
  }
  
- PARAGUI_CALLBACK(handle_pause) 
- {
-       thePlayer->Pause();
-         return true;
- }
- 
- PARAGUI_CALLBACK(handle_transparency) 
- {
-         PG_MPEGPlayerWindow* p = 
reinterpret_cast<PG_MPEGPlayerWindow*>(clientdata);
-         p->SetTransparency(data);
-       p->Update();
-         return true;
- }
- 
- PARAGUI_CALLBACK(handle_fastmode) 
- {
-         PG_MPEGPlayerWindow* p = 
reinterpret_cast<PG_MPEGPlayerWindow*>(clientdata);
-         p->SetFastMode(data);
-         return true;
- }
- 
- PARAGUI_CALLBACK(handle_exit) 
- {
-         PG_Application* app = reinterpret_cast<PG_Application*>(clientdata);
-         app->Quit();
-         return true;
- }
- 
  class PG_Panel : public PG_ThemeWidget
  {
--- 5,24 ----
  #include "pgcheckbutton.h"
  
! #include "pgmpegplayerwindow.h"
! #include "pgmpegplayerwindowmoveable.h"
  
! bool handle_exit(PG_Button* button, PG_Pointer* clientdata)
  {
!         PG_Application* app = reinterpret_cast<PG_Application*>(clientdata);
!         app->Quit();
          return true;
  }
  
! bool delete_window(PG_Window *w)
  {
!       delete w;
        return true;
  }
  
  class PG_Panel : public PG_ThemeWidget
  {
***************
*** 132,163 ****
        int ypos = 10, height = 30, yskip = 5;
  
-       PG_Button start(&f, 12, PG_Rect(10,ypos,80,height), "Start");
-         start.SetEventCallback(MSG_BUTTONCLICK, handle_start, &app);
-         start.Show();
-       ypos += height + yskip;
- 
-       PG_Button stop(&f, 13, PG_Rect(10,ypos,80,height), "Stop");
-         stop.SetEventCallback(MSG_BUTTONCLICK, handle_stop, &app);
-         stop.Show();
-       ypos += height + yskip;
-       
-       PG_Button rewind(&f, 14, PG_Rect(10,ypos,80,height), "Rewind");
-         rewind.SetEventCallback(MSG_BUTTONCLICK, handle_rewind, &app);
-         rewind.Show();
-       ypos += height + yskip;
-       
-       PG_Button pause(&f, 15, PG_Rect(10,ypos,80,height), "Pause");
-         pause.SetEventCallback(MSG_BUTTONCLICK, handle_pause, &app);
-         pause.Show();
-       ypos += height + yskip;
-       
        PG_Button quit(&f, 16, PG_Rect(10,ypos,80,height), "Quit");
-         quit.SetEventCallback(MSG_BUTTONCLICK, handle_exit, &app);
          quit.Show();
        ypos += height + yskip;
  
!       thePlayer = new PG_MPEGPlayerWindow(argv[1], 
!                                       NULL, PG_Rect(100, 100, 640, 480));
        thePlayer->SetTransparency(128);
        thePlayer->Show();
  
--- 58,76 ----
        int ypos = 10, height = 30, yskip = 5;
  
        PG_Button quit(&f, 16, PG_Rect(10,ypos,80,height), "Quit");
          quit.Show();
        ypos += height + yskip;
  
!         PG_MPEGPlayerWindow *thePlayer;
!       thePlayer = new PG_MPEGPlayerWindow(argv[1], NULL, PG_Rect(100, 100, 
! #if 0
!                                                           640, 480
! #else
!                                                           320, 300
! #endif
!                                                           ));
! 
        thePlayer->SetTransparency(128);
+       thePlayer->sigWindowClose.connect(slot(delete_window));
        thePlayer->Show();
  
***************
*** 167,175 ****
        PG_Slider slider(&win, -1, PG_Rect(10,65,180,20), PG_SB_HORIZONTAL);
        slider.SetRange(0, 255);
!       slider.SetPosition(128);                
!         slider.SetEventCallback(MSG_SLIDE, handle_transparency, thePlayer);
  
        PG_CheckButton check(&win, -1, PG_Rect(10,90,180,20), "fast 
displaymode");
!         check.SetEventCallback(MSG_BUTTONCLICK, handle_fastmode, thePlayer);
        
        win.SetTransparency(128);
--- 80,91 ----
        PG_Slider slider(&win, -1, PG_Rect(10,65,180,20), PG_SB_HORIZONTAL);
        slider.SetRange(0, 255);
!       slider.SetPosition(0);          
  
        PG_CheckButton check(&win, -1, PG_Rect(10,90,180,20), "fast 
displaymode");
! 
!         quit.sigButtonClick.connect(slot(handle_exit), &app);
! 
!         slider.sigSlide.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_transparency));
!         check.sigButtonClick.connect(slot(*thePlayer, 
&PG_MPEGPlayerWindow::handle_fastmode));
        
        win.SetTransparency(128);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]