home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
tools
/
pufferfish
/
source
/
gadgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-30
|
8KB
|
366 lines
/*
* gadgets.c
*
* Create gadget routines
*
*/
#include <exec/types.h>
#include <intuition/intuition.h>
#include <intuition/gadgetclass.h>
#include <intuition/imageclass.h>
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <stdio.h>
#include "buttonclass/headers.h"
#include "buttonclass/buttonclass.h"
#include "PufferFish.h"
extern struct Library *IntuitionBase;
extern struct Library *GfxBase;
ULONG height1, height2, width1, width2;
ULONG newleft, newtop;
struct Image *upimage, *downimage, *frameimage, *frame, *start, *end, *checkimage, *drive, *drivename[5], *drive_frame;
struct Gadget *prop[2], *uparrows[8], *downarrows[8], *digits[8], *integer[2], *format, *drives[5];
extern int frame_height;
extern Class *BoxedStringClass, *buttonclass;
/*
* make_digits()
*
* Creates digit gadgets
*
* NOTE: Should probably just make a "groupgclass" object from these
* (or a new BOOPSI class).
*
* Returns TRUE on success, FALSE otherwise
*
*/
BOOL make_digits( void )
{
int i;
BOOL ret = FALSE;
GetAttr( IA_Width, upimage, &width1 );
if( width1 < drawinfo->dri_Font->tf_XSize )
{
width1 = drawinfo->dri_Font->tf_XSize;
}
GetAttr( IA_Height, upimage, &height1 );
width2 = ( width1 - (drawinfo->dri_Font->tf_XSize + 4) ) / 2; /* extra 4 for frame */
height2 = drawinfo->dri_Font->tf_YSize;
for( i = 0; i < 8; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 - 2 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0);
newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1;
uparrows[i] = (struct Gadget *)NewObject( NULL, "buttongclass",
GA_ID, i + GAD_UPARROW_1,
GA_Top, newtop,
GA_Left,newleft,
GA_Image,upimage,
GA_RelVerify,TRUE,
((i > 0) ? GA_Previous : TAG_IGNORE ), ((i > 0) ? uparrows[i-1] : NULL),
GA_GadgetHelp, TRUE,
GA_Disabled, FALSE,
TAG_END );
if( uparrows[i] == NULL )
{
break;
}
}
if( i < 8 )
{
free_digits();
}
else
{
for( i = 0; i < 8; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0);
newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1 + width2 + 1;
digits[i] = (struct Gadget *)NewObject( NULL, "frbuttonclass",
GA_ID, i + GAD_DIGIT_1,
GA_Top, newtop,
GA_Left,newleft,
GA_RelVerify, TRUE,
GA_DrawInfo, drawinfo,
GA_Image, frameimage,
GA_Text, dig_text[i],
GA_Previous, ((i > 0) ? digits[i-1] : uparrows[7]),
GA_GadgetHelp, TRUE,
TAG_END );
if( digits[i] == NULL )
{
break;
}
}
if( i < 8 )
{
free_digits();
}
else
{
newtop += (drawinfo->dri_Font->tf_YSize + 2 + 4);
for( i = 0; i < 8; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + ((i >= 4) ? frame_height + drawinfo->dri_Font->tf_YSize : 0) + drawinfo->dri_Font->tf_YSize + 2 + 4;
newleft = win->BorderLeft + ( GF_LEFTBORDER * 2 ) + ((i >= 4) ? i-4 : i) * width1;
downarrows[i] = (struct Gadget *)NewObject( NULL, "buttongclass",
GA_ID, i + GAD_DOWNARROW_1,
GA_Top, newtop,
GA_Left,newleft,
GA_Image,downimage,
GA_RelVerify, TRUE,
GA_Previous, ((i > 0) ? downarrows[i-1] : digits[7]),
GA_Disabled, TRUE,
GA_GadgetHelp, TRUE,
TAG_END );
if( downarrows[i] == NULL )
{
break;
}
}
if( i < 8 )
{
free_digits();
}
else
{
for( i = 0; i < 2; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 + height1 + i * (frame_height + drawinfo->dri_Font->tf_YSize);
integer[i] = (struct Gadget *)NewObject( BoxedStringClass, NULL,
GA_ID, GAD_INTEGER_1 + i,
GA_Top, newtop,
GA_Left, win->BorderLeft + (GF_LEFTBORDER * 2) + (width1 * 9 / 2),
GA_Height, drawinfo->dri_Font->tf_YSize + 4,
GA_Width, drawinfo->dri_Font->tf_XSize * 5 + 8,
GA_RelVerify,TRUE,
GA_Previous,((i==0) ? downarrows[7] : integer[0]),
STRINGA_LongVal, firstdisk,
STRINGA_MaxChars, 5,
STRINGA_ExitHelp, TRUE,
GA_TabCycle, TRUE,
GA_GadgetHelp, TRUE,
TAG_END );
if( integer[i] == NULL )
{
break;
}
}
if( i == 2 )
{
for( i = 0; i < 2; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 + 2 * height1 + 2 + i * (frame_height + drawinfo->dri_Font->tf_YSize) + drawinfo->dri_Font->tf_YSize + 2 + 4;
prop[i] = (struct Gadget *)NewObject( NULL, "propgclass",
GA_ID, GAD_PROP_1 + i,
PGA_Freedom, FREEHORIZ,
PGA_Top, 0,
PGA_Total, lastdisk - firstdisk + 1,
PGA_Visible, 1,
PGA_NewLook, TRUE,
GA_Top, newtop,
GA_Left, win->BorderLeft + (GF_LEFTBORDER * 2),
GA_Height, drawinfo->dri_Font->tf_YSize,
GA_Width, width1 * 4,
GA_Previous, ((i==0) ? integer[1] : prop[0]),
GA_GadgetHelp, TRUE,
GA_RelVerify, TRUE,
TAG_END );
if( prop[i] == NULL )
{
break;
}
}
if( i == 2 )
{
ret = TRUE;
}
else
{
free_digits();
}
}
else
{
free_digits();
}
}
}
}
return( ret );
}
/*
* free_digits()
*
* Frees digit gadgets created by make_digits()
*
*/
void free_digits( void )
{
int i;
for( i = 0; i < 2; i += 1 )
{
if( prop[i] )
{
DisposeObject( prop[i] );
}
if( integer[i] )
{
DisposeObject( integer[i] );
}
}
for( i = 0; i < 8; i += 1)
{
if( downarrows[i] )
{
DisposeObject( downarrows[i] );
}
if( digits[i] )
{
DisposeObject( digits[i] );
}
if( uparrows[i] )
{
DisposeObject( uparrows[i] );
}
}
}
/*
* make_drives()
*
* Creates drive gadgets
*
* Returns TRUE on success, FALSE otherwise
*
*/
BOOL make_drives( void )
{
int i;
ULONG width, height, checkheight;
BOOL ret = FALSE;
GetAttr( IA_Height, checkimage, &checkheight );
height = checkheight;
if( height < drawinfo->dri_Font->tf_YSize )
{
height = drawinfo->dri_Font->tf_YSize;
}
GetAttr( IA_Width, upimage, &width );
for( i = 0; i < 5; i += 1 )
{
newtop = win->BorderTop + GF_TOPBORDER * 2 - 2 + i * (height + 5);
drives[i] = (struct Gadget *)NewObject( buttonclass, NULL,
GA_ID, GAD_DRIVE_0 + i,
GA_Top, newtop,
GA_Left,win->BorderLeft + GF_LEFTBORDER * 2 + width * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8
+ IntuiTextLength( &drivenames_text[0] ),
GA_Height, checkheight,
GA_Width, width + 8,
BUT_Image,checkimage,
GA_RelVerify,TRUE,
GA_Previous, ((i > 0) ? drives[i-1] : prop[1]),
GA_Disabled, ((avail_disks & 1<<i) ? FALSE : TRUE),
GA_GadgetHelp, TRUE,
GA_ToggleSelect, TRUE,
GA_Selected, FALSE,
TAG_END );
if( drives[i] == NULL )
{
break;
}
}
if( i < 5 )
{
free_drives();
}
else
{
ret = TRUE;
}
return( ret );
}
/*
* free_drives()
*
* Frees drive gadgets created by make_drives()
*
*/
void free_drives( void )
{
int i;
for( i = 0; i < 5; i += 1 )
{
if( drives[i] )
{
DisposeObject( drives[i] );
}
}
}
/*
* make_gadgets()
*
* Creates other (non-digit and non-drive) gadgets
*
* Returns TRUE on success, FALSE otherwise
*
*/
BOOL make_gadgets( void )
{
BOOL ret = FALSE;
ULONG arrowwidth, checkwidth, checkheight;
ULONG left;
GetAttr( IA_Width, upimage, &arrowwidth );
GetAttr( IA_Width, checkimage, &checkwidth );
GetAttr( IA_Height, checkimage, &checkheight );
left = ( win->Width - (win->BorderLeft + GF_LEFTBORDER + arrowwidth * 6 + drawinfo->dri_Font->tf_XSize * 5 ) - TextLength( win->RPort, "Go", 2 ) - 8 - drawinfo->dri_Font->tf_XSize - 4 - GF_RIGHTBORDER - win->BorderRight ) / 2;
if( format = (struct Gadget *)NewObject( buttonclass, NULL,
GA_ID, GAD_START,
BUT_Text, "_Go",
GA_Top, win->BorderTop + GF_TOPBORDER + 5 * (checkheight + 5) + GF_TOPBORDER * 2,
GA_Left, win->BorderLeft + GF_LEFTBORDER + arrowwidth * 6 + drawinfo->dri_Font->tf_XSize * 5 + 8 + left,
GA_Height, drawinfo->dri_Font->tf_YSize + 8,
GA_Width, TextLength(win->RPort, "Go", 2) + 8 + drawinfo->dri_Font->tf_XSize,
GA_Previous, drives[3],
GA_DrawInfo, drawinfo,
GA_RelVerify, TRUE,
GA_GadgetHelp, TRUE,
TAG_END ))
{