References:
1) Course textbook 2) /opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/doc/X_srgp.txtFor this lab you will write a program to draw the icon area of an interactive drawing program (actually a painting program) that allows exiting by clicking the left mouse button on a "quit" button.
/opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB
Some documentation for SRGP can be obtained in:
/opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/doc/X_srgp.txt
You can print out a nicely formatted PostScript version of this info by:
lpr /opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/doc/X_srgp.psYou can look at (and run!) the examples of programs using SRGP in the following directory (read the README file first):
/opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/examples
So you can use this package to compile and run your programs since I have
opened the permissions to the above directories. There are two sample
programs in the
lab2
subdirectory of the course directory:
lab2sample
(which I wrote) and
Demo_Paint, a student program.
2) In the main program file (or in any file where you want to call SRGP routines), you should include srgp.h ( i.e. #include "srgp.h" ).
In the main program body, you need to initialize SRGP before you make any calls to SRGP routines. To do this, call
SRGP_begin("Lab 2", 400, 400, 0, FALSE);
You may use different parameters, for example you could change 400,400 to
500,500 to get a larger window. Also, you can change the
FALSE
to TRUE if
you want an SRGPlogfile generated for each program run, which is sometimes
useful for debugging. After the initialization, then you may start making
calls to the SRGP routines to draw primitives, change color, etc. To
terminate SRGP you must do the following:
SRGP_end();However, if you only do this, your primitives will be drawn and then will disappear almost instantly. In order to stop the program from exiting (and to stop execution of an SRGP program in general), it is necessary to have the program wait for input from the user.
SRGP_setInputMode(LOCATOR, EVENT);Then draw the icons - this is part of initialization of the interface.
Next create the top-level interaction loop: a while ( !done ) loop that looks for a down-press of the left mouse button. As part of the locator measure structure, you can examine the point where the down-press occurred and take appropriate action. In lab2b if the point is in any of the icon squares, you will call the appropriate interaction-handling routine -- say DoEllipse() if the locator point is in the ellipse icon box. However for this lab you only have to test if the point is in the "quit" box, in which case the variable done should be set to TRUE, causing the program to exit. Here is some sample code/pseudocode:
declare a variable locMeasure to be of type locator_measure
while ( !done ) {
do { // get only left mouse button down-presses
SRGP_waitEvent ( INDEFINITE ) ;
SRGP_getLocator ( &locMeasure ) ;
} while ( locMeasure.buttonChord[LEFT_BUTTON] != DOWN ) ;
if ( locMeasure.position.x < x coordinate of right side of "quit" box ) and
( locMeasure.position.y < y coordinate of top of "quit" box ) then
done = TRUE ;
}
Thus your program can have the following form:
1. Start SRGP
2. Set the locator input mode
3. Draw the icons
4. Create the top-level interaction loop
5. Make a call to SRGP_end() to exit your program
3) You can find a copy of a Makefile
that can be used to compile your program in the
directory /opt/local/studata/COURSES/cs5721/lab2.
Look at the Makefile
for more information on how to use it and what it does.
Makefile is a copy of Makefile.ub and
can be used to compile programs on the ub or bulldog computers.
Makefile.cs can be used to compile programs on the
csdev computers in HH 314 if you want to work there and not have to log on
to ub or bulldog.
To get a "snapshot" of a window, you can use the X window capture
program, xv (which I think is short for X View)
on ub or bulldog.
It allows you to print the captured window (or screen or rectangle).
Again, ask a lab consultant for help if needed. There are other
ways of doing this directly from PCs (or Macs).
What to turn in:
Turn in the following items from the
Computer Science Lab Report Format:
1. (1 point) The Basic Information (your name, class, section,
TA's name, assignment number, and date) can be on a separate cover sheet or as
(highlighted) comments at the top of your main program file.
2. (1 points) The Problem Statement is a brief description of
The assignment: above. Note: the problem statement can (and should)
be in a comment at the top of your main program file.
11. (10 points) Include all program listings and output.
These listings should show good style,
be appropriately commented, have the important parts
highlighted, and include handwritten explanations if it helps the
reader's understanding of the code.
13. & 14. (8 points) Do a "demo" of your program,
showing that it displays the correct image and exits correctly.
15. Include a description of any Known Bugs if needed.
You may be able to gain back lost points by a careful analysis of
what went wrong and possible fixes.
16. This is optional (and no points usually),
but it is useful to think about Possible Improvements.
Obviously there are many for this program.
17. Comments on the lab assignment are also optional
(and again, no points usually), but appreciated!
Important Note: You may discuss algorithms and debugging with other students, but the program and lab report should be your own work.