home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Club Amiga de Montreal - CAM
/
CAM_CD_1.iso
/
files
/
262.lha
/
SpriteWizard_v1.0
/
SW_Gadgets.h
< prev
next >
Wrap
C/C++ Source or Header
|
1989-06-30
|
10KB
|
349 lines
/* SpriteWiz gadgets - By David A. Visage */
#include "SW_Images.h"
/* Defines for scroll gadgets */
#define SCROLL_UP 0
#define SCROLL_DOWN 1
#define SCROLL_LEFT 2
#define SCROLL_RIGHT 3
/* Defines for rotate gadgets */
#define ROTATE_LEFT 10
#define ROTATE_RIGHT 11
/* Defines for select gadgets */
#define SELECT_PLUS 20
#define SELECT_MINUS 21
/* Defines for color gadgets */
#define SPRCOLOR0 30 /* Background color */
#define SPRCOLOR1 31
#define SPRCOLOR2 32
#define SPRCOLOR3 33
/* Defines for proportional gadgets */
#define RED_GAD 40
#define GREEN_GAD 41
#define BLUE_GAD 42
#define SPEED_GAD 43
/* Defines for text gadgets */
#define GET_GAD 50
#define PUT_GAD 51
#define CLR_GAD 52
/* Define color gadget width and height */
#define COLOR_GAD_WIDTH 32
#define COLOR_GAD_HEIGHT 16
/* Define proportional gadget width and height */
#define PROP_GAD_WIDTH (16 * 7)
#define PROP_GAD_HEIGHT 10
/* Define text gadget width and height */
#define TEXT_GAD_WIDTH 40
#define TEXT_GAD_HEIGHT 11
/* Needed because Text() assumes YCoord is the baseline */
#define TEXT_HEIGHT 8
/* This defines the bit pattern for each sprite color */
struct BitPattern
{
UBYTE HighBit;
UBYTE LowBit;
};
/* Used for color gadgets */
struct ColorData
{
struct Border ColorBorder;
struct Points ColorPoints;
struct BitPattern ColorBits;
LONG ScreenColor,SpriteColor;
};
/* Used for text gadgets */
struct TextData
{
struct Border TextGadBorder;
struct Points TextGadPoints;
struct IntuiText TextGadIText;
};
/* Declares for scroll gadgets */
struct Gadget ScrollGadUp,ScrollGadDown;
struct Gadget ScrollGadLeft,ScrollGadRight;
/* Declares for select gadgets */
struct Gadget SelectGadPlus,SelectGadMinus;
/* Declares for rotate gadgets */
struct Gadget RotateGadLeft,RotateGadRight;
/* Declares for color gadgets */
struct Gadget ColorGad0,ColorGad1;
struct Gadget ColorGad2,ColorGad3;
struct ColorData ColorData0,ColorData1;
struct ColorData ColorData2,ColorData3;
/* Declares for proportional gadgets */
struct Gadget RedGad,GreenGad,BlueGad;
struct Gadget SpeedGad;
struct PropInfo RedInfo,GreenInfo,BlueInfo;
struct PropInfo SpeedInfo;
struct Image RedImage,GreenImage,BlueImage;
struct Image SpeedImage;
/* Declares for text gadgets */
struct Gadget GetGad,PutGad;
struct TextData GetGadData,PutGadData;
/* Put all gadgets on screen */
InitGadgets()
{
/* Initialize rotate gadgets */
InitBoolGad(&RotateGadLeft,296,45,&RotateLeftImage,ROTATE_LEFT);
InitBoolGad(&RotateGadRight,324,45,&RotateRightImage,ROTATE_RIGHT);
/* Initialize scroll gadgets */
InitBoolGad(&ScrollGadUp,390,37,&ScrollUpImage,SCROLL_UP);
InitBoolGad(&ScrollGadRight,403,46,&ScrollRightImage,SCROLL_RIGHT);
InitBoolGad(&ScrollGadLeft,369,46,&ScrollLeftImage,SCROLL_LEFT);
InitBoolGad(&ScrollGadDown,390,51,&ScrollDownImage,SCROLL_DOWN);
/* Initialize select gadgets */
InitBoolGad(&SelectGadMinus,451,45,&MinusImage,SELECT_MINUS);
InitBoolGad(&SelectGadPlus,482,45,&PlusImage,SELECT_PLUS);
/* Initialize color data structures for color gadgets */
InitColorData(&ColorData0,COLOR00,COLOR20,0,0);
InitColorData(&ColorData1,COLOR01,COLOR21,1,0);
InitColorData(&ColorData2,COLOR02,COLOR22,0,1);
InitColorData(&ColorData3,COLOR03,COLOR23,1,1);
/* Initialize color gadgets */
InitColorGad(&ColorGad0,300,75,&ColorData0,SPRCOLOR0);
InitColorGad(&ColorGad1,380,75,&ColorData1,SPRCOLOR1);
InitColorGad(&ColorGad2,460,75,&ColorData2,SPRCOLOR2);
InitColorGad(&ColorGad3,540,75,&ColorData3,SPRCOLOR3);
/* Initialize RGB gadgets and speed gadget */
InitPropGad(&RedGad,300,113,&RedImage,&RedInfo,RED_GAD);
InitPropGad(&GreenGad,300,128,&GreenImage,&GreenInfo,GREEN_GAD);
InitPropGad(&BlueGad,300,143,&BlueImage,&BlueInfo,BLUE_GAD);
InitPropGad(&SpeedGad,300,169,&SpeedImage,&SpeedInfo,SPEED_GAD);
/* Initialize text gadgets */
InitTextGad(&GetGad,450,168,&GetGadData,"GET",GET_GAD);
InitTextGad(&PutGad,500,168,&PutGadData,"PUT",PUT_GAD);
/* Initialize titles for gadgets */
InitGadTitle(&ColorGad0,1,-2,"COL0");
InitGadTitle(&ColorGad1,1,-2,"COL1");
InitGadTitle(&ColorGad2,1,-2,"COL2");
InitGadTitle(&ColorGad3,1,-2,"COL3");
InitGadTitle(&RedGad,-5,0,"R");
InitGadTitle(&GreenGad,-5,0,"G");
InitGadTitle(&BlueGad,-5,0,"B");
InitGadTitle(&SpeedGad,0,-2,"SPEED");
InitGadTitle(&GetGad,20,-2,"BUFFER");
}
/* Initialize bool gadgets */
InitBoolGad(GadPtr,LeftEdge,TopEdge,ImagePtr,GadID)
struct Gadget *GadPtr;
SHORT LeftEdge,TopEdge;
struct Image *ImagePtr;
USHORT GadID;
{
/* Initialize gadget information */
GadPtr->LeftEdge = LeftEdge;
GadPtr->TopEdge = TopEdge;
GadPtr->Width = ImagePtr->Width;
GadPtr->Height = ImagePtr->Height;
GadPtr->Flags = GADGHNONE | GADGIMAGE;
GadPtr->Activation = GADGIMMEDIATE | RELVERIFY;
GadPtr->GadgetType = BOOLGADGET;
GadPtr->GadgetRender = (APTR) ImagePtr;
GadPtr->GadgetID = GadID;
GadPtr->NextGadget = NULL;
AddGadget(WindowPtr,GadPtr,-1); /* Add gadget to window */
}
/* Initialize ColorData structures for color gadgets */
InitColorData(ColorDataPtr,ScreenColor,SpriteColor,HighBit,LowBit)
struct ColorData *ColorDataPtr;
LONG ScreenColor,SpriteColor;
UBYTE HighBit,LowBit;
{
UWORD ColorVal;
ULONG RedBits,GreenBits,BlueBits;
/* Set screen and sprite color registers */
ColorDataPtr->ScreenColor = ScreenColor;
ColorDataPtr->SpriteColor = SpriteColor;
/* Set bit pattern for sprite colors */
ColorDataPtr->ColorBits.HighBit = HighBit;
ColorDataPtr->ColorBits.LowBit = LowBit;
/* Copy screen color register to Sprite color register */
ColorVal = GetRGB4(Vp->ColorMap,ScreenColor);
SetPackedRGB(Vp,ColorVal,SpriteColor);
}
/* Initilize color gadgets */
InitColorGad(GadPtr,LeftEdge,TopEdge,ColorDataPtr,GadID)
struct Gadget *GadPtr;
SHORT LeftEdge,TopEdge;
struct ColorData *ColorDataPtr;
USHORT GadID;
{
struct Points *PointsPtr;
struct Border *BorderPtr;
LONG ScreenColor;
/* Initialize border structure for this color gadget */
PointsPtr = &ColorDataPtr->ColorPoints;
BorderPtr = &ColorDataPtr->ColorBorder;
InitBorder(PointsPtr,BorderPtr,COLOR_GAD_WIDTH,COLOR_GAD_HEIGHT);
/* Initialize gadget information */
GadPtr->LeftEdge = LeftEdge;
GadPtr->TopEdge = TopEdge;
GadPtr->Width = COLOR_GAD_WIDTH;
GadPtr->Height = COLOR_GAD_HEIGHT;
GadPtr->Flags = GADGHNONE;
GadPtr->Activation = GADGIMMEDIATE;
GadPtr->GadgetType = BOOLGADGET;
GadPtr->GadgetRender = (APTR) BorderPtr;
GadPtr->GadgetID = GadID;
GadPtr->UserData = (APTR) ColorDataPtr;
GadPtr->NextGadget = NULL;
AddGadget(WindowPtr,GadPtr,-1); /* Add gadget to window */
/* Set screen color of this color gadget */
ScreenColor = ColorDataPtr->ScreenColor;
MinX = GadPtr->LeftEdge;
MinY = GadPtr->TopEdge;
MaxX = MinX + COLOR_GAD_WIDTH;
MaxY = MinY + COLOR_GAD_HEIGHT;
SetAPen(Rp,ScreenColor);
RectFill(Rp,MinX + 1,MinY + 1,MaxX - 1,MaxY - 1);
}
/* Initialize proportional gadgets */
InitPropGad(GadPtr,LeftEdge,TopEdge,ImagePtr,InfoPtr,GadID)
struct Gadget *GadPtr;
SHORT LeftEdge,TopEdge;
struct Image *ImagePtr;
struct PropInfo *InfoPtr;
USHORT GadID;
{
/* Initialize proportional information */
InfoPtr->Flags = AUTOKNOB | FREEHORIZ;
InfoPtr->HorizBody = 0x1000;
InfoPtr->HorizPot = 0;
/* Initialize gadget information */
GadPtr->LeftEdge = LeftEdge;
GadPtr->TopEdge = TopEdge;
GadPtr->Width = PROP_GAD_WIDTH;
GadPtr->Height = PROP_GAD_HEIGHT;
GadPtr->Flags = GADGHNONE | GADGIMAGE;
GadPtr->Activation = GADGIMMEDIATE;
GadPtr->GadgetType = PROPGADGET;
GadPtr->GadgetRender = (APTR) ImagePtr;
GadPtr->GadgetID = GadID;
GadPtr->SpecialInfo = (APTR) InfoPtr;
GadPtr->NextGadget = NULL;
AddGadget(WindowPtr,GadPtr,-1); /* Add gadget to window */
}
/* Initialize text gadgets */
InitTextGad(GadPtr,LeftEdge,TopEdge,TextDataPtr,GadTextPtr,GadID)
struct Gadget *GadPtr;
SHORT LeftEdge,TopEdge;
struct TextData *TextDataPtr;
UBYTE *GadTextPtr;
USHORT GadID;
{
struct Points *PointsPtr;
struct Border *BorderPtr;
struct IntuiText *ITextPtr;
/* Create border for gadget */
PointsPtr = &TextDataPtr->TextGadPoints;
BorderPtr = &TextDataPtr->TextGadBorder;
InitBorder(PointsPtr,BorderPtr,TEXT_GAD_WIDTH - 1,TEXT_GAD_HEIGHT - 1);
/* Initialize gadget IntuiText */
ITextPtr = &TextDataPtr->TextGadIText;
ITextPtr->FrontPen = COLOR05;
ITextPtr->BackPen = COLOR00;
ITextPtr->DrawMode = JAM1;
ITextPtr->LeftEdge = 8;
ITextPtr->TopEdge = 2;
ITextPtr->ITextFont = NULL;
ITextPtr->IText = GadTextPtr;
ITextPtr->NextText = NULL;
/* Initialize gadget information */
GadPtr->LeftEdge = LeftEdge;
GadPtr->TopEdge = TopEdge;
GadPtr->Width = TEXT_GAD_WIDTH;
GadPtr->Height = TEXT_GAD_HEIGHT;
GadPtr->Flags = GADGHCOMP;
GadPtr->Activation = RELVERIFY;
GadPtr->GadgetType = BOOLGADGET;
GadPtr->GadgetRender = (APTR) &TextDataPtr->TextGadBorder;
GadPtr->GadgetID = GadID;
GadPtr->GadgetText = &TextDataPtr->TextGadIText;
GadPtr->NextGadget = NULL;
AddGadget(WindowPtr,GadPtr,-1); /* Add gadget to window */
}
/* Initialize gadget titles */
InitGadTitle(GadPtr,LeftOffSet,TopOffSet,Title)
struct Gadget *GadPtr;
SHORT LeftOffSet,TopOffSet;
UBYTE *Title;
{
SHORT Width,Height;
SHORT LeftEdge,TopEdge;
LONG XCoord,YCoord;
LeftEdge = GadPtr->LeftEdge;
TopEdge = GadPtr->TopEdge;
Width = GadPtr->Width;
Height = GadPtr->Height;
/* Check sign of LeftOffSet */
if ( LeftOffSet < 0 )
XCoord = LeftEdge + Width + (LeftOffSet * - 1);
else
XCoord = LeftEdge + LeftOffSet;
/* Check sign of TopOffSet */
if ( TopOffSet < 0 )
YCoord = TopEdge + Height + (TopOffSet * - 1) + TEXT_HEIGHT;
else
YCoord = TopEdge + TopOffSet + TEXT_HEIGHT;
Move(Rp,XCoord,YCoord);
SetAPen(Rp,COLOR05);
Text(Rp,Title,strlen(Title));
}