home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD1.iso / CDRom / fotocd11.lha / src / photocdaga / display.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-11  |  6.9 KB  |  301 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. #include <stdio.h>
  8.  
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/screens.h>
  14. #include <graphics/modeid.h>
  15.  
  16.  
  17. #ifndef __GNUC__
  18. #include <pragmas/intuition_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/exec_protos.h>
  24. #else
  25. #include <inline/graphics.h>  
  26. #include <inline/intuition.h> 
  27. #include <inline/exec.h>
  28. #endif
  29.  
  30. #define HAM8 1
  31.  
  32.  
  33. struct IntuitionBase *IntuitionBase = NULL;
  34. struct GfxBase *GfxBase = NULL;
  35. extern int VGAenable; /* indicates if user wants to have VGA mode */
  36. extern int SUPER72enable; /* indicates if user wants to have SUPER72 mode */
  37. static void error_exit(const char *msgtext);
  38. struct Screen *my_screen = NULL;
  39. struct Window *my_window = NULL;
  40. struct RastPort temprp; /* a copy of the screen's RastPort */
  41. int Drow = 0; 
  42. extern ULONG *ScreenColorTable;
  43.  
  44.  
  45. struct TagItem MyScreenTags[] = {
  46.  
  47. { SA_Width,     (ULONG)0 },
  48. { SA_Height,    (ULONG)0 },
  49. { SA_Depth,     (ULONG)0 },
  50. { SA_DisplayID, (ULONG)0 },
  51. { SA_Colors32,  (ULONG)NULL},
  52. { SA_Type,      (ULONG)CUSTOMSCREEN },
  53. { SA_Quiet,     (ULONG)TRUE },
  54. { SA_AutoScroll,(ULONG)TRUE },
  55. { SA_Overscan,  (ULONG)OSCAN_STANDARD },
  56. { TAG_DONE,     (ULONG)TRUE }  };
  57.  
  58. struct TagItem MyWindowTags[] = {
  59.  
  60. { WA_Width,        (ULONG)0 },
  61. { WA_Height,       (ULONG)0 },
  62. { WA_CustomScreen, (ULONG)NULL },
  63. { WA_Activate,     (ULONG)TRUE },
  64. { WA_Left,         (ULONG)0 },
  65. { WA_Top,          (ULONG)0 },
  66. { WA_NoCareRefresh,(ULONG)TRUE },
  67. { WA_Borderless,   (ULONG)TRUE },
  68. { WA_Backdrop,     (ULONG)TRUE },
  69. { WA_RMBTrap,      (ULONG)TRUE }, /* disable screen menu drawing */
  70. { WA_IDCMP,        (ULONG)IDCMP_MOUSEBUTTONS | IDCMP_VANILLAKEY },
  71. { WA_BusyPointer,  (ULONG)TRUE }, /* V39 only! */
  72. { TAG_DONE,        (ULONG)TRUE } };
  73.  
  74. void CloseDisplay(void);
  75.  
  76. /* Initialize the display, colors will be set later */
  77.  
  78. int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
  79. {
  80.   ULONG Depth, DisplayID;
  81.   ULONG NoSUPER72;
  82.  
  83.   if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 39)))
  84.    error_exit("Can't open intuition.library V39 or higher");
  85.  
  86.   if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",39)))
  87.    error_exit("Can't open graphics.library V39 or higher");
  88.  
  89.   
  90.   /* Calculate a DisplayID */
  91.   /* this should be done better... */
  92.  
  93.   /* check if SUPER72 mode is available */
  94.  
  95.   NoSUPER72 = ModeNotAvailable(SUPER72_MONITOR_ID | SUPERHAMLACE_KEY);
  96.  
  97.  
  98.   if(VGAenable)
  99.   {
  100.     if(Mode == HAM8)
  101.     {
  102.       if(cols > 780 && !NoSUPER72 && SUPER72enable) DisplayID = SUPER72_MONITOR_ID | SUPERHAMLACE_KEY;
  103.       else
  104.       if(cols > 384 || rows > 384)
  105.         DisplayID = VGAPRODUCTHAM_KEY;
  106.       else
  107.         DisplayID = VGALORESHAMDBL_KEY;
  108.     }
  109.     else
  110.     {
  111.       if(cols > 780 && !NoSUPER72 && SUPER72enable) DisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
  112.       else
  113.       if(cols > 384 || rows >384) 
  114.         DisplayID = VGAPRODUCT_KEY;
  115.       else
  116.         DisplayID = VGALORESDBL_KEY;        
  117.     }
  118.   }
  119.   else
  120.   {  
  121.     if(Mode == HAM8)
  122.     {
  123.       if(cols > 384 || rows > 384)
  124.         DisplayID = HIRESHAMLACE_KEY;
  125.       else
  126.         DisplayID = HAM_KEY;
  127.     }
  128.     else
  129.     {
  130.       if(cols > 384 || rows >384) 
  131.         DisplayID = HIRESLACE_KEY;
  132.       else
  133.         DisplayID = LORES_KEY; 
  134.     }   
  135.   }
  136.  
  137.   if(Mode == HAM8) Depth = 8;
  138.     else Depth = NumPlanes;
  139.  
  140.   MyScreenTags[0].ti_Data = (ULONG)cols;
  141.   MyScreenTags[1].ti_Data = (ULONG)rows;
  142.   MyScreenTags[2].ti_Data = (ULONG)Depth;
  143.   MyScreenTags[3].ti_Data = (ULONG)DisplayID;
  144.   MyScreenTags[4].ti_Data = (ULONG)((void *)ScreenColorTable);
  145.  
  146.   MyWindowTags[0].ti_Data = (ULONG)cols;
  147.   MyWindowTags[1].ti_Data = (ULONG)rows;
  148.   
  149.   my_screen = OpenScreenTagList(NULL, (struct TagItem *)&MyScreenTags);
  150.  
  151.   if(my_screen == NULL)  return 0;
  152.     
  153.   /* open a dummy window to allow autoscroll feature      */
  154.   
  155.   MyWindowTags[2].ti_Data = (ULONG)((void *)my_screen);
  156.   my_window = OpenWindowTagList(NULL, (struct TagItem *)&MyWindowTags);
  157.  
  158.   if(my_window == NULL) return 0;
  159.  
  160.   /* initialize temprp for use with WritePixelLine8() */
  161.  
  162.   CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
  163.   temprp.Layer = NULL;
  164.   /* V39 function */
  165.   temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
  166.  
  167.   if(temprp.BitMap == NULL) return 0;
  168.  
  169.   /* set pens and drawing modes */
  170.  
  171.   if(Depth == 8)
  172.   {
  173.     SetAPen(&my_screen->RastPort, 255); 
  174.     SetDrMd(&my_screen->RastPort, JAM1);
  175.   }
  176.  
  177.  
  178.   return 1; /* success */  
  179. }
  180.  
  181.  
  182. /* Close the display */
  183.  
  184. void CloseDisplay(void)
  185. {
  186.   if(my_screen) ScreenToBack(my_screen);
  187.  
  188.   if(temprp.BitMap)
  189.   {
  190.     /* V39 function */
  191.     FreeBitMap(temprp.BitMap);
  192.     temprp.BitMap = NULL;
  193.   }
  194.   if(my_window)
  195.   {
  196.     CloseWindow(my_window);
  197.     my_window = NULL;
  198.   }
  199.   if(my_screen)
  200.   {
  201.     CloseScreen(my_screen);
  202.     my_screen = NULL;
  203.   }
  204.   if(IntuitionBase)
  205.   {
  206.    CloseLibrary(IntuitionBase);
  207.    IntuitionBase = NULL;
  208.   }
  209.   if(GfxBase)
  210.   {
  211.     CloseLibrary(GfxBase);
  212.     GfxBase = NULL;
  213.   }
  214. }
  215.  
  216.  
  217. /* display a line of chunky pixel graphics... */
  218.  
  219.  
  220. void DisplayRow(char *array, int cols)
  221. {
  222.   if(my_screen)
  223.     WritePixelLine8(&my_screen->RastPort, 0, Drow++, cols, array, &temprp);
  224. }
  225.  
  226. void DisplayRowPos(char *array, int cols, int xpos, int ypos)
  227. {
  228.   if(my_screen)
  229.     WritePixelLine8(&my_screen->RastPort, (ULONG)xpos, (ULONG)ypos, cols, array, &temprp);
  230. }
  231.  
  232.  
  233. void DisplayNrGray(int nr, int xpos, int ypos)
  234. {
  235.   if(my_screen)
  236.   {
  237.     char String[10];
  238.     sprintf(String, "%d", nr);
  239.     Move(&my_screen->RastPort, (SHORT)xpos, (SHORT)ypos);
  240.     Text(&my_screen->RastPort, String, strlen(String));
  241.   }
  242.  
  243. /* check for a right mouse button press */
  244.  
  245. int CheckButton(void)
  246. {
  247.   struct IntuiMessage *msg;
  248.   int Button = 0;
  249.  
  250.   if(my_window)
  251.   {
  252.     while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  253.     {
  254.       if(msg->Class == IDCMP_MOUSEBUTTONS)
  255.         if(msg->Code == MENUDOWN)
  256.           Button = 1; 
  257.       ReplyMsg((struct Message *)msg);
  258.       if(Button) break;
  259.     }
  260.   }
  261.   return Button;
  262. }
  263.        
  264. /* final wait after the picture is finished */
  265.  
  266. void FinalWait(void)
  267. {
  268.   struct IntuiMessage *msg;
  269.   int Button = 0;
  270.   struct TagItem WinPointerSet[] = { {WA_Pointer, (ULONG)NULL}, {TAG_DONE, (ULONG)NULL} };
  271.  
  272.   /* set the normal pointer */
  273.   /* V39 function */
  274.  
  275.   /* SetWindowPointer(my_window, WA_Pointer, NULL, TAG_DONE); */
  276.   SetWindowPointerA(my_window, WinPointerSet);
  277.   
  278.   if(my_window)
  279.   {
  280.     while(!Button)
  281.     {
  282.       Wait(1L<<my_window->UserPort->mp_SigBit);
  283.       while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  284.       {
  285.         if(msg->Class == IDCMP_MOUSEBUTTONS)
  286.           if(msg->Code == MENUDOWN) Button = 1; 
  287.         ReplyMsg((struct Message *)msg);
  288.         if(Button) break;
  289.       }
  290.     }
  291.   }
  292. }
  293.       
  294. static void error_exit(const char *msgtext)
  295. {
  296.  printf("%s", msgtext);
  297.  CloseDisplay();
  298.  exit(10);
  299. }
  300.