PROGRAM 2
/* filename: program1.c author: anthony f. ortiz */
/* this program implements a pull-down menu package with a layout application
that allows the user to draw objects (elipses, squares, and triangles) on
the screen. the user may also redraw the screen, save scene to file,
restore the scene from a file, or quit. */
#include "srgp.h"
#include "geom.h"
#include
#include
#include
#include
#include
#define string_size 15
#define array_size 26
#define max_shapes 25
typedef char str [string_size + 1];
#define x_min 0
#define y_min 0
#define x_max 639
#define y_max 479
/* the screen layout (file, edit, pen-shape, pattern, etc) */
struct boxes
{
int box_x_min;
int box_y_min;
int box_x_max;
int box_y_max;
str header;
} buttons [array_size];
static int count = 0;
static int count2 = 0;
int global_color;
/* the objects that the user draws on the screen, vital for saving and
restoring from a file. */
struct shapes
{
int bottomleftx;
int bottomlefty;
int toprightx;
int toprighty;
int color;
int kind;
} shapes [max_shapes];
struct word
{
int x;
int y;
char string [10];
int color;
int kind;
} words [max_shapes];
/* i did not use these definitions. however, a clearer program would use
these 19 definitions throughout the source code. */
#define menu_bar 0
#define file 1
#define edit 2
#define font_size 3
#define font_style 4
#define action 5
#define quit 6
#define save 7
#define open 8
#define delete 9
#define size_12 10
#define size_24 11
#define times 12
#define roman 13
#define modern 14
#define red 15
#define green 16
#define blue 17
#define rotate 18
#define move 19
#define scaleup 20
#define scaledown 21
#define ellipse 22
#define rect 23
#define triangle 24
#define letters 25
#define KEYMEASURE_SIZE 80
void input_headers ();
void initialize_buttons ();
void draw_menu ();
void highlevelinteractionhandler (locator_measure measureoflocator);
int correlatemenubar (point measureoflocator);
int performpulldownmenu (int menuid);
int performactionchosenfrommenu (int choosenitemindex);
int correlatedrawingarea (point measureoflocator);
void processobject (int objectid);
void highlevelinteractionhandler2 (char * measure);
int correlatemenubar2 (char measure);
void quit_program ();
void open_file ();
void save_screen ();
void clear_screen ();
void rotate_object ();
void move_object ();
void scale_down ();
void scale_up ();
void paint_red ();
void paint_green ();
void paint_blue ();
void set_font12 ();
void set_font24 ();
void set_times ();
void set_roman ();
void set_modern ();
void redraw_object (int index, int pt1x, int pt1y, int pt2x, int pt2y);
/* main program */
void main ()
{
locator_measure measureoflocator;
int device;
char * keymeasure;
SRGP_begin ("top-down menu", SCREEN_WIDTH, SCREEN_HEIGHT, 3, FALSE);
global_color = COLOR_WHITE;
input_headers ();
initialize_buttons ();
draw_menu ();
SRGP_setInputMode (LOCATOR, EVENT);
SRGP_setLocatorButtonMask (LEFT_BUTTON_MASK | RIGHT_BUTTON_MASK);
SRGP_setInputMode (KEYBOARD, EVENT);
SRGP_setKeyboardProcessingMode (RAW);
SRGP_setBackgroundColor (COLOR_BLACK);
SRGP_setColor (global_color);
do
{
device = SRGP_waitEvent (INDEFINITE);
if (device == LOCATOR)
SRGP_getLocator (&measureoflocator);
else
SRGP_getKeyboard (keymeasure, 2);
if (device == LOCATOR)
{
highlevelinteractionhandler (measureoflocator);
measureoflocator.button_chord [0] = UP;
}
else if (device == KEYBOARD)
{
highlevelinteractionhandler2 (keymeasure);
keymeasure [0] = '\0';
}
}
while (1);
}
/* get the menu headers from a data file and put them in an array. */
void input_headers ()
{
FILE * infile;
int i = 0;
infile = fopen ("headers.dat", "r");
while (! feof (infile))
{
fscanf (infile, "%s", buttons [i].header);
i++;
}
fclose (infile);
}
/* store the initial screen layout in an array of records. */
void initialize_buttons ()
{
int i;
buttons [0].box_x_min = x_min + 5;
buttons [0].box_y_min = y_max - y_max / 5.0;
buttons [0].box_x_max = x_max - 5;
buttons [0].box_y_max = y_max - 5;
for (i = 1; i <= 5; i++)
{
buttons [i].box_x_min = buttons [0].box_x_min + (i - 1) * 100 + 10;
buttons [i].box_y_min = buttons [0].box_y_min + 10;
buttons [i].box_x_max = buttons [0].box_x_min + i * 100;
buttons [i].box_y_max = buttons [0].box_y_max - 10;
}
for (i = 6; i <= 9; i++)
{
buttons [i].box_x_min = buttons [1].box_x_min;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 5) * 50;
buttons [i].box_x_max = buttons [1].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 6) * 50;
}
for (i = 10; i <= 11; i++)
{
buttons [i].box_x_min = buttons [2].box_x_min;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 9) * 50;
buttons [i].box_x_max = buttons [2].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 10) * 50;
}
for (i = 12; i <= 14; i++)
{
buttons [i].box_x_min = buttons [3].box_x_min;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 11) * 50;
buttons [i].box_x_max = buttons [3].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 12) * 50;
}
for (i = 15; i <= 17; i++)
{
buttons [i].box_x_min = buttons [4].box_x_min;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 14) * 50;
buttons [i].box_x_max = buttons [4].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 15) * 50;
}
for (i = 18; i <= 21; i++)
{
buttons [i].box_x_min = buttons [5].box_x_max - 100;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 17) * 50;
buttons [i].box_x_max = buttons [5].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 18) * 50;
}
for (i = 22; i <= 25; i++)
{
buttons [i].box_x_min = buttons [0].box_x_max - 100;
buttons [i].box_y_min = buttons [0].box_y_min - (i - 21) * 85;
buttons [i].box_x_max = buttons [0].box_x_max;
buttons [i].box_y_max = buttons [0].box_y_min - (i - 22) * 85 - 10;
}
}
/* draw the initial screen. also draw the sub-menus on a second screen
that will be visible later on in the program. */
void draw_menu ()
{
int i, width, height, descent, menucanvasid;
point centerofbutton, textorigin, pt1, pt2, pt3;
rectangle rec;
SRGP_rectangleCoord (buttons [0].box_x_min, buttons [0].box_y_min, buttons [0].box_x_max, buttons [0].box_y_max);
for (i = 1; i <= 5; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
for (i = 22; i <= 25; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
}
rec.bottom_left.x = buttons [22].box_x_min + 10;
rec.bottom_left.y = buttons [22].box_y_min + 10;
rec.top_right.x = buttons [22].box_x_max - 10;
rec.top_right.y = buttons [22].box_y_max - 10;
SRGP_ellipseArc (rec, 0.0, 360.0);
SRGP_rectangleCoord (buttons [23].box_x_min + 10, buttons [23].box_y_min + 10, buttons [23].box_x_max - 10, buttons [23].box_y_max - 10);
pt1.x = (buttons [24].box_x_max + buttons [24].box_x_min) / 2.0;
pt1.y = buttons [24].box_y_max - 10;
pt2.x = buttons [24].box_x_min + 10;
pt2.y = buttons [24].box_y_min + 10;
pt3.x = buttons [24].box_x_max - 10;
pt3.y = buttons [24].box_y_min + 10;
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt1);
textorigin.x = (buttons [25].box_x_max + buttons [25].box_x_min) / 2 - 10;
textorigin.y = (buttons [25].box_y_max + buttons [25].box_y_min) / 2;;
SRGP_text (textorigin,"abc");
menucanvasid = SRGP_createCanvas (x_max, y_max);
SRGP_useCanvas (menucanvasid);
for (i = 6; i <= 9; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
for (i = 10; i <= 11; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
for (i = 12; i <= 14; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
for (i = 15; i <= 17; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
for (i = 18; i <= 21; i++)
{
SRGP_rectangleCoord (buttons [i].box_x_min, buttons [i].box_y_min, buttons [i].box_x_max, buttons [i].box_y_max);
SRGP_inquireTextExtent (buttons [i].header, &width, &height, &descent);
centerofbutton.x = (buttons [i].box_x_min + buttons [i].box_x_max)/2;
centerofbutton.y = (buttons [i].box_y_min + buttons [i].box_y_max)/2;
textorigin.x = centerofbutton.x - (width / 2);
textorigin.y = centerofbutton.y - (height / 2);
SRGP_text (textorigin, buttons [i].header);
}
SRGP_useCanvas (SCREEN_CANVAS);
}
/* this is a high level interaction handler for mouse events. */
void highlevelinteractionhandler (locator_measure measureoflocator)
{
int i, menuid, chosenitemindex, objectid;
rectangle menubarextent;
/* SRGP_defRectangle does not work. */
menubarextent.top_right.x = buttons [0].box_x_max;
menubarextent.top_right.y = buttons [0].box_y_max;
menubarextent.bottom_left.x = buttons [0].box_x_min;
menubarextent.bottom_left.y = buttons [0].box_y_min;
if (GEOM_ptInRect (measureoflocator.position, menubarextent))
{
menuid = correlatemenubar (measureoflocator.position);
if (menuid > 0)
{
chosenitemindex = performpulldownmenu (menuid);
if (chosenitemindex > 0)
{
performactionchosenfrommenu (chosenitemindex);
}
}
}
else
{
objectid = correlatedrawingarea (measureoflocator.position);
if (objectid > 0) processobject (objectid);
}
}
/* see if the user chose one of the menus with the mouse. */
int correlatemenubar (point measureoflocator)
{
rectangle menubarextent;
int i;
for (i = 1; i <= 5; i++)
{
menubarextent.top_right.x = buttons [i].box_x_max;
menubarextent.top_right.y = buttons [i].box_y_max;
menubarextent.bottom_left.x = buttons [i].box_x_min;
menubarextent.bottom_left.y = buttons [i].box_y_min;
if (GEOM_ptInRect (measureoflocator, menubarextent))
{
return i;
}
}
return 0;
}
/* activate the sub-menus, deactivate them, and get a choice from the
sub-menus. */
int performpulldownmenu (int menuid)
{
int device, i, width, height, descent, savecanvasid, menucanvasid;
point centerofbutton, textorigin;
rectangle menucanvasextent, savecanvas, submenuextent;
locator_measure measureoflocator;
char * keymeasure;
switch (menuid)
{
case 1: menucanvasextent.top_right.x = buttons [6].box_x_max;
menucanvasextent.top_right.y = buttons [6].box_y_max;
menucanvasextent.bottom_left.x = buttons [9].box_x_min;
menucanvasextent.bottom_left.y = buttons [9].box_y_min;
savecanvas.bottom_left.x = 200;
savecanvas.bottom_left.y = 0;
savecanvas.top_right.x = 200 + buttons [6].box_x_max - buttons [9].box_x_min;
savecanvas.top_right.y = buttons [6].box_y_max - buttons [9].box_y_min;
break;
case 2: menucanvasextent.top_right.x = buttons [10].box_x_max;
menucanvasextent.top_right.y = buttons [10].box_y_max;
menucanvasextent.bottom_left.x = buttons [11].box_x_min;
menucanvasextent.bottom_left.y = buttons [11].box_y_min;
savecanvas.bottom_left.x = 200;
savecanvas.bottom_left.y = 0;
savecanvas.top_right.x = 200 + buttons [10].box_x_max - buttons [11].box_x_min;
savecanvas.top_right.y = buttons [10].box_y_max - buttons [11].box_y_min;
break;
case 3: menucanvasextent.top_right.x = buttons [12].box_x_max;
menucanvasextent.top_right.y = buttons [12].box_y_max;
menucanvasextent.bottom_left.x = buttons [14].box_x_min;
menucanvasextent.bottom_left.y = buttons [14].box_y_min;
savecanvas.bottom_left.x = 200;
savecanvas.bottom_left.y = 0;
savecanvas.top_right.x = 200 + buttons [12].box_x_max - buttons [14].box_x_min;
savecanvas.top_right.y = buttons [12].box_y_max - buttons [14].box_y_min;
break;
case 4: menucanvasextent.top_right.x = buttons [15].box_x_max;
menucanvasextent.top_right.y = buttons [15].box_y_max;
menucanvasextent.bottom_left.x = buttons [17].box_x_min;
menucanvasextent.bottom_left.y = buttons [17].box_y_min;
savecanvas.bottom_left.x = 200;
savecanvas.bottom_left.y = 0;
savecanvas.top_right.x = 200 + buttons [15].box_x_max - buttons [17].box_x_min;
savecanvas.top_right.y = buttons [15].box_y_max - buttons [17].box_y_min;
break;
case 5: menucanvasextent.top_right.x = buttons [18].box_x_max;
menucanvasextent.top_right.y = buttons [18].box_y_max;
menucanvasextent.bottom_left.x = buttons [21].box_x_min;
menucanvasextent.bottom_left.y = buttons [21].box_y_min;
savecanvas.bottom_left.x = 200;
savecanvas.bottom_left.y = 0;
savecanvas.top_right.x = 200 + buttons [18].box_x_max - buttons [21].box_x_min;
savecanvas.top_right.y = buttons [18].box_y_max - buttons [21].box_y_min;
break;
}
SRGP_useCanvas (1);
SRGP_copyPixel (SCREEN_CANVAS,menucanvasextent,savecanvas.bottom_left);
savecanvasid = SRGP_inquireActiveCanvas ();
SRGP_useCanvas (SCREEN_CANVAS);
SRGP_copyPixel (savecanvasid, menucanvasextent, menucanvasextent.bottom_left);
measureoflocator.button_chord [0] = UP;
keymeasure [0] = '\0';
do
{
device = SRGP_waitEvent (INDEFINITE);
if (device == LOCATOR)
{
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
SRGP_copyPixel (savecanvasid, savecanvas, menucanvasextent.bottom_left);
}
else
{
SRGP_getKeyboard (keymeasure, 2);
if (keymeasure [0] != '\0')
SRGP_copyPixel (savecanvasid, savecanvas, menucanvasextent.bottom_left);
}
}
while (measureoflocator.button_chord [0] == UP && keymeasure [0] == '\0');
if (device == LOCATOR)
{
for (i = 6; i <= 21; i++)
{
submenuextent.top_right.x = buttons [i].box_x_max;
submenuextent.top_right.y = buttons [i].box_y_max;
submenuextent.bottom_left.x = buttons [i].box_x_min;
submenuextent.bottom_left.y = buttons [i].box_y_min;
if (GEOM_ptInRect (measureoflocator.position, submenuextent))
{
return i;
}
}
}
else if (device == KEYBOARD)
{
switch (keymeasure [0])
{
case 'a': return 6;
case 'b': return 7;
case 'c': return 8;
case 'd': return 9;
case 'e': return 10;
case 'f': return 11;
case 'g': return 12;
case 'h': return 13;
case 'i': return 14;
case 'j': return 15;
case 'k': return 16;
case 'l': return 17;
case 'm': return 18;
case 'n': return 19;
case 'o': return 20;
case 'p': return 21;
}
}
return 0;
}
/* perform one of the actions associated with the sub-menus. */
int performactionchosenfrommenu (int choosenitemindex)
{
switch (choosenitemindex)
{
case 6: quit_program ();
break;
case 7: open_file ();
break;
case 8: save_screen ();
break;
case 9: clear_screen ();
break;
case 10: set_font12 ();
break;
case 11: set_font24 ();
break;
case 12: set_times ();
break;
case 13: set_roman ();
break;
case 14: set_modern ();
break;
case 15: paint_red ();
break;
case 16: paint_green ();
break;
case 17: paint_blue ();
break;
case 18: rotate_object ();
break;
case 19: move_object ();
break;
case 20: scale_down ();
break;
case 21: scale_up ();
break;
}
return 0;
}
/* see if the user picked one of the objects with the mouse. */
int correlatedrawingarea (point measureoflocator)
{
int i;
rectangle objectextent;
for (i = 22; i <= 25; i++)
{
objectextent.top_right.x = buttons [i].box_x_max;
objectextent.top_right.y = buttons [i].box_y_max;
objectextent.bottom_left.x = buttons [i].box_x_min;
objectextent.bottom_left.y = buttons [i].box_y_min;
if (GEOM_ptInRect (measureoflocator, objectextent))
{
return i;
}
}
return 0;
}
/* put an object on the screen using the mouse. */
void processobject (int objectid)
{
int device, i;
char measure [10];
point pt1, pt2, pt3, pt4;
rectangle rec;
locator_measure measureoflocator;
if (objectid == 22 || objectid == 23 || objectid == 24)
{
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
pt1 = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
pt2 = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
}
shapes [count].bottomleftx = pt1.x;
shapes [count].bottomlefty = pt1.y;
shapes [count].toprightx = pt2.x;
shapes [count].toprighty = pt2.y;
shapes [count].color = global_color;
shapes [count].kind = objectid;
switch (objectid)
{
case 22: rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt2.x;
rec.top_right.y = pt2.y;
SRGP_ellipseArc (rec, 0.0, 360.0);
count++;
break;
case 23: SRGP_rectangleCoord (pt1.x, pt1.y, pt2.x, pt2.y);
count++;
break;
case 24: pt3.x = (pt1.x + pt2.x) / 2;
pt3.y = pt2.y;
pt4.x = pt2.x;
pt4.y = pt1.y;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
count++;
break;
case 25: measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
pt2 = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
for (i = 0; i <= 10; i++)
{
measure [i] = getch ();
if (measure [i] == 13)
{
break;
}
}
measure [i] = '\0';
SRGP_text (measureoflocator.position, measure);
words [count2].x = pt2.x;
words [count2].y = pt2.y;
strcpy (words [count2].string, measure);
words [count2].color = SRGP_inquireColor ();
words [count2].kind = 25;
measure [0] = '\0';
count2++;
break;
}
}
/* this is a high level interaction handler for the keyboard. */
void highlevelinteractionhandler2 (char * measure)
{
int menuid, chosenitemindex;
if (measure [0] == 'f' || measure [0] == 'e' || measure [0] == 's' || measure [0] == 'p' || measure [0] == 'a')
{
menuid = correlatemenubar2 (measure [0]);
if (menuid > 0)
chosenitemindex = performpulldownmenu (menuid);
if (chosenitemindex > 0)
performactionchosenfrommenu (chosenitemindex);
}
}
/* see whether the user picked one of the menus with the keyboard. */
int correlatemenubar2 (char measure)
{
switch (measure)
{
case 'f': return 1;
case 'e': return 2;
case 's': return 3;
case 'p': return 4;
case 'a': return 5;
}
return 0;
}
/* quit the program. */
void quit_program ()
{
SRGP_end ();
exit (0);
}
/* open the data file "shapes.dat" to retrieve the objects and display
them on the screen. */
void open_file ()
{
int i;
FILE * outfile;
outfile = fopen ("shapes.out", "w");
for (i = 0; i < count; i++)
{
fprintf (outfile, "%d ", shapes [i].bottomleftx);
fprintf (outfile, "%d ", shapes [i].bottomlefty);
fprintf (outfile, "%d ", shapes [i].toprightx);
fprintf (outfile, "%d ", shapes [i].toprighty);
fprintf (outfile, "%d ", shapes [i].color);
fprintf (outfile, "%d ", shapes [i].kind);
}
fclose (outfile);
outfile = fopen ("words.out", "w");
for (i = 0; i < count2; i++)
{
fprintf (outfile, "%d ", words [i].x);
fprintf (outfile, "%d ", words [i].y);
fprintf (outfile, "%s ", words [i].string);
fprintf (outfile, "%d ", words [i].color);
fprintf (outfile, "%d ", words [i].kind);
}
fclose (outfile);
}
/* put the objects in a data file called "shapes.dat". */
void save_screen ()
{
int i;
FILE * outfile, *infile;
rectangle clearscreen, rec;
point pt1, pt2, pt3, pt4;
count = 0;
for (i = 0; i < max_shapes; i++)
{
shapes [i].kind = 0;
shapes [i].color = 0;
}
clearscreen.bottom_left.x = 0;
clearscreen.bottom_left.y = 0;
clearscreen.top_right.x = buttons [22].box_x_min - 1;
clearscreen.top_right.y = buttons [22].box_y_max - 1;
SRGP_setFillStyle (SOLID);
SRGP_setColor (COLOR_BLACK);
SRGP_fillRectangle (clearscreen);
SRGP_setColor (global_color);
count = 0;
for (i = 0; i < max_shapes; i++)
{
words [i].kind = 0;
words [i].color = 0;
}
infile = fopen ("shapes.out", "r");
while (!feof (infile))
{
fscanf (infile, "%d", &shapes [count].bottomleftx);
fscanf (infile, "%d", &shapes [count].bottomlefty);
fscanf (infile, "%d", &shapes [count].toprightx);
fscanf (infile, "%d", &shapes [count].toprighty);
fscanf (infile, "%d", &shapes [count].color);
fscanf (infile, "%d", &shapes [count].kind);
SRGP_setColor (shapes [count].color);
switch (shapes [count].kind)
{
case 22: rec.bottom_left.x = shapes [count].bottomleftx;
rec.bottom_left.y = shapes [count].bottomlefty;
rec.top_right.x = shapes [count].toprightx;
rec.top_right.y = shapes [count].toprighty;
SRGP_ellipseArc (rec, 0.0, 360.0);
break;
case 23: SRGP_rectangleCoord (shapes [count].bottomleftx, shapes [count].bottomlefty, shapes [count].toprightx, shapes [count].toprighty);
break;
case 24: pt1.x = shapes [count].bottomleftx;
pt1.y = shapes [count].bottomlefty;
pt2.x = shapes [count].toprightx;
pt2.y = shapes [count].toprighty;
pt3.x = (shapes [count].bottomleftx + shapes [count].toprightx) / 2;
pt3.y = shapes [count].toprighty;
pt4.x = shapes [count].toprightx;
pt4.y = shapes [count].bottomlefty;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
break;
}
count = count + 1;
}
fclose (infile);
count2 = 0;
infile = fopen ("words.out", "r");
while (!feof (infile))
{
fscanf (infile, "%d", &words [count2].x);
fscanf (infile, "%d", &words [count2].y);
fscanf (infile, "%s", words [count2].string);
fscanf (infile, "%d", &words [count2].color);
fscanf (infile, "%d", &words [count2].kind);
pt1.x = words [count2].x;
pt1.y = words [count2].y;
SRGP_setColor (words [count2].color);
SRGP_text (pt1, words [count2].string);
count2 = count2 + 1;
}
SRGP_setColor (global_color);
close (infile);
}
/* clear the screen and initialize the size and shapes array to NULL. */
void clear_screen ()
{
int i;
rectangle clearscreen;
for (i = 0; i < max_shapes; i++)
{
shapes [i].kind = 0;
shapes [i].color = 0;
}
for (i = 0; i < max_shapes; i++)
{
words [i].kind = 0;
shapes [i].color = 0;
}
clearscreen.bottom_left.x = 0;
clearscreen.bottom_left.y = 0;
clearscreen.top_right.x = buttons [22].box_x_min - 1;
clearscreen.top_right.y = buttons [22].box_y_max - 1;
SRGP_setFillStyle (SOLID);
SRGP_setColor (COLOR_BLACK);
SRGP_fillRectangle (clearscreen);
SRGP_setColor (global_color);
count = 0;
count2 = 0;
}
/* rotate an object using algorithm in the book (tranlate to orgin, rotate,
and translate back to original point). */
void rotate_object ()
{
int i, j, flag;
int pt1x, pt1y, pt2x, pt2y, pt3x, pt3y, pt4x, pt4y;
double degree, scale;
rectangle clearscreen, rec, testshape;
point pt1, pt2, pt3, pt4, sh;
locator_measure measureoflocator;
int device;
flag = 0;
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
sh = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
for (i = 0; i < count; i++)
{
testshape.bottom_left.x = shapes [i].bottomleftx;
testshape.bottom_left.y = shapes [i].bottomlefty;
testshape.top_right.x = shapes [i].toprightx;
testshape.top_right.y = shapes [i].toprighty;
if (GEOM_ptInRect (sh, testshape))
{
flag = 1;
break;
}
}
if (flag == 1)
{
switch (shapes [i].kind)
{
case 22: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt3.x;
rec.top_right.y = pt3.y;
for (j = 1; j <= 360; j++)
{
degree = j * .0175;
SRGP_setColor (COLOR_BLACK);
SRGP_ellipseArc (rec, 0.0, 360.0);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * cos (degree) + (pt1y - pt1y) * sin (degree) + pt1x;
pt1.y = (pt1x - pt1x) * sin (degree) + (pt1y - pt1y) * cos (degree) + pt1y;
pt3.x = (pt3x - pt1x) * cos (degree) + (pt3y - pt1y) * sin (degree) + pt1x;
pt3.y = (pt3x - pt1x) * sin (degree) + (pt3y - pt1y) * cos (degree) + pt1y;
if (pt1.x < pt3.x)
{
rec.bottom_left.x = pt1.x;
rec.top_right.x = pt3.x;
}
else
{
rec.bottom_left.x = pt3.x;
rec.top_right.x = pt1.x ;
}
if (pt1.y < pt3.y)
{
rec.bottom_left.y = pt1.y;
rec.top_right.y = pt3.y;
}
else
{
rec.bottom_left.y = pt3.y;
rec.top_right.y = pt1.y;
}
SRGP_ellipseArc (rec, 0.0, 360.0);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 23: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
pt4x = pt4.x = shapes [i].bottomleftx;
pt4y = pt4.y = shapes [i].toprighty;
for (j = 1; j <= 360; j++)
{
degree = j * .0175;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * cos (degree) + (pt1y - pt1y) * sin (degree) + pt1x;
pt1.y = (pt1x - pt1x) * sin (degree) + (pt1y - pt1y) * cos (degree) + pt1y;
pt2.x = (pt2x - pt1x) * cos (degree) + (pt2y - pt1y) * sin (degree) + pt1x;
pt2.y = (pt2x - pt1x) * sin (degree) + (pt2y - pt1y) * cos (degree) + pt1y;
pt3.x = (pt3x - pt1x) * cos (degree) + (pt3y - pt1y) * sin (degree) + pt1x;
pt3.y = (pt3x - pt1x) * sin (degree) + (pt3y - pt1y) * cos (degree) + pt1y;
pt4.x = (pt4x - pt1x) * cos (degree) + (pt4y - pt1y) * sin (degree) + pt1x;
pt4.y = (pt4x - pt1x) * sin (degree) + (pt4y - pt1y) * cos (degree) + pt1y;
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
SRGP_rectangleCoord (shapes [i].bottomleftx, shapes [i].bottomlefty, shapes [i].toprightx, shapes [i].toprighty);
break;
case 24: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].toprighty;
pt3x = pt3.x = (pt1.x + pt2.x) / 2;
pt3y = pt3.y = pt2.y;
pt4x = pt4.x = pt2.x;
pt4y = pt4.y = pt1.y;
for (j = 1; j <= 360; j++)
{
degree = j * .0175;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * cos (degree) + (pt1y - pt1y) * sin (degree) + pt1x;
pt1.y = (pt1x - pt1x) * sin (degree) + (pt1y - pt1y) * cos (degree) + pt1y;
pt3.x = (pt3x - pt1x) * cos (degree) + (pt3y - pt1y) * sin (degree) + pt1x;
pt3.y = (pt3x - pt1x) * sin (degree) + (pt3y - pt1y) * cos (degree) + pt1y;
pt4.x = (pt4x - pt1x) * cos (degree) + (pt4y - pt1y) * sin (degree) + pt1x;
pt4.y = (pt4x - pt1x) * sin (degree) + (pt4y - pt1y) * cos (degree) + pt1y;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = pt1x;
pt1.y = pt1y;
pt3.x = pt3x;
pt3.y = pt3y;
pt4.x = pt4x;
pt4.y = pt4y;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
break;
}
SRGP_setColor (global_color);
}
}
/* move object using algorithm in the book. */
void move_object ()
{
int i, j, flag;
int pt1x, pt1y, pt2x, pt2y, pt3x, pt3y, pt4x, pt4y;
double degree, scale;
rectangle clearscreen, rec, testshape;
point pt1, pt2, pt3, pt4, sh;
locator_measure measureoflocator;
int device;
flag = 0;
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
sh = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
for (i = 0; i < count; i++)
{
testshape.bottom_left.x = shapes [i].bottomleftx;
testshape.bottom_left.y = shapes [i].bottomlefty;
testshape.top_right.x = shapes [i].toprightx;
testshape.top_right.y = shapes [i].toprighty;
if (GEOM_ptInRect (sh, testshape))
{
flag = 1;
break;
}
}
if (flag == 1)
{
switch (shapes [i].kind)
{
case 22: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
rec.bottom_left.x = pt1.x;
rec.top_right.x = pt3.x;
rec.bottom_left.y = pt1.y;
rec.top_right.y = pt3.y;
for (j = 1; j <= 360; j++)
{
SRGP_setColor (COLOR_BLACK);
SRGP_ellipseArc (rec, 0.0, 360.0);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - j);
pt1.y = (pt1y - j);
pt3.x = (pt3x - j);
pt3.y = (pt3y - j);
rec.bottom_left.x = pt1.x;
rec.top_right.x = pt3.x;
rec.bottom_left.y = pt1.y;
rec.top_right.y = pt3.y;
if (pt3.x < 0 || pt3.y < 0)
break;
SRGP_ellipseArc (rec, 0.0, 360.0);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 23: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
pt4x = pt4.x = shapes [i].bottomleftx;
pt4y = pt4.y = shapes [i].toprighty;
for (j = 1; j <= 360; j++)
{
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = pt1x - j;
pt1.y = pt1y - j;
pt2.x = pt2x - j;
pt2.y = pt2y - j;
pt3.x = pt3x - j;
pt3.y = pt3y - j;
pt4.x = pt4x - j;;
pt4.y = pt4y - j;
if (pt3.x < 0 || pt3.y < 0)
break;
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 24: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].toprighty;
pt3x = pt3.x = (pt1.x + pt2.x) / 2;
pt3y = pt3.y = pt2.y;
pt4x = pt4.x = pt2.x;
pt4y = pt4.y = pt1.y;
for (j = 1; j <= 360; j++)
{
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = pt1x - j;
pt1.y = pt1y - j;
pt3.x = pt3x - j;
pt3.y = pt3y - j;
pt4.x = pt4x - j;
pt4.y = pt4y - j;
if (pt3.x < 0 || pt3.y < 0)
break;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
}
SRGP_setColor (global_color);
}
}
/* scale down using algorithm in the book (translate to orgin, scale, and
translate back to original point). */
void scale_down ()
{
int i, j, flag;
int pt1x, pt1y, pt2x, pt2y, pt3x, pt3y, pt4x, pt4y;
double degree, scale;
rectangle clearscreen, rec, testshape;
point pt1, pt2, pt3, pt4, sh;
locator_measure measureoflocator;
int device;
flag = 0;
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
sh = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
for (i = 0; i < count; i++)
{
testshape.bottom_left.x = shapes [i].bottomleftx;
testshape.bottom_left.y = shapes [i].bottomlefty;
testshape.top_right.x = shapes [i].toprightx;
testshape.top_right.y = shapes [i].toprighty;
if (GEOM_ptInRect (sh, testshape))
{
flag = 1;
break;
}
}
if (flag == 1)
{
switch (shapes [i].kind)
{
case 22: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt3.x;
rec.top_right.y = pt3.y;
for (j = 100; j >= 1; j--)
{
scale = ((double) j) / 100.0;
SRGP_setColor (COLOR_BLACK);
SRGP_ellipseArc (rec, 0.0, 360.0);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt3.x;
rec.top_right.y = pt3.y;
SRGP_ellipseArc (rec, 0.0, 360.0);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 23: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
pt4x = pt4.x = shapes [i].bottomleftx;
pt4y = pt4.y = shapes [i].toprighty;
for (j = 100; j >= 1; j--)
{
scale = ((double) j) / 100.00;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt2.x = (pt2x - pt1x) * scale + pt1x;
pt2.y = (pt2y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
pt4.x = (pt4x - pt1x) * scale + pt1x;
pt4.y = (pt4y - pt1y) * scale + pt1y;
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 24: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].toprighty;
pt3x = pt3.x = (pt1.x + pt2.x) / 2;
pt3y = pt3.y = pt2.y;
pt4x = pt4.x = pt2.x;
pt4y = pt4.y = pt1.y;
for (j = 100; j >= 1; j--)
{
scale = ((double) j) / 100.0;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
pt4.x = (pt4x - pt1x) * scale + pt1x;
pt4.y = (pt4y - pt1y) * scale + pt1y;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt4.x, pt3.y);
break;
}
SRGP_setColor (global_color);
}
}
/* scale up using algorithm in the book (translate to orgin, scale, and
translate back to original point). */
void scale_up ()
{
int i, j, flag;
int pt1x, pt1y, pt2x, pt2y, pt3x, pt3y, pt4x, pt4y;
double degree, scale;
rectangle clearscreen, rec, testshape;
point pt1, pt2, pt3, pt4, sh;
locator_measure measureoflocator;
int device;
flag = 0;
measureoflocator.button_chord [0] = UP;
do
{
device = SRGP_waitEvent (INDEFINITE);
SRGP_getLocator (&measureoflocator);
if (measureoflocator.button_chord [0] == DOWN)
sh = measureoflocator.position;
}
while (measureoflocator.button_chord [0] == UP);
for (i = 0; i < count; i++)
{
testshape.bottom_left.x = shapes [i].bottomleftx;
testshape.bottom_left.y = shapes [i].bottomlefty;
testshape.top_right.x = shapes [i].toprightx;
testshape.top_right.y = shapes [i].toprighty;
if (GEOM_ptInRect (sh, testshape))
{
flag = 1;
break;
}
}
if (flag == 1)
{
switch (shapes [i].kind)
{
case 22: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt3.x;
rec.top_right.y = pt3.y;
for (j = 1; j <= 100; j++)
{
scale = 1.00 + ((double) j) / 100.00;
SRGP_setColor (COLOR_BLACK);
SRGP_ellipseArc (rec, 0.0, 360.0);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
rec.bottom_left.x = pt1.x;
rec.bottom_left.y = pt1.y;
rec.top_right.x = pt3.x;
rec.top_right.y = pt3.y;
SRGP_ellipseArc (rec, 0.0, 360.0);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 23: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].bottomlefty;
pt3x = pt3.x = shapes [i].toprightx;
pt3y = pt3.y = shapes [i].toprighty;
pt4x = pt4.x = shapes [i].bottomleftx;
pt4y = pt4.y = shapes [i].toprighty;
for (j = 1; j <= 100; j++)
{
scale = 1.00 + ((double) j) / 100.00;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt2.x = (pt2x - pt1x) * scale + pt1x;
pt2.y = (pt2y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
pt4.x = (pt4x - pt1x) * scale + pt1x;
pt4.y = (pt4y - pt1y) * scale + pt1y;
SRGP_line (pt1, pt2);
SRGP_line (pt2, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt3.x, pt3.y);
break;
case 24: pt1x = pt1.x = shapes [i].bottomleftx;
pt1y = pt1.y = shapes [i].bottomlefty;
pt2x = pt2.x = shapes [i].toprightx;
pt2y = pt2.y = shapes [i].toprighty;
pt3x = pt3.x = (pt1.x + pt2.x) / 2;
pt3y = pt3.y = pt2.y;
pt4x = pt4.x = pt2.x;
pt4y = pt4.y = pt1.y;
for (j = 1; j <= 100; j++)
{
scale = 1.00 + ((double) j) / 100.00;
SRGP_setColor (COLOR_BLACK);
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
SRGP_setColor (shapes [i].color);
pt1.x = (pt1x - pt1x) * scale + pt1x;
pt1.y = (pt1y - pt1y) * scale + pt1y;
pt3.x = (pt3x - pt1x) * scale + pt1x;
pt3.y = (pt3y - pt1y) * scale + pt1y;
pt4.x = (pt4x - pt1x) * scale + pt1x;
pt4.y = (pt4y - pt1y) * scale + pt1y;
SRGP_line (pt1, pt3);
SRGP_line (pt3, pt4);
SRGP_line (pt4, pt1);
delay (50);
}
redraw_object (i, pt1.x, pt1.y, pt4.x, pt3.y);
break;
}
SRGP_setColor (global_color);
}
}
/* paint the next objects red. */
void paint_red ()
{
SRGP_loadCommonColor (2, "red");
SRGP_setColor (2);
global_color = 2;
}
/* paint the next objects green. */
void paint_green ()
{
SRGP_loadCommonColor (3, "green");
SRGP_setColor (3);
global_color = 3;
}
/* paint the next objects blue. */
void paint_blue ()
{
SRGP_loadCommonColor (4, "blue");
SRGP_setColor (4);
global_color = 4;
}
/* set the font size to 12. */
/* no information on this in book, note, or disk. */
void set_font12 ()
{
}
/* set the font size to 24. */
/* no information on this in book, note, or disk. */
void set_font24 ()
{
}
/* set the font size to times. */
/* no information on this in book, note, or disk. */
void set_times ()
{
}
/* set the font size to roman. */
/* no information on this in book, note, or disk. */
void set_roman ()
{
}
/* set the font size to modern. */
/* no information on this in book, note, or disk. */
void set_modern ()
{
}
/* redraw the original object on the screen. */
void redraw_object (int index, int pt1x, int pt1y, int pt2x, int pt2y)
{
shapes [index].bottomleftx = pt1x;
shapes [index].bottomlefty = pt1y;
shapes [index].toprightx = pt2x;
shapes [index].toprighty = pt2y;
}
/* data file: headers.dat */
*
file
font_size
font_style
colors
action
quit
save
open
delete
size_12
size_24
times
roman
modern
red
green
blue
rotate
move
scale_down
scale_up
/* outfile: prog2.out */
/* sorry, can't show you the output for this program. */
BACK TO CS4840 PAGE.