home *** CD-ROM | disk | FTP | other *** search
- #include <exec/types.h>
- #include <intuition/intuition.h>
- #include <intuition/classusr.h>
- #include <libraries/resource.h>
-
- #include <classes/window.h>
- #include <reaction/reaction_macros.h>
-
- #include <gadgets/chooser.h>
- #include <gadgets/integer.h>
- #include <gadgets/slider.h>
-
- #include <proto/exec.h>
- #include <proto/intuition.h>
-
- #ifdef __MIXED_BINARY__
- #include <proto/powerpc.h>
- #endif
-
- #include <proto/resource.h>
- #include <clib/alib_protos.h>
- #include <clib/alib_stdio_protos.h>
-
- #include "glmatrix_gui.h"
- #include "glmatrix_prefs.h"
-
- RESOURCEFILE gui_resource = NULL;;
- Object *gui_window_object = NULL;
-
- struct MsgPort *IDCMP_port = NULL;
- struct MsgPort *app_port = NULL;
-
- struct Screen *gui_pub_screen = NULL;
- struct Window *gui_window = NULL;
- struct Gadget **gui_gadgets = NULL;
-
- ULONG gui_window_signals = 0L;
-
- BOOL window_open = FALSE;
-
- static struct GLMatrixPrefs prefs;
-
- BOOL gui_init(void)
- {
- gui_pub_screen = LockPubScreen("Workbench");
- if (gui_pub_screen != NULL)
- {
- IDCMP_port = CreateMsgPort();
- if (IDCMP_port != NULL)
- {
- app_port = CreateMsgPort();
- if (app_port != NULL)
- {
- gui_resource = RL_OpenResource(RCTResource, gui_pub_screen, NULL);
- if (gui_resource != NULL)
- {
- struct TagItem test[] = { {WINDOW_SharedPort, (ULONG)IDCMP_port},
- {WINDOW_AppPort, (ULONG)app_port},
- TAG_DONE };
-
- gui_window_object = RL_NewObjectA(gui_resource, WIN_1_ID, test);
-
- if (gui_window_object != NULL)
- {
- gui_gadgets = (struct Gadget **)RL_GetObjectArray(gui_resource, gui_window_object, GROUP_3_ID);
-
- glmatrix_prefs = read_prefs();
- if (glmatrix_prefs != NULL)
- {
- CopyMem(glmatrix_prefs, &prefs, sizeof(prefs));
- return TRUE;
- }
- }
- }
- }
- }
-
- }
- return FALSE;
- }
-
- void gui_destroy(void)
- {
- #ifdef __MIXED_BINARY__
- FreeVec32(glmatrix_prefs);
- #else
- FreeVec(glmatrix_prefs);
- #endif
- if (gui_resource != NULL)
- {
- if (gui_window_object != NULL) RL_DisposeObject(gui_resource, gui_window_object);
-
- RL_CloseResource(gui_resource);
- gui_resource = NULL;
- }
-
- if (app_port != NULL) DeleteMsgPort(app_port);
- app_port = NULL;
-
- if (IDCMP_port != NULL) DeleteMsgPort(IDCMP_port);
- IDCMP_port = NULL;
-
-
- /* AAARRRGGGHHH UnLockPubScreen crashes */
- /* if (gui_pub_screen != NULL) UnlockPubScreen("Workbench", gui_pub_screen);
- gui_pub_screen = NULL; */
- }
-
- void set_attr(void)
- {
- struct TagItem tags[] = { 0, TAG_DONE};
-
- tags[0].ti_Tag = INTEGER_Number;
- tags[0].ti_Data = prefs.glm_Timeout;
- SetGadgetAttrsA(gui_gadgets[Timeout_Integer], gui_window, NULL, tags);
-
- tags[0].ti_Data = prefs.glm_Density;
- SetGadgetAttrsA(gui_gadgets[Density_Integer], gui_window, NULL, tags);
-
- tags[0].ti_Data = prefs.glm_Speed;
- SetGadgetAttrsA(gui_gadgets[Speed_Integer], gui_window, NULL, tags);
-
- tags[0].ti_Tag = SLIDER_Level;
- tags[0].ti_Data = prefs.glm_Timeout;
- SetGadgetAttrsA(gui_gadgets[Timeout], gui_window, NULL, tags);
-
- tags[0].ti_Data = prefs.glm_Density;
- SetGadgetAttrsA(gui_gadgets[Density], gui_window, NULL, tags);
-
- tags[0].ti_Data = prefs.glm_Speed;
- SetGadgetAttrsA(gui_gadgets[Speed], gui_window, NULL, tags);
-
- tags[0].ti_Tag = CHOOSER_Selected;
- tags[0].ti_Data = prefs.glm_Encoding;
- SetGadgetAttrsA(gui_gadgets[Encoding], gui_window, NULL, tags);
-
- tags[0].ti_Data = prefs.glm_ScreenSize;
- SetGadgetAttrsA(gui_gadgets[ScreenSize], gui_window, NULL, tags);
-
- tags[0].ti_Tag = GA_Selected;
- tags[0].ti_Data = (ULONG)prefs.glm_Fog;
- SetGadgetAttrsA(gui_gadgets[Fog], gui_window, NULL, tags);
-
- tags[0].ti_Data = (ULONG)prefs.glm_Wave;
- SetGadgetAttrsA(gui_gadgets[Wave], gui_window, NULL, tags);
-
- tags[0].ti_Data = (ULONG)prefs.glm_Rotate;
- SetGadgetAttrsA(gui_gadgets[Rotate], gui_window, NULL, tags);
-
- tags[0].ti_Data = (ULONG)prefs.glm_Invert;
- SetGadgetAttrsA(gui_gadgets[Invert], gui_window, NULL, tags);
- }
-
- void gui_open(void)
- {
- if (gui_window_object != NULL && !window_open)
- {
- /*gui_window = RA_OpenWindow(gui_window_object);*/
- DoMethod(gui_window_object, WM_OPEN, NULL);
- GetAttr(WINDOW_Window, gui_window_object, (ULONG *)&gui_window);
- GetAttr(WINDOW_SigMask, gui_window_object, &gui_window_signals);
-
- set_attr();
- window_open = TRUE;
- }
- }
-
- void gui_close(void)
- {
- if (gui_window_object != NULL && gui_window != NULL && window_open)
- {
- RA_CloseWindow(gui_window_object);
- GetAttr(WINDOW_Window, gui_window_object, (ULONG *)&gui_window);
- gui_window_signals = 0;
- window_open = FALSE;
- }
- }
-
-
-
- void gui_handle_window(void)
- {
- ULONG code = 0;
- ULONG result = 0;
-
- if (gui_window_object != NULL)
- {
- result = RA_HandleInput(gui_window_object, &code);
- while(result != WMHI_LASTMSG)
- {
- switch (result & WMHI_CLASSMASK)
- {
- case WMHI_CLOSEWINDOW:
- {
- /*printf("Close\n");*/
- gui_close();
- break;
- } /* case CLOSEWINDOW */
-
- case WMHI_GADGETUP:
- {
- /* Note: we use RL_GADGETMASK instead of WMHI_GADGETMASK
- * because ReActor ors the gadget ID and the group ID to
- * the final gadget ID. If you want to know in which group
- * the gadget was use (result & RL_GROUPMASK).
- */
-
- ULONG attr = 0;
-
- switch (RL_GADGETID(result))
- {
- case Timeout:
- case Timeout_Integer:
- GetAttr(INTEGER_Number, gui_gadgets[Timeout_Integer], &attr);
- prefs.glm_Timeout = attr;
- /*printf("Timeout: %d\n", timeout);*/
- break;
- case Density:
- case Density_Integer:
- GetAttr(INTEGER_Number, gui_gadgets[Density_Integer], &attr);
- prefs.glm_Density = attr;
- /*printf("Density: %d\n", density);*/
- break;
- case Speed:
- case Speed_Integer:
- GetAttr(INTEGER_Number, gui_gadgets[Speed_Integer], &attr);
- prefs.glm_Speed = attr;
- /*printf("Speed: %d\n", speed);*/
- break;
- case Encoding:
- GetAttr(CHOOSER_Selected, gui_gadgets[Encoding], &attr);
- prefs.glm_Encoding = attr;
- /*printf("Encoding: %d\n", encoding);*/
- break;
- case ScreenSize:
- GetAttr(CHOOSER_Selected, gui_gadgets[ScreenSize], &attr);
- prefs.glm_ScreenSize = attr;
- /*printf("Encoding: %d\n", encoding);*/
- break;
- case Fog:
- GetAttr(GA_Selected, gui_gadgets[Fog], &attr);
- prefs.glm_Fog = (BOOL)attr;
- /*printf("Fog: %d\n", fog);*/
- break;
- case Wave:
- GetAttr(GA_Selected, gui_gadgets[Wave], &attr);
- prefs.glm_Wave = (BOOL)attr;
- /*printf("Wave: %d\n", wave);*/
- break;
- case Rotate:
- GetAttr(GA_Selected, gui_gadgets[Rotate], &attr);
- prefs.glm_Rotate = (BOOL)attr;
- /*printf("Rotate: %d\n", rotate);*/
- break;
- case Invert:
- GetAttr(GA_Selected, gui_gadgets[Invert], &attr);
- prefs.glm_Invert = (BOOL)attr;
- /*printf("Rotate: %d\n", rotate);*/
- break;
- case Save:
- /*printf("Save\n");*/
- CopyMem(&prefs, glmatrix_prefs, sizeof(prefs));
- save_prefs();
- gui_close();
- break;
- /*case Test:
- printf("Test\n");
- break;*/
- case Use:
- CopyMem(&prefs, glmatrix_prefs, sizeof(prefs));
- use_prefs();
- gui_close();
- break;
- case Cancel:
- /*printf("Cancel\n");*/
- CopyMem(glmatrix_prefs, &prefs, sizeof(prefs));
- gui_close();
- break;
- default:
- printf("Unknown\n");
- break;
- } /* switch gadget */
- break;
- } /* case GADGETUP */
- } /* switch result & CLASSMASK */
-
- result = RA_HandleInput(gui_window_object, &code);
- } /* result != LASTMSG */
- }
- }
-
-