home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / icoons / source / rotate_g.c < prev    next >
Encoding:
C/C++ Source or Header  |  1980-02-07  |  8.3 KB  |  261 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 "rotate_g.h"
  16.  
  17. /* Get Stringinfo buffer for the Rotate gadget with id 'G':    */
  18. #define Get_Gadget_String(G) (((struct StringInfo *) \
  19.                 (Rotate_GroupGadgets[G]->SpecialInfo))->Buffer)
  20.  
  21.     /* Set string to 'S' in string gadget 'G':    */
  22. #define Set_Gadget_String(G, S) \
  23.         GT_SetGadgetAttrs(Rotate_GroupGadgets[G], \
  24.             Windows[W_Rotate_Group].Window, NULL, \
  25.             GTST_String, S)
  26.  
  27. static Boolean_T    Rotate_Group_Active;
  28. static short        Rotate_Group_Axis = 0; /* 0 = X, 1 = Y, 2 = Z */
  29. static short        Orig_Rotate_Group_X;
  30. static short        Prev_Rotate_Group_X;
  31. static double        Rotate_Group_Angle;
  32. static Vector_T        Box_Min, Box_Max;
  33.  
  34. static
  35. void Set_Rotate_Group_Angle_Value(double Angle)
  36. /************************************************************************/
  37. /*                                                                      */
  38. /* Set rotate angle value gadget to 'Angle'.                */
  39. /*                                                                      */
  40. /************************************************************************/
  41. {
  42.     char Buffer[Buffer_Length+1];
  43.  
  44.     if (Windows[W_Rotate_Group].Window == NULL) return;
  45.  
  46.     sprintf(Buffer, " %.0lf", Angle);
  47.     Set_Gadget_String(GDX_Rotate_Group_Angle_Value, Buffer);
  48.  
  49. } /* Set_Rotate_Group_Angle_Value */
  50.  
  51. static
  52. void Rotate_Group_Timeout()
  53. /************************************************************************/
  54. /*                                                                      */
  55. /* Function called when timer expires: Draw all splines.        */
  56. /*                                                                      */
  57. /************************************************************************/
  58. {    
  59.     Points_Rotate(Rotate_Group_Angle, Rotate_Group_Axis);
  60.     Compute_Splines();
  61.     Clear_All(What_All);
  62.     Draw_All(What_All);
  63.  
  64.     Redraw_Mask = 0;
  65.  
  66.     Stop_Timer();
  67.  
  68. } /* Rotate_Group_Timeout */
  69.  
  70. static 
  71. void Rotate_Group_Redraw(long Mask)
  72. /************************************************************************/
  73. /*                                                                      */
  74. /* Function called to redraw screen while rotating points.        */
  75. /*                                                                      */
  76. /************************************************************************/
  77. {    
  78.     Vector_T R_Vector;
  79.  
  80.     if (Windows[W_Rotate_Group].Window == NULL) return;
  81.  
  82.     R_Vector[0] = R_Vector[1] = R_Vector[2] = 0.0;
  83.     R_Vector[Rotate_Group_Axis] = Rotate_Group_Angle;
  84.  
  85.     Set_Rotate_Group_Angle_Value(Rotate_Group_Angle);
  86.  
  87.     Clear_Plane(3, What_All);
  88.     Draw_Box(Box_Min, Box_Max, R_Vector, DM_Plane, What_All);
  89.  
  90.     Start_Timer(Delay_Draw_Seconds, Delay_Draw_Micros);
  91.  
  92.     Redraw_Mask = 0;
  93.  
  94. } /* Rotate_Group_Redraw */
  95.  
  96. static
  97. void Rotate_Group_Select_Up(short X, short Y)
  98. /************************************************************************/
  99. /*                                                                      */
  100. /* X, Y are the actual coordinates in the active window.        */
  101. /*                                                                      */
  102. /************************************************************************/
  103. {
  104.     /* If the timer hasn't expired, then call the timeout handler to*/
  105.     /* compute and draw the splines.                 */
  106.  
  107.     if (!Check_Timer()) Rotate_Group_Timeout();
  108.  
  109.     Set_Rotate_Group_Angle_Value(0.0);
  110.     Set_Mode_Normal();
  111.  
  112. } /* Rotate_Group_Select_Up */
  113.  
  114. static 
  115. void Rotate_Group_Select_Down(short X, short Y)
  116. /************************************************************************/
  117. /*                                                                      */
  118. /* X, Y are the actual coordinates in the active window.        */
  119. /*                                                                      */
  120. /************************************************************************/
  121. {
  122.  
  123.     if (X < 0) return;
  124.  
  125.     if (Get_Select_Bounding_Box(Box_Min, Box_Max)) {
  126.     Display_Message("No points selected");
  127.     return;
  128.     }
  129.     Draw_Box(Box_Min, Box_Max, NULL, DM_Plane, What_All);
  130.  
  131.     Rotate_Group_Active = TRUE;
  132.  
  133.     Orig_Rotate_Group_X = X;
  134.     Prev_Rotate_Group_X = X;
  135.  
  136.     Rotate_Group_Angle = 0.0; uble    nte_Group_Seleos   Group_X = >rn;
  137. ay__NoMouseQue
  138.   W_RotateId= TRUE;_W_Rota, NULL, \
  139. leos   Group_X =); 
  140.     ask = 0Always
  141.  
  142.     Ori  Dra elseMask = 0Always
  143.  
  144.  FALSERotate_Group_Select_Up */
  145.  
  146. srt Xtic 
  147. void Rotate_GGroup_Select_UMove, short Y)
  148. /************************************************************************/
  149. /*                                                                      */
  150. /* X, Y are called when timer exmouse /* moveraw scgle va    */
  151. /*          the actual coordinates in the active window.        */
  152. /*                                                                      */
  153. /************************************************************************/
  154. {
  155.  
  156.     if X < 0) return;
  157.  
  158.     if (Get_Sele!roup_Active = TRUE;;
  159.  
  160.     if Get_SeleABSret-tate_Group_X = X;
  161.  
  162.  )tur5;
  163.  
  164.     R_Vector[oup_Angle = 0.0; ublret-tate_Group_X = X;
  165.   et_Mode[oup_Angle = 0.0; ubl1.0 + Group_Angle);
  166.  
  167.     /4 Set_v_Rotate_Group_X = X;
  168.  
  169.     Rotate_GSeleask = 0Always_Group_Timeout(ong Mas);
  170.     Draw_BoxelseM      */
  171. /****ask = 0;
  172.  
  173. } /*);
  174.     DRotate_Group_Select_UMovetic
  175. void RotT    Rotate_Group_Select_UHo*/
  176.     _EventStringInI#inc"No poi *Msg*******************************************************************/
  177. /*                                                                      */
  178. /* X, Y areEvent to*/
  179.     /*ecttGadgRotate g'ROTATE GROUP' mode.         Events to*/
  180.     d:*               p */
  181.  
  182.     Rown:imer(Dg pointon.              p */
  183.  
  184.     up:imeopg pointon.              Mouse move: Cto*gng pointd wlue g/*                                                                      */
  185. /************************************************************************/
  186. {
  187.     charintf(B'G'chSelsg->Class;
  188. ayrintf(case IDCMP_MOUSEBUTTONS:_St   lsg->Codeatentactie_Gofforttd wpw asera     St   lsg->MouseXw thelsg->MouseYatentactimouse posintd w      
  189.     B'G'chSelsg->Code;
  190. ayr    case SELECTDOWN:_SMode[oup_Angle = own(short X,lsg->MouseX,elsg->MouseYrn;
  191. Mode
  192.     R(   Oet_v    case SELECTUP:_SMode[oup_Angle = own(sho X,lsg->MouseX,elsg->MouseYrn;
  193. Mode
  194.     R(   Oet_v    ate_GB'G'chSelsg->Code;
  195.    Sbreak;rintf(case IDCMP_MOUSEMOVE:_Sroup_Select_UMove,lsg->MouseX,elsg->MouseYrn;
  196.  
  197.     R(   Oet_v  Dra e_GB'G'chSelsg->Class;
  198. if (!Che
  199.     R(FALSE Rotate_Group_Select_UHo*/
  200.     _Event
  201. if (ate_GHo*/
  202.     _roup_Angle);
  203.  
  204.     ********************************************************************/
  205. /*                                                                      */
  206. /* FunctionCto*gngw sROTATE GROUP mode.                                                                         */
  207. /************************************************************************/
  208. {
  209.     char Bufows[W_Rotate_Group].Window == NULL) return;
  210.  
  211.     R_Vector[oup_Active = TRUE;        
  212.  FALSERot_Timerte.Ho*/
  213.     _Event        
  214.  roup_Select_UHo*/
  215.     _EventRot_Timerte.);
  216.  
  217.            
  218.  roup_Select_U);
  219.  
  220.    Rot_Timerte.ask =         
  221.  roup_Select_Uask = printf(Buffer, Errectlsgf",adget wiect_"raw_Box(essage(mertus Errectlsget_v_Rotatate(RSave, Rotate_GHo*/
  222.     _roup_Angle);
  223.  
  224.     
  225. if (ate_GHo*/
  226.     _roup_Angle);
  227.  
  228.     .0);
  229.   *******************************************************************/
  230. /*                                                                      */
  231. /* FunctionHo*/
  232.      ae[oup_Angle = 0.0; /
  233.  
  234. stato 'Anglevent/*                                                                      */
  235. /************************************************************************/
  236. {
  237.     char Bufows[W_Rotate_Group].Window == NULL) return;
  238.  
  239.     R_Vectoratate(RSave, RoMode[oup_Angle = 0.0; ublatof(et_String(G) (((stre_Group_Angle_Value, Buffer)Rotate_Group_Active =);
  240.  
  241.     Sete_GCnd draw the spli                 */
  242. if (!Chete_Group_Angle_Value(0.0);
  243.     Set_tate_GHo*/
  244.     _roup_Angle);
  245.  
  246.     /
  247.  
  248. static
  249. v(ate_GHo*/
  250.     _roup_Angle);
  251.  
  252. ota, short   Co******************************************************************/
  253. /*                                                                      */
  254. /* FunctionHo*/
  255.      ae[oup_Angle = 0 /* o 'Anglevent/*                                                                      */
  256. /************************************************************************/
  257. {
  258.     char Bufroup_Axis = 0; /* 0 ; /*t_tate_GHo*/
  259.     _roup_Angle);
  260.  
  261.