home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / opus / v5 / amipeg / source / cybergfx.c < prev    next >
C/C++ Source or Header  |  1977-12-31  |  5KB  |  186 lines

  1.  
  2. /* this source implements aMiPEG's interface to CyberGraphX */
  3.  
  4.  
  5. #include <string.h>
  6. #include <stdlib.h>
  7.  
  8. #include <exec/exec.h>
  9. #include <cybergraphics/cybergraphics.h>
  10. #include <intuition/intuition.h>
  11. #include <intuition/screens.h>
  12. #include <dos/dos.h>
  13.  
  14. #include <proto/graphics.h>
  15. #include <proto/exec.h>
  16. #include <proto/cybergraphics.h>
  17. #include <proto/intuition.h>
  18. #include <proto/dos.h>
  19.  
  20. #include "video.h"
  21. #include "proto.h"
  22.  
  23. extern int ditherType;
  24. extern int cyber_pub;
  25. extern struct GfxBase *GfxBase;
  26.  
  27. struct Library *CyberGfxBase;
  28. ULONG cyber_mode;
  29. ULONG depth;
  30. struct Screen *cyber_screen;
  31. struct Window *cyber_window;
  32. int original_x, original_y;
  33.  
  34. static void Quit(char *why, int failcode)
  35. {
  36.     puts(why);
  37.     exit(failcode);
  38. }
  39.  
  40. static void output_term(void)
  41. {
  42.     close_timer();
  43.  
  44.     if(cyber_window)
  45.         CloseWindow(cyber_window);
  46.  
  47.     if(!cyber_pub && cyber_screen)
  48.         CloseScreen(cyber_screen);
  49.  
  50.     if (GfxBase) CloseLibrary((struct Library *)GfxBase);
  51.     if (CyberGfxBase) CloseLibrary(CyberGfxBase);
  52.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  53. }
  54.  
  55. void DrawCyberGfxImage(void *data, int x, int y)
  56. {
  57.     int win_x = cyber_window->Width - cyber_window->BorderLeft - cyber_window->BorderRight;
  58.     int win_y = cyber_window->Height - cyber_window->BorderTop - cyber_window->BorderBottom;
  59.  
  60.     if(win_x == x && win_y == y)
  61.     {
  62.         if(ditherType == CYBERGFXGRAY_DITHER)
  63.             WritePixelArray(data, 0, 0, x & 0x0f ? ((x >> 4) + 1 ) << 4 : x, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, x, y, RECTFMT_GREY8);
  64.         else
  65.             WritePixelArray(data, 0, 0, (x & 0x0f ? ((x >> 4) + 1 ) << 4 : x ) * 4, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, x, y, RECTFMT_ARGB);
  66.     }
  67.     else
  68.     {
  69.         if(ditherType == CYBERGFXGRAY_DITHER)
  70.             ScalePixelArray(data, x, y, x & 0x0f ? ((x >> 4) + 1 ) << 4 : x, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, win_x, win_y, RECTFMT_GREY8);
  71.         else
  72.             ScalePixelArray(data, x, y, (x & 0x0f ? ((x >> 4) + 1 ) << 4 : x) * 4, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, win_x, win_y, RECTFMT_ARGB);
  73.     }
  74. }
  75.  
  76. int handle_window(void)
  77. {
  78.     struct IntuiMessage *imsg;
  79.     struct IntuiMessage msg;
  80.     static ULONG last_secs, last_micros;
  81.  
  82.     if(cyber_window)
  83.     {
  84.         while(imsg = (struct IntuiMessage *)GetMsg(cyber_window->UserPort))
  85.         {
  86.             CopyMem((char *)imsg, (char *)&msg, (long)sizeof(struct IntuiMessage));
  87.             ReplyMsg((struct Message *)imsg);
  88.             switch(msg.Class)
  89.             {
  90.                 case IDCMP_CLOSEWINDOW:
  91.                 return(FALSE);
  92.  
  93.                 case IDCMP_MOUSEBUTTONS:
  94.                     if(msg.Code == SELECTDOWN)
  95.                     {
  96.                         if(DoubleClick(last_secs, last_micros, msg.Seconds, msg.Micros))
  97.                             ChangeWindowBox(cyber_window, cyber_window->LeftEdge, cyber_window->TopEdge, original_x, original_y);
  98.  
  99.                         last_secs = msg.Seconds;
  100.                         last_micros = msg.Micros;
  101.                     }
  102.                 break;
  103.  
  104.                 default:
  105.                 break;
  106.             }
  107.         }
  108.     }
  109.     return(TRUE);
  110. }
  111.  
  112.  
  113. BOOL init_cybergfx(void)
  114. {
  115.     if(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37))
  116.         if(CyberGfxBase = OpenLibrary("cybergraphics.library", 40))
  117.             if(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39))
  118.                 return(TRUE);
  119.             else
  120.                 Quit("graphics.library v39+ not present", 25);
  121.         else
  122.             Quit("cybergraphics.library v40+ not present", 25);
  123.     else
  124.         Quit("intuition.library is too old, <V39", 25);
  125. }
  126.  
  127. int get_cyber_mode(void)
  128. {
  129.     return((int)CModeRequestTags(NULL,
  130.                                                     CYBRMREQ_WinTitle, "Select a screenmode for MPEG Window",
  131.                                                     CYBRMREQ_MinDepth, 15,
  132.                                                     TAG_DONE));
  133. }
  134.  
  135.  
  136. unsigned long InitCyberGfxDisplay(unsigned long modeid)
  137. {
  138.     atexit(output_term);
  139.  
  140.     if(init_cybergfx())
  141.     {
  142.         if(cyber_pub || (modeid != 0xffffffff) || (modeid = get_cyber_mode()) != 0xffffffff)
  143.         {
  144.             if(cyber_pub)
  145.             {
  146.                 cyber_screen = LockPubScreen(pubname_ptr);
  147.                 modeid = GetVPModeID(&cyber_screen->ViewPort);
  148.                 ScreenToFront(cyber_screen);
  149.                 UnlockPubScreen(NULL, cyber_screen);
  150.             }
  151.  
  152.             cyber_mode = modeid;
  153.             depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, cyber_mode);
  154.             if(depth < 15)
  155.                 Quit("aMiPEG: this screen is not deep enough (needed at least 15 bits).", 25);
  156.  
  157.             if(cyber_screen || (cyber_screen = OpenScreenTags(NULL,
  158.                             SA_Width, STDSCREENWIDTH,
  159.                             SA_Height, STDSCREENHEIGHT,
  160.                             SA_DisplayID, cyber_mode,
  161.                             SA_Title, (UBYTE *)"aMiPEG 0.7 by Michael Rausch and Miloslaw Smyk",
  162.                             SA_Depth, depth,
  163.                             TAG_DONE)))
  164.             {
  165.  
  166.  
  167.                 if(cyber_window = OpenWindowTags(NULL,
  168.                                     cyber_pub ? WA_PubScreenName : WA_CustomScreen, cyber_pub ? pubname_ptr : cyber_screen,
  169.                                     WA_Flags, WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_SIZEGADGET | WFLG_SIZEBBOTTOM | WFLG_ACTIVATE,
  170.                     WA_IDCMP, CLOSEWINDOW | MOUSEBUTTONS,
  171.                     WA_InnerWidth, 160,
  172.                     WA_InnerHeight,120,
  173.                     WA_MaxWidth, ~0,
  174.                     WA_MaxHeight, ~0,
  175.                     WA_MinWidth, 60,
  176.                     WA_MinHeight, 60,
  177.                     WA_Title, "Playing MPEG animation",
  178.                     WA_ScreenTitle, (UBYTE *)"aMiPEG 0.7 by Michael Rausch and Miloslaw Smyk",
  179.                     TAG_DONE))
  180.                     return(modeid);
  181.             }
  182.         }
  183.     }
  184.     Quit("aMiPEG: unable to open screen/window...", 25);
  185. }
  186.