|
|
 |
CS-321 Lab 4: 2D Graphics
Fall Quarter 1999
Electrical Engineering and Computer Science Department
Dr. Christopher C. Taylor
S-331, 277-7339

www.msoe.edu/~taylor/
Acknowledgment
This lab was originally developed by Dr. Henry L. Welch and
revised by Dr. Christopher C. Taylor.
Purpose
The purpose of this laboratory assignment is to add the following
functionality to your graphics shell: drawing lines and ellipses and
specifiying colors.
Assignment
Your are to do the following:
- Add a command line command that accepts two points (as x/y pairs) and
draws a line between the to points.
- Add a command line command that draws an ellipse give the center point
(as an x/y pair) and two distances (radii along the x and y axes).
- Update your button pressing code so that you can draw both lines and
ellipses using the mouse. (You may remove drawing points using the
mouse, but you should keep points on the command line.) Here are some
issues which you should consider:
- You may find it helpful to differentiate between the two mouse
buttons or to look at the shift key during a button event.
- Keep in mind that separate events will be used for each point
specified. Therefore, state information will have to be shared
between callbacks. Generally speaking, it is better to use
static objects which are local to the member function
than to use a data member of the class since doing so would make
it accessible to other member functions.
- You may want to experiment with pressing/releasing the mouse
button outside of the drawing window. Are the results what you
expected?
- For an additional challenge use the motion event to "draw"
the line or ellipse in progress; although this is
not a requirement.
- There are a number of dynamic memory challenges involved with storing
objects of varying sizes (ellipses, lines, and point objects). Be
sure to review your understanding of dynamic memory allocation.
Depending on how you proceed, this may complicate your memory
recovery operations in some of your destructors.
- Add a command line color command that either accepts RGB values, uses
one of the standard X color names from the standard list in the file
/usr/lib/X11/rgb.txt or by using the Color
class. Once a new color is selected, all subsequent objects should
appear in that color until a new and correct color editor command is
entered. During an exposure redraw each object should appear in the
color in which it was first drawn so you will need to save the color
information (as a GC or pixel value) with the object itself.
Unfortunately, both of these present a problem since both graphical
contexts and pixel values in the colormap are dynamically allocated on
both Torres and the PC. Consequently you will need to keep track of
them and then free them before exiting using either XFreeGC
or XFreeColors respectively (see
additional information). This is probably
best handled in a special member function of the image class or in
the image class destructor.
- Update your help information.
You may use XDrawLine in your line drawing
code; however, you may not use any of the
XDrawArc variants in your ellipse drawing code.
Although not required, you may find it useful to implement the file
reads and writes.
There are areas for extra credit with this assignment, however
you must complete the basic requirements in order to receive the extra
credit.
Lab report (due 4:30pm, October 13, 1999)
The lab reports should be self-contained. That is, it should be possible
for someone to understand what you did and why without seeing anything other
than your report and any previous reports that you have submitted. Your
report should include:
- Purpose
- Problem Statement
- Procedure -- what approach you used to solve the problem
- Documented source code (clearly
identifying any changes made since your last submission). Note: you
should include all the source code necessary to compile your project
except for unmodified source code written by Dr. Welch. For example, you
don't need to include shell.cpp if you didn't modify it.
You may wish to use gensrc, a shell script
which will produce one file containing all of your source code files
and Makefile with the markup commands required by my electronic
submission procedure.
- Discussion including:
- A tally of the number of new Non-commented Lines Of
Code (NLOC) written for this lab assignment. You may use the
CLC
perl script on your code. If possible, break the NLOC down
into the various features you needed to implement.
- A summary of your activity log indicating how much time you spent
on each phase of the assignment.
- A narrative describing any specific problems you encountered and how
you solved them.
- Conclusions (what you learned, suggestions of how the lab could be
improved, things you would have done differently, etc.)
As with any report you submit, correct spelling and grammar are
required. In addition, your report should be submitted electronically
following the Electronic Submission
Guidelines. (You may wish to consult the
sample report before submitting your
report.) Be sure to keep copies of all your files, in case something
gets lost. It may be wise to keep a diskette backup as well.
If you have any questions, consult the instructor.
This page was created by Dr.
Christopher C. Taylor.
|