home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Sound / Player / MCDPL121.LHA / MCDPlayer / Source / Windows.c < prev   
Encoding:
C/C++ Source or Header  |  1996-05-21  |  7.2 KB  |  257 lines

  1. #include "mcdplayer.h"
  2. #include "mcdplayer_gui.h"
  3.  
  4. struct Gadget *MainGadget[31];
  5.  
  6. WORD gad_x[] = { 267, 288, 309, 330, 351, 267, 288, 309, 330, 351, 267, 288, 309, 330, 351,
  7.                  267, 288, 309, 330, 351, 267, 302, 336,   7,  52,  77, 102, 137, 172, 207,
  8.                  242 };
  9.  
  10. WORD gad_y[] = {   6,   6,   6,   6,   6,  18,  18,  18,  18,  18,  30,  30,  30,  30,  30,
  11.                   42,  42,  42,  42,  42,  53,  53,  53,  65,  65,  65,  65,  65,  65,  65,
  12.                   65 };
  13.  
  14. WORD gad_w[] = {  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,  19,
  15.                   19,  19,  19,  19,  19,  34,  33,  34,  44,  24,  24,  34,  34,  34,  34,
  16.                   23 };
  17.  
  18. WORD gad_h[] = {   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,   9,
  19.                    9,   9,   9,   9,   9,  11,  11,  11,  13,  13,  13,  13,  13,  13,  13,
  20.                   13 };
  21.  
  22. UWORD offy = 0;
  23.  
  24. struct TagItem    MainWindowTags[] = {
  25.     WA_Left,          0,
  26.     WA_Top,           0,
  27.     WA_Width,         390,
  28.     WA_Height,        0,
  29.     WA_IDCMP,         IDCMP_GADGETUP|IDCMP_REFRESHWINDOW|IDCMP_CLOSEWINDOW,
  30.     WA_Flags,         WFLG_DRAGBAR|WFLG_DEPTHGADGET|WFLG_CLOSEGADGET|WFLG_SMART_REFRESH|WFLG_ACTIVATE,
  31.     WA_Gadgets,       0l,
  32.     WA_Title,         "MCDPlayer V" VERSION,
  33.     WA_ScreenTitle,   0l,
  34.     WA_PubScreen,     NULL,
  35.     TAG_DONE };
  36.  
  37. struct Image MainImage = {
  38.     0,0,382,84,2,
  39.     NULL,
  40.     0x3,0x0,NULL
  41.     };
  42.  
  43. struct Image PfeilImage = {
  44.     0,0,9,5,2,
  45.     NULL,
  46.     0x3,0x0,NULL
  47.     };
  48.  
  49. struct Image PauseImage = {
  50.     0,0,9,5,2,
  51.     NULL,
  52.     0x3,0x0,NULL
  53.     };
  54.  
  55. struct Image PrgmImage = {
  56.     0,0,21,5,2,
  57.     NULL,
  58.     0x3,0x0,NULL
  59.     };
  60.  
  61. char FontName[130];
  62.  
  63. struct TextAttr DispFont = {
  64.     &FontName[0], 10, 0x00, 0x01 };
  65.  
  66.  
  67. struct Window *MainWnd = NULL;
  68. struct TextFont *DFont = NULL;
  69. UWORD *MW_Data;
  70.  
  71. struct EasyStruct ErrorES = {
  72.     sizeof (struct EasyStruct),
  73.     0,
  74.     0l,
  75.     "%s",
  76.     0l,
  77.     };
  78.  
  79. void PlaceWnd( struct Screen *Scr, WORD WndWidth, WORD WndHeight, WORD *x_pos, WORD *y_pos, char Place )
  80.     {
  81.     ULONG             ModeID;
  82.     struct Rectangle  OSRect;
  83.     WORD              ScrWidth = 0, ScrHeight = 0;
  84.  
  85.     if (INVALID_ID != (ModeID = GetVPModeID(&(Scr->ViewPort) ) ) )
  86.         {
  87.         if (QueryOverscan (ModeID, &OSRect, OSCAN_TEXT) )
  88.             {
  89.             ScrWidth = OSRect.MaxX - OSRect.MinX + 1;
  90.             ScrHeight = OSRect.MaxY - OSRect.MinY + 1;
  91.             };
  92.         };
  93.     switch (Place)
  94.         {
  95.         case 0:
  96.             *x_pos = (ScrWidth/2 - WndWidth/2) - Scr->LeftEdge;
  97.             *y_pos = (ScrHeight/2 - WndHeight/2) - Scr->TopEdge;
  98.             break;
  99.         case 1:
  100.             *x_pos = Scr->Width - WndWidth;
  101.             *y_pos = Scr->BarHeight + 1;
  102.             break;
  103.         case 2:
  104.             *x_pos = 0;
  105.             *y_pos = Scr->BarHeight + 1;
  106.             break;
  107.         case 3:
  108.             *x_pos = 0;
  109.             *y_pos = Scr->Height - WndHeight;
  110.             break;
  111.         case 4:
  112.             *x_pos = Scr->Width - WndWidth;
  113.             *y_pos = Scr->Height - WndHeight;
  114.             break;
  115.         }
  116.     }
  117.  
  118. void DrawPlaySymb( int stat )
  119.     {
  120.     switch( stat )
  121.         {
  122.         case 1:
  123.             if (MW_Data) DrawImage( MainWnd->RPort,&PfeilImage, 248, 65+offy );
  124.             break;
  125.         case 0:
  126.             SetAPen( MainWnd->RPort, 1 );
  127.             RectFill( MainWnd->RPort, 248, 65+offy, 262, 70+offy );
  128.             break;
  129.         default:
  130.             if (MW_Data) DrawImage( MainWnd->RPort,&PauseImage, 248, 65+offy );
  131.             break;
  132.         }
  133.     }
  134.  
  135. void DrawPrgmSymb( int stat )
  136.     {
  137.     if (stat)
  138.         {
  139.         if (MW_Data) DrawImage( MainWnd->RPort,&PrgmImage, 218, 65+offy );
  140.         }
  141.     else
  142.         {
  143.         SetAPen( MainWnd->RPort, 1 );
  144.         RectFill( MainWnd->RPort, 218, 65+offy, 240, 70+offy );
  145.         }
  146.     }
  147.  
  148. ErrorMsg(char *Msg)
  149.     {
  150.     ErrorES.es_Title = "MCDP Requester:";
  151.     ErrorES.es_GadgetFormat = "Okay";
  152.  
  153.     EasyRequest( MainWnd, &ErrorES, 0, Msg );
  154.     }
  155.  
  156. void CleanMainWnd()
  157.     {
  158.     if (MW_Data) DrawImage( MainWnd->RPort,&MainImage, 5, 12+offy );
  159.     }
  160.  
  161. int OpenMainWnd( char Place, int xpos, int ypos )
  162.     {
  163.     struct Screen *Scr;
  164.     UWORD i;
  165.     WORD x,y;
  166.  
  167.     int Exit = 0;
  168.  
  169.     if (Scr = LockPubScreen( 0 ))
  170.         {
  171.         offy = Scr->WBorTop + Scr->RastPort.TxHeight - 10;
  172.         MainWindowTags[ 9 ].ti_Data = Scr;
  173.         PlaceWnd( Scr, 390, 98+offy, &x, &y, Place );
  174.         if(xpos != -1) x = xpos;
  175.         if(ypos != -1) y = ypos;
  176.         MainWindowTags[ 0 ].ti_Data = x;
  177.         MainWindowTags[ 1 ].ti_Data = y;
  178.         MainWindowTags[ 3 ].ti_Data = 98+offy;
  179.     
  180.         if ( MW_Data = (UWORD *)AllocMem( 8148, MEMF_CHIP ) )
  181.             {
  182.             memcpy( MW_Data, MainWinData, 8064 );
  183.             memcpy( ((char *)MW_Data)+8064, PfeilData, 20 );
  184.             memcpy( ((char *)MW_Data)+8084, PauseData, 20 );
  185.             memcpy( ((char *)MW_Data)+8108, PrgmData, 40 );
  186.             PfeilImage.ImageData = ((char *)MW_Data)+8064;
  187.             PauseImage.ImageData = ((char *)MW_Data)+8084;
  188.             PrgmImage.ImageData = ((char *)MW_Data)+8108;
  189.  
  190.             if ( MainWnd = OpenWindowTagList( 0l, MainWindowTags ))
  191.                 {
  192.                 MainImage.ImageData = MW_Data;
  193.                 DrawImage( MainWnd->RPort,&MainImage, 5, 12+offy );
  194.  
  195.                 for (i=0; i<31; i++)
  196.                     {
  197.                     if (MainGadget[i] = (struct Gadget *)AllocMem( sizeof( struct Gadget ), MEMF_CLEAR ))
  198.                         {
  199.                         MainGadget[i]->LeftEdge = gad_x[i]+5;
  200.                         MainGadget[i]->TopEdge  = gad_y[i]+12+offy;
  201.                         MainGadget[i]->Width    = gad_w[i];
  202.                         MainGadget[i]->Height   = gad_h[i];
  203.                         MainGadget[i]->Flags    = GFLG_GADGHCOMP;
  204.                         MainGadget[i]->Activation = GACT_RELVERIFY;
  205.                         MainGadget[i]->GadgetType = GTYP_BOOLGADGET;
  206.                         MainGadget[i]->GadgetID = i;
  207.                         AddGadget( MainWnd, MainGadget[i], ~0 );
  208.                         }
  209.                     else
  210.                         {
  211.                         ErrorMsg( "Problem allocating gadgets!" );
  212.                         Exit = 5;
  213.                         }
  214.                     };
  215.                 if (DFont = (struct TextFont *)OpenDiskFont( &DispFont ))
  216.                     {
  217.                     SetFont( MainWnd->RPort, DFont );
  218.                     }
  219.                 else
  220.                     {
  221.                     ErrorMsg( "Can't open font." );
  222.                     Exit = 4;
  223.                     }
  224.                 }
  225.             else
  226.                 {
  227.                 ErrorMsg( "Can't open window." );
  228.                 Exit = 1;
  229.                 }
  230.             }
  231.         else
  232.             {
  233.             ErrorMsg( "Can't allocate memory." );
  234.             Exit = 2;
  235.             }
  236.         UnlockPubScreen( NULL, Scr );
  237.         }
  238.     else
  239.         {
  240.         ErrorMsg( "Can't lock the screen." );
  241.         Exit = 3;
  242.         }
  243.     return ( Exit );
  244.     }
  245.  
  246. CloseMainWnd()
  247.     {
  248.     UWORD i;
  249.  
  250.     if (MW_Data) FreeMem( MW_Data, 8148 );
  251.     if (MainWnd) CloseWindow( MainWnd );
  252.     for (i=0; i<31; i++)
  253.          if (MainGadget[i]) FreeMem( MainGadget[i], sizeof( struct Gadget ) );
  254.     if (DFont) CloseFont( DFont );
  255.     }
  256.  
  257.