Thread View: mod.amiga.sources
1 messages
1 total messages
Started by doc
Mon, 14 Jul 1986 18:28
Super.c
Author: doc
Date: Mon, 14 Jul 1986 18:28
Date: Mon, 14 Jul 1986 18:28
348 lines
10734 bytes
10734 bytes
Return-Path: ihnp4!cbmvax!carolyn@ecn
Reply-To: ihnp4!cbmvax!carolyn@ecn (Carolyn Scheppner)
Here is the source for an example written by myself and phil lindsay.
It is a fairly simple SuperBitMap drawing-scrolling-printing demo.
It shows how to use ScrollLayer, how to sync (update) the SuperBitMap
prior to printing (would also be needed before saving), and how to
create a dummy rastport for dumping the SuperBitMap.
Note that this demo must be run under 1.2 to work properly. If run
under 1.1, when the SuperBitMap is scrolled to a position other than
the origin, the lines drawn offscreen will be lost.
* Moderators note: Carolyn means that it won't run under 1.1 Workbench,
not the compiler. This program can be compiled under 1.1 and run under
1.2. It is also very neat!
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CBM >>Amiga Technical Support<<
UUCP ...{allegra,caip,ihnp4,seismo}!cbmvax!carolyn
PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--------------------------------------------------------------------------
/* Super.c - superbitmap scrolling and printing demo - Requires 1.2 */
/* phillip lindsay / carolyn scheppner */
/* CBM 06/30/86 */
#include "exec/types.h"
#include "exec/execbase.h"
#include "exec/exec.h"
#include "graphics/gfxbase.h"
#include "graphics/rastport.h"
#include "graphics/layers.h"
#include "intuition/intuition.h"
#include "devices/printer.h"
/* constants */
#define SBWIDTH 800
#define SBHEIGHT 400
#define WIDTH 640
#define HEIGHT 200
#define MAXWIDTH WIDTH
#define MAXHEIGHT HEIGHT
#define MINWIDTH (MAXWIDTH/16)
#define MINHEIGHT (MAXHEIGHT/8)
#define DEPTH 2 /* bitplanes */
#define COLORS 4 /* COLORS = pow(DEPTH,2); */
#define NORMAL -1 /* value used for normal Abort() */
/* functions we want to declare */
long OpenLibrary();
struct IntuiMessage *GetMsg();
struct Window *OpenWindow();
/* external I want to see */
extern long SysBase;
/* working base pointers - pre-initialized for simplified aborting */
struct GfxBase *GfxBase = 0;
struct IntuitionBase *IntuitionBase = 0;
/* our window structures...*/
struct NewWindow mynuwindow =
{
0,0,WIDTH,HEIGHT,
0,1,
CLOSEWINDOW | VANILLAKEY,
GIMMEZEROZERO | SUPER_BITMAP | WINDOWDEPTH | WINDOWCLOSE |
WINDOWSIZING | WINDOWDRAG | ACTIVATE,
NULL,NULL,
"1.2 SuperBitMap Demo - SPACE=Draw/Pause UDLR=Scroll P=Print Q=Quit",
NULL,
NULL,
MINWIDTH,MINHEIGHT,
MAXWIDTH,MAXHEIGHT,
WBENCHSCREEN
};
/* Window related structures */
struct Window *mywindow;
struct ViewPort *vp;
struct RastPort *rp;
struct BitMap bitmap;
/* Intuition IDCMP stuff */
struct IntuiMessage *msg;
ULONG class;
USHORT code;
/* Layer stuff */
ULONG LayersBase;
struct Layer *l;
struct Layer_Info *li;
/**************************************************************************/
main()
{
long count, /* misc. loop var. */
gapX, gapY, /* holds current val for the line gap */
cycle, /* this is the current color register being used */
x,y; /* current line dest. coor. */
UBYTE do_close; /* this flag is TRUE for window close gadget selected */
UBYTE freeze; /* flag to freeze display */
int error; /* for return value of superDump() */
int deltaX, deltaY; /* scroll deltas */
int k;
/* Initialize PLANEPTR's to ZERO for simple deallocating */
for(k=0; k<DEPTH; k++) bitmap.Planes[k] = NULL;
GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0);
Abort(GfxBase,"Can't open Graphics library");
IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0);
Abort(IntuitionBase,"Can't open Intuition library");
LayersBase = OpenLibrary("layers.library",0);
Abort(LayersBase,"Can't open Layers library");
/* let's get our bitplanes */
InitBitMap(&bitmap,DEPTH,SBWIDTH,SBHEIGHT);
for(count=0;count < DEPTH;count++)
if((bitmap.Planes[count] = (PLANEPTR) AllocRaster(SBWIDTH,SBHEIGHT)) == NULL)
Abort(NULL,"No memory for bitplanes.");
else
BltClear(bitmap.Planes[count],RASSIZE(SBWIDTH,SBHEIGHT),NULL);
mynuwindow.BitMap = &bitmap; /* tell mynuwindow where our bitmap is */
Abort((mywindow = OpenWindow(&mynuwindow)),"Can't open window");
rp = mywindow->RPort;
vp = (struct ViewPort *) ViewPortAddress(mywindow);
l = rp->Layer;
li = l->LayerInfo;
deltaX = 4;
deltaY = 2;
SetDrMd(rp,JAM1);
/* Initialize flags to defaults */
do_close=0x00;
freeze = FALSE;
/* Loop until close gadget hit */
while(!do_close)
{
if(!freeze)
{
x = RangeRand(SBWIDTH);
y = RangeRand(SBHEIGHT);
gapX = RangeRand(4)+2;
gapY = RangeRand(4)+2;
cycle = RangeRand(4);
SetAPen(rp,cycle);
for (; ((x < SBWIDTH)&&(y > 0)); x += gapX, y -= gapY)
{
Move(rp,0,y);
Draw(rp,x,0);
Move(rp,SBWIDTH-1-x,0);
Draw(rp,SBWIDTH-1,y);
Move(rp,SBWIDTH-1,SBHEIGHT-1-y);
Draw(rp,SBWIDTH-1-x,SBHEIGHT-1);
Move(rp,x,SBHEIGHT-1);
Draw(rp,0,SBHEIGHT-1-y);
}
}
while(msg=(struct IntuiMessage *)GetMsg(mywindow->UserPort))
{
class = msg->Class;
code = msg->Code;
ReplyMsg(msg);
switch(class)
{
case CLOSEWINDOW:
do_close = TRUE;
break;
case VANILLAKEY:
switch(code)
{
case 'u':
if((l->Scroll_Y + deltaY) < maxYScroll(mywindow) )
ScrollLayer(li,l,0,deltaY);
break;
case 'd':
if((l->Scroll_Y - deltaY) > 0 )
ScrollLayer(li,l,0,-deltaY);
break;
case 'l':
if((l->Scroll_X + deltaX) < maxXScroll(mywindow) )
ScrollLayer(li,l,deltaX,0);
break;
case 'r':
if((l->Scroll_X-deltaX) > 0 )
ScrollLayer(li,l,-deltaX,0);
break;
case ' ':
freeze = (freeze == TRUE) ? FALSE : TRUE;
break;
case 'p':
/* ScreenDump of SuperBitMap */
error = superDump(rp,vp);
if (error) printf("DumpRPort error = %ld\n",error);
break;
case 'q':
do_close = TRUE;
break;
}
}
}
}
Abort(NORMAL,"\nGoodbye..");
}
/* Abort - an easy going exit routine - if val <= 0 a clean-up and exit will */
/* take place...val == 0 implies ERROR...val == -1 implies normal exit */
/* and val >= 1 implies no exit or error */
Abort(val,str)
long val;
UBYTE *str;
{
long count;
if(val < 1)
{
puts(str);
if(mywindow) msgflush(),CloseWindow(mywindow);
if(bitmap.Planes[0] != NULL)
for(count=0;(bitmap.Planes[count] != NULL) && (count < 8);count++)
FreeRaster(bitmap.Planes[count],SBWIDTH,SBHEIGHT);
if(GfxBase) CloseLibrary(GfxBase);
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(LayersBase) CloseLibrary(LayersBase);
exit(val == 0 ? 1 : 0);
}
}
/* msgflush - get/reply to all messages */
msgflush()
{
while((msg = GetMsg(mywindow->UserPort))) ReplyMsg(msg);
}
int maxXScroll(w)
struct Window *w;
{
return(SBWIDTH - (w->Width - w->BorderLeft - w->BorderRight));
}
int maxYScroll(w)
struct Window *w;
{
return(SBHEIGHT - (w->Height - w->BorderTop - w->BorderBottom));
}
/***************************/
/* SuperBitmap Screen Dump */
/***************************/
superDump(rp,vp)
struct RastPort *rp;
struct ViewPort *vp;
{
/* printer stuff */
union printerIO {
struct IOStdReq ios;
struct IODRPReq iodrp;
struct IOPrtCmdReq iopc;
};
union printerIO *request;
extern struct IORequest *CreateExtIO();
extern struct MsgPort *CreatePort();
struct MsgPort *printerPort;
struct RastPort dRastPort; /* Dummy RastPort */
int error;
/* Lock the Layer */
/* Update the SuperBitmap */
/* Copy window's Rastport structure to dummy */
/* Insert ptr to our SuperBitmap */
/* NULL the Layer pointer */
/* Unlock the Layer */
LockLayerRom(rp->Layer);
SyncSBitMap(rp->Layer);
dRastPort = *rp;
dRastPort.BitMap = rp->Layer->SuperBitMap;
dRastPort.Layer = NULL;
UnlockLayerRom(rp->Layer);
printerPort = CreatePort("my.print.port",0);
request = (union printerIO *)CreateExtIO(printerPort,
sizeof(union printerIO));
error = OpenDevice("printer.device",0,request,0);
if(error != 0) goto cleanup2;
request->iodrp.io_Command = PRD_DUMPRPORT;
request->iodrp.io_RastPort = &dRastPort;
request->iodrp.io_ColorMap = vp->ColorMap;
request->iodrp.io_Modes = (ULONG)vp->Modes;
/* request->iodrp.io_SrcX = 0; MEMF_CLEAR zeroed this */
/* request->iodrp.io_SrcY = 0; MEMF_CLEAR zeroed this */
request->iodrp.io_SrcWidth = SBWIDTH;
request->iodrp.io_SrcHeight = SBHEIGHT;
request->iodrp.io_DestCols = SBWIDTH;
/* request->iodrp.io_DestRows = 0; MEMF_CLEAR zeroed this */
request->iodrp.io_Special = SPECIAL_ASPECT;
error = DoIO(request);
CloseDevice(request);
cleanup2:
DeleteExtIO(request, sizeof(union printerIO));
DeletePort(printerPort);
cleanup1:
cleanup0:
return(error);
} /* end of demo screen dump */
/* EOF */
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads