home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
printer
/
graphpaper
/
src
/
src.lha
/
sliders.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-06
|
8KB
|
302 lines
#include "graph.h"
void setstrgadget(struct Gadget *gad, char *str)
{
/* set the string field to str */
strcpy(((struct StringInfo *)(gad->SpecialInfo)) -> Buffer, str);
((struct StringInfo *)(gad->SpecialInfo)) -> DispPos = 0;
((struct StringInfo *)(gad->SpecialInfo)) -> BufferPos = 0;
RefreshOneGad(gad);
}
void setslider(struct Gadget *slider, float val)
{
struct PropInfo *Prop = ((struct PropInfo *)slider->SpecialInfo);
int newvert;
newvert = (int)((1.0-val)*0xFFFF + 0.5);
SnipAllBut(slider);
#if 1
ModifyProp(slider, wG, NULL, Prop->Flags,
Prop->HorizPot, newvert,
Prop->HorizBody, Prop->VertBody
);
#else
/* what is NumGad??? */
NewModifyProp(slider ,wG ,NULL, Prop->Flags,
Prop->HorizPot, newvert,
Prop->HorizBody, Prop->VertBody,
1 /* NumGad, what is this ??? */
);
#endif
RestoreGads();
}
void setintgad(struct Gadget *intgad, int value)
{
char buf[50];
sprintf(buf, "%d", value);
INTFIELD((*intgad)) = value;
setstrgadget(intgad, buf);
}
void setfloatgad(struct Gadget *intgad, float value)
{
char buf[50];
sprintf(buf, "%.3f", value);
setstrgadget(intgad, buf);
}
void setstrgad(struct Gadget *strgad, char *value)
{
setstrgadget(strgad, value);
}
/* ******************** */
#define SIZES_RANGE 176
float sizes[SIZES_RANGE] =
{ 0.100, 0.125, 0.200, 0.250, 0.300, 0.375, 0.400,
0.500, 0.600, 0.625, 0.700, 0.750, 0.800, 0.875, 0.900,
1.000, 1.100, 1.125, 1.200, 1.250, 1.300, 1.375, 1.400,
1.500, 1.600, 1.625, 1.700, 1.750, 1.800, 1.875, 1.900,
2.000, 2.100, 2.125, 2.200, 2.250, 2.300, 2.375, 2.400,
2.500, 2.600, 2.625, 2.700, 2.750, 2.800, 2.875, 2.900,
3.000, 3.100, 3.125, 3.200, 3.250, 3.300, 3.375, 3.400,
3.500, 3.600, 3.625, 3.700, 3.750, 3.800, 3.875, 3.900,
4.000, 4.100, 4.125, 4.200, 4.250, 4.300, 4.375, 4.400,
4.500, 4.600, 4.625, 4.700, 4.750, 4.800, 4.875, 4.900,
5.000, 5.100, 5.125, 5.200, 5.250, 5.300, 5.375, 5.400,
5.500, 5.600, 5.625, 5.700, 5.750, 5.800, 5.875, 5.900,
6.000, 6.100, 6.125, 6.200, 6.250, 6.300, 6.375, 6.400,
6.500, 6.600, 6.625, 6.700, 6.750, 6.800, 6.875, 6.900,
7.000, 7.100, 7.125, 7.200, 7.250, 7.300, 7.375, 7.400,
7.500, 7.600, 7.625, 7.700, 7.750, 7.800, 7.875, 7.900,
8.000, 8.100, 8.125, 8.200, 8.250, 8.300, 8.375, 8.400,
8.500, 8.600, 8.625, 8.700, 8.750, 8.800, 8.875, 8.900,
9.000, 9.100, 9.125, 9.200, 9.250, 9.300, 9.375, 9.400,
9.500, 9.600, 9.625, 9.700, 9.750, 9.800, 9.875, 9.900,
10.000,10.100,10.125,10.200,10.250,10.300,10.375,10.400,
10.500,10.600,10.625,10.700,10.750,10.800,10.875,10.900,
11.000};
int find_size_index(float val)
{
int i;
for (i=0; i<SIZES_RANGE; ++i) {
if (val <= sizes[i]) {
return i;
}
}
return SIZES_RANGE-1;
}
#define RAWVAL(gad) (((struct PropInfo *)(gad.SpecialInfo))->VertPot)
#define SIZE(gad) sizes[(int)(SIZES_RANGE-1 - \
(RAWVAL(gad) * (SIZES_RANGE-1)) / 0xFFFF + .5)]
#define GETSTRFIELD_F(gad,val) \
sscanf((char *)(((struct StringInfo *)(gad.SpecialInfo))->Buffer), "%f", &val)
#define GETSTRFIELD_I(gad,val) \
sscanf((char *)(((struct StringInfo *)(gad.SpecialInfo))->Buffer), "%d", &val)
static void size_setmiddle(void)
{
float mean = (SIZE(size_slider_right) + SIZE(size_slider_left)) /2.;
setslider (&size_slider_middle, mean/sizes[SIZES_RANGE-1]);
}
void size_init(void)
{
setslider(&size_slider_left, x_size_v/sizes[SIZES_RANGE-1]);
setslider(&size_slider_right, y_size_v/sizes[SIZES_RANGE-1]);
size_setmiddle();
setfloatgad(&x_size, x_size_v);
setfloatgad(&y_size, y_size_v);
}
void y_size_func(APTR object)
{
int index;
float val;
GETSTRFIELD_F(y_size, val);
index = find_size_index(val);
setslider(&size_slider_right, ((float)index)/(SIZES_RANGE-1));
size_setmiddle();
}
void size_slider_middle_func (APTR object)
{
float size = SIZE(size_slider_middle);
setslider(&size_slider_right, ((float)SIZE(size_slider_middle))/sizes[SIZES_RANGE-1]);
setslider(&size_slider_left, ((float)SIZE(size_slider_middle))/sizes[SIZES_RANGE-1]);
setfloatgad(&x_size, size);
setfloatgad(&y_size, size);
}
void size_slider_right_func (APTR object)
{
float size = SIZE(size_slider_right);
setfloatgad(&y_size, size);
size_setmiddle();
}
void size_slider_left_func (APTR object)
{
float size = SIZE(size_slider_left);
setfloatgad(&x_size, size);
size_setmiddle();
}
void x_size_func(APTR object)
{
int index;
float val;
GETSTRFIELD_F(x_size, val);
index = find_size_index(val);
setslider (&size_slider_left, ((float)index)/(SIZES_RANGE-1));
size_setmiddle();
}
/* ******************** */
#define GRIDS_MAX (50)
#define GRIDS(gad) ((int)(GRIDS_MAX - RAWVAL(gad)*(GRIDS_MAX-1.)/0xFFFF + .5))
static void grids_setmiddle(void)
{
int mean = (GRIDS(grids_slider_right) + GRIDS(grids_slider_left)) /2.;
setslider(&grids_slider_middle, ((float)mean)/(GRIDS_MAX-1));
}
void grids_init()
{
setslider(&grids_slider_left, ((float)x_grids_page_v-1)/(GRIDS_MAX-1));
setslider(&grids_slider_right, ((float)y_grids_page_v-1)/(GRIDS_MAX-1));
grids_setmiddle();
setintgad(&x_grids_page,x_grids_page_v);
setintgad(&y_grids_page,y_grids_page_v);
}
void grids_slider_right_func (APTR object)
{
int grids = GRIDS(grids_slider_right);
setintgad(&y_grids_page, grids);
grids_setmiddle();
}
void grids_slider_middle_func(APTR object)
{
int grids = GRIDS(grids_slider_middle);
setslider(&grids_slider_left, ((float)grids-1)/(GRIDS_MAX-1));
setslider(&grids_slider_right, ((float)grids-1)/(GRIDS_MAX-1));
setintgad(&x_grids_page,grids);
setintgad(&y_grids_page,grids);
}
void grids_slider_left_func (APTR object)
{
int grids = GRIDS(grids_slider_left);
setintgad (&x_grids_page, grids);
grids_setmiddle();
}
void y_grids_func (APTR object)
{
int val;
GETSTRFIELD_I(y_grids_page, val);
setslider (&grids_slider_right, ((float)val-1)/(GRIDS_MAX-1));
grids_setmiddle();
}
void x_grids_func (APTR object)
{
int val;
GETSTRFIELD_I(x_grids_page, val);
setslider (&grids_slider_left, ((float)val-1)/(GRIDS_MAX-1));
grids_setmiddle();
}
/* ******************** */
#define MINORS_MAX (50)
#define MINORS(gad) ((int)(MINORS_MAX - RAWVAL(gad)*(MINORS_MAX-1.)/0xFFFF + .5))
static void minor_setmiddle(void)
{
int mean = (MINORS(minor_slider_right) + MINORS(minor_slider_left)) /2.;
setslider(&minor_slider_middle, ((float)mean)/(MINORS_MAX-1));
}
void minors_init()
{
setslider(&minor_slider_left, ((float)minor_x_v-1)/(MINORS_MAX-1));
setslider(&minor_slider_right, ((float)minor_y_v-1)/(MINORS_MAX-1));
minor_setmiddle();
setintgad(&minor_x,minor_x_v);
setintgad(&minor_y,minor_y_v);
}
void minor_slider_left_func (APTR object)
{
int minors = MINORS(minor_slider_left);
setintgad(&minor_x, minors);
minor_setmiddle();
}
void minor_slider_middle_func(APTR object)
{
int minors = MINORS(minor_slider_middle);
setslider(&minor_slider_left, ((float)minors-1)/(MINORS_MAX-1));
setslider(&minor_slider_right, ((float)minors-1)/(MINORS_MAX-1));
setintgad(&minor_x,minors);
setintgad(&minor_y,minors);
}
void minor_slider_right_func (APTR object)
{
int minors = MINORS(minor_slider_right);
setintgad(&minor_y, minors);
minor_setmiddle();
}
void minor_y_func (APTR object)
{
int val;
GETSTRFIELD_I(minor_y, val);
setslider (&minor_slider_right, ((float)val-1)/(MINORS_MAX-1));
minor_setmiddle();
}
void minor_x_func (APTR object)
{
int val;
GETSTRFIELD_I(minor_x, val);
setslider (&minor_slider_left, ((float)val-1)/(MINORS_MAX-1));
minor_setmiddle();
}