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

  1. /*
  2.  *    メインルーチン
  3.  *
  4.  *        1996.1.6        T.Kobayashi
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include <ctype.h>
  11. #include <setjmp.h>
  12. #include <assert.h>
  13.  
  14. #include "lib.h"
  15. #include "matrix.h"
  16. #include "reader.h"
  17. #include "matclass.h"
  18. #include "ml.h"
  19.  
  20. #include "view.h"
  21. #include "event.h"
  22. #include "model.h"
  23.  
  24. #include "graph.h"
  25. #include "input.h"
  26.  
  27. int        QuitFlag ;
  28. int        InputKey, CursorMoveKey ;
  29. int        Argc ;
  30. char    **Argv ;
  31.  
  32. static    int            mainloop = FALSE ;
  33. static    jmp_buf        env ;
  34. static    DataStruct *stacktop = NULL;
  35.  
  36. #ifndef WINDOWS
  37. void    main( argc, argv )
  38. int        argc ;
  39. char    *argv[] ;
  40. #else
  41. void    ModelMain( int argc, char **argv )
  42. #endif
  43. {
  44.     int ident;
  45.  
  46.     Argc = argc ;
  47.     Argv = argv ;
  48.  
  49.     mainloop = FALSE ;
  50.     InputKey = LEFT_SWITCH ;
  51.     CursorMoveKey = RIGHT_SWITCH ;
  52.  
  53.     ModelInit();
  54.  
  55. #ifndef WINDOWS
  56.     ViewFrame();
  57.     ViewLineAll( 0, 0, DISPLAY_X, DISPLAY_Y, TRUE );
  58.     DrawTitleBar();
  59.     DrawUserButtonAll();
  60.     DrawControlPanel();
  61. #endif
  62.  
  63.     MessageSet( InternalError, Message );
  64.     QuitFlag = FALSE ;
  65.     ExecSentenseAll();
  66.  
  67.     ViewCursor( ON );
  68.     mainloop = TRUE ;
  69.  
  70.     stacktop = StackTop();
  71.     if ( (ident = IdentSearch( IdentFunction, "main" ) ) >= 0 ) {
  72.         setjmp(env);
  73.         if (!QuitFlag) {
  74.             StackRelease( stacktop );
  75.             CallFunction( ident, 0, stacktop );
  76.         }
  77.     } else {
  78.         for(;;)
  79.         {
  80.             if ( QuitFlag )
  81.                 break ;
  82.             if ( setjmp( env ) == 0 )
  83.             {
  84.                 StackRelease( stacktop );
  85.                 if ( WaitEvent() )
  86.                     CallInputEvent();
  87.                 else if ( KeyCode != 0 )
  88.                     CallKeyEvent();
  89.             }
  90.         }
  91.     }
  92.     ViewCursor( OFF );
  93.  
  94.     ModelExit();
  95.     exit( 0 );
  96. }
  97.  
  98. /*    再表示    */
  99. void    RedrawAll()
  100. {
  101. /*    ViewCursor( OFF );*/
  102.     ViewFrame();
  103.     ViewLineAll( 0, 0, DISPLAY_X, DISPLAY_Y, TRUE );
  104.     DrawTitleBar();
  105.     DrawUserButtonAll();
  106.     DrawControlPanel();
  107. /*    ViewCursor( ON );*/
  108. }
  109.  
  110. /*    イベント待ち    */
  111. int        WaitEvent()
  112. {
  113.     int mleft, mright;
  114.     mleft = MouseLeft;
  115.     mright = MouseRight;
  116.     WaitMouseOrKey();
  117.     if (QuitFlag) {
  118.         longjmp( env, 1 );
  119.     }
  120. #ifdef WINDOWS
  121.     if (KEY_MENU_START <= KeyCode && KeyCode < KEY_MENU_START + KEY_MENU_STEP * MAX_MENU) {
  122.         int x, y;
  123.         x = (KeyCode - KEY_MENU_START)/KEY_MENU_STEP;
  124.         y = (KeyCode - KEY_MENU_START)%KEY_MENU_STEP;
  125.         ExecMenu(x, y);
  126.         KeyCode = 0;
  127.         return FALSE;
  128.     }
  129. #endif
  130.     if (MouseLeft || MouseRight ) {
  131. #ifndef WINDOWS
  132.         if (MouseY <= MENU_WIDTH) {
  133.             CallMenu( MouseX, MouseY );
  134.             return FALSE ;
  135.         }
  136. #endif
  137.         if (MouseY >= DISPLAY_Y-STATUS_WIDTH) {
  138.             WaitMouseOff();
  139.             return FALSE ;
  140.         }
  141.         if (MouseX >= DISPLAY_X - CTRL_WIDTH )
  142.         {
  143.             ControlSelect( MouseX, MouseY );
  144.             return FALSE ;
  145.         }
  146.         if (MouseX >= DISPLAY_X - CTRL_WIDTH - ButtonAreaWidth) {
  147.             CallButton( MouseX, MouseY );
  148.             return FALSE;
  149.         }
  150.         if (ScrollCheck(MouseX, MouseY)) {
  151. #if 0
  152.             ViewCursorPos( MouseX, MouseY);
  153. #else
  154. #ifdef WINDOWS
  155.             extern unsigned long WinGetTimer(void);
  156.             unsigned long lasttime = WinGetTimer();
  157.             while ((MouseRight || MouseLeft) && ScrollCheck(MouseX,MouseY)
  158.                 && !QuitFlag) {
  159.                 ViewCursorPos( MouseX, MouseY);
  160.  
  161.                 do {
  162.                     PeekInput();
  163.                 } while (lasttime + 66 > WinGetTimer()
  164.                     && !QuitFlag && (MouseRight || MouseLeft));
  165.                 lasttime = WinGetTimer();
  166.             }
  167. #else
  168.             while ((MouseRight || MouseLeft) && ScrollCheck(MouseX,MouseY)
  169.                  && !QuitFlag) {
  170.                 ViewCursorPos( MouseX, MouseY);
  171.                 PeekInput();
  172.             }
  173. #endif
  174. #endif
  175.             return FALSE;
  176.         }
  177.     }
  178.     if ( ( ( CursorMoveKey & 1 ) && MouseLeft ) || ( ( CursorMoveKey & 2 ) && MouseRight ) )
  179.     {
  180.         ViewCursorPos( MouseX, MouseY );
  181.         DrawCursorPos();
  182.     }
  183.  
  184.     if ( InputKey == ' ' ) {
  185.         return KeyCode == ' ' ;
  186.     }
  187.     if ( InputKey == LEFT_SWITCH && (MouseLeft || (mleft && !MouseLeft)) )
  188.     {
  189.         WaitMouseOff();
  190.         return TRUE ;
  191.     }
  192.     if ( InputKey == RIGHT_SWITCH && (MouseRight || (mright && !MouseRight)) )
  193.     {
  194.         WaitMouseOff();
  195.         return TRUE ;
  196.     }
  197.  
  198.     return FALSE ;
  199. }
  200.  
  201. /*    エラー処理ルーチン    */
  202. void    InternalError( msg )
  203. char    *msg ;
  204. {
  205.     Bell();
  206.     Message( msg );
  207.     if ( mainloop )
  208.     {
  209.         while( MenuStackPtr > 0 )
  210.             PopMenu();
  211.         DrawTitleBar();
  212.         longjmp( env, 1 );
  213.     }
  214.     else
  215.     {
  216.         ModelExit();
  217.         exit( 1 );
  218.     }
  219. }
  220.  
  221. /*    メッセージ表示    */
  222. void    Message( msg )
  223. char    *msg ;
  224. {
  225.     static char    str[1024];
  226.     static char *button_ok[2] = {"確認", NULL};
  227.     int lines;
  228.     char *p, *q;
  229.     strcpy(str, msg);
  230.     for (lines = 0, p = str; *p; p++) {
  231.         if (*p == '\n') lines++;
  232.     }
  233.     DlogOpen( "Message", lines + 1, button_ok );
  234.     for (lines = 0, p = q = str; *p; p++) {
  235.         if (*p == '\n') {
  236.             *p = '\0';
  237.             DlogMessage( lines++, q );
  238.             q = p + 1;
  239.         }
  240.     }
  241.     DlogMessage( lines, q );
  242.  
  243. /*    DlogMessage( 0, msg );*/
  244.     DlogWait();
  245. }
  246.  
  247. /*    警告音    */
  248. void    Warning()
  249. {
  250.     Bell();
  251. }
  252.  
  253.