home *** CD-ROM | disk | FTP | other *** search
/ Inter.Net 55-1 / Inter.Net 55-1.iso / beos / PPBeDevKit.ZIP / PLAYERPR.TAR / PlayerPRO / MAD Simple / mainMADSimple.cpp next >
Encoding:
C/C++ Source or Header  |  1998-12-24  |  2.6 KB  |  138 lines

  1. #include <Application.h>
  2. #include <View.h>
  3. #include <Window.h>
  4. #include <Bitmap.h>
  5. #include <fcntl.h>
  6. #include <debugger.h>
  7.  
  8. #include "RDriver.h"
  9. #include "mainMADSimple.h"
  10.  
  11. //---------------------------------------------
  12.  
  13. class MADWindow : public BWindow {
  14.  
  15. public:
  16.                 MADWindow(BRect frame, MADDriverClass *d);
  17. virtual void     MessageReceived(BMessage *message);
  18.                 
  19. virtual    bool    QuitRequested();
  20.  
  21. MADDriverClass *myMADDriverClass;
  22. };
  23.  
  24. //---------------------------------------------
  25.  
  26. class MADView : public BView {
  27.  
  28. public:
  29.                 MADView(BRect frame, char *name); 
  30. virtual    void    AttachedToWindow();
  31. virtual    void    Draw(BRect updateRect);
  32. };
  33.  
  34. //---------------------------------------------
  35.  
  36. main()
  37. {
  38.     MyApp* curApp = new MyApp('SNPL');
  39.     
  40.     curApp->Run();
  41.     
  42.     delete curApp;
  43.  
  44.     return 0;
  45. }
  46. //---------------------------------------------
  47.  
  48.  
  49. MyApp::MyApp( ulong signature) : BApplication(signature)
  50. {
  51.     myMADDriverClass = new MADDriverClass();
  52.     
  53.     MADWindow        *aWindow;
  54.     MADView            *aView;
  55.     BRect            aRect;
  56.  
  57.     // set up a rectangle and instantiate a new window
  58.     aRect.Set(40, 40, 400, 80);
  59.     aWindow = new MADWindow(aRect, myMADDriverClass);
  60.     
  61.     // set up a rectangle and instantiate a new view
  62.     // view rect should be same size as window rect but with left top at (0, 0)
  63.     aRect.OffsetTo(B_ORIGIN);
  64.     aView = new MADView(aRect, "MADText");
  65.     
  66.     // add view to window
  67.     aWindow->AddChild(aView);
  68.     
  69.     // make window visible
  70.     aWindow->Show();
  71. }
  72.  
  73. MyApp::~MyApp()
  74. {
  75.     delete myMADDriverClass;
  76. }
  77.  
  78. /* Files dropped on the application will end up here */
  79.  
  80. void MyApp::RefsReceived (BMessage * message)
  81. {
  82.     entry_ref ref;
  83.     
  84.     // get the ref from the message
  85.     if ( message->FindRef("refs", &ref) == B_OK )
  86.     {
  87.         myMADDriverClass->LoadMusic( &ref, 'MADI', true);
  88.     }
  89. }
  90.  
  91. //-----------------------------------------------------
  92.  
  93. MADWindow::MADWindow(BRect frame, MADDriverClass *d)
  94.                 : BWindow(frame, "MADDriver", B_TITLED_WINDOW, B_NOT_RESIZABLE)
  95. {
  96.     myMADDriverClass = d;
  97. }
  98.  
  99. void MADWindow::MessageReceived(BMessage *message)
  100. {
  101.     entry_ref ref;
  102.     
  103.     if (message->what == B_SIMPLE_DATA)
  104.     {
  105.         if( message->FindRef("refs", &ref) == B_OK )
  106.         {
  107.             myMADDriverClass->LoadMusic( &ref, 'MADI', true);
  108.         }
  109.     }
  110.     else BWindow::MessageReceived( message);
  111. }
  112.  
  113. bool MADWindow::QuitRequested()
  114. {
  115.     be_app->PostMessage(B_QUIT_REQUESTED);
  116.     return(TRUE);
  117. }
  118.  
  119. //------------------------------------------------------
  120.  
  121. MADView::MADView(BRect rect, char *name)
  122.               : BView(rect, name, B_FOLLOW_ALL, B_WILL_DRAW)
  123. {
  124. }
  125.  
  126.  
  127. void MADView::AttachedToWindow()
  128. {
  129.     SetFontSize(18);
  130. }
  131.  
  132.  
  133. void MADView::Draw(BRect)
  134. {
  135.     MovePenTo(BPoint(10, 30));
  136.     DrawString("Drag a music file on this window!");
  137. }
  138.