For this assignment you will write a function which takes as parameters the upper left corner of a button and a string representing the "label" of the button. The function will write the label to the screen with a rectangle drawn around it. The upper left hand corner of the rectangle will be the point sent to the function as a parameter. The declaration of the function is as follows:
//! \brief Draw a button in the drawing window at the specified
//! location with the specified label.
//! \param upper_left The upper left hand corner of the button.
//! \param label The text which appears inside the button.
//! \return Void.
void draw_button( const Point & upper_left, const std::string label );
You will then write a main ( ccc_win_main ) program which tests your function. The main function will set up the graphic window so the upper left hand corner is at the point ( 0, 0 ) and the lower right hand corner is at the point ( 100, 100 ). It will then prompt the user to click on a point in the window where they want the button to be drawn. After a point is entered by the user, the program will prompt the user to enter a string that should be the label of the button. You do not have to be able to handle multiple word strings, a single word is sufficient.
Once the position and label of the button have been obtained from the user, the screen should be cleared and the new button should be displayed in the graphic window by calling the draw_button function. Your program should continue prompting the user for a new location and a label for the button, and drawing the button in the graphic window until the user types "quit" as the button label.
When the user types "quit" as the button label, the program will draw the button with "quit" as its label and terminate. It is OK if the graphic window remains displayed on the computer screen.
Button Specification
When a Message object is displayed in the graphic window it is always the same size regardless of the coordinate system that has been set up with the cwin.coord( ... ) function. This makes it quite difficult to draw objects and text together in a way that is independent of the coordinate system being used. For this reason, amoung others, in every remaining assignment which uses the graphic window we will fix the graphic windows upper left hand corner at the point ( 0, 0 ) and its lower right hand corner at the point ( 100, 100 ).
Since we are permanently setting the size of the graphic window, we can define some constants which represent how wide and how tall a letter is when it is written in the graphic window. These constants are defined in the file global_const.h which is being provided to you. The constants defined in global_const.h that you will be interested in for this assignment are:
WINDOW_WIDTH
The width of the graphic window.
WINDOW_HEIGHT
The height of the graphic window.
UPPER_LEFT
The upper left coordinate of the graphic window.
LOWER_RIGHT
The lower right coordinate of the graphic window.
LETTER_WIDTH
The width of a letter in the graphic window.
LETTER_HEIGHT
The height of a letter in the graphic window.
To use these constants you simply need to sharp include "global_const.h" at the top of your file.
Since we know the width and height of an individial letter, we can draw the border of the button so that the label is completely contained within the border regardless of the length of the label. When the program draws the rectangle that is the border of the button, the rectangle should be a total of 1 LETTER_WIDTH wider than the label, and 1 LETTER_HEIGHTs higher than the label. The label should be centered in the rectangle. Placing the upper left hand conter of the label half a LETTER_WIDTH to the right, and a quarter of a LETTER_HEIGHT lower than the upper left hand corner of the border of the button centers the label quite nicely.
Assignment Framework
main.cpp
Use this file to implement the draw_button( ... ) function and your main function.
Makefile
Your makefile must use the options specified in the class coding standard. The first rule in the makefile shall have a target name of "all" and will compile the program with the default executable name of "a.out". Your makefile must also have a rule with a target name of "clean" which removes the executable and any backup files that were generated by your editor. You should always "make clean" before turning in your assignment.
global_const.h