home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 3 / FREEWARE.BIN / towns_os / whisper / source / event.c < prev    next >
Text File  |  1980-01-02  |  7KB  |  329 lines

  1. /*
  2.     マウス イベント処理ライブラリ
  3.  
  4.     1990.9.11    Make By ken
  5. */
  6. #include    <stdio.h>
  7. #include    <stdlib.h>
  8. #include    <string.h>
  9. #include    <egb.h>
  10. #include    <mos.h>
  11. #include    <msdos.cf>
  12. #include    "graphic.h"
  13. #include    "event.h"
  14. #include    "coldef.h"
  15.  
  16. #define    TRUE    1
  17. #define    FALSE    0
  18. #define    ERR    (-1)
  19.  
  20. #define    MAX_EVENT    256
  21.  
  22. void    CHK_snd(void);
  23. void    CHK_eup(void);
  24.  
  25. extern char     work[];
  26.  
  27. static int    evt_max=0;
  28. static int    evt_free=ERR;
  29. static int    last_node=ERR;
  30. static EVENT    evt_node[MAX_EVENT];
  31. static BLOCK    *clip_save=NULL;
  32.  
  33. int    EVT_get_node(void)
  34. {
  35.     int     no;
  36.  
  37.     if ( (no = evt_free) != ERR )
  38.     evt_free = evt_node[evt_free].level;
  39.     else if ( evt_max >= MAX_EVENT )
  40.     return ERR;
  41.     else
  42.     no = evt_max++;
  43.  
  44.     return no;
  45. }
  46. void    EVT_free_node(int no)
  47. {
  48.     evt_node[no].flg = FALSE;
  49.     evt_node[no].level = evt_free;
  50.     evt_free = no;
  51.     if ( no == last_node )
  52.     last_node = ERR;
  53. }
  54. void    EVT_level_free(int level)
  55. {
  56.     int     i;
  57.     register EVENT *ep;
  58.  
  59.     for ( i = 0 ; i < MAX_EVENT ; i++ ) {
  60.     ep = &(evt_node[i]);    
  61.     if ( ep->flg != FALSE && ep->level == level )
  62.         EVT_free_node(i);
  63.     }
  64. }
  65. EVENT    *EVT_set_node(int x1,int y1,int x2,int y2,
  66.             int level,void (*proc)(),int no)
  67. {
  68.     int     nodo;
  69.     register EVENT *ep;
  70.  
  71.     if ( (nodo = EVT_get_node()) == ERR )
  72.     return NULL;
  73.  
  74.     ep = &(evt_node[nodo]);
  75.     ep->flg = TRUE;
  76.     ep->level = level;
  77.     ep->now = 0;
  78.     ep->no = no;
  79.     ep->x1 = x1;
  80.     ep->y1 = y1;
  81.     ep->x2 = x2;
  82.     ep->y2 = y2;
  83.     ep->proc = proc;
  84.  
  85.     return ep;
  86. }
  87. int    EVT_chk(register EVENT *ep,int x,int y,int sw)
  88. {
  89.     int     fg;
  90.  
  91.     fg = (x >= ep->x1 && x <= ep->x2 && 
  92.       y >= ep->y1 && y <= ep->y2 ) ? TRUE:FALSE;
  93.  
  94.     switch(ep->now) {
  95.     case EVT_OFF_MOS:
  96.     case EVT_MOVE_MOS:
  97.     case EVT_DLSEL_MOS:
  98.     case EVT_SELECT_MOS:
  99.     ep->now = EVT_NON;
  100.     break;
  101.  
  102.     case EVT_NON:
  103.     if ( fg != FALSE ) {
  104.         ep->now = (sw != 0 ? EVT_CLIP_MOS:EVT_ON_MOS);
  105.         (*ep->proc)(ep,x,y,sw);
  106.     }
  107.     break;
  108.  
  109.     case EVT_ON_MOS:
  110.     if ( fg != FALSE ) {
  111.         if ( sw != 0 ) {
  112.             ep->now = EVT_CLIP_MOS;
  113.             (*ep->proc)(ep,x,y,sw);
  114.         }
  115.     } else {
  116.         ep->now = EVT_OFF_MOS;
  117.         (*ep->proc)(ep,x,y,sw);
  118.     }
  119.     break;
  120.  
  121.     case EVT_CLIP_MOS:
  122.     if ( fg != FALSE ) {
  123.         if ( sw == 0 ) {
  124.             ep->now = EVT_SELECT_MOS;
  125.             (*ep->proc)(ep,x,y,sw);
  126.         }
  127.     } else {
  128.         ep->now = (sw != 0 ? EVT_DOLACK_MOS : EVT_MOVE_MOS);
  129.         (*ep->proc)(ep,x,y,sw);
  130.     }
  131.     break;
  132.  
  133.     case EVT_DOLACK_MOS:
  134.     if ( sw == FALSE )
  135.         ep->now = EVT_DLSEL_MOS;
  136.     (*ep->proc)(ep,x,y,sw);
  137.     break;
  138.  
  139.     case EVT_REP_MOS:
  140.     if ( fg != FALSE ) {
  141.         if ( sw == 0 ) {
  142.             ep->now = EVT_SELECT_MOS;
  143.             (*ep->proc)(ep,x,y,sw);
  144.         } else
  145.             (*ep->proc)(ep,x,y,sw);
  146.     } else {
  147.         ep->now = (sw != 0 ? EVT_DOLACK_MOS : EVT_MOVE_MOS);
  148.         (*ep->proc)(ep,x,y,sw);
  149.     }
  150.     break;
  151.     }
  152.  
  153.     return ep->now;
  154. }
  155. void    EVT_loop(int level)
  156. {
  157.     int     i,x,y,sw;
  158.     register EVENT *ep;
  159.  
  160.     CHK_snd();
  161.     CHK_eup();
  162.  
  163.     MOS_rdpos(&sw,&x,&y);
  164.  
  165.     if ( last_node != ERR ) {
  166.     ep = &evt_node[last_node];    
  167.     if ( ep->flg != FALSE && ep->level >= level &&
  168.         EVT_chk(ep,x,y,sw) != EVT_NON )
  169.         return;
  170.     }
  171.  
  172.     last_node = ERR;
  173.  
  174.     for ( i = 0 ; i < MAX_EVENT ; i++ ) {
  175.     ep = &(evt_node[i]);    
  176.     if ( ep->flg != FALSE && ep->level >= level && 
  177.         EVT_chk(ep,x,y,sw) != EVT_NON ) {
  178.         last_node = i;
  179.         return;
  180.     }
  181.     }
  182. }
  183. void    EVT_sw(int x1,int y1,char *str,
  184.         int chrcol,int boxcol,
  185.         int level,void (*proc)(),int no)
  186. {
  187.     int     x2,y2;
  188.  
  189.     x2 = x1+strlen(str)*8+4;
  190.     y2 = y1+11;
  191.  
  192.     DSP_box(x1,y1,x2,y2,COL_LINE,boxcol);
  193.  
  194.     wrtstr(str,
  195.        page_ofs,(x1+2)/2 + (y1+2) * 512,
  196.        col_cnv[chrcol],col_cnv[boxcol],8);
  197.  
  198.     EVT_set_node(x1,y1,x2,y2,level,proc,no);
  199. }
  200. void    EVT_big_sw(int x1,int y1,char *str,
  201.         int chrcol,int boxcol,
  202.         int level,void (*proc)(),int no)
  203. {
  204.     int     x2,y2;
  205.  
  206.     x2 = x1+strlen(str)*8+4;
  207.     y2 = y1+17;
  208.  
  209.     DSP_box(x1,y1,x2,y2,COL_LINE,boxcol);
  210.  
  211.     wrtstr(str,
  212.        page_ofs,(x1+2)/2 + (y1+1) * 512,
  213.        col_cnv[chrcol],col_cnv[boxcol],16);
  214.  
  215.     EVT_set_node(x1,y1,x2,y2,level,proc,no);
  216. }
  217. void    EVT_clip_on(register EVENT *ep)
  218. {
  219.     struct {
  220.     char        *ptn;
  221.     short int   sel;
  222.     short int   x1,y1;
  223.     short int   x2,y2;
  224.     } para;
  225.     struct {
  226.     short int    count;
  227.     short int    x1,y1,x2,y2,x3,y3;
  228.     } connect;
  229.     int     n;
  230.     char    *ptn;
  231.  
  232.     n = ((ep->x2 - ep->x1) / 2 + 1) * (ep->y2 - ep->y1 + 1);
  233.  
  234.     if ( (ptn = (char *)malloc(n)) == NULL )
  235.     return;
  236.  
  237.     MOS_disp(FALSE);
  238.  
  239.     clip_save = DSP_push_vram(ep->x1,ep->y1,ep->x2,ep->y2);
  240.  
  241.     para.ptn = ptn;
  242.     para.sel = getds();
  243.     para.x1 = ep->x1;
  244.     para.y1 = ep->y1;
  245.     para.x2 = ep->x2-1;
  246.     para.y2 = ep->y2-1;
  247.     EGB_getBlock(work,(char *)¶);
  248.  
  249.     para.ptn = ptn;
  250.     para.sel = getds();
  251.     para.x1 = ep->x1+1;
  252.     para.y1 = ep->y1+1;
  253.     para.x2 = ep->x2;
  254.     para.y2 = ep->y2;
  255.     EGB_putBlock(work,0,(char *)¶);
  256.  
  257.     connect.count = 3;
  258.     connect.x1 = ep->x1;
  259.     connect.y1 = ep->y2;
  260.     connect.x2 = ep->x1;
  261.     connect.y2 = ep->y1;
  262.     connect.x3 = ep->x2;
  263.     connect.y3 = ep->y1;
  264.     EGB_color(work,0,0);
  265.     EGB_connect(work,(char *)&connect);
  266.  
  267.     MOS_disp(TRUE);
  268.  
  269.     free(ptn);
  270. }
  271. void    EVT_clip_off(register EVENT *ep)
  272. {
  273.     MOS_disp(FALSE);
  274.     DSP_pop_vram(clip_save);
  275.     clip_save = NULL;
  276.     MOS_disp(TRUE);
  277. /***************************************
  278.     struct {
  279.     char        *ptn;
  280.     short int   sel;
  281.     short int   x1,y1;
  282.     short int   x2,y2;
  283.     } para;
  284.     struct {
  285.     short int    count;
  286.     short int    x1,y1,x2,y2,x3,y3;
  287.     } connect;
  288.     int     n;
  289.     char    *ptn;
  290.  
  291.     n = ((ep->x2 - ep->x1) / 2 + 1) * (ep->y2 - ep->y1 + 1);
  292.  
  293.     if ( (ptn = (char *)malloc(n)) == NULL )
  294.     return;
  295.  
  296.     MOS_disp(FALSE);
  297.  
  298.     para.ptn = ptn;
  299.     para.sel = getds();
  300.     para.x1 = ep->x1+1;
  301.     para.y1 = ep->y1+1;
  302.     para.x2 = ep->x2;
  303.     para.y2 = ep->y2;
  304.     EGB_getBlock(work,(char *)¶);
  305.  
  306.     para.ptn = ptn;
  307.     para.sel = getds();
  308.     para.x1 = ep->x1;
  309.     para.y1 = ep->y1;
  310.     para.x2 = ep->x2-1;
  311.     para.y2 = ep->y2-1;
  312.     EGB_putBlock(work,0,(char *)¶);
  313.  
  314.     connect.count = 3;
  315.     connect.x1 = ep->x1;
  316.     connect.y1 = ep->y2;
  317.     connect.x2 = ep->x2;
  318.     connect.y2 = ep->y2;
  319.     connect.x3 = ep->x2;
  320.     connect.y3 = ep->y1;
  321.     EGB_color(work,0,8);
  322.     EGB_connect(work,(char *)&connect);
  323.  
  324.     MOS_disp(TRUE);
  325.  
  326.     free(ptn);
  327. **********************************************/
  328. }
  329.