home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 1: Amiga
/
FrozenFish-Apr94.iso
/
pufferfish
/
source
/
handlegadgets.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-03-26
|
6KB
|
292 lines
/*
* handlegadgets.c
*
* Gadget handling routines for PufferFish
*
*/
#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 "PufferFish.h"
/*
* update_gadgets()
*
* General dispatcher to handle gadgets
*
*/
void update_gadgets( ULONG id )
{
if( id <= GAD_UPARROW_8 )
{
/* Increasing value */
increase_digits(id);
update_disknum();
}
else if( id <= GAD_DIGIT_8 )
{
/* Chose a digit button, so reset it */
reset_digit( id );
update_disknum();
}
else if( id <= GAD_DOWNARROW_8 )
{
/* Decreasing value */
decrease_digits(id);
update_disknum();
}
else if( id <= GAD_INTEGER_2 )
{
/* Changed integer gadget */
handle_integer(id);
}
else if( id <= GAD_PROP_2 )
{
/* Changed prop gadget */
handle_prop(id);
}
else if( id <= GAD_DRIVE_4 )
{
/* Changed drive gadget */
handle_drive(id);
}
else
{
/* Bad gadget id */
;
}
refresh_gadgets();
RefreshGList( uparrows[0], win, NULL, -1 );
}
/*
* handle_integer()
*
* Handles changes in integer gadgets
*
*/
void handle_integer( ULONG id )
{
if( id == GAD_INTEGER_1 )
{
GetAttr( STRINGA_LongVal, integer[0], (ULONG *)&start_disknum );
}
else
{
GetAttr( STRINGA_LongVal, integer[1], (ULONG *)&end_disknum );
}
}
/*
* decrease_digits()
*
* Handles down arrows
*
*/
void decrease_digits( ULONG id )
{
int gadnum = id - GAD_DOWNARROW_1;
dig[gadnum] -= 1;
if( dig[gadnum] < 0 )
{
dig[gadnum] = 0;
}
}
/*
* reset_digit()
*
* Handles clicks on digits
*
*/
void reset_digit( ULONG id )
{
int gadnum = id - GAD_DIGIT_1;
dig[gadnum] = 0;
}
/*
* increase_digits()
*
* Handles up arrows
*
*/
void increase_digits( ULONG id )
{
int gadnum = id - GAD_UPARROW_1;
dig[gadnum] += 1;
if( dig[gadnum] >= 9 )
{
dig[gadnum] = 9;
}
}
/*
* handle_prop()
*
* Handles slider gadgets
*
*/
void handle_prop( ULONG id )
{
if( id == GAD_PROP_1 )
{
GetAttr( PGA_Top, prop[0], (ULONG *)&start_disknum );
start_disknum += firstdisk;
}
else
{
GetAttr( PGA_Top, prop[1], (ULONG *)&end_disknum );
end_disknum += firstdisk;
}
}
/*
* handle_drives()
*
* Handles drive selection gadgets
*
*/
void handle_drive( ULONG id )
{
int gadnum = id - GAD_DRIVE_0;
if( drives_selected & 1<<gadnum )
{
SetGadgetAttrs( drives[gadnum], win, NULL,
GA_Selected, FALSE,
TAG_END );
drives_selected &= ~(1<<gadnum);
}
else
{
SetGadgetAttrs( drives[gadnum], win, NULL,
GA_Selected, TRUE,
TAG_END );
drives_selected |= 1<<gadnum;
}
}
/*
* refresh_gadgets()
*
* Enables, disables, validates and updates gadgets
*
*/
void refresh_gadgets( void )
{
int i;
if( start_disknum <= firstdisk )
{
start_disknum = firstdisk;
}
if( start_disknum >= lastdisk )
{
start_disknum = lastdisk;
}
if( start_disknum > end_disknum )
{
end_disknum = start_disknum;
}
if( end_disknum >= lastdisk )
{
end_disknum = lastdisk;
}
for( i = 0; i < 4; i += 1 )
{
SetGadgetAttrs( uparrows[i], win, NULL,
GA_Disabled, (dig[i] < 9 && start_disknum < lastdisk && start_disknum / (10 ^ i) <= lastdisk / (10 ^ i)) ? FALSE : TRUE,
TAG_END );
SetGadgetAttrs( downarrows[i], win, NULL,
GA_Disabled, (dig[i] > 0 && start_disknum > firstdisk && start_disknum / (10 ^ i) >= firstdisk / (10 ^ i)) ? FALSE : TRUE,
TAG_END );
}
for( i = 4; i < 8; i += 1 )
{
SetGadgetAttrs( uparrows[i], win, NULL,
GA_Disabled, (dig[i] < 9 && end_disknum / (10 ^ (i-4)) < lastdisk / (10 ^ (i-4))) ? FALSE : TRUE,
TAG_END );
SetGadgetAttrs( downarrows[i], win, NULL,
GA_Disabled, (dig[i] > 0 && end_disknum > start_disknum && end_disknum / (10 ^ (i-4)) >= start_disknum / (10 ^ (i-4))) ? FALSE : TRUE,
TAG_END );
}
dig[0] = start_disknum / 1000;
dig[1] = (start_disknum - dig[0] * 1000) / 100;
dig[2] = (start_disknum - dig[0] * 1000 - dig[1] * 100) / 10;
dig[3] = (start_disknum - dig[0] * 1000 - dig[1] * 100 - dig[2] * 10);
dig[4] = end_disknum / 1000;
dig[5] = (end_disknum - dig[4] * 1000) / 100;
dig[6] = (end_disknum - dig[4] * 1000 - dig[5] * 100) / 10;
dig[7] = (end_disknum - dig[4] * 1000 - dig[5] * 100 - dig[6] * 10);
for( i = 0; i < 8; i += 1 )
{
dig_text[i][0] = '0' + dig[i];
SetGadgetAttrs( digits[i], win, NULL,
GA_Text, dig_text[i],
TAG_END );
}
SetGadgetAttrs( integer[0], win, NULL,
STRINGA_LongVal, start_disknum,
TAG_END );
SetGadgetAttrs( prop[0], win, NULL,
PGA_Top, start_disknum - firstdisk,
TAG_END );
SetGadgetAttrs( integer[1], win, NULL,
STRINGA_LongVal, end_disknum,
TAG_END );
SetGadgetAttrs( prop[1], win, NULL,
PGA_Top, end_disknum - firstdisk,
TAG_END );
}
/*
* update_disknum()
*
* Updates disk numbers from individual digits;
* updates digits if invalid
*
*/
void update_disknum( void )
{
int i;
start_disknum = dig[0] * 1000 + dig[1] * 100 + dig[2] * 10 + dig[3];
if( start_disknum > lastdisk )
{
start_disknum = lastdisk;
dig[0] = start_disknum / 1000;
dig[1] = (start_disknum - dig[0] * 1000) / 100;
dig[2] = (start_disknum - dig[0] * 1000 - dig[1] * 100) / 10;
dig[3] = (start_disknum - dig[0] * 1000 - dig[1] * 100 - dig[2] * 10);
}
end_disknum = dig[4] * 1000 + dig[5] * 100 + dig[6] * 10 + dig[7];
if( end_disknum > lastdisk )
{
end_disknum = lastdisk;
dig[4] = end_disknum / 1000;
dig[5] = (end_disknum - dig[4] * 1000) / 100;
dig[6] = (end_disknum - dig[4] * 1000 - dig[5] * 100) / 10;
dig[7] = (end_disknum - dig[4] * 1000 - dig[5] * 100 - dig[6] * 10);
}
if( start_disknum > end_disknum )
{
end_disknum = start_disknum;
for( i = 0; i < 4; i += 1 )
{
dig[i+4] = dig[i];
}
}
}