home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga Shareware Floppies / ma57.dms / ma57.adf / aMiPEG05 / source.lha / cybergfx.c < prev    next >
C/C++ Source or Header  |  1996-01-23  |  4KB  |  169 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/exec.h>
  15. #include <proto/cybergraphics.h>
  16. #include <proto/intuition.h>
  17. #include <proto/dos.h>
  18.  
  19. #include "video.h"
  20. #include "proto.h"
  21.  
  22. extern int ditherType;
  23.  
  24. struct Library *CyberGfxBase;
  25. ULONG cyber_mode;
  26. ULONG depth;
  27. struct Screen *cyber_screen;
  28. struct Window *cyber_window;
  29. int original_x, original_y;
  30.  
  31. extern UBYTE Cb_r_tab[2048];
  32.  
  33. static void Quit(char *why, int failcode)
  34. {
  35.     puts(why);
  36.     exit(failcode);
  37. }
  38.  
  39. static void output_term(void)
  40. {
  41.     if(cyber_window)
  42.         CloseWindow(cyber_window);
  43.  
  44.     if(cyber_screen)
  45.         CloseScreen(cyber_screen);
  46.  
  47.     if (CyberGfxBase) CloseLibrary(CyberGfxBase);
  48.     if (IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);
  49. }
  50.  
  51. void DrawCyberGfxImage(void *data, int x, int y)
  52. {
  53.     int win_x = cyber_window->Width - cyber_window->BorderLeft - cyber_window->BorderRight;
  54.     int win_y = cyber_window->Height - cyber_window->BorderTop - cyber_window->BorderBottom;
  55.  
  56.     if(win_x == x && win_y == y)
  57.     {
  58.         if(ditherType == CYBERGFXGRAY_DITHER)
  59.             WritePixelArray(data, 0, 0, x, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, x, y, RECTFMT_GREY8);
  60.         else
  61.             WritePixelArray(data, 0, 0, x * 4, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, x, y, RECTFMT_ARGB);
  62.     }
  63.     else
  64.     {
  65.         if(ditherType == CYBERGFXGRAY_DITHER)
  66.             ScalePixelArray(data, x, y, x, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, win_x, win_y, RECTFMT_GREY8);
  67.         else
  68.             ScalePixelArray(data, x, y, x * 4, cyber_window->RPort, cyber_window->BorderLeft, cyber_window->BorderTop, win_x, win_y, RECTFMT_ARGB);
  69.     }
  70. }
  71.  
  72. int handle_window(void)
  73. {
  74.     struct IntuiMessage *imsg;
  75.     struct IntuiMessage msg;
  76.     static ULONG last_secs, last_micros;
  77.  
  78.     if(cyber_window)
  79.     {
  80.         while(imsg = (struct IntuiMessage *)GetMsg(cyber_window->UserPort))
  81.         {
  82.             CopyMem((char *)imsg, (char *)&msg, (long)sizeof(struct IntuiMessage));
  83.             ReplyMsg((struct Message *)imsg);
  84.             switch(msg.Class)
  85.             {
  86.                 case IDCMP_CLOSEWINDOW:
  87.                 return(FALSE);
  88.  
  89.                 case IDCMP_MOUSEBUTTONS:
  90.                     if(msg.Code == SELECTDOWN)
  91.                     {
  92.                         if(DoubleClick(last_secs, last_micros, msg.Seconds, msg.Micros))
  93.                             ChangeWindowBox(cyber_window, cyber_window->LeftEdge, cyber_window->TopEdge, original_x, original_y);
  94.  
  95.                         last_secs = msg.Seconds;
  96.                         last_micros = msg.Micros;
  97.                     }
  98.                 break;
  99.  
  100.                 default:
  101.                 break;
  102.             }
  103.         }
  104.     }
  105.     return(TRUE);
  106. }
  107.  
  108.  
  109. BOOL init_cybergfx(void)
  110. {
  111.     if(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",37))
  112.         if(CyberGfxBase = OpenLibrary("cybergraphics.library", 40))
  113.             return(TRUE);
  114.         else
  115.             Quit("cybergraphics.library v40+ not present", 25);
  116.     else
  117.         Quit("intuition.library is too old, <V39", 25);
  118. }
  119.  
  120. int get_cyber_mode(void)
  121. {
  122.     return((int)CModeRequestTags(NULL,
  123.                                                     CYBRMREQ_WinTitle, "Select a screenmode for MPEG Window",
  124.                                                     CYBRMREQ_MinDepth, 15,
  125.                                                     TAG_DONE));
  126. }
  127.  
  128.  
  129. unsigned long InitCyberGfxDisplay(unsigned long modeid)
  130. {
  131.     atexit(output_term);
  132.  
  133.     if(init_cybergfx())
  134.     {
  135.         if((modeid != 0xffffffff) || (modeid = get_cyber_mode()) != 0xffffffff)
  136.         {
  137.             cyber_mode = modeid;
  138.             depth = GetCyberIDAttr(CYBRIDATTR_DEPTH, cyber_mode);
  139.             if(depth < 15)
  140.                 Quit("aMiPEG: this screen is not deep enough (needed at least 15 bits).", 25);
  141.  
  142.             if(cyber_screen = OpenScreenTags(NULL,
  143.                             SA_Width, STDSCREENWIDTH,
  144.                             SA_Height, STDSCREENHEIGHT,
  145.                             SA_DisplayID, cyber_mode,
  146.                             SA_Title, (UBYTE *)"CyberGraphX aMiPEG 0.5 by Michael Rausch and Miloslaw Smyk",
  147.                             SA_Depth, depth,
  148.                             TAG_DONE))
  149.             {
  150.  
  151.                 if(cyber_window = OpenWindowTags(NULL,
  152.                                     WA_CustomScreen, cyber_screen,
  153.                                     WA_Flags, WFLG_DEPTHGADGET | WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_SIZEGADGET | WFLG_SIZEBBOTTOM | WFLG_ACTIVATE,
  154.                     WA_IDCMP, CLOSEWINDOW | MOUSEBUTTONS,
  155.                     WA_InnerWidth, 160,
  156.                     WA_InnerHeight,120,
  157.                     WA_MaxWidth, ~0,
  158.                     WA_MaxHeight, ~0,
  159.                     WA_MinWidth, 60,
  160.                     WA_MinHeight, 60,
  161.                     WA_Title, "Playing MPEG animation",
  162.                     TAG_DONE))
  163.                     return(modeid);
  164.             }
  165.         }
  166.     }
  167.     Quit("aMiPEG: unable to open screen/window...", 25);
  168. }
  169.