home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / WBStartup+ / Source / WBStartup+OS2.x / ProgressWindow.c < prev    next >
C/C++ Source or Header  |  1998-10-26  |  7KB  |  255 lines

  1. #include <exec/types.h>
  2. #include <graphics/gfx.h>
  3. #include <proto/intuition.h>
  4. #include <proto/gadtools.h>
  5. #include <proto/graphics.h>
  6. #include <proto/dos.h>
  7. #include <proto/exec.h>
  8. #include <proto/icon.h>
  9. #include <proto/layers.h>
  10. #include <prefs/wbpattern.h>
  11. #include <prefs/prefhdr.h>
  12. #include <graphics/gfxmacros.h>
  13. #include <math.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16. #include <exec/memory.h>
  17.  
  18. #include "ProgressWindow.h"
  19. #include "WBStartup+.h"
  20.  
  21. #define winwidth 400
  22. #define winheight 80
  23. #define BARHEIGHT 12
  24. #define XOFFSET 75
  25.  
  26. static UWORD BackgroundPen, HighlightTextPen, ShinePen, ShadowPen;
  27. ULONG __chip Crosshatch = 0x5555AAAA;
  28. static struct WBStartup *wbarg=NULL;
  29.  
  30.  
  31. struct ProgressWindowData *CreateProgressWindow(struct WBStartupPrefs *prefs);
  32. void CloseProgressWindow(struct ProgressWindowData *data);
  33. void UpdateProgressBar(struct Window *win, int current, int total);
  34. void ShowIconImage(struct ProgressWindowData *data, struct Image *image);
  35. BOOL InteractiveRunProgram(struct Window *win);
  36. void DisplayProgramName(struct ProgressWindowData *data, char *name, BOOL query);
  37.  
  38.  
  39. struct ProgressWindowData *CreateProgressWindow(struct WBStartupPrefs *prefs)
  40. {
  41.   ULONG scrwidth=640,scrheight=200;
  42.   struct Rectangle rect;
  43.   LONG screen_modeID;
  44.   void *vi;
  45.   char buffer[7],*TitleText="Amiga Workbench \0\0\0\0\0\0\0";
  46.   struct IntuiText iText = { 2,0,0,0,0,NULL,NULL,NULL};
  47.   struct DrawInfo *dri;
  48.   struct Screen *scr;
  49.  
  50.   struct DiskObject *diskobj=NULL;  /* This must be initialized to NULL */
  51.   struct Process *process;
  52.   char buf[200];
  53.   struct Image *image;
  54.   struct ProgressWindowData *windata;
  55.   BOOL success=FALSE;
  56.  
  57.   if (windata = AllocVec(sizeof(struct ProgressWindowData),MEMF_ANY))
  58.   {
  59.     if (scr=LockPubScreen(prefs->PubScreenName))
  60.     {
  61.  
  62.       /********************************************/
  63.       /* Determine the Size of the visible screen */
  64.       /********************************************/
  65.       screen_modeID = GetVPModeID(&(scr->ViewPort));
  66.       if (screen_modeID != INVALID_ID)
  67.       {
  68.         if (QueryOverscan(screen_modeID, &rect, OSCAN_TEXT))
  69.         {
  70.           scrwidth  = rect.MaxX - rect.MinX + 1;
  71.           scrheight = rect.MaxY - rect.MinY + 1;
  72.  
  73.           scrwidth  = min(scrwidth,scr->Width);
  74.           scrheight = min(scrheight,scr->Height);
  75.         }
  76.       }
  77.  
  78.       /*******************************/
  79.       /* Get WBStartup+'s Icon image */
  80.       /*******************************/
  81.       if (process = (struct Process *)FindTask(NULL))
  82.       {
  83.         NameFromLock(process->pr_HomeDir,buf,199);
  84.         AddPart(buf,process->pr_Task.tc_Node.ln_Name,199);
  85.  
  86.         if (diskobj=(GetDiskObject(buf)))  // We release the Disk Object down below!
  87.           image = (struct Image *)diskobj->do_Gadget.GadgetRender;
  88.       }
  89.  
  90.       if (windata->win = OpenWindowTags(NULL,
  91.           WA_Left,   (scrwidth-winwidth)/2,
  92.           WA_Top,    (scrheight-winheight)/2,
  93.           WA_Width, winwidth,
  94.           WA_Height, winheight,
  95.           WA_AutoAdjust, TRUE,
  96.           WA_Activate, prefs->Interactive,
  97.           WA_IDCMP,  (prefs->Interactive) ? IDCMP_VANILLAKEY : 0L,
  98.           WA_Flags,  WFLG_SMART_REFRESH | WFLG_ACTIVATE,
  99.           WA_PubScreen, scr,
  100.           WA_PubScreenFallBack, "Workbench",
  101.           TAG_END))
  102.       {
  103.         /* Set Global Pen Numbers */
  104.         if (dri = GetScreenDrawInfo(scr))
  105.         {
  106.           BackgroundPen = dri->dri_Pens[BACKGROUNDPEN];
  107.           HighlightTextPen = dri->dri_Pens[HIGHLIGHTTEXTPEN];
  108.           ShinePen = dri->dri_Pens[SHINEPEN];
  109.           ShadowPen = dri->dri_Pens[SHADOWPEN];
  110.           FreeScreenDrawInfo( scr, dri );
  111.         }
  112.  
  113.         if (vi=GetVisualInfo(scr,TAG_DONE))
  114.         {
  115.           DrawBevelBox(windata->win->RPort, XOFFSET, 34, windata->win->Width-150, BARHEIGHT, GTBB_Recessed, TRUE, GT_VisualInfo, vi, TAG_DONE);  /* Draw Progress Indicator Box */
  116.           FreeVisualInfo(vi);
  117.         }
  118.  
  119.         /************************/
  120.         /* Write text to window */
  121.         /************************/
  122.         if (GetVar("Workbench",buffer,7,0)>=0)
  123.           strcat(TitleText,buffer);
  124.         iText.IText = TitleText;
  125.         iText.FrontPen = ShadowPen;
  126.         PrintIText(windata->win->RPort, &iText, ((windata->win->Width-IntuiTextLength(&iText))/2)+1, 16);
  127.         iText.FrontPen = HighlightTextPen;
  128.         PrintIText(windata->win->RPort, &iText, (windata->win->Width-IntuiTextLength(&iText))/2, 15);
  129.  
  130.         SetAfPt(windata->win->RPort, NULL, 0);
  131.  
  132.         success=TRUE;
  133.  
  134.       }
  135.  
  136.       if (diskobj)
  137.       {
  138.         DrawImage(windata->win->RPort,image,((XOFFSET-windata->win->BorderLeft-image->Width)/2)+windata->win->BorderLeft,((80-image->Height)/2));
  139.         FreeDiskObject(diskobj);
  140.       }
  141.  
  142.       UnlockPubScreen(NULL,scr);
  143.     }
  144.   }
  145.  
  146.   if (!success)
  147.   {
  148.     FreeVec(windata);
  149.     windata=NULL;
  150.   }
  151.  
  152.   return(windata);
  153. }
  154.  
  155. void CloseProgressWindow(struct ProgressWindowData *data)
  156. {
  157.   CloseWindow(data->win);
  158.   FreeVec(data);
  159. }
  160.  
  161. void UpdateProgressBar(struct Window *win, int current, int total)
  162. {
  163.   int x;
  164.   x = ((win->Width-(2*(XOFFSET+2)))*current/total)+(XOFFSET+2);
  165.  
  166.   SetAfPt(win->RPort,(UWORD *)&Crosshatch,1);
  167.   SetBPen(win->RPort,ShinePen);
  168.   SetAPen(win->RPort,3);
  169.   RectFill(win->RPort,(XOFFSET+2),35,x,35+BARHEIGHT-3);
  170. }
  171.  
  172. void ShowIconImage(struct ProgressWindowData *data, struct Image *image)
  173. {
  174.   struct Region *reg;
  175.   struct Region *oldreg;
  176.   struct Rectangle rect;
  177.  
  178.   SetAfPt(data->win->RPort,NULL,0);
  179.   SetAPen(data->win->RPort,BackgroundPen);
  180.   RectFill(data->win->RPort,winwidth-XOFFSET,data->win->BorderTop,winwidth-data->win->BorderRight-1,winheight-data->win->BorderBottom-1);
  181.  
  182.   rect.MinX=winwidth-XOFFSET;
  183.   rect.MinY=data->win->BorderTop;
  184.   rect.MaxX=winwidth-data->win->BorderRight-1;
  185.   rect.MaxY=winheight-data->win->BorderBottom-1;
  186.   if (reg=NewRegion())
  187.   {
  188.     OrRectRegion(reg,&rect);
  189.  
  190.     oldreg=InstallClipRegion(data->win->WLayer,reg);
  191.  
  192.     DrawImage(data->win->RPort,image,(400-XOFFSET)+((XOFFSET-image->Width)/2),((80-image->Height)/2));
  193.  
  194.     InstallClipRegion(data->win->WLayer,oldreg);
  195.  
  196.     DisposeRegion(reg);
  197.   }
  198.  
  199. }
  200.  
  201.  
  202.  
  203.  
  204. BOOL InteractiveRunProgram(struct Window *win)
  205. {
  206.   BOOL runprogram=FALSE;
  207.   struct IntuiMessage *msg;
  208.   BOOL done=FALSE;
  209.  
  210.   while (!done)
  211.   {
  212.     Wait(1L<<win->UserPort->mp_SigBit);
  213.  
  214.     while (msg = (struct IntuiMessage *)GetMsg(win->UserPort))
  215.     {
  216.       if (msg->Class == IDCMP_VANILLAKEY)
  217.         if (msg->Code=='Y' || msg->Code=='y')
  218.         {
  219.           done=TRUE;
  220.           runprogram = TRUE;
  221.         }
  222.         else if (msg->Code=='N' || msg->Code=='n')
  223.         {
  224.           done=TRUE;
  225.           runprogram = FALSE;
  226.         }
  227.       ReplyMsg((struct Message *)msg);
  228.     }
  229.   }
  230.  
  231.   return(runprogram);
  232. }
  233.  
  234. void DisplayProgramName(struct ProgressWindowData *data, char *name, BOOL query)
  235. {
  236.   struct IntuiText iText = { 2,0,0,0,0,NULL,NULL,NULL};
  237.   char *outputbuffer;
  238.  
  239.   SetAfPt(data->win->RPort,NULL,0);
  240.   SetAPen(data->win->RPort,BackgroundPen);
  241.   RectFill(data->win->RPort,XOFFSET,34+BARHEIGHT,winwidth-XOFFSET-1,winheight-data->win->BorderBottom-1);
  242.  
  243.   if (outputbuffer = AllocVec(strlen(name)+3,MEMF_ANY))
  244.   {
  245.     strcpy(outputbuffer,name);
  246.     if (query)
  247.       strcat(outputbuffer," ?");
  248.     iText.IText = outputbuffer;
  249.     iText.FrontPen = ShadowPen;
  250.     PrintIText(data->win->RPort, &iText, (data->win->Width-IntuiTextLength(&iText))/2, 34+BARHEIGHT+((data->win->Height-34-BARHEIGHT-data->win->WScreen->Font->ta_YSize)/2)+2);
  251.  
  252.     FreeVec(outputbuffer);
  253.   }
  254. }
  255.