home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD2.bin
/
bbs
/
gfx
/
jpegaga-1.0.lha
/
jpegAGA
/
display.c
next >
Wrap
C/C++ Source or Header
|
1994-05-28
|
6KB
|
232 lines
/* Screen display routines */
/* written by Günther Röhrich */
/* this source is Public Domain */
/* this works only with OS 3.0 or higher */
#define INTUI_V36_NAMES_ONLY
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <graphics/modeid.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <clib/exec_protos.h>
#ifndef __GNUC__
#include <pragmas/intuition_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#endif
#define HAM8 1
struct Library *IntuitionBase = NULL;
struct Library *GfxBase = NULL;
extern int VGAenable;
extern void error_exit(const char *msgtext);
struct Screen *my_screen = NULL;
struct Window *my_window = NULL;
struct RastPort temprp; /* a copy of the screen's RastPort */
int Drow = 0;
void CloseDisplay(void);
/* Initialize the display, colors will be set later */
int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
{
ULONG Depth, DisplayID;
if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 39)))
error_exit("Can't open intuition.library V39 or higher");
if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
error_exit("Can't open graphics.library V39 or higher");
/* Calculate a DisplayID */
/* this should be done better... */
if(VGAenable)
{
if(Mode == HAM8)
{
if(cols > 370 || rows > 260)
DisplayID = VGAPRODUCTHAM_KEY;
else
DisplayID = VGALORESHAMDBL_KEY;
}
else
{
if(cols > 370 || rows >260)
DisplayID = VGAPRODUCT_KEY;
else
DisplayID = VGALORESDBL_KEY;
}
}
else
{
if(Mode == HAM8)
DisplayID = DEFAULT_MONITOR_ID | HAM_KEY;
else
DisplayID = DEFAULT_MONITOR_ID;
if(cols > 370 || rows >260) DisplayID |= HIRES|LACE;
}
if(Mode == HAM8) Depth = 8;
else Depth = NumPlanes;
my_screen = OpenScreenTags(NULL, SA_Width, (ULONG)cols,
SA_Height, (ULONG)rows,
SA_Depth, (ULONG)Depth,
SA_DisplayID, (ULONG)DisplayID,
SA_Type, (ULONG)CUSTOMSCREEN,
SA_Quiet, (ULONG)TRUE,
SA_AutoScroll,(ULONG)TRUE,
SA_Overscan, (ULONG)OSCAN_STANDARD,
TAG_DONE);
if(my_screen == NULL) return 0;
/* open a dummy window to allow autoscroll feature */
my_window = OpenWindowTags(NULL, WA_Left, (ULONG)0,
WA_Top, (ULONG)0,
WA_Width, (ULONG)cols,
WA_Height, (ULONG)rows,
WA_CustomScreen, my_screen,
WA_NoCareRefresh,(ULONG)TRUE,
WA_Borderless, (ULONG)TRUE,
WA_Backdrop, (ULONG)TRUE,
WA_RMBTrap, (ULONG)TRUE, /* disable screen menu drawing */
WA_IDCMP, (ULONG)IDCMP_MOUSEBUTTONS,
WA_Activate, (ULONG)TRUE,
WA_BusyPointer, (ULONG)TRUE, /* V39 only! */
TAG_DONE);
if(my_window == NULL) return 0;
/* initialize temprp for use with WritePixelLine8() */
CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
temprp.Layer = NULL;
/* V39 function */
temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
if(temprp.BitMap == NULL) return 0;
return 1; /* success */
}
/* Set a color... */
void SetDisplayColor(int ColorNumber, UBYTE r, UBYTE g, UBYTE b)
{
if(my_screen)
/* V39 function */
SetRGB32(&my_screen->ViewPort, (ULONG)ColorNumber, (ULONG)r << 24,
(ULONG)g << 24,
(ULONG)b << 24);
}
/* Close the display */
void CloseDisplay(void)
{
if(temprp.BitMap)
{
/* V39 function */
FreeBitMap(temprp.BitMap);
temprp.BitMap = NULL;
}
if(my_window)
{
CloseWindow(my_window);
my_window = NULL;
}
if(my_screen)
{
CloseScreen(my_screen);
my_screen = NULL;
}
if(IntuitionBase)
{
CloseLibrary(IntuitionBase);
IntuitionBase = NULL;
}
if(GfxBase)
{
CloseLibrary(GfxBase);
GfxBase = NULL;
}
}
/* display a line of chunky pixel graphics... */
void DisplayRow(char *array, int cols)
{
if(my_screen)
WritePixelLine8(&my_screen->RastPort, 0, Drow++, cols, array, &temprp);
}
/* check for a right mouse button press */
int CheckButton(void)
{
struct IntuiMessage *msg;
int Button = 0;
if(my_window)
{
while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
{
if(msg->Class == IDCMP_MOUSEBUTTONS)
if(msg->Code == MENUDOWN)
Button = 1;
ReplyMsg((struct Message *)msg);
if(Button) break;
}
}
return Button;
}
/* final wait after the picture is finished */
void FinalWait(void)
{
struct IntuiMessage *msg;
int Button = 0;
/* set the normal pointer */
/* V39 function */
SetWindowPointer(my_window, WA_Pointer, NULL, TAG_DONE);
if(my_window)
{
while(!Button)
{
Wait(1L<<my_window->UserPort->mp_SigBit);
while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
{
if(msg->Class == IDCMP_MOUSEBUTTONS)
if(msg->Code == MENUDOWN)
Button = 1;
ReplyMsg((struct Message *)msg);
if(Button) break;
}
}
}
}