Lab Assignment 2 -- Demo and writeup Due Thursday, February 2
CS 5721, Spring Semester, 2006
20 Points
Topic: Introduction to SRGP

References:

  1) Course textbook
  2) /opt/local/studata/COURSES/cs5721/srgp_sphigs/SRGP_DISTRIB/doc/X_srgp.txt
For 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.

Hints:

1) SRGP has been installed in the following directory:
     /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.ps
You 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.

Here is how to do it:

First, after SRGP_begin(), put the locator (mouse) into event mode:
	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.

Discussion:

The icon area will consist of a tall thin rectangle on the left of the SRGP window; the rest of the window will be the drawing area. The icon area is divided into small subrectangles or "buttons" that will allow the user choose the option of drawing "polypoints" (actually small squares -- say 3x3 pixels), polylines, polygons, (upright) rectangles, (upright) ellipses (full ellipses, not partial ellipse arcs), and filled versions of the last three kinds of primitives. Also you will need a "quit" button, for a total of 9 buttons. A tenth, "clear" button would be useful also. Each button should be an outlined rectangle containing a sample (icon) of what it is supposed to draw (and the text: "Quit" and "Clear" inside those buttons). In Lab 2b, clicking on one of the buttons will allow the user to interactively draw a primitive of that type. As mentioned above, there are two sample programs that implement this assignment, lab2sample (a simple program), and Demo_Paint (more features) in the lab2 directory.

Notes:

If you run on PC's, you may have to be in 256-color mode (otherwise SRGP won't work). Ask a lab consultant how to change modes if you don't know how. There may be similar problems and fixes on Mac's.

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.


Page URL: http://www.d.umn.edu /~ddunham/cs5721s06/assignments/lab2/assignment.html
Page Author: Doug Dunham
Last Modified: Wednesday, 25-Jan-2006 21:17:54 CST
Comments to: ddunham@d.umn.edu