home *** CD-ROM | disk | FTP | other *** search
- /* View Gad.c
- Source code for View Gadgets. These are very
- handy little gadgets. This is only a small
- demo, there is more you can do. I don't
- believe this is documented by Viona yet,
- so look at include:egs/clib/gbview_protos.h
- for the functions.
-
- Patrick Hager, Great Valley Products Inc.
- November 6, 1993.
- */
- #include <stdio.h>
- #include <stdlib.h>
- #include "/global/userwindow.h"
- #include "/global/egslibraries.h"
-
- #include <clib/alib_protos.h>
- #include <clib/exec_protos.h>
- #include <egs/egs.h>
- #include <egs/clib/egs_protos.h>
- #include <egs/pragmas/egs_pragmas.h>
- #include <egs/egsintui.h>
- #include <egs/clib/egsintui_protos.h>
- #include <egs/pragmas/egsintui_pragmas.h>
- #include <egs/egsgadbox.h>
- #include <egs/clib/egsgadbox_protos.h>
- #include <egs/pragmas/egsgadbox_pragmas.h>
- #include <egs/egb/gbview.h>
- #include <egs/clib/gbview_protos.h>
- #include <egs/pragmas/gbview_pragmas.h>
-
- #define VIEWGAD_ID 400
- #define ZOOM_BASE_ID 500 // Only one ID for a multi action.
- // 500 = first, 501 = second etc.
-
- struct UserInputWindow Example_Request;
- struct EGB_ViewGadget *ViewGad; // It is very handy to keep a pointer to the
- // View gad once we've created it, so we
- // can modify it later.
- E_EBitMapPtr Example_BitMap; // This is the actual image we view through the
- // viewgad.
-
- struct MsgPort *ExamplePort; // Our Port.
- WORD ViewGad_Zoom=0; // Our current zoom factor.
- BYTE Quit_Example=0; // Flag to quit the program.
-
-
- // Prototypes
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow);
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress);
- void Redraw_Example (UserInputWindowPtr UserWindow);
- void Close_Example (UserInputWindowPtr UserWindow);
-
- void main (void) {
- FILE *fp;
- WORD sizex, sizey;
- EI_EIntuiMsgPtr Mesg;
-
- if (OpenEGSLibraries ()) {
- if (ExamplePort = CreatePort (0,0)) {
- if (fp = fopen ("picture.raw","rb")) {
- fread ((char *)&sizex,2,1,fp);
- fread ((char *)&sizey,2,1,fp);
- if (Example_BitMap = E_AllocBitMap (sizex,sizey,24,E_PIXELMAP,0,NULL)) {
- // Load picture to our bitmap.
- // ALLWAYS lock your memory before accesing
- // directly.
- ++Example_BitMap->Lock;
- fread ((char *)Example_BitMap->Plane,4,sizex*sizey,fp);
- --Example_BitMap->Lock;
-
- Init_UserWindow (&Example_Request, "Example Window",WINDOW_NONMODAL,NULL,
- ExamplePort);
- Example_Request.Create = Create_Example;
- Example_Request.GadgetDown = GadgetDown_Example;
- Example_Request.Redraw = Redraw_Example;
- Example_Request.Close = Close_Example;
-
- Example_Request.IDCMPFlags = EI_iCLOSEWINDOW | EI_iSIZEVERIFY |
- EI_iNEWSIZE |
- EI_iGADGETDOWN;
- Example_Request.Flags = EI_GIMMEZEROZERO| EI_SIZEBBOTTOM| EI_SIMPLE_REFRESH;
- Example_Request.SysGadgets = (EI_WINDOWCLOSE)|(EI_WINDOWSIZE)|EI_WINDOWDRAG;
-
- if (Open_UserWindow (&Example_Request,-1,-1)) {
- EGB_ModifyBMZoomViewGadget (Example_Request.Window,ViewGad,
- Example_BitMap,0,0,0);
- while (!Quit_Example) {
- WaitPort (ExamplePort);
- while (Mesg=(struct EI_EIntuiMsg *)GetMsg (ExamplePort)) {
- if ( ((WindowInfoPtr)Mesg->IDCMPWindow->UserData)->EventHandler) {
- ((WindowInfoPtr)Mesg->IDCMPWindow->UserData)->EventHandler (Mesg);
- }
- }
- }
- Close_All_UserWindows ();
- }
- else
- printf ("Couldn't open my window!\n");
- if (Example_BitMap)
- E_DisposeBitMap (Example_BitMap);
- }
- else
- printf ("Couldn't alloc the memory for my image!\n");
- }
- else
- printf ("Couldn't open file pointer for my image!\n"
- "Picture.raw must be in the same directory as me.\n");
- DeletePort (ExamplePort);
- }
- else
- printf ("Couldn't open my Port!\n");
- }
- CloseEGSLibraries (); // after the bracket cause what if I opened 3 but
- // couldn't find the rest, still need to close the 3.
- }
-
- /*************************************
- PRIVATE: Create_Example.
- This routine is called by the UserWindow routines.
- It passes back a GadBoxPtr to the gadgets wanted.
- *************************************/
- EB_GadBoxPtr Create_Example (UserInputWindowPtr UserWindow) {
- EB_GadBoxPtr root, box;
- EB_GadContext gadcon;
- EB_StrArray names = {"Zoom in", "Zoom out",NULL};
-
- gadcon = UserWindow->GadCon;
-
- root = EB_CreateVertiBox (gadcon);
- box= EGB_CreateViewGadget (gadcon,32,4000,32,4000,
- EGB_ViewScrollRight|EGB_ViewScrollBottom,
- VIEWGAD_ID);
- ViewGad = (EGB_ViewGadPtr)box->Render.Gad;
- EB_AddLastSon (root,EB_CreateGroupBorder (gadcon,box,EB_FILL_ALL,
- " View Gadget "));
- EB_AddLastSon (root,EB_CreateVertiFill (gadcon,0,0));
- EB_AddLastSon (root,EB_CreateMultiAction (gadcon,&names,ZOOM_BASE_ID,EB_FILL_ALL));
- return root;
- }
-
- /**************************************
- PRIVATE: GadgetDown_Example.
- This routine handles the gadget down events passed to the
- Example Control Window.
- **************************************/
- void GadgetDown_Example (UserInputWindowPtr UserWindow, EI_GadgetPtr iaddress) {
-
- switch (iaddress->GadgetID) {
- case ZOOM_BASE_ID: // Zoom in
- ++ViewGad_Zoom;
- Redraw_Example (UserWindow);
- break;
- case ZOOM_BASE_ID+1: // Zoom out
- --ViewGad_Zoom;
- Redraw_Example (UserWindow);
- break;
- }
-
- }
- /*************************************
- PRIVATE: Close_Example.
- This routine CANNOT be used to close the Example
- Control Window!!! It is called by the UserWindow
- routines to allow this window to clean up any
- allocated memory.
- To Close the Example Control Window, call
- CloseDown_Example ();
- *************************************/
- void Close_Example (UserInputWindowPtr UserWindow) {
-
- Quit_Example=1;
- }
-
- /**************************************
- PUBLIC: Redraw_Example.
- This routine handles redraw events to the Example
- Control Window. Called by UserWindow routines, and
- could be called by other routines as well.
- Also called on an EI_iREFRESHWINDOW message.
- **************************************/
- void Redraw_Example (UserInputWindowPtr UserWindow) {
-
- // We need to reset the View Gad on a NewSize
- // Message. Redraw is called on a newsize, so we'll
- // do it here.
-
- EGB_ModifyBMZoomViewGadget (Example_Request.Window,ViewGad,
- Example_BitMap,0,0,ViewGad_Zoom);
- }
-