home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmigaPlus / Tools / Anwendungen / glmatrix / source / glmatrix_gui.c next >
Encoding:
C/C++ Source or Header  |  2004-01-31  |  9.6 KB  |  292 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuition.h>
  3. #include <intuition/classusr.h>
  4. #include <libraries/resource.h>
  5.  
  6. #include <classes/window.h>
  7. #include <reaction/reaction_macros.h>
  8.  
  9. #include <gadgets/chooser.h>
  10. #include <gadgets/integer.h>
  11. #include <gadgets/slider.h>
  12.  
  13. #include <proto/exec.h>
  14. #include <proto/intuition.h>
  15.  
  16. #ifdef __MIXED_BINARY__
  17. #include <proto/powerpc.h>
  18. #endif
  19.  
  20. #include <proto/resource.h>
  21. #include <clib/alib_protos.h>
  22. #include <clib/alib_stdio_protos.h>
  23.  
  24. #include "glmatrix_gui.h"
  25. #include "glmatrix_prefs.h"
  26.  
  27. RESOURCEFILE gui_resource = NULL;;
  28. Object *gui_window_object = NULL;
  29.  
  30. struct MsgPort *IDCMP_port = NULL;
  31. struct MsgPort *app_port = NULL;
  32.  
  33. struct Screen *gui_pub_screen = NULL;
  34. struct Window *gui_window = NULL;
  35. struct Gadget **gui_gadgets = NULL;
  36.  
  37. ULONG gui_window_signals = 0L;
  38.  
  39. BOOL window_open = FALSE;
  40.  
  41. static struct GLMatrixPrefs prefs;
  42.  
  43. BOOL gui_init(void)
  44. {
  45.     gui_pub_screen = LockPubScreen("Workbench");
  46.     if (gui_pub_screen != NULL)
  47.     {
  48.         IDCMP_port = CreateMsgPort();
  49.         if (IDCMP_port != NULL)
  50.         {
  51.             app_port = CreateMsgPort();
  52.             if (app_port != NULL)
  53.             {
  54.                 gui_resource = RL_OpenResource(RCTResource, gui_pub_screen, NULL);
  55.                 if (gui_resource != NULL)
  56.                 {
  57.                     struct TagItem test[] = { {WINDOW_SharedPort, (ULONG)IDCMP_port},
  58.                                               {WINDOW_AppPort, (ULONG)app_port},
  59.                                               TAG_DONE };
  60.  
  61.                     gui_window_object = RL_NewObjectA(gui_resource, WIN_1_ID, test);
  62.  
  63.                     if (gui_window_object != NULL)
  64.                     {
  65.                         gui_gadgets = (struct Gadget **)RL_GetObjectArray(gui_resource, gui_window_object, GROUP_3_ID);
  66.  
  67.                         glmatrix_prefs = read_prefs();
  68.                         if (glmatrix_prefs != NULL)
  69.                         {
  70.                             CopyMem(glmatrix_prefs, &prefs, sizeof(prefs));
  71.                             return TRUE;
  72.                         }
  73.                     }
  74.                 }
  75.             }
  76.         }
  77.  
  78.     }
  79.     return FALSE;
  80. }
  81.  
  82. void gui_destroy(void)
  83. {
  84. #ifdef __MIXED_BINARY__
  85.     FreeVec32(glmatrix_prefs);
  86. #else
  87.     FreeVec(glmatrix_prefs);
  88. #endif
  89.     if (gui_resource != NULL)
  90.     {
  91.         if (gui_window_object != NULL) RL_DisposeObject(gui_resource, gui_window_object);
  92.  
  93.         RL_CloseResource(gui_resource);
  94.         gui_resource = NULL;
  95.     }
  96.  
  97.     if (app_port != NULL) DeleteMsgPort(app_port);
  98.     app_port = NULL;
  99.  
  100.     if (IDCMP_port != NULL) DeleteMsgPort(IDCMP_port);
  101.     IDCMP_port = NULL;
  102.  
  103.  
  104.     /* AAARRRGGGHHH UnLockPubScreen crashes */
  105. /*    if (gui_pub_screen != NULL) UnlockPubScreen("Workbench", gui_pub_screen);
  106.     gui_pub_screen = NULL; */
  107. }
  108.  
  109. void set_attr(void)
  110. {
  111.     struct TagItem tags[] = { 0, TAG_DONE};
  112.  
  113.     tags[0].ti_Tag  = INTEGER_Number;
  114.     tags[0].ti_Data = prefs.glm_Timeout;
  115.     SetGadgetAttrsA(gui_gadgets[Timeout_Integer], gui_window, NULL, tags);
  116.  
  117.     tags[0].ti_Data = prefs.glm_Density;
  118.     SetGadgetAttrsA(gui_gadgets[Density_Integer], gui_window, NULL, tags);
  119.  
  120.     tags[0].ti_Data = prefs.glm_Speed;
  121.     SetGadgetAttrsA(gui_gadgets[Speed_Integer], gui_window, NULL, tags);
  122.  
  123.     tags[0].ti_Tag  = SLIDER_Level;
  124.     tags[0].ti_Data = prefs.glm_Timeout;
  125.     SetGadgetAttrsA(gui_gadgets[Timeout], gui_window, NULL, tags);
  126.  
  127.     tags[0].ti_Data = prefs.glm_Density;
  128.     SetGadgetAttrsA(gui_gadgets[Density], gui_window, NULL, tags);
  129.  
  130.     tags[0].ti_Data = prefs.glm_Speed;
  131.     SetGadgetAttrsA(gui_gadgets[Speed], gui_window, NULL, tags);
  132.  
  133.     tags[0].ti_Tag  = CHOOSER_Selected;
  134.     tags[0].ti_Data = prefs.glm_Encoding;
  135.     SetGadgetAttrsA(gui_gadgets[Encoding], gui_window, NULL, tags);
  136.  
  137.     tags[0].ti_Data = prefs.glm_ScreenSize;
  138.     SetGadgetAttrsA(gui_gadgets[ScreenSize], gui_window, NULL, tags);
  139.  
  140.     tags[0].ti_Tag  = GA_Selected;
  141.     tags[0].ti_Data = (ULONG)prefs.glm_Fog;
  142.     SetGadgetAttrsA(gui_gadgets[Fog], gui_window, NULL, tags);
  143.  
  144.     tags[0].ti_Data = (ULONG)prefs.glm_Wave;
  145.     SetGadgetAttrsA(gui_gadgets[Wave], gui_window, NULL, tags);
  146.  
  147.     tags[0].ti_Data = (ULONG)prefs.glm_Rotate;
  148.     SetGadgetAttrsA(gui_gadgets[Rotate], gui_window, NULL, tags);
  149.  
  150.     tags[0].ti_Data = (ULONG)prefs.glm_Invert;
  151.     SetGadgetAttrsA(gui_gadgets[Invert], gui_window, NULL, tags);
  152. }
  153.  
  154. void gui_open(void)
  155. {
  156.     if (gui_window_object != NULL && !window_open)
  157.     {
  158.         /*gui_window = RA_OpenWindow(gui_window_object);*/
  159.         DoMethod(gui_window_object, WM_OPEN, NULL);
  160.         GetAttr(WINDOW_Window, gui_window_object, (ULONG *)&gui_window);
  161.         GetAttr(WINDOW_SigMask, gui_window_object, &gui_window_signals);
  162.  
  163.         set_attr();
  164.         window_open = TRUE;
  165.     }
  166. }
  167.  
  168. void gui_close(void)
  169. {
  170.     if (gui_window_object != NULL && gui_window != NULL && window_open)
  171.     {
  172.         RA_CloseWindow(gui_window_object);
  173.         GetAttr(WINDOW_Window, gui_window_object, (ULONG *)&gui_window);
  174.         gui_window_signals = 0;
  175.         window_open = FALSE;
  176.     }
  177. }
  178.  
  179.  
  180.  
  181. void gui_handle_window(void)
  182. {
  183.     ULONG code = 0;
  184.     ULONG result = 0;
  185.  
  186.     if (gui_window_object != NULL)
  187.     {
  188.         result = RA_HandleInput(gui_window_object, &code);
  189.         while(result != WMHI_LASTMSG)
  190.         {
  191.             switch (result & WMHI_CLASSMASK)
  192.             {
  193.                 case WMHI_CLOSEWINDOW:
  194.                 {
  195.                     /*printf("Close\n");*/
  196.                     gui_close();
  197.                     break;
  198.                 } /* case CLOSEWINDOW */
  199.  
  200.                 case WMHI_GADGETUP:
  201.                 {
  202.                     /* Note: we use RL_GADGETMASK instead of WMHI_GADGETMASK
  203.                     * because ReActor ors the gadget ID and the group ID to
  204.                     * the final gadget ID. If you want to know in which group
  205.                     * the gadget was use (result & RL_GROUPMASK).
  206.                     */
  207.  
  208.                     ULONG attr = 0;
  209.  
  210.                     switch (RL_GADGETID(result))
  211.                     {
  212.                         case Timeout:
  213.                         case Timeout_Integer:
  214.                             GetAttr(INTEGER_Number, gui_gadgets[Timeout_Integer], &attr);
  215.                             prefs.glm_Timeout = attr;
  216.                             /*printf("Timeout: %d\n", timeout);*/
  217.                             break;
  218.                         case Density:
  219.                         case Density_Integer:
  220.                             GetAttr(INTEGER_Number, gui_gadgets[Density_Integer], &attr);
  221.                             prefs.glm_Density = attr;
  222.                             /*printf("Density: %d\n", density);*/
  223.                             break;
  224.                         case Speed:
  225.                         case Speed_Integer:
  226.                             GetAttr(INTEGER_Number, gui_gadgets[Speed_Integer], &attr);
  227.                             prefs.glm_Speed = attr;
  228.                             /*printf("Speed: %d\n", speed);*/
  229.                             break;
  230.                         case Encoding:
  231.                             GetAttr(CHOOSER_Selected, gui_gadgets[Encoding], &attr);
  232.                             prefs.glm_Encoding = attr;
  233.                             /*printf("Encoding: %d\n", encoding);*/
  234.                             break;
  235.                         case ScreenSize:
  236.                             GetAttr(CHOOSER_Selected, gui_gadgets[ScreenSize], &attr);
  237.                             prefs.glm_ScreenSize = attr;
  238.                             /*printf("Encoding: %d\n", encoding);*/
  239.                             break;
  240.                         case Fog:
  241.                             GetAttr(GA_Selected, gui_gadgets[Fog], &attr);
  242.                             prefs.glm_Fog = (BOOL)attr;
  243.                             /*printf("Fog: %d\n", fog);*/
  244.                             break;
  245.                         case Wave:
  246.                             GetAttr(GA_Selected, gui_gadgets[Wave], &attr);
  247.                             prefs.glm_Wave = (BOOL)attr;
  248.                             /*printf("Wave: %d\n", wave);*/
  249.                             break;
  250.                         case Rotate:
  251.                             GetAttr(GA_Selected, gui_gadgets[Rotate], &attr);
  252.                             prefs.glm_Rotate = (BOOL)attr;
  253.                             /*printf("Rotate: %d\n", rotate);*/
  254.                             break;
  255.                         case Invert:
  256.                             GetAttr(GA_Selected, gui_gadgets[Invert], &attr);
  257.                             prefs.glm_Invert = (BOOL)attr;
  258.                             /*printf("Rotate: %d\n", rotate);*/
  259.                             break;
  260.                         case Save:
  261.                             /*printf("Save\n");*/
  262.                             CopyMem(&prefs, glmatrix_prefs, sizeof(prefs));
  263.                             save_prefs();
  264.                             gui_close();
  265.                             break;
  266.                         /*case Test:
  267.                             printf("Test\n");
  268.                             break;*/
  269.                         case Use:
  270.                             CopyMem(&prefs, glmatrix_prefs, sizeof(prefs));
  271.                             use_prefs();
  272.                             gui_close();
  273.                             break;
  274.                         case Cancel:
  275.                             /*printf("Cancel\n");*/
  276.                             CopyMem(glmatrix_prefs, &prefs, sizeof(prefs));
  277.                             gui_close();
  278.                             break;
  279.                         default:
  280.                             printf("Unknown\n");
  281.                             break;
  282.                     } /* switch gadget */
  283.                     break;
  284.                 } /* case GADGETUP */
  285.             } /* switch result & CLASSMASK */
  286.  
  287.             result = RA_HandleInput(gui_window_object, &code);
  288.         } /* result != LASTMSG */
  289.     }
  290. }
  291.  
  292.