CSC311-003 Data Structures |
Due: 20 September |
|
Fall 1996 |
At Midnight |
|
| ||
The overall structure of the main program is given by the action you have to take upon receiving a particular mouse code depending on previous actions. Such a control structure is usually called "event-handler" (the window class also contains a member function event_handler). It can be precisely described by a so-called "finite state diagram":
void window (int w=DEF_WIDTH, int h=DEF_HEIGHT);- The constructor creates a window of size w*h. The default sizes for width and height are defined in defs.h
Button readMouse (UNIT& x, UINT& y);- This function is used to get the coordinates of the first point. Whenever the user clicks one of the mouse buttons, it will return the respective button code and the coordinates
xandy(by reference) of the mouse. Coordinates are measured relative to the upper left corner of the window (as indicated in the figure above). The enumeration type Button is defined in defs.h.
Button readMouse (UINT x1, UINT y1, UINT& x2, UINT& y2);- The second (overloaded) version has to be called for intermediate points and the final point of the polygon.
x1andy1are the coordinates of the previous point, which have to be supplied. Again, the function will return the button code (return value), and the mouse coordinatesx2andy2(passed by reference).
Void drawLine (UINT x1, UINT y1, UINT x2, UINT y2);- While the second form of readMouse automatically draws a provisional line, you are responsible for drawing the actual line upon receiving the appropriate mouse code. This is important because you have to keep track of the points belonging to the polygon, and you have to be able to un-draw an unfinished polygon in case the "undo" button is clicked. The lines are drawn in "xor" mode, i.e., if you call drawLine a second time for the same end points (
x1,y1) and (x2,y2) the line will be erased.

Finally, you have to use adequate data structures to store the polygon. For the sake of simplicity we are using a struct (members are public by default) for the points. Two data members of type UINT (= unsigned int) are needed for the coordinates. Besides the constructor (which should initialize the x and the y coordinate), only the overloaded output operator << is required. The header file point.h will contain the definition of struct point. In main.C you have to keep points in some sort of list. Basically, any STL container class would suffice, but for our application the doubly-linked list, list is themost suitable one. New points are appended at the end (in STL: push_back). In case of an "undo" operation the queue can be emptied point by point starting at the beginning; at the same time you have to erase the line segments in the window. After the polygon is completed you can use the copy function for an output iterator (connected to cout).
- defs.h
- general definitions for all modules
- window.h
- definitions for the window class
- window.C
- implementations of member functions for window
- icon.xbm
- X11 bitmap file for the window icon
- Makefile
- The project make file. Thus just type "make poly" will compile your programs
- point.h
- this file will contain your definition of the point structure
- main.C
- the actual code for the polygon draw program
- poly.demo
- demo program
Weight Files
20% point.h
75% main.C
5% Comments, Styles
main.C will be graded by the following:
Weight Description
20% Using STL list class for user-defined data type point
15% The left click works right
20% The right click works right
10% The middle click works right
10% final output to screen is right