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

  1. /*
  2.  *        コントロールパネル制御
  3.  *
  4.  *        1994.8.13
  5.  */
  6. #include <stdio.h>
  7. #include <string.h>
  8.  
  9. #include "poly.h"
  10. #include "view.h"
  11. #include "menu.h"
  12. #include "event.h"
  13. #include "ml.h"
  14.  
  15. #include "graph.h"
  16. #include "input.h"
  17. #include "model.h"
  18.  
  19. #ifndef WINDOWS
  20. #define    ATTR_START        3
  21. #else
  22. #define    ATTR_START        2
  23. #endif
  24. #define    ATTR_LINES        (DISPLAY_Y/FontV-(OBJ_LINES+CURSOR_LINES+ATTR_START+4))
  25. #define    OBJ_START        (ATTR_START+ATTR_LINES+2+1)
  26. #define    OBJ_LINES        6
  27. #define    CURSOR_START    (OBJ_START+OBJ_LINES+1)
  28. #define    CURSOR_LINES    5
  29.  
  30. #define    SEL_START        (DISPLAY_X - CTRL_WIDTH + FontH)    /*    選択ウインドウの開始位置    */
  31. #define    SEL_WIDTH        8            /*    選択ウインドウの幅            */
  32.  
  33. static    int        AttrScroll = 0 ;
  34. static    int        ObjScroll = 0 ;
  35.  
  36. static    short    UpArrow[] = {
  37.     0xCC00, 0xCC00, 0x8400, 0x8400, 0x0000, 0x0000,
  38. };
  39. static    short    DownArrow[] = {
  40.     0x0000, 0x0000, 0x8400, 0x8400, 0xCC00, 0xCC00,
  41. };
  42.  
  43. static    void    AttrSelect( int );
  44. static    void    ObjSelect( int );
  45. static    void    DrawFrame( int, int, int, int );
  46. static    void    DrawItem( int, char*, int );
  47. static    void    CallAttrSelect(int n);
  48. static    void    CallObjSelect(int n);
  49.  
  50. int    IdentControl;
  51. int IdentAttrSelect;
  52. int IdentObjSelect;
  53.  
  54. char StatusText[MAXSTATUS][STATUSTEXTLENGTH+1];
  55. int StatusWidth[MAXSTATUS];
  56.  
  57. /*    コントロールパネルの表示    */
  58. void    DrawControlPanel()
  59. {
  60.     int        x1, y1, x2, y2 ;
  61.  
  62.     x1 = DISPLAY_X - CTRL_WIDTH ;
  63.     y1 = MENU_WIDTH ;
  64.     x2 = DISPLAY_X - 1 ;
  65.     y2 = DISPLAY_Y - STATUS_WIDTH - 1 ;
  66. /*    graph_line( x1, y1, x2, y1, 7 );
  67.     graph_fill( x1, y1, x1+1, y2, 7 );*/
  68.     graph_fill( x1+1, y1+1, x2-1, y2-1, FRAME_COLOR );
  69.     graph_box(x1, y1, x2, y2, TRUE);
  70.  
  71.     DrawAttrSelect();
  72.     DrawObjSelect();
  73.     DrawCursorPos();
  74.  
  75.     DrawStatusBar(-1);
  76. }
  77.  
  78. /*    コントロールパネルのマウス制御    */
  79. void    ControlSelect( x, y )
  80. int        x, y ;
  81. {
  82.     int yo;
  83.     yo = y;
  84.     y /= FontV ;
  85.  
  86.     if ( y >= CURSOR_START ) {
  87.         WaitMouseOff();
  88.         if ( IdentControl >= 0 )
  89.         {
  90.             DataStruct    *top = StackTop();
  91.             StackPushInt( y - CURSOR_START );
  92.             CallFunction( IdentControl, 1, top+1 );
  93.             StackRelease( top );
  94.         }
  95.     } else if ( y >= OBJ_START-1 )
  96.         ObjSelect( y );
  97.     else if ( y >= ATTR_START-1 )
  98.         AttrSelect( y );
  99.     else
  100.         WaitMouseOff();
  101.  
  102. }
  103.  
  104. /*    アトリビュート選択ウインドウの表示     */
  105. void    DrawAttrSelect()
  106. {
  107.     int        i, n ;
  108.  
  109.     if (AttrCurrent < AttrScroll) {
  110.         AttrScroll = AttrCurrent;
  111.     } else if (AttrCurrent >= AttrScroll + ATTR_LINES) {
  112.         AttrScroll = AttrCurrent - ATTR_LINES + 1;
  113.     }
  114.  
  115.     DrawFrame( ATTR_START, ATTR_LINES, AttrScroll>0, AttrLast >= AttrScroll+ATTR_LINES-1 );
  116.     graph_puts( "アトリビュート", SEL_START, (ATTR_START-1) * FontV - 12, FRAME_COLOR << 4);
  117.  
  118.     for( i = 0 ; i < ATTR_LINES ; i++ )
  119.     {
  120.         n = i + AttrScroll ;
  121.         if ( n <= AttrLast && AttrData[n].flag )
  122.             DrawItem( ATTR_START+i, AttrData[n].name, ( n == AttrCurrent ) );
  123.         else
  124.             DrawItem( ATTR_START+i, "", FALSE );
  125.     }
  126. }
  127.  
  128. /*    オブジェクト選択ウインドウの表示     */
  129. void    DrawObjSelect()
  130. {
  131.     int        i, n ;
  132.     char    objname[OBJ_NAME_LEN+2] ;
  133.  
  134.  
  135.     if (ObjCurrent < ObjScroll) {
  136.         ObjScroll = ObjCurrent;
  137.     } else if (ObjCurrent >= ObjScroll + OBJ_LINES) {
  138.         ObjScroll = ObjCurrent - OBJ_LINES + 1;
  139.     }
  140.  
  141.     DrawFrame( OBJ_START, OBJ_LINES, ObjScroll>0, ObjLast >= ObjScroll+OBJ_LINES-1 );
  142.     graph_puts( "オブジェクト", SEL_START, (OBJ_START-1) * FontV - 12, FRAME_COLOR << 4);
  143.  
  144.     for( i = 0 ; i < OBJ_LINES ; i++ )
  145.     {
  146.         n = i + ObjScroll ;
  147.         if ( n <= ObjLast && ObjData[n].flag )
  148.         {
  149.             strcpy( objname+1, ObjData[n].name );
  150.             objname[0] = ObjData[n].edit ? '*' : ' ' ;
  151.         }
  152.         else
  153.             strcpy( objname, "" );
  154.         DrawItem( OBJ_START+i, objname, ( n == ObjCurrent ) );
  155.     }
  156. }
  157.  
  158. static    void CallAttrSelect(int n)
  159. {
  160.     if (IdentAttrSelect >= 0) {
  161.         DataStruct    *top ;
  162.         top = StackTop();
  163.         StackPushInt( n );
  164.         CallFunction( IdentAttrSelect, 1, top+1 );
  165.         StackRelease( top );
  166.     } else if (n >= 0) {
  167.         AttrCurrent = n;
  168.     }
  169. }
  170.  
  171. static    void    AttrSelect( y )
  172. int        y ;
  173. {
  174.     int        n ;
  175.  
  176.     n = y - ATTR_START ;
  177.  
  178.     if ( 0 <= n && n < ATTR_LINES) {
  179.         WaitMouseOff();
  180.         if (n+AttrScroll <= AttrLast ) {
  181.             CallAttrSelect(AttrScroll + n);
  182.         } else {
  183.             CallAttrSelect(-1);
  184.         }
  185.     } else if ( n < 0 && AttrScroll > 0 ) {
  186. #ifdef WINDOWS
  187.         extern unsigned long WinGetTimer(void);
  188.         unsigned long lasttime = WinGetTimer();
  189.         do {
  190.             AttrScroll -- ;
  191.             if (AttrCurrent >= AttrScroll + ATTR_LINES) {
  192.                 CallAttrSelect(AttrScroll + ATTR_LINES - 1);
  193.             }
  194.             DrawAttrSelect();
  195.             do {
  196.                 PeekInput();
  197.             } while (lasttime + 200 > WinGetTimer()
  198.                 && !QuitFlag && (MouseRight || MouseLeft));
  199.         } while (AttrScroll > 0
  200.             && ! QuitFlag && (MouseLeft || MouseRight));
  201.         WaitMouseOff();
  202. #else
  203.         WaitMouseOff();
  204.         AttrScroll -- ;
  205.         if (AttrCurrent >= AttrScroll + ATTR_LINES) {
  206.             CallAttrSelect(AttrScroll + ATTR_LINES - 1);
  207.         }
  208. #endif
  209.     } else if ( n >= ATTR_LINES && AttrScroll + ATTR_LINES <= AttrLast+1 ) {
  210. #ifdef WINDOWS
  211.         extern unsigned long WinGetTimer(void);
  212.         unsigned long lasttime = WinGetTimer();
  213.         do {
  214.             AttrScroll ++ ;
  215.             if (AttrCurrent < AttrScroll) {
  216.                 CallAttrSelect(AttrScroll);
  217.             }
  218.             DrawAttrSelect();
  219.             do {
  220.                 PeekInput();
  221.             } while (lasttime + 200 > WinGetTimer()
  222.                 && !QuitFlag && (MouseRight || MouseLeft));
  223.         } while (AttrScroll + ATTR_LINES <= AttrLast+1
  224.             && ! QuitFlag && (MouseLeft || MouseRight));
  225.         WaitMouseOff();
  226. #else
  227.         WaitMouseOff();
  228.         AttrScroll ++ ;
  229.         if (AttrCurrent < AttrScroll) {
  230.             CallAttrSelect(AttrScroll);
  231.         }
  232. #endif
  233.     } else {
  234.         WaitMouseOff();
  235.     }
  236.     DrawAttrSelect();
  237. }
  238.  
  239. static    void CallObjSelect(int n)
  240. {
  241.     if (IdentObjSelect >= 0) {
  242.         DataStruct    *top ;
  243.         top = StackTop();
  244.         StackPushInt( n );
  245.         CallFunction( IdentObjSelect, 1, top+1 );
  246.         StackRelease( top );
  247.     } else if (n >= 0) {
  248.         ObjCurrent = n;
  249.     }
  250. }
  251.  
  252. static    void    ObjSelect( y )
  253. int        y ;
  254. {
  255.     int        n ;
  256.  
  257.     n = y - OBJ_START ;
  258.  
  259.     if ( 0 <= n && n < OBJ_LINES) {
  260.         WaitMouseOff();
  261.         if (n+ObjScroll <= ObjLast ) {
  262.             CallObjSelect(ObjScroll + n) ;
  263.         } else {
  264.             CallObjSelect(-1);
  265.         }
  266.     } else if ( n < 0 && ObjScroll > 0 ) {
  267. #ifdef WINDOWS
  268.         extern unsigned long WinGetTimer(void);
  269.         unsigned long lasttime = WinGetTimer();
  270.         do {
  271.             ObjScroll -- ;
  272.             if (ObjCurrent >= ObjScroll + OBJ_LINES) {
  273.                 CallObjSelect(ObjScroll + OBJ_LINES - 1);
  274.             }
  275.             DrawObjSelect();
  276.             do {
  277.                 PeekInput();
  278.             } while (lasttime + 200 > WinGetTimer()
  279.                 && !QuitFlag && (MouseRight || MouseLeft));
  280.         } while (ObjScroll > 0
  281.             && ! QuitFlag && (MouseLeft || MouseRight));
  282.         WaitMouseOff();
  283. #else
  284.         WaitMouseOff();
  285.         ObjScroll -- ;
  286.         if (ObjCurrent >= ObjScroll + OBJ_LINES) {
  287.             CallObjSelect(ObjScroll + OBJ_LINES - 1);
  288.         }
  289. #endif
  290.     } else if ( n >= OBJ_LINES && ObjScroll + OBJ_LINES <= ObjLast+1 ) {
  291. #ifdef WINDOWS
  292.         extern unsigned long WinGetTimer(void);
  293.         unsigned long lasttime = WinGetTimer();
  294.         do {
  295.             ObjScroll ++ ;
  296.             if (ObjCurrent < ObjScroll) {
  297.                 CallObjSelect(ObjScroll);
  298.             }
  299.             DrawObjSelect();
  300.             do {
  301.                 PeekInput();
  302.             } while (lasttime + 200 > WinGetTimer()
  303.                 && !QuitFlag && (MouseRight || MouseLeft));
  304.         } while (ObjScroll + OBJ_LINES <= ObjLast+1
  305.              && ! QuitFlag && (MouseLeft || MouseRight));
  306.         WaitMouseOff();
  307. #else
  308.         WaitMouseOff();
  309.         ObjScroll ++ ;
  310.         if (ObjCurrent < ObjScroll) {
  311.             CallObjSelect(ObjScroll);
  312.         }
  313. #endif
  314.     } else {
  315.         WaitMouseOff();
  316.     }
  317.     DrawObjSelect();
  318. }
  319.  
  320. static    void    DrawFrame( start, lines, upflag, downflag )
  321. int        start, lines, upflag, downflag ;
  322. {
  323.     int        x1, y1, x2, y2 ;
  324.  
  325.     x1 = SEL_START - 2 ;
  326.     y1 = start * FontV - 1 ;
  327.     x2 = SEL_START + SEL_WIDTH * FontH ;
  328.     y2 = ( start + lines ) * FontV ;
  329.     graph_box( x1, y1, x2, y2, FALSE );
  330.  
  331.     x1 = ( x1 + x2 - FontH ) / 2 ;
  332.     if (upflag) {
  333.         graph_pattern( x1, y1 - 9, FRAME_COLOR, UpArrow, 6, 6 );
  334.     } else {
  335.         graph_fill( x1, y1-9, x1+5, y1-4, FRAME_COLOR );
  336.     }
  337.     if (downflag) {
  338.         graph_pattern( x1, y2 + 3, FRAME_COLOR, DownArrow, 6, 6 );
  339.     } else {
  340.         graph_fill( x1, y2+3, x1+5, y2+8, FRAME_COLOR );
  341.     }
  342. }
  343.  
  344. static    void    DrawItem( y, str, flag )
  345. int        y ;
  346. char    *str ;
  347. int        flag ;
  348. {
  349.     int        code ;
  350.     char    buf[256] ;
  351.  
  352.     sprintf( buf, "%-10s", str );
  353.     buf[SEL_WIDTH] = '\0' ;
  354.     code = flag ? FRAME_COLOR : FRAME_COLOR << 4 ;
  355.     graph_puts( buf, SEL_START, y*FontV, code );
  356. }
  357.  
  358. /*    カーソル位置の表示    */
  359. void    DrawCursorPos()
  360. {
  361.     int        x, y ;
  362.     int        mx, my, mz ;
  363.     char    str[80] ;
  364.  
  365.     Get3DCursor( &mx, &my, &mz );
  366.  
  367.     x = SEL_START ;
  368.     y = CURSOR_START * FontV ;
  369.  
  370.     sprintf( str, "X:%6d", mx );
  371.     graph_puts( str, x, y, FRAME_COLOR<<4 );
  372.     sprintf( str, "Y:%6d", my );
  373.     graph_puts( str, x, y+FontV, FRAME_COLOR<<4 );
  374.     sprintf( str, "Z:%6d", mz );
  375.     graph_puts( str, x, y+FontV*2, FRAME_COLOR<<4 );
  376. }
  377.  
  378. void    DrawStatusBar(int pos)
  379. {
  380.     int i;
  381.     int x, x2, y;
  382.     y = DISPLAY_Y - STATUS_WIDTH;
  383. #if 0
  384.     if (pos < 0) {
  385. #endif
  386.         graph_line( 0, y, DISPLAY_X-1, y, 7 );
  387.         graph_fill( 0, y+1, DISPLAY_X-1, DISPLAY_Y-1, FRAME_COLOR );
  388.         graph_puts(StatusText[0], FontH, y+3, FRAME_COLOR<<4);
  389.         x = DISPLAY_X - (FontH-2);
  390.         graph_fill( x, y+1, DISPLAY_X-1, DISPLAY_Y-1, FRAME_COLOR );
  391.         for (i = MAXSTATUS-1; i > 0; i--) {
  392.             if (StatusWidth[i] > 0) {
  393.                 x2 = x - FontH * StatusWidth[i] - 3;
  394.                 graph_box( x2, y+1, x, DISPLAY_Y-2, FALSE);
  395.                 graph_puts(StatusText[i], x2+2, y+3, FRAME_COLOR<<4);
  396.                 x = x2 - 2;
  397.                 graph_fill( x, y+1, x2-1, DISPLAY_Y-1, FRAME_COLOR );
  398.             }
  399.         }
  400.         graph_box( FontH-2, y+1, x, DISPLAY_Y-2, FALSE);
  401. #if 0
  402.     } else if (pos < MAXSTATUS && (pos == 0 || StatusWidth[pos] > 0)) {
  403.         x = DISPLAY_X - (FontH-2);
  404.         for (i = MAXSTATUS-1; i > pos; i--) {
  405.             if (StatusWidth[i] > 0) {
  406.                 x = x - FontH * StatusWidth[i] - 3 - 2;
  407.             }
  408.         }
  409.         if (pos > 0) {
  410.             x2 = x - FontH * StatusWidth[pos] - 3;
  411.         } else {
  412.             x2 = FontH-2;
  413.         }
  414.         graph_fill( x2+1, y+2, x-1, DISPLAY_Y-3, FRAME_COLOR );
  415.         graph_puts(StatusText[pos], x2+2, y+3, FRAME_COLOR<<4);
  416.     }
  417. #endif
  418. }
  419.