home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of A1200
/
World_Of_A1200.iso
/
programs
/
printer
/
graphpaper
/
src
/
src.lha
/
events.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-06
|
5KB
|
220 lines
/* access the LongInt field of an integer gadget */
#include "graph.h"
int x_dpi_V;
int y_dpi_V;
int Minor_Thickness_V;
int Major_Thickness_V;
float x_size_v;
float y_size_v;
int x_grids_page_v;
int y_grids_page_v;
int minor_x_v;
int minor_y_v;
static void set_maxthick()
{
if (Minor_Thickness_V > Major_Thickness_V ) {
maxthick = Minor_Thickness_V;
} else {
maxthick = Major_Thickness_V;
}
}
static void show_vals(void)
{
printf("x_dpi = %d\n", x_dpi_V);
printf("y_dpi = %d\n", y_dpi_V);
printf("Minor_Thickness = %d\n", Minor_Thickness_V);
printf("Major_Thickness = %d\n", Major_Thickness_V);
printf("x_size %f\n", x_size_v);
printf("y_size %f\n", y_size_v);
printf("x_grids_page_v = %d\n", x_grids_page_v);
printf("y_grids_page_v = %d\n", y_grids_page_v);
printf("minor_x_v = %d\n", minor_x_v);
printf("minor_y_v = %d\n", minor_y_v);
printf("maxthick = %d\n", maxthick);
}
/* Gadgets */
void GetValues(void)
{
x_dpi_V = INTFIELD(x_dpi);
y_dpi_V = INTFIELD(y_dpi);
Minor_Thickness_V = INTFIELD(Minor_Thickness);
Major_Thickness_V = INTFIELD(Major_Thickness);
sscanf(STRFIELD(x_size), "%f", &x_size_v);
sscanf(STRFIELD(y_size), "%f", &y_size_v);
x_grids_page_v = INTFIELD(x_grids_page);
y_grids_page_v = INTFIELD(y_grids_page);
minor_x_v = INTFIELD(minor_x);
minor_y_v = INTFIELD(minor_y);
set_maxthick();
}
void initialize(void)
{
INTFIELD(x_dpi) = 300;
INTFIELD(y_dpi) = 300;
INTFIELD(Minor_Thickness) = 1;
INTFIELD(Major_Thickness) = 4;
sprintf((char *) x_dpiSIBuff,"%d", INTFIELD(x_dpi));
sprintf((char *) y_dpiSIBuff,"%d", INTFIELD(y_dpi));
sprintf((char *)Minor_ThicknessSIBuff,"%d", INTFIELD(Minor_Thickness));
sprintf((char *)Major_ThicknessSIBuff,"%d", INTFIELD(Major_Thickness));
set_maxthick();
GetValues();
/* these will be initialized once main gets far enough */
x_size_v = 1.0;
y_size_v = 1.0;
x_grids_page_v = 9;
y_grids_page_v = 7;
minor_x_v = 10;
minor_y_v = 10;
/* show_vals(); */
}
void OffGad(struct Gadget *gad)
{
#if 0
if (gad->GadgetText) {
printf("Turning off %s\n", gad->GadgetText->IText);
}
#endif
gad->UserData = (APTR)gad->Flags; /* remember old enabled flag */
SnipAllBut(gad);
OffGadget(gad, wG, NULL);
RestoreGads();
}
#define dotogads(func) \
func(&LogLog); \
func(&LogY); \
func(&LogX); \
func(&None); \
func(&Linear); \
/* func(&go); skip go - that one becomes the Cancel gadget */ \
func(&check); \
func(&Major_Thickness); \
func(&Minor_Thickness); \
func(&x_dpi); \
func(&y_dpi); \
func(&x_size); \
func(&y_size); \
func(&size_slider_left); \
func(&size_slider_middle); \
func(&size_slider_right); \
func(&x_grids_page); \
func(&y_grids_page); \
func(&grids_slider_left); \
func(&grids_slider_middle); \
func(&grids_slider_right); \
func(&minor_x); \
func(&minor_y); \
func(&minor_slider_left); \
func(&minor_slider_middle); \
func(&minor_slider_right);
void TurnOffGadgets(void)
{
dotogads(OffGad);
}
void OnGad(struct Gadget *gad)
{
#if 0
if (gad->GadgetText) {
printf("Turning on %s\n", gad->GadgetText->IText);
}
#endif
/* check to make sure it was enabled before */
if ( !(((int)gad->UserData) & GFLG_DISABLED) ) {
SnipAllBut(gad);
OnGadget(gad, wG, NULL);
RestoreGads();
}
}
void TurnOnGadgets(void)
{
dotogads(OnGad);
}
/* batch callable */
void do_graph(int doit)
{
message("Allocating memory ...");
if (!getraster()) {
return;
}
message("Creating graph ...");
DrawGraph();
message("Checking graph ...");
if (PrintGraph(SPECIAL_NOPRINT)) {
/* it fits, do it for real */
if (doit) {
message("Printing graph ...");
if (PrintGraph(0)) {
message("Done.");
} else {
/* the PrintGraph routine supplies a message if it fails */
}
} else {
sprintf(messagebuf, "OK. Graph size is %.3f x %.3f",
(float)(((float)WIDTH) /x_dpi_V),
(float)(((float)HEIGHT)/y_dpi_V));
message(messagebuf);
}
} else {
/* not enough room */
sprintf(messagebuf, "Sorry, graph size is %.3f x %.3f; too big for paper.",
(float)(((float)WIDTH) /x_dpi_V),
(float)(((float)HEIGHT)/y_dpi_V));
message(messagebuf);
}
freeraster(); /* in case dpi or size changes */
}
static void tryit(int doit)
{
GetValues();
/* show_vals(); */
/* change go gadget to abort gadget */
go.GadgetText->IText = (UBYTE *)"ABORT";
RefreshOneGad(&go);
TurnOffGadgets();
do_graph(doit);
/* restore go gadget */
go.GadgetText->IText = (UBYTE *)"PRINT";
RefreshOneGad(&go);
TurnOnGadgets();
}
void go_func(APTR object)
{
tryit(1);
}
void check_func(APTR object)
{
tryit(0);
}
/* Menu Items */
void Project_Quit(APTR object)
{
quit(object);
}