home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ool.zip / OOL / samples / sample3 / sample3.cpp < prev    next >
Text File  |  1997-04-03  |  7KB  |  237 lines

  1. #include "sample3.h"
  2.  
  3. #include XColor_i
  4. #include XFont_i
  5. #include XToolBar_i
  6. #include XBubbleHelp_i
  7. #include XFileDialog_i
  8. #include XString_i
  9. #include XControlEvent_i
  10. #include XException_i
  11. #include XMessageBox_i
  12.  
  13. #include <stdlib.h>
  14.  
  15. SHORT volume = 50;
  16. MyApp * app;
  17.  
  18. //this sample support bubble-help done like in sample2
  19. class MyBubble: public XBubbleHelp
  20. {
  21.    public:
  22.       MyBubble( XResource * r, XWindow*w);
  23.       BOOL SetMsgText( ULONG windowID );
  24. };
  25.  
  26.  
  27. MyBubble :: MyBubble( XResource * r, XWindow*w): XBubbleHelp(r, w) 
  28.    XFont * font = new XFont(GetGraphicDevice(), "Tms Rmn", 9);
  29.     GetTextObject()->SetFont( font );    
  30. }
  31.  
  32.  
  33. //set the text for the controls
  34. BOOL MyBubble :: SetMsgText( ULONG windowID )
  35. {
  36.    switch( windowID)
  37.       {
  38.          case IDM_PLAY:
  39.             SetText( "Play a loaded file");
  40.             break;
  41.          case IDM_HALT:
  42.             SetText("Stop playing a file");
  43.             break;
  44.          case IDM_BACK:
  45.             SetText("Seek to the beginning of the file");
  46.             break;
  47.          case IDM_PLUS:
  48.             SetText("more volume");
  49.             break;
  50.          case IDM_MIN:
  51.             SetText( "less volume");
  52.             break;
  53.          case IDM_SEL:
  54.             SetText( "load a file");
  55.             break;
  56.          default:
  57.             return FALSE;
  58.       }
  59.    return TRUE;
  60. }
  61.  
  62.  
  63. MyAppWindow :: MyAppWindow( XApplication * app, XResource * r ): XFrameWindow( r, "Sample3 - Videoplayer", XFrameWindow::defaultDialogStyle | FRM_TASKLIST | FRM_ICON)
  64. {
  65.    //we create a toolbar for the buttons at the top...
  66.    XToolBar * toolBar = new XToolBar( this, TB_TOP);
  67.  
  68.    //now create pushbuttons with bitmaps, the bitmaps are in the resources of the exe
  69.    XRect rec( 0, 0, 20, 20);
  70.  
  71.    back = new XPushButton( toolBar, &rec, (USHORT) IDM_BACK, BU_BITMAP);
  72.    play = new XPushButton( toolBar, &rec, (USHORT) IDM_PLAY, BU_BITMAP);
  73.    halt = new XPushButton( toolBar, &rec, (USHORT) IDM_HALT, BU_BITMAP);
  74.    mini = new XPushButton( toolBar, &rec, (USHORT) IDM_MIN, BU_BITMAP);
  75.    plus = new XPushButton( toolBar, &rec, (USHORT) IDM_PLUS, BU_BITMAP);
  76.    sel = new XPushButton( toolBar, &rec, (USHORT) IDM_SEL, BU_BITMAP);
  77.  
  78.    //disable buttons
  79.    play->Enable(FALSE);
  80.    halt->Enable(FALSE);
  81.    back->Enable(FALSE);
  82.  
  83.    //add the pushbuttons to the toolbar, the toolbar will use the size of the first button
  84.    toolBar->AddWindow( play , FALSE, TRUE);
  85.    toolBar->AddWindow( halt );
  86.    toolBar->AddWindow( back );
  87.    toolBar->AddWindow( plus, TRUE );
  88.    toolBar->AddWindow( mini );
  89.    toolBar->AddWindow( sel, TRUE );
  90.  
  91.    // set the size of the window and display it
  92.    XColor col( COL_BLACK);
  93.    SetBackgroundColor( &col);
  94.  
  95.    XRect rect( 150, 150, 280, 230);
  96.    SetSize(&rect);
  97.  
  98.    Show();
  99.  
  100.    // know we generate a videoplayer and open it
  101.    video = new XVideo ( this); //this is the needed REIHENFOLGE
  102.    if( video->OpenDevice() != 0)
  103.       XMessageBox( "cannot open video-device");
  104.  
  105.    // if you don∩t set the viewport like this, the default ULTIMOTION-window
  106.    // will be opened, but our window will receive the media-control messages
  107.    // (see below function DoControl() )
  108.    if( video->SetViewPort( this) != 0)
  109.       XMessageBox( "cannot set viewport");
  110.  
  111.    //create the bubblehelp
  112.    XResource resource(0, r->GetResourceLibrary());
  113.    MyBubble * bubble = new MyBubble( &resource, toolBar);
  114.  
  115.    Activate();
  116. }
  117.  
  118.  
  119. BOOL MyAppWindow :: QueryForClose( void )
  120. {
  121.    /* we MUST close the video and destroy it ourselves */
  122.    video->CloseDevice();
  123.    delete video;
  124.    return TRUE;
  125. }
  126.  
  127.  
  128. void MyAppWindow :: Draw( void )
  129. {
  130.    FillBackground( );
  131. }
  132.  
  133.  
  134. /* here the command of the toolbar are posted */
  135. BOOL MyAppWindow :: DoCommand( LONG com)
  136. {
  137.   switch(com)
  138.      {
  139.          case IDM_SEL:
  140.             {
  141.                XFileDialog dlg( this, "c:\\mmos2\\movies\\*.AVI");
  142.                if( dlg.GetCommand() == DID_OK)
  143.                   {
  144.                      XString s;
  145.                      dlg.GetFileName( &s );
  146.                      if( video->SetDataFile( (char*) s ) != 0)
  147.                               XMessageBox( "cannot load video file");
  148.                      play->Enable();
  149.                   }
  150.             }
  151.             return TRUE;
  152.          case IDM_PLAY:
  153.             Activate();
  154.             back->Enable();
  155.             halt->Enable();
  156.             play->Enable(FALSE);
  157.             if( video->Play() != 0)
  158.                XMessageBox( "cannot play video-device");
  159.             return TRUE;
  160.          case IDM_BACK:
  161.             video->Rewind();
  162.             return TRUE;
  163.          case IDM_HALT:
  164.             video->Pause();
  165.             return TRUE;
  166.          case IDM_PLUS:
  167.             if( volume < 100)
  168.                {
  169.                   volume += 10;
  170.                   if( video->SetVolume( volume ) != 0)
  171.                      XMessageBox( "cannot set volume");
  172.                }
  173.             if(volume == 100)
  174.                plus->Enable(FALSE);
  175.             if(volume == 10)
  176.                mini->Enable();
  177.             return TRUE;
  178.          case IDM_MIN:
  179.             if( volume > 0)
  180.                {
  181.                   volume -= 10;
  182.                   video->SetVolume( volume );
  183.                }
  184.             if(volume == 0)
  185.                mini->Enable(FALSE);
  186.             if(volume == 90)
  187.                plus->Enable();
  188.             return TRUE;
  189.      }
  190.    return FALSE;
  191. }
  192.  
  193.  
  194. void MyAppWindow :: DoControl( XControlEvent * event)
  195. {
  196.    //here the control-messages are posted, we only care about media-messages */
  197.    switch( event->GetEventID())
  198.       {
  199.          case MEDIA_PLAYED: //end of file reached
  200.             play->Enable(FALSE);
  201.             halt->Enable(FALSE);
  202.             return;
  203.          case MEDIA_PAUSED: //video stopped
  204.             halt->Enable(FALSE);
  205.             play->Enable();
  206.             return;
  207.          case MEDIA_REWINDED: //file has been seeked to start
  208.             halt->Enable(FALSE);
  209.             back->Enable(FALSE);
  210.             play->Enable();
  211.             return;
  212.       }
  213. }
  214.  
  215.  
  216. MyApp :: MyApp(): XApplication()
  217. {
  218.    XResource r( IDM_MAIN, GetResourceLibrary());
  219.    window = new MyAppWindow( this, &r );   //create new framewindow (see above)
  220. }
  221.  
  222. void main ( void)
  223. {
  224.    try
  225.    {
  226.       app = new MyApp();  //create a new application
  227.    }
  228.    catch( XException e)
  229.    {
  230.       XMessageBox( e.GetErrorMessage());
  231.       exit(-1);
  232.    }
  233.  
  234.    app->Start();               //let the application work
  235. }
  236.