source to amiga dot graphics demo
Dale Luck
dale at amiga.UUCP
Fri Oct 25 11:27:11 AEST 1985
For those that are interested, here is a sample program that uses the
window libraries and message stuff on the amiga. If there is going to be
significant quantities of shared amiga source maybe we should have an
net.sources.amiga
Happy Hacking
Dale
#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;
}
}
}
More information about the Comp.sources.unix
mailing list