CMSC 437/691C
Graphical User Interface Programming
TUE,THU 5:30-6:45 PM ACIV 150
Fall 1996
Project 2: A Pixel-Based Paint Program
This page was last updated on 2 October 1996.
Date Due: Tuesday, October 8, 1996 before midnight.
Purpose
To familiarize you with basic X11 drawing operations, interactive mouse input,
event handling, and Motif manager widgets.
Assignment
You must write a pixel-based paint program based on the Motif
DrawingArea widget.
Commands to the program will be given using PushButton and
ToggleButton widgets, which will set the various drawing modes, and
direct interaction with the mouse on the DrawingArea widget. No menus,
pop-up dialog boxes, etc. are required.
The paint application project should take the form of a large
rectangle for drawing flanked by a vertical tool bar on the left and a
horizontal color bar on the top. The tool bar should consist of icons
which can be selected to set the type of shape to be drawn, the fill
mode and the color mode. The color bar should contain buttons for
selecting the current color. The drawing area should allow interactive
drawing of the selected shapes in the current drawing color. Two push
buttons, in the upper-left, should allow the drawing area to be
cleared to the clear color and the program to quit.
The final program should have the following functionality:
- Set current drawing mode for interactively drawing points, lines,
polylines, rectangles, ellipses and free-form drawing.
- Set modes to control whether the rectangles and ellipses are filled or
hollow.
- Set modes to control which color the color bar currently represents:
clear color, fill color, or line color. There should be a dozen or so colors
to choose from.
- "Clear" screen (to current clear color) and "Quit" program buttons.
- Interactive drawing should be performed by selecting a starting point,
dragging to the final point, and releasing using the pointer. For rectangles
and ellipses, these should be opposite corners of the enclosing rectangle.
While dragging is taking place, a rubber-band version of the geometry to
be drawn should be displayed, using the XOR technique.
- For polylines, user should click the left mouse button to start a
line, and then click the left button at each vertex of the polyline.
A click of the middle mouse button should be used to terminate the
polyline. The segments themselves should rubberband from the last set
point.
In addition to the above, projects by students enrolled in the 691C
section should have the following:
- An "Undo" button. After a drawing operation, the user should be
able to click the Undo button, which should remove the last-drawn
object. The Undo should only be one "level", i.e., the user can only
go one step backwards.
Hints
As before, you are encouraged to reuse code from a prototype. Also as
before, please indicate in your code which prototype you are working
from, even if your final result bears little resemblance to the
original.
One place to start is the "draw" program in Chapter 13 of the Young
textbook. However, since that program is more sophisticated than the
assignment in its use of widgets, I suggest that you start with your
Project 1 code and add in portions from the "draw" program, rather
than starting with the "draw" program.
Another prototype is called 'draw2', which comes from O'Reilly volume
6A, and will be available in
~ian/pub/guip/oreilly/ch10/draw2.c
. It is a very simple
example illustrating the DrawingArea, pixmap-storage, and handling
input with callbacks (rather than Event Handlers).
Demo Example
I have installed an example of the second project in
~ian/pub/guip/proj-ex/proj2/color_draw
. As with the
demos for Project 1, this example does not necessarily have
all the features or look-and-feel of what you are required to
do! For example, your project requires a different widget
layout. However, it does have colors, rubberbanding, and all the
tools, and the behavior of the tools is as described above.