home *** CD-ROM | disk | FTP | other *** search
/ Falcon 030 Power 2 / F030_POWER2.iso / ST_STE / MAGS / ICTARI03.ARJ / ictari.03 / C / GEM_TUT / GEM002.C < prev    next >
Text File  |  1997-09-17  |  6KB  |  166 lines

  1. /* >>>>>>>>>>>>>>>>>>>>>>>>> Sample Redraw Code <<<<<<<<<<<<<<<<<<<<<<<<<<< */
  2.  
  3. VOID
  4. do_redraw(wh, area)             /* wh = window handle from msg[3] */
  5. WORD    wh;             /* area = pointer to redraw rect- */
  6. GRECT   *area;          /*   tangle in msg[4] thru msg[7] */
  7. {
  8.         GRECT   box;
  9.         
  10.         graf_mouse(M_OFF, 0x0L);
  11.         wind_update(BEG_UPDATE);
  12.         
  13.         wind_get(wh, WF_FIRSTXYWH, &box.g_x, &box.g_y, &box.g_w, &box.g_h);
  14.         while ( box.g_w && box.g_h )
  15.         {
  16.                 if (rc_intersect(full, &box))     /* Full is entire screen */
  17.                     if (rc_intersect(area, &box))
  18.                     {
  19.                             if (wh == w1_handle)          /* Test for window 1 handle */
  20.                             {             /* AES redraw example       */
  21.                                     objc_draw(w1_tree, ROOT, MAX_DEPTH, box.g_x, 
  22.                                               box.g_y, box.g_w, box.g_h);
  23.                             }
  24.                             else if (wh == w2_handle) /* Test for window 2 handle */
  25.                             {             /* VDI redraw example       */
  26.                                     set_clip(TRUE, &box);
  27.                                     /*  Put VDI drawing calls here */
  28.                             }
  29.                             /* add more windows here */
  30.                     }
  31.                 wind_get(wh, WF_NEXTXYWH, &box.g_x, &box.g_y, &box.g_w, 
  32.                          &box.g_h);
  33.         }
  34.         
  35.         wind_update(END_UPDATE);
  36.         graf_mouse(M_ON, 0x0L);
  37. }
  38.  
  39.  
  40. /* >>>>>>>>>>>>>>>>>>>>>>>> Utilities used in do_redraw <<<<<<<<<<<<<<<<<<<< */
  41.  
  42. VOID
  43. set_clip(clip_flag, area)       /* set clip to specified area   */
  44. WORD    clip_flag;
  45. GRECT   *area;
  46. {
  47.         WORD    pxy[4];
  48.         
  49.         grect_to_array(area, pxy);
  50.         vs_clip(vdi_handle, clip_flag, pxy);
  51. }
  52.  
  53. VOID
  54. grect_to_array(area, array)     /* convert x,y,w,h to upr lt x,y and    */
  55. GRECT   *area;          /*                    lwr rt x,y        */
  56. WORD    *array;
  57. {
  58.         *array++ = area->g_x;
  59.         *array++ = area->g_y;
  60.         *array++ = area->g_x + area->g_w - 1;
  61.         *array = area->g_y + area->g_h - 1;
  62. }
  63.  
  64. WORD
  65. rc_intersect(p1, p2)            /* compute intersect of two rectangles  */
  66. GRECT   *p1, *p2;
  67. {
  68.         WORD    tx, ty, tw, th;
  69.         
  70.         tw = min(p2->g_x + p2->g_w, p1->g_x + p1->g_w);
  71.         th = min(p2->g_y + p2->g_h, p1->g_y + p1->g_h);
  72.         tx = max(p2->g_x, p1->g_x);
  73.         ty = max(p2->g_y, p1->g_y);
  74.         p2->g_x = tx;
  75.         p2->g_y = ty;
  76.         p2->g_w = tw - tx;
  77.         p2->g_h = th - ty;
  78.         return( (tw > tx) && (th > ty) );
  79. }
  80.  
  81. /* >>>>>>>>>>>>>>>>>>>>>>> "Self-redraw" Utility <<<<<<<<<<<<<<<<<<<<<<<<< */
  82.  
  83. VOID
  84. send_redraw(wh, p)
  85. WORD    wh;
  86. GRECT   *p;
  87. {
  88.         WORD    msg[8];
  89.         
  90.         msg[0] = WM_REDRAW;             /* Defined in GEMBIND.H     */
  91.         msg[1] = gl_apid;               /* As returned by appl_init */
  92.         msg[2] = 0;
  93.         msg[3] = wh;                    /* Handle of window to redraw */
  94.         msg[4] = p->g_x;
  95.         msg[5] = p->g_y;
  96.         msg[6] = p->g_w;
  97.         msg[7] = p->g_h;
  98.         appl_write(gl_apid, 16, &msg);  /* Use ADDR(msg) for portability */
  99. }
  100.  
  101. /* >>>>>>>>>>>>>>>>>>>> Utilities for Window Requests <<<<<<<<<<<<<<<<<< */
  102.  
  103. VOID
  104. rc_constrain(pc, pt)
  105. GRECT           *pc;
  106. GRECT           *pt;
  107. {
  108.         if (pt->g_x < pc->g_x)
  109.             pt->g_x = pc->g_x;
  110.         if (pt->g_y < pc->g_y)
  111.             pt->g_y = pc->g_y;
  112.         if ((pt->g_x + pt->g_w) > (pc->g_x + pc->g_w))
  113.             pt->g_x = (pc->g_x + pc->g_w) - pt->g_w;
  114.         if ((pt->g_y + pt->g_h) > (pc->g_y + pc->g_h))
  115.             pt->g_y = (pc->g_y + pc->g_h) - pt->g_h;
  116. }
  117.  
  118. WORD
  119. align(x,n)              /* Snap position x to an n-bit grid         */ 
  120. WORD    x, n;   /* Use n = 16 for horizontal word alignment */
  121. {
  122.         x += (n >> 2) - 1;              /* Round and... */
  123.         x = n * (x / n);                /* remove residue */
  124.         return (x);
  125. }       
  126.  
  127. /* >>>>>>>>>>>>>>>>>>>>>>> Window full utility <<<<<<<<<<<<<<<<<<<<<<< */
  128.  
  129. VOID
  130. hndl_full(wh)           /* depending on current window state, make window    */
  131. WORD    wh;     /*   full size -or- return to previous shrunken size */
  132. {               /* graf_ calls are optional special effects.         */
  133.         GRECT   prev;
  134.         GRECT   curr;
  135.         GRECT   full;
  136.         
  137.         wind_get(wh, WF_CXYWH, &curr.g_x, &curr.g_y, &curr.g_w, &curr.g_h);
  138.         wind_get(wh, WF_PXYWH, &prev.g_x, &prev.g_y, &prev.g_w, &prev.g_h);
  139.         wind_get(wh, WF_FXYWH, &full.g_x, &full.g_y, &full.g_w, &full.g_h);
  140.         if ( rc_equal(&curr, &full) )
  141.         {               /* Is full, change to previous          */
  142.                 graf_shrinkbox(prev.g_x, prev.g_y, prev.g_w, prev.g_h,
  143.                                full.g_x, full.g_y, full.g_w, full.g_h);
  144.                 wind_set(wh, WF_CXYWH, prev.g_x, prev.g_y, prev.g_w, prev.g_h);
  145.                 /* put send_redraw here if you need it */
  146.         }
  147.         else
  148.         {               /* is not full, so set to full          */
  149.                 graf_growbox(curr.g_x, curr.g_y, curr.g_w, curr.g_h,
  150.                              full.g_x, full.g_y, full.g_w, full.g_h);
  151.                 wind_set(wh, WF_CXYWH, full.g_x, full.g_y, full.g_w, full.g_h);
  152.         }
  153. }
  154.  
  155. WORD
  156. rc_equal(p1, p2)                /* tests for two rectangles equal       */
  157. GRECT   *p1, *p2;
  158. {
  159.         if ((p1->g_x != p2->g_x) ||
  160.             (p1->g_y != p2->g_y) ||
  161.             (p1->g_w != p2->g_w) ||
  162.             (p1->g_h != p2->g_h))
  163.             return(FALSE);
  164.         return(TRUE);
  165. }
  166.