home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / icoons / source / add.c next >
C/C++ Source or Header  |  1992-10-03  |  4KB  |  143 lines

  1. /* :ts=8 */
  2. /************************************************************************/
  3. /*                                                                      */
  4. /* This file contains code to handle the ADD 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 "normal.h"
  19. #include "add.h"
  20.  
  21. static 
  22. void  Add_Select_Down(short X, short Y)
  23. /************************************************************************/
  24. /*                                                                      */
  25. /* Select has been pressed in add mode, this means that the user wants    */
  26. /* to add a new point here.                        */
  27. /*                                                                      */
  28. /************************************************************************/
  29. {
  30.     short     Point_Id;
  31.     Knot_T     *Knot;
  32.     Spline_T     *Spline;
  33.  
  34.     Select_View_Id = Screen_To_World(X, Y, Current_Pos);
  35.     if (Select_View_Id < 0) return;
  36.  
  37.     /* Try to locate a point near the cursor */
  38.     Point_Id = Point_Find(Current_Pos, Select_View_Id);
  39.  
  40.  
  41.     if (Point_Id < 0) {
  42.  
  43.     /* The cursor wasn't near a point so add a new spline, ie. 2    */
  44.     /* points at the same time.                    */
  45.  
  46.     /* Deselect all, and draw prev. selected spline in normal mode */
  47.         Spline = Select_Spline;
  48.         Deselect_All();
  49.         Draw_Spline(Spline, DM_Normal, What_All);
  50.         
  51.         if (Grid_Snap_Active) Snap_To_Grid(Current_Pos);
  52.  
  53.         Spline = Spline_Add(Current_Pos);
  54.         if (Spline == NULL) return;
  55.  
  56.     } else {
  57.     
  58.     /* Add a knot to an existing spline                 */
  59.  
  60.     if (Point_Id != Select_Point_Id || Select_Knot == NULL) {
  61.  
  62.        /* The chosen point isn't the currently selected point, so    */
  63.        /* deselect all, and select the chosen point.        */
  64.  
  65.             Spline = Select_Spline;
  66.             Deselect_All();
  67.             Draw_Spline(Spline, DM_Normal, What_All);
  68.  
  69.         Select_Point(Point_Id);
  70.  
  71.     }
  72.  
  73.     /* Undraw the spline as it will be modified:             */
  74.         Draw_Spline(Select_Spline, DM_Erase, What_All);
  75.  
  76.     /* Add a new knot after the selected knot at Current_Pos */
  77.  
  78.         Knot = Knot_Add(Select_Spline, Select_Knot, Current_Pos); 
  79.  
  80.     /* Draw the modified spline again.                 */
  81.         Draw_Spline(Select_Spline, DM_Normal, What_All);
  82.  
  83.         if (Knot == NULL) return;
  84.  
  85.     } /* if .. else .. */
  86.  
  87.     Set_Window_Title(NULL);
  88.  
  89.     /* Enter move mode so the user can move the new knot */
  90.     Set_Mode_Move(X, Y);
  91.  
  92. } /* Add_Select_Down */
  93.  
  94. static 
  95. Boolean_T Add_Handle_Event(struct IntuiMessage *Msg)
  96. /************************************************************************/
  97. /*                                                                      */
  98. /* Event handler routine for the 'ADD' mode.                */
  99. /*                                                                      */
  100. /* Events handled:                            */
  101. /*    Select down: Add a knot or a spline.                */
  102. /*                                                                      */
  103. /************************************************************************/
  104. {
  105.  
  106.     switch (Msg->Class) {
  107.  
  108.  
  109.     case IDCMP_MOUSEBUTTONS:
  110.         /* Msg->Code contain id of button pressed         */
  111.         /* Msg->MouseX and Msg->MouseY contain mouse position     */
  112.  
  113.     switch (Msg->Code) {
  114.  
  115.     case SELECTDOWN:
  116.         Add_Select_Down(Msg->MouseX, Msg->MouseY);
  117.         return(TRUE);
  118.  
  119.     } /* switch (Msg->Code) */
  120.     break;
  121.  
  122.  
  123.     } /* switch (Msg->Class) */
  124.  
  125.     return(FALSE);
  126.  
  127. } /* Add_Handle_Event */
  128.  
  129. void Set_Mode_Add()
  130. /************************************************************************/
  131. /*                                                                      */
  132. /* Enter add mode, ie. add a new knot next time the user presses left    */
  133. /* button.                                */
  134. /*                                                                      */
  135. /************************************************************************/
  136. {
  137.  
  138.     State.Handle_Event        = Add_Handle_Event;
  139.  
  140.     Display_Status("Add");
  141.  
  142. } /* Set_Mode_Add */
  143.