dale@amiga.UUCP (Dale Luck) (10/24/85)
Since there is no net.sources.amiga at this time I am taking the liberty of dropping this demo on ya'all. It is a copy of source to one of the simple graphics demos. This was available on the Amiga support bulletin board about 1 month ago. If there is going to be good quantity of amiga source shared then maybe the powers that be should consider a source.amiga group. We are still a little timid about using this net. We do not want to abuse it. Suggestions and encouragement are welcome. This listing is a few pages. Good luck and have fun. Dale Luck #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> struct IntuitionBase *IntuitionBase; struct GfxBase *GfxBase; #define DEPTH 2 #define WIDTH 100 #define HEIGHT 50 int waiting_for_message = FALSE; char dotty[] = "Dotty Window"; int usable_width(w) struct Window *w; { return (w->Width - w->BorderLeft - w->BorderRight); } int usable_height(w) struct Window *w; { return(w->Height - w->BorderTop - w->BorderBottom); } main() { struct RastPort *rp; struct Window *window; struct NewWindow nw; int x,y,c; int xoffset,yoffset; int width,height; struct IntuiMessage *message; ULONG MessageClass; if (!(GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",1))) { printf("no graphics library!!!\n"); exit(1); } if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",1)) ) { CloseLibrary(GfxBase); printf("no intuition here!!\n"); exit(1); } nw.LeftEdge = 50; nw.TopEdge = 50; nw.Width = WIDTH; nw.Height = HEIGHT; nw.DetailPen = -1; nw.BlockPen = -1; nw.IDCMPFlags = CLOSEWINDOW | REFRESHWINDOW | SIZEVERIFY | NEWSIZE; nw.Flags = WINDOWDEPTH | WINDOWSIZING | WINDOWDRAG | WINDOWCLOSE | SIMPLE_REFRESH; nw.FirstGadget = NULL; nw.CheckMark = NULL; nw.Title = dotty; nw.Screen = NULL; nw.BitMap = NULL; nw.MinHeight = 10; nw.MinWidth = 10; nw.MaxHeight = 200; nw.MaxWidth = 640; nw.Type = WBENCHSCREEN; if (!(window = (struct Window *)OpenWindow(&nw) )) { printf("could not open the window\n"); CloseLibrary(IntuitionBase); CloseLibrary(GfxBase); exit(2); } width = usable_width(window); height = usable_height(window); rp = window->RPort; xoffset = window->BorderLeft; yoffset = window->BorderTop; while (TRUE) /* do this forever, or until user gets bored */ { while (!(message = (struct IntuiMessage *)GetMsg(window->UserPort)) ) { if (waiting_for_message) Wait(1<<window->UserPort->mp_SigBit); else { x = RangeRand(width); y = RangeRand(height); c = RangeRand(32); SetAPen(rp,c); WritePixel(rp,xoffset+x,yoffset+y); } } MessageClass = message->Class; ReplyMsg(message); switch (MessageClass) { case CLOSEWINDOW : CloseWindow(window); CloseLibrary(IntuitionBase); CloseLibrary(GfxBase); exit(0); case SIZEVERIFY : waiting_for_message = TRUE; break; case REFRESHWINDOW: BeginRefresh(window); SetAPen(rp,0); /* should not have to recalculate these */ width = usable_width(window); height = usable_height(window); RectFill(rp,xoffset,yoffset, xoffset+width-1,yoffset+height-1); EndRefresh(window,TRUE); break; case NEWSIZE : waiting_for_message = FALSE; width = usable_width(window); height = usable_height(window); break; } } } end of source listing