home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 5 / FreshFish_July-August1994.bin / bbs / gfx / jpegaga-1.0.lha / jpegAGA-1.0 / display.c next >
C/C++ Source or Header  |  1994-05-28  |  6KB  |  232 lines

  1. /* Screen display routines              */
  2. /* written by Günther Röhrich           */
  3. /* this source is Public Domain         */
  4.  
  5. /* this works only with OS 3.0 or higher */
  6.  
  7.  
  8. #define INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/screens.h>
  13. #include <graphics/modeid.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17. #include <clib/exec_protos.h>
  18.  
  19. #ifndef __GNUC__
  20. #include <pragmas/intuition_pragmas.h>
  21. #include <pragmas/graphics_pragmas.h>
  22. #endif
  23.  
  24. #define HAM8 1
  25.  
  26.  
  27. struct Library *IntuitionBase = NULL;
  28. struct Library *GfxBase = NULL;
  29. extern int VGAenable;
  30. extern void error_exit(const char *msgtext);
  31. struct Screen *my_screen = NULL;
  32. struct Window *my_window = NULL;
  33. struct RastPort temprp; /* a copy of the screen's RastPort */
  34. int Drow = 0; 
  35.  
  36. void CloseDisplay(void);
  37.  
  38. /* Initialize the display, colors will be set later */
  39.  
  40. int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
  41. {
  42.   ULONG Depth, DisplayID;
  43.  
  44.   if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 39)))
  45.    error_exit("Can't open intuition.library V39 or higher");
  46.  
  47.   if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
  48.    error_exit("Can't open graphics.library V39 or higher");
  49.  
  50.   
  51.   /* Calculate a DisplayID */
  52.   /* this should be done better... */
  53.  
  54.   if(VGAenable)
  55.   {
  56.     if(Mode == HAM8)
  57.     {
  58.       if(cols > 370 || rows > 260)
  59.         DisplayID = VGAPRODUCTHAM_KEY;
  60.       else
  61.         DisplayID = VGALORESHAMDBL_KEY;
  62.     }
  63.     else
  64.     {
  65.       if(cols > 370 || rows >260) 
  66.         DisplayID = VGAPRODUCT_KEY;
  67.       else
  68.         DisplayID = VGALORESDBL_KEY;        
  69.     }
  70.   }
  71.   else
  72.   {  
  73.     if(Mode == HAM8)
  74.       DisplayID = DEFAULT_MONITOR_ID | HAM_KEY;
  75.     else
  76.       DisplayID = DEFAULT_MONITOR_ID;
  77.  
  78.     if(cols > 370 || rows >260) DisplayID |= HIRES|LACE;
  79.   }
  80.  
  81.   if(Mode == HAM8) Depth = 8;
  82.     else Depth = NumPlanes;
  83.  
  84.   my_screen = OpenScreenTags(NULL, SA_Width,     (ULONG)cols,
  85.                                    SA_Height,    (ULONG)rows,
  86.                                    SA_Depth,     (ULONG)Depth,
  87.                                    SA_DisplayID, (ULONG)DisplayID,
  88.                                    SA_Type,      (ULONG)CUSTOMSCREEN,
  89.                                    SA_Quiet,     (ULONG)TRUE,
  90.                                    SA_AutoScroll,(ULONG)TRUE,
  91.                                    SA_Overscan,  (ULONG)OSCAN_STANDARD,
  92.                                    TAG_DONE);
  93.  
  94.   if(my_screen == NULL)  return 0;
  95.     
  96.   /* open a dummy window to allow autoscroll feature      */
  97.   
  98.   my_window = OpenWindowTags(NULL, WA_Left,         (ULONG)0,
  99.                                    WA_Top,          (ULONG)0,
  100.                                    WA_Width,        (ULONG)cols,
  101.                                    WA_Height,       (ULONG)rows,
  102.                                    WA_CustomScreen, my_screen,
  103.                                    WA_NoCareRefresh,(ULONG)TRUE,
  104.                                    WA_Borderless,   (ULONG)TRUE,
  105.                                    WA_Backdrop,     (ULONG)TRUE,
  106.                                    WA_RMBTrap,      (ULONG)TRUE, /* disable screen menu drawing */
  107.                                    WA_IDCMP,        (ULONG)IDCMP_MOUSEBUTTONS,
  108.                                    WA_Activate,     (ULONG)TRUE,
  109.                                    WA_BusyPointer,  (ULONG)TRUE, /* V39 only! */
  110.                                    TAG_DONE);
  111.  
  112.   if(my_window == NULL) return 0;
  113.  
  114.   /* initialize temprp for use with WritePixelLine8() */
  115.  
  116.   CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
  117.   temprp.Layer = NULL;
  118.   /* V39 function */
  119.   temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
  120.  
  121.   if(temprp.BitMap == NULL) return 0;
  122.  
  123.   return 1; /* success */  
  124. }
  125.  
  126.  
  127. /* Set a color... */
  128.  
  129. void SetDisplayColor(int ColorNumber, UBYTE r, UBYTE g, UBYTE b)
  130. {
  131.   if(my_screen)
  132.     /* V39 function */
  133.     SetRGB32(&my_screen->ViewPort, (ULONG)ColorNumber, (ULONG)r << 24,
  134.                                                        (ULONG)g << 24,
  135.                                                        (ULONG)b << 24);
  136. }
  137.  
  138.  
  139. /* Close the display */
  140.  
  141. void CloseDisplay(void)
  142. {
  143.   if(temprp.BitMap)
  144.   {
  145.     /* V39 function */
  146.     FreeBitMap(temprp.BitMap);
  147.     temprp.BitMap = NULL;
  148.   }
  149.   if(my_window)
  150.   {
  151.     CloseWindow(my_window);
  152.     my_window = NULL;
  153.   }
  154.   if(my_screen)
  155.   {
  156.     CloseScreen(my_screen);
  157.     my_screen = NULL;
  158.   }
  159.   if(IntuitionBase)
  160.   {
  161.    CloseLibrary(IntuitionBase);
  162.    IntuitionBase = NULL;
  163.   }
  164.   if(GfxBase)
  165.   {
  166.     CloseLibrary(GfxBase);
  167.     GfxBase = NULL;
  168.   }
  169. }
  170.  
  171.  
  172. /* display a line of chunky pixel graphics... */
  173.  
  174.  
  175. void DisplayRow(char *array, int cols)
  176. {
  177.   if(my_screen)
  178.     WritePixelLine8(&my_screen->RastPort, 0, Drow++, cols, array, &temprp);
  179. }
  180.  
  181.  
  182. /* check for a right mouse button press */
  183.  
  184. int CheckButton(void)
  185. {
  186.   struct IntuiMessage *msg;
  187.   int Button = 0;
  188.  
  189.   if(my_window)
  190.   {
  191.     while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  192.     {
  193.       if(msg->Class == IDCMP_MOUSEBUTTONS)
  194.         if(msg->Code == MENUDOWN)
  195.           Button = 1; 
  196.       ReplyMsg((struct Message *)msg);
  197.       if(Button) break;
  198.     }
  199.   }
  200.   return Button;
  201. }
  202.        
  203. /* final wait after the picture is finished */
  204.  
  205. void FinalWait(void)
  206. {
  207.   struct IntuiMessage *msg;
  208.   int Button = 0;
  209.  
  210.   /* set the normal pointer */
  211.   /* V39 function */
  212.  
  213.   SetWindowPointer(my_window, WA_Pointer, NULL, TAG_DONE);
  214.   
  215.   if(my_window)
  216.   {
  217.     while(!Button)
  218.     {
  219.       Wait(1L<<my_window->UserPort->mp_SigBit);
  220.       while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  221.       {
  222.         if(msg->Class == IDCMP_MOUSEBUTTONS)
  223.           if(msg->Code == MENUDOWN)
  224.             Button = 1; 
  225.         ReplyMsg((struct Message *)msg);
  226.         if(Button) break;
  227.       }
  228.     }
  229.   }
  230. }
  231.       
  232.