home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1997 March / VPR9703A.ISO / VPR_DATA / DOGA / SOURCES / POLYEDIT.LZH / MODEL / EVENT.C < prev    next >
C/C++ Source or Header  |  1996-06-05  |  3KB  |  160 lines

  1. /*
  2.  *    イベント制御
  3.  *
  4.  *        Copyright T.Kobayashi    1994.6.26
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <assert.h>
  11.  
  12. #include "event.h"
  13. #include "view.h"
  14.  
  15. #include "graph.h"
  16. #include "input.h"
  17.  
  18. #include "ml.h"
  19.  
  20. extern    int        QuitFlag;
  21.  
  22. static    int        EventKeyIdent[0x80] ;
  23. static    int        EventSpcKeyIdent[KEY_FUNC_END - KEY_FUNC_START] ;
  24. static    int        EventInput ;
  25.  
  26. /*    イベント初期化    */
  27. void    EventInit()
  28. {
  29.     int        i ;
  30.  
  31.     EventInput = -1 ;
  32.  
  33.     for( i = 0 ; i < 0x80 ; i++ )
  34.         EventKeyIdent[i] = -1 ;
  35.  
  36.     for( i = 0 ; i < (KEY_FUNC_END - KEY_FUNC_START) ;i++ )
  37.         EventSpcKeyIdent[i] = -1 ;
  38. }
  39.  
  40.  
  41. /*    マウス、キー入力待ち    */
  42. void    WaitMouseOrKey()
  43. {
  44. #if    0
  45.     int        col ;
  46.     static    int        selectcol ;
  47.     selectcol = ( selectcol + 1 ) & 0xFFFF ;
  48.     col = ( selectcol >> 3 ) & 511 ;
  49.     if ( col >= 256 )
  50.         col = 511 - col ;
  51.     graph_palet( SELECT_COLOR, 255, 255-col, col );
  52. #endif
  53.  
  54.     WaitInput();
  55. }
  56.  
  57. /*    イベント設定    */
  58. void    EventSetKey( ident, key )
  59. int        ident ;
  60. char    *key ;
  61. {
  62.     int        code ;
  63.  
  64.     while( *key != '\0' )
  65.     {
  66.         if ( *key == 'F' )
  67.         {
  68.             code = 0 ;
  69.             key++ ;
  70.             while( isdigit( *key ) )
  71.             {
  72.                 code = code * 10 + *key - '0';
  73.                 key++ ;
  74.             }
  75.             if ( 0 <= code && code <= (KEY_FUNC_END - KEY_FUNC_START) )
  76.                 EventSpcKeyIdent[code] = ident ;
  77.         }
  78.         else
  79.         {
  80.             code = *key & 0x7F ;
  81.             EventKeyIdent[code] = ident ;
  82.             key++ ;
  83.         }
  84.     }
  85. }
  86.  
  87. /*    入力イベント設定    */
  88. void    EventSetInput( ident )
  89. int        ident ;
  90. {
  91.     EventInput = ident ;
  92. }
  93.  
  94.  
  95. /*    キーイベント呼び出し    */
  96. int CallKeyEvent()
  97. {
  98.     int        code, ident ;
  99.     DataStruct    *mark ;
  100.  
  101.     if ( KeyCode & 0x8000 )
  102.     {
  103.         assert( ( KeyCode & 0xff ) < (KEY_FUNC_END - KEY_FUNC_START) );
  104.         code = KeyCode ;
  105.         ident = EventSpcKeyIdent[code&0xFF] ;
  106.     }
  107.     else
  108.     {
  109.         code = KeyCode & 0x7F ;
  110.         ident = EventKeyIdent[code] ;
  111.     }
  112.  
  113.     if ( ident >= 0 )
  114.     {
  115.         mark = StackTop();
  116.         StackPushInt( code );
  117.         StackPushInt( ShiftStat );
  118.  
  119.         CallFunction( ident, 2, mark+1 );
  120.         StackRelease( mark );
  121.         return TRUE;
  122.     }
  123.     return FALSE;
  124. }
  125.  
  126. /*    入力イベント呼び出し    */
  127. void    CallInputEvent()
  128. {
  129.     DataStruct    *mark ;
  130.  
  131.     if ( EventInput >= 0 )
  132.     {
  133.         mark = StackTop();
  134.         StackPushInt( ShiftStat );
  135.         CallFunction( EventInput, 1, mark+1 );
  136.         StackRelease( mark );
  137.     }
  138. }
  139.  
  140. /*    マウスボタンが離されるまで待つ    */
  141. void    WaitMouseOff()
  142. {
  143. #if 0
  144.     do
  145.     {
  146.         WaitInput();
  147.         if (QuitFlag) {
  148.             return;
  149.         }
  150.     } while( MouseLeft || MouseRight );
  151. #else
  152.     while( MouseLeft || MouseRight ) {
  153.         if (QuitFlag) {
  154.             return;
  155.         }
  156.         WaitInput();
  157.     }
  158. #endif
  159. }
  160.