home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / UTILS / M_GLASS / M_GLASS.C < prev    next >
C/C++ Source or Header  |  1997-06-25  |  9KB  |  311 lines

  1. #include <aes.h>      /* GEM-Defines */
  2. #include <vdi.h>
  3. #include <osbind.h>
  4. #include <minimum.h>
  5. #include "m_glass.h"
  6.  
  7.  
  8. /* ***Programm beim GEM abmelden*** */
  9. void GEM_exit(void)
  10. {
  11.  v_clsvwk(vhandle);
  12.  appl_exit();
  13. }
  14.  
  15. /* ***Programm beim GEM anmelden*** */
  16. void GEM_init(void)
  17. {
  18.  int work_in[12], i;
  19.  ap_id=appl_init();
  20.  vhandle=graf_handle(&i, &i, &i, &i);
  21.  for(i=0;i<10;i++) work_in[i]=1;  work_in[10]=2;
  22.  v_opnvwk(work_in, &vhandle, work_out);
  23.  if(vhandle<0)
  24.   {
  25.    form_alert(1,"[3][v_opnvwk hat|nicht geklappt!][Abbruch]");
  26.    appl_exit(); exit(-1);
  27.   }
  28.  x_aufl=work_out[0]; y_aufl=work_out[1];
  29.  wind_get(0, WF_WORKXYWH, &deskx, &desky, &deskw, &deskh); /* Desktopgrö₧e */
  30.  graf_mouse(ARROW, 0L);
  31. }
  32.  
  33. /* ***MFDBs einrichten*** */
  34. void mfdb_init(void)
  35. {
  36.  pic1mfdb.fd_addr=pic1addr;
  37.  pic1mfdb.fd_nplanes=planes;
  38.  
  39.  pic2mfdb.fd_addr=pic2addr;
  40.  pic2mfdb.fd_nplanes=planes;
  41.  
  42.  pic3mfdb.fd_addr=pic3addr;
  43.  pic3mfdb.fd_nplanes=planes;
  44. }
  45.  
  46. /* ***Mausflgag setzen*** */
  47. void setmouseflag(void)
  48. {
  49.  form_dial(0, 0, 0, 0, 0, dialogx, dialogy, dialogw, dialogh);
  50.  objc_draw(tree, MAINBOX, 4, dialogx, dialogy, dialogw, dialogh);
  51.  do
  52.   {
  53.    wahl=form_do(tree, 0);
  54.    switch(wahl)
  55.     {
  56.      case MFCROSSB:
  57.        tree[MFCROSSB].ob_state^=CROSSED;
  58.        objc_draw(tree, MFCROSSB, 1, dialogx, dialogy, dialogw, dialogh);
  59.        evnt_timer(0x01F4,0x00); break;
  60.      case WUCROSSB:
  61.        tree[WUCROSSB].ob_state^=CROSSED;
  62.        objc_draw(tree, WUCROSSB, 1, dialogx, dialogy, dialogw, dialogh);
  63.        evnt_timer(0x01F4,0x00); break;
  64.     }
  65.   }
  66.  while(wahl!=OKBUTTON);
  67.  tree[OKBUTTON].ob_state=NORMAL;
  68.  form_dial(3, 0, 0, 0, 0, dialogx, dialogy, dialogw, dialogh);
  69.  mouseflag=!(tree[MFCROSSB].ob_state & CROSSED);
  70.  w_updateflag=tree[WUCROSSB].ob_state & CROSSED;
  71.  if(tree[FSTRBUT].ob_state & SELECTED)    blowup=1;
  72.  if(tree[SCNDRBUT].ob_state & SELECTED)  blowup=2;
  73.  if(tree[THRDRBUT].ob_state & SELECTED)  blowup=3;
  74. }
  75.  
  76. /* ***Vergrö₧ern*** */
  77. void blow_up(register unsigned char *src, register unsigned int *dest, int step)
  78. {
  79.  register int x, y;
  80.  for(y=0; y<wi_h/2/step*planes; y++)
  81.   {
  82.    for(x=0; x<wi_w/16/step; x++)
  83.      *dest++ = *(dest+wi_w/16/step) = (table[(*src)>>4]<<8) | table[(*src++) & 0x0F];
  84.    dest+=x;
  85.   }
  86. }
  87.  
  88. /* ***Doppelte Grö₧e*** */
  89. void normalblowup(int faktor)
  90. {
  91.   register int div;
  92.  
  93.   /* Die Maus darf nicht ganz am Bildschirmrand sein: */
  94.   div=4*faktor;
  95.   if(mausx-wi_w/div<0)    mausx=wi_w/div;
  96.   if(mausx+wi_w/div>x_aufl)  mausx=x_aufl-wi_w/div;
  97.   if(mausy-wi_h/div<0)    mausy=wi_h/div;
  98.   if(mausy+wi_h/div>y_aufl)  mausy=y_aufl-wi_h/div;
  99.  
  100.   /* MFDBs auf die richtige Grö₧e bringen: */
  101.   div=2*faktor;
  102.   pic1mfdb.fd_w=wi_w/div; pic1mfdb.fd_h=wi_h/div; pic1mfdb.fd_wdwidth=wi_w/32/faktor;
  103.   pic2mfdb.fd_w=wi_w/div; pic2mfdb.fd_h=wi_h/div; pic2mfdb.fd_wdwidth=wi_w/32/faktor;
  104.   pic3mfdb.fd_w=wi_w; pic3mfdb.fd_h=wi_h; pic3mfdb.fd_wdwidth=wi_w/16;
  105.  
  106.   /* Bildschirm unter der Maus kopieren: */
  107.   div=4*faktor;
  108.   xy[0]=mausx-wi_w/div;  xy[1]=mausy-wi_h/div;
  109.   xy[2]=mausx+wi_w/div-1;xy[3]=mausy+wi_h/div-1;
  110.   xy[4]=0;                 xy[5]=0;
  111.   xy[6]=pic2mfdb.fd_w-1; xy[7]=pic2mfdb.fd_h-1;
  112.   if(w_updateflag)     wind_update(BEG_UPDATE);
  113.   if(mouseflag)      graf_mouse(M_OFF, 0L);
  114.   vro_cpyfm(vhandle, S_ONLY, xy, &scrnmfdb, &pic1mfdb);
  115.   if(mouseflag)   graf_mouse(M_ON, 0L);
  116.   if(w_updateflag)     wind_update(END_UPDATE);
  117.  
  118.   /* MFDB verändern: */
  119.   vr_trnfm(vhandle, &pic1mfdb, &pic2mfdb);
  120.   switch(faktor)
  121.    {
  122.    case 1:
  123.       blow_up(pic2addr, pic3addr, 1);
  124.       break;
  125.    case 2:
  126.       blow_up(pic2addr, pic1addr, 2);
  127.       blow_up(pic1addr, pic3addr, 1);
  128.       break;
  129.    }
  130.   pic1mfdb.fd_w=wi_w; pic1mfdb.fd_h=wi_h; pic1mfdb.fd_wdwidth=wi_w/16;
  131.   vr_trnfm(vhandle, &pic3mfdb, &pic1mfdb);
  132.  
  133.   xy[0]=0;             xy[1]=0;
  134.   xy[2]=wi_w-1;      xy[3]=wi_h-1;
  135.   xy[4]=wi_x;         xy[5]=wi_y;
  136.   xy[6]=wi_x+wi_w-1; xy[7]=wi_y+wi_h-1;
  137.  
  138.   /* Auf den Bildschirm kopieren: */
  139.   if(w_updateflag)     wind_update(BEG_UPDATE);
  140.   wind_get(wi_handle, WF_FIRSTXYWH, &xyclip[0], &xyclip[1], &rw, &rh);
  141.   do
  142.    {
  143.    xyclip[2]=xyclip[0]+rw-1;  xyclip[3]=xyclip[1]+rh-1;
  144.    vs_clip(vhandle, 1, xyclip);
  145.    vro_cpyfm(vhandle, S_ONLY, xy, &pic1mfdb, &scrnmfdb);  /* Copy */
  146.    wind_get(wi_handle, WF_NEXTXYWH, &xyclip[0], &xyclip[1], &rw, &rh);
  147.    }
  148.   while(rw!=0 && rh!=0);
  149.   if(w_updateflag)     wind_update(END_UPDATE);
  150. }
  151.  
  152. /* ***Mega-Vergrö₧ern*** */
  153. void megablowup(void)
  154. {
  155.  register int x, y;
  156.  int color;
  157.  
  158.  if(mausx<3)  mausx=3;
  159.  if(mausx>x_aufl-3)  mausx=x_aufl-3;
  160.  if(mausy<3)  mausy=3;
  161.  if(mausy>y_aufl-3)  mausy=y_aufl-3;
  162.  
  163.  for(x=0; x<7; x++)
  164.   for(y=0; y<7; y++)
  165.    {
  166.     if(mouseflag)  graf_mouse(M_OFF, 0L);
  167.     v_get_pixel(vhandle, x+mausx-3, y+mausy-3, xy, &color);
  168.     if(mouseflag)  graf_mouse(M_ON, 0L);
  169.     vsf_color(vhandle, color);
  170.     xy[0]=wi_x+wi_w*x/5;       xy[1]=wi_y+wi_h*y/5;
  171.     xy[2]=wi_x-1+wi_w*(x+1)/5; xy[3]=wi_y-1+wi_h*(y+1)/5;
  172.     if(w_updateflag)  wind_update(BEG_UPDATE);
  173.     wind_get(wi_handle, WF_FIRSTXYWH, &xyclip[0], &xyclip[1], &rw, &rh);
  174.     do
  175.      {
  176.       xyclip[2]=xyclip[0]+rw-1;  xyclip[3]=xyclip[1]+rh-1;
  177.       vs_clip(vhandle, 1, xyclip);
  178.       v_bar(vhandle, xy);         /* Draw */
  179.       wind_get(wi_handle, WF_NEXTXYWH, &xyclip[0], &xyclip[1], &rw, &rh);
  180.      }
  181.     while(rw!=0 && rh!=0);
  182.     if(w_updateflag)  wind_update(END_UPDATE);
  183.    }
  184. }
  185.  
  186. /* ***Fenster öffnen und Lupe darstellen*** */
  187. int mag_glass(void)
  188. {
  189.  int whichevnt;
  190.  int i;
  191.  
  192.  /* Window erstellen und öffnen:*/
  193.  wi_handle=wind_create(NAME|CLOSER|FULLER|MOVER|SIZER, deskx ,desky,
  194.             deskw, deskh);      /* Window anmelden */
  195.  if(wi_handle<0)
  196.   { form_alert(1,"[3][Kein Fenster übrig!][Abbruch]");
  197.     return(-1); }
  198.  wind_set(wi_handle, WF_NAME, "Magicfying Glass", 0L); /* Name setzen */
  199.  wind_calc(WC_BORDER, NAME|CLOSER|FULLER|MOVER|SIZER, 0, 0, 128, 104,
  200.          &wi_x, &wi_y, &wi_w, &wi_h);
  201.  wi_x=deskx+(deskw-wi_w)/2;  wi_y=desky+(deskh-wi_h)/2;
  202.  graf_growbox(x_aufl/2, y_aufl/2, 2, 1, wi_x, wi_y, wi_w, wi_h);
  203.  wind_open(wi_handle, wi_x, wi_y, wi_w, wi_h);      /* Window öffnen */
  204.  
  205.  /* Hauptschleife: */
  206.  do
  207.  {
  208.   whichevnt=evnt_multi(MU_TIMER|MU_MESAG|MU_BUTTON, 0, 3, 0, 0, 0, 0, 0, 0,
  209.             0, 0, 0, 0, 0,msgbuff, 15, 0, &mausx, &mausy, &i, &i, &i, &i);
  210.  
  211.   if(whichevnt & MU_MESAG)      /* Ereignisse auswerten */
  212.    switch(msgbuff[0])
  213.    {
  214.     case WM_TOPPED:
  215.       wind_set(msgbuff[3], WF_TOP, 0L, 0L);
  216.       break;
  217.     case WM_FULLED:
  218.       msgbuff[4]=deskx; msgbuff[5]=desky;
  219.       msgbuff[6]=deskw; msgbuff[7]=deskh;
  220.      case WM_SIZED:
  221.       wind_calc(WC_WORK, NAME|CLOSER|FULLER|MOVER|SIZER, 0, 0,
  222.             msgbuff[6], msgbuff[7], &wi_x, &wi_y, &wi_w, &wi_h);
  223.       switch(blowup)
  224.        {
  225.         case 1: wi_w &= 0xFFE0; wi_h &= 0xFFFC; break;
  226.         case 2: wi_w=(wi_w+32) & 0xFFC0; wi_h &= 0xFFF8; break;
  227.        }
  228.       wind_calc(WC_BORDER, NAME|CLOSER|FULLER|MOVER|SIZER, wi_x, wi_y,
  229.             wi_w, wi_h, &wi_x, &wi_y, &msgbuff[6], &msgbuff[7]);
  230.     case WM_MOVED:
  231.       wind_set(msgbuff[3], WF_CURRXYWH, msgbuff[4], msgbuff[5],
  232.             msgbuff[6], msgbuff[7]);
  233.       break;
  234.     case AC_OPEN:
  235.       setmouseflag();
  236.       wind_get(wi_handle, WF_WORKXYWH, &wi_x, &wi_y, &wi_w, &wi_h);
  237.       wi_w=(wi_w+32) & 0xFFC0; wi_h &= 0xFFF8;
  238.       wind_calc(WC_BORDER, NAME|CLOSER|FULLER|MOVER|SIZER, wi_x, wi_y,
  239.             wi_w, wi_h, &wi_x, &wi_y, &wi_w, &wi_h);
  240.       wind_set(wi_handle, WF_CURRXYWH, wi_x, wi_y, wi_w, wi_h);
  241.       break;
  242.    }
  243.  
  244.   wind_get(wi_handle, WF_WORKXYWH, &wi_x, &wi_y, &wi_w, &wi_h);
  245.  
  246.   switch(blowup)
  247.    {
  248.    case 1: normalblowup(1); break;
  249.    case 2: normalblowup(2); break;
  250.    case 3: megablowup(); break;
  251.    }
  252.  
  253.  }
  254.  while( (msgbuff[0]!=WM_CLOSED || msgbuff[3]!=wi_handle)
  255.       && msgbuff[0]!=AC_CLOSE );
  256.  
  257.  if(msgbuff[0]!=AC_CLOSE)
  258.   {   wind_close(wi_handle);     /* Fenster schlie₧en */
  259.    wind_delete(wi_handle); }  /* Fenster abmelden */
  260.  
  261.  graf_shrinkbox(x_aufl/2, y_aufl/2, 2, 1, wi_x, wi_y, wi_w, wi_h);
  262.  return(0);
  263. }
  264.  
  265.  
  266. /* ***Start*** */
  267. main(void)
  268. {
  269.  long dummy;
  270.  
  271.  GEM_init();
  272.  
  273.  wind_update(BEG_UPDATE);
  274.  vq_extnd(vhandle, 1, work_out);
  275.  planes=work_out[4];
  276.  wind_calc(WC_WORK, NAME|CLOSER|FULLER|MOVER|SIZER, deskx, desky,
  277.            deskw, deskh, &wi_x, &wi_y, &max_x, &max_y);
  278.  dummy=(long)max_x*(long)max_y*(long)planes/8L;
  279.  pic1addr=Malloc(dummy);
  280.  pic2addr=Malloc(dummy/4L);
  281.  pic3addr=Malloc(dummy);
  282.  if(pic1addr<0 || pic2addr<0 || pic3addr<0)
  283.   {
  284.    form_alert(1,"[3][Nicht genug Speicher|übrig!][Abbruch]");
  285.    GEM_exit();
  286.    exit(-1);
  287.   }
  288.  mfdb_init();
  289.  for(dummy=MAINBOX; dummy<OKBUTTON+1; dummy++)    rsrc_obfix(tree, (int)dummy);
  290.  form_center(tree, &dialogx, &dialogy, &dialogw, &dialogh);
  291.  wind_update(END_UPDATE);
  292.  
  293.  if(_app)
  294.    {                    /* Normales Programm */
  295.    setmouseflag();
  296.    mag_glass();
  297.    GEM_exit();
  298.    }
  299.   else
  300.    {                    /* Accessory */
  301.    menu_id=menu_register(ap_id,"  Magicfying Glass");
  302.    while(-1)
  303.     {
  304.      evnt_mesag(msgbuff);
  305.      if(msgbuff[0]==AC_OPEN)  mag_glass();
  306.      }
  307.    }
  308.  
  309.  return 0;
  310. }
  311.