home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / GAMES / BOINKO21 / SRC / SRC / WINDOW.C < prev    next >
C/C++ Source or Header  |  2000-11-27  |  7KB  |  344 lines

  1. /*
  2.  * Window.C
  3.  *  v. 1.1
  4.  */
  5.  
  6. #include <stdio.h>
  7.  
  8. #include "boink.h"
  9.  
  10. #ifndef ED_INIT
  11. #define ED_INIT 1
  12. #endif
  13.  
  14. GRECT clip;
  15. GRECT full;
  16.  
  17. /* Close all windows
  18.  *
  19.  * Rewritten so it doesn't look so bad 
  20.  */
  21.  
  22. int
  23. close_all_windows(void)
  24. {
  25.     int i;
  26.     
  27.     for(i=0;i<MAX_WINDOWS;i++)
  28.     {
  29.         if (win[i].handle != NO_WINDOW)
  30.         {
  31.             wind_close(win[i].handle);
  32.             wind_delete(win[i].handle);
  33.             win[i].handle = NO_WINDOW;
  34.         }
  35.     }
  36.  
  37.     return(1);
  38. }
  39.  
  40. int
  41. get_wininfo_from_handle(int w_hand)
  42. {
  43.     int i;
  44.     
  45.     for(i = 0; i < MAX_WINDOWS; i++)
  46.     {
  47.         if (win[i].handle == w_hand)
  48.             return (i);
  49.     }
  50.  
  51.     return(-1); /* Didn't find the handle in our structures */
  52. }
  53.  
  54. int    
  55. new_window(OBJECT *tree, const char *title, int type)
  56. {
  57.     GRECT p;
  58.     int wh;
  59.  
  60.     /* compute required size for window given object tree */
  61.  
  62.     form_center(tree,ELTR(clip));
  63.  
  64.     if (type == 0)
  65.     {
  66.         wind_calc(WC_BORDER, W_TYPE, PTRS((GRECT *)&clip),ELTR(p));
  67.     
  68.         wh = wind_create(W_TYPE, ELTS(p));
  69.     }
  70.     else if (type == 1)
  71.     {
  72.         wind_calc(WC_BORDER, W_T2, PTRS((GRECT *)&clip),ELTR(p));
  73.     
  74.         wh = wind_create(W_T2, ELTS(p));
  75.     }
  76.     else
  77.     {
  78.         wind_calc(WC_BORDER, W_T3, PTRS((GRECT *)&clip),ELTR(p));
  79.     
  80.         wh = wind_create(W_T3, ELTS(p));
  81.     }
  82.                 
  83.     if (wh >= 0) 
  84.     {
  85. #if OS_DOS
  86.         wind_set(wh, WF_NAME, LLOWD(title), LHIWD(title),0,0);
  87. #else
  88.         wind_set(wh, WF_NAME, title);
  89. #endif
  90.         wind_open(wh, ELTS(p));
  91.         
  92.     }
  93.     return wh;
  94. }
  95.  
  96. int
  97. redraw(int wh, GRECT *area) 
  98. {
  99.     /* wh = window handle from msg[3] */
  100.     /* area = pointer to redraw rect- */
  101.     /*   tangle in msg[4] thru msg[7] */
  102.  
  103.     GRECT    box;
  104.  
  105.     HIDE_MOUSE;
  106.  
  107.     wind_update(BEG_UPDATE);
  108.  
  109.     wind_get(wh, WF_FIRSTXYWH, ELTR(box));
  110.  
  111.     while ( box.g_w && box.g_h )
  112.     {
  113.         if (rc_intersect(&full, &box))       /* Full is entire screen */
  114.         {
  115.             if (rc_intersect(area, &box))
  116.             {
  117.                 switch(win[wh].status)
  118.                 {
  119.                     case 1:
  120.                         /* normal */
  121.                         objc_draw(win[wh].window_obj, ROOT, MAX_DEPTH, ELTS(box));
  122.                         break;
  123.                                         
  124.                     case 2:
  125.                         /* rolled up */
  126.                         objc_draw(win[wh].window_obj, ROOT, MAX_DEPTH, ELTS(box));
  127.                         break;
  128.                                         
  129.                     case 3:
  130.                         /* iconified */
  131.                         objc_draw(win[wh].icon_obj, ROOT, MAX_DEPTH, ELTS(box));
  132.                         break;
  133.                 }
  134.                }
  135.         }
  136.  
  137.         wind_get(wh, WF_NEXTXYWH, ELTR(box));
  138.     }
  139.  
  140.     wind_update(END_UPDATE);
  141.  
  142.     SHOW_MOUSE;
  143.     
  144.     return(1);
  145. }
  146.  
  147.  
  148. int
  149. do_wind_redraw(int wh, GRECT *p)
  150. {
  151.     GRECT new;
  152.     GRECT rect;
  153.      int cliparray[4];    /* MAR -- [] war leer */
  154.     int pxy[8];
  155.     int x,y;
  156.     GRECT temp;
  157.     int w_info;
  158.  
  159.     /* Suspend menu */
  160.  
  161.     wind_update(BEG_UPDATE);
  162.  
  163.     /* turn off mouse */
  164.  
  165.     HIDE_MOUSE;
  166.  
  167.     /* Reset the window objects area */
  168.  
  169.     wind_get(wh,WF_WORKXYWH,ELTR(new));
  170.     
  171.     w_info = get_wininfo_from_handle(wh);
  172.     
  173.     /* If the window doesn't have an object don't try to
  174.      * manipulate a NULL
  175.      */
  176.      
  177.     if (win[w_info].window_obj != (OBJECT *)NULL)
  178.     {
  179.         /* Don't reset if either width or height == 0 */
  180.     
  181.         if (new.g_w && new.g_h)
  182.         {
  183.             win[w_info].window_obj[ROOT].ob_x = new.g_x;
  184.             win[w_info].window_obj[ROOT].ob_y = new.g_y;
  185.             win[w_info].window_obj[ROOT].ob_width = new.g_w;
  186.             win[w_info].window_obj[ROOT].ob_height = new.g_h;
  187.         }
  188.     }
  189.  
  190.     /* Get the first rectangle off the windows list */
  191.  
  192.     wind_get(wh, WF_FIRSTXYWH, ELTR(rect));
  193.  
  194.     while (rect.g_w && rect.g_h) 
  195.     {
  196.         if( rc_intersect(p, &rect) )
  197.         {
  198.             /*cliparray[0]=rect.g_x; 
  199.             cliparray[1]=rect.g_y;
  200.             cliparray[2]=rect.g_x + rect.g_w - 1;
  201.             cliparray[3]=rect.g_y + rect.g_h - 1;
  202.  
  203.             vs_clip(vdi_handle, 1, cliparray);*/
  204.  
  205.             Vsync();
  206.  
  207.             switch (win[w_info].status)
  208.             {
  209.                 case 1:
  210.                     objc_draw(win[w_info].window_obj,ROOT,MAX_DEPTH, ELTS(rect));
  211.  
  212.                     if (w_info == OBJCOLOR_WIN)
  213.                     {
  214.                         cliparray[0]=rect.g_x; 
  215.                         cliparray[1]=rect.g_y;
  216.                         cliparray[2]=rect.g_x + rect.g_w - 1;
  217.                         cliparray[3]=rect.g_y + rect.g_h - 1;
  218.         
  219.                         vs_clip(vdi_handle, 1, cliparray);
  220.  
  221.                         redraw_objcolors();                    
  222.  
  223.                         vs_clip(vdi_handle, 0, cliparray);
  224.                     }
  225.                     else if (w_info == ABOUT_WIN)
  226.                     {
  227.                         objc_offset(about_dial,RTITLE,&x,&y);
  228.                         
  229.                         temp.g_x = x;
  230.                         temp.g_y = y;
  231.                         temp.g_w = tit_buf.fd_w;
  232.                         temp.g_h = tit_buf.fd_h;
  233.             
  234.                         /* The following test is here for MagicPC
  235.                          * if you draw the bottom of the screen with magicPC
  236.                          * it crashes
  237.                          */
  238.                         if ((temp.g_y+temp.g_h) > max.g_y)
  239.                             temp.g_h =max.g_y-temp.g_y;
  240.  
  241.                         if ((temp.g_x+temp.g_w) > max.g_x)
  242.                             temp.g_w = max.g_x - temp.g_x;
  243.  
  244.                         if (rc_intersect(&rect,&temp))
  245.                         {
  246.                             /* clip it to screen */
  247.                             /* Whole lot of manipulations going on here,
  248.                                 might not all be necessary.  However it's 
  249.                                 finally working so I'm going to be bad
  250.                                 and not touch it anymore right now */
  251.  
  252.                             pxy[0] = temp.g_x - x;
  253.                             pxy[1] = temp.g_y - y;
  254.                             pxy[2] = pxy[0] + temp.g_w - 1;
  255.                             pxy[3] = pxy[1] + temp.g_h - 1;
  256.                             pxy[4] = temp.g_x;
  257.                             pxy[5] = temp.g_y;
  258.                             pxy[6] = pxy[4] + temp.g_w - 1;
  259.                             pxy[7] = pxy[5] + temp.g_h - 1;
  260.  
  261.                             /* Keep messy AES's from drawing off the left side of the screen */
  262.                             if (pxy[4] < 0)
  263.                                 pxy[4] = 0;
  264.                                 
  265.                             vro_cpyfm(vdi_handle,S_ONLY,pxy,&tit_buf,&screen_fdb);
  266.                         }
  267.                     }
  268.                     break;
  269.                             
  270.                 case 3:
  271.                     objc_draw(win[w_info].icon_obj, ROOT, MAX_DEPTH, ELTS(rect));
  272.                     break;
  273.             }
  274.                         
  275.             if((win[w_info].cur_item != -1)&&(win[w_info].edit == 1))
  276.             {
  277.                 objc_edit(win[w_info].window_obj,win[w_info].cur_item,0,win[w_info].edit_pos,ED_INIT,&win[w_info].edit_pos);
  278.                 win[w_info].edit = 0;
  279.             }
  280.  
  281. /*            vs_clip(vdi_handle, 0, cliparray);*/
  282.         }
  283.  
  284.         wind_get(wh, WF_NEXTXYWH, ELTR(rect));
  285.     }
  286.  
  287.     /* show mouse */
  288.  
  289.     SHOW_MOUSE;
  290.  
  291.     wind_update(END_UPDATE);
  292.  
  293.     return 1;
  294. }
  295.  
  296. int
  297. custom_redraw(int wh, GRECT *p)
  298. {
  299.     int current_obj = 0;
  300.     GRECT new;
  301.     
  302.     /* Suspend menu */
  303.  
  304.     /*wind_update(BEG_UPDATE);*/
  305.  
  306.     /* turn off mouse */
  307.  
  308.     HIDE_MOUSE;
  309.  
  310.     /* Reset the window objects area */
  311.  
  312.     wind_get(wh,WF_WORKXYWH,ELTR(new));
  313.  
  314.     win[wh].window_obj[ROOT].ob_x = new.g_x;
  315.     win[wh].window_obj[ROOT].ob_y = new.g_y;
  316.  
  317.     if (rc_intersect(p, &new))
  318.     {
  319.         current_obj = objc_find(win[wh].window_obj,ROOT,MAX_DEPTH,new.g_x,new.g_y);
  320.  
  321.         objc_draw(win[wh].window_obj,current_obj,MAX_DEPTH, ELTS(new));
  322.     }
  323.  
  324.     /* show mouse */
  325.  
  326.     SHOW_MOUSE;
  327.  
  328.     /*wind_update(END_UPDATE);*/
  329.  
  330.     return 1;
  331. }
  332.  
  333. /* A routine for getting the top window simply for tests */
  334. int
  335. get_topwindow(int window)
  336. {
  337.     int top_window;
  338.     int junk;
  339.     
  340.     wind_get(window,WF_TOP,&top_window,&junk,&junk,&junk);
  341.     
  342.     return(top_window);
  343. }
  344.