home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 1
/
GoldFishApril1994_CD1.img
/
d1xx
/
d159
/
starchart
/
source
/
star8.c
< prev
next >
Wrap
C/C++ Source or Header
|
1988-10-02
|
19KB
|
625 lines
/*=========================================================================
Star8.c -- This module builds and submits a requester in response to
the user's choice of 'change magnitude' from the OPTIONS menu
of the Star Chart program. The requester lets the user modify the
maximum magnitudes for stars to be displayed as pluses, or as white
dots.
Credits for Star Chart:
Robert L. Hill of the Orange County, CA. Amiga Friends User Group
wrote the original version of StarChart in AmigaBasic
The star data and many of the main functions of this
version are derived from that program.
Ray R. Larson wrote the c version 1.0 of StarChart, 'intuitionizing'
and enhancing the speed and functions of the original.
Copyright (c) 1986 by Ray R. Larson
This program may be freely distributed and copied, but may not be sold
without the permission of the author. If you modify or enhance it,
please include the above credits (and please send me a copy!).
Ray R. Larson
6425 Central Ave. #304
El Cerrito, CA 94530
BitNet LARSON@UCBCMSA
=========================================================================*/
/*------------Header file for all of the standard stuff----*/
/*-------------plus definitions of global structures-------*/
#include "star.h"
/**********************************************************************
* Gadget Structure Definitions
*
* The following structures were defined using the Gadget Editor created
* by the Programmer's Network.
* The credits for the Gadget Editor are:
*
* John Draper - Initial design, coordination, and integration.
* Ray Larson - Images and Intuitext.
* Brent Southard - Saving and restoring gadgets in binary form.
* Dave Milligan - Gadget Editor Main menu.
*
*
**********************************************************************/
/* Definitions for Gadget ID numbers */
#define MAGGADGAD 0
#define WHITEGADGAD 1
#define CANMAGGAD 2
#define OKMAGGAD 3
/**********************************************************************
* Text attribute structures used in rendering IntuiTexts
**********************************************************************/
extern struct TextAttr TxtAt_Plain,TxtAt_BIU,TxtAt_BU,TxtAt_BI,TxtAt_B,
TxtAt_IU,TxtAt_I,TxtAt_U;
struct IntuiText Mag_Error_Text = {
3, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
0, 0, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"?",
NULL /* NextText */
};
/**********************************************************************
* Border Definitions for MagniReq requester
**********************************************************************/
SHORT MagniReq_Pairs_1[] = {
0, 0,
257, 0,
257, 140,
0, 140,
0, 0
};
struct Border MagniReq_bord_1 = {
1, 1, /* LeftEdge, TopEdge */
7, 1, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&MagniReq_Pairs_1, /* XY pairs */
NULL /* Next Border */
};
SHORT MagniReq_Pairs_2[] = {
0, 0,
251, 0,
251, 137,
0, 137,
0, 0
};
struct Border MagniReq_bord_2 = {
3, 3, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&MagniReq_Pairs_2, /* XY pairs */
&MagniReq_bord_1 /* Next Border */
};
/**********************************************************************
* Border Definitions for okmag gadget
**********************************************************************/
SHORT okmag_Pairs_2[] = {
0, 0,
88, 0,
88, 17,
0, 17,
0, 0
};
struct Border okmag_bord_2 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&okmag_Pairs_2, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the okmag gadget.
**********************************************************************/
struct IntuiText okmag_Text_0 = {
7, 0, /* FrontPen, BackPen */
JAM2, /* DrawMode */
12, 4, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" OK ",
NULL
};
/**********************************************************************
* Gadget Structure definition for the okmag gadget.
**********************************************************************/
struct Gadget okmag = {
NULL, /* NextGadget pointer */
152, 116, /* LeftEdge, TopEdge */
88, 17, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE,
/* GadgetType */
BOOLGADGET | REQGADGET,
(APTR)&okmag_bord_2, /* GadgetRender */
NULL, /* SelectRender */
&okmag_Text_0, /* GadgetText */
0x0, /* MutualExclude */
NULL, /* SpecialInfo */
OKMAGGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/**********************************************************************
* Border Definitions for canmag gadget
**********************************************************************/
SHORT canmag_Pairs_3[] = {
0, 0,
88, 0,
88, 17,
0, 17,
0, 0
};
struct Border canmag_bord_3 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&canmag_Pairs_3, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the canmag gadget.
**********************************************************************/
struct IntuiText canmag_Text_0 = {
7, 0, /* FrontPen, BackPen */
JAM2, /* DrawMode */
10, 4, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)" CANCEL ",
NULL
};
/**********************************************************************
* Gadget Structure definition for the canmag gadget.
**********************************************************************/
struct Gadget canmag = {
&okmag, /* NextGadget pointer */
29, 116, /* LeftEdge, TopEdge */
88, 17, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE | ENDGADGET,
/* GadgetType */
BOOLGADGET | REQGADGET,
(APTR)&canmag_bord_3, /* GadgetRender */
NULL, /* SelectRender */
&canmag_Text_0, /* GadgetText */
0x0, /* MutualExclude */
NULL, /* SpecialInfo */
CANMAGGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/**********************************************************************
* Border Definitions for whitegad gadget
**********************************************************************/
SHORT whitegad_Pairs_4[] = {
0, 0,
74, 0,
74, 10,
0, 10,
0, 0
};
struct Border whitegad_bord_4 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&whitegad_Pairs_4, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the whitegad gadget.
**********************************************************************/
struct IntuiText whitegad_Text_2 = {
0, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-37, 11, /* LeftEdge, TopEdge */
&TxtAt_I, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"(range 0.0 - 10.0)",
NULL
};
struct IntuiText whitegad_Text_1 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-56, -10, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"displayed as a white dot:",
&whitegad_Text_2 /* NextText */
};
struct IntuiText whitegad_Text_0 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-63, -19, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"Maximum Magnitude for stars",
&whitegad_Text_1 /* NextText */
};
/**********************************************************************
* String information for the whitegad string gadget.
**********************************************************************/
UBYTE WhiteMagBuf[12];
UBYTE whitegad_ubuf_1[12];
struct StringInfo WhiteMagTxt = {
WhiteMagBuf, whitegad_ubuf_1, /* Buffer, UndoBuffer */
0, 11, 0, /* BufferPos, MaxChars, DispPos */
0, 0, /* UndoPos, NumChars */
0, 86, 84, /* DispCount, CLeft, CTop */
0x0, 0, /* LayerPtr, LongInt */
0x0 /* AltKeyMap */
};
/**********************************************************************
* Gadget Structure definition for the whitegad gadget.
**********************************************************************/
struct Gadget whitegad = {
&canmag, /* NextGadget pointer */
86, 84, /* LeftEdge, TopEdge */
74, 10, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE | STRINGCENTER,
/* GadgetType */
STRGADGET | REQGADGET,
(APTR)&whitegad_bord_4, /* GadgetRender */
NULL, /* SelectRender */
&whitegad_Text_0, /* GadgetText */
0x0, /* MutualExclude */
(APTR)&WhiteMagTxt, /* SpecialInfo */
WHITEGADGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/**********************************************************************
* Border Definitions for maggad gadget
**********************************************************************/
SHORT maggad_Pairs_5[] = {
0, 0,
73, 0,
73, 9,
0, 9,
0, 0
};
struct Border maggad_bord_5 = {
-1, -1, /* LeftEdge, TopEdge */
1, 7, JAM2, /* FrontPen, BackPen, DrawMode*/
5, /* Count of XY pairs */
(SHORT *)&maggad_Pairs_5, /* XY pairs */
NULL /* Next Border */
};
/**********************************************************************
* IntuiTexts for the maggad gadget.
**********************************************************************/
struct IntuiText maggad_Text_2 = {
0, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-39, 10, /* LeftEdge, TopEdge */
&TxtAt_I, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"(range 0.0 - 10.0)",
NULL
};
struct IntuiText maggad_Text_1 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-56, -10, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"displayed as a plus sign:",
&maggad_Text_2 /* NextText */
};
struct IntuiText maggad_Text_0 = {
1, 2, /* FrontPen, BackPen */
JAM2, /* DrawMode */
-64, -19, /* LeftEdge, TopEdge */
&TxtAt_B, /* ITextFont Pointer */
/* The IText */
(UBYTE *)"Maximum Magnitude for stars",
&maggad_Text_1 /* NextText */
};
/**********************************************************************
* String information for the maggad string gadget.
**********************************************************************/
UBYTE PlusMagBuf[12];
UBYTE maggad_ubuf_2[12];
struct StringInfo PlusMagTxt = {
PlusMagBuf, maggad_ubuf_2, /* Buffer, UndoBuffer */
0, 11, 0, /* BufferPos, MaxChars, DispPos */
0, 0, /* UndoPos, NumChars */
0, 87, 39, /* DispCount, CLeft, CTop */
0x0, 0, /* LayerPtr, LongInt */
0x0 /* AltKeyMap */
};
/**********************************************************************
* Gadget Structure definition for the maggad gadget.
**********************************************************************/
struct Gadget maggad = {
&whitegad, /* NextGadget pointer */
87, 39, /* LeftEdge, TopEdge */
73, 9, /* Width, Height */
/* Gadget Flags */
GADGHCOMP,
/* Activation Flags */
RELVERIFY | GADGIMMEDIATE | STRINGCENTER,
/* GadgetType */
STRGADGET | REQGADGET,
(APTR)&maggad_bord_5, /* GadgetRender */
NULL, /* SelectRender */
&maggad_Text_0, /* GadgetText */
0x0, /* MutualExclude */
(APTR)&PlusMagTxt, /* SpecialInfo */
MAGGADGAD, /* GadgetID */
0x1 /* UserData Pointer */
};
/****************************************************************************
* Global Structures
***************************************************************************/
/* the newwindow structure used in GT */
extern struct NewWindow nw;
extern struct Window *w;
extern FLOAT MaxPlus, MaxWhite;
/****************************************************************************
* External function definitions
***************************************************************************/
extern struct IntuiMessage *GetMsg();
extern double atof();
/****************************************************************************
* Requester structure and global pointer to it's gadget list.
***************************************************************************/
struct Requester MagniRequester;
/****************************************************************************
* The Code part of the Getmags module.
***************************************************************************/
GetMags()
{
BOOL cancelchosen;
LONG iflags;
struct RastPort *reqrp;
/* fix the IDCMP flags to report requester set and clear */
iflags = nw.IDCMPFlags;
iflags |= REQCLEAR;
ModifyIDCMP(w,iflags);
/* initialize the magnitude requester */
InitMagniReq();
/* Put up the requester */
Request(&MagniRequester,w);
reqrp = MagniRequester.ReqLayer->rp;
/* let the user fill in the parameters and wait for a cancel or ok. */
cancelchosen = WaitMagniReq(reqrp);
/* if the user cancelled, just return -- otherwise set magnitudes */
/* and redisplay the star chart. */
if (cancelchosen) return(0);
MaxPlus = (FLOAT)atof(PlusMagBuf);
MaxWhite = (FLOAT)atof(WhiteMagBuf);
ReDisplay();
} /* GetMags */
/*
* Init the magnitude requester
*/
InitMagniReq()
{
struct RastPort *reqrp;
InitRequester(&MagniRequester);
MagniRequester.LeftEdge = 110;
MagniRequester.TopEdge = 12;
MagniRequester.Width = 260;
MagniRequester.Height = 145;
MagniRequester.ReqGadget = &maggad;
MagniRequester.ReqText = NULL;
MagniRequester.BackFill = 2;
MagniRequester.Flags = 0;
MagniRequester.ReqBorder = &MagniReq_bord_2;
sprintf(PlusMagBuf,"%6.2f",MaxPlus);
PlusMagTxt.NumChars = (LONG)strlen(PlusMagBuf);
*(maggad_ubuf_2) = '\0';
sprintf(WhiteMagBuf,"%6.2f",MaxWhite);
WhiteMagTxt.NumChars = (LONG)strlen(WhiteMagBuf);
*(whitegad_ubuf_1) = '\0';
}
/****************************************************************************
* WaitMagniReq - permit user to change the values in the requester gadgets
* and check the values they install until either the
* CANCEL gadget is clicked or the OK gadget is clicked AND
* there are no outstanding input errors
***************************************************************************/
BOOL WaitMagniReq(reqrp)
struct RastPort *reqrp;
{
ULONG class = GADGETDOWN;
struct IntuiMessage *message;
struct Gadget *gadget;
BOOL cancelflag = FALSE;
LONG errorflag = 0L, checkmag();
while (class != REQCLEAR)
{
if ((message=(struct IntuiMessage *) GetMsg(w->UserPort)) == 0L)
{
Wait(1L<<w->UserPort->mp_SigBit);
continue;
}
class = message->Class;
gadget = (struct Gadget *) message->IAddress;
ReplyMsg(message);
switch (class)
{
case GADGETDOWN:
break;
case GADGETUP:
switch (gadget->GadgetID)
{
case MAGGADGAD:
errorflag = checkmag(reqrp,gadget,errorflag,class);
break;
case WHITEGADGAD:
errorflag = checkmag(reqrp,gadget,errorflag,class);
break;
case CANMAGGAD :
cancelflag = TRUE;
break;
case OKMAGGAD :
if (errorflag == 0)
EndRequest(&MagniRequester,w);
else DisplayBeep(w->WScreen);
break;
} /* end of GADGETUP switch */
} /* end of CLASS switch */
}/* end of while loop */
return(cancelflag);
} /* WaitMagniReq */
/****************************************************************************
* checkmag - verify that the values returned in the string gadgets are
* in the appropriate range for the parameter.
***************************************************************************/
LONG checkmag(reqrp,checkgad,errorflag,class)
struct RastPort *reqrp;
struct Gadget *checkgad;
LONG errorflag;
ULONG class;
{
struct StringInfo *si;
BOOL inputerror = FALSE;
LONG checknum, pendingerror;
UBYTE *c;
FLOAT temp;
if (checkgad == NULL) return(errorflag);
pendingerror = errorflag;
si = (struct StringInfo *)checkgad->SpecialInfo;
if (si == NULL) return(errorflag);
for(c=si->Buffer; *c; c++)
{ if ((isdigit(*c)) || (*c == '.') || (isspace(*c))) ;
else inputerror == TRUE;
}
if (inputerror == FALSE)
temp = (FLOAT)atof(si->Buffer);
if ((temp < 0.0) || (temp > 10.0))
inputerror == TRUE;
if (inputerror == TRUE) /* put a "?" next to the gadget */
{
errorflag |= (1L << checkgad->GadgetID);
DisplayBeep(w->WScreen);
PrintIText(reqrp,&Mag_Error_Text,
(LONG)(checkgad->LeftEdge - 10),(LONG)checkgad->TopEdge);
}
if ((pendingerror != errorflag) && (inputerror == FALSE))
{ /* user must have fixed an error, so turn off the ? */
pendingerror = errorflag;
Mag_Error_Text.FrontPen = 2;
PrintIText(reqrp,&Mag_Error_Text,
(LONG)(checkgad->LeftEdge - 10),(LONG)checkgad->TopEdge);
Mag_Error_Text.FrontPen = 3;
}
return(errorflag);
} /* end of checkmag */