home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / icoons / source / normal.c < prev    next >
C/C++ Source or Header  |  1992-10-05  |  7KB  |  284 lines

  1. /* :ts=8 */
  2. /************************************************************************/
  3. /*                                                                      */
  4. /* This file contains code to handle the NORMAL mode.            */
  5. /*                                                                      */
  6. /************************************************************************/
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <math.h>
  11.  
  12. #include "general.h"
  13. #include "globals.h"
  14. #include "intui.h"
  15. #include "spl_math.h"
  16. #include "spl_util.h"
  17. #include "spl_gfx.h"
  18. #include "commands.h"
  19. #include "render.h"
  20. #include "move.h"
  21. #include "group.h"
  22. #include "pan.h"
  23. #include "normal.h"
  24.  
  25. void Normal_Redraw(long What)
  26. /************************************************************************/
  27. /*                                                                      */
  28. /* Function normally called to redraw the screen:            */
  29. /* Clear all windows and draw everything again.                */
  30. /*                                                                      */
  31. /************************************************************************/
  32. {
  33.     if (What & What_S) Clear_All(What_All);
  34.     Draw_All(What);
  35.  
  36. } /* Normal_Redraw */
  37.  
  38. static 
  39. void  Normal_Select_Down(short X, short Y)
  40. /************************************************************************/
  41. /*                                                                      */
  42. /* This function is called when the user activates the select button    */
  43. /* in normal mode, ie. to select/move a knot.                */
  44. /*                                                                      */
  45. /************************************************************************/
  46. {
  47.     short    Point_Id;
  48.  
  49.     Select_View_Id = Screen_To_World(X, Y, Current_Pos);
  50.     if (Select_View_Id < 0) return;
  51.  
  52.     Point_Id = Point_Find(Current_Pos,  Select_View_Id);
  53.     if (Point_Id < 0) {
  54.  
  55.     /* We don't need a selected point to move in group mode: */
  56.     if (Group_Mode) Set_Mode_Move(X, Y);
  57.     return;
  58.  
  59.     } /* if */
  60.  
  61.     Vec2Op(Current_Pos, =, Points[Point_Id].Pos);
  62.  
  63.     if (Select_Point_Id != Point_Id) { /* Select another point     */
  64.  
  65.     if (Select_Point_Id != -1) {   /* Deselect previous    */
  66.  
  67.         if (!Group_Mode) Deselect_All();
  68.  
  69.             Draw_Marked_Segments(DM_Normal, What_S);
  70.  
  71.     } /* if */
  72.  
  73.     Select_Point(Point_Id);
  74.  
  75.     Set_Move_Group_Position(Points[Select_Point_Id].Pos);
  76.     KnotInfo_Show_Info(Select_Spline, Select_Knot);
  77.         Set_Window_Title(NULL);
  78.  
  79.     }
  80.  
  81.     Set_Mode_Move(X, Y);
  82.     return;
  83.  
  84. } /* Normal_Select_Down */
  85.  
  86. static
  87. void Normal_Timeout()
  88. /************************************************************************/
  89. /*                                                                      */
  90. /* Handle timeout in normal mode.                    */
  91. /*                                                                      */
  92. /************************************************************************/
  93. {
  94.     /* The default timeout action: Don't do anything */
  95. } /* Normal_Timeout */
  96.  
  97. static
  98. Boolean_T Normal_Handle_Event(struct IntuiMessage *Msg)
  99. /************************************************************************/
  100. /*                                                                      */
  101. /* Event handler routine for the 'NORMAL' mode.                */
  102. /*                                                                      */
  103. /* Events handled:                            */
  104. /*    Select down: Select or move a knot.                */
  105. /*     Up arrow:                            */
  106. /*     And lots of other keys... ########                */
  107. /*                                                                      */
  108. /************************************************************************/
  109. {
  110.  
  111.     switch (Msg->Class) {
  112.  
  113.     case IDCMP_MOUSEBUTTONS:
  114.         /* Msg->Code contain id of button pressed         */
  115.         /* Msg->MouseX and Msg->MouseY contain mouse position             */
  116.  
  117.     switch (Msg->Code) {
  118.  
  119.     case SELECTDOWN:
  120.         Normal_Select_Down(Msg->MouseX, Msg->MouseY);
  121.         return(TRUE);
  122.  
  123.     } /* switch (Msg->Code) */
  124.     break;
  125.  
  126.     case IDCMP_RAWKEY:
  127.     switch (Msg->Code) { /* Msg->Code contain RAW keycode    */
  128.  
  129.     case 0x4c:                    /* Up arrow    */
  130.         Command_Pan_Up();
  131.         return(TRUE);
  132.  
  133.     case 0x4d:                    /* Down arrow    */
  134.         Command_Pan_Down();
  135.         return(TRUE);
  136.  
  137.     case 0x4e:                    /* Right arrow    */
  138.         Command_Pan_Right();
  139.         return(TRUE);
  140.  
  141.     case 0x4f:                    /* Left arrow    */
  142.         Command_Pan_Left();
  143.         return(TRUE);
  144.  
  145.     case 0x50:                    /* F1            */
  146.     case 0x51:                    /* F2            */
  147.     case 0x52:                    /* F3            */
  148.     case 0x53:                    /* F4            */
  149.     case 0x54:                    /* F5            */
  150.     case 0x55:                    /* F6            */
  151.     case 0x56:                    /* F7            */
  152.     case 0x57:                    /* F8            */
  153.     case 0x58:                    /* F9            */
  154.     case 0x59:                    /* F10           */
  155.     case 0x5f:                    /* Help          */
  156.         return(TRUE);
  157.  
  158.     } /* switch */
  159.         return(FALSE);
  160.  
  161.     case IDCMP_VANILLAKEY:
  162.     switch (Msg->Code) { /* Msg->Code contain ASCII code    */
  163.  
  164.     case 'L':                    /* L    */
  165.         Command_Load_JMan_Object();
  166.         return(TRUE);
  167.  
  168.     case 'a':                    /* a    */
  169.         Command_Add();
  170.         return(TRUE);
  171.  
  172.     case 'c':                    /* c    */
  173.         Command_Cut();
  174.         return(TRUE);
  175.  
  176.     case 'C':                    /* C    */
  177.         Command_Combine();
  178.         return(TRUE);
  179.  
  180.     case 'd':                    /* d    */
  181.         Command_Delete();
  182.         return(TRUE);
  183.  
  184.     case 'D':                    /* D    */
  185.         Command_Disconnect();
  186.         return(TRUE);
  187.  
  188.     case 'h':                    /* h    */
  189.         Command_Hide();
  190.         return(TRUE);
  191.  
  192.     case 'H':                    /* H    */
  193.         Command_Show();
  194.         return(TRUE);
  195.  
  196.     case 'l':                    /* l    */
  197.         Command_Loop();
  198.         return(TRUE);
  199.  
  200.     case 'n':                    /* n    */
  201.         Command_Select_Next();
  202.         return(TRUE);
  203.  
  204.     case 'g':                    /* g    */
  205.         Set_Mode_Group();
  206.         return(TRUE);
  207.  
  208.     case 'p':                    /* p    */
  209.         Set_Mode_Pan();
  210.         return(TRUE);
  211.  
  212.     case '-':                    /* -    */
  213.         Command_Resolution_Down();
  214.         return(TRUE);
  215.  
  216.     case '+':                    /* +    */
  217.         Command_Resolution_Up();
  218.         return(TRUE);
  219.     
  220.     case '.':
  221.         Command_Toggle_Select_All();
  222.         break;
  223.  
  224.     case ',':
  225.         Command_Toggle_Select_Spline();
  226.         break;
  227.  
  228.     case ';':
  229.         if (Select_Point_Id >= 0) {
  230.         Group_Mode = TRUE;
  231.         Set_Window_Title(NULL);
  232.         }    
  233.         break;
  234.  
  235.     case 'r':                     /* r: Render */
  236.             Render_Tesselate_Object();
  237.             return(TRUE);
  238.  
  239.     case 'R':                     /* R: ReRender */
  240.             Render_Object();
  241.             return(TRUE);
  242.  
  243.     case '\r':
  244.     case '\n':
  245.         Command_Deselect_All();
  246.         return(TRUE);
  247.     
  248.     case 12:                    /* Ctrl+L    */
  249.         Compute_Splines();
  250.             Redraw_Mask |= What_All;
  251.         break;
  252.  
  253.     case ' ':                    /* Space    */
  254.         Command_Redraw();
  255.         return(TRUE);
  256.  
  257.     default:
  258.         return(FALSE);
  259.  
  260.         } /* switch */
  261.         break;
  262.  
  263.     } /* switch (Msg->Class) */
  264.  
  265.     return(FALSE);
  266.  
  267. } /* Normal_Handle_Event */
  268.  
  269. void Set_Mode_Normal()
  270. /************************************************************************/
  271. /*                                                                      */
  272. /* Change to NORMAL mode.                        */
  273. /*                                                                      */
  274. /************************************************************************/
  275. {
  276.     State.Handle_Event        = Normal_Handle_Event;
  277.     State.Timeout        = Normal_Timeout;
  278.     State.Redraw        = Normal_Redraw;
  279.  
  280.     Mark_Selected_Segments();
  281.     Display_Status(NULL);
  282.  
  283. } /* Set_Mode_Normal */
  284.