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

  1. /* :ts=8 */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5. #include <math.h>
  6.  
  7. #include "general.h"
  8. #include "globals.h"
  9. #include "intui.h"
  10. #include "normal.h"
  11. #include "spl_math.h"
  12. #include "spl_util.h"
  13. #include "spl_gfx.h"
  14. /************************************************************************/
  15. /*                                                                      */
  16. /* This file contains code to handle the GROUP command.            */
  17. /*                                                                      */
  18. /************************************************************************/
  19.  
  20. static short        Group_View_Id;
  21. static short        Group_X1;
  22. static short        Group_Y1;
  23. static short        Group_X2;
  24. static short        Group_Y2;
  25. static Boolean_T    Group_Active;
  26.  
  27. static 
  28. void  Group_Select_Up()
  29. /************************************************************************/
  30. /*                                                                      */
  31. /* This function is called when selection of a group is finished.    */
  32. /* The selection is given by the area (Group_X1, Group_Y1) ->        */
  33. /* (Group_X2, Group_Y2) in the view given by Group_View_Id.        */
  34. /*                                                                      */
  35. /************************************************************************/
  36. {
  37.     short    i;
  38.     Vector_T    Pos1, Pos2;
  39.  
  40.     if (!Group_Active) return;
  41.     if (Group_X1 == Group_X2 || Group_Y1 == Group_Y2) return;
  42.  
  43.     /* Remove the selection box */
  44.     if (Group_X2 < Group_X1) {
  45.        i        = Group_X1;
  46.        Group_X1 = Group_X2;
  47.        Group_X2 = i;
  48.     }
  49.     if (Group_Y2 < Group_Y1) {
  50.        i        = Group_Y1;
  51.        Group_Y1 = Group_Y2;
  52.        Group_Y2 = i;
  53.     }
  54.     Move(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  55.     Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y2);
  56.     Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y2);
  57.     Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y1);
  58.     Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  59.  
  60.     Screen_To_World(Group_X1, Group_Y1, Pos1);
  61.     Screen_To_World(Group_X2, Group_Y2, Pos2);
  62.  
  63.     Select_Area(Group_View_Id, Pos1, Pos2);
  64.     Set_Window_Title(NULL);
  65.  
  66.     Set_Mode_Normal();
  67.     Redraw_Mask |= What_K;
  68.  
  69. } /* Group_Group_Select_Up */
  70.  
  71. static 
  72. void  Group_Select_Down(short X, short Y)
  73. /************************************************************************/
  74. /*                                                                      */
  75. /* Function called when mouse is moved to select a group.        */
  76. /* X, Y are the actual coordinates in the active window 'Win'.        */
  77. /*                                                                      */
  78. /************************************************************************/
  79. {
  80.     Vector_T      Pos;
  81.  
  82.     Group_View_Id = Screen_To_World(X, Y, Pos);
  83.     if (Group_View_Id < 0) return;
  84.  
  85.     Group_Active = TRUE;
  86.  
  87.     Group_X2 = Group_X1 = X;
  88.     Group_Y2 = Group_Y1 = Y;
  89.  
  90.     Windows[Id_Active_Window].RastPort->Mask    = 0x01;
  91.     SetDrMd(Windows[Id_Active_Window].RastPort, COMPLEMENT);
  92.  
  93. } /* Group_Select_Down */
  94.  
  95. static 
  96. void  Group_Move(short X, short Y)
  97. /************************************************************************/
  98. /*                                                                      */
  99. /* Function called when mouse is moved to select a group.        */
  100. /* X, Y are the actual coordinates in the active window 'Win'.        */
  101. /*                                                                      */
  102. /************************************************************************/
  103. {
  104.     Vector_T      Pos;
  105.     short      View_Id;
  106.  
  107.     if (!Group_Active) return;
  108.  
  109.     View_Id = Screen_To_World(X, Y, Pos);
  110.     if (View_Id != Group_View_Id) return;
  111.  
  112.     /* Remove old selection box */
  113.  
  114.     if (Group_X1 != Group_X2 && Group_Y1 != Group_Y2) {
  115.  
  116.         Move(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  117.         Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y2);
  118.         Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y2);
  119.         Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y1);
  120.         Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  121.  
  122.     } /* if */
  123.  
  124.  
  125.     Group_X2 = X;
  126.     Group_Y2 = Y;
  127.  
  128.     /* Draw new selection box */
  129.  
  130.     if (Group_X1 != Group_X2 && Group_Y1 != Group_Y2) {
  131.  
  132.         Move(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  133.         Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y2);
  134.         Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y2);
  135.         Draw(Windows[Id_Active_Window].RastPort, Group_X2, Group_Y1);
  136.         Draw(Windows[Id_Active_Window].RastPort, Group_X1, Group_Y1);
  137.  
  138.     } /* if */
  139.  
  140. } /* Group_Move */
  141.  
  142.  
  143. static
  144. Boolean_T Group_Handle_Event(struct IntuiMessage *Msg)
  145. /************************************************************************/
  146. /*                                                                      */
  147. /* Event handler routine for the 'ADD' mode.                */
  148. /* Events handled:                            */
  149. /*    Select down: Start mark group.                    */
  150. /*    Select up: End mark group.                    */
  151. /*    Mousemove: Change group area.                    */
  152. /*                                                                      */
  153. /************************************************************************/
  154. {
  155.  
  156.     switch (Msg->Class) {
  157.  
  158.  
  159.     case IDCMP_MOUSEBUTTONS:
  160.         /* Msg->Code contain id of button pressed         */
  161.         /* Msg->MouseX and Msg->MouseY contain mouse position             */
  162.  
  163.     switch(Msg->Code) {
  164.  
  165.     case SELECTDOWN:
  166.         Group_Select_Down(Msg->MouseX, Msg->MouseY);
  167.         return(TRUE);
  168.  
  169.     case SELECTUP:
  170.         Group_Select_Up();
  171.         return(TRUE);
  172.  
  173.     } /* switch (Msg->Code) */
  174.     break;
  175.  
  176.     case IDCMP_MOUSEMOVE:
  177.         Group_Move(Msg->MouseX, Msg->MouseY);
  178.     return(TRUE);
  179.  
  180.     } /* switch (Msg->Class) */
  181.  
  182.     return(FALSE);
  183.  
  184. } /* Group_Handle_Event */
  185.  
  186. void Set_Mode_Group()
  187. /************************************************************************/
  188. /*                                                                      */
  189. /* Change to GROUP mode.                        */
  190. /*                                                                      */
  191. /************************************************************************/
  192. {
  193.     Group_Active        = FALSE;
  194.     State.Handle_Event        = Group_Handle_Event;
  195.     State.Redraw        = Normal_Redraw;
  196.  
  197.     Display_Status("Group");
  198.  
  199.  
  200. } /* Set_Mode_Group */
  201.