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

  1. /* :ts=8 */
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <ctype.h>
  6. #include <math.h>
  7.  
  8. #include "general.h"
  9. #include "globals.h"
  10. #include "intui.h"
  11. #include "timer.h"
  12. #include "spl_math.h"
  13. #include "spl_util.h"
  14. #include "spl_gfx.h"
  15. #include "pan.h"
  16.  
  17. static Boolean_T    Pan_Active;
  18. static short        Old_X;
  19. static short        Old_Y;
  20. static Vector_T        Orig_Pos;
  21. static Vector_T        Orig_Offset;
  22. static Vector_T        Box_Min, Box_Max;
  23.  
  24. static
  25. void Pan_Timeout()
  26. /************************************************************************/
  27. /*                                                                      */
  28. /* Function called when timer expires: Draw all splines.        */
  29. /*                                                                      */
  30. /************************************************************************/
  31. {    
  32.     Vector_T    New_Offset;
  33.     Vector_T    Distance;
  34.     Vector_T    Corrected_Pos;
  35.     /* Convert Current_Pos the original offset         */
  36.     /* and compute moved distance.                */
  37.     /* Subtract this from original offset to get new offset    */
  38.     Vec3Op(Corrected_Pos, =, Current_Pos, -, Offset);
  39.     Vec2Op(Corrected_Pos, +=, Orig_Offset);
  40.  
  41.     Vec3Op(Distance, =, Corrected_Pos, -, Orig_Pos);
  42.  
  43.     Vec3Op(New_Offset, =, Orig_Offset, -, Distance);
  44.  
  45.     Set_Offset(New_Offset, Select_View_Id);
  46.  
  47.     Compute_Splines();
  48.     Clear_All(What_All);
  49.     Draw_All(What_All);
  50.  
  51.     Redraw_Mask = 0;
  52.  
  53.     Stop_Timer();
  54.  
  55. } /* Pan_Timeout */
  56.  
  57. static 
  58. void Pan_Redraw(long Mask)
  59. /************************************************************************/
  60. /*                                                                      */
  61. /* Function called to redraw screen while panning a view.        */
  62. /*                                                                      */
  63. /************************************************************************/
  64. {    
  65.     Vector_T    New_Offset;
  66.     Vector_T    Distance;
  67.     Vector_T    Corrected_Pos;
  68.     /* Convert Current_Pos the original offset         */
  69.     /* and compute moved distance.                */
  70.     /* Subtract this from original offset to get new offset    */
  71.     Vec3Op(Corrected_Pos, =, Current_Pos, -, Offset);
  72.     Vec2Op(Corrected_Pos, +=, Orig_Offset);
  73.  
  74.     Vec3Op(Distance, =, Corrected_Pos, -, Orig_Pos);
  75.  
  76.     Vec3Op(New_Offset, =, Orig_Offset, -, Distance);
  77.  
  78.     Set_Offset(New_Offset, Select_View_Id);
  79.  
  80.     Clear_All(What_All);
  81.     Draw_Box(Box_Min, Box_Max, NULL, DM_Plane, What_All);
  82.     Draw_Origin(DM_Normal, What_All);
  83.  
  84.     Start_Timer(Delay_Draw_Seconds, Delay_Draw_Micros);
  85.  
  86.     Redraw_Mask = 0;
  87.  
  88. } /* Pan_Redraw */
  89.  
  90. static
  91. void Pan_Select_Up(short X, short Y)
  92. /************************************************************************/
  93. /*                                                                      */
  94. /* X, Y are the actual coordinates in the active window.        */
  95. /*                                                                      */
  96. /************************************************************************/
  97. {
  98.     /* If the timer hasn't expired, then call the timeout handler to*/
  99.     /* compute and draw the splines.                 */
  100.  
  101.     if (!Check_Timer()) Pan_Timeout();
  102.  
  103.     Set_Mode_Normal();
  104.  
  105. } /* Pan_Select_Up */
  106.  
  107. static 
  108. void Pan_Select_Down(short X, short Y)
  109. /************************************************************************/
  110. /*                                                                      */
  111. /* X, Y are the actual coordinates in the active window.        */
  112. /*                                                                      */
  113. /************************************************************************/
  114. {
  115.     Select_View_Id = Screen_To_World(X, Y, Current_Pos);
  116.     if (Select_View_Id < 0) return;
  117.  
  118.     if (Get_Bounding_Box(Box_Min, Box_Max)) {
  119.     Vec3Scalar(Box_Min, =, -Grid_Size, -Grid_Size, -Grid_Size);
  120.     Vec3Scalar(Box_Max, =,  Grid_Size,  Grid_Size,  Grid_Size);
  121.  
  122.     }
  123.     Draw_Box(Box_Min, Box_Max, NULL, DM_Plane, What_All);
  124.  
  125.     Vec2Op(Orig_Pos, =, Current_Pos);
  126.  
  127.     Old_X = X;
  128.     Old_Y = Y;
  129.  
  130.     Pan_Active = TRUE;
  131.  
  132. } /* Pan_Select_Down */
  133.  
  134. static 
  135. void  Pan_Move(short X, short Y)
  136. /************************************************************************/
  137. /*                                                                      */
  138. /* Function called when mouse is moved to pan a view.            */
  139. /* X, Y are the actual coordinates in the active window.        */
  140. /*                                                                      */
  141. /************************************************************************/
  142. {
  143.     short View_Id;
  144.  
  145.     if (!Pan_Active) return;
  146.  
  147.     View_Id = Screen_To_World(X, Y, Current_Pos);
  148.  
  149.     if (View_Id != Select_View_Id) return;
  150.  
  151.     if (Old_X == X && Old_Y == Y) return;
  152.  
  153.     Old_X = X;
  154.     Old_Y = Y;
  155.  
  156.     if (Redraw_Always) Pan_Redraw(What_All);
  157.     else               Redraw_Mask = What_All;
  158.  
  159. } /* Pan_Pan */
  160.  
  161. static
  162. Boolean_T Pan_Handle_Event(struct IntuiMessage *Msg)
  163. /************************************************************************/
  164. /*                                                                      */
  165. /* Event handler routine for the 'PAN VIEW' mode.            */
  166. /* Events handled:                            */
  167. /*    Select down: Start pan.                        */
  168. /*    Select up: Stop pan.                        */
  169. /*    Mouse move: Change position.                    */
  170. /*                                                                      */
  171. /************************************************************************/
  172. {
  173.  
  174.     switch (Msg->Class) {
  175.  
  176.  
  177.     case IDCMP_MOUSEBUTTONS:
  178.         /* Msg->Code contain id of button pressed         */
  179.         /* Msg->MouseX and Msg->MouseY contain mouse position             */
  180.  
  181.     switch (Msg->Code) {
  182.  
  183.     case SELECTDOWN:
  184.         Pan_Select_Down(Msg->MouseX, Msg->MouseY);
  185.         return(TRUE);
  186.  
  187.     case SELECTUP:
  188.         Pan_Select_Up(Msg->MouseX, Msg->MouseY);
  189.         return(TRUE);
  190.  
  191.     } /* switch (Msg->Code) */
  192.     break;
  193.  
  194.     case IDCMP_MOUSEMOVE:
  195.     Pan_Move(Msg->MouseX, Msg->MouseY);
  196.     return(TRUE);
  197.  
  198.     } /* switch (Msg->Class) */
  199.  
  200.     return(FALSE);
  201.  
  202. } /* Pan_Handle_Event */
  203.  
  204. void Set_Mode_Pan()
  205. /************************************************************************/
  206. /*                                                                      */
  207. /* Start panning a view.                        */
  208. /*                                                                      */
  209. /************************************************************************/
  210. {
  211.     Pan_Active        = FALSE;
  212.     State.Handle_Event    = Pan_Handle_Event;
  213.     State.Timeout    = Pan_Timeout;
  214.     State.Redraw    = Pan_Redraw;
  215.  
  216.     if (MQ_Size_Move_G > 0) {
  217.         SetMouseQueue(Windows[Id_Active_Window].Window, MQ_Size_Move_G); 
  218.         Redraw_Always = TRUE;
  219.     } else Redraw_Always = FALSE;
  220.  
  221.  
  222.     Vec2Op(Orig_Offset, =, Offset);
  223.  
  224.     sprintf(Error_Msg, "Pan view");
  225.     Display_Status(Error_Msg);
  226.  
  227. } /* Set_Mode_Pan */
  228.