/*** * toolskel.c -- skeleton tool for b&p * © 1997 Michael Rees (aka Another Option) All rights reserved. ***/ /* ============================================================================= | DATE | WHAT ============================================================================= */ #define DBUG 0 //#define FILEDUMP #include #include #include #include #include #include #include #include #include #include #include #include "bars.h" #include "BarsMacros.h" #include "BPLib.h" //#include "configlib.h" //#include "PopUpPipes.h" #include "proto/toolskel_protos.h" #include "ToolID.h" #include "debug.h" #include "/icons/devicon.h" static UBYTE const versiontag[] = "$VER: Tool_Skeleton 40.9 (09.02.97)"; struct SkelTool { struct Tool tool; }; #define TOOLID _ToolID #define TOOL_SIZE sizeof(struct SkelTool) extern struct IntuitionBase *IntuitionBase; extern struct GfxBase *GfxBase; extern struct LayersBase *LayersBase; extern struct DOSBase *DOSBase; extern struct ExecBase *SysBase; extern struct Functions *functions; /*========================================================================== * inittool * * INPUT: pointer to tool * RETURN: none * * EFFECT: sets tool defaults *=========================================================================*/ static void __regargs inittool(struct SkelTool *tool) { tool->tool.touched |= TOUCH_INIT; } /*========================================================================== * processevent * * INPUT: pointer to Event * RETURN: pointer to Event * * EFFECT: processes events one at a time *=========================================================================*/ static struct Event * __stdargs __saveds processevent(struct Event *event) { struct SkelTool *tool = (struct SkelTool *)event->tool; event->tool = event->tool->next; return(event); } /*========================================================================== * processlist * * INPUT: pointers to tool and list to process, start and stop times * RETURN: pointer to inverted list * * EFFECT: processes a list of events *=========================================================================*/ static struct Event * __stdargs __saveds processlist(struct SkelTool *tool, struct Event *list, long start, long stop) { return(list); } #define tw tool->tool.window /*========================================================================== * edittool * * INPUT: pointer to tool * RETURN: none * * EFFECT: ui handler *=========================================================================*/ static void __stdargs __saveds edittool(struct SkelTool *tool) { struct IntuiMessage *message; long class; long code; struct Gadget *gadget; struct NewWindow *nw; // struct Menu *menu; // struct MenuItem *menuitem; // short menunum; UBYTE refresh; if (!(tool->tool.touched & TOUCH_INIT)) inittool(tool); // menu = functions->DupeMenu(&MenuList1); // if (!menu) return; nw=NewOpenEmbossedWindow(&NewWindowStructure1,&tool->tool,0,WTITLE); if (!nw) return; // if it is a noncritical menu... // if (menu = functions->DupeMenu(&MenuList1)) SetMenuStrip(tw,menu); // else SetWindowTitles(tw,(UBYTE *)-1,MenuList1.MenuName); SetMenuStrip(tw,&MenuList1); PrintIText(tw->RPort,&IntuiTextList1,0,0); EmbossOnGList(tw,&GadgetList1,GCOUNT,1); functions->FatEmbossedPropOn(tw,CONTROLLER,CONTROLLER+GDOWN,CONTROLLER+GUP, hilo,121,1); refresh = 255; // SetRefreshOK(&tool->tool); /*** ui handling ***/ for ( ; ; ) { if (refresh) { DrawEmbossedGList(tw,functions->GetGadget(tw,ON),2); EnableFatProp(tw, CONTROLLER,CONTROLLER+GDOWN,CONTROLLER+GUP, tool->flags & (CCHG | TRIGGER)); functions->ModifyEmbossedProp(tw,CONTROLLER,tool->controller,0,0,0,0,0); functions->DrawEmbossedProp(tw,CONTROLLER); functions->EnableGadget(tw,POP_CC,tool->flags & (CCHG | TRIGGER)); /* if (refresh & REFRESH_POPPIPES) { gadget = functions->GetGadget(tw,POP_DELAY); if (tool->flags & BRANCH_DELAY) gadget->GadgetRender = (APTR)&ElbowImage; else gadget->GadgetRender = (APTR)&PipeImage; gadget = functions->GetGadget(tw,POP_CC); if (tool->flags & DISCARD_CC) gadget->GadgetRender = (APTR)&PlugImage; // else if (tool->flags & BRANCH_CC) gadget->GadgetRender = (APTR)&ElbowImage; else gadget->GadgetRender = (APTR)&PipeImage; gadget = functions->GetGadget(tw,POP_SOURCE); if (tool->flags & BRANCH_SOURCE) gadget->GadgetRender = (APTR)&ElbowImage; else if (tool->flags & DISCARD_SOURCE) gadget->GadgetRender = (APTR)&PlugImage; else gadget->GadgetRender = (APTR)&PipeImage; RefreshGList(gadget,tw,NULL,3); } */ } message = (struct IntuiMessage *)functions->GetIntuiMessage(tw); if (message->ExecMessage.mn_Length == SECRET_MESSAGE) { // ooh, read sysex! refresh = 0xFF; functions->myfree((char *)message,sizeof(struct Message)); continue; } /* else */ class = message->Class; code = message->Code; gadget = (struct Gadget *)message->IAddress; ReplyMsg((struct Message *)message); class = functions->SystemGadgets(tw,class,gadget,code); if (class == CLOSEWINDOW) { // ResetRefreshOK(&tool->tool); break; } else if (class == MENUPICK) { while (code != MENUNULL) { menuitem = ItemAddress(menu,code); switch (ITEMNUM(code)) { default : break; } code = menuitem->NextSelect; } } else if (class == GADGETUP) { switch (gadget->GadgetID) { /* case CONFIG_GADGET_ID : ZoomWindow(tw); break; case SNAPSHOT_GADGET_ID : dosnapshot(tool); break; */ default : break; } } else if (class == GADGETDOWN) { switch (gadget->GadgetID) { default : break; } } } EmbossOffGList(tw,&GadgetList1,GCOUNT); functions->FatEmbossedPropOff(tw,CONTROLLER,CONTROLLER+GDOWN,CONTROLLER+GUP); // functions->DeleteMenu(menu); NewCloseEmbossedWindow(&tool->tool,nw); } /***************** optional poop ********* /*========================================================================== * savesize * * INPUT: pointer to tool * RETURN: bytes required to save the tool * * EFFECT: checks and adds *=========================================================================*/ static long __stdargs __saveds savesize(struct SkelTool *tool) { return(TOOL_SIZE); } /*========================================================================== * createtool * * INPUT: none * RETURN: pointer to Tool * * EFFECT: does unique initialization for an instance of the tool, such as * allocating dynamic structures, initializing tasks or resources. * createtool() must allocate and initialize a Tool structure; B&P * won't do it. *=========================================================================*/ static struct Tool * __stdargs __saveds createtool(void) { } /*========================================================================== * deletetool * * INPUT: pointer to Tool * RETURN: none * * EFFECT: cleans up anything dirtied by createtool() *=========================================================================*/ static void __stdargs __saveds deletetool(struct SkelTool *tool) { } /*========================================================================== * removetool * * INPUT: none * RETURN: none * * EFFECT: removetool() is called when B&P removes the ToolMaster from the * system. called when B&P is closing down, or RemoveTool is selected * from the Toolbox. Usually not needed. *=========================================================================*/ static void __stdargs __saveds removetool(void) { } /*========================================================================== * loadtool * * INPUT: file id, size of chunk to read * RETURN: pointer to allocated tool, or NULL * * EFFECT: allocates and initializes a tool with data read from disk *=========================================================================*/ static struct Tool * __stdargs __saveds loadtool(long file, long size) { struct SkelTool *tool; if (tool = (struct SkelTool *)functions->myalloc(TOOL_SIZE,0)) { functions->fastread(file,(char *)tool,TOOL_SIZE); size -= TOOL_SIZE; } if (size) { /* leftovers */ functions->fastseek(file,size,0); } return((struct Tool *)tool); } /*========================================================================== * savetool * * INPUT: file id, pointer to tool to save * RETURN: 0 if successful; 1 otherwise * * EFFECT: writes a tool's data to a file. * this is mostly lifted from p21r of Rules for Tools documentation. *=========================================================================*/ static long __stdargs __saveds savetool(long file, struct SkelTool *tool) { long size; /* first write the tool's id */ (*functions->fastwrite)(file,&tool->toolmaster->toolid,4); /* then the size of the data */ size = savesize(tool); (*functions->fastwrite)(file,&size,4); /* write the tool data -- even the useless stuff */ (*functions->fastwrite)(file,tool,TOOL_SIZE); /* here, write the unique tool data */ return(0); /* return 0 for success, 1 for trouble */ } /*========================================================================== * drawicon * * INPUT: pointers to tool and RastPort; x,y for location; height * RETURN: none * * EFFECT: redraws the tool's icon at the location passed * * NOTE: got this from Mark; has not been used yet. *=========================================================================*/ static void * __stdargs __saveds drawicon(struct SkelTool *tool, struct RastPort *rp, SHORT x, SHORT y, SHORT height) { return; } /**************************************************************************/ /** looping transport handler **/ /******************************* static void __inline dotransport(struct SkelTool *tool, long command, long time, long end, long offset) { if (!tool->tool.touched) inittool(tool); switch (command) { case TC_STOP : break; case TC_START : case TC_PLAY : break; case TC_TICK : break; } } *********/ static struct ToolMaster master; /********** /*========================================================================== * transportcode * * INPUT: command, time, endtime, offset * RETURN: none * * EFFECT: looping transport skeleton *=========================================================================*/ static void __stdargs __saveds transportcode(command, time, end, offset) register long command; register long time; register long end; long offset; { register struct SkelTool *tool; register struct Track *track; if ((time -= offset) < 0) time = 0; if (functions->multiin) track = (struct Track *)functions->tracklist; else track = master.intrack; for ( ; track ; track=track->next ) { tool = (struct SkelTool *)track->toollist; for ( ; tool ; tool=(struct SkelTool *)tool->tool.next ) { if (tool->tool.toolid == TOOLID) { dotransport(tool,command,time,end-offset,offset); } } } } ************/ /*========================================================================== * inittoolmaster * * INPUT: none * RETURN: pointer to ToolMaster * * EFFECT: initializes. *=========================================================================*/ struct ToolMaster * __stdargs __saveds inittoolmaster(void) { memset((char *)&master,0,sizeof(struct ToolMaster)); master.toolsize = TOOL_SIZE; master.toolid = TOOLID; master.edittool = edittool; master.processevent = processevent; master.processlist = processlist; /*** these are the optional routines master.removetool = removetool; master.savesize = savesize; master.savetool = savetool; master.loadtool = loadtool; master.createtool = createtool; master.deletetool = deletetool; master.drawtoolicon = drawicon; ***/ master.image = &ImageDown; strcpy(master.name,WTITLE); master.tooltype = TOOL_NORMAL; // functions->installtransportpl((void *)transportcode,0); return(&master); }