home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 1 / ARM_CLUB_CD.iso / contents / apps / clib / progs / haswinlib / c / windowopen < prev    next >
Encoding:
Text File  |  1991-02-04  |  8.3 KB  |  235 lines

  1. /* > $.CLIB.C.windowopen
  2.  *
  3.  *      HASWIN Graphics Library
  4.  *     =========================
  5.  *
  6.  *      Copyright (C) H.A.Shaw 1990.
  7.  *              Howard A. Shaw.
  8.  *              The Unit for Space Sciences,
  9.  *              Room 165,
  10.  *              Physics Building,
  11.  *              University of Kent at Canterbury.
  12.  *              Canterbury.
  13.  *              Kent.  CT2 7NJ
  14.  *      You may use and distribute this code freely, however please leave
  15.  *      it alone.  If you find bugs (and there will be many) please contact
  16.  *      me and the master source can be modified.  If you keep me informed
  17.  *      of who you give copies of this to then I can get release upgrades
  18.  *      to them.
  19.  *
  20.  *      window routines.  This is mainly open and close routines.  For
  21.  *      drawing see "pollwind" and for others see "window'
  22.  */
  23. #include "includes.h"
  24.  
  25. static void _haswin_closewindow(window *wptr) {
  26.  
  27.         _kernel_swi_regs  regs;
  28.         buffer   buff;
  29.  
  30.         if ((int)wptr <=0 )
  31.                 return;
  32.         buff.i[0] = wptr->handle;
  33.         regs.r[1] = (int)&buff;
  34.         if (!haswin_swi(HASWIN_Close_window, ®s))
  35.                 return;
  36.         if (haswin_inactivelist(wptr->handle))
  37.                 haswin_removeactivelist(wptr->handle);
  38.         if (wptr->win)
  39.                 ((int *)wptr->win)[7] &= ~WINDOW_OPEN;
  40.         if (wptr->flags & WINDOW_TEMP)
  41.                 haswin_deletewindow(wptr);
  42. }
  43.  
  44. void haswin_closewindow(window *wptr) {
  45.  
  46.         window  *wptr1;
  47.  
  48.         if ((int)wptr <= 0)
  49.                 return;
  50.         for (wptr1=wptr; wptr1->pane; wptr1=wptr1->pane)
  51.                 _haswin_closewindow(wptr1->pane);
  52.         for (wptr1=wptr; wptr1->slide; wptr1=wptr1->slide)
  53.                 _haswin_closewindow(wptr1->slide);
  54.         _haswin_closewindow(wptr);
  55. }
  56.  
  57. static int _openwindow1(int dir, window *wptr, int xadj, int yadj, int bhandle) {
  58.  
  59.         _kernel_swi_regs  regs;
  60.         buffer            buff;
  61.  
  62.         if (wptr == 0)
  63.                 return(HASWIN_TRUE);
  64.         if ((int)wptr < 0)
  65.                 return(HASWIN_FALSE);
  66.         buff.i[0] = wptr->handle;
  67.         regs.r[1] = (int)&buff;
  68.         haswin_swi(HASWIN_Get_window_state, ®s);
  69.         regs.r[1] = (int)&buff;
  70.         buff.i[1] += xadj;
  71.         buff.i[2] += yadj;
  72.         buff.i[3] += xadj;
  73.         buff.i[4] += yadj;
  74.         buff.i[7] = bhandle;
  75.         if ((*wptr->openroutine) && (!((*wptr->openroutine)(wptr, &buff))))
  76.                 return(HASWIN_FALSE);
  77.         if (dir) {
  78.                 if (!_openwindow1(dir, wptr->pane, xadj, yadj, bhandle))
  79.                         return(HASWIN_FALSE);
  80.                 haswin_swi(HASWIN_Open_window, ®s);
  81.                 haswin_updatewindowinfo(wptr);
  82.         } else {
  83.                 haswin_swi(HASWIN_Open_window, ®s);
  84.                 haswin_updatewindowinfo(wptr);
  85.                 if (!_openwindow1(dir, wptr->pane, xadj, yadj, bhandle))
  86.                         return(HASWIN_FALSE);
  87.         }
  88.         return(HASWIN_TRUE);
  89. }
  90.  
  91. static int _openwindow2(int dir, window *wptr, int xadj, int yadj,
  92.                   double sxadj, double syadj, int bhandle) {
  93.  
  94.         _kernel_swi_regs  regs;
  95.         buffer            buff;
  96.  
  97.         if (wptr == 0)
  98.                 return(HASWIN_TRUE);
  99.         if ((int)wptr < 0)
  100.                 return(HASWIN_FALSE);
  101.         buff.i[0] = wptr->handle;
  102.         regs.r[1] = (int)&buff;
  103.         haswin_swi(HASWIN_Get_window_state, ®s);
  104.         regs.r[1] = (int)&buff;
  105.         buff.i[1] += xadj;
  106.         buff.i[2] += yadj;
  107.         buff.i[3] += xadj;
  108.         buff.i[4] += yadj;
  109.         buff.i[5] = (int)(sxadj*(double)(((int *)wptr->win)[12]-((int *)wptr->win)[10]))+((int *)wptr->win)[10];
  110.         buff.i[6] = (int)(syadj*(double)(((int *)wptr->win)[11]-((int *)wptr->win)[13]))+((int *)wptr->win)[13];
  111.         buff.i[7] = bhandle;
  112.         if ((*wptr->openroutine) && (!((*wptr->openroutine)(wptr, &buff))))
  113.                 return(HASWIN_FALSE);
  114.         if (dir) {
  115.                 if (!_openwindow2(dir, wptr->slide, xadj, yadj, sxadj, syadj,
  116.                         bhandle))
  117.                         return(HASWIN_FALSE);
  118.                 haswin_swi(HASWIN_Open_window, ®s);
  119.                 haswin_updatewindowinfo(wptr);
  120.         } else {
  121.                 haswin_swi(HASWIN_Open_window, ®s);
  122.                 haswin_updatewindowinfo(wptr);
  123.                 if (!_openwindow2(dir, wptr->slide, xadj, yadj, sxadj, syadj,
  124.                         bhandle))
  125.                         return(HASWIN_FALSE);
  126.         }
  127.         return(HASWIN_TRUE);
  128. }
  129.  
  130. int haswin_openwindow(window *wptr, int x0, int y0, int x1, int y1, int scx, int scy, int bhandle) {
  131.  
  132.         int                     xadj, yadj;
  133.         double                  sxadj, syadj;
  134.         _kernel_swi_regs        regs;
  135.         buffer                  buff;
  136.  
  137.         if ((int)wptr <= 0)
  138.                 return(HASWIN_FALSE);
  139.  
  140.         buff.i[0] = wptr->handle;
  141.         regs.r[1] = (int)&buff;
  142.         haswin_swi(HASWIN_Get_window_state, ®s);
  143.         xadj = x0 - buff.i[1];
  144.         yadj = y1 - buff.i[4];
  145.         sxadj = (double)(scx-((int *)wptr->win)[10])/(double)(((int *)wptr->win)[12]-((int *)wptr->win)[10]);
  146.         syadj = (double)(scy-((int *)wptr->win)[13])/(double)(((int *)wptr->win)[11]-((int *)wptr->win)[13]);
  147.         buff.i[0] = wptr->handle;
  148.         buff.i[1] = x0;
  149.         buff.i[2] = y0;
  150.         buff.i[3] = x1;
  151.         buff.i[4] = y1;
  152.         buff.i[5] = scx;
  153.         buff.i[6] = scy;
  154.         buff.i[7] = bhandle;
  155.         regs.r[1] = (int)&buff;
  156.         if ((*wptr->openroutine) && (!((*wptr->openroutine)(wptr, &buff))))
  157.                 return(HASWIN_FALSE);
  158.         if (bhandle != -2) {
  159.                 /* if window is not to be opened at bottom then do panes and
  160.                    slides afterwards */
  161.                 haswin_swi(HASWIN_Open_window, ®s);
  162.                 haswin_updatewindowinfo(wptr);
  163.                 if (!_openwindow1(0, wptr->pane, xadj, yadj, bhandle))
  164.                         return(HASWIN_FALSE);
  165.                 if (!_openwindow2(0, wptr->slide, xadj, yadj, sxadj, syadj, bhandle))
  166.                         return(HASWIN_FALSE);
  167.         } else {
  168.                 if (!_openwindow1(1, wptr->pane, xadj, yadj, bhandle))
  169.                         return(HASWIN_FALSE);
  170.                 if (!_openwindow2(1, wptr->slide, xadj, yadj, sxadj, syadj, bhandle))
  171.                         return(HASWIN_FALSE);
  172.                 haswin_swi(HASWIN_Open_window, ®s);
  173.                 haswin_updatewindowinfo(wptr);
  174.         }
  175.         return(HASWIN_TRUE);
  176. }
  177.  
  178. int haswin_reopenwindow(window *wptr) {
  179.  
  180.         _kernel_swi_regs        regs;
  181.         buffer                  buff;
  182.  
  183.         if ((int)wptr <= 0)
  184.                 return(HASWIN_FALSE);
  185.         buff.i[0] = wptr->handle;
  186.         regs.r[1] = (int)&buff;
  187.         haswin_swi(HASWIN_Get_window_state, ®s);
  188.         if ((*wptr->openroutine) && (!((*wptr->openroutine)(wptr, &buff))))
  189.                 return(HASWIN_FALSE);
  190.  
  191.         if (buff.i[7] != -2) {
  192.                 /* if window is not to be opened at bottom then do panes and
  193.                    slides afterwards */
  194.                 haswin_swi(HASWIN_Open_window, ®s);
  195.                 haswin_updatewindowinfo(wptr);
  196.                 if (!_openwindow1(0, wptr->pane, 0, 0, buff.i[7]))
  197.                         return(HASWIN_FALSE);
  198.                 if (!_openwindow2(0, wptr->slide, 0, 0, 0.0, 0.0, buff.i[7]))
  199.                         return(HASWIN_FALSE);
  200.         } else {
  201.                 if (!_openwindow1(1, wptr->pane, 0, 0, buff.i[7]))
  202.                         return(HASWIN_FALSE);
  203.                 if (!_openwindow2(1, wptr->slide, 0, 0, 0.0, 0.0, buff.i[7]))
  204.                         return(HASWIN_FALSE);
  205.                 haswin_swi(HASWIN_Open_window, ®s);
  206.                 haswin_updatewindowinfo(wptr);
  207.         }
  208.         return(HASWIN_TRUE);
  209. }
  210.  
  211. int haswin_forceredraw(window *win, int x0, int x1, int y0, int y1) {
  212.  
  213.         _kernel_swi_regs  regs;
  214.  
  215.         if (!win)
  216.                 regs.r[0] = -1;
  217.         else
  218.                 regs.r[0] = win->handle;
  219.         if (x0 || x1 || y0 || y1) {
  220.                 regs.r[1] = x0;
  221.                 regs.r[2] = y0;
  222.                 regs.r[3] = x1;
  223.                 regs.r[4] = y1;
  224.         } else if ((win) && (win->win)) {
  225.                 haswin_updatewindowinfo(win);
  226.                 regs.r[1] = win->win[0];
  227.                 regs.r[2] = win->win[1];
  228.                 regs.r[3] = win->win[2];
  229.                 regs.r[4] = win->win[3];
  230.         }
  231.         haswin_swi(HASWIN_Force_redraw, ®s);
  232.         return(HASWIN_TRUE);
  233. }
  234.  
  235.