bart@amiga.UUCP (Barry A. Whitebook) (06/13/86)
< eat this line - please! > /***************************************************************/ lbnc.c /***************************************************************/ #include <exec/types.h> #include <exec/nodes.h> #include <exec/lists.h> #include <exec/ports.h> #include <graphics/gfx.h> #include <graphics/clip.h> #include <graphics/view.h> #include <graphics/rastport.h> #include <graphics/layers.h> #include <intuition/intuition.h> #define COPY NANBC|NABC|ABNC|ABC long seed[] = {0xB807C324, 0x9E8732B5, 0x4E50957BC}; /* random number generator */ rand(i) register short i; { return(seed[i] = seed[i] < 0 ? seed[i] << 1 ^ 0x1D872B41 : seed[i] << 1); } #define RWidth Get_RWidth(w) #define RHeight Get_RHeight(w) #define MAX_CLOSEWINDOW 1 /* #define DEBUG */ /* #define KPRINTF */ #ifdef KPRINTF #define printf kprintf #endif int close_count; extern struct Gadget *vgadget_ptr; extern struct Gadget *hgadget_ptr; lbnc(w) struct RastPort *w; { register long i; short lx,ly,lvx,lvy; short rx,ry,rvx,rvy; short clrDepth,linDepth; struct Layer *l; int counter; int lcounter; int xoffset,yoffset; struct Window *window; struct IntuiMessage *message; close_count = MAX_CLOSEWINDOW; counter = 0; lcounter = 0; l = w->Layer; lx = 0; ly = 0; rx = 30; ry = 10; lvx = 2; lvy = 3; rvx = 5; rvy = 7; clrDepth = 320; linDepth = 160; SetDrMd(w,1); xoffset = Get_xoffset(w); yoffset = Get_yoffset(w); #ifdef DEBUG printf("xoffset = %ld yoffset = %ld\n",xoffset,yoffset); #endif if (l) window = l->Window; restart: while ((message = (struct IntuiMessage *)GetMsg(window->UserPort)) == 0) { if (clrDepth-- == 0) { clrDepth = 320; SetAPen(w,w->FgPen+1); } if (linDepth-- == 0) { newvel(&lvx); newvel(&lvy); newvel(&rvx); newvel(&rvy); linDepth = 320; } Move(w,xoffset+lx,yoffset+ly); Draw(w,xoffset+rx,yoffset+ry); lx += lvx; ly += lvy; rx += rvx; ry += rvy; if (lx<0) zbounce(&lx,&lvx); if (rx<0) zbounce(&rx,&rvx); if (ly<0) zbounce(&ly,&lvy); if (ry<0) zbounce(&ry,&rvy); if (lx>RWidth-1) mbounce(&lx,&lvx,RWidth-1); if (ly>RHeight-1) mbounce(&ly,&lvy,RHeight-1); if (rx>RWidth-1) mbounce(&rx,&rvx,RWidth-1); if (ry>RHeight-1) mbounce(&ry,&rvy,RHeight-1); endit: } switch (message->Class) { case CLOSEWINDOW : { ReplyMsg(message); return; } case GADGETDOWN: { struct IntuiMessage copymsg; /* copy all fields */ copymsg = *message; /* reply to original */ ReplyMsg(message); /* smooth-scroll until gadget is released */ { ULONG old_idcmp_flags; ULONG new_idcmp_flags; /* save old idcmp_flags */ old_idcmp_flags = copymsg.IDCMPWindow->IDCMPFlags; /* listen for ticks as long as gadget is down */ new_idcmp_flags = (old_idcmp_flags | INTUITICKS); ModifyIDCMP(copymsg.IDCMPWindow,new_idcmp_flags); /* loop for intuiticks messages */ { struct IntuiMessage *loopmsg; while((loopmsg = (struct IntuiMessage *) WaitPort(copymsg.IDCMPWindow->UserPort)) && (loopmsg->Class == INTUITICKS)) { if(loopmsg = (struct IntuiMessage *)GetMsg(copymsg.IDCMPWindow->UserPort)) { ReplyMsg(loopmsg); do_gadget_up(©msg); /* draw after smooth scrolling */ { if (clrDepth-- == 0) { clrDepth = 320; SetAPen(w,w->FgPen+1); } if (linDepth-- == 0) { newvel(&lvx); newvel(&lvy); newvel(&rvx); newvel(&rvy); linDepth = 320; } Move(w,xoffset+lx,yoffset+ly); Draw(w,xoffset+rx,yoffset+ry); lx += lvx; ly += lvy; rx += rvx; ry += rvy; if (lx<0) zbounce(&lx,&lvx); if (rx<0) zbounce(&rx,&rvx); if (ly<0) zbounce(&ly,&lvy); if (ry<0) zbounce(&ry,&rvy); if (lx>RWidth-1) mbounce(&lx,&lvx,RWidth-1); if (ly>RHeight-1) mbounce(&ly,&lvy,RHeight-1); if (rx>RWidth-1) mbounce(&rx,&rvx,RWidth-1); if (ry>RHeight-1) mbounce(&ry,&rvy,RHeight-1); } /* done drawing */ } } /* next message was not a tick */ } /* restore old idcmp_flags */ ModifyIDCMP(copymsg.IDCMPWindow,old_idcmp_flags); } } break; case GADGETUP: { struct IntuiMessage copymsg; /* copy all fields */ copymsg = *message; /* reply to original */ ReplyMsg(message); /* process message */ do_gadget_up(©msg); } break; case SIZEVERIFY: { ReplyMsg(message); /* wait for newsize */ WaitPort(window->UserPort); } break; case NEWSIZE: { struct IntuiMessage copymsg; /* copy all fields */ copymsg = *message; /* reply to original */ ReplyMsg(message); /* provide vertical gadget address */ copymsg.IAddress = vgadget_ptr; /* set vertical scroll */ do_gadget_up(©msg); /* bart - 04.23.86 */ /* re-calculate vertical pot body for new size */ { struct Window *w; struct RastPort *rp; struct Layer *l; if(w = copymsg.IDCMPWindow) { if(rp = w->RPort) { if(l = rp->Layer) { struct PropInfo *pi; UWORD sb_height; ULONG rel_body; pi = (struct PropInfo *)vgadget_ptr->SpecialInfo; sb_height = l->SuperBitMap->Rows; rel_body=(MAXPOT*(usable_height(w)))/(sb_height); ModifyProp(vgadget_ptr, window, NULL, pi->Flags, pi->HorizPot, pi->VertPot, pi->HorizBody, rel_body); } } } } /* provide vertical gadget address */ copymsg.IAddress = hgadget_ptr; /* set horizontal scroll */ do_gadget_up(©msg); /* bart - 04.23.86 */ /* re-calculate horizontal pot body for new size */ { struct Window *w; struct RastPort *rp; struct Layer *l; if(w = copymsg.IDCMPWindow) { if(rp = w->RPort) { if(l = rp->Layer) { struct PropInfo *pi; UWORD bb_width; ULONG rel_body; pi = (struct PropInfo *)hgadget_ptr->SpecialInfo; bb_width = l->SuperBitMap->BytesPerRow << 3; rel_body=(MAXPOT*(usable_width(w)))/(bb_width); ModifyProp(hgadget_ptr, window, NULL, pi->Flags, pi->HorizPot, pi->VertPot, rel_body, pi->VertBody); } } } } } break; default: { ReplyMsg(message); } break; } goto restart; } newvel(v) short *v; { *v = (15 & rand(0)) - 7; } zbounce(p,v) short *p,*v; { *p = -*p; *v = -*v; } mbounce(p,v,c) short *p,*v; short c; { *p = 2*c - *p; *v = -*v; }
bart@amiga.UUCP (Barry A. Whitebook) (06/13/86)
< eat this line - please! > /***************************************************************/ start_lines.c /***************************************************************/ #define MAXPOINTS 50 #define TMPRASWIDTH 640 #define TMPRASHEIGHT 200 #define NTSC_HEIGHT 200 #define PAL_HEIGHT 256 #define NTSC_MAX_HEIGHT 200 #define PAL_MAX_HEIGHT 256 #include <exec/types.h> #include <exec/nodes.h> #include <exec/lists.h> #include <graphics/gfx.h> #include <graphics/gfxbase.h> #include <graphics/clip.h> #include <graphics/rastport.h> #include <graphics/view.h> #include <graphics/text.h> #include <graphics/gfxmacros.h> #include <graphics/layers.h> #include <intuition/intuition.h> /*#define DEBUG*/ /*#define KPRINTF*/ /*#define NEWSCREEN*/ #ifdef KPRINTF #define printf kprintf #endif #define TXHEIGHT 8 #define GADGETS #define RBG_ID 0x0001 #define BBG_ID 0x0002 struct Image bb_knob_image; struct PropInfo bb_knob = { FREEHORIZ | AUTOKNOB, 0, 0, MAXBODY/8, MAXBODY }; struct Gadget bb_gadget = { NULL, 0,-8,-16,9, GRELWIDTH|GRELBOTTOM, GADGIMMEDIATE|RELVERIFY|BOTTOMBORDER, GZZGADGET|PROPGADGET, &bb_knob_image, NULL, NULL, 0, &bb_knob, BBG_ID, NULL }; struct Image rb_knob_image; struct PropInfo rb_knob = { FREEVERT | AUTOKNOB, 0, 0, MAXBODY, MAXBODY/8 }; struct Gadget rb_gadget = { &bb_gadget, -15,10,16,-18, GRELHEIGHT|GRELRIGHT, GADGIMMEDIATE|RELVERIFY|RIGHTBORDER, GZZGADGET|PROPGADGET, &rb_knob_image, NULL, NULL, 0, &rb_knob, RBG_ID, NULL }; struct Gadget *vgadget_ptr = &rb_gadget; struct Gadget *hgadget_ptr = &bb_gadget; struct TextAttr TestFont = { "topaz.font", TXHEIGHT, 0, 0, }; long GfxBase = 0; long LayersBase = 0; long IntuitionBase = 0; #define IS_PAL (((struct GfxBase *)GfxBase)->DisplayFlags & PAL) struct AreaInfo areainfo; UWORD areafill[(MAXPOINTS/2)*5]; startgfx(x,y,height, width, n_bit_Planess, palette, gfxproc,s,flags,sbitmap) WORD x,y; WORD height, width, n_bit_Planess; UWORD *palette; int (*gfxproc)(); UBYTE *s; struct BitMap *sbitmap; /* optional parameter */ { struct Window *window; struct RastPort *w=0; register i, j; int idcmp; struct NewWindow nw; UBYTE *ras; GfxBase = OpenLibrary("graphics.library",32); if (GfxBase == NULL) { #ifdef DEBUG printf("no graphics library\n"); #endif exit(); } LayersBase = OpenLibrary("layers.library",32); if (LayersBase == NULL) { #ifdef DEBUG printf("no layers library\n"); #endif exit(); } IntuitionBase = OpenLibrary("intuition.library",32); if (IntuitionBase == NULL) { #ifdef DEBUG printf("no intuition library\n"); #endif exit(); } /* intuition direct comunication message port */ idcmp = CLOSEWINDOW|REFRESHWINDOW|GADGETUP|GADGETDOWN|SIZEVERIFY|NEWSIZE; nw.LeftEdge = x; nw.TopEdge = y; nw.Width = width; nw.Height = height; nw.DetailPen = -1; nw.BlockPen = -1; nw.IDCMPFlags = idcmp; nw.Flags = WINDOWDEPTH|WINDOWSIZING|WINDOWDRAG|WINDOWCLOSE|flags; nw.FirstGadget = 0; #ifdef GADGETS nw.FirstGadget = &rb_gadget; #endif nw.CheckMark = 0; nw.Title = s; nw.Screen = 0; nw.BitMap = sbitmap; nw.MinWidth = 80; nw.MinHeight = 16; nw.MaxWidth = 640; nw.MaxHeight = ~0; /* V32 and above */ nw.Type = WBENCHSCREEN; #ifdef DEBUG printf("calling open window\n sbitmap=%lx\n",nw.BitMap); #endif window = (struct Window *)OpenWindow(&nw); /* bart - 11.21.85 */ if (!window) return; #ifdef DEBUG printf("after call to open window\n"); #endif /* bart - 11.13.85 */ SetWindowTitles(window,-1,s); w = window->RPort; w->Layer->Window = window; InitArea(&areainfo,areafill,MAXPOINTS); w->AreaInfo = &areainfo; (*gfxproc)(&window->WScreen->ViewPort,w); CloseWindow(window); /* restart workbench screen */ #ifdef NEWSCREEN CloseScreen(ActiveGroup.ActiveScreen); myscreen = OpenScreen(0,0,640,200,2,HIRES,WBENCHSCREEN,&TestFont); #endif } Get_RWidth(rp) struct RastPort *rp; { int width; struct Layer *cw; if ( (cw = rp->Layer) == 0) width = rp->BitMap->BytesPerRow<<3; else if (cw->SuperBitMap == 0) width = cw->bounds.MaxX-cw->bounds.MinX + 1; else width = cw->SuperBitMap->BytesPerRow<<3; if (cw) { struct Window *window; window = cw->Window; if (window) { if ((window->Flags & GIMMEZEROZERO) == 0) width -= window->BorderLeft+window->BorderRight; } } return (width); } Get_RHeight(rp) struct RastPort *rp; { int height; struct Layer *cw; if ( (cw = rp->Layer) == 0) height = rp->BitMap->Rows; else if (cw->SuperBitMap == 0) height = cw->bounds.MaxY-cw->bounds.MinY + 1; else height = cw->SuperBitMap->Rows; if (cw) { struct Window *window; if (window = cw->Window) if ((window->Flags & GIMMEZEROZERO) == 0) height -= window->BorderTop+window->BorderBottom; } return(height); } struct TmpRas *gettmpras(t,w,h) struct TmpRas *t; int w,h; { char *ras; ras = (char *)AllocRaster(w,h); if (ras == 0) { #ifdef DEBUG printf("no ram for tmpras\n"); #endif exit(1); } return((struct TmpRas *)InitTmpRas(t,ras,RASSIZE(w,h))); } Get_xoffset(rp) struct RastPort *rp; { struct Layer *l; struct Window *window; l = rp->Layer; if (l != 0) { window = l->Window; if (window->Flags & GIMMEZEROZERO) return(0); else return(window->BorderLeft); } else return(0); } Get_yoffset(rp) struct RastPort *rp; { struct Layer *l; struct Window *window; l = rp->Layer; if (l != 0) { window = l->Window; if (window->Flags & GIMMEZEROZERO) return(0); else return(window->BorderTop); } else return(0); } /***************************************************************/