home *** CD-ROM | disk | FTP | other *** search
/ Dream 48 / Amiga_Dream_48.iso / Atari / c / libs / xaes_new.lzh / FLYING.C < prev    next >
C/C++ Source or Header  |  1994-10-27  |  6KB  |  180 lines

  1. /********************************************************************
  2.  *                                                                0.50*
  3.  *    XAES: Flying Dialogs and Custom Screen save routines            *
  4.  *    by Ken Hollis and Markus Gutschke                                *
  5.  *                                                                    *
  6.  *    Copyright (c) 1994, Bitgate Software.  All Rights Reserved.        *
  7.  *                                                                    *
  8.  *    Commented routines are not yet used, but are functional.        *
  9.  *    This code is by Markus Gutschke, which goes without saying.        *
  10.  *    Markus makes a living out of *trying* to create convoluted code.*
  11.  *                                                                    *
  12.  ********************************************************************/
  13.  
  14. #include <stdlib.h>
  15. #include <stdarg.h>
  16. #include <string.h>
  17. #include <aes.h>
  18. #include <vdi.h>
  19.  
  20. #include "xaes.h"
  21.  
  22. void *bgbuffer;
  23.  
  24. GLOBAL int intersect(int  x1,int  y1,int  w1,int  h1,
  25.                           int  x2,int  y2,int  w2,int  h2,
  26.                        int *x3,int *y3,int *w3,int *h3)
  27. {
  28.     *x3    = max(x1,x2);
  29.     *y3    = max(y1,y2);
  30.     *w3    = min(x1+w1-1,x2+w2-1) - *x3 + 1;
  31.     *h3    = min(y1+h1-1,y2+h2-1) - *y3 + 1;
  32.     return ((*w3 > 0) && (*h3 > 0));
  33. }
  34.  
  35. /* GLOBAL void *scrmove(void *buffer,int nx,int ny)
  36. {
  37.     #define    buffer    ((Buffer *)buffer)
  38.     Buffer    *newbuffer;
  39.     int        w,h;
  40.     int        rx,ry,rw,rh;
  41.     int        pxy[8],rst[8];
  42.  
  43.     if (buffer != 0 && buffer->magic == 0x4711) {
  44.         graf_mouse(M_OFF,0);
  45.         w = buffer->pxy[2]-buffer->pxy[0]+1;
  46.         h = buffer->pxy[3]-buffer->pxy[1]+1;
  47.         newbuffer = scrsave(buffer->vdihandle,nx,ny,w,h);
  48.         if (newbuffer == 0) {
  49.             form_dial(FMD_FINISH,0,0,0,0,nx,ny,w,h);
  50.             scrrestore(buffer);
  51.             return(0); }
  52.         buffer->magic = 0;
  53.         pxy[0] = buffer->pxy[0];
  54.         pxy[1] = buffer->pxy[1];
  55.         pxy[2] = buffer->pxy[2];
  56.         pxy[3] = buffer->pxy[3];
  57.         pxy[6] = (pxy[4] = nx) + w - 1;
  58.         pxy[7] = (pxy[5] = ny) + h - 1;
  59.         if (intersect(pxy[0],pxy[1],w,h,
  60.                       pxy[4],pxy[5],w,h,
  61.                       &rx,&ry,&rw,&rh)) {
  62.             rst[2] = (rst[0] = rx - pxy[0]) + rw - 1;
  63.             rst[3] = (rst[1] = ry - pxy[1]) + rh - 1;
  64.             rst[6] = (rst[4] = rx - nx) + rw - 1;
  65.             rst[7] = (rst[5] = ry - ny) + rh - 1;
  66.             vro_cpyfm(buffer->vdihandle,S_ONLY,rst,
  67.                       &buffer->mfdb,&newbuffer->mfdb); }
  68.         vro_cpyfm(buffer->vdihandle,S_ONLY,pxy,&buffer->scr,&buffer->scr);
  69.         if (intersect(pxy[0],pxy[1],w,h,
  70.                       pxy[0],pxy[1],pxy[6]-pxy[0]+1,pxy[5]-pxy[1],
  71.                       &rx,&ry,&rw,&rh)) {
  72.             rst[2] = (rst[0] = rx - pxy[0]) + rw - 1;
  73.             rst[3] = (rst[1] = ry - pxy[1]) + rh - 1;
  74.             rst[6] = (rst[4] = rx) + rw - 1;
  75.             rst[7] = (rst[5] = ry) + rh - 1;
  76.             vro_cpyfm(buffer->vdihandle,S_ONLY,rst,&buffer->mfdb,&buffer->scr); }
  77.         if (intersect(pxy[0],pxy[1],w,h,
  78.                       pxy[6]+1,pxy[1],pxy[2]-pxy[6],pxy[7]-pxy[1]+1,
  79.                       &rx,&ry,&rw,&rh)) {
  80.             rst[2] = (rst[0] = rx - pxy[0]) + rw - 1;
  81.             rst[3] = (rst[1] = ry - pxy[1]) + rh - 1;
  82.             rst[6] = (rst[4] = rx) + rw - 1;
  83.             rst[7] = (rst[5] = ry) + rh - 1;
  84.             vro_cpyfm(buffer->vdihandle,S_ONLY,rst,&buffer->mfdb,&buffer->scr); }
  85.         if (intersect(pxy[0],pxy[1],w,h,
  86.                       pxy[4],pxy[7]+1,pxy[2]-pxy[4]+1,pxy[3]-pxy[7],
  87.                       &rx,&ry,&rw,&rh)) {
  88.             rst[2] = (rst[0] = rx - pxy[0]) + rw - 1;
  89.             rst[3] = (rst[1] = ry - pxy[1]) + rh - 1;
  90.             rst[6] = (rst[4] = rx) + rw - 1;
  91.             rst[7] = (rst[5] = ry) + rh - 1;
  92.             vro_cpyfm(buffer->vdihandle,S_ONLY,rst,&buffer->mfdb,&buffer->scr); }
  93.         if (intersect(pxy[0],pxy[1],w,h,
  94.                       pxy[0],pxy[5],pxy[4]-pxy[0],pxy[3]-pxy[5]+1,
  95.                       &rx,&ry,&rw,&rh)) {
  96.             rst[2] = (rst[0] = rx - pxy[0]) + rw - 1;
  97.             rst[3] = (rst[1] = ry - pxy[1]) + rh - 1;
  98.             rst[6] = (rst[4] = rx) + rw - 1;
  99.             rst[7] = (rst[5] = ry) + rh - 1;
  100.             vro_cpyfm(buffer->vdihandle,S_ONLY,rst,&buffer->mfdb,&buffer->scr); }
  101.         graf_mouse(M_ON,0);
  102.         free(buffer);
  103.         return(newbuffer); }
  104.     return(0);
  105.     
  106.     #undef    buffer
  107. } */
  108.  
  109. GLOBAL void *scrsave(int vdihandle,int x,int y,int w,int h)
  110. {
  111.     int        workout[57];
  112.     Buffer    *buffer;
  113.     long    size;
  114.     int        planes,wdwidth;
  115.  
  116.     vq_extnd(vdihandle,1,workout);
  117.     planes = workout[4];
  118.     wdwidth = (int)((w + 15) / 16);
  119.     size = sizeof(Buffer) + (long)planes*(long)h*2L*(long)wdwidth;
  120.     if ((buffer = malloc(size)) == 0)
  121.         return(0);
  122.     else {
  123.         buffer->magic = 0x4711;
  124.         buffer->vdihandle        = vdihandle;
  125.         buffer->mfdb.fd_addr     = ((long) &buffer->data);
  126.         buffer->mfdb.fd_w        = w;
  127.         buffer->mfdb.fd_h        = h;
  128.         buffer->mfdb.fd_wdwidth    = wdwidth;
  129.         buffer->mfdb.fd_stand    = 0;
  130.         buffer->mfdb.fd_nplanes    = planes;
  131.         buffer->scr.fd_addr        = (long)(0L);
  132.         buffer->scr.fd_w        = 
  133.         buffer->scr.fd_h        = 
  134.         buffer->scr.fd_wdwidth    = 
  135.         buffer->scr.fd_stand    =
  136.         buffer->scr.fd_nplanes    = 0;
  137.         buffer->pxy[0]            = x;
  138.         buffer->pxy[1]            = y;
  139.         buffer->pxy[2]            = x + w - 1;
  140.         buffer->pxy[3]            = y + h - 1;
  141.         buffer->pxy[4]             = 0;
  142.         buffer->pxy[5]             = 0;
  143.         buffer->pxy[6]             = w-1;
  144.         buffer->pxy[7]             = h-1;
  145.         graf_mouse(M_OFF,0);
  146.         vro_cpyfm(vdihandle,S_ONLY,buffer->pxy,
  147.                   &buffer->scr,&buffer->mfdb);
  148.         graf_mouse(M_ON,0);
  149.         return((void *)buffer); }
  150. }
  151.  
  152. GLOBAL void scrrestore(void *buffer)
  153. {
  154.     #define    buffer    ((Buffer *)buffer)
  155.     int        pxy[8];
  156.     int        *s,*d;
  157.  
  158.     if (buffer != 0 && buffer->magic == 0x4711) {
  159.         buffer->magic = 0;
  160.         d = pxy; s = buffer->pxy+4;
  161.         *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
  162.         d = pxy+4; s = buffer->pxy;
  163.         *d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++;
  164.         graf_mouse(M_OFF,0);
  165.         vro_cpyfm(buffer->vdihandle,S_ONLY,pxy,
  166.                   &buffer->mfdb,&buffer->scr);
  167.         graf_mouse(M_ON,0);
  168.         free(buffer); }
  169.     return;
  170.     
  171.     #undef    buffer
  172. }
  173.  
  174. /* GLOBAL BOOL WCanFly(void)
  175. {
  176.     if (find_cookie('NVDI'))
  177.         return TRUE;
  178.  
  179.     return FALSE;
  180. } */